diff --git a/.gitignore b/.gitignore index 54cc59ee4..0380a6557 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ node_modules .settings/ target/ .idea/ -docs/doc/ +docs/doc/ \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 3487a781d..7c4375a2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,97 @@ =========================== +## [3.0.0](https://github.com/buession/buessionframework/releases/tag/v3.0.0) (2024-11-07) + +### 🔨依赖升级 + +- [依赖库版本升级和安全漏洞修复](https://github.com/buession/buession-parent/releases/tag/v3.0.0) + + +### ⭐ 新特性 + +- ClassUtils 新增检测类是否存在方法 isPresent +- 新增 list 到 set 转换器 ListSetConverter +- 新增 set 到 list 转换器 SetListConverter +- 新增断言转换器 PredicateConverter +- 新增 集合转换器 CollectionConverter +- 新增 Map.Entry 到 Map 转换器 MapEntryMapConverter +- httpClient Configuration 新增 expectContinueEnabled、hardCancellationEnabled、targetPreferredAuthSchemes、cookieSpec、proxy 配置 +- httpClient 新增代理支持 +- ApacheClient 新增支持 apache httpcomponents 5,根据依赖的 apache httpcomponents 5 和 apache httpcomponents 4 自动判断,优先使用 apache httpcomponents 5 +- 新增支持 Lettuce(stream 命令不稳定,不推荐使用) +- jedis 模式下,集群支持管道 +- 新增代理方法调用者 ProxyMethodInvoker +- 新增代理调用处理器 InvocationHandler 抽象类 AbstractInvocationHandler +- PropertyMapper 增加正数断言 alwaysApplyingWhenPositiveNumber +- com.buession.io.file.File 新增支持将 InputStream 写入文件 +- JSON 序列化和反序列化支持对原生对象进行配置 +- 增加范围类 Range 及其衍生类 +- 新增日期时间工具类 DateTimeUtils + + +### 🔔 变化 + +- Maps.toList 参数为 LinkedHashMap 时返回 LinkedList +- Lists.toSet 参数为 LinkedList 返回 LinkedHashSet +- Sets.toList 参数为 LinkedHashSet 返回 LinkedList +- core 包中删除依赖 commons-beanutils +- 删除 ArrayUtils、StatusUtils、ObjectUtils、MapUtils、BuesssionFrameworkVersion +- 删除 AbstractAspectAnnotationsMethodInterceptor +- geoip 删除依赖 apache httpcomponents +- 废弃 ApacheRequest、ApacheRequestBuilder、ApacheHttpClientBuilder +- httpClient 优化 ConnectionManager 创建默认原生 ConnectionManager,以解决在创建原生 ConnectionManager 之前,更新了 Configuration 不生效的问题 +- ApacheHttpClient 删除 apache httpcomponents 4 中的特有方法 +- httpClient 参数为 URL 时,不再验证是否为 null +- apache httpcomponents 异步请求时 HttpAsyncResponseConsumer 采用 ZeroCopyConsumer +- okhttp maxRequestsPerHost 大于 0 时,才会更新 okhttp 原生 maxRequestsPerHost 的值 +- 删除 OkHttpClient +- 重构 JDBC 连接池和数据源 +- MyBatisDao 废弃 masterTemplate、slaveSqlSessionTemplate,通过其它数据库本身或其它中间件实现读写分离 +- redis 删除参数为字符串数组或 byte[] 数组的方法 bitField +- redis 废弃字符串型 / byte[]型 min、max 参数的方法 +- redis role 命令直接返回 Role,不再返回 List<Role> +- redis 重构管道、事务内部实现 +- redis 哨兵连接,如果指定了连接超时、读取超时,但未指定哨兵节点连接超时、读取超时,哨兵节点连接超时、读取超时也使用该值 +- redis 连接池调整在连接对象中创建,不再在 DataSource 中创建 +- redis 不再推荐从 DataSource 中创建 RedisConnection 实例 +- IO MimeType 忽略大小写比较 +- 删除 com.buession.web.mvc.Response 中参数为 com.buession.core.Pagination 的构造函数和 setter 函数 +- 删除 buession-cron 和 buession-session +- 删除 MobileFilter、PoweredByHeaderFilter +- 序列化类删除反序列化方法 + + +### 🐞 Bug 修复 + +- httpClient 修复 ConnectionManager 未设置 connectionManagerShared 时,无法从 Configuration 中获取 connectionManagerShared 值的 BUG +- 修复 okhttp 设置 followRedirects 时,followSslRedirects 未生效的 BUG +- 修复 jedis 模式下 role 命令未返回数据的 BUG +- 修复 jedis 模式下 API 中,“命令”参数设置错误的 BUG +- 修复 jedis GeoRadiusResponseConverter coordinate 为 null 时,空指针异常 +- 修复 jedis 模式下连接中的错误和参数丢失等问题 +- 修复 Validate IPV4 验证,第一段为 10 ~ 99 时,验证失败的 BUG + + +### ⏪ 优化 +- 优化 redis 转换器,不使用静态属性,以减少内存占用 +- jedis 模式命令运算优化 +- 优化 JDBC 数据源连接池设置 +- 优化 httpclient 配置、连接管理器以及连接客户端 +- 优化默认线程池执行器 DefaultThreadPoolExecutor 初始化 +- com.buession.io.file.File 读取文件优化 + + +### 📔 文档 + +- 完善 redis 注释 +- 修正 httpclient 错误注释 +- 完善 httpclient 注释 + + +--- + + ## [2.3.3](https://github.com/buession/buessionframework/releases/tag/v2.3.3) (2024-05-06) ### 🔨依赖升级 diff --git a/buession-aop/pom.xml b/buession-aop/pom.xml index 518aa7c6f..25adad0a1 100644 --- a/buession-aop/pom.xml +++ b/buession-aop/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-aop http://www.buession.com/ @@ -61,8 +61,6 @@ aopalliance aopalliance - 1.0 - provided @@ -77,8 +75,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -122,8 +120,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-aop/src/main/java/com/buession/aop/AbstractInvocationHandler.java b/buession-aop/src/main/java/com/buession/aop/AbstractInvocationHandler.java new file mode 100644 index 000000000..4c7feb7bf --- /dev/null +++ b/buession-aop/src/main/java/com/buession/aop/AbstractInvocationHandler.java @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.aop; + +import com.buession.aop.utils.ProxyUtils; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +/** + * {@link InvocationHandler} 抽象类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractInvocationHandler implements InvocationHandler { + + private final static int ALLOWED_MODES = MethodHandles.Lookup.PRIVATE | MethodHandles.Lookup.PROTECTED + | MethodHandles.Lookup.PUBLIC | MethodHandles.Lookup.PACKAGE; + + protected final static Constructor lookupConstructor; + + protected final static Method privateLookupInMethod; + + static { + Method privateLookupIn; + try{ + privateLookupIn = MethodHandles.class.getMethod("privateLookupIn", Class.class, MethodHandles.Lookup.class); + }catch(NoSuchMethodException e){ + privateLookupIn = null; + } + privateLookupInMethod = privateLookupIn; + + Constructor lookup = null; + if(privateLookupInMethod == null){ + // JDK 1.8 + try{ + lookup = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, int.class); + lookup.setAccessible(true); + }catch(NoSuchMethodException e){ + throw new IllegalStateException( + "There is neither 'privateLookupIn(Class, Lookup)' nor 'Lookup(Class, int)' method in java.lang.invoke.MethodHandles.", + e); + }catch(Exception e){ + lookup = null; + } + } + lookupConstructor = lookup; + } + + @Override + public final Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if(args == null){ + args = ProxyMethodInvoker.NO_ARGS; + } + + if(args.length == 0){ + if("hashCode".equals(method.getName())){ + return doHashCode(); + }else if("toString".equals(method.getName())){ + return doToString(); + } + } + + if(args.length == 1 && "equals".equals(method.getName()) && method.getParameterTypes()[0] == Object.class){ + Object arg = args[0]; + return doEquals(proxy, arg); + } + + return doInvoke(proxy, method, args); + } + + protected Object doHashCode() { + return hashCode(); + } + + protected Object doEquals(final Object proxy, final Object arg) { + if(arg == null){ + return false; + } + + if(proxy == arg){ + return true; + } + + return ProxyUtils.isProxyOfSameInterfaces(arg, proxy.getClass()) && equals(Proxy.getInvocationHandler(arg)); + } + + protected Object doToString() { + return toString(); + } + + protected Object doInvoke(final Object proxy, final Method method, final Object[] args) throws Throwable { + if(Object.class.equals(method.getDeclaringClass())){ + return method.invoke(this, args); + } + + return handleInvocation(proxy, method, args); + } + + protected abstract Object handleInvocation(final Object proxy, final Method method, final Object[] args) + throws Throwable; + + protected int getAllowedModes() { + return ALLOWED_MODES; + } + + protected ProxyMethodInvoker createMethodInvoker(final Method method) + throws InvocationTargetException, IllegalAccessException, InstantiationException, NoSuchMethodException { + if(method.isDefault()){ + final MethodHandle methodHandle = privateLookupInMethod == null ? getMethodHandleJava8(method) : + getMethodHandleJava9(method); + return new DefaultMethodInvoker<>(methodHandle); + }else{ + return new PlainMethodInvoker<>(); + } + } + + protected MethodHandle getMethodHandleJava8(final Method method) + throws IllegalAccessException, InstantiationException, InvocationTargetException { + final Class declaringClass = method.getDeclaringClass(); + return lookupConstructor.newInstance(declaringClass, getAllowedModes()) + .unreflectSpecial(method, declaringClass); + } + + protected MethodHandle getMethodHandleJava9(final Method method) + throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { + final Class declaringClass = method.getDeclaringClass(); + final MethodType methodType = MethodType.methodType(method.getReturnType(), method.getParameterTypes()); + + return ((MethodHandles.Lookup) privateLookupInMethod.invoke(null, declaringClass, MethodHandles.lookup())) + .findSpecial(declaringClass, method.getName(), methodType, declaringClass); + } + +} diff --git a/buession-aop/src/main/java/com/buession/aop/DefaultMethodInvoker.java b/buession-aop/src/main/java/com/buession/aop/DefaultMethodInvoker.java new file mode 100644 index 000000000..368bd469f --- /dev/null +++ b/buession-aop/src/main/java/com/buession/aop/DefaultMethodInvoker.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.aop; + +import com.buession.core.utils.Assert; + +import java.lang.invoke.MethodHandle; +import java.lang.reflect.Method; + +/** + * 默认代理方法调用者 + * + * @param + * 代理类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class DefaultMethodInvoker implements ProxyMethodInvoker { + + private final MethodHandle methodHandle; + + /** + * 构造函数 + * + * @param methodHandle + * {@link MethodHandle} + */ + public DefaultMethodInvoker(final MethodHandle methodHandle) { + Assert.isNull(methodHandle, "MethodHandle cloud not be null"); + this.methodHandle = methodHandle; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args, T object) throws Throwable { + return methodHandle.bindTo(proxy).invokeWithArguments(args); + } + +} diff --git a/buession-aop/src/main/java/com/buession/aop/PlainMethodInvoker.java b/buession-aop/src/main/java/com/buession/aop/PlainMethodInvoker.java new file mode 100644 index 000000000..89b8655d3 --- /dev/null +++ b/buession-aop/src/main/java/com/buession/aop/PlainMethodInvoker.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.aop; + +import java.lang.reflect.Method; + +/** + * 简单代理方法调用者 + * + * @param + * 代理类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class PlainMethodInvoker implements ProxyMethodInvoker { + + @Override + public Object invoke(Object proxy, Method method, Object[] args, T object) throws Throwable { + return method.invoke(object, args); + } + +} diff --git a/buession-aop/src/main/java/com/buession/aop/ProxyMethodInvoker.java b/buession-aop/src/main/java/com/buession/aop/ProxyMethodInvoker.java new file mode 100644 index 000000000..70c7e603c --- /dev/null +++ b/buession-aop/src/main/java/com/buession/aop/ProxyMethodInvoker.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.aop; + +import java.lang.reflect.Method; + +/** + * 代理方法调用者 + * + * @param + * 代理类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +@FunctionalInterface +public interface ProxyMethodInvoker { + + Object[] NO_ARGS = {}; + + /** + * 代理方法调用 + * + * @param proxy + * 代理类实例 + * @param method + * 方法 + * @param args + * 参数 + * @param object + * 代理类实例 + * + * @return 返回结果 + * + * @throws Throwable + * 异常 + */ + Object invoke(Object proxy, Method method, Object[] args, T object) throws Throwable; + +} diff --git a/buession-aop/src/main/java/com/buession/aop/aopalliance/AbstractAopAllianceAnnotationsMethodInterceptor.java b/buession-aop/src/main/java/com/buession/aop/aopalliance/AbstractAopAllianceAnnotationsMethodInterceptor.java index de34baa42..34c2c57f4 100644 --- a/buession-aop/src/main/java/com/buession/aop/aopalliance/AbstractAopAllianceAnnotationsMethodInterceptor.java +++ b/buession-aop/src/main/java/com/buession/aop/aopalliance/AbstractAopAllianceAnnotationsMethodInterceptor.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.aop.aopalliance; @@ -42,12 +42,12 @@ public abstract class AbstractAopAllianceAnnotationsMethodInterceptor extends Ab /** * 构造函数 */ - public AbstractAopAllianceAnnotationsMethodInterceptor(){ + public AbstractAopAllianceAnnotationsMethodInterceptor() { super(); } @Override - public Object invoke(MethodInvocation methodInvocation) throws Throwable{ + public Object invoke(MethodInvocation methodInvocation) throws Throwable { com.buession.aop.MethodInvocation mi = createMethodInvocation(methodInvocation); return super.invoke(mi); } @@ -60,32 +60,32 @@ public Object invoke(MethodInvocation methodInvocation) throws Throwable{ * * @return The instance of {@link com.buession.aop.MethodInvocation} */ - protected com.buession.aop.MethodInvocation createMethodInvocation(final MethodInvocation mi){ + protected com.buession.aop.MethodInvocation createMethodInvocation(final MethodInvocation mi) { return new com.buession.aop.MethodInvocation() { @Override - public Object getThis(){ + public Object getThis() { return mi.getThis(); } @Override - public Method getMethod(){ + public Method getMethod() { return mi.getMethod(); } @Override - public Object[] getArguments(){ + public Object[] getArguments() { return mi.getArguments(); } @Override - public Object proceed() throws Throwable{ + public Object proceed() throws Throwable { return mi.proceed(); } @Override - public String toString(){ - return "Method invocation [" + mi.getMethod() + "]"; + public String toString() { + return "Method invocation [" + mi.getMethod() + ']'; } }; diff --git a/buession-aop/src/main/java/com/buession/aop/utils/ProxyUtils.java b/buession-aop/src/main/java/com/buession/aop/utils/ProxyUtils.java new file mode 100644 index 000000000..2330c52fa --- /dev/null +++ b/buession-aop/src/main/java/com/buession/aop/utils/ProxyUtils.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.aop.utils; + +import java.lang.reflect.Proxy; +import java.util.Arrays; + +/** + * 代理工具类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class ProxyUtils { + + protected ProxyUtils() { + + } + + /** + * 检测对象是否为代理类实例 + * + * @param obj + * 待检测对象 + * @param proxyClass + * 代理类 + * + * @return true / false + */ + public static boolean isProxyOfSameInterfaces(Object obj, Class proxyClass) { + return proxyClass.isInstance(obj) || (Proxy.isProxyClass(obj.getClass()) + && Arrays.equals(obj.getClass().getInterfaces(), proxyClass.getInterfaces())); + } + +} diff --git a/buession-aop/src/main/java/com/buession/aop/utils/package-info.java b/buession-aop/src/main/java/com/buession/aop/utils/package-info.java new file mode 100644 index 000000000..6b9ffff28 --- /dev/null +++ b/buession-aop/src/main/java/com/buession/aop/utils/package-info.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + * @since 3.0.0 + */ +package com.buession.aop.utils; \ No newline at end of file diff --git a/buession-beans/pom.xml b/buession-beans/pom.xml index c1122199b..18e7136b3 100644 --- a/buession-beans/pom.xml +++ b/buession-beans/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-beans http://www.buession.com/ @@ -67,6 +67,10 @@ commons-beanutils commons-beanutils + + commons-logging + commons-logging + org.slf4j @@ -74,8 +78,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -119,8 +123,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-beans/src/test/java/com/buession/beans/BeanConverterTest.java b/buession-beans/src/test/java/com/buession/beans/BeanConverterTest.java index 7db05f2d8..31a70da42 100644 --- a/buession-beans/src/test/java/com/buession/beans/BeanConverterTest.java +++ b/buession-beans/src/test/java/com/buession/beans/BeanConverterTest.java @@ -19,13 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.beans; -import org.junit.Test; -import org.springframework.cglib.beans.BeanMap; +import org.junit.jupiter.api.Test; import java.util.Date; import java.util.HashMap; diff --git a/buession-core/pom.xml b/buession-core/pom.xml index c76468e7c..aa1d41ff0 100644 --- a/buession-core/pom.xml +++ b/buession-core/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-core http://www.buession.com/ @@ -89,11 +89,6 @@ commons-collections4 - - commons-beanutils - commons-beanutils - - jakarta.annotation jakarta.annotation-api @@ -113,7 +108,7 @@ com.fasterxml.jackson.core jackson-databind - compile + provided true @@ -121,12 +116,20 @@ com.alibaba fastjson provided + true com.google.code.gson gson provided + true + + + com.google.errorprone + error_prone_annotations + + @@ -140,8 +143,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -185,8 +188,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-core/src/main/java/com/buession/core/BuessionFrameworkVersion.java b/buession-core/src/main/java/com/buession/core/BuessionFrameworkVersion.java index 457dc2f86..303e74437 100644 --- a/buession-core/src/main/java/com/buession/core/BuessionFrameworkVersion.java +++ b/buession-core/src/main/java/com/buession/core/BuessionFrameworkVersion.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core; @@ -34,12 +34,23 @@ */ public final class BuessionFrameworkVersion { + private static String VERSION; + private BuessionFrameworkVersion() { } + /** + * 获取框架版本 + * + * @return 框架版本 + */ public static String getVersion() { - return VersionUtils.determineClassVersion(BuessionFrameworkVersion.class); + if(VERSION == null){ + VERSION = VersionUtils.determineClassVersion(BuessionFrameworkVersion.class); + } + + return VERSION; } } diff --git a/buession-core/src/main/java/com/buession/core/Customizer.java b/buession-core/src/main/java/com/buession/core/Customizer.java index 629e4d44a..149cd6b0f 100644 --- a/buession-core/src/main/java/com/buession/core/Customizer.java +++ b/buession-core/src/main/java/com/buession/core/Customizer.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core; @@ -27,25 +27,21 @@ /** * 定制器接口 * - * @param - * 源类型 * @param - * 待定制对象类型 + * 定制对象类型 * * @author Yong.Teng * @since 2.3.0 */ @FunctionalInterface -public interface Customizer { +public interface Customizer { /** * 定制 * - * @param source - * 源实例 - * @param target - * 待定制实例 + * @param object + * 定制对象 */ - void customize(S source, T target); + void customize(T object); } diff --git a/buession-core/src/main/java/com/buession/core/DoubleRange.java b/buession-core/src/main/java/com/buession/core/DoubleRange.java new file mode 100644 index 000000000..79b6daae1 --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/DoubleRange.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core; + +/** + * {@code Double} 范围 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class DoubleRange extends NumberRange { + + /** + * 构造函数 + */ + public DoubleRange() { + super(); + } + + /** + * 构造函数 + * + * @param start + * 起始值 + * @param end + * 截止值 + */ + public DoubleRange(Double start, Double end) { + super(start, end); + } + +} diff --git a/buession-core/src/main/java/com/buession/core/FloatRange.java b/buession-core/src/main/java/com/buession/core/FloatRange.java new file mode 100644 index 000000000..2ad7d055c --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/FloatRange.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core; + +/** + * {@code Float} 范围 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class FloatRange extends NumberRange { + + /** + * 构造函数 + */ + public FloatRange() { + super(); + } + + /** + * 构造函数 + * + * @param start + * 起始值 + * @param end + * 截止值 + */ + public FloatRange(Float start, Float end) { + super(start, end); + } + +} diff --git a/buession-core/src/main/java/com/buession/core/IntegerRange.java b/buession-core/src/main/java/com/buession/core/IntegerRange.java new file mode 100644 index 000000000..e881e75a9 --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/IntegerRange.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core; + +/** + * {@code Integer} 范围 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class IntegerRange extends NumberRange { + + /** + * 构造函数 + */ + public IntegerRange() { + super(); + } + + /** + * 构造函数 + * + * @param start + * 起始值 + * @param end + * 截止值 + */ + public IntegerRange(Integer start, Integer end) { + super(start, end); + } + +} diff --git a/buession-core/src/main/java/com/buession/core/LongRange.java b/buession-core/src/main/java/com/buession/core/LongRange.java new file mode 100644 index 000000000..cc32c5b97 --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/LongRange.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core; + +/** + * {@code Long} 范围 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LongRange extends NumberRange { + + /** + * 构造函数 + */ + public LongRange() { + super(); + } + + /** + * 构造函数 + * + * @param start + * 起始值 + * @param end + * 截止值 + */ + public LongRange(Long start, Long end) { + super(start, end); + } + +} diff --git a/buession-core/src/main/java/com/buession/core/NumberRange.java b/buession-core/src/main/java/com/buession/core/NumberRange.java new file mode 100644 index 000000000..b9a3d8804 --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/NumberRange.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core; + +/** + * 数值范围 + * + * @param + * 数值类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class NumberRange extends Range { + + /** + * 构造函数 + */ + public NumberRange() { + super(); + } + + /** + * 构造函数 + * + * @param start + * 起始值 + * @param end + * 截止值 + */ + public NumberRange(T start, T end) { + super(start, end); + } + +} diff --git a/buession-core/src/main/java/com/buession/core/Pagination.java b/buession-core/src/main/java/com/buession/core/Pagination.java index 08e1dd6f9..a544f8c51 100755 --- a/buession-core/src/main/java/com/buession/core/Pagination.java +++ b/buession-core/src/main/java/com/buession/core/Pagination.java @@ -21,11 +21,12 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.core; +import java.io.Serializable; import java.util.List; /** @@ -36,7 +37,9 @@ * * @author Yong.Teng */ -public class Pagination { +public class Pagination implements Serializable { + + private final static long serialVersionUID = 1135345190741903064L; /** * 默认每页大小 @@ -81,7 +84,7 @@ public class Pagination { /** * Constructs with default configuration. */ - public Pagination(){ + public Pagination() { } /** @@ -92,7 +95,7 @@ public Pagination(){ * @param pagesize * 每页大小 */ - public Pagination(int page, int pagesize){ + public Pagination(int page, int pagesize) { setPagesize(pagesize); setPage(page); } @@ -107,7 +110,7 @@ public Pagination(int page, int pagesize){ * @param totalRecords * 总记录数 */ - public Pagination(int page, int pagesize, long totalRecords){ + public Pagination(int page, int pagesize, long totalRecords) { setPagesize(pagesize); setTotalRecords(totalRecords); setPage(page); @@ -118,7 +121,7 @@ public Pagination(int page, int pagesize, long totalRecords){ * * @return 当前页码 */ - public int getPage(){ + public int getPage() { return page; } @@ -128,7 +131,7 @@ public int getPage(){ * @param page * 当前页码 */ - public void setPage(int page){ + public void setPage(int page) { this.page = page < 1 ? 1 : (totalPages > 1 && page > totalPages ? totalPages : page); } @@ -137,7 +140,7 @@ public void setPage(int page){ * * @return 每页大小 */ - public int getPagesize(){ + public int getPagesize() { return pagesize; } @@ -147,7 +150,7 @@ public int getPagesize(){ * @param pagesize * 每页大小 */ - public void setPagesize(int pagesize){ + public void setPagesize(int pagesize) { this.pagesize = pagesize < 1 ? PAGESIZE : pagesize; } @@ -156,7 +159,7 @@ public void setPagesize(int pagesize){ * * @return 前一页页码 */ - public int getPreviousPage(){ + public int getPreviousPage() { return previousPage; } @@ -166,7 +169,7 @@ public int getPreviousPage(){ * @param previousPage * 前一页页码 */ - public void setPreviousPage(int previousPage){ + public void setPreviousPage(int previousPage) { this.previousPage = (page <= 1 ? 1 : previousPage); } @@ -175,7 +178,7 @@ public void setPreviousPage(int previousPage){ * * @return 下一页页码 */ - public int getNextPage(){ + public int getNextPage() { return nextPage; } @@ -185,7 +188,7 @@ public int getNextPage(){ * @param nextPage * 下一页页码 */ - public void setNextPage(int nextPage){ + public void setNextPage(int nextPage) { this.nextPage = totalPages < page ? page : nextPage; } @@ -194,7 +197,7 @@ public void setNextPage(int nextPage){ * * @return 总页码 */ - public int getTotalPages(){ + public int getTotalPages() { return totalPages; } @@ -204,7 +207,7 @@ public int getTotalPages(){ * @param totalPages * 总页码 */ - public void setTotalPages(int totalPages){ + public void setTotalPages(int totalPages) { this.totalPages = Math.max(totalPages, 1); } @@ -213,7 +216,7 @@ public void setTotalPages(int totalPages){ * * @return 总记录数 */ - public long getTotalRecords(){ + public long getTotalRecords() { return totalRecords; } @@ -223,7 +226,7 @@ public long getTotalRecords(){ * @param totalRecords * 总记录数 */ - public void setTotalRecords(long totalRecords){ + public void setTotalRecords(long totalRecords) { this.totalRecords = totalRecords < 0 ? 0 : totalRecords; setTotalPages((int) Math.ceil((double) this.totalRecords / pagesize)); @@ -236,7 +239,7 @@ public void setTotalRecords(long totalRecords){ * * @return 结果数据 */ - public List getData(){ + public List getData() { return data; } @@ -246,7 +249,7 @@ public List getData(){ * @param data * 结果数据 */ - public void setData(List data){ + public void setData(List data) { this.data = data; } diff --git a/buession-core/src/main/java/com/buession/core/Range.java b/buession-core/src/main/java/com/buession/core/Range.java new file mode 100644 index 000000000..bb1317afc --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/Range.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core; + +/** + * 范围 + * + * @param + * 值类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class Range { + + /** + * 起始值 + */ + private T start; + + /** + * 截止值 + */ + private T end; + + /** + * 构造函数 + */ + public Range() { + } + + /** + * 构造函数 + * + * @param start + * 起始值 + * @param end + * 截止值 + */ + public Range(final T start, final T end) { + this.start = start; + this.end = end; + } + + /** + * 返回起始值 + * + * @return 起始值 + */ + public T getStart() { + return start; + } + + /** + * 设置起始值 + * + * @param start + * 起始值 + */ + public void setStart(T start) { + this.start = start; + } + + /** + * 返回截止值 + * + * @return 截止值 + */ + public T getEnd() { + return end; + } + + /** + * 设置截止值 + * + * @param end + * 截止值 + */ + public void setEnd(T end) { + this.end = end; + } + + @Override + public String toString() { + return "[" + start + ", " + end + "]"; + } + +} diff --git a/buession-core/src/main/java/com/buession/core/Rawable.java b/buession-core/src/main/java/com/buession/core/Rawable.java index 14469abf4..79be0a308 100644 --- a/buession-core/src/main/java/com/buession/core/Rawable.java +++ b/buession-core/src/main/java/com/buession/core/Rawable.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core; @@ -30,6 +30,7 @@ * @author Yong.Teng * @since 2.0.0 */ +@FunctionalInterface public interface Rawable { /** diff --git a/buession-core/src/main/java/com/buession/core/ShortRange.java b/buession-core/src/main/java/com/buession/core/ShortRange.java new file mode 100644 index 000000000..3402ab0e4 --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/ShortRange.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core; + +/** + * {@code Short} 范围 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class ShortRange extends NumberRange { + + /** + * 构造函数 + */ + public ShortRange() { + super(); + } + + /** + * 构造函数 + * + * @param start + * 起始值 + * @param end + * 截止值 + */ + public ShortRange(Short start, Short end) { + super(start, end); + } + +} diff --git a/buession-core/src/main/java/com/buession/core/collect/Arrays.java b/buession-core/src/main/java/com/buession/core/collect/Arrays.java index 1771032db..5462ab08c 100644 --- a/buession-core/src/main/java/com/buession/core/collect/Arrays.java +++ b/buession-core/src/main/java/com/buession/core/collect/Arrays.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.collect; diff --git a/buession-core/src/main/java/com/buession/core/collect/Lists.java b/buession-core/src/main/java/com/buession/core/collect/Lists.java index af019760c..2d44ce0e9 100644 --- a/buession-core/src/main/java/com/buession/core/collect/Lists.java +++ b/buession-core/src/main/java/com/buession/core/collect/Lists.java @@ -19,14 +19,16 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.collect; import com.buession.core.utils.StringUtils; +import java.util.HashSet; import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -50,7 +52,7 @@ public class Lists { * * @return 拼接后的字符串 */ - public static String toString(final List data){ + public static String toString(final List data) { return StringUtils.join(data, DEFAULT_GLUE); } @@ -66,7 +68,7 @@ public static String toString(final List data){ * * @return 拼接后的字符串 */ - public static String toString(final List data, final String glue){ + public static String toString(final List data, final String glue) { return StringUtils.join(data, glue); } @@ -80,8 +82,14 @@ public static String toString(final List data, final String glue){ * * @return 当 data 为 null 时,返回 null;否则,返回 O 类型的 {@link Set} */ - public static Set toSet(final List data){ - return data == null ? null : new LinkedHashSet<>(data); + public static Set toSet(final List data) { + if(data == null){ + return null; + }else if(data instanceof LinkedList){ + return new LinkedHashSet<>(data); + }else{ + return new HashSet<>(data); + } } } diff --git a/buession-core/src/main/java/com/buession/core/collect/Maps.java b/buession-core/src/main/java/com/buession/core/collect/Maps.java index 692a20867..b0365436e 100644 --- a/buession-core/src/main/java/com/buession/core/collect/Maps.java +++ b/buession-core/src/main/java/com/buession/core/collect/Maps.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.collect; @@ -30,6 +30,7 @@ import java.util.IdentityHashMap; import java.util.LinkedHashMap; import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -134,7 +135,13 @@ public static Map map(final Map map, final Func * @return 当 map 为 null 时,返回 null;否则返回 V 类型的 {@link List} */ public static List toList(final Map map) { - return map == null ? null : new ArrayList<>(map.values()); + if(map == null){ + return null; + }else if(map instanceof LinkedHashMap){ + return new LinkedList<>(map.values()); + }else{ + return new ArrayList<>(map.values()); + } } /** diff --git a/buession-core/src/main/java/com/buession/core/collect/Sets.java b/buession-core/src/main/java/com/buession/core/collect/Sets.java index 0352a895b..40157cdec 100644 --- a/buession-core/src/main/java/com/buession/core/collect/Sets.java +++ b/buession-core/src/main/java/com/buession/core/collect/Sets.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.collect; @@ -27,6 +27,8 @@ import com.buession.core.utils.StringUtils; import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -50,7 +52,7 @@ public class Sets { * * @return 拼接后的字符串 */ - public static String toString(final Set data){ + public static String toString(final Set data) { return StringUtils.join(data, DEFAULT_GLUE); } @@ -66,7 +68,7 @@ public static String toString(final Set data){ * * @return 拼接后的字符串 */ - public static String toString(final Set data, final String glue){ + public static String toString(final Set data, final String glue) { return StringUtils.join(data, glue); } @@ -80,8 +82,14 @@ public static String toString(final Set data, final String glue){ * * @return 当 data 为 null 时,返回 null;否则,返回 O 类型的 {@link List} */ - public static List toList(final Set data){ - return data == null ? null : new ArrayList<>(data); + public static List toList(final Set data) { + if(data == null){ + return null; + }else if(data instanceof LinkedHashSet){ + return new LinkedList<>(data); + }else{ + return new ArrayList<>(data); + } } } diff --git a/buession-core/src/main/java/com/buession/core/concurrent/DefaultThreadPoolExecutor.java b/buession-core/src/main/java/com/buession/core/concurrent/DefaultThreadPoolExecutor.java index 2e4f22e09..f0462b74b 100644 --- a/buession-core/src/main/java/com/buession/core/concurrent/DefaultThreadPoolExecutor.java +++ b/buession-core/src/main/java/com/buession/core/concurrent/DefaultThreadPoolExecutor.java @@ -31,6 +31,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; +import java.util.function.Supplier; /** * 默认线程池执行器 @@ -56,13 +57,12 @@ public DefaultThreadPoolExecutor() { * 线程池配置 */ public DefaultThreadPoolExecutor(final ThreadPoolConfiguration configuration) { - super(initValue(configuration.getCorePoolSize(), Runtime.getRuntime().availableProcessors() << 1), + super(initValue(configuration.getCorePoolSize(), ()->Runtime.getRuntime().availableProcessors() << 1), configuration.getMaximumPoolSize() > 0 ? configuration.getMaximumPoolSize() : Runtime.getRuntime().availableProcessors() << 1, - initValue(configuration.getKeepAliveTime(), DEFAULT_KEEP_ALIVE_TIME), - configuration.getKeepAliveTimeUnit(), - initValue(configuration.getWorkQueue(), new LinkedBlockingQueue<>()), - initValue(configuration.getThreadFactory(), createDefaultThreadFactory(configuration))); + initValue(configuration.getKeepAliveTime(), ()->DEFAULT_KEEP_ALIVE_TIME), + configuration.getKeepAliveTimeUnit(), initValue(configuration.getWorkQueue(), LinkedBlockingQueue::new), + initValue(configuration.getThreadFactory(), ()->createDefaultThreadFactory(configuration))); final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); @@ -70,16 +70,16 @@ public DefaultThreadPoolExecutor(final ThreadPoolConfiguration configuration) { propertyMapper.from(configuration.getRejectedHandler()).to(this::setRejectedExecutionHandler); } - protected static int initValue(final int value, final int defaultValue) { - return value >= 0 ? value : defaultValue; + protected static int initValue(final int value, final Supplier defaultValue) { + return value >= 0 ? value : defaultValue.get(); } - protected static long initValue(final long value, final long defaultValue) { - return value >= 0 ? value : defaultValue; + protected static long initValue(final long value, final Supplier defaultValue) { + return value >= 0 ? value : defaultValue.get(); } - protected static T initValue(final T value, final T defaultValue) { - return Optional.ofNullable(value).orElse(defaultValue); + protected static T initValue(final T value, final Supplier defaultValue) { + return Optional.ofNullable(value).orElse(defaultValue.get()); } protected static ThreadFactory createDefaultThreadFactory(final ThreadPoolConfiguration configuration) { diff --git a/buession-core/src/main/java/com/buession/core/converter/CollectionConverter.java b/buession-core/src/main/java/com/buession/core/converter/CollectionConverter.java new file mode 100644 index 000000000..cfddcb56e --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/converter/CollectionConverter.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core.converter; + +import org.springframework.beans.BeanUtils; + +import java.util.Collection; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * {@link Collection} 转换器 + * + * @param + * 原类型 + * @param + * 目标类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class CollectionConverter implements Converter, Collection> { + + /** + * List item 转换器 + */ + private final Converter itemConverter; + + /** + * 构造函数 + * + * @param itemConverter + * Collection item 转换器 + */ + public CollectionConverter(final Converter itemConverter) { + this.itemConverter = itemConverter; + } + + @SuppressWarnings({"unchecked"}) + @Override + public Collection convert(final Collection source) { + if(source == null){ + return null; + }else{ + Stream stream = source.stream().map(itemConverter::convert); + + try{ + return stream.collect(Collectors.toCollection(()->BeanUtils.instantiateClass(source.getClass()))); + }catch(Exception e){ + return stream.collect(Collectors.toList()); + } + } + } + +} diff --git a/buession-core/src/main/java/com/buession/core/converter/ListMapEntryMapConverter.java b/buession-core/src/main/java/com/buession/core/converter/ListMapEntryMapConverter.java new file mode 100644 index 000000000..a0b4d5ef7 --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/converter/ListMapEntryMapConverter.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core.converter; + +import org.springframework.lang.Nullable; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * 值为 {@link Map.Entry} 的 {@link List} 到 {@link Map} 转换器 + * + * @param + * Map 原 key 类型 + * @param + * Map 原 value 类型 + * @param + * Map 目标 key 类型 + * @param + * Map 目标 value 类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class ListMapEntryMapConverter implements Converter>, Map> { + + /** + * Map key 转换器 + */ + private final Converter keyConverter; + + /** + * Map value 转换器 + */ + private final Converter valueConverter; + + /** + * 构造函数 + * + * @param keyConverter + * Map key 转换器 + * @param valueConverter + * Map value 转换器 + */ + public ListMapEntryMapConverter(final Converter keyConverter, final Converter valueConverter) { + this.keyConverter = keyConverter; + this.valueConverter = valueConverter; + } + + @Nullable + @Override + public Map convert(final List> source) { + if(source == null){ + return null; + }else{ + final Map result = new LinkedHashMap<>(source.size()); + + for(Map.Entry e : source){ + result.put(keyConverter.convert(e.getKey()), valueConverter.convert(e.getValue())); + } + + return result; + } + } + +} diff --git a/buession-core/src/main/java/com/buession/core/converter/ListSetConverter.java b/buession-core/src/main/java/com/buession/core/converter/ListSetConverter.java new file mode 100644 index 000000000..68e5dce52 --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/converter/ListSetConverter.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core.converter; + +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * List => Set 转换器 + * + * @param + * 原类型 + * @param + * 目标类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class ListSetConverter implements Converter, Set> { + + /** + * List item 转换器 + */ + private final Converter itemConverter; + + /** + * 构造函数 + * + * @param itemConverter + * List item 转换器 + */ + public ListSetConverter(final Converter itemConverter) { + this.itemConverter = itemConverter; + } + + @Override + public Set convert(final List source) { + if(source == null){ + return null; + }else{ + return source.stream().map(itemConverter::convert) + .collect(Collectors.toCollection(source instanceof LinkedList ? LinkedHashSet::new : HashSet::new)); + } + } + +} diff --git a/buession-core/src/main/java/com/buession/core/converter/MapEntryKeyValueConverter.java b/buession-core/src/main/java/com/buession/core/converter/MapEntryKeyValueConverter.java new file mode 100644 index 000000000..c3b75e640 --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/converter/MapEntryKeyValueConverter.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core.converter; + +import com.buession.lang.KeyValue; +import org.springframework.lang.Nullable; + +import java.util.Map; + +/** + * {@link Map.Entry} 到 {@link KeyValue} 转换器 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class MapEntryKeyValueConverter implements Converter, KeyValue> { + + /** + * Map key 转换器 + */ + private final Converter keyConverter; + + /** + * Map value 转换器 + */ + private final Converter valueConverter; + + /** + * 构造函数 + * + * @param keyConverter + * Map key 转换器 + * @param valueConverter + * Map value 转换器 + */ + public MapEntryKeyValueConverter(final Converter keyConverter, final Converter valueConverter) { + this.keyConverter = keyConverter; + this.valueConverter = valueConverter; + } + + @Nullable + @Override + public KeyValue convert(final Map.Entry source) { + return source == null ? null : new KeyValue<>(keyConverter.convert(source.getKey()), + valueConverter.convert(source.getValue())); + } + +} diff --git a/buession-core/src/main/java/com/buession/core/converter/MapEntryMapConverter.java b/buession-core/src/main/java/com/buession/core/converter/MapEntryMapConverter.java new file mode 100644 index 000000000..03fa77c4e --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/converter/MapEntryMapConverter.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core.converter; + +import com.buession.core.builder.MapBuilder; +import org.springframework.lang.Nullable; + +import java.util.Map; + +/** + * {@link Map.Entry} 到 {@link Map} 转换器 + * + * @param + * Map 原 key 类型 + * @param + * Map 原 value 类型 + * @param + * Map 目标 key 类型 + * @param + * Map 目标 value 类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class MapEntryMapConverter implements Converter, Map> { + + /** + * Map key 转换器 + */ + private final Converter keyConverter; + + /** + * Map value 转换器 + */ + private final Converter valueConverter; + + /** + * 构造函数 + * + * @param keyConverter + * Map key 转换器 + * @param valueConverter + * Map value 转换器 + */ + public MapEntryMapConverter(final Converter keyConverter, final Converter valueConverter) { + this.keyConverter = keyConverter; + this.valueConverter = valueConverter; + } + + @Nullable + @Override + public Map convert(final Map.Entry source) { + if(source == null){ + return null; + }else{ + return MapBuilder.of(keyConverter.convert(source.getKey()), valueConverter.convert(source.getValue())); + } + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/AbstractHttpClientBuilder.java b/buession-core/src/main/java/com/buession/core/converter/PredicateConverter.java similarity index 70% rename from buession-httpclient/src/main/java/com/buession/httpclient/core/AbstractHttpClientBuilder.java rename to buession-core/src/main/java/com/buession/core/converter/PredicateConverter.java index 294812e3b..2b09264e6 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/core/AbstractHttpClientBuilder.java +++ b/buession-core/src/main/java/com/buession/core/converter/PredicateConverter.java @@ -19,34 +19,38 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.httpclient.core; +package com.buession.core.converter; import com.buession.core.utils.Assert; -import com.buession.httpclient.conn.ConnectionManager; +import com.buession.lang.Status; + +import java.util.function.Predicate; /** - * Http Client Builder 抽象类 + * 通过 {@link Predicate} 比较参数值转换为 {@link Boolean} * - * @param - * 原生 Http Client Builder - * @param - * 连接管理器 - * @param - * 原生 Http Client + * @param + * 谓词的输入类型 * * @author Yong.Teng - * @since 2.3.0 + * @see Predicate + * @since 3.0.0 */ -public abstract class AbstractHttpClientBuilder implements HttpClientBuilder { +public class PredicateConverter implements Converter { + + private final Predicate predicate; - protected final CM connectionManager; + public PredicateConverter(final Predicate predicate) { + Assert.isNull(predicate, "Predicate cloud not be null."); + this.predicate = predicate; + } - public AbstractHttpClientBuilder(final CM connectionManager){ - Assert.isNull(connectionManager, "Connection manager cloud not be null."); - this.connectionManager = connectionManager; + @Override + public Boolean convert(final T source) { + return predicate.test(source); } } diff --git a/buession-core/src/main/java/com/buession/core/converter/SetListConverter.java b/buession-core/src/main/java/com/buession/core/converter/SetListConverter.java new file mode 100644 index 000000000..66b99607f --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/converter/SetListConverter.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core.converter; + +import java.util.ArrayList; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Set => List 转换器 + * + * @param + * 原类型 + * @param + * 目标类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class SetListConverter implements Converter, List> { + + /** + * Set item 转换器 + */ + private final Converter itemConverter; + + /** + * 构造函数 + * + * @param itemConverter + * Set item 转换器 + */ + public SetListConverter(final Converter itemConverter) { + this.itemConverter = itemConverter; + } + + @Override + public List convert(final Set source) { + if(source == null){ + return null; + }else{ + return source.stream().map(itemConverter::convert).collect( + Collectors.toCollection(source instanceof LinkedHashSet ? LinkedList::new : ArrayList::new)); + } + } + +} diff --git a/buession-core/src/main/java/com/buession/core/converter/mapper/PropertyMapper.java b/buession-core/src/main/java/com/buession/core/converter/mapper/PropertyMapper.java index 53707f49e..0fb14acb1 100644 --- a/buession-core/src/main/java/com/buession/core/converter/mapper/PropertyMapper.java +++ b/buession-core/src/main/java/com/buession/core/converter/mapper/PropertyMapper.java @@ -99,6 +99,18 @@ public PropertyMapper alwaysApplyingWhenNonText() { return alwaysApplying(this::whenNonText); } + /** + * Return a new {@link PropertyMapper} instance that applies + * {@link Source#whenPositiveNumber() whenHasText} to every source. + * + * @return a new property mapper instance + * + * @since 3.0.0 + */ + public PropertyMapper alwaysApplyingWhenPositiveNumber() { + return alwaysApplying(this::whenPositiveNumber); + } + /** * Return a new {@link PropertyMapper} instance that applies the given * {@link SourceOperator} to every source. @@ -185,6 +197,10 @@ private Source whenNonText(Source source) { return source.whenNonText(); } + private Source whenPositiveNumber(Source source) { + return source.whenPositiveNumber(); + } + private Source whenTrue(Source source) { return source.whenTrue(); } @@ -422,6 +438,17 @@ public Source whenNonText() { return when((value)->value == null || Validate.isBlank(Objects.toString(value, null))); } + /** + * Return a filtered version of the source that will only map values that have a positive number. + * + * @return a new filtered source instance + * + * @since 3.0.0 + */ + public Source whenPositiveNumber() { + return when((value)->value instanceof Number && ((Number) value).doubleValue() > 0); + } + /** * Return a filtered version of the source that will only map values equal to the specified {@code object}. * diff --git a/buession-core/src/main/java/com/buession/core/datetime/DateTimeUtils.java b/buession-core/src/main/java/com/buession/core/datetime/DateTimeUtils.java new file mode 100644 index 000000000..8ceabc811 --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/datetime/DateTimeUtils.java @@ -0,0 +1,549 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core.datetime; + +import java.sql.Timestamp; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.chrono.ChronoZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.time.temporal.TemporalAccessor; +import java.time.zone.ZoneRules; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.TimeUnit; + +/** + * 日期时间工具类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class DateTimeUtils { + + protected DateTimeUtils() { + + } + + /** + * 从字符串创建 {@link LocalDateTime} 实例 + * + * @param value + * 日期字符串 + * + * @return {@link LocalDateTime} 实例 + */ + public static LocalDateTime localDateTimeOf(final String value) { + return localDateTimeOf(value, ZoneId.systemDefault()); + } + + /** + * 从字符串创建 {@link LocalDateTime} 实例 + * + * @param value + * 日期字符串 + * @param zoneId + * 时区 ID + * + * @return {@link LocalDateTime} 实例 + */ + public static LocalDateTime localDateTimeOf(final String value, final ZoneId zoneId) { + LocalDateTime result = null; + + try{ + result = LocalDateTime.parse(value, DateTimeFormatter.ISO_LOCAL_DATE_TIME); + }catch(Exception e){ + result = null; + } + + if(result == null){ + try{ + result = LocalDateTime.parse(value, DateTimeFormatter.ISO_ZONED_DATE_TIME); + }catch(Exception e){ + result = null; + } + } + + if(result == null){ + try{ + result = LocalDateTime.parse(value); + }catch(Exception e){ + result = null; + } + } + + if(result == null){ + try{ + result = LocalDateTime.parse(value.toUpperCase(), DateTimeFormatter.ofPattern("MM/dd/yyyy hh:mm a")); + }catch(Exception e){ + result = null; + } + } + + if(result == null){ + try{ + result = LocalDateTime.parse(value.toUpperCase(), DateTimeFormatter.ofPattern("MM/dd/yyyy h:mm a")); + }catch(Exception e){ + result = null; + } + } + + if(result == null){ + try{ + result = LocalDateTime.parse(value, DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm")); + }catch(Exception e){ + result = null; + } + } + + LocalDate ld; + if(result == null){ + try{ + ld = LocalDate.parse(value, DateTimeFormatter.ofPattern("MM/dd/yyyy")); + result = LocalDateTime.of(ld, LocalTime.now(zoneId)); + }catch(Exception e){ + result = null; + } + } + + if(result == null){ + try{ + ld = LocalDate.parse(value); + result = LocalDateTime.of(ld, LocalTime.now(zoneId)); + }catch(Exception e){ + result = null; + } + } + + return result; + } + + /** + * 从时间戳创建 {@link LocalDateTime} 实例 + * + * @param timestamp + * 日期字符串 + * + * @return {@link LocalDateTime} 实例 + */ + public static LocalDateTime localDateTimeOf(final long timestamp) { + return localDateTimeOf(timestamp, ZoneId.systemDefault()); + } + + /** + * 从时间戳创建 {@link LocalDateTime} 实例 + * + * @param timestamp + * 日期字符串 + * @param zoneId + * 时区 ID + * + * @return {@link LocalDateTime} 实例 + */ + public static LocalDateTime localDateTimeOf(final long timestamp, final ZoneId zoneId) { + return LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), zoneId); + } + + /** + * 从{@link Date}创建 {@link LocalDateTime} 实例 + * + * @param date + * {@link Date} + * + * @return {@link LocalDateTime} 实例 + */ + public static LocalDateTime localDateTimeOf(final Date date) { + return localDateTimeOf(date.getTime()); + } + + /** + * 从{@link Date}创建 {@link LocalDateTime} 实例 + * + * @param date + * {@link Date} + * @param zoneId + * 时区 ID + * + * @return {@link LocalDateTime} 实例 + */ + public static LocalDateTime localDateTimeOf(final Date date, final ZoneId zoneId) { + return localDateTimeOf(date.getTime(), zoneId); + } + + /** + * 从时间戳创建 {@link LocalDateTime} 实例 + * + * @param timestamp + * 日期字符串 + * + * @return {@link LocalDate} 实例 + */ + public static LocalDate localDateOf(final long timestamp) { + return localDateOf(timestamp, ZoneId.systemDefault()); + } + + /** + * 从时间戳创建 {@link LocalDate} 实例 + * + * @param timestamp + * 日期字符串 + * @param zoneId + * 时区 ID + * + * @return {@link LocalDate} 实例 + */ + public static LocalDate localDateOf(final long timestamp, final ZoneId zoneId) { + Instant instant = Instant.ofEpochMilli(timestamp); + ZoneRules rules = zoneId.getRules(); + ZoneOffset offset = rules.getOffset(instant); + long localSecond = instant.getEpochSecond() + offset.getTotalSeconds(); + long localEpochDay = Math.floorDiv(localSecond, 86400); + return LocalDate.ofEpochDay(localEpochDay); + } + + /** + * 从{@link Date}创建 {@link LocalDate} 实例 + * + * @param date + * {@link Date} + * + * @return {@link LocalDate} 实例 + */ + public static LocalDate localDateOf(final Date date) { + return localDateOf(date.getTime()); + } + + /** + * 从{@link Date}创建 {@link LocalDate} 实例 + * + * @param date + * {@link Date} + * @param zoneId + * 时区 ID + * + * @return {@link LocalDate} 实例 + */ + public static LocalDate localDateOf(final Date date, final ZoneId zoneId) { + return localDateOf(date.getTime(), zoneId); + } + + /** + * 从字符串创建 {@link ZonedDateTime} 实例 + * + * @param value + * 日期时间字符串 + * + * @return {@link ZonedDateTime} 实例 + */ + public static ZonedDateTime zonedDateTimeOf(final String value) { + List parsers = Arrays.asList(DateTimeFormatter.ISO_ZONED_DATE_TIME, + DateTimeFormatter.RFC_1123_DATE_TIME); + return parsers.stream().map((parser)->{ + try{ + return ZonedDateTime.parse(value, parser); + }catch(Exception e){ + return null; + } + }).filter(Objects::nonNull).findFirst().orElse(null); + } + + /** + * 从 {@link TemporalAccessor} 创建 {@link ZonedDateTime} 实例 + * + * @param temporalAccessor + * {@link TemporalAccessor} + * + * @return {@link ZonedDateTime} 实例 + */ + public static ZonedDateTime zonedDateTimeOf(final TemporalAccessor temporalAccessor) { + return ZonedDateTime.from(temporalAccessor); + } + + /** + * 从 {@link Instant} 创建 {@link ZonedDateTime} 实例 + * + * @param instant + * {@link Instant} + * + * @return {@link ZonedDateTime} 实例 + */ + public static ZonedDateTime zonedDateTimeOf(final Instant instant) { + return zonedDateTimeOf(instant, ZoneId.systemDefault()); + } + + /** + * 从 {@link Instant} 创建 {@link ZonedDateTime} 实例 + * + * @param instant + * {@link Instant} + * @param zoneId + * 时区 ID + * + * @return {@link ZonedDateTime} 实例 + */ + public static ZonedDateTime zonedDateTimeOf(final Instant instant, final ZoneId zoneId) { + return instant != null ? instant.atZone(zoneId) : null; + } + + /** + * 从时间戳创建 {@link ZonedDateTime} 实例 + * + * @param timestamp + * 时间戳 + * + * @return {@link ZonedDateTime} 实例 + */ + public static ZonedDateTime zonedDateTimeOf(final long timestamp) { + return zonedDateTimeOf(timestamp, ZoneId.systemDefault()); + } + + /** + * 从时间戳创建 {@link ZonedDateTime} 实例 + * + * @param timestamp + * 时间戳 + * @param zoneId + * 时区 ID + * + * @return {@link ZonedDateTime} 实例 + */ + public static ZonedDateTime zonedDateTimeOf(final long timestamp, final ZoneId zoneId) { + return ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp), zoneId); + } + + /** + * 从 {@link Date} 创建 {@link ZonedDateTime} 实例 + * + * @param date + * {@link Date} + * + * @return {@link ZonedDateTime} 实例 + */ + public static ZonedDateTime zonedDateTimeOf(final Date date) { + return zonedDateTimeOf(date, ZoneId.systemDefault()); + } + + /** + * 从 {@link Date} 创建 {@link ZonedDateTime} 实例 + * + * @param date + * {@link Date} + * @param zoneId + * 时区 ID + * + * @return {@link ZonedDateTime} 实例 + */ + public static ZonedDateTime zonedDateTimeOf(final Date date, final ZoneId zoneId) { + return date != null ? zonedDateTimeOf(Instant.ofEpochMilli(date.getTime()), zoneId) : null; + } + + /** + * 从 {@link Calendar} 创建 {@link ZonedDateTime} 实例 + * + * @param calendar + * {@link Date} + * + * @return {@link ZonedDateTime} 实例 + */ + public static ZonedDateTime zonedDateTimeOf(final Calendar calendar) { + return ZonedDateTime.ofInstant(calendar.toInstant(), calendar.getTimeZone().toZoneId()); + } + + /** + * 从 {@link ChronoZonedDateTime} 创建 {@link Date} 实例 + * + * @param chronoZonedDateTime + * {@link ChronoZonedDateTime} + * + * @return {@link Date} 实例 + */ + public static Date dateOf(final ChronoZonedDateTime chronoZonedDateTime) { + return dateOf(chronoZonedDateTime.toInstant()); + } + + /** + * 从 {@link LocalDate} 创建 {@link Date} 实例 + * + * @param localDate + * {@link LocalDate} + * + * @return {@link Date} 实例 + */ + public static Date dateOf(final LocalDate localDate) { + return dateOf(localDate, ZoneId.systemDefault()); + } + + /** + * 从 {@link LocalDate} 创建 {@link Date} 实例 + * + * @param localDate + * {@link LocalDate} + * @param zoneId + * 时区 ID + * + * @return {@link Date} 实例 + */ + public static Date dateOf(final LocalDate localDate, final ZoneId zoneId) { + return Date.from(localDate.atStartOfDay(zoneId).toInstant()); + } + + /** + * 从 {@link LocalDateTime} 创建 {@link Date} 实例 + * + * @param localDateTime + * {@link LocalDate} + * + * @return {@link Date} 实例 + */ + public static Date dateOf(final LocalDateTime localDateTime) { + return dateOf(localDateTime, ZoneId.systemDefault()); + } + + /** + * 从 {@link LocalDateTime} 创建 {@link Date} 实例 + * + * @param localDateTime + * {@link LocalDate} + * @param zoneId + * 时区 ID + * + * @return {@link Date} 实例 + */ + public static Date dateOf(final LocalDateTime localDateTime, final ZoneId zoneId) { + return dateOf(localDateTime.toInstant(zoneId.getRules().getOffset(localDateTime))); + } + + /** + * 从 {@link Instant} 创建 {@link Date} 实例 + * + * @param instant + * {@link Instant} + * + * @return {@link Date} 实例 + */ + public static Date dateOf(final Instant instant) { + return Date.from(instant); + } + + /** + * 从 {@link ChronoZonedDateTime} 创建 {@link Timestamp} 实例 + * + * @param chronoZonedDateTime + * {@link ChronoZonedDateTime} + * + * @return {@link Timestamp} 实例 + */ + public static Timestamp timestampOf(final ChronoZonedDateTime chronoZonedDateTime) { + return timestampOf(chronoZonedDateTime.toInstant()); + } + + /** + * 从 {@link Instant} 创建 {@link Timestamp} 实例 + * + * @param instant + * {@link Instant} + * + * @return {@link Timestamp} 实例 + */ + public static Timestamp timestampOf(final Instant instant) { + return Timestamp.from(instant); + } + + /** + * {@link ChronoUnit} 转换为 {@link TimeUnit} + * + * @param chronoUnit + * {@link ChronoUnit} + * + * @return {@link TimeUnit} 实例 + */ + public static TimeUnit toTimeUnit(final ChronoUnit chronoUnit) { + if(chronoUnit == null){ + return null; + }else{ + switch(chronoUnit){ + case DAYS: + return TimeUnit.DAYS; + case HOURS: + return TimeUnit.HOURS; + case MINUTES: + return TimeUnit.MINUTES; + case SECONDS: + return TimeUnit.SECONDS; + case MICROS: + return TimeUnit.MICROSECONDS; + case MILLIS: + return TimeUnit.MILLISECONDS; + case NANOS: + return TimeUnit.NANOSECONDS; + default: + throw new UnsupportedOperationException("Temporal unit is not supported"); + } + } + } + + /** + * {@link TimeUnit} 转换为 {@link ChronoUnit} + * + * @param timeUnit + * {@link TimeUnit} + * + * @return {@link ChronoUnit} 实例 + */ + public static ChronoUnit toChronoUnit(final TimeUnit timeUnit) { + if(timeUnit == null){ + return null; + }else{ + switch(timeUnit){ + case DAYS: + return ChronoUnit.DAYS; + case HOURS: + return ChronoUnit.HOURS; + case MINUTES: + return ChronoUnit.MINUTES; + case MICROSECONDS: + return ChronoUnit.MICROS; + case MILLISECONDS: + return ChronoUnit.MILLIS; + case NANOSECONDS: + return ChronoUnit.NANOS; + case SECONDS: + return ChronoUnit.SECONDS; + default: + return ChronoUnit.SECONDS; + } + } + } + +} diff --git a/buession-core/src/main/java/com/buession/core/deserializer/AbstractJsonDeserializer.java b/buession-core/src/main/java/com/buession/core/deserializer/AbstractJsonDeserializer.java index ad4179821..7766e20b4 100644 --- a/buession-core/src/main/java/com/buession/core/deserializer/AbstractJsonDeserializer.java +++ b/buession-core/src/main/java/com/buession/core/deserializer/AbstractJsonDeserializer.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.deserializer; @@ -29,11 +29,13 @@ /** * JSON 反序列化抽象类 * + * @param + * JSON 反序列化原生类型 + * * @author Yong.Teng * @since 2.3.0 */ -@Deprecated -public abstract class AbstractJsonDeserializer extends AbstractDeserializer implements JsonDeserializer { +public abstract class AbstractJsonDeserializer extends AbstractDeserializer implements JsonDeserializer { @Override public V deserialize(final String str, final String charsetName) throws DeserializerException { diff --git a/buession-core/src/main/java/com/buession/core/deserializer/FastJsonJsonDeserializer.java b/buession-core/src/main/java/com/buession/core/deserializer/FastJsonJsonDeserializer.java index 276029c35..1540ac2e3 100644 --- a/buession-core/src/main/java/com/buession/core/deserializer/FastJsonJsonDeserializer.java +++ b/buession-core/src/main/java/com/buession/core/deserializer/FastJsonJsonDeserializer.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.deserializer; @@ -34,8 +34,7 @@ * @author Yong.Teng * @since 2.3.0 */ -@Deprecated -public class FastJsonJsonDeserializer extends AbstractJsonDeserializer { +public class FastJsonJsonDeserializer extends AbstractJsonDeserializer { @Override public V deserialize(final String str) throws DeserializerException { diff --git a/buession-core/src/main/java/com/buession/core/deserializer/GsonJsonDeserializer.java b/buession-core/src/main/java/com/buession/core/deserializer/GsonJsonDeserializer.java index 0aa72980d..6ea83418e 100644 --- a/buession-core/src/main/java/com/buession/core/deserializer/GsonJsonDeserializer.java +++ b/buession-core/src/main/java/com/buession/core/deserializer/GsonJsonDeserializer.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.deserializer; @@ -34,12 +34,16 @@ * @author Yong.Teng * @since 2.3.0 */ -@Deprecated -public class GsonJsonDeserializer extends AbstractJsonDeserializer { +public class GsonJsonDeserializer extends AbstractJsonDeserializer { + + private final Gson gson = new Gson(); + + public GsonJsonDeserializer() { + configure(gson); + } @Override public V deserialize(final String str) throws DeserializerException { - Gson gson = new Gson(); return gson.fromJson(str, new TypeReference() { }.getType()); @@ -49,7 +53,6 @@ public V deserialize(final String str) throws DeserializerException { public V deserialize(final String str, final Class clazz) throws DeserializerException { Assert.isNull(str, "String cloud not be null."); - Gson gson = new Gson(); return gson.fromJson(str, clazz); } @@ -57,7 +60,6 @@ public V deserialize(final String str, final Class clazz) throws Deserial public V deserialize(String str, TypeReference type) throws DeserializerException { Assert.isNull(str, "String cloud not be null."); - Gson gson = new Gson(); return gson.fromJson(str, type.getType()); } diff --git a/buession-core/src/main/java/com/buession/core/deserializer/JacksonJsonDeserializer.java b/buession-core/src/main/java/com/buession/core/deserializer/JacksonJsonDeserializer.java index 11a476b84..7f69940e1 100644 --- a/buession-core/src/main/java/com/buession/core/deserializer/JacksonJsonDeserializer.java +++ b/buession-core/src/main/java/com/buession/core/deserializer/JacksonJsonDeserializer.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.deserializer; @@ -40,15 +40,26 @@ * @author Yong.Teng * @since 2.3.0 */ -@Deprecated -public class JacksonJsonDeserializer extends AbstractJsonDeserializer { +public class JacksonJsonDeserializer extends AbstractJsonDeserializer { + + private final ObjectMapper objectMapper = new ObjectMapper(); + + public JacksonJsonDeserializer() { + configure(objectMapper); + } + + @Override + public void configure(ObjectMapper object) { + objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + } @Override public V deserialize(final String str) throws DeserializerException { Assert.isNull(str, "String cloud not be null."); try{ - return getObjectMapper().readValue(str, new com.fasterxml.jackson.core.type.TypeReference() { + return objectMapper.readValue(str, new com.fasterxml.jackson.core.type.TypeReference() { }); }catch(IOException e){ @@ -61,7 +72,7 @@ public V deserialize(final String str, final Class clazz) throws Deserial Assert.isNull(str, "String cloud not be null."); try{ - return getObjectMapper().readValue(str, clazz); + return objectMapper.readValue(str, clazz); }catch(IOException e){ final String className = clazz == null ? "null" : clazz.getName(); throw new DeserializerException(str + " json deserialize to " + className + " failure.", e); @@ -73,7 +84,7 @@ public V deserialize(final String str, final TypeReference type) throws D Assert.isNull(str, "String cloud not be null."); try{ - return getObjectMapper().readValue(str, new com.fasterxml.jackson.core.type.TypeReference() { + return objectMapper.readValue(str, new com.fasterxml.jackson.core.type.TypeReference() { @Override public Type getType() { @@ -92,7 +103,7 @@ public V deserialize(final byte[] bytes) throws DeserializerException { Assert.isNull(bytes, "Bytes cloud not be null."); try{ - return getObjectMapper().readValue(bytes, new com.fasterxml.jackson.core.type.TypeReference() { + return objectMapper.readValue(bytes, new com.fasterxml.jackson.core.type.TypeReference() { }); }catch(IOException e){ @@ -105,7 +116,7 @@ public V deserialize(final byte[] bytes, final Class clazz) throws Deseri Assert.isNull(bytes, "Bytes cloud not be null."); try{ - return getObjectMapper().readValue(bytes, clazz); + return objectMapper.readValue(bytes, clazz); }catch(IOException e){ final String className = clazz == null ? "null" : clazz.getName(); throw new DeserializerException(Arrays.toString(bytes) + " json deserialize to " + className + " failure.", @@ -118,7 +129,7 @@ public V deserialize(final byte[] bytes, final TypeReference type) throws Assert.isNull(bytes, "Bytes cloud not be null."); try{ - return getObjectMapper().readValue(bytes, new com.fasterxml.jackson.core.type.TypeReference() { + return objectMapper.readValue(bytes, new com.fasterxml.jackson.core.type.TypeReference() { @Override public Type getType() { @@ -133,13 +144,4 @@ public Type getType() { } } - protected static ObjectMapper getObjectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); - - objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS) - .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - - return objectMapper; - } - } diff --git a/buession-core/src/main/java/com/buession/core/deserializer/JsonDeserializer.java b/buession-core/src/main/java/com/buession/core/deserializer/JsonDeserializer.java index 688cae392..6ce1875a2 100644 --- a/buession-core/src/main/java/com/buession/core/deserializer/JsonDeserializer.java +++ b/buession-core/src/main/java/com/buession/core/deserializer/JsonDeserializer.java @@ -19,21 +19,52 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.deserializer; +import com.buession.core.Customizer; import com.buession.core.type.TypeReference; /** * JSON 反序列化 * + * @param + * JSON 序列化原生类型 + * * @author Yong.Teng * @since 2.3.0 */ -@Deprecated -public interface JsonDeserializer extends Deserializer { +public interface JsonDeserializer extends Deserializer { + + /** + * 反序列化配置 + * + * @param object + * JSON 原生对象 + * + * @since 3.0.0 + */ + default void configure(T object) { + + } + + /** + * 反序列化配置 + * + * @param object + * JSON 原生对象 + * @param customizer + * 配置定制 + * + * @since 3.0.0 + */ + default void configure(T object, Customizer customizer) { + if(customizer != null){ + customizer.customize(object); + } + } /** * 字符串反序列化 diff --git a/buession-core/src/main/java/com/buession/core/serializer/AbstractJsonSerializer.java b/buession-core/src/main/java/com/buession/core/serializer/AbstractJsonSerializer.java index d49b6d807..3e89f6b0d 100644 --- a/buession-core/src/main/java/com/buession/core/serializer/AbstractJsonSerializer.java +++ b/buession-core/src/main/java/com/buession/core/serializer/AbstractJsonSerializer.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.serializer; @@ -29,10 +29,12 @@ /** * JSON 序列化抽象类 * + * @param + * JSON 序列化原生类型 + * * @author Yong.Teng */ -@Deprecated -public abstract class AbstractJsonSerializer extends AbstractSerializer implements JsonSerializer { +public abstract class AbstractJsonSerializer extends AbstractSerializer implements JsonSerializer { @Override public String serialize(final V object, final String charsetName) throws SerializerException { @@ -54,28 +56,4 @@ public byte[] serializeAsBytes(final V object, final Charset charset) throws return serializeAsBytes(object); } - @Deprecated - @Override - public V deserialize(final String str, final String charsetName) throws SerializerException { - return deserialize(str); - } - - @Deprecated - @Override - public V deserialize(final String str, final Charset charset) throws SerializerException { - return deserialize(str); - } - - @Deprecated - @Override - public V deserialize(final byte[] bytes, final String charsetName) throws SerializerException { - return deserialize(bytes); - } - - @Deprecated - @Override - public V deserialize(final byte[] bytes, final Charset charset) throws SerializerException { - return deserialize(bytes); - } - } diff --git a/buession-core/src/main/java/com/buession/core/serializer/DefaultByteArraySerializer.java b/buession-core/src/main/java/com/buession/core/serializer/DefaultByteArraySerializer.java index 9f47f156a..19ad9f4f6 100644 --- a/buession-core/src/main/java/com/buession/core/serializer/DefaultByteArraySerializer.java +++ b/buession-core/src/main/java/com/buession/core/serializer/DefaultByteArraySerializer.java @@ -19,13 +19,11 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.serializer; -import com.buession.core.deserializer.DefaultByteArrayDeserializer; -import com.buession.core.deserializer.DeserializerException; import com.buession.core.utils.Assert; import java.io.ByteArrayOutputStream; @@ -46,7 +44,7 @@ public class DefaultByteArraySerializer extends AbstractByteArraySerializer { private final static int BYTE_ARRAY_OUTPUT_STREAM_SIZE = 128; @Override - public String serialize(final V object, final String charsetName) throws SerializerException{ + public String serialize(final V object, final String charsetName) throws SerializerException { try{ return URLEncoder.encode(baosWrite(object), charsetName); }catch(IOException e){ @@ -56,12 +54,12 @@ public String serialize(final V object, final String charsetName) throws Ser } @Override - public String serialize(final V object, final Charset charset) throws SerializerException{ + public String serialize(final V object, final Charset charset) throws SerializerException { return serialize(object, charset.name()); } @Override - public byte[] serializeAsBytes(final V object, final String charsetName) throws SerializerException{ + public byte[] serializeAsBytes(final V object, final String charsetName) throws SerializerException { Assert.isNull(object, "Object cloud not be null."); if((object instanceof Serializable) == false){ @@ -89,55 +87,11 @@ public byte[] serializeAsBytes(final V object, final String charsetName) thr } @Override - public byte[] serializeAsBytes(final V object, final Charset charset) throws SerializerException{ + public byte[] serializeAsBytes(final V object, final Charset charset) throws SerializerException { return serializeAsBytes(object, charset.name()); } - @Deprecated - @Override - public V deserialize(final String str, final String charsetName) throws SerializerException{ - DefaultByteArrayDeserializer deserializer = new DefaultByteArrayDeserializer(); - try{ - return deserializer.deserialize(str, charsetName); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Deprecated - @Override - public V deserialize(final String str, final Charset charset) throws SerializerException{ - DefaultByteArrayDeserializer deserializer = new DefaultByteArrayDeserializer(); - try{ - return deserializer.deserialize(str, charset); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Deprecated - @Override - public V deserialize(final byte[] bytes, final String charsetName) throws SerializerException{ - DefaultByteArrayDeserializer deserializer = new DefaultByteArrayDeserializer(); - try{ - return deserializer.deserialize(bytes, charsetName); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Deprecated - @Override - public V deserialize(final byte[] bytes, final Charset charset) throws SerializerException{ - DefaultByteArrayDeserializer deserializer = new DefaultByteArrayDeserializer(); - try{ - return deserializer.deserialize(bytes, charset); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - protected static String baosWrite(final V value) throws IOException{ + protected static String baosWrite(final V value) throws IOException { Assert.isNull(value, "Object cloud not be null."); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); diff --git a/buession-core/src/main/java/com/buession/core/serializer/FastJsonJsonSerializer.java b/buession-core/src/main/java/com/buession/core/serializer/FastJsonJsonSerializer.java index 7c9884028..c3e40d4bf 100644 --- a/buession-core/src/main/java/com/buession/core/serializer/FastJsonJsonSerializer.java +++ b/buession-core/src/main/java/com/buession/core/serializer/FastJsonJsonSerializer.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.serializer; @@ -27,9 +27,6 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.serializer.SerializeConfig; import com.alibaba.fastjson.serializer.SerializeFilter; -import com.buession.core.deserializer.DeserializerException; -import com.buession.core.deserializer.FastJsonJsonDeserializer; -import com.buession.core.type.TypeReference; import com.buession.core.utils.Assert; import java.nio.charset.Charset; @@ -39,8 +36,7 @@ * * @author Yong.Teng */ -@Deprecated -public class FastJsonJsonSerializer extends AbstractJsonSerializer { +public class FastJsonJsonSerializer extends AbstractJsonSerializer { @Override public String serialize(final V object) throws SerializerException { @@ -66,70 +62,4 @@ public byte[] serializeAsBytes(final V object, final Charset charset) throws .DEFAULT_GENERATE_FEATURE); } - @Deprecated - @Override - public V deserialize(final String str) throws SerializerException { - FastJsonJsonDeserializer deserializer = new FastJsonJsonDeserializer(); - try{ - return deserializer.deserialize(str); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Deprecated - @Override - public V deserialize(final String str, final Class clazz) throws SerializerException { - FastJsonJsonDeserializer deserializer = new FastJsonJsonDeserializer(); - try{ - return deserializer.deserialize(str, clazz); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Deprecated - @Override - public V deserialize(final String str, final TypeReference type) throws SerializerException { - FastJsonJsonDeserializer deserializer = new FastJsonJsonDeserializer(); - try{ - return deserializer.deserialize(str, type); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Deprecated - @Override - public V deserialize(final byte[] bytes) throws SerializerException { - FastJsonJsonDeserializer deserializer = new FastJsonJsonDeserializer(); - try{ - return deserializer.deserialize(bytes); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Deprecated - @Override - public V deserialize(byte[] bytes, Class clazz) throws SerializerException { - FastJsonJsonDeserializer deserializer = new FastJsonJsonDeserializer(); - try{ - return deserializer.deserialize(bytes, clazz); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Deprecated - @Override - public V deserialize(final byte[] bytes, final TypeReference type) throws SerializerException { - FastJsonJsonDeserializer deserializer = new FastJsonJsonDeserializer(); - try{ - return deserializer.deserialize(bytes, type); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - } diff --git a/buession-core/src/main/java/com/buession/core/serializer/GsonJsonSerializer.java b/buession-core/src/main/java/com/buession/core/serializer/GsonJsonSerializer.java index b74495673..4f83be60a 100644 --- a/buession-core/src/main/java/com/buession/core/serializer/GsonJsonSerializer.java +++ b/buession-core/src/main/java/com/buession/core/serializer/GsonJsonSerializer.java @@ -19,14 +19,11 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.serializer; -import com.buession.core.deserializer.DeserializerException; -import com.buession.core.deserializer.GsonJsonDeserializer; -import com.buession.core.type.TypeReference; import com.buession.core.utils.Assert; import com.google.gson.Gson; @@ -37,14 +34,18 @@ * * @author Yong.Teng */ -@Deprecated -public class GsonJsonSerializer extends AbstractJsonSerializer { +public class GsonJsonSerializer extends AbstractJsonSerializer { + + private final Gson gson = new Gson(); + + public GsonJsonSerializer() { + configure(gson); + } @Override public String serialize(final V object) throws SerializerException { Assert.isNull(object, "Object cloud not be null."); - Gson gson = new Gson(); return gson.toJson(object); } @@ -58,70 +59,4 @@ public byte[] serializeAsBytes(final V object, final Charset charset) throws return serialize(object).getBytes(charset); } - @Deprecated - @Override - public V deserialize(final String str) throws SerializerException { - GsonJsonDeserializer deserializer = new GsonJsonDeserializer(); - try{ - return deserializer.deserialize(str); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Deprecated - @Override - public V deserialize(final String str, final Class clazz) throws SerializerException { - GsonJsonDeserializer deserializer = new GsonJsonDeserializer(); - try{ - return deserializer.deserialize(str, clazz); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Deprecated - @Override - public V deserialize(String str, TypeReference type) throws SerializerException { - GsonJsonDeserializer deserializer = new GsonJsonDeserializer(); - try{ - return deserializer.deserialize(str, type); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Deprecated - @Override - public V deserialize(final byte[] bytes) throws SerializerException { - GsonJsonDeserializer deserializer = new GsonJsonDeserializer(); - try{ - return deserializer.deserialize(bytes); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Deprecated - @Override - public V deserialize(byte[] bytes, Class clazz) throws SerializerException { - GsonJsonDeserializer deserializer = new GsonJsonDeserializer(); - try{ - return deserializer.deserialize(bytes, clazz); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Deprecated - @Override - public V deserialize(byte[] bytes, TypeReference type) throws SerializerException { - GsonJsonDeserializer deserializer = new GsonJsonDeserializer(); - try{ - return deserializer.deserialize(bytes, type); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - } diff --git a/buession-core/src/main/java/com/buession/core/serializer/JacksonJsonSerializer.java b/buession-core/src/main/java/com/buession/core/serializer/JacksonJsonSerializer.java index e626957ac..0fd2911e9 100644 --- a/buession-core/src/main/java/com/buession/core/serializer/JacksonJsonSerializer.java +++ b/buession-core/src/main/java/com/buession/core/serializer/JacksonJsonSerializer.java @@ -19,14 +19,11 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.serializer; -import com.buession.core.deserializer.DeserializerException; -import com.buession.core.deserializer.JacksonJsonDeserializer; -import com.buession.core.type.TypeReference; import com.buession.core.utils.Assert; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -37,15 +34,25 @@ * * @author Yong.Teng */ -@Deprecated -public class JacksonJsonSerializer extends AbstractJsonSerializer { +public class JacksonJsonSerializer extends AbstractJsonSerializer { + + private final ObjectMapper objectMapper = new ObjectMapper(); + + public JacksonJsonSerializer() { + configure(objectMapper); + } + + @Override + public void configure(ObjectMapper objectMapper) { + objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); + } @Override public String serialize(final V object) throws SerializerException { Assert.isNull(object, "Object cloud not be null."); try{ - return getObjectMapper().writeValueAsString(object); + return objectMapper.writeValueAsString(object); }catch(JsonProcessingException e){ throw new SerializerException(object.getClass().getName() + " json serialize failure.", e); } @@ -56,78 +63,10 @@ public byte[] serializeAsBytes(final V object) throws SerializerException { Assert.isNull(object, "Object cloud not be null."); try{ - return getObjectMapper().writeValueAsBytes(object); + return objectMapper.writeValueAsBytes(object); }catch(JsonProcessingException e){ throw new SerializerException(object.getClass().getName() + " json serialize failure.", e); } } - @Override - public V deserialize(final String str) throws SerializerException { - JacksonJsonDeserializer deserializer = new JacksonJsonDeserializer(); - try{ - return deserializer.deserialize(str); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Override - public V deserialize(final String str, final Class clazz) throws SerializerException { - JacksonJsonDeserializer deserializer = new JacksonJsonDeserializer(); - try{ - return deserializer.deserialize(str, clazz); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Override - public V deserialize(final String str, final TypeReference type) throws SerializerException { - JacksonJsonDeserializer deserializer = new JacksonJsonDeserializer(); - try{ - return deserializer.deserialize(str, type); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Override - public V deserialize(final byte[] bytes) throws SerializerException { - JacksonJsonDeserializer deserializer = new JacksonJsonDeserializer(); - try{ - return deserializer.deserialize(bytes); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Override - public V deserialize(final byte[] bytes, final Class clazz) throws SerializerException { - JacksonJsonDeserializer deserializer = new JacksonJsonDeserializer(); - try{ - return deserializer.deserialize(bytes, clazz); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - @Override - public V deserialize(final byte[] bytes, final TypeReference type) throws SerializerException { - JacksonJsonDeserializer deserializer = new JacksonJsonDeserializer(); - try{ - return deserializer.deserialize(bytes, type); - }catch(DeserializerException e){ - throw new SerializerException(e.getMessage(), e); - } - } - - protected static ObjectMapper getObjectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); - - objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); - - return objectMapper; - } - } diff --git a/buession-core/src/main/java/com/buession/core/serializer/JsonSerializer.java b/buession-core/src/main/java/com/buession/core/serializer/JsonSerializer.java index 38cc8a38e..53aa27384 100644 --- a/buession-core/src/main/java/com/buession/core/serializer/JsonSerializer.java +++ b/buession-core/src/main/java/com/buession/core/serializer/JsonSerializer.java @@ -19,171 +19,49 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.serializer; -import com.buession.core.type.TypeReference; +import com.buession.core.Customizer; /** * JSON 序列化 * + * @param + * JSON 序列化原生类型 + * * @author Yong.Teng */ -@Deprecated -public interface JsonSerializer extends Serializer { - - /** - * 字符串反序列化 - * - * @param str - * 待反序列化字符串 - * @param clazz - * 待反序列化对象类 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后对象 - * - * @throws SerializerException - * 反序列化异常 - */ - @Deprecated - V deserialize(final String str, final Class clazz) throws SerializerException; - - /** - * 字符串反序列化 - * - * @param str - * 待反序列化字符串 - * @param type - * 待反序列化对象类引用 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后对象 - * - * @throws SerializerException - * 反序列化异常 - */ - @Deprecated - V deserialize(final String str, final TypeReference type) throws SerializerException; - - /** - * 字节反序列化 - * - * @param bytes - * 待反序列化的字节 - * @param clazz - * 待反序列化对象类 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后的对象 - * - * @throws SerializerException - * 反序列化异常 - */ - @Deprecated - V deserialize(final byte[] bytes, final Class clazz) throws SerializerException; - - /** - * 字节反序列化 - * - * @param bytes - * 待反序列化的字节 - * @param type - * 待反序列化对象类引用 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后的对象 - * - * @throws SerializerException - * 反序列化异常 - */ - @Deprecated - V deserialize(final byte[] bytes, final TypeReference type) throws SerializerException; - - /** - * 字符串反序列化 - * - * @param str - * 待反序列化字符串 - * @param clazz - * 待反序列化对象类 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后对象 - * - * @throws SerializerException - * 反序列化异常 - */ - @Deprecated - default V unserialize(final String str, final Class clazz) throws SerializerException { - return deserialize(str, clazz); - } +public interface JsonSerializer extends Serializer { /** - * 字符串反序列化 - * - * @param str - * 待反序列化字符串 - * @param type - * 待反序列化对象类引用 - * @param - * 待反序列化对象类型 + * 序列化配置 * - * @return 反序列化后对象 + * @param object + * JSON 原生对象 * - * @throws SerializerException - * 反序列化异常 + * @since 3.0.0 */ - @Deprecated - default V unserialize(final String str, final TypeReference type) throws SerializerException { - return deserialize(str, type); - } + default void configure(T object) { - /** - * 字节反序列化 - * - * @param bytes - * 待反序列化的字节 - * @param clazz - * 待反序列化对象类 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后的对象 - * - * @throws SerializerException - * 反序列化异常 - */ - @Deprecated - default V unserialize(final byte[] bytes, final Class clazz) throws SerializerException { - return deserialize(bytes, clazz); } /** - * 字节反序列化 - * - * @param bytes - * 待反序列化的字节 - * @param type - * 待反序列化对象类引用 - * @param - * 待反序列化对象类型 + * 序列化配置 * - * @return 反序列化后的对象 + * @param object + * JSON 原生对象 + * @param customizer + * 配置定制 * - * @throws SerializerException - * 反序列化异常 + * @since 3.0.0 */ - @Deprecated - default V unserialize(final byte[] bytes, final TypeReference type) throws SerializerException { - return deserialize(bytes, type); + default void configure(T object, Customizer customizer) { + if(customizer != null){ + customizer.customize(object); + } } } diff --git a/buession-core/src/main/java/com/buession/core/serializer/Serializer.java b/buession-core/src/main/java/com/buession/core/serializer/Serializer.java index 6e21eb085..0bdb52b46 100644 --- a/buession-core/src/main/java/com/buession/core/serializer/Serializer.java +++ b/buession-core/src/main/java/com/buession/core/serializer/Serializer.java @@ -19,13 +19,11 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.serializer; -import com.buession.core.deserializer.Deserializer; - import java.nio.charset.Charset; /** @@ -133,240 +131,4 @@ public interface Serializer { */ byte[] serializeAsBytes(final V object, final Charset charset) throws SerializerException; - /** - * 字符串反序列化 - * - * @param str - * 待反序列化字符串 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后对象 - * - * @throws SerializerException - * 反序列化异常 - * @see Deserializer - */ - @Deprecated - default V deserialize(final String str) throws SerializerException{ - return deserialize(str, Charset.defaultCharset()); - } - - /** - * 字符串反序列化 - * - * @param str - * 待反序列化字符串 - * @param charsetName - * 字符集 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后对象 - * - * @throws SerializerException - * 反序列化异常 - * @see Deserializer - */ - @Deprecated - V deserialize(final String str, final String charsetName) throws SerializerException; - - /** - * 字符串反序列化 - * - * @param str - * 待反序列化字符串 - * @param charset - * 字符集 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后对象 - * - * @throws SerializerException - * 反序列化异常 - * @see Deserializer - */ - @Deprecated - V deserialize(final String str, final Charset charset) throws SerializerException; - - /** - * 字节反序列化 - * - * @param bytes - * 待反序列化的字节 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后的对象 - * - * @throws SerializerException - * 反序列化异常 - * @see Deserializer - */ - @Deprecated - default V deserialize(final byte[] bytes) throws SerializerException{ - return deserialize(bytes, Charset.defaultCharset().name()); - } - - /** - * 字节反序列化 - * - * @param bytes - * 待反序列化的字节 - * @param charsetName - * 字符集 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后的对象 - * - * @throws SerializerException - * 反序列化异常 - * @see Deserializer - */ - @Deprecated - V deserialize(final byte[] bytes, final String charsetName) throws SerializerException; - - /** - * 字节反序列化 - * - * @param bytes - * 待反序列化的字节 - * @param charset - * 字符集 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后的对象 - * - * @throws SerializerException - * 反序列化异常 - * @see Deserializer - */ - @Deprecated - V deserialize(final byte[] bytes, final Charset charset) throws SerializerException; - - /** - * 字符串反序列化 - * - * @param str - * 待反序列化字符串 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后对象 - * - * @throws SerializerException - * 反序列化异常 - * @see Deserializer - */ - @Deprecated - default V unserialize(final String str) throws SerializerException{ - return deserialize(str); - } - - /** - * 字符串反序列化 - * - * @param str - * 待反序列化字符串 - * @param charsetName - * 字符集 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后对象 - * - * @throws SerializerException - * 反序列化异常 - * @see Deserializer - */ - @Deprecated - default V unserialize(final String str, final String charsetName) throws SerializerException{ - return deserialize(str, charsetName); - } - - /** - * 字符串反序列化 - * - * @param str - * 待反序列化字符串 - * @param charset - * 字符集 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后对象 - * - * @throws SerializerException - * 反序列化异常 - * @see Deserializer - */ - @Deprecated - default V unserialize(final String str, final Charset charset) throws SerializerException{ - return deserialize(str, charset); - } - - /** - * 字节反序列化 - * - * @param bytes - * 待反序列化的字节 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后的对象 - * - * @throws SerializerException - * 反序列化异常 - * @see Deserializer - */ - @Deprecated - default V unserialize(final byte[] bytes) throws SerializerException{ - return deserialize(bytes); - } - - /** - * 字节反序列化 - * - * @param bytes - * 待反序列化的字节 - * @param charsetName - * 字符集 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后对象 - * - * @throws SerializerException - * 反序列化异常 - * @see Deserializer - */ - @Deprecated - default V unserialize(final byte[] bytes, final String charsetName) throws SerializerException{ - return deserialize(bytes, charsetName); - } - - /** - * 字节反序列化 - * - * @param bytes - * 待反序列化的字节 - * @param charset - * 字符集 - * @param - * 待反序列化对象类型 - * - * @return 反序列化后对象 - * - * @throws SerializerException - * 反序列化异常 - * @see Deserializer - */ - @Deprecated - default V unserialize(final byte[] bytes, final Charset charset) throws SerializerException{ - return deserialize(bytes, charset); - } - } diff --git a/buession-core/src/main/java/com/buession/core/utils/ArrayUtils.java b/buession-core/src/main/java/com/buession/core/utils/ArrayUtils.java deleted file mode 100644 index f14079cdd..000000000 --- a/buession-core/src/main/java/com/buession/core/utils/ArrayUtils.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - * ================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | - * +------------------------------------------------------------------------------------------------+ - */ -package com.buession.core.utils; - -import com.buession.core.collect.Arrays; - -/** - * 数组工具类 - * - * @author Yong.Teng - */ -@Deprecated -public class ArrayUtils extends Arrays { - -} \ No newline at end of file diff --git a/buession-core/src/main/java/com/buession/core/utils/ClassUtils.java b/buession-core/src/main/java/com/buession/core/utils/ClassUtils.java index eeec43037..100f7cf92 100644 --- a/buession-core/src/main/java/com/buession/core/utils/ClassUtils.java +++ b/buession-core/src/main/java/com/buession/core/utils/ClassUtils.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.core.utils; @@ -59,6 +59,98 @@ */ public class ClassUtils extends org.apache.commons.lang3.ClassUtils { + /** + * 获取默认类加载器 + * + * @return 默认类加载器 + * + * @since 3.0.0 + */ + public static ClassLoader getDefaultClassLoader() { + ClassLoader classLoader = null; + try{ + classLoader = Thread.currentThread().getContextClassLoader(); + }catch(Throwable ex){ + // Cannot access thread context ClassLoader - falling back... + } + + if(classLoader == null){ + // No thread context class loader -> use class loader of this class. + classLoader = ClassUtils.class.getClassLoader(); + if(classLoader == null){ + // getClassLoader() returning null indicates the bootstrap ClassLoader + try{ + classLoader = ClassLoader.getSystemClassLoader(); + }catch(Throwable ex){ + // Cannot access system ClassLoader - oh well, maybe the caller can live with null... + } + } + } + + return classLoader; + } + + /** + * 判断类是否存在 + * + * @param className + * 类名 + * + * @return true / false + * + * @since 3.0.0 + */ + public static boolean isPresent(String className) { + try{ + getClass(getDefaultClassLoader(), className, false); + return true; + }catch(IllegalAccessError error){ + throw new IllegalStateException("Readability mismatch in inheritance hierarchy of class [" + + className + "]: " + error.getMessage(), error); + }catch(Throwable e){ + return false; + } + } + + /** + * 判断类是否存在 + * + * @param className + * 类名 + * @param classLoader + * 类加载器 + * + * @return true / false + * + * @since 3.0.0 + */ + public static boolean isPresent(String className, @Nullable ClassLoader classLoader) { + try{ + getClass(classLoader, className, false); + return true; + }catch(IllegalAccessError error){ + throw new IllegalStateException("Readability mismatch in inheritance hierarchy of class [" + + className + "]: " + error.getMessage(), error); + }catch(Throwable e){ + return false; + } + } + + /** + * 类初始化 + * + * @param clazz + * 类 + * @param args + * 构造函数参数 + * @param + * 实例类型 + * + * @return 类实例 + * + * @throws ClassInstantiationException + * 类初始化异常 + */ public static T instantiate(Class clazz, Object... args) throws ClassInstantiationException { Assert.isNull(clazz, "Class cloud not be null"); Assert.isTrue(clazz.isInterface(), diff --git a/buession-core/src/main/java/com/buession/core/utils/MapUtils.java b/buession-core/src/main/java/com/buession/core/utils/MapUtils.java deleted file mode 100644 index b82236d46..000000000 --- a/buession-core/src/main/java/com/buession/core/utils/MapUtils.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - * ================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | - * +------------------------------------------------------------------------------------------------+ - */ -package com.buession.core.utils; - -import com.buession.core.collect.Maps; - -/** - * Map 工具类 - * More {@link org.apache.commons.collections4.MapUtils} - * - * @author Yong.Teng - */ -@Deprecated -public class MapUtils extends Maps { - -} diff --git a/buession-core/src/main/java/com/buession/core/utils/NumberUtils.java b/buession-core/src/main/java/com/buession/core/utils/NumberUtils.java index 23dfb44c9..f71f925da 100644 --- a/buession-core/src/main/java/com/buession/core/utils/NumberUtils.java +++ b/buession-core/src/main/java/com/buession/core/utils/NumberUtils.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.utils; @@ -39,7 +39,7 @@ public class NumberUtils { * * @return byte[] 值 */ - public static byte[] int2bytes(final int value){ + public static byte[] int2bytes(final int value) { byte[] result = new byte[4]; for(int i = 0; i < 4; ++i){ @@ -58,7 +58,7 @@ public static byte[] int2bytes(final int value){ * * @return int 值 */ - public static int bytes2int(final byte[] value){ + public static int bytes2int(final byte[] value) { int result = 0; for(int i = 0; i < 4; ++i){ @@ -77,7 +77,7 @@ public static int bytes2int(final byte[] value){ * * @return byte[] 值 */ - public static byte[] long2bytes(final long value){ + public static byte[] long2bytes(final long value) { byte[] result = new byte[8]; for(int i = 0; i < 8; ++i){ @@ -96,7 +96,7 @@ public static byte[] long2bytes(final long value){ * * @return long 值 */ - public static long bytes2long(final byte[] value){ + public static long bytes2long(final byte[] value) { long result = 0; for(int i = 0; i < 8; ++i){ @@ -115,7 +115,7 @@ public static long bytes2long(final byte[] value){ * * @return byte[] 值 */ - public static byte[] float2bytes(final float value){ + public static byte[] float2bytes(final float value) { return int2bytes(Float.floatToIntBits(value)); } @@ -127,7 +127,7 @@ public static byte[] float2bytes(final float value){ * * @return float 值 */ - public static double bytes2float(final byte[] value){ + public static double bytes2float(final byte[] value) { return (float) bytes2int(value); } @@ -139,7 +139,7 @@ public static double bytes2float(final byte[] value){ * * @return byte[] 值 */ - public static byte[] double2bytes(final double value){ + public static byte[] double2bytes(final double value) { return long2bytes(Double.doubleToLongBits(value)); } @@ -151,7 +151,7 @@ public static byte[] double2bytes(final double value){ * * @return double 值 */ - public static double bytes2double(final byte[] value){ + public static double bytes2double(final byte[] value) { return (double) bytes2long(value); } diff --git a/buession-core/src/main/java/com/buession/core/utils/StatusUtils.java b/buession-core/src/main/java/com/buession/core/utils/StatusUtils.java deleted file mode 100644 index b546e322e..000000000 --- a/buession-core/src/main/java/com/buession/core/utils/StatusUtils.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - * ================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2024 Buession.com Inc. | - * +------------------------------------------------------------------------------------------------+ - */ -package com.buession.core.utils; - -import com.buession.lang.Status; - -/** - * {@link Status} 工具类 - * - * @author Yong.Teng - */ -@Deprecated -public class StatusUtils { - - /** - * {@link Boolean} 转换为 {@link Status} - * - * @param v - * {@link Boolean} 值 - * - * @return 当 {@link Boolean} 为 true 时,返回 {@link Status#SUCCESS};否则,返回 {@link Status#FAILURE} - */ - public static Status valueOf(final boolean v) { - return Status.valueOf(v); - } - - /** - * {@link Short} 转换为 {@link Status} - * - * @param v - * {@link Short} 值 - * - * @return 当 {@link Short} 为 0 时,返回 {@link Status#FAILURE};否则,返回 {@link Status#SUCCESS} - */ - public static Status valueOf(final short v) { - return Status.valueOf(v); - } - - /** - * {@link Integer} 转换为 {@link Status} - * - * @param v - * {@link Integer} 值 - * - * @return 当 {@link Integer} 为 0 时,返回 {@link Status#FAILURE};否则,返回 {@link Status#SUCCESS} - */ - public static Status valueOf(final int v) { - return Status.valueOf(v); - } - - /** - * {@link Long} 转换为 {@link Status} - * - * @param v - * {@link Long} 值 - * - * @return 当 {@link Long} 为 0 时,返回 {@link Status#FAILURE};否则,返回 {@link Status#SUCCESS} - */ - public static Status valueOf(final long v) { - return Status.valueOf(v); - } - -} diff --git a/buession-core/src/main/java/com/buession/core/utils/StringJoiner.java b/buession-core/src/main/java/com/buession/core/utils/StringJoiner.java new file mode 100644 index 000000000..741cd224b --- /dev/null +++ b/buession-core/src/main/java/com/buession/core/utils/StringJoiner.java @@ -0,0 +1,236 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core.utils; + +import com.buession.lang.Constants; + +/** + * 字符串拼接处理,其可以在初始化的时候指定分隔符和前缀后缀; + * 与 {@link java.util.StringJoiner} 不同的是,{#add} 方法可以像 {@link StringBuilder} 为其它类型的参数,以及分隔符和前后缀可以为 {@code null}。 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class StringJoiner { + + /** + * 前缀 + */ + private final String prefix; + + /** + * 分隔符 + */ + private final String delimiter; + + /** + * 后缀 + */ + private final String suffix; + + private StringBuilder value; + + private final String emptyValue; + + /** + * 构造函数 + * + * @param delimiter + * 分隔符 + */ + public StringJoiner(CharSequence delimiter) { + this(delimiter, Constants.EMPTY_STRING, Constants.EMPTY_STRING); + } + + /** + * 构造函数 + * + * @param delimiter + * 分隔符 + * @param prefix + * 前缀 + * @param suffix + * 后缀 + */ + public StringJoiner(CharSequence delimiter, CharSequence prefix, CharSequence suffix) { + this.prefix = prefix == null ? Constants.EMPTY_STRING : prefix.toString(); + this.delimiter = delimiter == null ? Constants.EMPTY_STRING : delimiter.toString(); + this.suffix = suffix == null ? Constants.EMPTY_STRING : suffix.toString(); + this.emptyValue = this.prefix + this.suffix; + } + + /** + * 构造函数 + * + * @param delimiter + * 分隔符 + * @param prefix + * 前缀 + * @param suffix + * 后缀 + */ + public StringJoiner(CharSequence delimiter, char prefix, char suffix) { + this(delimiter, prefix + "", suffix + ""); + } + + /** + * 构造函数 + * + * @param delimiter + * 分隔符 + */ + public StringJoiner(char delimiter) { + this(delimiter, Constants.EMPTY_STRING, Constants.EMPTY_STRING); + } + + /** + * 构造函数 + * + * @param delimiter + * 分隔符 + * @param prefix + * 前缀 + * @param suffix + * 后缀 + */ + public StringJoiner(char delimiter, CharSequence prefix, CharSequence suffix) { + this(delimiter + "", prefix, suffix); + } + + /** + * 构造函数 + * + * @param delimiter + * 分隔符 + * @param prefix + * 前缀 + * @param suffix + * 后缀 + */ + public StringJoiner(char delimiter, char prefix, char suffix) { + this(delimiter + "", prefix + "", suffix + ""); + } + + public StringJoiner add(final boolean value) { + prepareBuilder().append(value); + return this; + } + + public StringJoiner add(final float value) { + prepareBuilder().append(value); + return this; + } + + public StringJoiner add(final double value) { + prepareBuilder().append(value); + return this; + } + + public StringJoiner add(final short value) { + prepareBuilder().append(value); + return this; + } + + public StringJoiner add(final int value) { + prepareBuilder().append(value); + return this; + } + + public StringJoiner add(final long value) { + prepareBuilder().append(value); + return this; + } + + public StringJoiner add(final byte[] str) { + if(str != null){ + prepareBuilder().append(new String(str)); + } + + return this; + } + + public StringJoiner add(final char[] str) { + prepareBuilder().append(str); + return this; + } + + public StringJoiner add(final char[] str, final int offset, final int length) { + prepareBuilder().append(str, offset, length); + return this; + } + + public StringJoiner add(final CharSequence s) { + prepareBuilder().append(s); + return this; + } + + public StringJoiner add(final CharSequence s, final int start, final int end) { + prepareBuilder().append(s, start, end); + return this; + } + + public StringJoiner add(final String obj) { + prepareBuilder().append(obj); + return this; + } + + public StringJoiner add(final Object obj) { + prepareBuilder().append(obj); + return this; + } + + public int length() { + return (value != null ? value.length() + suffix.length() : emptyValue.length()); + } + + @Override + public String toString() { + if(value == null){ + return emptyValue; + }else{ + if(Constants.EMPTY_STRING.equals(suffix) == false){ + value.append(suffix); + } + + return value.toString(); + } + } + + private StringBuilder prepareBuilder() { + if(value != null){ + if(delimiter != null){ + value.append(delimiter); + } + }else{ + value = new StringBuilder(); + if(prefix != null){ + value.append(prefix); + } + } + + return value; + } + +} diff --git a/buession-core/src/main/java/com/buession/core/utils/comparator/ByteArrayComparable.java b/buession-core/src/main/java/com/buession/core/utils/comparator/ByteArrayComparable.java index 2db67fcb4..a41ab98fa 100644 --- a/buession-core/src/main/java/com/buession/core/utils/comparator/ByteArrayComparable.java +++ b/buession-core/src/main/java/com/buession/core/utils/comparator/ByteArrayComparable.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.utils.comparator; @@ -33,16 +33,22 @@ public class ByteArrayComparable implements Comparable { private final byte[] value; - public ByteArrayComparable(final byte[] value){ + public ByteArrayComparable(final byte[] value) { this.value = value; } @Override - public int compareTo(byte[] other){ + public int compareTo(byte[] other) { int len1 = this.value.length; int len2 = other.length; - for(int i = 0, j = Math.min(len1, len2); i < j; i++){ + if(len1 < len2){ + return -1; + }else if(len1 > len2){ + return 1; + } + + for(int i = 0; i < len1; i++){ if(this.value[i] < other[i]){ return -1; }else if(this.value[i] > other[i]){ @@ -50,12 +56,6 @@ public int compareTo(byte[] other){ } } - if(len1 < len2){ - return -1; - }else if(len1 > len2){ - return 1; - } - return 0; } diff --git a/buession-core/src/main/java/com/buession/core/validator/routines/IpValidator.java b/buession-core/src/main/java/com/buession/core/validator/routines/IpValidator.java index 546c31ed7..3f17bf1f5 100644 --- a/buession-core/src/main/java/com/buession/core/validator/routines/IpValidator.java +++ b/buession-core/src/main/java/com/buession/core/validator/routines/IpValidator.java @@ -96,7 +96,7 @@ private static boolean IPV4_group_valid(final char[] digits, final int digitSize case 1: return digits[0] >= '0' && digits[0] <= '9'; case 2: - return (digits[0] >= 1 && digits[0] <= 9) && (digits[1] >= '0' && digits[1] <= '9'); + return (digits[0] >= '1' && digits[0] <= '9') && (digits[1] >= '0' && digits[1] <= '9'); case 3: if(digits[0] == '1'){ return (digits[1] >= '0' && digits[1] <= '9') && (digits[2] >= '0' && digits[2] <= '9'); diff --git a/buession-core/src/test/java/com/buession/core/ListTest.java b/buession-core/src/test/java/com/buession/core/ListTest.java index 004920936..10a5ad981 100644 --- a/buession-core/src/test/java/com/buession/core/ListTest.java +++ b/buession-core/src/test/java/com/buession/core/ListTest.java @@ -24,7 +24,7 @@ */ package com.buession.core; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; @@ -36,12 +36,12 @@ public class ListTest { @Test - public void test(){ + public void test() { List list = new ArrayList<>(2); list.add("A"); list.add("B"); - + } } diff --git a/buession-core/src/test/java/com/buession/core/collect/ArraysTest.java b/buession-core/src/test/java/com/buession/core/collect/ArraysTest.java index fd7eed8ce..335b8efc7 100644 --- a/buession-core/src/test/java/com/buession/core/collect/ArraysTest.java +++ b/buession-core/src/test/java/com/buession/core/collect/ArraysTest.java @@ -25,10 +25,9 @@ package com.buession.core.collect; import com.buession.core.converter.ArrayConverter; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Set; -import java.util.function.Function; /** * @author Yong.Teng @@ -39,7 +38,7 @@ public class ArraysTest { @Test public void convert() { String[] data = new String[]{"1", "2"}; - ArrayConverter converter = new ArrayConverter<>((value)->Integer.parseInt(value), + ArrayConverter converter = new ArrayConverter<>(Integer::parseInt, Integer.class); Integer[] result = converter.convert(data); diff --git a/buession-core/src/test/java/com/buession/core/converter/ArrayConverterTest.java b/buession-core/src/test/java/com/buession/core/converter/ArrayConverterTest.java index 5662b3e4e..861b71274 100644 --- a/buession-core/src/test/java/com/buession/core/converter/ArrayConverterTest.java +++ b/buession-core/src/test/java/com/buession/core/converter/ArrayConverterTest.java @@ -25,7 +25,7 @@ package com.buession.core.converter; import com.buession.core.collect.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Yong.Teng @@ -34,7 +34,7 @@ public class ArrayConverterTest { @Test - public void map(){ + public void map() { String[] data = new String[]{"1", "2"}; String[] result = Arrays.map(data, String.class, (value)->"key" + value); diff --git a/buession-core/src/test/java/com/buession/core/datetime/DateTimeTest.java b/buession-core/src/test/java/com/buession/core/datetime/DateTimeTest.java index 25ad9a66b..5a65ba95f 100644 --- a/buession-core/src/test/java/com/buession/core/datetime/DateTimeTest.java +++ b/buession-core/src/test/java/com/buession/core/datetime/DateTimeTest.java @@ -24,7 +24,8 @@ */ package com.buession.core.datetime; -import org.junit.Test; + +import org.junit.jupiter.api.Test; /** * @author Yong.Teng diff --git a/buession-core/src/test/java/com/buession/core/id/IdGeneratorTest.java b/buession-core/src/test/java/com/buession/core/id/IdGeneratorTest.java index 7eda197c3..849b7c246 100644 --- a/buession-core/src/test/java/com/buession/core/id/IdGeneratorTest.java +++ b/buession-core/src/test/java/com/buession/core/id/IdGeneratorTest.java @@ -24,7 +24,7 @@ */ package com.buession.core.id; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Yong.Teng diff --git a/buession-core/src/test/java/com/buession/core/math/MathTest.java b/buession-core/src/test/java/com/buession/core/math/MathTest.java index 52a609e40..51319ad3e 100644 --- a/buession-core/src/test/java/com/buession/core/math/MathTest.java +++ b/buession-core/src/test/java/com/buession/core/math/MathTest.java @@ -24,8 +24,8 @@ */ package com.buession.core.math; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * @author Yong.Teng @@ -34,8 +34,8 @@ public class MathTest { @Test - public void continuousSum(){ - Assert.assertEquals(5050, Math.continuousSum(1, 100)); + public void continuousSum() { + Assertions.assertEquals(5050, Math.continuousSum(1, 100)); } } diff --git a/buession-core/src/test/java/com/buession/core/serializer/DefaultByteArraySerializerTest.java b/buession-core/src/test/java/com/buession/core/serializer/DefaultByteArraySerializerTest.java index 8ee858cc4..dc765f397 100644 --- a/buession-core/src/test/java/com/buession/core/serializer/DefaultByteArraySerializerTest.java +++ b/buession-core/src/test/java/com/buession/core/serializer/DefaultByteArraySerializerTest.java @@ -25,7 +25,7 @@ package com.buession.core.serializer; import com.buession.lang.Uptime; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; @@ -38,7 +38,7 @@ public class DefaultByteArraySerializerTest { private final static DefaultByteArraySerializer serializer = new DefaultByteArraySerializer(); @Test - public void serialize() throws SerializerException{ + public void serialize() throws SerializerException { Uptime uptime = new Uptime(5, 100); String str = serializer.serialize(uptime); @@ -46,7 +46,7 @@ public void serialize() throws SerializerException{ } @Test - public void serializeWithCharsetName() throws SerializerException{ + public void serializeWithCharsetName() throws SerializerException { Uptime uptime = new Uptime(5, 100); String str = serializer.serialize(uptime, StandardCharsets.UTF_8.name()); @@ -54,7 +54,7 @@ public void serializeWithCharsetName() throws SerializerException{ } @Test - public void serializeWithCharset() throws SerializerException{ + public void serializeWithCharset() throws SerializerException { Uptime uptime = new Uptime(5, 100); String str = serializer.serialize(uptime, StandardCharsets.UTF_8); @@ -62,7 +62,7 @@ public void serializeWithCharset() throws SerializerException{ } @Test - public void serializeAsBytes() throws SerializerException{ + public void serializeAsBytes() throws SerializerException { Uptime uptime = new Uptime(5, 100); byte[] str = serializer.serializeAsBytes(uptime); @@ -70,7 +70,7 @@ public void serializeAsBytes() throws SerializerException{ } @Test - public void serializeAsBytesWithCharsetName() throws SerializerException{ + public void serializeAsBytesWithCharsetName() throws SerializerException { Uptime uptime = new Uptime(5, 100); byte[] str = serializer.serializeAsBytes(uptime, StandardCharsets.UTF_8.name()); @@ -78,7 +78,7 @@ public void serializeAsBytesWithCharsetName() throws SerializerException{ } @Test - public void serializeAsBytesWithCharset() throws SerializerException{ + public void serializeAsBytesWithCharset() throws SerializerException { Uptime uptime = new Uptime(5, 100); byte[] str = serializer.serializeAsBytes(uptime, StandardCharsets.UTF_8); @@ -86,56 +86,11 @@ public void serializeAsBytesWithCharset() throws SerializerException{ } @Test - public void deserialize() throws SerializerException{ + public void deserialize() throws SerializerException { Uptime uptime = new Uptime(5, 100); String str = serializer.serialize(uptime); System.out.println(str); } - @Test - public void deserializeWithCharsetName() throws SerializerException{ - Uptime uptime = new Uptime(5, 100); - - String str = serializer.serialize(uptime, StandardCharsets.UTF_8.name()); - Uptime ret = serializer.deserialize(str, StandardCharsets.UTF_8.name()); - System.out.println(ret); - } - - @Test - public void deserializeWithCharset() throws SerializerException{ - Uptime uptime = new Uptime(5, 100); - - String str = serializer.serialize(uptime, StandardCharsets.UTF_8); - Uptime ret = serializer.deserialize(str, StandardCharsets.UTF_8); - System.out.println(ret); - } - - @Test - public void deserializeBytes() throws SerializerException{ - Uptime uptime = new Uptime(5, 100); - - byte[] str = serializer.serializeAsBytes(uptime); - Uptime ret = serializer.deserialize(str); - System.out.println(ret); - } - - @Test - public void deserializeBytesWithCharsetName() throws SerializerException{ - Uptime uptime = new Uptime(5, 100); - - byte[] str = serializer.serializeAsBytes(uptime, StandardCharsets.UTF_8.name()); - Uptime ret = serializer.deserialize(str, StandardCharsets.UTF_8.name()); - System.out.println(ret); - } - - @Test - public void deserializeBytesWithCharset() throws SerializerException{ - Uptime uptime = new Uptime(5, 100); - - byte[] str = serializer.serializeAsBytes(uptime, StandardCharsets.UTF_8); - Uptime ret = serializer.deserialize(str, StandardCharsets.UTF_8); - System.out.println(ret); - } - } diff --git a/buession-core/src/test/java/com/buession/core/serializer/FastJsonJsonSerializerTest.java b/buession-core/src/test/java/com/buession/core/serializer/FastJsonJsonSerializerTest.java index 139a4bc3e..ee09b79d2 100644 --- a/buession-core/src/test/java/com/buession/core/serializer/FastJsonJsonSerializerTest.java +++ b/buession-core/src/test/java/com/buession/core/serializer/FastJsonJsonSerializerTest.java @@ -26,7 +26,7 @@ import com.buession.core.type.TypeReference; import com.buession.lang.Uptime; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; @@ -39,7 +39,7 @@ public class FastJsonJsonSerializerTest { private final static FastJsonJsonSerializer serializer = new FastJsonJsonSerializer(); @Test - public void serialize() throws SerializerException{ + public void serialize() throws SerializerException { Uptime uptime = new Uptime(5, 100); String str = serializer.serialize(uptime); @@ -47,7 +47,7 @@ public void serialize() throws SerializerException{ } @Test - public void serializeWithCharsetName() throws SerializerException{ + public void serializeWithCharsetName() throws SerializerException { Uptime uptime = new Uptime(5, 100); String str = serializer.serialize(uptime, StandardCharsets.UTF_8.name()); @@ -55,7 +55,7 @@ public void serializeWithCharsetName() throws SerializerException{ } @Test - public void serializeWithCharset() throws SerializerException{ + public void serializeWithCharset() throws SerializerException { Uptime uptime = new Uptime(5, 100); String str = serializer.serialize(uptime, StandardCharsets.UTF_8); @@ -63,7 +63,7 @@ public void serializeWithCharset() throws SerializerException{ } @Test - public void serializeAsBytes() throws SerializerException{ + public void serializeAsBytes() throws SerializerException { Uptime uptime = new Uptime(5, 100); byte[] str = serializer.serializeAsBytes(uptime); @@ -71,7 +71,7 @@ public void serializeAsBytes() throws SerializerException{ } @Test - public void serializeAsBytesWithCharsetName() throws SerializerException{ + public void serializeAsBytesWithCharsetName() throws SerializerException { Uptime uptime = new Uptime(5, 100); byte[] str = serializer.serializeAsBytes(uptime, StandardCharsets.UTF_8.name()); @@ -79,68 +79,11 @@ public void serializeAsBytesWithCharsetName() throws SerializerException{ } @Test - public void serializeAsBytesWithCharset() throws SerializerException{ + public void serializeAsBytesWithCharset() throws SerializerException { Uptime uptime = new Uptime(5, 100); byte[] str = serializer.serializeAsBytes(uptime, StandardCharsets.UTF_8); System.out.println(str); } - @Test - public void deserialize() throws SerializerException{ - Uptime uptime = new Uptime(5, 100); - - String str = serializer.serialize(uptime); - System.out.println(String.format("%s", serializer.deserialize(str, Uptime.class))); - System.out.println(String.format("%s", serializer.deserialize(str, new TypeReference() { - - }))); - System.out.println(String.format("%s", serializer.deserialize(str))); - } - - @Test - public void deserializeWithCharsetName() throws SerializerException{ - Uptime uptime = new Uptime(5, 100); - - String str = serializer.serialize(uptime, StandardCharsets.UTF_8.name()); - Uptime ret = serializer.deserialize(str, StandardCharsets.UTF_8.name()); - System.out.println(ret); - } - - @Test - public void deserializeWithCharset() throws SerializerException{ - Uptime uptime = new Uptime(5, 100); - - String str = serializer.serialize(uptime, StandardCharsets.UTF_8); - Uptime ret = serializer.deserialize(str, StandardCharsets.UTF_8); - System.out.println(ret); - } - - @Test - public void deserializeBytes() throws SerializerException{ - Uptime uptime = new Uptime(5, 100); - - byte[] str = serializer.serializeAsBytes(uptime); - Uptime ret = serializer.deserialize(str); - System.out.println(ret); - } - - @Test - public void deserializeBytesWithCharsetName() throws SerializerException{ - Uptime uptime = new Uptime(5, 100); - - byte[] str = serializer.serializeAsBytes(uptime, StandardCharsets.UTF_8.name()); - Uptime ret = serializer.deserialize(str, StandardCharsets.UTF_8.name()); - System.out.println(ret); - } - - @Test - public void deserializeBytesWithCharset() throws SerializerException{ - Uptime uptime = new Uptime(5, 100); - - byte[] str = serializer.serializeAsBytes(uptime, StandardCharsets.UTF_8); - Uptime ret = serializer.deserialize(str, StandardCharsets.UTF_8); - System.out.println(ret); - } - } diff --git a/buession-core/src/main/java/com/buession/core/utils/ObjectUtils.java b/buession-core/src/test/java/com/buession/core/utils/NumberUtilsTest.java similarity index 74% rename from buession-core/src/main/java/com/buession/core/utils/ObjectUtils.java rename to buession-core/src/test/java/com/buession/core/utils/NumberUtilsTest.java index d24b90010..2a064c177 100644 --- a/buession-core/src/main/java/com/buession/core/utils/ObjectUtils.java +++ b/buession-core/src/test/java/com/buession/core/utils/NumberUtilsTest.java @@ -19,39 +19,33 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.core.utils; -import java.util.Optional; -import java.util.function.Consumer; +import org.junit.jupiter.api.Test; /** - * 对象工具类 - * * @author Yong.Teng - * @since 2.3.2 + * @since 3.0.0 */ -@Deprecated -public class ObjectUtils { - - private ObjectUtils() { +public class NumberUtilsTest { + @Test + public void longTest() { + String s = "1716131060146"; + byte[] bytes = NumberUtils.long2bytes(Long.parseLong(s)); + long l = NumberUtils.bytes2long(bytes); + System.out.println(l); } - /** - * 当对象不为 null 时,执行方法 - * - * @param object - * 对象 - * @param consumer - * {@link Consumer} - * @param - * 对象引用类型 - */ - public static void invokeIfAvailable(final T object, final Consumer consumer) { - Optional.ofNullable(object).ifPresent(consumer); + @Test + public void intTest() { + String s = "373407"; + byte[] bytes = NumberUtils.int2bytes(Integer.parseInt(s)); + int i = NumberUtils.bytes2int(bytes); + System.out.println(i); } } diff --git a/buession-core/src/test/java/com/buession/core/utils/StringJoinerTest.java b/buession-core/src/test/java/com/buession/core/utils/StringJoinerTest.java new file mode 100644 index 000000000..17884fc63 --- /dev/null +++ b/buession-core/src/test/java/com/buession/core/utils/StringJoinerTest.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.core.utils; + +import org.junit.jupiter.api.Test; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class StringJoinerTest { + + @Test + public void join() { + System.out.println(new StringJoiner(", ", '[', ']').add("A").add("B").toString()); + } + +} diff --git a/buession-core/src/test/java/com/buession/core/utils/StringUtilsTest.java b/buession-core/src/test/java/com/buession/core/utils/StringUtilsTest.java index aef51e01a..1319ef023 100644 --- a/buession-core/src/test/java/com/buession/core/utils/StringUtilsTest.java +++ b/buession-core/src/test/java/com/buession/core/utils/StringUtilsTest.java @@ -24,8 +24,8 @@ */ package com.buession.core.utils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * @author Yong.Teng @@ -36,7 +36,7 @@ public class StringUtilsTest { @Test public void left() { String str = "123456789"; - Assert.assertEquals("123", StringUtils.left(str, 3)); + Assertions.assertEquals("123", StringUtils.left(str, 3)); } } diff --git a/buession-core/src/test/java/com/buession/core/utils/VersionUtilsTest.java b/buession-core/src/test/java/com/buession/core/utils/VersionUtilsTest.java index bad807912..882d1a364 100644 --- a/buession-core/src/test/java/com/buession/core/utils/VersionUtilsTest.java +++ b/buession-core/src/test/java/com/buession/core/utils/VersionUtilsTest.java @@ -24,8 +24,8 @@ */ package com.buession.core.utils; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * @author Yong.Teng @@ -34,11 +34,11 @@ public class VersionUtilsTest { @Test - public void compare(){ - Assert.assertEquals(VersionUtils.compare("1.0.0", "1.0.1-beta"), -1); - Assert.assertEquals(VersionUtils.compare("1.0.0-beta", "1.0.0-release"), -1); - Assert.assertEquals(VersionUtils.compare("1.0.0", "1.0.0-release"), 1); - Assert.assertEquals(VersionUtils.compare("1.0.0", "1.0.0-pl"), 1); + public void compare() { + Assertions.assertEquals(VersionUtils.compare("1.0.0", "1.0.1-beta"), -1); + Assertions.assertEquals(VersionUtils.compare("1.0.0-beta", "1.0.0-release"), -1); + Assertions.assertEquals(VersionUtils.compare("1.0.0", "1.0.0-release"), 1); + Assertions.assertEquals(VersionUtils.compare("1.0.0", "1.0.0-pl"), 1); } } diff --git a/buession-core/src/test/java/com/buession/core/validator/ValidateTest.java b/buession-core/src/test/java/com/buession/core/validator/ValidateTest.java index 2f964ebe2..d9f1e6a16 100644 --- a/buession-core/src/test/java/com/buession/core/validator/ValidateTest.java +++ b/buession-core/src/test/java/com/buession/core/validator/ValidateTest.java @@ -24,8 +24,8 @@ */ package com.buession.core.validator; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * @author Yong.Teng @@ -35,39 +35,39 @@ public class ValidateTest { @Test public void isBlank() { - Assert.assertEquals(true, Validate.isBlank("")); - Assert.assertEquals(true, Validate.isBlank(null)); - Assert.assertEquals(true, Validate.isBlank("\r\n")); - Assert.assertEquals(true, Validate.isBlank(" ")); - Assert.assertEquals(false, Validate.isBlank("\na")); + Assertions.assertEquals(true, Validate.isBlank("")); + Assertions.assertEquals(true, Validate.isBlank(null)); + Assertions.assertEquals(true, Validate.isBlank("\r\n")); + Assertions.assertEquals(true, Validate.isBlank(" ")); + Assertions.assertEquals(false, Validate.isBlank("\na")); } @Test public void isNotBlank() { - Assert.assertEquals(false, Validate.isNotBlank("")); - Assert.assertEquals(false, Validate.isNotBlank(null)); - Assert.assertEquals(false, Validate.isNotBlank("\r\n")); - Assert.assertEquals(false, Validate.isNotBlank(" ")); - Assert.assertEquals(true, Validate.isNotBlank("\na")); + Assertions.assertEquals(false, Validate.isNotBlank("")); + Assertions.assertEquals(false, Validate.isNotBlank(null)); + Assertions.assertEquals(false, Validate.isNotBlank("\r\n")); + Assertions.assertEquals(false, Validate.isNotBlank(" ")); + Assertions.assertEquals(true, Validate.isNotBlank("\na")); } @Test public void isEmail() { - Assert.assertFalse(Validate.isEmail("")); - Assert.assertTrue(Validate.isEmail("webmaster@buession.com")); + Assertions.assertFalse(Validate.isEmail("")); + Assertions.assertTrue(Validate.isEmail("webmaster@buession.com")); } @Test public void isMimeType() { - Assert.assertEquals(true, Validate.isMimeType("application/rtf")); - Assert.assertEquals(true, Validate.isMimeType("application/vnd.wap.wmlc")); - Assert.assertEquals(true, Validate.isMimeType("application/x-rar-compressed")); - Assert.assertEquals(true, + Assertions.assertEquals(true, Validate.isMimeType("application/rtf")); + Assertions.assertEquals(true, Validate.isMimeType("application/vnd.wap.wmlc")); + Assertions.assertEquals(true, Validate.isMimeType("application/x-rar-compressed")); + Assertions.assertEquals(true, Validate.isMimeType("application/vnd.openxmlformats-officedocument.wordprocessingml.document")); - Assert.assertEquals(true, Validate.isMimeType("video/3gpp")); - Assert.assertEquals(false, Validate.isMimeType("video/-3gpp")); - Assert.assertEquals(false, Validate.isMimeType("video/3gpp-")); - Assert.assertEquals(false, Validate.isMimeType("application/x-rar--compressed")); + Assertions.assertEquals(true, Validate.isMimeType("video/3gpp")); + Assertions.assertEquals(false, Validate.isMimeType("video/-3gpp")); + Assertions.assertEquals(false, Validate.isMimeType("video/3gpp-")); + Assertions.assertEquals(false, Validate.isMimeType("application/x-rar--compressed")); } } diff --git a/buession-core/src/test/java/com/buession/core/validator/annotation/NullTest.java b/buession-core/src/test/java/com/buession/core/validator/annotation/NullTest.java index f478f8bbb..203535d3e 100644 --- a/buession-core/src/test/java/com/buession/core/validator/annotation/NullTest.java +++ b/buession-core/src/test/java/com/buession/core/validator/annotation/NullTest.java @@ -24,12 +24,10 @@ */ package com.buession.core.validator.annotation; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.validation.Valid; import javax.validation.constraints.NotNull; @@ -42,12 +40,11 @@ */ @Configuration @ComponentScan(basePackages = {"com.buession"}) -@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {NullTest.class}) public class NullTest { @Test - public void test(){ + public void test() { User user = new User(); user.setUsername(null); @@ -61,16 +58,16 @@ private final static class User { @Null private String username; - public String getUsername(){ + public String getUsername() { return username; } - public void setUsername(@Valid @Null String username){ + public void setUsername(@Valid @Null String username) { this.username = username; } @Override - public String toString(){ + public String toString() { return new StringJoiner(", ", User.class.getSimpleName() + "[", "]") .add("username='" + username + "'") .toString(); diff --git a/buession-cron/pom.xml b/buession-cron/pom.xml deleted file mode 100644 index 1e936898c..000000000 --- a/buession-cron/pom.xml +++ /dev/null @@ -1,134 +0,0 @@ - - - Buession Cron - 4.0.0 - - com.buession - buession-parent - ../buession-parent - 2.3.3 - - buession-cron - http://www.buession.com/ - Buession Framework Crontab - jar - - - - yong.teng - yong.teng - webmaster@buession.com - - Project Manager - Developer - - - - - - buession.com Inc. - http://www.buession.com/ - - - - - The Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - A business-friendly OSS license - - - - - scm:git:https://github.com/buession/buessionframework.git - scm:git:https://github.com/buession/buessionframework.git - https://github.com/buession/buessionframework - - - - github - https://github.com/buession/buessionframework/issues - - - - - com.buession - buession-core - ${project.version} - - - - jakarta.validation - jakarta.validation-api - - - - org.quartz-scheduler - quartz - 2.3.2 - - - com.zaxxer - * - - - - - - org.slf4j - slf4j-api - - - - junit - junit - - - - - buession-cron - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-jar-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.apache.maven.plugins - maven-resources-plugin - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - org.apache.maven.plugins - maven-release-plugin - - - org.apache.maven.plugins - maven-gpg-plugin - - - org.sonatype.plugins - nexus-staging-maven-plugin - - - - \ No newline at end of file diff --git a/buession-cron/src/main/java/com/buession/cron/AbstractCron.java b/buession-cron/src/main/java/com/buession/cron/AbstractCron.java deleted file mode 100644 index 4705dd9a7..000000000 --- a/buession-cron/src/main/java/com/buession/cron/AbstractCron.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - * ================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | - * +------------------------------------------------------------------------------------------------+ - */ -package com.buession.cron; - -import java.util.Date; -import java.util.Set; - -import org.quartz.CronScheduleBuilder; -import org.quartz.CronTrigger; -import org.quartz.JobBuilder; -import org.quartz.JobDetail; -import org.quartz.Scheduler; -import org.quartz.SchedulerException; -import org.quartz.TriggerBuilder; -import org.quartz.impl.StdSchedulerFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Yong.Teng - */ -public abstract class AbstractCron implements Cron { - - protected final static long DEFAULT_SLEEP_MILLISECONDS = 60000L; - - private long sleepMilliseconds = DEFAULT_SLEEP_MILLISECONDS; - - private final static Logger logger = LoggerFactory.getLogger(AbstractCron.class); - - public long getSleepMilliseconds(){ - return sleepMilliseconds; - } - - public void setSleepMilliseconds(long sleepMilliseconds){ - this.sleepMilliseconds = sleepMilliseconds; - } - - protected void run(final Set jobs) throws SchedulerException{ - if(jobs == null){ - logger.debug("Jobs is null."); - return; - } - - logger.debug("job size: {}", jobs.size()); - - Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); - - for(Job job : jobs){ - execute(scheduler, job); - logger.debug("Register job {} [{}]", job.getName(), job.getClass().getName()); - } - - scheduler.start(); - - try{ - long sleepMilliseconds = getSleepMilliseconds(); - Thread.sleep(sleepMilliseconds <= 0 ? DEFAULT_SLEEP_MILLISECONDS : sleepMilliseconds); - }catch(InterruptedException e){ - logger.error("Thread sleep execute failure: {}", e.getMessage()); - } - - // scheduler.shutdown(true); - } - - private static void execute(final Scheduler scheduler, final Job job) throws SchedulerException{ - JobDetail jobDetail = JobBuilder.newJob(job.getClazz()).withIdentity(job.getName(), job.getGroup()).build(); - // 设置作业 - CronTrigger trigger = - TriggerBuilder.newTrigger().withIdentity(job.getName(), job.getGroup()).withSchedule(CronScheduleBuilder.cronSchedule(job.getExpression())).build(); // 设置触发器 - Date ft = scheduler.scheduleJob(jobDetail, trigger); // 设置调度作业 - - if(logger.isDebugEnabled()){ - logger.debug("{} has been scheduled to run at: {} and repeat based on expression: {}", jobDetail.getKey(), - ft, trigger.getCronExpression()); - } - } - -} \ No newline at end of file diff --git a/buession-cron/src/main/java/com/buession/cron/AbstractJob.java b/buession-cron/src/main/java/com/buession/cron/AbstractJob.java deleted file mode 100644 index 1ba08fc8b..000000000 --- a/buession-cron/src/main/java/com/buession/cron/AbstractJob.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - * ================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2018 Buession.com Inc. | - * +------------------------------------------------------------------------------------------------+ - */ -package com.buession.cron; - -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; - -/** - * @author Yong.Teng - */ -public abstract class AbstractJob implements org.quartz.Job { - - @Override - public void execute(JobExecutionContext context) throws JobExecutionException{ - doExecute(context); - } - - protected abstract void doExecute(JobExecutionContext context) throws JobExecutionException; - -} \ No newline at end of file diff --git a/buession-cron/src/main/java/com/buession/cron/Cron.java b/buession-cron/src/main/java/com/buession/cron/Cron.java deleted file mode 100644 index 26afda729..000000000 --- a/buession-cron/src/main/java/com/buession/cron/Cron.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - * ================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2018 Buession.com Inc. | - * +------------------------------------------------------------------------------------------------+ - */ -package com.buession.cron; - -import org.quartz.SchedulerException; - -/** - * @author Yong.Teng - */ -public interface Cron { - - void run() throws SchedulerException; - -} \ No newline at end of file diff --git a/buession-cron/src/main/java/com/buession/cron/Job.java b/buession-cron/src/main/java/com/buession/cron/Job.java deleted file mode 100644 index ab1cd4718..000000000 --- a/buession-cron/src/main/java/com/buession/cron/Job.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - * ================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2018 Buession.com Inc. | - * +------------------------------------------------------------------------------------------------+ - */ -package com.buession.cron; - -import java.io.Serializable; - -import javax.validation.constraints.NotNull; - -/** - * 计划任务作业实体 - * - * @author Yong.Teng - */ -public final class Job implements Serializable { - - private static final long serialVersionUID = -3006447320967793168L; - - /** - * 计划任务作业名称 - */ - @NotNull(message = "job name could not be null") - private String name; - - /** - * 计划任务作业分组 - */ - @NotNull(message = "job group could not be null") - private String group; - - /** - * 计划任务作业类 - */ - @NotNull(message = "job class could not be null") - private Class clazz; - - /** - * 计划任务作业执行表达式 - */ - @NotNull(message = "job excute expression could not be null") - private String expression; - - /** - * 返回计划任务作业名称 - * - * @return 计划任务作业名称 - */ - public String getName(){ - return name; - } - - /** - * 设置计划任务作业名称 - * - * @param name - * 计划任务作业名称 - */ - public void setName(String name){ - this.name = name; - } - - /** - * 返回计划任务作业分组 - * - * @return 计划任务作业分组 - */ - public String getGroup(){ - return group; - } - - /** - * 设置计划任务作业分组 - * - * @param group - * 计划任务作业分组 - */ - public void setGroup(String group){ - this.group = group; - } - - /** - * 返回计划任务作业类 - * - * @return 计划任务作业类 - */ - public Class getClazz(){ - return clazz; - } - - /** - * 设置计划任务作业类 - * - * @param clazz - * 计划任务作业类 - */ - public void setClazz(Class clazz){ - this.clazz = clazz; - } - - /** - * 返回计划任务作业执行表达式 - * - * @return 计划任务作业执行表达式 - */ - public String getExpression(){ - return expression; - } - - /** - * 设置计划任务作业执行表达式 - * - * @param expression - * 计划任务作业执行表达式 - */ - public void setExpression(String expression){ - this.expression = expression; - } - -} \ No newline at end of file diff --git a/buession-cron/src/main/java/com/buession/cron/config/JobConfigurer.java b/buession-cron/src/main/java/com/buession/cron/config/JobConfigurer.java deleted file mode 100644 index 5e6ebcc28..000000000 --- a/buession-cron/src/main/java/com/buession/cron/config/JobConfigurer.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - * ================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2018 Buession.com Inc. | - * +------------------------------------------------------------------------------------------------+ - */ -package com.buession.cron.config; - -import java.util.LinkedHashSet; -import java.util.Set; - -import com.buession.cron.Job; - -/** - * @author Yong.Teng - */ -public class JobConfigurer { - - private Set jobs; - - public Set getJobs(){ - return jobs; - } - - public void setJobs(Set jobs){ - this.jobs = jobs; - } - - public void addJob(Job job){ - if(jobs == null){ - jobs = new LinkedHashSet<>(); - } - - jobs.add(job); - } - -} \ No newline at end of file diff --git a/buession-cron/src/main/java/com/buession/cron/config/package-info.java b/buession-cron/src/main/java/com/buession/cron/config/package-info.java deleted file mode 100644 index 9bcd02654..000000000 --- a/buession-cron/src/main/java/com/buession/cron/config/package-info.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - * ================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2018 Buession.com Inc. | - * +------------------------------------------------------------------------------------------------+ - */ -/** - * @author Yong.Teng - */ -package com.buession.cron.config; \ No newline at end of file diff --git a/buession-cron/src/main/java/com/buession/cron/package-info.java b/buession-cron/src/main/java/com/buession/cron/package-info.java deleted file mode 100644 index 047d06815..000000000 --- a/buession-cron/src/main/java/com/buession/cron/package-info.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - * ================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2018 Buession.com Inc. | - * +------------------------------------------------------------------------------------------------+ - */ -/** - * @author Yong.Teng - */ -package com.buession.cron; \ No newline at end of file diff --git a/buession-dao/pom.xml b/buession-dao/pom.xml index 9357c1cd6..879b738b3 100644 --- a/buession-dao/pom.xml +++ b/buession-dao/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-dao http://www.buession.com/ @@ -57,11 +57,6 @@ buession-core ${project.version} - - com.buession - buession-beans - ${project.version} - org.springframework @@ -106,8 +101,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -151,8 +146,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-dao/src/main/java/com/buession/dao/AbstractMongoDBDao.java b/buession-dao/src/main/java/com/buession/dao/AbstractMongoDBDao.java index fc64cbb58..631a5a189 100644 --- a/buession-dao/src/main/java/com/buession/dao/AbstractMongoDBDao.java +++ b/buession-dao/src/main/java/com/buession/dao/AbstractMongoDBDao.java @@ -27,7 +27,6 @@ package com.buession.dao; import com.buession.core.Pagination; -import com.buession.core.builder.ListBuilder; import com.buession.core.builder.MapBuilder; import com.buession.core.utils.Assert; import com.buession.core.validator.Validate; @@ -37,8 +36,6 @@ import com.mongodb.BasicDBObject; import com.mongodb.client.result.DeleteResult; import com.mongodb.client.result.UpdateResult; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; @@ -63,18 +60,6 @@ */ public abstract class AbstractMongoDBDao extends AbstractDao implements MongoDBDao { - /** - * master MongoTemplate - */ - @Deprecated - private MongoTemplate masterMongoTemplate; - - /** - * slave MongoTemplate - */ - @Deprecated - private List slaveMongoTemplates; - /** * {@link MongoTemplate} * @@ -83,51 +68,6 @@ public abstract class AbstractMongoDBDao extends AbstractDao impleme @Resource private MongoTemplate mongoTemplate; - protected final Logger logger = LoggerFactory.getLogger(getClass()); - - /** - * 返回 master MongoTemplate - * - * @return master MongoTemplate - */ - @Deprecated - public MongoTemplate getMasterMongoTemplate() { - return masterMongoTemplate; - } - - /** - * 设置 master MongoTemplate - * - * @param masterMongoTemplate - * master MongoTemplate - */ - @Deprecated - public void setMasterMongoTemplate(MongoTemplate masterMongoTemplate) { - this.masterMongoTemplate = masterMongoTemplate; - this.mongoTemplate = masterMongoTemplate; - } - - /** - * 返回 slave MongoTemplate - * - * @return slave MongoTemplate - */ - @Deprecated - public List getSlaveMongoTemplates() { - return slaveMongoTemplates; - } - - /** - * 设置 slave MongoTemplate - * - * @param slaveMongoTemplates - * slave MongoTemplate - */ - @Deprecated - public void setSlaveMongoTemplates(List slaveMongoTemplates) { - this.slaveMongoTemplates = slaveMongoTemplates; - } - /** * 返回 {@link MongoTemplate} 实例 * @@ -149,8 +89,6 @@ public MongoTemplate getMongoTemplate() { */ public void setMongoTemplate(MongoTemplate mongoTemplate) { this.mongoTemplate = mongoTemplate; - this.masterMongoTemplate = mongoTemplate; - this.slaveMongoTemplates = ListBuilder.of(mongoTemplate); } /** @@ -353,7 +291,7 @@ protected void buildSort(final Query query, final Map orders) { private int delete(final Query query, final Map conditions) { query.addCriteria(buildCriteria(conditions)); - DeleteResult writeResult = getMasterMongoTemplate().remove(query, getStatement()); + DeleteResult writeResult = getMongoTemplate().remove(query, getStatement()); return (int) writeResult.getDeletedCount(); } diff --git a/buession-dao/src/main/java/com/buession/dao/AbstractMyBatisDao.java b/buession-dao/src/main/java/com/buession/dao/AbstractMyBatisDao.java index 62848f946..457de99c3 100755 --- a/buession-dao/src/main/java/com/buession/dao/AbstractMyBatisDao.java +++ b/buession-dao/src/main/java/com/buession/dao/AbstractMyBatisDao.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.dao; @@ -32,11 +32,8 @@ import java.util.List; import java.util.Map; -import com.buession.beans.BeanConverter; -import com.buession.beans.DefaultBeanConverter; import com.buession.core.utils.FieldUtils; import com.buession.core.utils.Assert; -import com.buession.core.utils.RandomUtils; import com.buession.core.validator.Validate; import com.buession.dao.mybatis.PageRowBounds; import com.buession.lang.Order; @@ -48,7 +45,7 @@ import org.slf4j.LoggerFactory; import com.buession.core.Pagination; -import com.buession.core.exception.OperationException; +import org.springframework.cglib.beans.BeanMap; import javax.annotation.Resource; @@ -68,62 +65,37 @@ public abstract class AbstractMyBatisDao extends AbstractDao impleme * master SqlSessionTemplate */ @Resource - protected SqlSessionTemplate masterSqlSessionTemplate; - - /** - * slave SqlSessionTemplate - */ - @Resource - protected List slaveSqlSessionTemplates; + protected SqlSessionTemplate sqlSessionTemplate; protected final Logger logger = LoggerFactory.getLogger(getClass()); /** - * 返回 master SqlSessionTemplate + * 返回 SqlSessionTemplate * - * @return master SqlSessionTemplate + * @return SqlSessionTemplate */ - public SqlSessionTemplate getMasterSqlSessionTemplate() { - return masterSqlSessionTemplate; + public SqlSessionTemplate getSqlSessionTemplate() { + return sqlSessionTemplate; } /** - * 设置 master SqlSessionTemplate + * 设置 SqlSessionTemplate * - * @param masterSqlSessionTemplate - * master SqlSessionTemplate + * @param sqlSessionTemplate + * SqlSessionTemplate */ - public void setMasterSqlSessionTemplate(final SqlSessionTemplate masterSqlSessionTemplate) { - this.masterSqlSessionTemplate = masterSqlSessionTemplate; - } - - /** - * 返回 slave SqlSessionTemplate - * - * @return slave SqlSessionTemplate - */ - public List getSlaveSqlSessionTemplates() { - return slaveSqlSessionTemplates; - } - - /** - * 设置 slave SqlSessionTemplate - * - * @param slaveSqlSessionTemplates - * slave SqlSessionTemplate - */ - public void setSlaveSqlSessionTemplates(final List slaveSqlSessionTemplates) { - this.slaveSqlSessionTemplates = slaveSqlSessionTemplates; + public void setSqlSessionTemplate(final SqlSessionTemplate sqlSessionTemplate) { + this.sqlSessionTemplate = sqlSessionTemplate; } @Override public int insert(E e) { - return getMasterSqlSessionTemplate().insert(getStatement(DML.INSERT), e); + return getSqlSessionTemplate().insert(getStatement(DML.INSERT), e); } @Override public int replace(E e) { - return getMasterSqlSessionTemplate().insert(getStatement(DML.REPLACE), e); + return getSqlSessionTemplate().insert(getStatement(DML.REPLACE), e); } @Override @@ -140,31 +112,22 @@ public int update(E e, Map conditions) { Map eMap = (Map) e; eMap.forEach((key, value)->data.put(key.toString(), value)); }else{ - BeanConverter beanConverter = new DefaultBeanConverter(); - Map eData = new HashMap<>(); - - beanConverter.convert(e, eData); - data.putAll(eData); + BeanMap beanMap = BeanMap.create(e); + data.putAll(beanMap); } - return getMasterSqlSessionTemplate().update(getStatement(DML.UPDATE), data); + return getSqlSessionTemplate().update(getStatement(DML.UPDATE), data); } @Override public int updateByPrimary(P primary, E e) { updatePrimary(e, primary); - return getMasterSqlSessionTemplate().update(getStatement(DML.UPDATE_BY_PRIMARY), e); + return getSqlSessionTemplate().update(getStatement(DML.UPDATE_BY_PRIMARY), e); } @Override public E getByPrimary(P primary) { - try{ - return getSlaveSqlSessionTemplate().selectOne(getStatement(DML.GET_BY_PRIMARY), primary); - }catch(OperationException e){ - logger.error(e.getMessage()); - } - - return null; + return getSqlSessionTemplate().selectOne(getStatement(DML.GET_BY_PRIMARY), primary); } @Override @@ -175,13 +138,7 @@ public E selectOne(Map conditions, int offset, Map select(Map conditions, Map orders) parameters.put(ORDERS_PARAMETER_NAME, orders); } - try{ - return getSlaveSqlSessionTemplate().selectList(getStatement(DML.SELECT), parameters); - }catch(OperationException e){ - logger.error(e.getMessage()); - } - - return null; + return getSqlSessionTemplate().selectList(getStatement(DML.SELECT), parameters); } @Override @@ -212,14 +163,7 @@ public List select(Map conditions, int offset, int size, Map< parameters.put(ORDERS_PARAMETER_NAME, orders); } - try{ - return getSlaveSqlSessionTemplate().selectList(getStatement(DML.SELECT), parameters, - new RowBounds(offset, size)); - }catch(OperationException e){ - logger.error(e.getMessage()); - } - - return null; + return getSqlSessionTemplate().selectList(getStatement(DML.SELECT), parameters, new RowBounds(offset, size)); } @Override @@ -238,13 +182,9 @@ public Pagination paging(Map conditions, int page, int pagesi parameters.put(ORDERS_PARAMETER_NAME, orders); } - try{ - List result = getSlaveSqlSessionTemplate().selectList(getStatement(DML.SELECT), parameters, - new PageRowBounds(pagination.getOffset(), pagination.getPagesize())); - pagination.setData(result); - }catch(OperationException e){ - logger.error(e.getMessage()); - } + List result = getSqlSessionTemplate().selectList(getStatement(DML.SELECT), parameters, + new PageRowBounds(pagination.getOffset(), pagination.getPagesize())); + pagination.setData(result); } return pagination; @@ -252,40 +192,22 @@ public Pagination paging(Map conditions, int page, int pagesi @Override public List getAll() { - try{ - return getSlaveSqlSessionTemplate().selectList(getStatement(DML.GET_ALL)); - }catch(OperationException e){ - logger.error(e.getMessage()); - } - - return null; + return getSqlSessionTemplate().selectList(getStatement(DML.GET_ALL)); } @Override public long count() { - try{ - return getSlaveSqlSessionTemplate().selectOne(getStatement("count")); - }catch(OperationException e){ - logger.error(e.getMessage()); - } - - return 0L; + return getSqlSessionTemplate().selectOne(getStatement("count")); } @Override public long count(Map conditions) { - try{ - return getSlaveSqlSessionTemplate().selectOne(getStatement("count"), conditions); - }catch(OperationException e){ - logger.error(e.getMessage()); - } - - return 0L; + return getSqlSessionTemplate().selectOne(getStatement("count"), conditions); } @Override public int delete(Map conditions) { - return getMasterSqlSessionTemplate().delete(getStatement(DML.DELETE), conditions); + return getSqlSessionTemplate().delete(getStatement(DML.DELETE), conditions); } @Override @@ -294,51 +216,26 @@ public int delete(Map conditions, int size) { parameters.put("SIZE", size); - return getMasterSqlSessionTemplate().delete(getStatement(DML.DELETE), parameters); + return getSqlSessionTemplate().delete(getStatement(DML.DELETE), parameters); } @Override public int deleteByPrimary(P primary) { - return getMasterSqlSessionTemplate().delete(getStatement(DML.DELETE_BY_PRIMARY), primary); + return getSqlSessionTemplate().delete(getStatement(DML.DELETE_BY_PRIMARY), primary); } @Override public int clear() { - return getMasterSqlSessionTemplate().delete(getStatement(DML.CLEAR)); + return getSqlSessionTemplate().delete(getStatement(DML.CLEAR)); } @Override public int truncate() { - return getMasterSqlSessionTemplate().delete(getStatement(DML.TRUNCATE)); - } - - protected final SqlSessionTemplate getSlaveSqlSessionTemplate(final int index) throws OperationException { - if(Validate.isEmpty(slaveSqlSessionTemplates)){ - return getMasterSqlSessionTemplate(); - }else{ - SqlSessionTemplate sqlSessionTemplate = slaveSqlSessionTemplates.get(index); - - if(sqlSessionTemplate == null){ - throw new OperationException("Could not find the \"" + index + "\" slave SqlSessionTemplate."); - } - - return sqlSessionTemplate; - } - } - - protected final SqlSessionTemplate getSlaveSqlSessionTemplate() throws OperationException { - if(Validate.isEmpty(slaveSqlSessionTemplates)){ - return getMasterSqlSessionTemplate(); - }else if(slaveSqlSessionTemplates.size() == 1){ - return getSlaveSqlSessionTemplate(0); - }else{ - int index = RandomUtils.nextInt(slaveSqlSessionTemplates.size()); - return getSlaveSqlSessionTemplate(index); - } + return getSqlSessionTemplate().delete(getStatement(DML.TRUNCATE)); } protected void updatePrimary(E e, P primary) { - final Collection resultMaps = masterSqlSessionTemplate.getConfiguration().getResultMaps(); + final Collection resultMaps = getSqlSessionTemplate().getConfiguration().getResultMaps(); if(Validate.isEmpty(resultMaps)){ return; diff --git a/buession-dao/src/main/java/com/buession/dao/Pagination.java b/buession-dao/src/main/java/com/buession/dao/Pagination.java index bca6acebf..ae50991b1 100644 --- a/buession-dao/src/main/java/com/buession/dao/Pagination.java +++ b/buession-dao/src/main/java/com/buession/dao/Pagination.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.dao; @@ -36,6 +36,8 @@ */ public class Pagination extends com.buession.core.Pagination { + private final static long serialVersionUID = -861860070044591052L; + /** * 偏移量 */ diff --git a/buession-dao/src/main/java/org/apache/ibatis/type/DefaultJsonTypeHandler.java b/buession-dao/src/main/java/org/apache/ibatis/type/DefaultJsonTypeHandler.java index 79bf1e286..0f3016da9 100644 --- a/buession-dao/src/main/java/org/apache/ibatis/type/DefaultJsonTypeHandler.java +++ b/buession-dao/src/main/java/org/apache/ibatis/type/DefaultJsonTypeHandler.java @@ -19,11 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package org.apache.ibatis.type; +import com.buession.core.deserializer.DeserializerException; +import com.buession.core.deserializer.JacksonJsonDeserializer; import com.buession.core.serializer.JacksonJsonSerializer; import com.buession.core.serializer.SerializerException; import com.buession.core.validator.Validate; @@ -39,14 +41,16 @@ */ public class DefaultJsonTypeHandler extends AbstractJsonTypeHandler { + private final JacksonJsonSerializer jsonSerializer = new JacksonJsonSerializer(); + + private final JacksonJsonDeserializer jsonDeserializer = new JacksonJsonDeserializer(); + public DefaultJsonTypeHandler(final Class type) { super(type); } @Override public void setNonNullParameter(PreparedStatement ps, int i, E parameter, JdbcType jdbcType) throws SQLException { - JacksonJsonSerializer jsonSerializer = new JacksonJsonSerializer(); - try{ if(jdbcType == null){ ps.setString(i, jsonSerializer.serialize(parameter)); @@ -61,11 +65,9 @@ public void setNonNullParameter(PreparedStatement ps, int i, E parameter, JdbcTy @Override protected E parseResult(final String str) throws SQLException { if(Validate.hasText(str)){ - JacksonJsonSerializer jsonSerializer = new JacksonJsonSerializer(); - try{ - return jsonSerializer.deserialize(str, type); - }catch(SerializerException e){ + return jsonDeserializer.deserialize(str, type); + }catch(DeserializerException e){ throw new SQLException(str + " cloud not be deserialize to " + type.getName() + ": " + e.getMessage()); } } diff --git a/buession-dao/src/test/java/com/buession/dao/TypeTest.java b/buession-dao/src/test/java/com/buession/dao/TypeTest.java index 99724e157..c7481cb18 100644 --- a/buession-dao/src/test/java/com/buession/dao/TypeTest.java +++ b/buession-dao/src/test/java/com/buession/dao/TypeTest.java @@ -19,34 +19,34 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://buession.buession.com.cn/LICENSE | * | Author: Yong.Teng | - * | Copyright @ 2013-2018 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.dao; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Yong.Teng */ public class TypeTest { - @Test - public void test(){ - SimpleType simpleType = new SimpleType<>(); - simpleType.getType(); - } + @Test + public void test() { + SimpleType simpleType = new SimpleType<>(); + simpleType.getType(); + } - public static interface IType { + public static interface IType { - } + } - public final static class SimpleType implements IType { + public final static class SimpleType implements IType { - public void getType(){ - } + public void getType() { + } - } + } } diff --git a/buession-geoip/pom.xml b/buession-geoip/pom.xml index 131caa426..64dfa06a4 100644 --- a/buession-geoip/pom.xml +++ b/buession-geoip/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-geoip http://www.buession.com/ @@ -72,17 +72,17 @@ com.maxmind.geoip2 geoip2 2.16.1 + + + org.apache.httpcomponents + * + + - org.apache.httpcomponents - httpcore - provided - - - org.apache.httpcomponents - httpclient - provided + commons-codec + commons-codec @@ -104,8 +104,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -149,8 +149,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-geoip/src/main/java/com/buession/geoip/DatabaseResolver.java b/buession-geoip/src/main/java/com/buession/geoip/DatabaseResolver.java index d87faa22e..ea8f23bb9 100644 --- a/buession-geoip/src/main/java/com/buession/geoip/DatabaseResolver.java +++ b/buession-geoip/src/main/java/com/buession/geoip/DatabaseResolver.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.geoip; @@ -37,7 +37,6 @@ import com.buession.geoip.model.Geo; import com.buession.geoip.model.Location; import com.buession.geoip.model.Traits; -import com.maxmind.db.CHMCache; import com.maxmind.db.Reader; import com.maxmind.db.Metadata; import com.maxmind.db.NodeCache; @@ -75,7 +74,7 @@ public class DatabaseResolver extends AbstractResolver { * @throws IOException * IO 错误 */ - public DatabaseResolver(final String database) throws IOException{ + public DatabaseResolver(final String database) throws IOException { this(database == null ? null : new File(database)); } @@ -90,7 +89,7 @@ public DatabaseResolver(final String database) throws IOException{ * @throws IOException * IO 错误 */ - public DatabaseResolver(final String database, final NodeCache cache) throws IOException{ + public DatabaseResolver(final String database, final NodeCache cache) throws IOException { this(database == null ? null : new File(database), cache); } @@ -105,7 +104,7 @@ public DatabaseResolver(final String database, final NodeCache cache) throws IOE * @throws IOException * IO 错误 */ - public DatabaseResolver(final String database, final Reader.FileMode fileMode) throws IOException{ + public DatabaseResolver(final String database, final Reader.FileMode fileMode) throws IOException { this(database == null ? null : new File(database), fileMode); } @@ -123,7 +122,7 @@ public DatabaseResolver(final String database, final Reader.FileMode fileMode) t * IO 错误 */ public DatabaseResolver(final String database, final Reader.FileMode fileMode, final NodeCache cache) - throws IOException{ + throws IOException { this(database == null ? null : new File(database), fileMode, cache); } @@ -136,7 +135,7 @@ public DatabaseResolver(final String database, final Reader.FileMode fileMode, f * @throws IOException * IO 错误 */ - public DatabaseResolver(final File database) throws IOException{ + public DatabaseResolver(final File database) throws IOException { Assert.isNull(database, "Database could not be null."); this.reader = new DatabaseReader.Builder(database).build(); this.asnReader = getDefaultAsnReaderBuilder().build(); @@ -153,7 +152,7 @@ public DatabaseResolver(final File database) throws IOException{ * @throws IOException * IO 错误 */ - public DatabaseResolver(final File database, final NodeCache cache) throws IOException{ + public DatabaseResolver(final File database, final NodeCache cache) throws IOException { Assert.isNull(database, "Database could not be null."); this.reader = new DatabaseReader.Builder(database).withCache(cache).build(); this.asnReader = getDefaultAsnReaderBuilder().withCache(cache).build(); @@ -170,7 +169,7 @@ public DatabaseResolver(final File database, final NodeCache cache) throws IOExc * @throws IOException * IO 错误 */ - public DatabaseResolver(final File database, final Reader.FileMode fileMode) throws IOException{ + public DatabaseResolver(final File database, final Reader.FileMode fileMode) throws IOException { Assert.isNull(database, "Database could not be null."); this.reader = new DatabaseReader.Builder(database).fileMode(fileMode).build(); this.asnReader = getDefaultAsnReaderBuilder().fileMode(fileMode).build(); @@ -190,7 +189,7 @@ public DatabaseResolver(final File database, final Reader.FileMode fileMode) thr * IO 错误 */ public DatabaseResolver(final File database, final Reader.FileMode fileMode, final NodeCache cache) - throws IOException{ + throws IOException { Assert.isNull(database, "Database could not be null."); this.reader = new DatabaseReader.Builder(database).fileMode(fileMode).withCache(cache).build(); this.asnReader = getDefaultAsnReaderBuilder().fileMode(fileMode).withCache(cache) @@ -206,7 +205,7 @@ public DatabaseResolver(final File database, final Reader.FileMode fileMode, fin * @throws IOException * IO 错误 */ - public DatabaseResolver(final Path database) throws IOException{ + public DatabaseResolver(final Path database) throws IOException { this(database == null ? null : database.toFile()); } @@ -221,7 +220,7 @@ public DatabaseResolver(final Path database) throws IOException{ * @throws IOException * IO 错误 */ - public DatabaseResolver(final Path database, final NodeCache cache) throws IOException{ + public DatabaseResolver(final Path database, final NodeCache cache) throws IOException { this(database == null ? null : database.toFile(), cache); } @@ -236,7 +235,7 @@ public DatabaseResolver(final Path database, final NodeCache cache) throws IOExc * @throws IOException * IO 错误 */ - public DatabaseResolver(final Path database, final Reader.FileMode fileMode) throws IOException{ + public DatabaseResolver(final Path database, final Reader.FileMode fileMode) throws IOException { this(database == null ? null : database.toFile(), fileMode); } @@ -254,7 +253,7 @@ public DatabaseResolver(final Path database, final Reader.FileMode fileMode) thr * IO 错误 */ public DatabaseResolver(final Path database, final Reader.FileMode fileMode, final NodeCache cache) - throws IOException{ + throws IOException { this(database == null ? null : database.toFile(), fileMode, cache); } @@ -267,7 +266,7 @@ public DatabaseResolver(final Path database, final Reader.FileMode fileMode, fin * @throws IOException * IO 错误 */ - public DatabaseResolver(final InputStream source) throws IOException{ + public DatabaseResolver(final InputStream source) throws IOException { Assert.isNull(source, "Database stream could not be null."); this.reader = new DatabaseReader.Builder(source).build(); this.asnReader = getDefaultAsnReaderBuilder().build(); @@ -284,7 +283,7 @@ public DatabaseResolver(final InputStream source) throws IOException{ * @throws IOException * IO 错误 */ - public DatabaseResolver(final InputStream source, final NodeCache cache) throws IOException{ + public DatabaseResolver(final InputStream source, final NodeCache cache) throws IOException { Assert.isNull(source, "Database stream could not be null."); this.reader = new DatabaseReader.Builder(source).withCache(cache).build(); this.asnReader = getDefaultAsnReaderBuilder().withCache(cache).build(); @@ -301,7 +300,7 @@ public DatabaseResolver(final InputStream source, final NodeCache cache) throws * @throws IOException * IO 错误 */ - public DatabaseResolver(final InputStream source, final Reader.FileMode fileMode) throws IOException{ + public DatabaseResolver(final InputStream source, final Reader.FileMode fileMode) throws IOException { Assert.isNull(source, "Database stream could not be null."); this.reader = new DatabaseReader.Builder(source).fileMode(fileMode).build(); this.asnReader = getDefaultAsnReaderBuilder().fileMode(fileMode).build(); @@ -321,7 +320,7 @@ public DatabaseResolver(final InputStream source, final Reader.FileMode fileMode * IO 错误 */ public DatabaseResolver(final InputStream source, final Reader.FileMode fileMode, final NodeCache cache) - throws IOException{ + throws IOException { Assert.isNull(source, "Database stream could not be null."); this.reader = new DatabaseReader.Builder(source).fileMode(fileMode).withCache(cache).build(); this.asnReader = getDefaultAsnReaderBuilder().fileMode(fileMode).withCache(cache).build(); @@ -339,7 +338,7 @@ public DatabaseResolver(final InputStream source, final Reader.FileMode fileMode * IO 错误 * @since 2.2.0 */ - public DatabaseResolver(final String database, final String asnDatabase) throws IOException{ + public DatabaseResolver(final String database, final String asnDatabase) throws IOException { this(database == null ? null : new File(database), asnDatabase == null ? null : new File(asnDatabase)); } @@ -357,7 +356,7 @@ public DatabaseResolver(final String database, final String asnDatabase) throws * IO 错误 * @since 2.2.0 */ - public DatabaseResolver(final String database, final String asnDatabase, final NodeCache cache) throws IOException{ + public DatabaseResolver(final String database, final String asnDatabase, final NodeCache cache) throws IOException { this(database == null ? null : new File(database), asnDatabase == null ? null : new File(asnDatabase), cache); } @@ -376,7 +375,7 @@ public DatabaseResolver(final String database, final String asnDatabase, final N * @since 2.2.0 */ public DatabaseResolver(final String database, final String asnDatabase, final Reader.FileMode fileMode) - throws IOException{ + throws IOException { this(database == null ? null : new File(database), asnDatabase == null ? null : new File(asnDatabase), fileMode); } @@ -399,7 +398,7 @@ public DatabaseResolver(final String database, final String asnDatabase, final R */ public DatabaseResolver(final String database, final String asnDatabase, final Reader.FileMode fileMode, final NodeCache cache) - throws IOException{ + throws IOException { this(database == null ? null : new File(database), asnDatabase == null ? null : new File(asnDatabase), fileMode, cache); } @@ -416,7 +415,7 @@ public DatabaseResolver(final String database, final String asnDatabase, final R * IO 错误 * @since 2.2.0 */ - public DatabaseResolver(final File database, final File asnDatabase) throws IOException{ + public DatabaseResolver(final File database, final File asnDatabase) throws IOException { Assert.isNull(database, "Database could not be null."); this.reader = new DatabaseReader.Builder(database).build(); this.asnReader = new DatabaseReader.Builder(asnDatabase).build(); @@ -436,7 +435,7 @@ public DatabaseResolver(final File database, final File asnDatabase) throws IOEx * IO 错误 * @since 2.2.0 */ - public DatabaseResolver(final File database, final File asnDatabase, final NodeCache cache) throws IOException{ + public DatabaseResolver(final File database, final File asnDatabase, final NodeCache cache) throws IOException { Assert.isNull(database, "Database could not be null."); Assert.isNull(asnDatabase, "ASN database could not be null."); this.reader = new DatabaseReader.Builder(database).withCache(cache).build(); @@ -458,7 +457,7 @@ public DatabaseResolver(final File database, final File asnDatabase, final NodeC * @since 2.2.0 */ public DatabaseResolver(final File database, final File asnDatabase, final Reader.FileMode fileMode) - throws IOException{ + throws IOException { Assert.isNull(database, "Database could not be null."); Assert.isNull(asnDatabase, "ASN database could not be null."); this.reader = new DatabaseReader.Builder(database).fileMode(fileMode).build(); @@ -483,7 +482,7 @@ public DatabaseResolver(final File database, final File asnDatabase, final Reade */ public DatabaseResolver(final File database, final File asnDatabase, final Reader.FileMode fileMode, final NodeCache cache) - throws IOException{ + throws IOException { Assert.isNull(database, "Database could not be null."); Assert.isNull(asnDatabase, "ASN database could not be null."); this.reader = new DatabaseReader.Builder(database).fileMode(fileMode).withCache(cache).build(); @@ -502,7 +501,7 @@ public DatabaseResolver(final File database, final File asnDatabase, final Reade * IO 错误 * @since 2.2.0 */ - public DatabaseResolver(final Path database, final Path asnDatabase) throws IOException{ + public DatabaseResolver(final Path database, final Path asnDatabase) throws IOException { this(database == null ? null : database.toFile(), asnDatabase == null ? null : asnDatabase.toFile()); } @@ -520,7 +519,7 @@ public DatabaseResolver(final Path database, final Path asnDatabase) throws IOEx * IO 错误 * @since 2.2.0 */ - public DatabaseResolver(final Path database, final Path asnDatabase, final NodeCache cache) throws IOException{ + public DatabaseResolver(final Path database, final Path asnDatabase, final NodeCache cache) throws IOException { this(database == null ? null : database.toFile(), asnDatabase == null ? null : asnDatabase.toFile(), cache); } @@ -539,7 +538,7 @@ public DatabaseResolver(final Path database, final Path asnDatabase, final NodeC * @since 2.2.0 */ public DatabaseResolver(final Path database, final Path asnDatabase, final Reader.FileMode fileMode) - throws IOException{ + throws IOException { this(database == null ? null : database.toFile(), asnDatabase == null ? null : asnDatabase.toFile(), fileMode); } @@ -561,7 +560,7 @@ public DatabaseResolver(final Path database, final Path asnDatabase, final Reade */ public DatabaseResolver(final Path database, final Path asnDatabase, final Reader.FileMode fileMode, final NodeCache cache) - throws IOException{ + throws IOException { this(database == null ? null : database.toFile(), asnDatabase == null ? null : asnDatabase.toFile(), fileMode, cache); } @@ -578,7 +577,7 @@ public DatabaseResolver(final Path database, final Path asnDatabase, final Reade * IO 错误 * @since 2.2.0 */ - public DatabaseResolver(final InputStream source, final InputStream asnSource) throws IOException{ + public DatabaseResolver(final InputStream source, final InputStream asnSource) throws IOException { this(source); Assert.isNull(asnSource, "ASN database stream could not be null."); this.asnReader = new DatabaseReader.Builder(asnSource).build(); @@ -599,7 +598,7 @@ public DatabaseResolver(final InputStream source, final InputStream asnSource) t * @since 2.2.0 */ public DatabaseResolver(final InputStream source, final InputStream asnSource, final NodeCache cache) - throws IOException{ + throws IOException { this(source, cache); Assert.isNull(asnSource, "ASN database stream could not be null."); this.asnReader = new DatabaseReader.Builder(asnSource).withCache(cache).build(); @@ -620,7 +619,7 @@ public DatabaseResolver(final InputStream source, final InputStream asnSource, f * @since 2.2.0 */ public DatabaseResolver(final InputStream source, final InputStream asnSource, final Reader.FileMode fileMode) - throws IOException{ + throws IOException { this(source, fileMode); Assert.isNull(asnSource, "ASN database stream could not be null."); this.asnReader = new DatabaseReader.Builder(asnSource).fileMode(fileMode).build(); @@ -644,14 +643,14 @@ public DatabaseResolver(final InputStream source, final InputStream asnSource, f */ public DatabaseResolver(final InputStream source, final InputStream asnSource, final Reader.FileMode fileMode, final NodeCache cache) - throws IOException{ + throws IOException { this(source, fileMode, cache); Assert.isNull(asnSource, "ASN database stream could not be null."); this.asnReader = new DatabaseReader.Builder(asnSource).fileMode(fileMode).withCache(cache).build(); } @Override - public Country country(InetAddress ipAddress, Locale locale) throws IOException, GeoIp2Exception{ + public Country country(InetAddress ipAddress, Locale locale) throws IOException, GeoIp2Exception { final CountryConverter countryConverter = new CountryConverter(); final CountryResponse response = reader.country(ipAddress); @@ -659,7 +658,7 @@ public Country country(InetAddress ipAddress, Locale locale) throws IOException, } @Override - public District district(InetAddress ipAddress, Locale locale) throws IOException, GeoIp2Exception{ + public District district(InetAddress ipAddress, Locale locale) throws IOException, GeoIp2Exception { final CityConverter cityConverter = new CityConverter(); final CityResponse response = reader.city(ipAddress); @@ -667,7 +666,7 @@ public District district(InetAddress ipAddress, Locale locale) throws IOExceptio } @Override - public Location location(InetAddress ipAddress, Locale locale) throws IOException, GeoIp2Exception{ + public Location location(InetAddress ipAddress, Locale locale) throws IOException, GeoIp2Exception { final CountryConverter countryConverter = new CountryConverter(); final CityConverter cityConverter = new CityConverter(); final ContinentConverter continentConverter = new ContinentConverter(); @@ -690,18 +689,18 @@ public Location location(InetAddress ipAddress, Locale locale) throws IOExceptio } @Override - public Metadata getMetadata(){ + public Metadata getMetadata() { return reader.getMetadata(); } @Override - public void close() throws IOException{ + public void close() throws IOException { if(reader != null){ reader.close(); } } - protected static DatabaseReader.Builder getDefaultAsnReaderBuilder(){ + protected static DatabaseReader.Builder getDefaultAsnReaderBuilder() { return new DatabaseReader.Builder(DatabaseResolver.class.getResourceAsStream(DEFAULT_ASN_DB)); } diff --git a/buession-geoip/src/main/java/com/buession/geoip/spring/GeoIPResolverFactory.java b/buession-geoip/src/main/java/com/buession/geoip/spring/GeoIPResolverFactory.java index 761655680..d0a6a76cd 100644 --- a/buession-geoip/src/main/java/com/buession/geoip/spring/GeoIPResolverFactory.java +++ b/buession-geoip/src/main/java/com/buession/geoip/spring/GeoIPResolverFactory.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.geoip.spring; @@ -30,7 +30,6 @@ import org.springframework.core.io.Resource; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.file.Path; @@ -66,12 +65,6 @@ public class GeoIPResolverFactory { */ private InputStream asnStream; - /** - * IP 库加载模式 - */ - @Deprecated - private LoadMode loadMode = LoadMode.STREAM; - /** * 是否开启缓存 */ @@ -85,7 +78,7 @@ public class GeoIPResolverFactory { * @throws IOException * 数据库文件不存在时 */ - public File getDbPath() throws IOException{ + public File getDbPath() throws IOException { if(dbPath == null){ dbPath = new File(DatabaseResolver.class.getResource(DatabaseResolver.DEFAULT_CITY_DB).getFile()); } @@ -102,7 +95,7 @@ public File getDbPath() throws IOException{ * @throws IOException * 数据库文件不存在时 */ - public void setDbPath(Resource dbPath) throws IOException{ + public void setDbPath(Resource dbPath) throws IOException { Assert.isNull(dbPath, "Ip database path cloud not be null."); this.dbPath = dbPath.getFile(); } @@ -116,7 +109,7 @@ public void setDbPath(Resource dbPath) throws IOException{ * @throws IOException * 数据库文件不存在时 */ - public void setDbPath(File dbPath) throws IOException{ + public void setDbPath(File dbPath) throws IOException { Assert.isNull(dbPath, "Ip database path cloud not be null."); this.dbPath = dbPath; } @@ -130,7 +123,7 @@ public void setDbPath(File dbPath) throws IOException{ * @throws IOException * 数据库文件不存在时 */ - public void setDbPath(Path dbPath) throws IOException{ + public void setDbPath(Path dbPath) throws IOException { Assert.isNull(dbPath, "Ip database path cloud not be null."); this.dbPath = dbPath.toFile(); } @@ -144,7 +137,7 @@ public void setDbPath(Path dbPath) throws IOException{ * @throws IOException * 数据库文件不存在时 */ - public void setDbPath(String dbPath) throws IOException{ + public void setDbPath(String dbPath) throws IOException { Assert.isBlank(dbPath, "Ip database path cloud not be null or empty."); setDbPath(new File(dbPath)); } @@ -158,7 +151,7 @@ public void setDbPath(String dbPath) throws IOException{ * ASN 库文件不存在时 * @since 2.2.0 */ - public File getAsnDbPath() throws IOException{ + public File getAsnDbPath() throws IOException { if(asnDbPath == null){ asnDbPath = new File(DatabaseResolver.class.getResource(DatabaseResolver.DEFAULT_ASN_DB).getFile()); } @@ -176,7 +169,7 @@ public File getAsnDbPath() throws IOException{ * ASN 库文件不存在时 * @since 2.2.0 */ - public void setAsnDbPath(Resource asnDbPath) throws IOException{ + public void setAsnDbPath(Resource asnDbPath) throws IOException { Assert.isNull(asnDbPath, "Ip asn database path cloud not be null."); this.asnDbPath = asnDbPath.getFile(); } @@ -191,7 +184,7 @@ public void setAsnDbPath(Resource asnDbPath) throws IOException{ * ASN 库文件不存在时 * @since 2.2.0 */ - public void setAsnDbPath(File asnDbPath) throws IOException{ + public void setAsnDbPath(File asnDbPath) throws IOException { Assert.isNull(asnDbPath, "Ip asn database path cloud not be null."); this.asnDbPath = asnDbPath; } @@ -206,7 +199,7 @@ public void setAsnDbPath(File asnDbPath) throws IOException{ * 数据库文件不存在时 * @since 2.2.0 */ - public void setAsnDbPath(Path asnDbPath) throws IOException{ + public void setAsnDbPath(Path asnDbPath) throws IOException { Assert.isNull(asnDbPath, "Ip asn database path cloud not be null."); this.asnDbPath = asnDbPath.toFile(); } @@ -221,7 +214,7 @@ public void setAsnDbPath(Path asnDbPath) throws IOException{ * 数据库文件不存在时 * @since 2.2.0 */ - public void setAsnDbPath(String asnDbPath) throws IOException{ + public void setAsnDbPath(String asnDbPath) throws IOException { Assert.isBlank(asnDbPath, "Ip asn database path cloud not be null or empty."); setAsnDbPath(new File(asnDbPath)); } @@ -234,7 +227,7 @@ public void setAsnDbPath(String asnDbPath) throws IOException{ * @throws IOException * 数据库文件不存在时 */ - public InputStream getStream() throws IOException{ + public InputStream getStream() throws IOException { if(stream == null){ stream = DatabaseResolver.class.getResourceAsStream(DatabaseResolver.DEFAULT_CITY_DB); } @@ -248,7 +241,7 @@ public InputStream getStream() throws IOException{ * @param stream * IP 库文件流 */ - public void setStream(InputStream stream){ + public void setStream(InputStream stream) { Assert.isNull(stream, "Ip database stream cloud not be null."); this.stream = stream; } @@ -262,7 +255,7 @@ public void setStream(InputStream stream){ * ASN 库文件不存在时 * @since 2.2.0 */ - public InputStream getAsnStream() throws IOException{ + public InputStream getAsnStream() throws IOException { if(asnStream == null){ asnStream = DatabaseResolver.class.getResourceAsStream(DatabaseResolver.DEFAULT_ASN_DB); } @@ -278,27 +271,17 @@ public InputStream getAsnStream() throws IOException{ * * @since 2.2.0 */ - public void setAsnStream(InputStream asnStream){ + public void setAsnStream(InputStream asnStream) { Assert.isNull(asnStream, "Ip asn database stream cloud not be null."); this.asnStream = asnStream; } - /** - * 返回 IP 库加载模式 - * - * @return IP 库加载模式 - */ - @Deprecated - public LoadMode getLoadMode(){ - return loadMode; - } - /** * 返回是否开启缓存 * * @return 是否开启缓存 */ - public boolean isEnableCache(){ + public boolean isEnableCache() { return enableCache; } @@ -308,7 +291,7 @@ public boolean isEnableCache(){ * @param enableCache * 是否开启缓存 */ - public void setEnableCache(boolean enableCache){ + public void setEnableCache(boolean enableCache) { this.enableCache = enableCache; } diff --git a/buession-geoip/src/test/java/com/buession/geoip/DatabaseResolverTest.java b/buession-geoip/src/test/java/com/buession/geoip/DatabaseResolverTest.java index 6bcfbab7b..e4e5d241e 100644 --- a/buession-geoip/src/test/java/com/buession/geoip/DatabaseResolverTest.java +++ b/buession-geoip/src/test/java/com/buession/geoip/DatabaseResolverTest.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.geoip; @@ -28,7 +28,7 @@ import com.buession.geoip.model.District; import com.buession.geoip.model.Location; import com.buession.geoip.spring.GeoIPResolverFactoryBean; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Yong.Teng @@ -37,7 +37,7 @@ public class DatabaseResolverTest { @Test - public void country() throws Exception{ + public void country() throws Exception { DatabaseResolver resolver = new DatabaseResolver( DatabaseResolver.class.getResourceAsStream("/maxmind/City.mmdb")); Country country = resolver.country("114.114.114.114"); @@ -45,7 +45,7 @@ public void country() throws Exception{ } @Test - public void country1() throws Exception{ + public void country1() throws Exception { DatabaseResolver resolver = new DatabaseResolver( DatabaseResolver.class.getResourceAsStream("/maxmind/City.mmdb")); Country country = resolver.country(3739974408L); @@ -53,7 +53,7 @@ public void country1() throws Exception{ } @Test - public void country2() throws Exception{ + public void country2() throws Exception { GeoIPResolverFactoryBean factoryBean = new GeoIPResolverFactoryBean(); factoryBean.afterPropertiesSet(); @@ -64,7 +64,7 @@ public void country2() throws Exception{ } @Test - public void country3() throws Exception{ + public void country3() throws Exception { DatabaseResolver resolver = new CacheDatabaseResolver( DatabaseResolver.class.getResourceAsStream("/maxmind/City.mmdb")); Country country = resolver.country(3739974408L); @@ -72,7 +72,7 @@ public void country3() throws Exception{ } @Test - public void district() throws Exception{ + public void district() throws Exception { DatabaseResolver resolver = new DatabaseResolver( DatabaseResolver.class.getResourceAsStream("/maxmind/City.mmdb")); District district = resolver.district("114.114.114.114"); @@ -80,7 +80,7 @@ public void district() throws Exception{ } @Test - public void district1() throws Exception{ + public void district1() throws Exception { DatabaseResolver resolver = new DatabaseResolver( DatabaseResolver.class.getResourceAsStream("/maxmind/City.mmdb")); District district = resolver.district(3739974408L); @@ -88,7 +88,7 @@ public void district1() throws Exception{ } @Test - public void location() throws Exception{ + public void location() throws Exception { DatabaseResolver resolver = new DatabaseResolver( DatabaseResolver.class.getResourceAsStream("/maxmind/City.mmdb")); Location location = resolver.location("1.11.64.11"); @@ -96,7 +96,7 @@ public void location() throws Exception{ } @Test - public void location1() throws Exception{ + public void location1() throws Exception { DatabaseResolver resolver = new DatabaseResolver( DatabaseResolver.class.getResourceAsStream("/maxmind/City.mmdb")); Location location = resolver.location(3739974408L); diff --git a/buession-git/pom.xml b/buession-git/pom.xml index 6d8aaf9dd..5541831f7 100644 --- a/buession-git/pom.xml +++ b/buession-git/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-git http://www.buession.com/ @@ -70,8 +70,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -115,8 +115,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-git/src/test/java/com/buession/git/GitTest.java b/buession-git/src/test/java/com/buession/git/GitTest.java index ee5f63016..01386ad05 100644 --- a/buession-git/src/test/java/com/buession/git/GitTest.java +++ b/buession-git/src/test/java/com/buession/git/GitTest.java @@ -19,14 +19,14 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.git; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Yong.Teng @@ -35,7 +35,7 @@ public class GitTest { @Test - public void gitToString(){ + public void gitToString() { Git git = new Git(); git.setBranch("master"); @@ -47,14 +47,14 @@ public void gitToString(){ } @Test - public void buildToString(){ + public void buildToString() { Build build = new Build(); System.out.println(build.toString()); } @Test - public void gitJsonEncode() throws JsonProcessingException{ + public void gitJsonEncode() throws JsonProcessingException { Git git = new Git(); git.setBranch("master"); @@ -74,7 +74,7 @@ public void gitJsonEncode() throws JsonProcessingException{ } @Test - public void totalJsonEncode() throws JsonProcessingException{ + public void totalJsonEncode() throws JsonProcessingException { Total total = new Total(); ObjectMapper objectMapper = new ObjectMapper(); diff --git a/buession-httpclient/pom.xml b/buession-httpclient/pom.xml index 6ed3a523e..6d8c4e0af 100644 --- a/buession-httpclient/pom.xml +++ b/buession-httpclient/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-httpclient http://www.buession.com/ @@ -67,12 +67,7 @@ com.buession buession-io ${project.version} - - - org.apache.tika - tika-core - - + provided com.buession @@ -114,6 +109,16 @@ httpasyncclient provided + + org.apache.httpcomponents.core5 + httpcore5 + provided + + + org.apache.httpcomponents.client5 + httpclient5 + provided + com.squareup.okhttp3 @@ -149,8 +154,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -194,8 +199,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/AbstractBaseHttpClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/AbstractBaseHttpClient.java index 0fdf1fe38..1c2c42bf6 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/AbstractBaseHttpClient.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/AbstractBaseHttpClient.java @@ -19,29 +19,33 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient; -import com.buession.core.utils.Assert; -import com.buession.httpclient.conn.ConnectionManager; +import com.buession.httpclient.conn.IConnectionManager; import com.buession.httpclient.core.ProtocolVersion; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; - /** * HttpClient 基类 * + * @param + * 连接管理器类型 + * * @author Yong.Teng * @since 2.3.0 */ -abstract class AbstractBaseHttpClient implements IBaseHttpClient { +abstract class AbstractBaseHttpClient implements IBaseHttpClient, IHttpClient { - private ConnectionManager connectionManager; + /** + * 连接管理器 + */ + private CM connectionManager; + /** + * HTTP 协议版本 + */ private ProtocolVersion httpVersion; /** @@ -56,17 +60,26 @@ public AbstractBaseHttpClient() { * @param connectionManager * 连接管理器 */ - public AbstractBaseHttpClient(ConnectionManager connectionManager) { + public AbstractBaseHttpClient(CM connectionManager) { this.connectionManager = connectionManager; } - @Override - public ConnectionManager getConnectionManager() { + /** + * 返回连接管理器 + * + * @return 连接管理器 + */ + public CM getConnectionManager() { return connectionManager; } - @Override - public void setConnectionManager(ConnectionManager connectionManager) { + /** + * 设置连接管理器 + * + * @param connectionManager + * 连接管理器 + */ + public void setConnectionManager(CM connectionManager) { this.connectionManager = connectionManager; } @@ -80,9 +93,4 @@ public void setHttpVersion(ProtocolVersion httpVersion) { this.httpVersion = httpVersion; } - protected static URI URL2URI(final URL url) throws URISyntaxException { - Assert.isNull(url, "Request URL cloud not be null."); - return url.toURI(); - } - } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpAsyncClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpAsyncClient.java index 78b47c0e1..60d208650 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpAsyncClient.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpAsyncClient.java @@ -19,13 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient; import com.buession.core.utils.Assert; -import com.buession.httpclient.conn.ConnectionManager; +import com.buession.httpclient.conn.NioConnectionManager; import com.buession.httpclient.core.Header; import com.buession.httpclient.core.RequestBody; import com.buession.httpclient.core.RequestMethod; @@ -45,7 +45,8 @@ * @author Yong.Teng * @since 2.3.0 */ -public abstract class AbstractHttpAsyncClient extends AbstractBaseHttpClient implements HttpAsyncClient { +public abstract class AbstractHttpAsyncClient extends AbstractBaseHttpClient + implements HttpAsyncClient { /** * 构造函数 @@ -60,7 +61,7 @@ public AbstractHttpAsyncClient() { * @param connectionManager * 连接管理器 */ - public AbstractHttpAsyncClient(ConnectionManager connectionManager) { + public AbstractHttpAsyncClient(NioConnectionManager connectionManager) { super(connectionManager); } @@ -71,7 +72,7 @@ public void get(URI uri, Callback callback) throws IOException, RequestException @Override public void get(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->get(URL2URI(url), null, null, callback)); + asyncExecute(()->get(url.toURI(), null, null, callback)); } @Override @@ -81,7 +82,7 @@ public void get(URI uri, Map parameters, Callback callback) thro @Override public void get(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->get(URL2URI(url), parameters, null, callback)); + asyncExecute(()->get(url.toURI(), parameters, null, callback)); } @Override @@ -91,13 +92,13 @@ public void get(URI uri, List
headers, Callback callback) throws IOExcep @Override public void get(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->get(URL2URI(url), null, headers, callback)); + asyncExecute(()->get(url.toURI(), null, headers, callback)); } @Override public void get(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->get(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->get(url.toURI(), parameters, headers, callback)); } @Override @@ -107,7 +108,7 @@ public void get(URI uri, int readTimeout, Callback callback) throws IOException, @Override public void get(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->get(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->get(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -119,7 +120,7 @@ public void get(URI uri, int readTimeout, Map parameters, Callba @Override public void get(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->get(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->get(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -131,13 +132,13 @@ public void get(URI uri, int readTimeout, List
headers, Callback callbac @Override public void get(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->get(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->get(url.toURI(), readTimeout, null, headers, callback)); } @Override public void get(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->get(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->get(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -147,7 +148,7 @@ public void post(URI uri, Callback callback) throws IOException, RequestExceptio @Override public void post(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), null, null, null, callback)); + asyncExecute(()->post(url.toURI(), null, null, null, callback)); } @Override @@ -157,7 +158,7 @@ public void post(URI uri, Map parameters, Callback callback) thr @Override public void post(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), null, parameters, null, callback)); + asyncExecute(()->post(url.toURI(), null, parameters, null, callback)); } @Override @@ -167,7 +168,7 @@ public void post(URI uri, List
headers, Callback callback) throws IOExce @Override public void post(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), null, null, headers, callback)); + asyncExecute(()->post(url.toURI(), null, null, headers, callback)); } @Override @@ -179,7 +180,7 @@ public void post(URI uri, Map parameters, List
headers, @Override public void post(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), null, parameters, headers, callback)); + asyncExecute(()->post(url.toURI(), null, parameters, headers, callback)); } @Override @@ -189,7 +190,7 @@ public void post(URI uri, RequestBody data, Callback callback) throws IOExcep @Override public void post(URL url, RequestBody data, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), data, null, null, callback)); + asyncExecute(()->post(url.toURI(), data, null, null, callback)); } @Override @@ -201,7 +202,7 @@ public void post(URI uri, RequestBody data, Map parameters, C @Override public void post(URL url, RequestBody data, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), data, parameters, null, callback)); + asyncExecute(()->post(url.toURI(), data, parameters, null, callback)); } @Override @@ -213,13 +214,13 @@ public void post(URI uri, RequestBody data, List
headers, Callback ca @Override public void post(URL url, RequestBody data, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), data, null, headers, callback)); + asyncExecute(()->post(url.toURI(), data, null, headers, callback)); } @Override public void post(URL url, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), data, parameters, headers, callback)); + asyncExecute(()->post(url.toURI(), data, parameters, headers, callback)); } @Override @@ -229,7 +230,7 @@ public void post(URI uri, int readTimeout, Callback callback) throws IOException @Override public void post(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), readTimeout, null, null, null, callback)); + asyncExecute(()->post(url.toURI(), readTimeout, null, null, null, callback)); } @Override @@ -241,7 +242,7 @@ public void post(URI uri, int readTimeout, Map parameters, Callb @Override public void post(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), readTimeout, null, parameters, null, callback)); + asyncExecute(()->post(url.toURI(), readTimeout, null, parameters, null, callback)); } @Override @@ -253,7 +254,7 @@ public void post(URI uri, int readTimeout, List
headers, Callback callba @Override public void post(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), readTimeout, null, null, headers, callback)); + asyncExecute(()->post(url.toURI(), readTimeout, null, null, headers, callback)); } @Override @@ -265,7 +266,7 @@ public void post(URI uri, int readTimeout, Map parameters, List< @Override public void post(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), readTimeout, null, parameters, headers, callback)); + asyncExecute(()->post(url.toURI(), readTimeout, null, parameters, headers, callback)); } @Override @@ -277,7 +278,7 @@ public void post(URI uri, int readTimeout, RequestBody data, Callback callbac @Override public void post(URL url, int readTimeout, RequestBody data, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), readTimeout, data, null, null, callback)); + asyncExecute(()->post(url.toURI(), readTimeout, data, null, null, callback)); } @Override @@ -289,7 +290,7 @@ public void post(URI uri, int readTimeout, RequestBody data, Map data, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), readTimeout, data, parameters, null, callback)); + asyncExecute(()->post(url.toURI(), readTimeout, data, parameters, null, callback)); } @Override @@ -301,13 +302,13 @@ public void post(URI uri, int readTimeout, RequestBody data, List
hea @Override public void post(URL url, int readTimeout, RequestBody data, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), readTimeout, data, null, headers, callback)); + asyncExecute(()->post(url.toURI(), readTimeout, data, null, headers, callback)); } @Override public void post(URL url, int readTimeout, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->post(URL2URI(url), readTimeout, data, parameters, headers, callback)); + asyncExecute(()->post(url.toURI(), readTimeout, data, parameters, headers, callback)); } @Override @@ -317,7 +318,7 @@ public void put(URI uri, Callback callback) throws IOException, RequestException @Override public void put(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), null, null, null, callback)); + asyncExecute(()->put(url.toURI(), null, null, null, callback)); } @Override @@ -327,7 +328,7 @@ public void put(URI uri, Map parameters, Callback callback) thro @Override public void put(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), null, parameters, null, callback)); + asyncExecute(()->put(url.toURI(), null, parameters, null, callback)); } @Override @@ -337,7 +338,7 @@ public void put(URI uri, List
headers, Callback callback) throws IOExcep @Override public void put(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), null, null, headers, callback)); + asyncExecute(()->put(url.toURI(), null, null, headers, callback)); } @Override @@ -349,7 +350,7 @@ public void put(URI uri, Map parameters, List
headers, C @Override public void put(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), null, parameters, headers, callback)); + asyncExecute(()->put(url.toURI(), null, parameters, headers, callback)); } @Override @@ -359,7 +360,7 @@ public void put(URI uri, RequestBody data, Callback callback) throws IOExcept @Override public void put(URL url, RequestBody data, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), data, null, null, callback)); + asyncExecute(()->put(url.toURI(), data, null, null, callback)); } @Override @@ -371,7 +372,7 @@ public void put(URI uri, RequestBody data, Map parameters, Ca @Override public void put(URL url, RequestBody data, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), data, parameters, null, callback)); + asyncExecute(()->put(url.toURI(), data, parameters, null, callback)); } @Override @@ -383,13 +384,13 @@ public void put(URI uri, RequestBody data, List
headers, Callback cal @Override public void put(URL url, RequestBody data, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), data, null, headers, callback)); + asyncExecute(()->put(url.toURI(), data, null, headers, callback)); } @Override public void put(URL url, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), data, parameters, headers, callback)); + asyncExecute(()->put(url.toURI(), data, parameters, headers, callback)); } @Override @@ -399,7 +400,7 @@ public void put(URI uri, int readTimeout, Callback callback) throws IOException, @Override public void put(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), readTimeout, null, null, null, callback)); + asyncExecute(()->put(url.toURI(), readTimeout, null, null, null, callback)); } @Override @@ -411,7 +412,7 @@ public void put(URI uri, int readTimeout, Map parameters, Callba @Override public void put(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), readTimeout, null, parameters, null, callback)); + asyncExecute(()->put(url.toURI(), readTimeout, null, parameters, null, callback)); } @Override @@ -423,7 +424,7 @@ public void put(URI uri, int readTimeout, List
headers, Callback callbac @Override public void put(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), readTimeout, null, null, headers, callback)); + asyncExecute(()->put(url.toURI(), readTimeout, null, null, headers, callback)); } @Override @@ -435,7 +436,7 @@ public void put(URI uri, int readTimeout, Map parameters, List parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->put(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -447,7 +448,7 @@ public void put(URI uri, int readTimeout, RequestBody data, Callback callback @Override public void put(URL url, int readTimeout, RequestBody data, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), readTimeout, data, null, null, callback)); + asyncExecute(()->put(url.toURI(), readTimeout, data, null, null, callback)); } @Override @@ -459,7 +460,7 @@ public void put(URI uri, int readTimeout, RequestBody data, Map data, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), readTimeout, data, parameters, null, callback)); + asyncExecute(()->put(url.toURI(), readTimeout, data, parameters, null, callback)); } @Override @@ -471,13 +472,13 @@ public void put(URI uri, int readTimeout, RequestBody data, List
head @Override public void put(URL url, int readTimeout, RequestBody data, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), readTimeout, data, null, headers, callback)); + asyncExecute(()->put(url.toURI(), readTimeout, data, null, headers, callback)); } @Override public void put(URL url, int readTimeout, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->put(URL2URI(url), readTimeout, data, parameters, headers, callback)); + asyncExecute(()->put(url.toURI(), readTimeout, data, parameters, headers, callback)); } @Override @@ -487,7 +488,7 @@ public void patch(URI uri, Callback callback) throws IOException, RequestExcepti @Override public void patch(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), null, null, null, callback)); + asyncExecute(()->patch(url.toURI(), null, null, null, callback)); } @Override @@ -497,7 +498,7 @@ public void patch(URI uri, Map parameters, Callback callback) th @Override public void patch(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), null, parameters, null, callback)); + asyncExecute(()->patch(url.toURI(), null, parameters, null, callback)); } @Override @@ -507,7 +508,7 @@ public void patch(URI uri, List
headers, Callback callback) throws IOExc @Override public void patch(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), null, null, headers, callback)); + asyncExecute(()->patch(url.toURI(), null, null, headers, callback)); } @Override @@ -519,7 +520,7 @@ public void patch(URI uri, Map parameters, List
headers, @Override public void patch(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), null, parameters, headers, callback)); + asyncExecute(()->patch(url.toURI(), null, parameters, headers, callback)); } @Override @@ -529,7 +530,7 @@ public void patch(URI uri, RequestBody data, Callback callback) throws IOExce @Override public void patch(URL url, RequestBody data, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), data, null, null, callback)); + asyncExecute(()->patch(url.toURI(), data, null, null, callback)); } @Override @@ -541,7 +542,7 @@ public void patch(URI uri, RequestBody data, Map parameters, @Override public void patch(URL url, RequestBody data, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), data, parameters, null, callback)); + asyncExecute(()->patch(url.toURI(), data, parameters, null, callback)); } @Override @@ -553,13 +554,13 @@ public void patch(URI uri, RequestBody data, List
headers, Callback c @Override public void patch(URL url, RequestBody data, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), data, null, headers, callback)); + asyncExecute(()->patch(url.toURI(), data, null, headers, callback)); } @Override public void patch(URL url, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), data, parameters, headers, callback)); + asyncExecute(()->patch(url.toURI(), data, parameters, headers, callback)); } @Override @@ -569,7 +570,7 @@ public void patch(URI uri, int readTimeout, Callback callback) throws IOExceptio @Override public void patch(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), readTimeout, null, null, null, callback)); + asyncExecute(()->patch(url.toURI(), readTimeout, null, null, null, callback)); } @Override @@ -581,7 +582,7 @@ public void patch(URI uri, int readTimeout, Map parameters, Call @Override public void patch(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), readTimeout, null, parameters, null, callback)); + asyncExecute(()->patch(url.toURI(), readTimeout, null, parameters, null, callback)); } @Override @@ -593,7 +594,7 @@ public void patch(URI uri, int readTimeout, List
headers, Callback callb @Override public void patch(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), readTimeout, null, null, headers, callback)); + asyncExecute(()->patch(url.toURI(), readTimeout, null, null, headers, callback)); } @Override @@ -605,7 +606,7 @@ public void patch(URI uri, int readTimeout, Map parameters, List @Override public void patch(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), readTimeout, null, parameters, headers, callback)); + asyncExecute(()->patch(url.toURI(), readTimeout, null, parameters, headers, callback)); } @Override @@ -617,7 +618,7 @@ public void patch(URI uri, int readTimeout, RequestBody data, Callback callba @Override public void patch(URL url, int readTimeout, RequestBody data, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), readTimeout, data, null, null, callback)); + asyncExecute(()->patch(url.toURI(), readTimeout, data, null, null, callback)); } @Override @@ -629,7 +630,7 @@ public void patch(URI uri, int readTimeout, RequestBody data, Map data, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), readTimeout, data, parameters, null, callback)); + asyncExecute(()->patch(url.toURI(), readTimeout, data, parameters, null, callback)); } @Override @@ -641,13 +642,13 @@ public void patch(URI uri, int readTimeout, RequestBody data, List
he @Override public void patch(URL url, int readTimeout, RequestBody data, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), readTimeout, data, null, headers, callback)); + asyncExecute(()->patch(url.toURI(), readTimeout, data, null, headers, callback)); } @Override public void patch(URL url, int readTimeout, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->patch(URL2URI(url), readTimeout, data, parameters, headers, callback)); + asyncExecute(()->patch(url.toURI(), readTimeout, data, parameters, headers, callback)); } @Override @@ -657,7 +658,7 @@ public void delete(URI uri, Callback callback) throws IOException, RequestExcept @Override public void delete(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->delete(URL2URI(url), null, null, callback)); + asyncExecute(()->delete(url.toURI(), null, null, callback)); } @Override @@ -669,7 +670,7 @@ public void delete(URI uri, Map parameters, Callback callback) @Override public void delete(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->delete(URL2URI(url), parameters, null, callback)); + asyncExecute(()->delete(url.toURI(), parameters, null, callback)); } @Override @@ -679,13 +680,13 @@ public void delete(URI uri, List
headers, Callback callback) throws IOEx @Override public void delete(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->delete(URL2URI(url), null, headers, callback)); + asyncExecute(()->delete(url.toURI(), null, headers, callback)); } @Override public void delete(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->delete(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->delete(url.toURI(), parameters, headers, callback)); } @Override @@ -695,7 +696,7 @@ public void delete(URI uri, int readTimeout, Callback callback) throws IOExcepti @Override public void delete(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->delete(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->delete(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -707,7 +708,7 @@ public void delete(URI uri, int readTimeout, Map parameters, Cal @Override public void delete(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->delete(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->delete(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -719,13 +720,13 @@ public void delete(URI uri, int readTimeout, List
headers, Callback call @Override public void delete(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->delete(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->delete(url.toURI(), readTimeout, null, headers, callback)); } @Override public void delete(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->delete(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->delete(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -735,7 +736,7 @@ public void connect(URI uri, Callback callback) throws IOException, RequestExcep @Override public void connect(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->connect(URL2URI(url), null, null, callback)); + asyncExecute(()->connect(url.toURI(), null, null, callback)); } @Override @@ -747,7 +748,7 @@ public void connect(URI uri, Map parameters, Callback callback) @Override public void connect(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->connect(URL2URI(url), parameters, null, callback)); + asyncExecute(()->connect(url.toURI(), parameters, null, callback)); } @Override @@ -757,13 +758,13 @@ public void connect(URI uri, List
headers, Callback callback) throws IOE @Override public void connect(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->connect(URL2URI(url), null, headers, callback)); + asyncExecute(()->connect(url.toURI(), null, headers, callback)); } @Override public void connect(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->connect(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->connect(url.toURI(), parameters, headers, callback)); } @Override @@ -773,7 +774,7 @@ public void connect(URI uri, int readTimeout, Callback callback) throws IOExcept @Override public void connect(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->connect(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->connect(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -785,7 +786,7 @@ public void connect(URI uri, int readTimeout, Map parameters, Ca @Override public void connect(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->connect(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->connect(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -797,13 +798,13 @@ public void connect(URI uri, int readTimeout, List
headers, Callback cal @Override public void connect(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->connect(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->connect(url.toURI(), readTimeout, null, headers, callback)); } @Override public void connect(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->connect(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->connect(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -813,7 +814,7 @@ public void trace(URI uri, Callback callback) throws IOException, RequestExcepti @Override public void trace(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->trace(URL2URI(url), null, null, callback)); + asyncExecute(()->trace(url.toURI(), null, null, callback)); } @Override @@ -823,7 +824,7 @@ public void trace(URI uri, Map parameters, Callback callback) th @Override public void trace(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->trace(URL2URI(url), parameters, null, callback)); + asyncExecute(()->trace(url.toURI(), parameters, null, callback)); } @Override @@ -833,13 +834,13 @@ public void trace(URI uri, List
headers, Callback callback) throws IOExc @Override public void trace(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->trace(URL2URI(url), null, headers, callback)); + asyncExecute(()->trace(url.toURI(), null, headers, callback)); } @Override public void trace(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->trace(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->trace(url.toURI(), parameters, headers, callback)); } @Override @@ -849,7 +850,7 @@ public void trace(URI uri, int readTimeout, Callback callback) throws IOExceptio @Override public void trace(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->trace(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->trace(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -861,7 +862,7 @@ public void trace(URI uri, int readTimeout, Map parameters, Call @Override public void trace(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->trace(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->trace(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -873,13 +874,13 @@ public void trace(URI uri, int readTimeout, List
headers, Callback callb @Override public void trace(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->trace(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->trace(url.toURI(), readTimeout, null, headers, callback)); } @Override public void trace(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->trace(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->trace(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -889,7 +890,7 @@ public void copy(URI uri, Callback callback) throws IOException, RequestExceptio @Override public void copy(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->copy(URL2URI(url), null, null, callback)); + asyncExecute(()->copy(url.toURI(), null, null, callback)); } @Override @@ -899,7 +900,7 @@ public void copy(URI uri, Map parameters, Callback callback) thr @Override public void copy(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->copy(URL2URI(url), parameters, null, callback)); + asyncExecute(()->copy(url.toURI(), parameters, null, callback)); } @Override @@ -909,13 +910,13 @@ public void copy(URI uri, List
headers, Callback callback) throws IOExce @Override public void copy(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->copy(URL2URI(url), null, headers, callback)); + asyncExecute(()->copy(url.toURI(), null, headers, callback)); } @Override public void copy(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->copy(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->copy(url.toURI(), parameters, headers, callback)); } @Override @@ -925,7 +926,7 @@ public void copy(URI uri, int readTimeout, Callback callback) throws IOException @Override public void copy(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->copy(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->copy(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -937,7 +938,7 @@ public void copy(URI uri, int readTimeout, Map parameters, Callb @Override public void copy(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->copy(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->copy(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -949,13 +950,13 @@ public void copy(URI uri, int readTimeout, List
headers, Callback callba @Override public void copy(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->copy(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->copy(url.toURI(), readTimeout, null, headers, callback)); } @Override public void copy(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->copy(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->copy(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -965,7 +966,7 @@ public void move(URI uri, Callback callback) throws IOException, RequestExceptio @Override public void move(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->move(URL2URI(url), null, null, callback)); + asyncExecute(()->move(url.toURI(), null, null, callback)); } @Override @@ -975,7 +976,7 @@ public void move(URI uri, Map parameters, Callback callback) thr @Override public void move(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->move(URL2URI(url), parameters, null, callback)); + asyncExecute(()->move(url.toURI(), parameters, null, callback)); } @Override @@ -985,13 +986,13 @@ public void move(URI uri, List
headers, Callback callback) throws IOExce @Override public void move(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->move(URL2URI(url), null, headers, callback)); + asyncExecute(()->move(url.toURI(), null, headers, callback)); } @Override public void move(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->move(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->move(url.toURI(), parameters, headers, callback)); } @Override @@ -1001,7 +1002,7 @@ public void move(URI uri, int readTimeout, Callback callback) throws IOException @Override public void move(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->move(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->move(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -1013,7 +1014,7 @@ public void move(URI uri, int readTimeout, Map parameters, Callb @Override public void move(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->move(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->move(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -1025,13 +1026,13 @@ public void move(URI uri, int readTimeout, List
headers, Callback callba @Override public void move(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->move(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->move(url.toURI(), readTimeout, null, headers, callback)); } @Override public void move(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->move(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->move(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -1041,7 +1042,7 @@ public void head(URI uri, Callback callback) throws IOException, RequestExceptio @Override public void head(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->head(URL2URI(url), null, null, callback)); + asyncExecute(()->head(url.toURI(), null, null, callback)); } @Override @@ -1051,7 +1052,7 @@ public void head(URI uri, Map parameters, Callback callback) thr @Override public void head(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->head(URL2URI(url), parameters, null, callback)); + asyncExecute(()->head(url.toURI(), parameters, null, callback)); } @Override @@ -1061,13 +1062,13 @@ public void head(URI uri, List
headers, Callback callback) throws IOExce @Override public void head(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->head(URL2URI(url), null, headers, callback)); + asyncExecute(()->head(url.toURI(), null, headers, callback)); } @Override public void head(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->head(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->head(url.toURI(), parameters, headers, callback)); } @Override @@ -1077,7 +1078,7 @@ public void head(URI uri, int readTimeout, Callback callback) throws IOException @Override public void head(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->head(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->head(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -1089,7 +1090,7 @@ public void head(URI uri, int readTimeout, Map parameters, Callb @Override public void head(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->head(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->head(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -1101,13 +1102,13 @@ public void head(URI uri, int readTimeout, List
headers, Callback callba @Override public void head(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->head(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->head(url.toURI(), readTimeout, null, headers, callback)); } @Override public void head(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->head(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->head(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -1117,7 +1118,7 @@ public void options(URI uri, Callback callback) throws IOException, RequestExcep @Override public void options(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->options(URL2URI(url), null, null, callback)); + asyncExecute(()->options(url.toURI(), null, null, callback)); } @Override @@ -1129,7 +1130,7 @@ public void options(URI uri, Map parameters, Callback callback) @Override public void options(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->options(URL2URI(url), parameters, null, callback)); + asyncExecute(()->options(url.toURI(), parameters, null, callback)); } @Override @@ -1139,13 +1140,13 @@ public void options(URI uri, List
headers, Callback callback) throws IOE @Override public void options(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->options(URL2URI(url), null, headers, callback)); + asyncExecute(()->options(url.toURI(), null, headers, callback)); } @Override public void options(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->options(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->options(url.toURI(), parameters, headers, callback)); } @Override @@ -1155,7 +1156,7 @@ public void options(URI uri, int readTimeout, Callback callback) throws IOExcept @Override public void options(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->options(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->options(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -1167,7 +1168,7 @@ public void options(URI uri, int readTimeout, Map parameters, Ca @Override public void options(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->options(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->options(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -1179,13 +1180,13 @@ public void options(URI uri, int readTimeout, List
headers, Callback cal @Override public void options(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->options(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->options(url.toURI(), readTimeout, null, headers, callback)); } @Override public void options(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->options(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->options(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -1195,7 +1196,7 @@ public void link(URI uri, Callback callback) throws IOException, RequestExceptio @Override public void link(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->link(URL2URI(url), null, null, callback)); + asyncExecute(()->link(url.toURI(), null, null, callback)); } @Override @@ -1205,7 +1206,7 @@ public void link(URI uri, Map parameters, Callback callback) thr @Override public void link(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->link(URL2URI(url), parameters, null, callback)); + asyncExecute(()->link(url.toURI(), parameters, null, callback)); } @Override @@ -1215,13 +1216,13 @@ public void link(URI uri, List
headers, Callback callback) throws IOExce @Override public void link(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->link(URL2URI(url), null, headers, callback)); + asyncExecute(()->link(url.toURI(), null, headers, callback)); } @Override public void link(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->link(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->link(url.toURI(), parameters, headers, callback)); } @Override @@ -1231,7 +1232,7 @@ public void link(URI uri, int readTimeout, Callback callback) throws IOException @Override public void link(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->link(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->link(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -1243,7 +1244,7 @@ public void link(URI uri, int readTimeout, Map parameters, Callb @Override public void link(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->link(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->link(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -1255,13 +1256,13 @@ public void link(URI uri, int readTimeout, List
headers, Callback callba @Override public void link(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->link(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->link(url.toURI(), readTimeout, null, headers, callback)); } @Override public void link(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->link(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->link(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -1271,7 +1272,7 @@ public void unlink(URI uri, Callback callback) throws IOException, RequestExcept @Override public void unlink(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlink(URL2URI(url), null, null, callback)); + asyncExecute(()->unlink(url.toURI(), null, null, callback)); } @Override @@ -1283,7 +1284,7 @@ public void unlink(URI uri, Map parameters, Callback callback) @Override public void unlink(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlink(URL2URI(url), parameters, null, callback)); + asyncExecute(()->unlink(url.toURI(), parameters, null, callback)); } @Override @@ -1293,13 +1294,13 @@ public void unlink(URI uri, List
headers, Callback callback) throws IOEx @Override public void unlink(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlink(URL2URI(url), null, headers, callback)); + asyncExecute(()->unlink(url.toURI(), null, headers, callback)); } @Override public void unlink(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlink(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->unlink(url.toURI(), parameters, headers, callback)); } @Override @@ -1309,7 +1310,7 @@ public void unlink(URI uri, int readTimeout, Callback callback) throws IOExcepti @Override public void unlink(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlink(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->unlink(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -1321,7 +1322,7 @@ public void unlink(URI uri, int readTimeout, Map parameters, Cal @Override public void unlink(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlink(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->unlink(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -1333,13 +1334,13 @@ public void unlink(URI uri, int readTimeout, List
headers, Callback call @Override public void unlink(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlink(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->unlink(url.toURI(), readTimeout, null, headers, callback)); } @Override public void unlink(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlink(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->unlink(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -1349,7 +1350,7 @@ public void purge(URI uri, Callback callback) throws IOException, RequestExcepti @Override public void purge(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->purge(URL2URI(url), null, null, callback)); + asyncExecute(()->purge(url.toURI(), null, null, callback)); } @Override @@ -1359,7 +1360,7 @@ public void purge(URI uri, Map parameters, Callback callback) th @Override public void purge(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->purge(URL2URI(url), parameters, null, callback)); + asyncExecute(()->purge(url.toURI(), parameters, null, callback)); } @Override @@ -1369,13 +1370,13 @@ public void purge(URI uri, List
headers, Callback callback) throws IOExc @Override public void purge(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->purge(URL2URI(url), null, headers, callback)); + asyncExecute(()->purge(url.toURI(), null, headers, callback)); } @Override public void purge(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->purge(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->purge(url.toURI(), parameters, headers, callback)); } @Override @@ -1385,7 +1386,7 @@ public void purge(URI uri, int readTimeout, Callback callback) throws IOExceptio @Override public void purge(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->purge(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->purge(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -1397,7 +1398,7 @@ public void purge(URI uri, int readTimeout, Map parameters, Call @Override public void purge(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->purge(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->purge(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -1409,13 +1410,13 @@ public void purge(URI uri, int readTimeout, List
headers, Callback callb @Override public void purge(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->purge(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->purge(url.toURI(), readTimeout, null, headers, callback)); } @Override public void purge(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->purge(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->purge(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -1425,7 +1426,7 @@ public void lock(URI uri, Callback callback) throws IOException, RequestExceptio @Override public void lock(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->lock(URL2URI(url), null, null, callback)); + asyncExecute(()->lock(url.toURI(), null, null, callback)); } @Override @@ -1435,7 +1436,7 @@ public void lock(URI uri, Map parameters, Callback callback) thr @Override public void lock(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->lock(URL2URI(url), parameters, null, callback)); + asyncExecute(()->lock(url.toURI(), parameters, null, callback)); } @Override @@ -1445,13 +1446,13 @@ public void lock(URI uri, List
headers, Callback callback) throws IOExce @Override public void lock(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->lock(URL2URI(url), null, headers, callback)); + asyncExecute(()->lock(url.toURI(), null, headers, callback)); } @Override public void lock(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->lock(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->lock(url.toURI(), parameters, headers, callback)); } @Override @@ -1461,7 +1462,7 @@ public void lock(URI uri, int readTimeout, Callback callback) throws IOException @Override public void lock(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->lock(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->lock(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -1473,7 +1474,7 @@ public void lock(URI uri, int readTimeout, Map parameters, Callb @Override public void lock(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->lock(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->lock(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -1485,13 +1486,13 @@ public void lock(URI uri, int readTimeout, List
headers, Callback callba @Override public void lock(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->lock(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->lock(url.toURI(), readTimeout, null, headers, callback)); } @Override public void lock(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->lock(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->lock(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -1501,7 +1502,7 @@ public void unlock(URI uri, Callback callback) throws IOException, RequestExcept @Override public void unlock(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlock(URL2URI(url), null, null, callback)); + asyncExecute(()->unlock(url.toURI(), null, null, callback)); } @Override @@ -1513,7 +1514,7 @@ public void unlock(URI uri, Map parameters, Callback callback) @Override public void unlock(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlock(URL2URI(url), parameters, null, callback)); + asyncExecute(()->unlock(url.toURI(), parameters, null, callback)); } @Override @@ -1523,13 +1524,13 @@ public void unlock(URI uri, List
headers, Callback callback) throws IOEx @Override public void unlock(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlock(URL2URI(url), null, headers, callback)); + asyncExecute(()->unlock(url.toURI(), null, headers, callback)); } @Override public void unlock(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlock(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->unlock(url.toURI(), parameters, headers, callback)); } @Override @@ -1539,7 +1540,7 @@ public void unlock(URI uri, int readTimeout, Callback callback) throws IOExcepti @Override public void unlock(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlock(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->unlock(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -1551,7 +1552,7 @@ public void unlock(URI uri, int readTimeout, Map parameters, Cal @Override public void unlock(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlock(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->unlock(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -1563,13 +1564,13 @@ public void unlock(URI uri, int readTimeout, List
headers, Callback call @Override public void unlock(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlock(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->unlock(url.toURI(), readTimeout, null, headers, callback)); } @Override public void unlock(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->unlock(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->unlock(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -1579,7 +1580,7 @@ public void propfind(URI uri, Callback callback) throws IOException, RequestExce @Override public void propfind(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->propfind(URL2URI(url), null, null, callback)); + asyncExecute(()->propfind(url.toURI(), null, null, callback)); } @Override @@ -1591,7 +1592,7 @@ public void propfind(URI uri, Map parameters, Callback callback) @Override public void propfind(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->propfind(URL2URI(url), parameters, null, callback)); + asyncExecute(()->propfind(url.toURI(), parameters, null, callback)); } @Override @@ -1601,13 +1602,13 @@ public void propfind(URI uri, List
headers, Callback callback) throws IO @Override public void propfind(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->propfind(URL2URI(url), null, headers, callback)); + asyncExecute(()->propfind(url.toURI(), null, headers, callback)); } @Override public void propfind(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->propfind(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->propfind(url.toURI(), parameters, headers, callback)); } @Override @@ -1617,7 +1618,7 @@ public void propfind(URI uri, int readTimeout, Callback callback) throws IOExcep @Override public void propfind(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->propfind(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->propfind(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -1629,7 +1630,7 @@ public void propfind(URI uri, int readTimeout, Map parameters, C @Override public void propfind(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->propfind(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->propfind(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -1641,13 +1642,13 @@ public void propfind(URI uri, int readTimeout, List
headers, Callback ca @Override public void propfind(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->propfind(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->propfind(url.toURI(), readTimeout, null, headers, callback)); } @Override public void propfind(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->propfind(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->propfind(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -1657,7 +1658,7 @@ public void proppatch(URI uri, Callback callback) throws IOException, RequestExc @Override public void proppatch(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), null, null, null, callback)); + asyncExecute(()->proppatch(url.toURI(), null, null, null, callback)); } @Override @@ -1669,7 +1670,7 @@ public void proppatch(URI uri, Map parameters, Callback callback @Override public void proppatch(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), null, parameters, null, callback)); + asyncExecute(()->proppatch(url.toURI(), null, parameters, null, callback)); } @Override @@ -1679,7 +1680,7 @@ public void proppatch(URI uri, List
headers, Callback callback) throws I @Override public void proppatch(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), null, null, headers, callback)); + asyncExecute(()->proppatch(url.toURI(), null, null, headers, callback)); } @Override @@ -1691,7 +1692,7 @@ public void proppatch(URI uri, Map parameters, List
head @Override public void proppatch(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), null, parameters, headers, callback)); + asyncExecute(()->proppatch(url.toURI(), null, parameters, headers, callback)); } @Override @@ -1701,7 +1702,7 @@ public void proppatch(URI uri, RequestBody data, Callback callback) throws IO @Override public void proppatch(URL url, RequestBody data, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), data, null, null, callback)); + asyncExecute(()->proppatch(url.toURI(), data, null, null, callback)); } @Override @@ -1713,7 +1714,7 @@ public void proppatch(URI uri, RequestBody data, Map paramete @Override public void proppatch(URL url, RequestBody data, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), data, parameters, null, callback)); + asyncExecute(()->proppatch(url.toURI(), data, parameters, null, callback)); } @Override @@ -1725,13 +1726,13 @@ public void proppatch(URI uri, RequestBody data, List
headers, Callba @Override public void proppatch(URL url, RequestBody data, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), data, null, headers, callback)); + asyncExecute(()->proppatch(url.toURI(), data, null, headers, callback)); } @Override public void proppatch(URL url, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), data, parameters, headers, callback)); + asyncExecute(()->proppatch(url.toURI(), data, parameters, headers, callback)); } @Override @@ -1741,7 +1742,7 @@ public void proppatch(URI uri, int readTimeout, Callback callback) throws IOExce @Override public void proppatch(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), readTimeout, null, null, null, callback)); + asyncExecute(()->proppatch(url.toURI(), readTimeout, null, null, null, callback)); } @Override @@ -1753,7 +1754,7 @@ public void proppatch(URI uri, int readTimeout, Map parameters, @Override public void proppatch(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), readTimeout, null, parameters, null, callback)); + asyncExecute(()->proppatch(url.toURI(), readTimeout, null, parameters, null, callback)); } @Override @@ -1765,7 +1766,7 @@ public void proppatch(URI uri, int readTimeout, List
headers, Callback c @Override public void proppatch(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), readTimeout, null, null, headers, callback)); + asyncExecute(()->proppatch(url.toURI(), readTimeout, null, null, headers, callback)); } @Override @@ -1777,7 +1778,7 @@ public void proppatch(URI uri, int readTimeout, Map parameters, @Override public void proppatch(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), readTimeout, null, parameters, headers, callback)); + asyncExecute(()->proppatch(url.toURI(), readTimeout, null, parameters, headers, callback)); } @Override @@ -1789,7 +1790,7 @@ public void proppatch(URI uri, int readTimeout, RequestBody data, Callback ca @Override public void proppatch(URL url, int readTimeout, RequestBody data, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), readTimeout, data, null, null, callback)); + asyncExecute(()->proppatch(url.toURI(), readTimeout, data, null, null, callback)); } @Override @@ -1801,7 +1802,7 @@ public void proppatch(URI uri, int readTimeout, RequestBody data, Map data, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), readTimeout, data, parameters, null, callback)); + asyncExecute(()->proppatch(url.toURI(), readTimeout, data, parameters, null, callback)); } @Override @@ -1813,13 +1814,13 @@ public void proppatch(URI uri, int readTimeout, RequestBody data, List
data, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), readTimeout, data, null, headers, callback)); + asyncExecute(()->proppatch(url.toURI(), readTimeout, data, null, headers, callback)); } @Override public void proppatch(URL url, int readTimeout, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->proppatch(URL2URI(url), readTimeout, data, parameters, headers, callback)); + asyncExecute(()->proppatch(url.toURI(), readTimeout, data, parameters, headers, callback)); } @Override @@ -1829,7 +1830,7 @@ public void report(URI uri, Callback callback) throws IOException, RequestExcept @Override public void report(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), null, null, null, callback)); + asyncExecute(()->report(url.toURI(), null, null, null, callback)); } @Override @@ -1841,7 +1842,7 @@ public void report(URI uri, Map parameters, Callback callback) @Override public void report(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), null, parameters, null, callback)); + asyncExecute(()->report(url.toURI(), null, parameters, null, callback)); } @Override @@ -1851,7 +1852,7 @@ public void report(URI uri, List
headers, Callback callback) throws IOEx @Override public void report(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), null, null, headers, callback)); + asyncExecute(()->report(url.toURI(), null, null, headers, callback)); } @Override @@ -1863,7 +1864,7 @@ public void report(URI uri, Map parameters, List
headers @Override public void report(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), null, parameters, headers, callback)); + asyncExecute(()->report(url.toURI(), null, parameters, headers, callback)); } @Override @@ -1873,7 +1874,7 @@ public void report(URI uri, RequestBody data, Callback callback) throws IOExc @Override public void report(URL url, RequestBody data, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), data, null, null, callback)); + asyncExecute(()->report(url.toURI(), data, null, null, callback)); } @Override @@ -1885,7 +1886,7 @@ public void report(URI uri, RequestBody data, Map parameters, @Override public void report(URL url, RequestBody data, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), data, parameters, null, callback)); + asyncExecute(()->report(url.toURI(), data, parameters, null, callback)); } @Override @@ -1897,13 +1898,13 @@ public void report(URI uri, RequestBody data, List
headers, Callback @Override public void report(URL url, RequestBody data, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), data, null, headers, callback)); + asyncExecute(()->report(url.toURI(), data, null, headers, callback)); } @Override public void report(URL url, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), data, parameters, headers, callback)); + asyncExecute(()->report(url.toURI(), data, parameters, headers, callback)); } @Override @@ -1913,7 +1914,7 @@ public void report(URI uri, int readTimeout, Callback callback) throws IOExcepti @Override public void report(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), readTimeout, null, null, null, callback)); + asyncExecute(()->report(url.toURI(), readTimeout, null, null, null, callback)); } @Override @@ -1925,7 +1926,7 @@ public void report(URI uri, int readTimeout, Map parameters, Cal @Override public void report(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), readTimeout, null, parameters, null, callback)); + asyncExecute(()->report(url.toURI(), readTimeout, null, parameters, null, callback)); } @Override @@ -1937,7 +1938,7 @@ public void report(URI uri, int readTimeout, List
headers, Callback call @Override public void report(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), readTimeout, null, null, headers, callback)); + asyncExecute(()->report(url.toURI(), readTimeout, null, null, headers, callback)); } @Override @@ -1949,7 +1950,7 @@ public void report(URI uri, int readTimeout, Map parameters, Lis @Override public void report(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->report(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -1961,7 +1962,7 @@ public void report(URI uri, int readTimeout, RequestBody data, Callback callb @Override public void report(URL url, int readTimeout, RequestBody data, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), readTimeout, data, null, null, callback)); + asyncExecute(()->report(url.toURI(), readTimeout, data, null, null, callback)); } @Override @@ -1973,7 +1974,7 @@ public void report(URI uri, int readTimeout, RequestBody data, Map data, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), readTimeout, data, parameters, null, callback)); + asyncExecute(()->report(url.toURI(), readTimeout, data, parameters, null, callback)); } @Override @@ -1985,13 +1986,13 @@ public void report(URI uri, int readTimeout, RequestBody data, List
h @Override public void report(URL url, int readTimeout, RequestBody data, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), readTimeout, data, null, headers, callback)); + asyncExecute(()->report(url.toURI(), readTimeout, data, null, headers, callback)); } @Override public void report(URL url, int readTimeout, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->report(URL2URI(url), readTimeout, data, parameters, headers, callback)); + asyncExecute(()->report(url.toURI(), readTimeout, data, parameters, headers, callback)); } @Override @@ -2001,7 +2002,7 @@ public void view(URI uri, Callback callback) throws IOException, RequestExceptio @Override public void view(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->view(URL2URI(url), null, null, callback)); + asyncExecute(()->view(url.toURI(), null, null, callback)); } @Override @@ -2011,7 +2012,7 @@ public void view(URI uri, Map parameters, Callback callback) thr @Override public void view(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->view(URL2URI(url), parameters, null, callback)); + asyncExecute(()->view(url.toURI(), parameters, null, callback)); } @Override @@ -2021,13 +2022,13 @@ public void view(URI uri, List
headers, Callback callback) throws IOExce @Override public void view(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->view(URL2URI(url), null, headers, callback)); + asyncExecute(()->view(url.toURI(), null, headers, callback)); } @Override public void view(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->view(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->view(url.toURI(), parameters, headers, callback)); } @Override @@ -2037,7 +2038,7 @@ public void view(URI uri, int readTimeout, Callback callback) throws IOException @Override public void view(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->view(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->view(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -2049,7 +2050,7 @@ public void view(URI uri, int readTimeout, Map parameters, Callb @Override public void view(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->view(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->view(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -2061,13 +2062,13 @@ public void view(URI uri, int readTimeout, List
headers, Callback callba @Override public void view(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->view(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->view(url.toURI(), readTimeout, null, headers, callback)); } @Override public void view(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->view(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->view(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -2077,7 +2078,7 @@ public void wrapped(URI uri, Callback callback) throws IOException, RequestExcep @Override public void wrapped(URL url, Callback callback) throws IOException, RequestException { - asyncExecute(()->wrapped(URL2URI(url), null, null, callback)); + asyncExecute(()->wrapped(url.toURI(), null, null, callback)); } @Override @@ -2089,7 +2090,7 @@ public void wrapped(URI uri, Map parameters, Callback callback) @Override public void wrapped(URL url, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->wrapped(URL2URI(url), parameters, null, callback)); + asyncExecute(()->wrapped(url.toURI(), parameters, null, callback)); } @Override @@ -2099,13 +2100,13 @@ public void wrapped(URI uri, List
headers, Callback callback) throws IOE @Override public void wrapped(URL url, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->wrapped(URL2URI(url), null, headers, callback)); + asyncExecute(()->wrapped(url.toURI(), null, headers, callback)); } @Override public void wrapped(URL url, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->wrapped(URL2URI(url), parameters, headers, callback)); + asyncExecute(()->wrapped(url.toURI(), parameters, headers, callback)); } @Override @@ -2115,7 +2116,7 @@ public void wrapped(URI uri, int readTimeout, Callback callback) throws IOExcept @Override public void wrapped(URL url, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->wrapped(URL2URI(url), readTimeout, null, null, callback)); + asyncExecute(()->wrapped(url.toURI(), readTimeout, null, null, callback)); } @Override @@ -2127,7 +2128,7 @@ public void wrapped(URI uri, int readTimeout, Map parameters, Ca @Override public void wrapped(URL url, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->wrapped(URL2URI(url), readTimeout, parameters, null, callback)); + asyncExecute(()->wrapped(url.toURI(), readTimeout, parameters, null, callback)); } @Override @@ -2139,13 +2140,13 @@ public void wrapped(URI uri, int readTimeout, List
headers, Callback cal @Override public void wrapped(URL url, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->wrapped(URL2URI(url), readTimeout, null, headers, callback)); + asyncExecute(()->wrapped(url.toURI(), readTimeout, null, headers, callback)); } @Override public void wrapped(URL url, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->wrapped(URL2URI(url), readTimeout, parameters, headers, callback)); + asyncExecute(()->wrapped(url.toURI(), readTimeout, parameters, headers, callback)); } @Override @@ -2155,7 +2156,7 @@ public void request(URI uri, RequestMethod requestMethod, Callback callback) thr @Override public void request(URL url, RequestMethod requestMethod, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, callback)); } @Override @@ -2167,7 +2168,7 @@ public void request(URI uri, RequestMethod requestMethod, Map pa @Override public void request(URL url, RequestMethod requestMethod, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, parameters, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, parameters, callback)); } @Override @@ -2179,7 +2180,7 @@ public void request(URI uri, RequestMethod requestMethod, List
headers, @Override public void request(URL url, RequestMethod requestMethod, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, headers, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, headers, callback)); } @Override @@ -2191,7 +2192,7 @@ public void request(URI uri, RequestMethod requestMethod, Map pa @Override public void request(URL url, RequestMethod requestMethod, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, parameters, headers, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, parameters, headers, callback)); } @Override @@ -2203,7 +2204,7 @@ public void request(URI uri, RequestMethod requestMethod, RequestBody data, C @Override public void request(URL url, RequestMethod requestMethod, RequestBody data, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, data, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, data, callback)); } @Override @@ -2215,7 +2216,7 @@ public void request(URI uri, RequestMethod requestMethod, RequestBody data, M @Override public void request(URL url, RequestMethod requestMethod, RequestBody data, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, data, parameters, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, data, parameters, callback)); } @Override @@ -2227,7 +2228,7 @@ public void request(URI uri, RequestMethod requestMethod, RequestBody data, L @Override public void request(URL url, RequestMethod requestMethod, RequestBody data, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, data, headers, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, data, headers, callback)); } @Override @@ -2284,7 +2285,7 @@ public void request(URI uri, RequestMethod requestMethod, RequestBody data, M @Override public void request(URL url, RequestMethod requestMethod, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, data, parameters, headers, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, data, parameters, headers, callback)); } @Override @@ -2296,7 +2297,7 @@ public void request(URI uri, RequestMethod requestMethod, int readTimeout, Callb @Override public void request(URL url, RequestMethod requestMethod, int readTimeout, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, readTimeout, callback)); } @Override @@ -2308,7 +2309,7 @@ public void request(URI uri, RequestMethod requestMethod, int readTimeout, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, parameters, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, readTimeout, parameters, callback)); } @Override @@ -2320,7 +2321,7 @@ public void request(URI uri, RequestMethod requestMethod, int readTimeout, List< @Override public void request(URL url, RequestMethod requestMethod, int readTimeout, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, headers, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, readTimeout, headers, callback)); } @Override @@ -2332,7 +2333,7 @@ public void request(URI uri, RequestMethod requestMethod, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, parameters, headers, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, readTimeout, parameters, headers, callback)); } @Override @@ -2344,7 +2345,7 @@ public void request(URI uri, RequestMethod requestMethod, int readTimeout, Reque @Override public void request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, data, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, readTimeout, data, callback)); } @Override @@ -2356,7 +2357,7 @@ public void request(URI uri, RequestMethod requestMethod, int readTimeout, Reque @Override public void request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data, Map parameters, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, data, parameters, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, readTimeout, data, parameters, callback)); } @Override @@ -2368,7 +2369,7 @@ public void request(URI uri, RequestMethod requestMethod, int readTimeout, Reque @Override public void request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, data, headers, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, readTimeout, data, headers, callback)); } @Override @@ -2427,7 +2428,7 @@ public void request(URI uri, RequestMethod requestMethod, int readTimeout, Reque public void request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - asyncExecute(()->request(URL2URI(url), requestMethod, readTimeout, data, parameters, headers, callback)); + asyncExecute(()->request(url.toURI(), requestMethod, readTimeout, data, parameters, headers, callback)); } protected static void asyncExecute(final AsyncExecute execute) throws IOException, RequestException { diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpClient.java index e7b43647d..56367e0f0 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpClient.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/AbstractHttpClient.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient; @@ -44,7 +44,7 @@ * * @author Yong.Teng */ -public abstract class AbstractHttpClient extends AbstractBaseHttpClient implements HttpClient { +public abstract class AbstractHttpClient extends AbstractBaseHttpClient implements HttpClient { /** * 构造函数 @@ -70,7 +70,7 @@ public Response get(URI uri) throws IOException, RequestException { @Override public Response get(URL url) throws IOException, RequestException { - return execute(()->get(URL2URI(url))); + return execute(()->get(url.toURI())); } @Override @@ -80,7 +80,7 @@ public Response get(URI uri, Map parameters) throws IOException, @Override public Response get(URL url, Map parameters) throws IOException, RequestException { - return execute(()->get(URL2URI(url), parameters)); + return execute(()->get(url.toURI(), parameters)); } @Override @@ -90,13 +90,13 @@ public Response get(URI uri, List
headers) throws IOException, RequestEx @Override public Response get(URL url, List
headers) throws IOException, RequestException { - return execute(()->get(URL2URI(url), headers)); + return execute(()->get(url.toURI(), headers)); } @Override public Response get(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->get(URL2URI(url), parameters, headers)); + return execute(()->get(url.toURI(), parameters, headers)); } @Override @@ -106,7 +106,7 @@ public Response get(URI uri, int readTimeout) throws IOException, RequestExcepti @Override public Response get(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->get(URL2URI(url), readTimeout)); + return execute(()->get(url.toURI(), readTimeout)); } @Override @@ -116,7 +116,7 @@ public Response get(URI uri, int readTimeout, Map parameters) th @Override public Response get(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->get(URL2URI(url), readTimeout, parameters)); + return execute(()->get(url.toURI(), readTimeout, parameters)); } @Override @@ -126,13 +126,13 @@ public Response get(URI uri, int readTimeout, List
headers) throws IOExc @Override public Response get(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->get(URL2URI(url), readTimeout, headers)); + return execute(()->get(url.toURI(), readTimeout, headers)); } @Override public Response get(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->get(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->get(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -142,7 +142,7 @@ public Response post(URI uri) throws IOException, RequestException { @Override public Response post(URL url) throws IOException, RequestException { - return execute(()->post(URL2URI(url))); + return execute(()->post(url.toURI())); } @Override @@ -152,7 +152,7 @@ public Response post(URI uri, Map parameters) throws IOException @Override public Response post(URL url, Map parameters) throws IOException, RequestException { - return execute(()->post(URL2URI(url), parameters)); + return execute(()->post(url.toURI(), parameters)); } @Override @@ -162,7 +162,7 @@ public Response post(URI uri, List
headers) throws IOException, RequestE @Override public Response post(URL url, List
headers) throws IOException, RequestException { - return execute(()->post(URL2URI(url), headers)); + return execute(()->post(url.toURI(), headers)); } @Override @@ -174,7 +174,7 @@ public Response post(URI uri, Map parameters, List
heade @Override public Response post(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->post(URL2URI(url), parameters, headers)); + return execute(()->post(url.toURI(), parameters, headers)); } @Override @@ -184,7 +184,7 @@ public Response post(URI uri, RequestBody data) throws IOException, RequestEx @Override public Response post(URL url, RequestBody data) throws IOException, RequestException { - return execute(()->post(URL2URI(url), data)); + return execute(()->post(url.toURI(), data)); } @Override @@ -196,7 +196,7 @@ public Response post(URI uri, RequestBody data, Map parameter @Override public Response post(URL url, RequestBody data, Map parameters) throws IOException, RequestException { - return execute(()->post(URL2URI(url), data, parameters)); + return execute(()->post(url.toURI(), data, parameters)); } @Override @@ -206,13 +206,13 @@ public Response post(URI uri, RequestBody data, List
headers) throws @Override public Response post(URL url, RequestBody data, List
headers) throws IOException, RequestException { - return execute(()->post(URL2URI(url), data, headers)); + return execute(()->post(url.toURI(), data, headers)); } @Override public Response post(URL url, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->post(URL2URI(url), data, parameters, headers)); + return execute(()->post(url.toURI(), data, parameters, headers)); } @Override @@ -222,7 +222,7 @@ public Response post(URI uri, int readTimeout) throws IOException, RequestExcept @Override public Response post(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->post(URL2URI(url), readTimeout)); + return execute(()->post(url.toURI(), readTimeout)); } @Override @@ -234,7 +234,7 @@ public Response post(URI uri, int readTimeout, Map parameters) @Override public Response post(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->post(URL2URI(url), readTimeout, parameters)); + return execute(()->post(url.toURI(), readTimeout, parameters)); } @Override @@ -244,7 +244,7 @@ public Response post(URI uri, int readTimeout, List
headers) throws IOEx @Override public Response post(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->post(URL2URI(url), readTimeout, headers)); + return execute(()->post(url.toURI(), readTimeout, headers)); } @Override @@ -256,7 +256,7 @@ public Response post(URI uri, int readTimeout, Map parameters, L @Override public Response post(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->post(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->post(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -266,7 +266,7 @@ public Response post(URI uri, int readTimeout, RequestBody data) throws IOExc @Override public Response post(URL url, int readTimeout, RequestBody data) throws IOException, RequestException { - return execute(()->post(URL2URI(url), readTimeout, data)); + return execute(()->post(url.toURI(), readTimeout, data)); } @Override @@ -278,7 +278,7 @@ public Response post(URI uri, int readTimeout, RequestBody data, Map data, Map parameters) throws IOException, RequestException { - return execute(()->post(URL2URI(url), readTimeout, data, parameters)); + return execute(()->post(url.toURI(), readTimeout, data, parameters)); } @Override @@ -290,13 +290,13 @@ public Response post(URI uri, int readTimeout, RequestBody data, List
@Override public Response post(URL url, int readTimeout, RequestBody data, List
headers) throws IOException, RequestException { - return execute(()->post(URL2URI(url), readTimeout, data, headers)); + return execute(()->post(url.toURI(), readTimeout, data, headers)); } @Override public Response post(URL url, int readTimeout, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->post(URL2URI(url), readTimeout, data, parameters, headers)); + return execute(()->post(url.toURI(), readTimeout, data, parameters, headers)); } @Override @@ -306,7 +306,7 @@ public Response put(URI uri) throws IOException, RequestException { @Override public Response put(URL url) throws IOException, RequestException { - return execute(()->put(URL2URI(url))); + return execute(()->put(url.toURI())); } @Override @@ -316,7 +316,7 @@ public Response put(URI uri, Map parameters) throws IOException, @Override public Response put(URL url, Map parameters) throws IOException, RequestException { - return execute(()->put(URL2URI(url), parameters)); + return execute(()->put(url.toURI(), parameters)); } @Override @@ -326,7 +326,7 @@ public Response put(URI uri, List
headers) throws IOException, RequestEx @Override public Response put(URL url, List
headers) throws IOException, RequestException { - return execute(()->put(URL2URI(url), headers)); + return execute(()->put(url.toURI(), headers)); } @Override @@ -338,7 +338,7 @@ public Response put(URI uri, Map parameters, List
header @Override public Response put(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->put(URL2URI(url), parameters, headers)); + return execute(()->put(url.toURI(), parameters, headers)); } @Override @@ -348,7 +348,7 @@ public Response put(URI uri, RequestBody data) throws IOException, RequestExc @Override public Response put(URL url, RequestBody data) throws IOException, RequestException { - return execute(()->put(URL2URI(url), data)); + return execute(()->put(url.toURI(), data)); } @Override @@ -360,7 +360,7 @@ public Response put(URI uri, RequestBody data, Map parameters @Override public Response put(URL url, RequestBody data, Map parameters) throws IOException, RequestException { - return execute(()->put(URL2URI(url), data, parameters)); + return execute(()->put(url.toURI(), data, parameters)); } @Override @@ -370,13 +370,13 @@ public Response put(URI uri, RequestBody data, List
headers) throws I @Override public Response put(URL url, RequestBody data, List
headers) throws IOException, RequestException { - return execute(()->put(URL2URI(url), data, headers)); + return execute(()->put(url.toURI(), data, headers)); } @Override public Response put(URL url, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->put(URL2URI(url), data, parameters, headers)); + return execute(()->put(url.toURI(), data, parameters, headers)); } @Override @@ -386,7 +386,7 @@ public Response put(URI uri, int readTimeout) throws IOException, RequestExcepti @Override public Response put(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->put(URL2URI(url), readTimeout)); + return execute(()->put(url.toURI(), readTimeout)); } @Override @@ -396,7 +396,7 @@ public Response put(URI uri, int readTimeout, Map parameters) th @Override public Response put(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->put(URL2URI(url), readTimeout, parameters)); + return execute(()->put(url.toURI(), readTimeout, parameters)); } @Override @@ -406,7 +406,7 @@ public Response put(URI uri, int readTimeout, List
headers) throws IOExc @Override public Response put(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->put(URL2URI(url), readTimeout, headers)); + return execute(()->put(url.toURI(), readTimeout, headers)); } @Override @@ -418,7 +418,7 @@ public Response put(URI uri, int readTimeout, Map parameters, Li @Override public Response put(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->put(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->put(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -428,7 +428,7 @@ public Response put(URI uri, int readTimeout, RequestBody data) throws IOExce @Override public Response put(URL url, int readTimeout, RequestBody data) throws IOException, RequestException { - return execute(()->put(URL2URI(url), readTimeout, data)); + return execute(()->put(url.toURI(), readTimeout, data)); } @Override @@ -440,7 +440,7 @@ public Response put(URI uri, int readTimeout, RequestBody data, Map data, Map parameters) throws IOException, RequestException { - return execute(()->put(URL2URI(url), readTimeout, data, parameters)); + return execute(()->put(url.toURI(), readTimeout, data, parameters)); } @Override @@ -452,13 +452,13 @@ public Response put(URI uri, int readTimeout, RequestBody data, List
@Override public Response put(URL url, int readTimeout, RequestBody data, List
headers) throws IOException, RequestException { - return execute(()->put(URL2URI(url), readTimeout, data, headers)); + return execute(()->put(url.toURI(), readTimeout, data, headers)); } @Override public Response put(URL url, int readTimeout, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->put(URL2URI(url), readTimeout, data, parameters, headers)); + return execute(()->put(url.toURI(), readTimeout, data, parameters, headers)); } @Override @@ -468,7 +468,7 @@ public Response patch(URI uri) throws IOException, RequestException { @Override public Response patch(URL url) throws IOException, RequestException { - return execute(()->patch(URL2URI(url))); + return execute(()->patch(url.toURI())); } @Override @@ -478,7 +478,7 @@ public Response patch(URI uri, Map parameters) throws IOExceptio @Override public Response patch(URL url, Map parameters) throws IOException, RequestException { - return execute(()->patch(URL2URI(url), parameters)); + return execute(()->patch(url.toURI(), parameters)); } @Override @@ -488,7 +488,7 @@ public Response patch(URI uri, List
headers) throws IOException, Request @Override public Response patch(URL url, List
headers) throws IOException, RequestException { - return execute(()->patch(URL2URI(url), headers)); + return execute(()->patch(url.toURI(), headers)); } @Override @@ -500,7 +500,7 @@ public Response patch(URI uri, Map parameters, List
head @Override public Response patch(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->patch(URL2URI(url), parameters, headers)); + return execute(()->patch(url.toURI(), parameters, headers)); } @Override @@ -510,7 +510,7 @@ public Response patch(URI uri, RequestBody data) throws IOException, RequestE @Override public Response patch(URL url, RequestBody data) throws IOException, RequestException { - return execute(()->patch(URL2URI(url), data)); + return execute(()->patch(url.toURI(), data)); } @Override @@ -522,7 +522,7 @@ public Response patch(URI uri, RequestBody data, Map paramete @Override public Response patch(URL url, RequestBody data, Map parameters) throws IOException, RequestException { - return execute(()->patch(URL2URI(url), data, parameters)); + return execute(()->patch(url.toURI(), data, parameters)); } @Override @@ -532,13 +532,13 @@ public Response patch(URI uri, RequestBody data, List
headers) throws @Override public Response patch(URL url, RequestBody data, List
headers) throws IOException, RequestException { - return execute(()->patch(URL2URI(url), data, headers)); + return execute(()->patch(url.toURI(), data, headers)); } @Override public Response patch(URL url, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->patch(URL2URI(url), data, parameters, headers)); + return execute(()->patch(url.toURI(), data, parameters, headers)); } @Override @@ -548,7 +548,7 @@ public Response patch(URI uri, int readTimeout) throws IOException, RequestExcep @Override public Response patch(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->patch(URL2URI(url), readTimeout)); + return execute(()->patch(url.toURI(), readTimeout)); } @Override @@ -560,7 +560,7 @@ public Response patch(URI uri, int readTimeout, Map parameters) @Override public Response patch(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->patch(URL2URI(url), readTimeout, parameters)); + return execute(()->patch(url.toURI(), readTimeout, parameters)); } @Override @@ -570,7 +570,7 @@ public Response patch(URI uri, int readTimeout, List
headers) throws IOE @Override public Response patch(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->patch(URL2URI(url), readTimeout, headers)); + return execute(()->patch(url.toURI(), readTimeout, headers)); } @Override @@ -582,7 +582,7 @@ public Response patch(URI uri, int readTimeout, Map parameters, @Override public Response patch(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->patch(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->patch(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -592,7 +592,7 @@ public Response patch(URI uri, int readTimeout, RequestBody data) throws IOEx @Override public Response patch(URL url, int readTimeout, RequestBody data) throws IOException, RequestException { - return execute(()->patch(URL2URI(url), readTimeout, data)); + return execute(()->patch(url.toURI(), readTimeout, data)); } @Override @@ -604,7 +604,7 @@ public Response patch(URI uri, int readTimeout, RequestBody data, Map data, Map parameters) throws IOException, RequestException { - return execute(()->patch(URL2URI(url), readTimeout, data, parameters)); + return execute(()->patch(url.toURI(), readTimeout, data, parameters)); } @Override @@ -616,13 +616,13 @@ public Response patch(URI uri, int readTimeout, RequestBody data, List
data, List
headers) throws IOException, RequestException { - return execute(()->patch(URL2URI(url), readTimeout, data, headers)); + return execute(()->patch(url.toURI(), readTimeout, data, headers)); } @Override public Response patch(URL url, int readTimeout, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->patch(URL2URI(url), readTimeout, data, parameters, headers)); + return execute(()->patch(url.toURI(), readTimeout, data, parameters, headers)); } @Override @@ -637,12 +637,12 @@ public Response delete(URI uri, Map parameters) throws IOExcepti @Override public Response delete(URL url) throws IOException, RequestException { - return execute(()->delete(URL2URI(url))); + return execute(()->delete(url.toURI())); } @Override public Response delete(URL url, Map parameters) throws IOException, RequestException { - return execute(()->delete(URL2URI(url), parameters)); + return execute(()->delete(url.toURI(), parameters)); } @Override @@ -652,13 +652,13 @@ public Response delete(URI uri, List
headers) throws IOException, Reques @Override public Response delete(URL url, List
headers) throws IOException, RequestException { - return execute(()->delete(URL2URI(url), headers)); + return execute(()->delete(url.toURI(), headers)); } @Override public Response delete(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->delete(URL2URI(url), parameters, headers)); + return execute(()->delete(url.toURI(), parameters, headers)); } @Override @@ -674,13 +674,13 @@ public Response delete(URI uri, int readTimeout, Map parameters) @Override public Response delete(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->delete(URL2URI(url), readTimeout)); + return execute(()->delete(url.toURI(), readTimeout)); } @Override public Response delete(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->delete(URL2URI(url), readTimeout, parameters)); + return execute(()->delete(url.toURI(), readTimeout, parameters)); } @Override @@ -690,13 +690,13 @@ public Response delete(URI uri, int readTimeout, List
headers) throws IO @Override public Response delete(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->delete(URL2URI(url), readTimeout, headers)); + return execute(()->delete(url.toURI(), readTimeout, headers)); } @Override public Response delete(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->delete(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->delete(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -706,7 +706,7 @@ public Response connect(URI uri) throws IOException, RequestException { @Override public Response connect(URL url) throws IOException, RequestException { - return execute(()->connect(URL2URI(url))); + return execute(()->connect(url.toURI())); } @Override @@ -716,7 +716,7 @@ public Response connect(URI uri, Map parameters) throws IOExcept @Override public Response connect(URL url, Map parameters) throws IOException, RequestException { - return execute(()->connect(URL2URI(url), parameters)); + return execute(()->connect(url.toURI(), parameters)); } @Override @@ -726,13 +726,13 @@ public Response connect(URI uri, List
headers) throws IOException, Reque @Override public Response connect(URL url, List
headers) throws IOException, RequestException { - return execute(()->connect(URL2URI(url), headers)); + return execute(()->connect(url.toURI(), headers)); } @Override public Response connect(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->connect(URL2URI(url), parameters, headers)); + return execute(()->connect(url.toURI(), parameters, headers)); } @Override @@ -742,7 +742,7 @@ public Response connect(URI uri, int readTimeout) throws IOException, RequestExc @Override public Response connect(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->connect(URL2URI(url), readTimeout)); + return execute(()->connect(url.toURI(), readTimeout)); } @Override @@ -754,7 +754,7 @@ public Response connect(URI uri, int readTimeout, Map parameters @Override public Response connect(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->connect(URL2URI(url), readTimeout, parameters)); + return execute(()->connect(url.toURI(), readTimeout, parameters)); } @Override @@ -764,13 +764,13 @@ public Response connect(URI uri, int readTimeout, List
headers) throws I @Override public Response connect(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->connect(URL2URI(url), readTimeout, headers)); + return execute(()->connect(url.toURI(), readTimeout, headers)); } @Override public Response connect(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->connect(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->connect(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -780,7 +780,7 @@ public Response trace(URI uri) throws IOException, RequestException { @Override public Response trace(URL url) throws IOException, RequestException { - return execute(()->trace(URL2URI(url))); + return execute(()->trace(url.toURI())); } @Override @@ -790,7 +790,7 @@ public Response trace(URI uri, Map parameters) throws IOExceptio @Override public Response trace(URL url, Map parameters) throws IOException, RequestException { - return execute(()->trace(URL2URI(url), parameters)); + return execute(()->trace(url.toURI(), parameters)); } @Override @@ -800,13 +800,13 @@ public Response trace(URI uri, List
headers) throws IOException, Request @Override public Response trace(URL url, List
headers) throws IOException, RequestException { - return execute(()->trace(URL2URI(url), headers)); + return execute(()->trace(url.toURI(), headers)); } @Override public Response trace(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->trace(URL2URI(url), parameters, headers)); + return execute(()->trace(url.toURI(), parameters, headers)); } @Override @@ -816,7 +816,7 @@ public Response trace(URI uri, int readTimeout) throws IOException, RequestExcep @Override public Response trace(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->trace(URL2URI(url), readTimeout)); + return execute(()->trace(url.toURI(), readTimeout)); } @Override @@ -828,7 +828,7 @@ public Response trace(URI uri, int readTimeout, Map parameters) @Override public Response trace(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->trace(URL2URI(url), readTimeout, parameters)); + return execute(()->trace(url.toURI(), readTimeout, parameters)); } @Override @@ -838,13 +838,13 @@ public Response trace(URI uri, int readTimeout, List
headers) throws IOE @Override public Response trace(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->trace(URL2URI(url), readTimeout, headers)); + return execute(()->trace(url.toURI(), readTimeout, headers)); } @Override public Response trace(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->trace(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->trace(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -854,7 +854,7 @@ public Response copy(URI uri) throws IOException, RequestException { @Override public Response copy(URL url) throws IOException, RequestException { - return execute(()->copy(URL2URI(url))); + return execute(()->copy(url.toURI())); } @Override @@ -864,7 +864,7 @@ public Response copy(URI uri, Map parameters) throws IOException @Override public Response copy(URL url, Map parameters) throws IOException, RequestException { - return execute(()->copy(URL2URI(url), parameters)); + return execute(()->copy(url.toURI(), parameters)); } @Override @@ -874,13 +874,13 @@ public Response copy(URI uri, List
headers) throws IOException, RequestE @Override public Response copy(URL url, List
headers) throws IOException, RequestException { - return execute(()->copy(URL2URI(url), headers)); + return execute(()->copy(url.toURI(), headers)); } @Override public Response copy(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->copy(URL2URI(url), parameters, headers)); + return execute(()->copy(url.toURI(), parameters, headers)); } @Override @@ -890,7 +890,7 @@ public Response copy(URI uri, int readTimeout) throws IOException, RequestExcept @Override public Response copy(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->copy(URL2URI(url), readTimeout)); + return execute(()->copy(url.toURI(), readTimeout)); } @Override @@ -902,7 +902,7 @@ public Response copy(URI uri, int readTimeout, Map parameters) @Override public Response copy(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->copy(URL2URI(url), readTimeout, parameters)); + return execute(()->copy(url.toURI(), readTimeout, parameters)); } @Override @@ -912,13 +912,13 @@ public Response copy(URI uri, int readTimeout, List
headers) throws IOEx @Override public Response copy(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->copy(URL2URI(url), readTimeout, headers)); + return execute(()->copy(url.toURI(), readTimeout, headers)); } @Override public Response copy(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->copy(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->copy(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -928,7 +928,7 @@ public Response move(URI uri) throws IOException, RequestException { @Override public Response move(URL url) throws IOException, RequestException { - return execute(()->move(URL2URI(url))); + return execute(()->move(url.toURI())); } @Override @@ -938,7 +938,7 @@ public Response move(URI uri, Map parameters) throws IOException @Override public Response move(URL url, Map parameters) throws IOException, RequestException { - return execute(()->move(URL2URI(url), parameters)); + return execute(()->move(url.toURI(), parameters)); } @Override @@ -948,13 +948,13 @@ public Response move(URI uri, List
headers) throws IOException, RequestE @Override public Response move(URL url, List
headers) throws IOException, RequestException { - return execute(()->move(URL2URI(url), headers)); + return execute(()->move(url.toURI(), headers)); } @Override public Response move(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->move(URL2URI(url), parameters, headers)); + return execute(()->move(url.toURI(), parameters, headers)); } @Override @@ -964,7 +964,7 @@ public Response move(URI uri, int readTimeout) throws IOException, RequestExcept @Override public Response move(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->move(URL2URI(url), readTimeout)); + return execute(()->move(url.toURI(), readTimeout)); } @Override @@ -976,7 +976,7 @@ public Response move(URI uri, int readTimeout, Map parameters) @Override public Response move(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->move(URL2URI(url), readTimeout, parameters)); + return execute(()->move(url.toURI(), readTimeout, parameters)); } @Override @@ -986,13 +986,13 @@ public Response move(URI uri, int readTimeout, List
headers) throws IOEx @Override public Response move(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->move(URL2URI(url), readTimeout, headers)); + return execute(()->move(url.toURI(), readTimeout, headers)); } @Override public Response move(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->move(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->move(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -1002,7 +1002,7 @@ public Response head(URI uri) throws IOException, RequestException { @Override public Response head(URL url) throws IOException, RequestException { - return execute(()->head(URL2URI(url))); + return execute(()->head(url.toURI())); } @Override @@ -1012,7 +1012,7 @@ public Response head(URI uri, Map parameters) throws IOException @Override public Response head(URL url, Map parameters) throws IOException, RequestException { - return execute(()->head(URL2URI(url), parameters)); + return execute(()->head(url.toURI(), parameters)); } @Override @@ -1022,13 +1022,13 @@ public Response head(URI uri, List
headers) throws IOException, RequestE @Override public Response head(URL url, List
headers) throws IOException, RequestException { - return execute(()->head(URL2URI(url), headers)); + return execute(()->head(url.toURI(), headers)); } @Override public Response head(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->head(URL2URI(url), parameters, headers)); + return execute(()->head(url.toURI(), parameters, headers)); } @Override @@ -1038,7 +1038,7 @@ public Response head(URI uri, int readTimeout) throws IOException, RequestExcept @Override public Response head(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->head(URL2URI(url), readTimeout)); + return execute(()->head(url.toURI(), readTimeout)); } @Override @@ -1050,7 +1050,7 @@ public Response head(URI uri, int readTimeout, Map parameters) @Override public Response head(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->head(URL2URI(url), readTimeout, parameters)); + return execute(()->head(url.toURI(), readTimeout, parameters)); } @Override @@ -1060,13 +1060,13 @@ public Response head(URI uri, int readTimeout, List
headers) throws IOEx @Override public Response head(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->head(URL2URI(url), readTimeout, headers)); + return execute(()->head(url.toURI(), readTimeout, headers)); } @Override public Response head(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->head(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->head(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -1076,7 +1076,7 @@ public Response options(URI uri) throws IOException, RequestException { @Override public Response options(URL url) throws IOException, RequestException { - return execute(()->options(URL2URI(url))); + return execute(()->options(url.toURI())); } @Override @@ -1086,7 +1086,7 @@ public Response options(URI uri, Map parameters) throws IOExcept @Override public Response options(URL url, Map parameters) throws IOException, RequestException { - return execute(()->options(URL2URI(url), parameters)); + return execute(()->options(url.toURI(), parameters)); } @Override @@ -1096,13 +1096,13 @@ public Response options(URI uri, List
headers) throws IOException, Reque @Override public Response options(URL url, List
headers) throws IOException, RequestException { - return execute(()->options(URL2URI(url), headers)); + return execute(()->options(url.toURI(), headers)); } @Override public Response options(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->options(URL2URI(url), parameters, headers)); + return execute(()->options(url.toURI(), parameters, headers)); } @Override @@ -1112,7 +1112,7 @@ public Response options(URI uri, int readTimeout) throws IOException, RequestExc @Override public Response options(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->options(URL2URI(url), readTimeout)); + return execute(()->options(url.toURI(), readTimeout)); } @Override @@ -1124,7 +1124,7 @@ public Response options(URI uri, int readTimeout, Map parameters @Override public Response options(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->options(URL2URI(url), readTimeout, parameters)); + return execute(()->options(url.toURI(), readTimeout, parameters)); } @Override @@ -1134,13 +1134,13 @@ public Response options(URI uri, int readTimeout, List
headers) throws I @Override public Response options(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->options(URL2URI(url), readTimeout, headers)); + return execute(()->options(url.toURI(), readTimeout, headers)); } @Override public Response options(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->options(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->options(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -1150,7 +1150,7 @@ public Response link(URI uri) throws IOException, RequestException { @Override public Response link(URL url) throws IOException, RequestException { - return execute(()->link(URL2URI(url))); + return execute(()->link(url.toURI())); } @Override @@ -1160,7 +1160,7 @@ public Response link(URI uri, Map parameters) throws IOException @Override public Response link(URL url, Map parameters) throws IOException, RequestException { - return execute(()->link(URL2URI(url), parameters)); + return execute(()->link(url.toURI(), parameters)); } @Override @@ -1170,13 +1170,13 @@ public Response link(URI uri, List
headers) throws IOException, RequestE @Override public Response link(URL url, List
headers) throws IOException, RequestException { - return execute(()->link(URL2URI(url), headers)); + return execute(()->link(url.toURI(), headers)); } @Override public Response link(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->link(URL2URI(url), parameters, headers)); + return execute(()->link(url.toURI(), parameters, headers)); } @Override @@ -1186,7 +1186,7 @@ public Response link(URI uri, int readTimeout) throws IOException, RequestExcept @Override public Response link(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->link(URL2URI(url), readTimeout)); + return execute(()->link(url.toURI(), readTimeout)); } @Override @@ -1198,7 +1198,7 @@ public Response link(URI uri, int readTimeout, Map parameters) @Override public Response link(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->link(URL2URI(url), readTimeout, parameters)); + return execute(()->link(url.toURI(), readTimeout, parameters)); } @Override @@ -1208,13 +1208,13 @@ public Response link(URI uri, int readTimeout, List
headers) throws IOEx @Override public Response link(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->link(URL2URI(url), readTimeout, headers)); + return execute(()->link(url.toURI(), readTimeout, headers)); } @Override public Response link(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->link(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->link(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -1224,7 +1224,7 @@ public Response unlink(URI uri) throws IOException, RequestException { @Override public Response unlink(URL url) throws IOException, RequestException { - return execute(()->unlink(URL2URI(url))); + return execute(()->unlink(url.toURI())); } @Override @@ -1234,7 +1234,7 @@ public Response unlink(URI uri, Map parameters) throws IOExcepti @Override public Response unlink(URL url, Map parameters) throws IOException, RequestException { - return execute(()->unlink(URL2URI(url), parameters)); + return execute(()->unlink(url.toURI(), parameters)); } @Override @@ -1244,13 +1244,13 @@ public Response unlink(URI uri, List
headers) throws IOException, Reques @Override public Response unlink(URL url, List
headers) throws IOException, RequestException { - return execute(()->unlink(URL2URI(url), headers)); + return execute(()->unlink(url.toURI(), headers)); } @Override public Response unlink(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->unlink(URL2URI(url), parameters, headers)); + return execute(()->unlink(url.toURI(), parameters, headers)); } @Override @@ -1260,7 +1260,7 @@ public Response unlink(URI uri, int readTimeout) throws IOException, RequestExce @Override public Response unlink(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->unlink(URL2URI(url), readTimeout)); + return execute(()->unlink(url.toURI(), readTimeout)); } @Override @@ -1272,7 +1272,7 @@ public Response unlink(URI uri, int readTimeout, Map parameters) @Override public Response unlink(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->unlink(URL2URI(url), readTimeout, parameters)); + return execute(()->unlink(url.toURI(), readTimeout, parameters)); } @Override @@ -1282,13 +1282,13 @@ public Response unlink(URI uri, int readTimeout, List
headers) throws IO @Override public Response unlink(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->unlink(URL2URI(url), readTimeout, headers)); + return execute(()->unlink(url.toURI(), readTimeout, headers)); } @Override public Response unlink(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->unlink(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->unlink(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -1298,7 +1298,7 @@ public Response purge(URI uri) throws IOException, RequestException { @Override public Response purge(URL url) throws IOException, RequestException { - return execute(()->purge(URL2URI(url))); + return execute(()->purge(url.toURI())); } @Override @@ -1308,7 +1308,7 @@ public Response purge(URI uri, Map parameters) throws IOExceptio @Override public Response purge(URL url, Map parameters) throws IOException, RequestException { - return execute(()->purge(URL2URI(url), parameters)); + return execute(()->purge(url.toURI(), parameters)); } @Override @@ -1318,13 +1318,13 @@ public Response purge(URI uri, List
headers) throws IOException, Request @Override public Response purge(URL url, List
headers) throws IOException, RequestException { - return execute(()->purge(URL2URI(url), headers)); + return execute(()->purge(url.toURI(), headers)); } @Override public Response purge(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->purge(URL2URI(url), parameters, headers)); + return execute(()->purge(url.toURI(), parameters, headers)); } @Override @@ -1334,7 +1334,7 @@ public Response purge(URI uri, int readTimeout) throws IOException, RequestExcep @Override public Response purge(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->purge(URL2URI(url), readTimeout)); + return execute(()->purge(url.toURI(), readTimeout)); } @Override @@ -1346,7 +1346,7 @@ public Response purge(URI uri, int readTimeout, Map parameters) @Override public Response purge(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->purge(URL2URI(url), readTimeout, parameters)); + return execute(()->purge(url.toURI(), readTimeout, parameters)); } @Override @@ -1356,13 +1356,13 @@ public Response purge(URI uri, int readTimeout, List
headers) throws IOE @Override public Response purge(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->purge(URL2URI(url), readTimeout, headers)); + return execute(()->purge(url.toURI(), readTimeout, headers)); } @Override public Response purge(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->purge(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->purge(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -1372,7 +1372,7 @@ public Response lock(URI uri) throws IOException, RequestException { @Override public Response lock(URL url) throws IOException, RequestException { - return execute(()->lock(URL2URI(url))); + return execute(()->lock(url.toURI())); } @Override @@ -1382,7 +1382,7 @@ public Response lock(URI uri, Map parameters) throws IOException @Override public Response lock(URL url, Map parameters) throws IOException, RequestException { - return execute(()->lock(URL2URI(url), parameters)); + return execute(()->lock(url.toURI(), parameters)); } @Override @@ -1392,13 +1392,13 @@ public Response lock(URI uri, List
headers) throws IOException, RequestE @Override public Response lock(URL url, List
headers) throws IOException, RequestException { - return execute(()->lock(URL2URI(url), headers)); + return execute(()->lock(url.toURI(), headers)); } @Override public Response lock(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->lock(URL2URI(url), parameters, headers)); + return execute(()->lock(url.toURI(), parameters, headers)); } @Override @@ -1408,7 +1408,7 @@ public Response lock(URI uri, int readTimeout) throws IOException, RequestExcept @Override public Response lock(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->lock(URL2URI(url), readTimeout)); + return execute(()->lock(url.toURI(), readTimeout)); } @Override @@ -1420,7 +1420,7 @@ public Response lock(URI uri, int readTimeout, Map parameters) @Override public Response lock(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->lock(URL2URI(url), readTimeout, parameters)); + return execute(()->lock(url.toURI(), readTimeout, parameters)); } @Override @@ -1430,13 +1430,13 @@ public Response lock(URI uri, int readTimeout, List
headers) throws IOEx @Override public Response lock(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->lock(URL2URI(url), readTimeout, headers)); + return execute(()->lock(url.toURI(), readTimeout, headers)); } @Override public Response lock(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->lock(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->lock(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -1446,7 +1446,7 @@ public Response unlock(URI uri) throws IOException, RequestException { @Override public Response unlock(URL url) throws IOException, RequestException { - return execute(()->unlock(URL2URI(url))); + return execute(()->unlock(url.toURI())); } @Override @@ -1456,7 +1456,7 @@ public Response unlock(URI uri, Map parameters) throws IOExcepti @Override public Response unlock(URL url, Map parameters) throws IOException, RequestException { - return execute(()->unlock(URL2URI(url), parameters)); + return execute(()->unlock(url.toURI(), parameters)); } @Override @@ -1466,13 +1466,13 @@ public Response unlock(URI uri, List
headers) throws IOException, Reques @Override public Response unlock(URL url, List
headers) throws IOException, RequestException { - return execute(()->unlock(URL2URI(url), headers)); + return execute(()->unlock(url.toURI(), headers)); } @Override public Response unlock(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->unlock(URL2URI(url), parameters, headers)); + return execute(()->unlock(url.toURI(), parameters, headers)); } @Override @@ -1482,7 +1482,7 @@ public Response unlock(URI uri, int readTimeout) throws IOException, RequestExce @Override public Response unlock(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->unlock(URL2URI(url), readTimeout)); + return execute(()->unlock(url.toURI(), readTimeout)); } @Override @@ -1494,7 +1494,7 @@ public Response unlock(URI uri, int readTimeout, Map parameters) @Override public Response unlock(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->unlock(URL2URI(url), readTimeout, parameters)); + return execute(()->unlock(url.toURI(), readTimeout, parameters)); } @Override @@ -1504,13 +1504,13 @@ public Response unlock(URI uri, int readTimeout, List
headers) throws IO @Override public Response unlock(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->unlock(URL2URI(url), readTimeout, headers)); + return execute(()->unlock(url.toURI(), readTimeout, headers)); } @Override public Response unlock(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->unlock(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->unlock(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -1520,7 +1520,7 @@ public Response propfind(URI uri) throws IOException, RequestException { @Override public Response propfind(URL url) throws IOException, RequestException { - return execute(()->propfind(URL2URI(url))); + return execute(()->propfind(url.toURI())); } @Override @@ -1530,7 +1530,7 @@ public Response propfind(URI uri, Map parameters) throws IOExcep @Override public Response propfind(URL url, Map parameters) throws IOException, RequestException { - return execute(()->propfind(URL2URI(url), parameters)); + return execute(()->propfind(url.toURI(), parameters)); } @Override @@ -1540,13 +1540,13 @@ public Response propfind(URI uri, List
headers) throws IOException, Requ @Override public Response propfind(URL url, List
headers) throws IOException, RequestException { - return execute(()->propfind(URL2URI(url), headers)); + return execute(()->propfind(url.toURI(), headers)); } @Override public Response propfind(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->propfind(URL2URI(url), parameters, headers)); + return execute(()->propfind(url.toURI(), parameters, headers)); } @Override @@ -1556,7 +1556,7 @@ public Response propfind(URI uri, int readTimeout) throws IOException, RequestEx @Override public Response propfind(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->propfind(URL2URI(url), readTimeout)); + return execute(()->propfind(url.toURI(), readTimeout)); } @Override @@ -1568,7 +1568,7 @@ public Response propfind(URI uri, int readTimeout, Map parameter @Override public Response propfind(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->propfind(URL2URI(url), readTimeout, parameters)); + return execute(()->propfind(url.toURI(), readTimeout, parameters)); } @Override @@ -1578,13 +1578,13 @@ public Response propfind(URI uri, int readTimeout, List
headers) throws @Override public Response propfind(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->propfind(URL2URI(url), readTimeout, headers)); + return execute(()->propfind(url.toURI(), readTimeout, headers)); } @Override public Response propfind(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->propfind(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->propfind(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -1594,7 +1594,7 @@ public Response proppatch(URI uri) throws IOException, RequestException { @Override public Response proppatch(URL url) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url))); + return execute(()->proppatch(url.toURI())); } @Override @@ -1604,7 +1604,7 @@ public Response proppatch(URI uri, Map parameters) throws IOExce @Override public Response proppatch(URL url, Map parameters) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url), parameters)); + return execute(()->proppatch(url.toURI(), parameters)); } @Override @@ -1614,7 +1614,7 @@ public Response proppatch(URI uri, List
headers) throws IOException, Req @Override public Response proppatch(URL url, List
headers) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url), headers)); + return execute(()->proppatch(url.toURI(), headers)); } @Override @@ -1626,7 +1626,7 @@ public Response proppatch(URI uri, Map parameters, List
@Override public Response proppatch(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url), parameters, headers)); + return execute(()->proppatch(url.toURI(), parameters, headers)); } @Override @@ -1636,7 +1636,7 @@ public Response proppatch(URI uri, RequestBody data) throws IOException, Requ @Override public Response proppatch(URL url, RequestBody data) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url), data)); + return execute(()->proppatch(url.toURI(), data)); } @Override @@ -1648,7 +1648,7 @@ public Response proppatch(URI uri, RequestBody data, Map para @Override public Response proppatch(URL url, RequestBody data, Map parameters) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url), data, parameters)); + return execute(()->proppatch(url.toURI(), data, parameters)); } @Override @@ -1658,13 +1658,13 @@ public Response proppatch(URI uri, RequestBody data, List
headers) th @Override public Response proppatch(URL url, RequestBody data, List
headers) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url), data, headers)); + return execute(()->proppatch(url.toURI(), data, headers)); } @Override public Response proppatch(URL url, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url), data, parameters, headers)); + return execute(()->proppatch(url.toURI(), data, parameters, headers)); } @Override @@ -1674,7 +1674,7 @@ public Response proppatch(URI uri, int readTimeout) throws IOException, RequestE @Override public Response proppatch(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url), readTimeout)); + return execute(()->proppatch(url.toURI(), readTimeout)); } @Override @@ -1686,7 +1686,7 @@ public Response proppatch(URI uri, int readTimeout, Map paramete @Override public Response proppatch(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url), readTimeout, parameters)); + return execute(()->proppatch(url.toURI(), readTimeout, parameters)); } @Override @@ -1696,7 +1696,7 @@ public Response proppatch(URI uri, int readTimeout, List
headers) throws @Override public Response proppatch(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url), readTimeout, headers)); + return execute(()->proppatch(url.toURI(), readTimeout, headers)); } @Override @@ -1708,7 +1708,7 @@ public Response proppatch(URI uri, int readTimeout, Map paramete @Override public Response proppatch(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->proppatch(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -1718,7 +1718,7 @@ public Response proppatch(URI uri, int readTimeout, RequestBody data) throws @Override public Response proppatch(URL url, int readTimeout, RequestBody data) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url), readTimeout, data)); + return execute(()->proppatch(url.toURI(), readTimeout, data)); } @Override @@ -1730,7 +1730,7 @@ public Response proppatch(URI uri, int readTimeout, RequestBody data, Map data, Map parameters) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url), readTimeout, data, parameters)); + return execute(()->proppatch(url.toURI(), readTimeout, data, parameters)); } @Override @@ -1742,13 +1742,13 @@ public Response proppatch(URI uri, int readTimeout, RequestBody data, List data, List
headers) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url), readTimeout, data, headers)); + return execute(()->proppatch(url.toURI(), readTimeout, data, headers)); } @Override public Response proppatch(URL url, int readTimeout, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->proppatch(URL2URI(url), readTimeout, data, parameters, headers)); + return execute(()->proppatch(url.toURI(), readTimeout, data, parameters, headers)); } @Override @@ -1758,7 +1758,7 @@ public Response report(URI uri) throws IOException, RequestException { @Override public Response report(URL url) throws IOException, RequestException { - return execute(()->report(URL2URI(url))); + return execute(()->report(url.toURI())); } @Override @@ -1768,7 +1768,7 @@ public Response report(URI uri, Map parameters) throws IOExcepti @Override public Response report(URL url, Map parameters) throws IOException, RequestException { - return execute(()->report(URL2URI(url), parameters)); + return execute(()->report(url.toURI(), parameters)); } @Override @@ -1778,7 +1778,7 @@ public Response report(URI uri, List
headers) throws IOException, Reques @Override public Response report(URL url, List
headers) throws IOException, RequestException { - return execute(()->report(URL2URI(url), headers)); + return execute(()->report(url.toURI(), headers)); } @Override @@ -1790,7 +1790,7 @@ public Response report(URI uri, Map parameters, List
hea @Override public Response report(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->report(URL2URI(url), parameters, headers)); + return execute(()->report(url.toURI(), parameters, headers)); } @Override @@ -1800,7 +1800,7 @@ public Response report(URI uri, RequestBody data) throws IOException, Request @Override public Response report(URL url, RequestBody data) throws IOException, RequestException { - return execute(()->report(URL2URI(url), data)); + return execute(()->report(url.toURI(), data)); } @Override @@ -1812,7 +1812,7 @@ public Response report(URI uri, RequestBody data, Map paramet @Override public Response report(URL url, RequestBody data, Map parameters) throws IOException, RequestException { - return execute(()->report(URL2URI(url), data, parameters)); + return execute(()->report(url.toURI(), data, parameters)); } @Override @@ -1822,13 +1822,13 @@ public Response report(URI uri, RequestBody data, List
headers) throw @Override public Response report(URL url, RequestBody data, List
headers) throws IOException, RequestException { - return execute(()->report(URL2URI(url), data, headers)); + return execute(()->report(url.toURI(), data, headers)); } @Override public Response report(URL url, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->report(URL2URI(url), data, parameters, headers)); + return execute(()->report(url.toURI(), data, parameters, headers)); } @Override @@ -1838,7 +1838,7 @@ public Response report(URI uri, int readTimeout) throws IOException, RequestExce @Override public Response report(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->report(URL2URI(url), readTimeout)); + return execute(()->report(url.toURI(), readTimeout)); } @Override @@ -1850,7 +1850,7 @@ public Response report(URI uri, int readTimeout, Map parameters) @Override public Response report(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->report(URL2URI(url), readTimeout, parameters)); + return execute(()->report(url.toURI(), readTimeout, parameters)); } @Override @@ -1860,7 +1860,7 @@ public Response report(URI uri, int readTimeout, List
headers) throws IO @Override public Response report(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->report(URL2URI(url), readTimeout, headers)); + return execute(()->report(url.toURI(), readTimeout, headers)); } @Override @@ -1872,7 +1872,7 @@ public Response report(URI uri, int readTimeout, Map parameters, @Override public Response report(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->report(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->report(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -1882,7 +1882,7 @@ public Response report(URI uri, int readTimeout, RequestBody data) throws IOE @Override public Response report(URL url, int readTimeout, RequestBody data) throws IOException, RequestException { - return execute(()->report(URL2URI(url), readTimeout, data)); + return execute(()->report(url.toURI(), readTimeout, data)); } @Override @@ -1894,7 +1894,7 @@ public Response report(URI uri, int readTimeout, RequestBody data, Map data, Map parameters) throws IOException, RequestException { - return execute(()->report(URL2URI(url), readTimeout, data, parameters)); + return execute(()->report(url.toURI(), readTimeout, data, parameters)); } @Override @@ -1906,13 +1906,13 @@ public Response report(URI uri, int readTimeout, RequestBody data, List data, List
headers) throws IOException, RequestException { - return execute(()->report(URL2URI(url), readTimeout, data, headers)); + return execute(()->report(url.toURI(), readTimeout, data, headers)); } @Override public Response report(URL url, int readTimeout, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->report(URL2URI(url), readTimeout, data, parameters, headers)); + return execute(()->report(url.toURI(), readTimeout, data, parameters, headers)); } @Override @@ -1922,7 +1922,7 @@ public Response view(URI uri) throws IOException, RequestException { @Override public Response view(URL url) throws IOException, RequestException { - return execute(()->view(URL2URI(url))); + return execute(()->view(url.toURI())); } @Override @@ -1932,7 +1932,7 @@ public Response view(URI uri, Map parameters) throws IOException @Override public Response view(URL url, Map parameters) throws IOException, RequestException { - return execute(()->view(URL2URI(url), parameters)); + return execute(()->view(url.toURI(), parameters)); } @Override @@ -1942,13 +1942,13 @@ public Response view(URI uri, List
headers) throws IOException, RequestE @Override public Response view(URL url, List
headers) throws IOException, RequestException { - return execute(()->view(URL2URI(url), headers)); + return execute(()->view(url.toURI(), headers)); } @Override public Response view(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->view(URL2URI(url), parameters, headers)); + return execute(()->view(url.toURI(), parameters, headers)); } @Override @@ -1958,7 +1958,7 @@ public Response view(URI uri, int readTimeout) throws IOException, RequestExcept @Override public Response view(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->view(URL2URI(url), readTimeout)); + return execute(()->view(url.toURI(), readTimeout)); } @Override @@ -1970,7 +1970,7 @@ public Response view(URI uri, int readTimeout, Map parameters) @Override public Response view(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->view(URL2URI(url), readTimeout, parameters)); + return execute(()->view(url.toURI(), readTimeout, parameters)); } @Override @@ -1980,13 +1980,13 @@ public Response view(URI uri, int readTimeout, List
headers) throws IOEx @Override public Response view(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->view(URL2URI(url), readTimeout, headers)); + return execute(()->view(url.toURI(), readTimeout, headers)); } @Override public Response view(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->view(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->view(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -1996,7 +1996,7 @@ public Response wrapped(URI uri) throws IOException, RequestException { @Override public Response wrapped(URL url) throws IOException, RequestException { - return execute(()->wrapped(URL2URI(url))); + return execute(()->wrapped(url.toURI())); } @Override @@ -2006,7 +2006,7 @@ public Response wrapped(URI uri, Map parameters) throws IOExcept @Override public Response wrapped(URL url, Map parameters) throws IOException, RequestException { - return execute(()->wrapped(URL2URI(url), parameters)); + return execute(()->wrapped(url.toURI(), parameters)); } @Override @@ -2016,13 +2016,13 @@ public Response wrapped(URI uri, List
headers) throws IOException, Reque @Override public Response wrapped(URL url, List
headers) throws IOException, RequestException { - return execute(()->wrapped(URL2URI(url), headers)); + return execute(()->wrapped(url.toURI(), headers)); } @Override public Response wrapped(URL url, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->wrapped(URL2URI(url), parameters, headers)); + return execute(()->wrapped(url.toURI(), parameters, headers)); } @Override @@ -2032,7 +2032,7 @@ public Response wrapped(URI uri, int readTimeout) throws IOException, RequestExc @Override public Response wrapped(URL url, int readTimeout) throws IOException, RequestException { - return execute(()->wrapped(URL2URI(url), readTimeout)); + return execute(()->wrapped(url.toURI(), readTimeout)); } @Override @@ -2044,7 +2044,7 @@ public Response wrapped(URI uri, int readTimeout, Map parameters @Override public Response wrapped(URL url, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->wrapped(URL2URI(url), readTimeout, parameters)); + return execute(()->wrapped(url.toURI(), readTimeout, parameters)); } @Override @@ -2054,13 +2054,13 @@ public Response wrapped(URI uri, int readTimeout, List
headers) throws I @Override public Response wrapped(URL url, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->wrapped(URL2URI(url), readTimeout, headers)); + return execute(()->wrapped(url.toURI(), readTimeout, headers)); } @Override public Response wrapped(URL url, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->wrapped(URL2URI(url), readTimeout, parameters, headers)); + return execute(()->wrapped(url.toURI(), readTimeout, parameters, headers)); } @Override @@ -2070,7 +2070,7 @@ public Response request(URI uri, RequestMethod requestMethod) throws IOException @Override public Response request(URL url, RequestMethod requestMethod) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod)); + return execute(()->request(url.toURI(), requestMethod)); } @Override @@ -2082,7 +2082,7 @@ public Response request(URI uri, RequestMethod requestMethod, Map parameters) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod, parameters)); + return execute(()->request(url.toURI(), requestMethod, parameters)); } @Override @@ -2094,7 +2094,7 @@ public Response request(URI uri, RequestMethod requestMethod, List
heade @Override public Response request(URL url, RequestMethod requestMethod, List
headers) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod, headers)); + return execute(()->request(url.toURI(), requestMethod, headers)); } @Override @@ -2106,7 +2106,7 @@ public Response request(URI uri, RequestMethod requestMethod, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod, parameters, headers)); + return execute(()->request(url.toURI(), requestMethod, parameters, headers)); } @Override @@ -2118,7 +2118,7 @@ public Response request(URI uri, RequestMethod requestMethod, RequestBody dat @Override public Response request(URL url, RequestMethod requestMethod, RequestBody data) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod, data)); + return execute(()->request(url.toURI(), requestMethod, data)); } @Override @@ -2130,7 +2130,7 @@ public Response request(URI uri, RequestMethod requestMethod, RequestBody dat @Override public Response request(URL url, RequestMethod requestMethod, RequestBody data, Map parameters) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod, data, parameters)); + return execute(()->request(url.toURI(), requestMethod, data, parameters)); } @Override @@ -2142,7 +2142,7 @@ public Response request(URI uri, RequestMethod requestMethod, RequestBody dat @Override public Response request(URL url, RequestMethod requestMethod, RequestBody data, List
headers) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod, data, headers)); + return execute(()->request(url.toURI(), requestMethod, data, headers)); } @Override @@ -2199,7 +2199,7 @@ public Response request(URI uri, RequestMethod requestMethod, RequestBody dat @Override public Response request(URL url, RequestMethod requestMethod, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod, data, parameters, headers)); + return execute(()->request(url.toURI(), requestMethod, data, parameters, headers)); } @Override @@ -2211,7 +2211,7 @@ public Response request(URI uri, RequestMethod requestMethod, int readTimeout) @Override public Response request(URL url, RequestMethod requestMethod, int readTimeout) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod, readTimeout)); + return execute(()->request(url.toURI(), requestMethod, readTimeout)); } @Override @@ -2223,7 +2223,7 @@ public Response request(URI uri, RequestMethod requestMethod, int readTimeout, M @Override public Response request(URL url, RequestMethod requestMethod, int readTimeout, Map parameters) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod, readTimeout, parameters)); + return execute(()->request(url.toURI(), requestMethod, readTimeout, parameters)); } @Override @@ -2235,7 +2235,7 @@ public Response request(URI uri, RequestMethod requestMethod, int readTimeout, L @Override public Response request(URL url, RequestMethod requestMethod, int readTimeout, List
headers) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod, readTimeout, headers)); + return execute(()->request(url.toURI(), requestMethod, readTimeout, headers)); } @Override @@ -2247,7 +2247,7 @@ public Response request(URI uri, RequestMethod requestMethod, int readTimeout, M @Override public Response request(URL url, RequestMethod requestMethod, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod, readTimeout, parameters, headers)); + return execute(()->request(url.toURI(), requestMethod, readTimeout, parameters, headers)); } @Override @@ -2259,7 +2259,7 @@ public Response request(URI uri, RequestMethod requestMethod, int readTimeout, R @Override public Response request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod, readTimeout, data)); + return execute(()->request(url.toURI(), requestMethod, readTimeout, data)); } @Override @@ -2272,7 +2272,7 @@ public Response request(URI uri, RequestMethod requestMethod, int readTimeout, R @Override public Response request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data, Map parameters) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod, readTimeout, data, parameters)); + return execute(()->request(url.toURI(), requestMethod, readTimeout, data, parameters)); } @Override @@ -2284,7 +2284,7 @@ public Response request(URI uri, RequestMethod requestMethod, int readTimeout, R @Override public Response request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data, List
headers) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod, readTimeout, data, headers)); + return execute(()->request(url.toURI(), requestMethod, readTimeout, data, headers)); } @Override @@ -2341,7 +2341,7 @@ public Response request(URI uri, RequestMethod requestMethod, int readTimeout, R @Override public Response request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return execute(()->request(URL2URI(url), requestMethod, readTimeout, data, parameters, headers)); + return execute(()->request(url.toURI(), requestMethod, readTimeout, data, parameters, headers)); } protected static T execute(final Execute execute) throws IOException, RequestException { diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpAsyncClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpAsyncClient.java index 32dec4323..fd8928afb 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpAsyncClient.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpAsyncClient.java @@ -19,34 +19,27 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient; -import com.buession.core.converter.mapper.PropertyMapper; -import com.buession.httpclient.apache.ApacheHttpAsyncClientBuilder; -import com.buession.httpclient.apache.ApacheRequest; -import com.buession.httpclient.apache.ApacheRequestBuilder; -import com.buession.httpclient.apache.nio.DefaultCallback; -import com.buession.httpclient.apache.nio.protocol.BasicAsyncResponseConsumer; +import com.buession.core.utils.ClassUtils; +import com.buession.httpclient.apache.Apache4AsyncClient; +import com.buession.httpclient.apache.Apache5AsyncClient; +import com.buession.httpclient.apache.ApacheAsyncClient; +import com.buession.httpclient.conn.Apache5NioClientConnectionManager; import com.buession.httpclient.conn.ApacheNioClientConnectionManager; import com.buession.httpclient.core.Configuration; import com.buession.httpclient.core.Header; import com.buession.httpclient.core.RequestBody; -import com.buession.httpclient.core.Response; import com.buession.httpclient.core.concurrent.Callback; import com.buession.httpclient.exception.RequestException; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.nio.client.methods.HttpAsyncMethods; -import org.apache.http.nio.protocol.HttpAsyncRequestProducer; import java.io.IOException; import java.net.URI; import java.util.List; import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; /** * Apache HttpComponents 异步 HttpClient @@ -56,16 +49,16 @@ */ public class ApacheHttpAsyncClient extends AbstractHttpAsyncClient { - private RequestConfig requestConfig; + private final static boolean V5 = ClassUtils.isPresent("org.apache.hc.client5.http.async.HttpAsyncClient"); - private org.apache.http.nio.client.HttpAsyncClient httpAsyncClient; + private ApacheAsyncClient httpAsyncClient; /** * 构造函数 */ public ApacheHttpAsyncClient() { super(); - setConnectionManager(new ApacheNioClientConnectionManager()); + setConnectionManager(V5 ? new Apache5NioClientConnectionManager() : new ApacheNioClientConnectionManager()); } /** @@ -73,363 +66,302 @@ public ApacheHttpAsyncClient() { * * @param connectionManager * 连接管理器 + * + * @since 3.0.0 */ - public ApacheHttpAsyncClient(ApacheNioClientConnectionManager connectionManager) { + public ApacheHttpAsyncClient(com.buession.httpclient.apache.ApacheNioClientConnectionManager connectionManager) { super(connectionManager); } /** * 构造函数 * - * @param httpAsyncClient - * {@link org.apache.http.nio.client.HttpAsyncClient} 实例 + * @param configuration + * 配置 + * + * @since 3.0.0 */ - public ApacheHttpAsyncClient(org.apache.http.nio.client.HttpAsyncClient httpAsyncClient) { - this.httpAsyncClient = httpAsyncClient; + public ApacheHttpAsyncClient(Configuration configuration) { + super(V5 ? new Apache5NioClientConnectionManager(configuration) : new ApacheNioClientConnectionManager( + configuration)); } /** * 构造函数 * * @param httpAsyncClient - * {@link org.apache.http.nio.client.HttpAsyncClient} 实例 - * @param requestConfig - * 请求配置 + * {@link ApacheAsyncClient} 实例 + * + * @since 3.0.0 */ - public ApacheHttpAsyncClient(org.apache.http.nio.client.HttpAsyncClient httpAsyncClient, - RequestConfig requestConfig) { + public ApacheHttpAsyncClient(ApacheAsyncClient httpAsyncClient) { this.httpAsyncClient = httpAsyncClient; - this.requestConfig = requestConfig; - } - - public RequestConfig getRequestConfig() { - if(requestConfig == null){ - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - final Configuration configuration = getConnectionManager().getConfiguration(); - final RequestConfig.Builder builder = RequestConfig.custom() - .setConnectTimeout(configuration.getConnectTimeout()) - .setConnectionRequestTimeout(configuration.getConnectionRequestTimeout()) - .setSocketTimeout(configuration.getReadTimeout()) - .setAuthenticationEnabled(configuration.isAuthenticationEnabled()) - .setContentCompressionEnabled(configuration.isContentCompressionEnabled()) - .setNormalizeUri(configuration.isNormalizeUri()); - - propertyMapper.from(configuration.isAllowRedirects()).to(builder::setRedirectsEnabled); - propertyMapper.from(configuration.getMaxRedirects()).to(builder::setMaxRedirects); - propertyMapper.from(configuration.isCircularRedirectsAllowed()).to(builder::setCircularRedirectsAllowed); - propertyMapper.from(configuration.isRelativeRedirectsAllowed()).to(builder::setRelativeRedirectsAllowed); - - requestConfig = builder.build(); - } - - return requestConfig; - } - - public void setRequestConfig(RequestConfig requestConfig) { - this.requestConfig = requestConfig; } - public org.apache.http.nio.client.HttpAsyncClient getHttpClient() { + public ApacheAsyncClient getHttpClient() { if(httpAsyncClient == null){ - final ApacheHttpAsyncClientBuilder httpAsyncClientBuilder = new ApacheHttpAsyncClientBuilder( - (ApacheNioClientConnectionManager) getConnectionManager()); - - httpAsyncClient = httpAsyncClientBuilder.build((builder)->{ - }); + httpAsyncClient = V5 ? new Apache5AsyncClient((Apache5NioClientConnectionManager) getConnectionManager(), + getHttpVersion()) : new Apache4AsyncClient( + (ApacheNioClientConnectionManager) getConnectionManager(), getHttpVersion()); } return httpAsyncClient; } - public void setHttpClient(org.apache.http.nio.client.HttpAsyncClient httpAsyncClient) { + public void setHttpClient(ApacheAsyncClient httpAsyncClient) { this.httpAsyncClient = httpAsyncClient; } @Override public void get(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).get(), callback); + getHttpClient().get(uri, parameters, headers, callback); } @Override public void get(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).get(), readTimeout, callback); + getHttpClient().get(uri, readTimeout, parameters, headers, callback); } @Override public void post(URI uri, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).post(data), callback); + getHttpClient().post(uri, parameters, headers, data, callback); } @Override public void post(URI uri, int readTimeout, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).post(data), readTimeout, callback); + getHttpClient().post(uri, readTimeout, parameters, headers, data, callback); } @Override public void put(URI uri, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).put(data), callback); + getHttpClient().put(uri, parameters, headers, data, callback); } @Override public void put(URI uri, int readTimeout, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).put(data), readTimeout, callback); + getHttpClient().put(uri, readTimeout, parameters, headers, data, callback); } @Override public void patch(URI uri, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).patch(data), callback); + getHttpClient().patch(uri, parameters, headers, data, callback); } @Override public void patch(URI uri, int readTimeout, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).patch(data), readTimeout, callback); + getHttpClient().patch(uri, readTimeout, parameters, headers, data, callback); } @Override public void delete(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).delete(), callback); + getHttpClient().delete(uri, parameters, headers, callback); } @Override public void delete(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).delete(), readTimeout, callback); + getHttpClient().delete(uri, readTimeout, parameters, headers, callback); } @Override public void connect(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).connect(), callback); + getHttpClient().connect(uri, parameters, headers, callback); } @Override public void connect(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).connect(), readTimeout, callback); + getHttpClient().connect(uri, readTimeout, parameters, headers, callback); } @Override public void trace(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).trace(), callback); + getHttpClient().trace(uri, parameters, headers, callback); } @Override public void trace(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).trace(), readTimeout, callback); + getHttpClient().trace(uri, readTimeout, parameters, headers, callback); } @Override public void copy(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).copy(), callback); + getHttpClient().copy(uri, parameters, headers, callback); } @Override public void copy(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).copy(), readTimeout, callback); + getHttpClient().copy(uri, readTimeout, parameters, headers, callback); } @Override public void move(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).move(), callback); + getHttpClient().move(uri, parameters, headers, callback); } @Override public void move(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).move(), readTimeout, callback); + getHttpClient().move(uri, readTimeout, parameters, headers, callback); } @Override public void head(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).head(), callback); + getHttpClient().head(uri, parameters, headers, callback); } @Override public void head(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).head(), readTimeout, callback); + getHttpClient().head(uri, readTimeout, parameters, headers, callback); } @Override public void options(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).options(), callback); + getHttpClient().options(uri, parameters, headers, callback); } @Override public void options(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).options(), readTimeout, callback); + getHttpClient().options(uri, readTimeout, parameters, headers, callback); } @Override public void link(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).link(), callback); + getHttpClient().link(uri, parameters, headers, callback); } @Override public void link(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).link(), readTimeout, callback); + getHttpClient().link(uri, readTimeout, parameters, headers, callback); } @Override public void unlink(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlink(), callback); + getHttpClient().unlink(uri, parameters, headers, callback); } @Override public void unlink(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlink(), readTimeout, callback); + getHttpClient().unlink(uri, readTimeout, parameters, headers, callback); } @Override public void purge(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).purge(), callback); + getHttpClient().purge(uri, parameters, headers, callback); } @Override public void purge(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).purge(), readTimeout, callback); + getHttpClient().purge(uri, readTimeout, parameters, headers, callback); } @Override public void lock(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).lock(), callback); + getHttpClient().lock(uri, parameters, headers, callback); } @Override public void lock(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).lock(), readTimeout, callback); + getHttpClient().lock(uri, readTimeout, parameters, headers, callback); } @Override public void unlock(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlock(), callback); + getHttpClient().unlock(uri, parameters, headers, callback); } @Override public void unlock(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlock(), readTimeout, callback); + getHttpClient().unlock(uri, readTimeout, parameters, headers, callback); } @Override public void propfind(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).propfind(), callback); + getHttpClient().propfind(uri, parameters, headers, callback); } @Override public void propfind(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).propfind(), readTimeout, callback); + getHttpClient().propfind(uri, readTimeout, parameters, headers, callback); } @Override public void proppatch(URI uri, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, - RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).proppatch(data), callback); + Callback callback) throws IOException, RequestException { + getHttpClient().proppatch(uri, parameters, headers, data, callback); } @Override public void proppatch(URI uri, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) - throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).proppatch(data), readTimeout, callback); + List
headers, Callback callback) throws IOException, RequestException { + getHttpClient().proppatch(uri, readTimeout, parameters, headers, data, callback); } @Override public void report(URI uri, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).report(data), callback); + getHttpClient().report(uri, parameters, headers, data, callback); } @Override public void report(URI uri, int readTimeout, RequestBody data, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).report(data), readTimeout, callback); + getHttpClient().report(uri, readTimeout, parameters, headers, data, callback); } @Override public void view(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).view(), callback); + getHttpClient().view(uri, parameters, headers, callback); } @Override public void view(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).view(), readTimeout, callback); + getHttpClient().view(uri, readTimeout, parameters, headers, callback); } @Override public void wrapped(URI uri, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).wrapped(), callback); + getHttpClient().wrapped(uri, parameters, headers, callback); } @Override public void wrapped(URI uri, int readTimeout, Map parameters, List
headers, Callback callback) throws IOException, RequestException { - doRequest(ApacheRequestBuilder.create(uri, parameters, headers).wrapped(), readTimeout, callback); - } - - protected void doRequest(final ApacheRequestBuilder builder, final Callback callback) throws IOException, - RequestException { - doRequest(builder, getRequestConfig(), callback); - } - - protected void doRequest(final ApacheRequestBuilder builder, final int readTimeout, final Callback callback) - throws IOException, RequestException { - final RequestConfig.Builder requestConfigBuilder = RequestConfig.copy(getRequestConfig()) - .setSocketTimeout(readTimeout); - doRequest(builder, requestConfigBuilder.build(), callback); - } - - protected void doRequest(final ApacheRequestBuilder builder, final RequestConfig requestConfig, - final Callback callback) throws IOException, RequestException { - final ApacheRequest request = builder.setRequestConfig(requestConfig) - .setProtocolVersion(getHttpVersion()).build(); - final HttpAsyncRequestProducer httpAsyncRequestProducer = HttpAsyncMethods.create( - request.getHttpRequest()); - - try{ - Future future = getHttpClient().execute(httpAsyncRequestProducer, - new BasicAsyncResponseConsumer(request.getHttpRequest()), - new DefaultCallback(callback)); - future.get(); - }catch(ExecutionException e){ - throw new RequestException(e.getMessage(), e); - }catch(InterruptedException e){ - throw new RequestException(e.getMessage(), e); - }finally{ - //request.getHttpRequest().releaseConnection(); - } + getHttpClient().wrapped(uri, readTimeout, parameters, headers, callback); } } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpClient.java index dd16a18d4..2d8c7a110 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpClient.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/ApacheHttpClient.java @@ -19,36 +19,25 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient; -import com.buession.core.converter.mapper.PropertyMapper; -import com.buession.httpclient.apache.ApacheHttpClientBuilder; -import com.buession.httpclient.apache.ApacheRequest; +import com.buession.core.utils.ClassUtils; +import com.buession.httpclient.apache.Apache4Client; +import com.buession.httpclient.apache.Apache5Client; +import com.buession.httpclient.apache.ApacheClient; +import com.buession.httpclient.conn.Apache5ClientConnectionManager; import com.buession.httpclient.conn.ApacheClientConnectionManager; import com.buession.httpclient.core.Configuration; import com.buession.httpclient.core.Header; import com.buession.httpclient.core.RequestBody; import com.buession.httpclient.core.Response; -import com.buession.httpclient.exception.ConnectTimeoutException; -import com.buession.httpclient.exception.ConnectionPoolTimeoutException; -import com.buession.httpclient.exception.ReadTimeoutException; -import com.buession.httpclient.exception.RequestAbortedException; import com.buession.httpclient.exception.RequestException; -import com.buession.httpclient.apache.ApacheRequestBuilder; -import com.buession.httpclient.apache.ApacheResponseBuilder; -import org.apache.http.HttpResponse; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.config.RequestConfig; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; -import java.net.SocketTimeoutException; import java.net.URI; -import java.net.UnknownHostException; import java.util.List; import java.util.Map; @@ -59,18 +48,17 @@ */ public class ApacheHttpClient extends AbstractHttpClient { - private RequestConfig requestConfig; + private final static boolean V5 = ClassUtils.isPresent("org.apache.hc.client5.http.classic.HttpClient"); - private org.apache.http.client.HttpClient httpClient; - - private final static Logger logger = LoggerFactory.getLogger(ApacheHttpClient.class); + private ApacheClient httpClient; /** * 构造函数 */ public ApacheHttpClient() { super(); - setConnectionManager(new ApacheClientConnectionManager()); + setConnectionManager(V5 ? new Apache5ClientConnectionManager() : + new ApacheClientConnectionManager()); } /** @@ -78,373 +66,302 @@ public ApacheHttpClient() { * * @param connectionManager * 连接管理器 + * + * @since 3.0.0 */ - public ApacheHttpClient(ApacheClientConnectionManager connectionManager) { + public ApacheHttpClient(com.buession.httpclient.apache.ApacheClientConnectionManager connectionManager) { super(connectionManager); } /** * 构造函数 * - * @param httpClient - * {@link org.apache.http.client.HttpClient} 实例 + * @param configuration + * 配置 + * + * @since 3.0.0 */ - public ApacheHttpClient(org.apache.http.client.HttpClient httpClient) { - this.httpClient = httpClient; + public ApacheHttpClient(Configuration configuration) { + super(V5 ? new Apache5ClientConnectionManager(configuration) : new ApacheClientConnectionManager( + configuration)); } /** * 构造函数 * * @param httpClient - * {@link org.apache.http.client.HttpClient} 实例 - * @param requestConfig - * 请求配置 + * {@link ApacheClient} 实例 + * + * @since 3.0.0 */ - public ApacheHttpClient(org.apache.http.client.HttpClient httpClient, RequestConfig requestConfig) { + public ApacheHttpClient(ApacheClient httpClient) { this.httpClient = httpClient; - this.requestConfig = requestConfig; - } - - public RequestConfig getRequestConfig() { - if(requestConfig == null){ - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - final Configuration configuration = getConnectionManager().getConfiguration(); - final RequestConfig.Builder builder = RequestConfig.custom() - .setConnectTimeout(configuration.getConnectTimeout()) - .setConnectionRequestTimeout(configuration.getConnectionRequestTimeout()) - .setSocketTimeout(configuration.getReadTimeout()) - .setAuthenticationEnabled(configuration.isAuthenticationEnabled()) - .setContentCompressionEnabled(configuration.isContentCompressionEnabled()) - .setNormalizeUri(configuration.isNormalizeUri()); - - propertyMapper.from(configuration.isAllowRedirects()).to(builder::setRedirectsEnabled); - propertyMapper.from(configuration.getMaxRedirects()).to(builder::setMaxRedirects); - propertyMapper.from(configuration.isCircularRedirectsAllowed()).to(builder::setCircularRedirectsAllowed); - propertyMapper.from(configuration.isRelativeRedirectsAllowed()).to(builder::setRelativeRedirectsAllowed); - - requestConfig = builder.build(); - } - - return requestConfig; - } - - public void setRequestConfig(RequestConfig requestConfig) { - this.requestConfig = requestConfig; } - public org.apache.http.client.HttpClient getHttpClient() { + public ApacheClient getHttpClient() { if(httpClient == null){ - final ApacheHttpClientBuilder httpClientBuilder = new ApacheHttpClientBuilder( - (ApacheClientConnectionManager) getConnectionManager()); - - httpClient = httpClientBuilder.build((builder)->{ - }); + httpClient = V5 ? new Apache5Client((Apache5ClientConnectionManager) getConnectionManager(), + getHttpVersion()) : new Apache4Client((ApacheClientConnectionManager) getConnectionManager(), + getHttpVersion()); } return httpClient; } - public void setHttpClient(org.apache.http.client.HttpClient httpClient) { + public void setHttpClient(ApacheClient httpClient) { this.httpClient = httpClient; } @Override public Response get(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).get()); + return getHttpClient().get(uri, parameters, headers); } @Override public Response get(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).get(), readTimeout); + return getHttpClient().get(uri, readTimeout, parameters, headers); } @Override public Response post(URI uri, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).post(data)); + return getHttpClient().post(uri, parameters, headers, data); } @Override public Response post(URI uri, int readTimeout, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).post(data), readTimeout); + return getHttpClient().post(uri, readTimeout, parameters, headers, data); } @Override public Response put(URI uri, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).put(data)); + return getHttpClient().put(uri, parameters, headers, data); } @Override public Response put(URI uri, int readTimeout, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).put(data), readTimeout); + return getHttpClient().put(uri, readTimeout, parameters, headers, data); } @Override public Response patch(URI uri, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).patch(data)); + return getHttpClient().patch(uri, parameters, headers, data); } @Override public Response patch(URI uri, int readTimeout, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).patch(data), readTimeout); + return getHttpClient().patch(uri, readTimeout, parameters, headers, data); } @Override public Response delete(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).delete()); + return getHttpClient().delete(uri, parameters, headers); } @Override public Response delete(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).delete(), readTimeout); + return getHttpClient().delete(uri, readTimeout, parameters, headers); } @Override public Response connect(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).connect()); + return getHttpClient().connect(uri, parameters, headers); } @Override public Response connect(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).connect(), readTimeout); + return getHttpClient().connect(uri, readTimeout, parameters, headers); } @Override public Response trace(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).trace()); + return getHttpClient().trace(uri, parameters, headers); } @Override public Response trace(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).trace(), readTimeout); + return getHttpClient().trace(uri, readTimeout, parameters, headers); } @Override public Response copy(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).copy()); + return getHttpClient().trace(uri, parameters, headers); } @Override public Response copy(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).copy(), readTimeout); + return getHttpClient().trace(uri, readTimeout, parameters, headers); } @Override public Response move(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).move()); + return getHttpClient().move(uri, parameters, headers); } @Override public Response move(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).move(), readTimeout); + return getHttpClient().move(uri, readTimeout, parameters, headers); } @Override public Response head(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).head()); + return getHttpClient().head(uri, parameters, headers); } @Override public Response head(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).head(), readTimeout); + return getHttpClient().head(uri, readTimeout, parameters, headers); } @Override public Response options(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).options()); + return getHttpClient().options(uri, parameters, headers); } @Override public Response options(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).options(), readTimeout); + return getHttpClient().options(uri, readTimeout, parameters, headers); } @Override public Response link(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).link()); + return getHttpClient().link(uri, parameters, headers); } @Override public Response link(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).link(), readTimeout); + return getHttpClient().link(uri, readTimeout, parameters, headers); } @Override public Response unlink(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlink()); + return getHttpClient().unlink(uri, parameters, headers); } @Override public Response unlink(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlink(), readTimeout); + return getHttpClient().unlink(uri, readTimeout, parameters, headers); } @Override public Response purge(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).purge()); + return getHttpClient().purge(uri, parameters, headers); } @Override public Response purge(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).purge(), readTimeout); + return getHttpClient().purge(uri, readTimeout, parameters, headers); } @Override public Response lock(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).lock()); + return getHttpClient().lock(uri, parameters, headers); } @Override public Response lock(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).lock(), readTimeout); + return getHttpClient().lock(uri, readTimeout, parameters, headers); } @Override public Response unlock(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlock()); + return getHttpClient().unlock(uri, parameters, headers); } @Override public Response unlock(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).unlock(), readTimeout); + return getHttpClient().unlock(uri, readTimeout, parameters, headers); } @Override public Response propfind(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).propfind()); + return getHttpClient().propfind(uri, parameters, headers); } @Override public Response propfind(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).propfind(), readTimeout); + return getHttpClient().propfind(uri, readTimeout, parameters, headers); } @Override public Response proppatch(URI uri, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).proppatch(data)); + return getHttpClient().proppatch(uri, parameters, headers, data); } @Override public Response proppatch(URI uri, int readTimeout, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).proppatch(data), readTimeout); + return getHttpClient().proppatch(uri, readTimeout, parameters, headers, data); } @Override public Response report(URI uri, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).report(data)); + return getHttpClient().report(uri, parameters, headers, data); } @Override public Response report(URI uri, int readTimeout, RequestBody data, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).report(data), readTimeout); + return getHttpClient().report(uri, readTimeout, parameters, headers, data); } @Override public Response view(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).view()); + return getHttpClient().view(uri, parameters, headers); } @Override public Response view(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).view(), readTimeout); + return getHttpClient().view(uri, readTimeout, parameters, headers); } @Override public Response wrapped(URI uri, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).wrapped()); + return getHttpClient().wrapped(uri, parameters, headers); } @Override public Response wrapped(URI uri, int readTimeout, Map parameters, List
headers) throws IOException, RequestException { - return doRequest(ApacheRequestBuilder.create(uri, parameters, headers).wrapped(), readTimeout); - } - - protected Response doRequest(final ApacheRequestBuilder builder) - throws IOException, RequestException { - return doRequest(builder, getRequestConfig()); - } - - protected Response doRequest(final ApacheRequestBuilder builder, final int readTimeout) - throws IOException, RequestException { - final RequestConfig.Builder requestConfigBuilder = RequestConfig.copy(getRequestConfig()) - .setSocketTimeout(readTimeout); - return doRequest(builder, requestConfigBuilder.build()); - } - - protected Response doRequest(final ApacheRequestBuilder builder, final RequestConfig requestConfig) - throws IOException, RequestException { - final ApacheRequest request = builder.setRequestConfig(requestConfig) - .setProtocolVersion(getHttpVersion()).build(); - final ApacheResponseBuilder apacheResponseBuilder = new ApacheResponseBuilder(); - - try{ - HttpResponse httpResponse = getHttpClient().execute(request.getHttpRequest()); - return apacheResponseBuilder.build(httpResponse); - }catch(IOException e){ - if(logger.isErrorEnabled()){ - logger.error("Request({}) url: {} error.", request.getMethod(), request.getUrl(), e); - } - - if(e instanceof org.apache.http.conn.ConnectionPoolTimeoutException){ - throw new ConnectionPoolTimeoutException(e.getMessage()); - }else if(e instanceof org.apache.http.conn.ConnectTimeoutException){ - throw new ConnectTimeoutException(e.getMessage()); - }else if(e instanceof SocketTimeoutException){ - throw new ReadTimeoutException(e.getMessage()); - }else if(e instanceof org.apache.http.impl.execchain.RequestAbortedException){ - throw new RequestAbortedException(e.getMessage()); - }else if(e instanceof ClientProtocolException){ - throw new RequestException(e.getMessage(), e); - }else if(e instanceof UnknownHostException){ - throw e; - }else{ - throw new RequestException(e.getMessage(), e); - } - }finally{ - request.getHttpRequest().releaseConnection(); - } + return getHttpClient().wrapped(uri, readTimeout, parameters, headers); } } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/HttpAsyncClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/HttpAsyncClient.java index 60c27d092..45ebee9b5 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/HttpAsyncClient.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/HttpAsyncClient.java @@ -19,11 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient; +import com.buession.httpclient.conn.NioConnectionManager; import com.buession.httpclient.core.Header; import com.buession.httpclient.core.RequestBody; import com.buession.httpclient.core.RequestMethod; @@ -42,7 +43,22 @@ * @author Yong.Teng * @since 2.3.0 */ -public interface HttpAsyncClient extends IBaseHttpClient { +public interface HttpAsyncClient extends IBaseHttpClient, IHttpClient { + + /** + * 获取连接管理器 + * + * @return 连接管理器 + */ + NioConnectionManager getConnectionManager(); + + /** + * 设置连接管理器 + * + * @param connectionManager + * 连接管理器 + */ + void setConnectionManager(NioConnectionManager connectionManager); /** * GET 请求 @@ -57,7 +73,7 @@ public interface HttpAsyncClient extends IBaseHttpClient { * @throws RequestException * 请求异常 */ - default void get(String url, Callback callback) throws IOException, RequestException{ + default void get(String url, Callback callback) throws IOException, RequestException { get(URI.create(url), callback); } @@ -107,7 +123,7 @@ default void get(String url, Callback callback) throws IOException, RequestExcep * 请求异常 */ default void get(String url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { get(URI.create(url), parameters, callback); } @@ -160,7 +176,7 @@ default void get(String url, Map parameters, Callback callback) * @throws RequestException * 请求异常 */ - default void get(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void get(String url, List
headers, Callback callback) throws IOException, RequestException { get(URI.create(url), headers, callback); } @@ -216,7 +232,7 @@ default void get(String url, List
headers, Callback callback) throws IOE * 请求异常 */ default void get(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { get(URI.create(url), parameters, headers, callback); } @@ -275,7 +291,7 @@ void get(URL url, Map parameters, List
headers, Callback * @throws RequestException * 请求异常 */ - default void get(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void get(String url, int readTimeout, Callback callback) throws IOException, RequestException { get(URI.create(url), readTimeout, callback); } @@ -331,7 +347,7 @@ default void get(String url, int readTimeout, Callback callback) throws IOExcept * 请求异常 */ default void get(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { get(URI.create(url), readTimeout, parameters, callback); } @@ -393,7 +409,7 @@ void get(URL url, int readTimeout, Map parameters, Callback call * 请求异常 */ default void get(String url, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { get(URI.create(url), readTimeout, headers, callback); } @@ -455,7 +471,7 @@ default void get(String url, int readTimeout, List
headers, Callback cal * 请求异常 */ default void get(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { get(URI.create(url), readTimeout, parameters, headers, callback); } @@ -516,7 +532,7 @@ void get(URL url, int readTimeout, Map parameters, List
* @throws RequestException * 请求异常 */ - default void post(String url, Callback callback) throws IOException, RequestException{ + default void post(String url, Callback callback) throws IOException, RequestException { post(URI.create(url), callback); } @@ -566,7 +582,7 @@ default void post(String url, Callback callback) throws IOException, RequestExce * 请求异常 */ default void post(String url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { post(URI.create(url), parameters, callback); } @@ -619,7 +635,7 @@ default void post(String url, Map parameters, Callback callback) * @throws RequestException * 请求异常 */ - default void post(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void post(String url, List
headers, Callback callback) throws IOException, RequestException { post(URI.create(url), headers, callback); } @@ -675,7 +691,7 @@ default void post(String url, List
headers, Callback callback) throws IO * 请求异常 */ default void post(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { post(URI.create(url), parameters, headers, callback); } @@ -734,7 +750,7 @@ void post(URL url, Map parameters, List
headers, Callbac * @throws RequestException * 请求异常 */ - default void post(String url, RequestBody data, Callback callback) throws IOException, RequestException{ + default void post(String url, RequestBody data, Callback callback) throws IOException, RequestException { post(URI.create(url), data, callback); } @@ -790,7 +806,7 @@ default void post(String url, RequestBody data, Callback callback) throws IOE * 请求异常 */ default void post(String url, RequestBody data, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { post(URI.create(url), data, parameters, callback); } @@ -852,7 +868,7 @@ void post(URL url, RequestBody data, Map parameters, Callback * 请求异常 */ default void post(String url, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { post(URI.create(url), data, headers, callback); } @@ -916,7 +932,7 @@ void post(URL url, RequestBody data, List
headers, Callback callback) * 请求异常 */ default void post(String url, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { post(URI.create(url), data, parameters, headers, callback); } @@ -979,7 +995,7 @@ void post(URL url, RequestBody data, Map parameters, List parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { post(URI.create(url), readTimeout, parameters, callback); } @@ -1097,7 +1113,7 @@ void post(URL url, int readTimeout, Map parameters, Callback cal * 请求异常 */ default void post(String url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { post(URI.create(url), readTimeout, headers, callback); } @@ -1159,7 +1175,7 @@ default void post(String url, int readTimeout, List
headers, Callback ca * 请求异常 */ default void post(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { post(URI.create(url), readTimeout, parameters, headers, callback); } @@ -1225,7 +1241,7 @@ void post(URL url, int readTimeout, Map parameters, List
* 请求异常 */ default void post(String url, int readTimeout, RequestBody data, Callback callback) throws IOException, - RequestException{ + RequestException { post(URI.create(url), readTimeout, data, callback); } @@ -1287,7 +1303,7 @@ default void post(String url, int readTimeout, RequestBody data, Callback cal * 请求异常 */ default void post(String url, int readTimeout, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { post(URI.create(url), readTimeout, data, parameters, callback); } @@ -1355,7 +1371,7 @@ void post(URL url, int readTimeout, RequestBody data, Map par * 请求异常 */ default void post(String url, int readTimeout, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { post(URI.create(url), readTimeout, data, headers, callback); } @@ -1425,7 +1441,7 @@ void post(URL url, int readTimeout, RequestBody data, List
headers, C * 请求异常 */ default void post(String url, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { post(URI.create(url), readTimeout, data, parameters, headers, callback); } @@ -1490,7 +1506,7 @@ void post(URL url, int readTimeout, RequestBody data, Map par * @throws RequestException * 请求异常 */ - default void put(String url, Callback callback) throws IOException, RequestException{ + default void put(String url, Callback callback) throws IOException, RequestException { put(URI.create(url), callback); } @@ -1540,7 +1556,7 @@ default void put(String url, Callback callback) throws IOException, RequestExcep * 请求异常 */ default void put(String url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { put(URI.create(url), parameters, callback); } @@ -1593,7 +1609,7 @@ default void put(String url, Map parameters, Callback callback) * @throws RequestException * 请求异常 */ - default void put(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void put(String url, List
headers, Callback callback) throws IOException, RequestException { put(URI.create(url), headers, callback); } @@ -1649,7 +1665,7 @@ default void put(String url, List
headers, Callback callback) throws IOE * 请求异常 */ default void put(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { put(URI.create(url), parameters, headers, callback); } @@ -1708,7 +1724,7 @@ void put(URL url, Map parameters, List
headers, Callback * @throws RequestException * 请求异常 */ - default void put(String url, RequestBody data, Callback callback) throws IOException, RequestException{ + default void put(String url, RequestBody data, Callback callback) throws IOException, RequestException { put(URI.create(url), data, callback); } @@ -1764,7 +1780,7 @@ default void put(String url, RequestBody data, Callback callback) throws IOEx * 请求异常 */ default void put(String url, RequestBody data, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { put(URI.create(url), data, parameters, callback); } @@ -1826,7 +1842,7 @@ void put(URL url, RequestBody data, Map parameters, Callback * 请求异常 */ default void put(String url, RequestBody data, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { put(URI.create(url), data, headers, callback); } @@ -1890,7 +1906,7 @@ void put(URL url, RequestBody data, List
headers, Callback callback) * 请求异常 */ default void put(String url, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { put(URI.create(url), data, parameters, headers, callback); } @@ -1953,7 +1969,7 @@ void put(URL url, RequestBody data, Map parameters, List parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { put(URI.create(url), readTimeout, parameters, callback); } @@ -2071,7 +2087,7 @@ void put(URL url, int readTimeout, Map parameters, Callback call * 请求异常 */ default void put(String url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { put(URI.create(url), readTimeout, headers, callback); } @@ -2133,7 +2149,7 @@ default void put(String url, int readTimeout, List
headers, Callback cal * 请求异常 */ default void put(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { put(URI.create(url), readTimeout, parameters, headers, callback); } @@ -2199,7 +2215,7 @@ void put(URL url, int readTimeout, Map parameters, List
* 请求异常 */ default void put(String url, int readTimeout, RequestBody data, Callback callback) throws IOException, - RequestException{ + RequestException { put(URI.create(url), readTimeout, data, callback); } @@ -2261,7 +2277,7 @@ default void put(String url, int readTimeout, RequestBody data, Callback call * 请求异常 */ default void put(String url, int readTimeout, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { put(URI.create(url), readTimeout, data, parameters, callback); } @@ -2329,7 +2345,7 @@ void put(URL url, int readTimeout, RequestBody data, Map para * 请求异常 */ default void put(String url, int readTimeout, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { put(URI.create(url), readTimeout, data, headers, callback); } @@ -2399,7 +2415,7 @@ void put(URL url, int readTimeout, RequestBody data, List
headers, Ca * 请求异常 */ default void put(String url, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { put(URI.create(url), readTimeout, data, parameters, headers, callback); } @@ -2464,7 +2480,7 @@ void put(URL url, int readTimeout, RequestBody data, Map para * @throws RequestException * 请求异常 */ - default void patch(String url, Callback callback) throws IOException, RequestException{ + default void patch(String url, Callback callback) throws IOException, RequestException { patch(URI.create(url), callback); } @@ -2514,7 +2530,7 @@ default void patch(String url, Callback callback) throws IOException, RequestExc * 请求异常 */ default void patch(String url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { patch(URI.create(url), parameters, callback); } @@ -2567,7 +2583,7 @@ default void patch(String url, Map parameters, Callback callback * @throws RequestException * 请求异常 */ - default void patch(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void patch(String url, List
headers, Callback callback) throws IOException, RequestException { patch(URI.create(url), headers, callback); } @@ -2623,7 +2639,7 @@ default void patch(String url, List
headers, Callback callback) throws I * 请求异常 */ default void patch(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { patch(URI.create(url), parameters, headers, callback); } @@ -2682,7 +2698,7 @@ void patch(URL url, Map parameters, List
headers, Callba * @throws RequestException * 请求异常 */ - default void patch(String url, RequestBody data, Callback callback) throws IOException, RequestException{ + default void patch(String url, RequestBody data, Callback callback) throws IOException, RequestException { patch(URI.create(url), data, callback); } @@ -2738,7 +2754,7 @@ default void patch(String url, RequestBody data, Callback callback) throws IO * 请求异常 */ default void patch(String url, RequestBody data, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { patch(URI.create(url), data, parameters, callback); } @@ -2800,7 +2816,7 @@ void patch(URL url, RequestBody data, Map parameters, Callbac * 请求异常 */ default void patch(String url, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { patch(URI.create(url), data, headers, callback); } @@ -2864,7 +2880,7 @@ void patch(URL url, RequestBody data, List
headers, Callback callback * 请求异常 */ default void patch(String url, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { patch(URI.create(url), data, parameters, headers, callback); } @@ -2927,7 +2943,7 @@ void patch(URL url, RequestBody data, Map parameters, List parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { patch(URI.create(url), readTimeout, parameters, callback); } @@ -3045,7 +3061,7 @@ void patch(URL url, int readTimeout, Map parameters, Callback ca * 请求异常 */ default void patch(String url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { patch(URI.create(url), readTimeout, headers, callback); } @@ -3107,7 +3123,7 @@ default void patch(String url, int readTimeout, List
headers, Callback c * 请求异常 */ default void patch(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { patch(URI.create(url), readTimeout, parameters, headers, callback); } @@ -3173,7 +3189,7 @@ void patch(URL url, int readTimeout, Map parameters, List
data, Callback callback) throws IOException, - RequestException{ + RequestException { patch(URI.create(url), readTimeout, data, callback); } @@ -3235,7 +3251,7 @@ default void patch(String url, int readTimeout, RequestBody data, Callback ca * 请求异常 */ default void patch(String url, int readTimeout, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { patch(URI.create(url), readTimeout, data, parameters, callback); } @@ -3303,7 +3319,7 @@ void patch(URL url, int readTimeout, RequestBody data, Map pa * 请求异常 */ default void patch(String url, int readTimeout, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { patch(URI.create(url), readTimeout, data, headers, callback); } @@ -3373,7 +3389,7 @@ void patch(URL url, int readTimeout, RequestBody data, List
headers, * 请求异常 */ default void patch(String url, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { patch(URI.create(url), readTimeout, data, parameters, headers, callback); } @@ -3438,7 +3454,7 @@ void patch(URL url, int readTimeout, RequestBody data, Map pa * @throws RequestException * 请求异常 */ - default void delete(String url, Callback callback) throws IOException, RequestException{ + default void delete(String url, Callback callback) throws IOException, RequestException { delete(URI.create(url), callback); } @@ -3488,7 +3504,7 @@ default void delete(String url, Callback callback) throws IOException, RequestEx * 请求异常 */ default void delete(String url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { delete(URI.create(url), parameters, callback); } @@ -3541,7 +3557,7 @@ default void delete(String url, Map parameters, Callback callbac * @throws RequestException * 请求异常 */ - default void delete(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void delete(String url, List
headers, Callback callback) throws IOException, RequestException { delete(URI.create(url), headers, callback); } @@ -3597,7 +3613,7 @@ default void delete(String url, List
headers, Callback callback) throws * 请求异常 */ default void delete(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { delete(URI.create(url), parameters, headers, callback); } @@ -3656,7 +3672,7 @@ void delete(URL url, Map parameters, List
headers, Callb * @throws RequestException * 请求异常 */ - default void delete(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void delete(String url, int readTimeout, Callback callback) throws IOException, RequestException { delete(URI.create(url), readTimeout, callback); } @@ -3712,7 +3728,7 @@ default void delete(String url, int readTimeout, Callback callback) throws IOExc * 请求异常 */ default void delete(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { delete(URI.create(url), readTimeout, parameters, callback); } @@ -3774,7 +3790,7 @@ void delete(URL url, int readTimeout, Map parameters, Callback c * 请求异常 */ default void delete(String url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { delete(URI.create(url), readTimeout, headers, callback); } @@ -3836,7 +3852,7 @@ default void delete(String url, int readTimeout, List
headers, Callback * 请求异常 */ default void delete(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { delete(URI.create(url), readTimeout, parameters, headers, callback); } @@ -3897,7 +3913,7 @@ void delete(URL url, int readTimeout, Map parameters, List parameters, Callback callback) throws IOException, - RequestException{ + RequestException { connect(URI.create(url), parameters, callback); } @@ -4000,7 +4016,7 @@ default void connect(String url, Map parameters, Callback callba * @throws RequestException * 请求异常 */ - default void connect(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void connect(String url, List
headers, Callback callback) throws IOException, RequestException { connect(URI.create(url), headers, callback); } @@ -4056,7 +4072,7 @@ default void connect(String url, List
headers, Callback callback) throws * 请求异常 */ default void connect(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { connect(URI.create(url), parameters, headers, callback); } @@ -4115,7 +4131,7 @@ void connect(URL url, Map parameters, List
headers, Call * @throws RequestException * 请求异常 */ - default void connect(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void connect(String url, int readTimeout, Callback callback) throws IOException, RequestException { connect(URI.create(url), readTimeout, callback); } @@ -4171,7 +4187,7 @@ default void connect(String url, int readTimeout, Callback callback) throws IOEx * 请求异常 */ default void connect(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { connect(URI.create(url), readTimeout, parameters, callback); } @@ -4233,7 +4249,7 @@ void connect(URL url, int readTimeout, Map parameters, Callback * 请求异常 */ default void connect(String url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { connect(URI.create(url), readTimeout, headers, callback); } @@ -4297,7 +4313,7 @@ void connect(URL url, int readTimeout, List
headers, Callback callback) * 请求异常 */ default void connect(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { connect(URI.create(url), readTimeout, parameters, headers, callback); } @@ -4358,7 +4374,7 @@ void connect(URL url, int readTimeout, Map parameters, List parameters, Callback callback) throws IOException, - RequestException{ + RequestException { trace(URI.create(url), parameters, callback); } @@ -4461,7 +4477,7 @@ default void trace(String url, Map parameters, Callback callback * @throws RequestException * 请求异常 */ - default void trace(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void trace(String url, List
headers, Callback callback) throws IOException, RequestException { trace(URI.create(url), headers, callback); } @@ -4517,7 +4533,7 @@ default void trace(String url, List
headers, Callback callback) throws I * 请求异常 */ default void trace(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { trace(URI.create(url), parameters, headers, callback); } @@ -4576,7 +4592,7 @@ void trace(URL url, Map parameters, List
headers, Callba * @throws RequestException * 请求异常 */ - default void trace(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void trace(String url, int readTimeout, Callback callback) throws IOException, RequestException { trace(URI.create(url), readTimeout, callback); } @@ -4632,7 +4648,7 @@ default void trace(String url, int readTimeout, Callback callback) throws IOExce * 请求异常 */ default void trace(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { trace(URI.create(url), readTimeout, parameters, callback); } @@ -4694,7 +4710,7 @@ void trace(URL url, int readTimeout, Map parameters, Callback ca * 请求异常 */ default void trace(String url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { trace(URI.create(url), readTimeout, headers, callback); } @@ -4756,7 +4772,7 @@ default void trace(String url, int readTimeout, List
headers, Callback c * 请求异常 */ default void trace(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { trace(URI.create(url), readTimeout, parameters, headers, callback); } @@ -4817,7 +4833,7 @@ void trace(URL url, int readTimeout, Map parameters, List
parameters, Callback callback) throws IOException, - RequestException{ + RequestException { copy(URI.create(url), parameters, callback); } @@ -4920,7 +4936,7 @@ default void copy(String url, Map parameters, Callback callback) * @throws RequestException * 请求异常 */ - default void copy(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void copy(String url, List
headers, Callback callback) throws IOException, RequestException { copy(URI.create(url), headers, callback); } @@ -4976,7 +4992,7 @@ default void copy(String url, List
headers, Callback callback) throws IO * 请求异常 */ default void copy(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { copy(URI.create(url), parameters, headers, callback); } @@ -5035,7 +5051,7 @@ void copy(URL url, Map parameters, List
headers, Callbac * @throws RequestException * 请求异常 */ - default void copy(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void copy(String url, int readTimeout, Callback callback) throws IOException, RequestException { copy(URI.create(url), readTimeout, callback); } @@ -5091,7 +5107,7 @@ default void copy(String url, int readTimeout, Callback callback) throws IOExcep * 请求异常 */ default void copy(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { copy(URI.create(url), readTimeout, parameters, callback); } @@ -5153,7 +5169,7 @@ void copy(URL url, int readTimeout, Map parameters, Callback cal * 请求异常 */ default void copy(String url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { copy(URI.create(url), readTimeout, headers, callback); } @@ -5215,7 +5231,7 @@ default void copy(String url, int readTimeout, List
headers, Callback ca * 请求异常 */ default void copy(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { copy(URI.create(url), readTimeout, parameters, headers, callback); } @@ -5276,7 +5292,7 @@ void copy(URL url, int readTimeout, Map parameters, List
* @throws RequestException * 请求异常 */ - default void move(String url, Callback callback) throws IOException, RequestException{ + default void move(String url, Callback callback) throws IOException, RequestException { move(URI.create(url), callback); } @@ -5326,7 +5342,7 @@ default void move(String url, Callback callback) throws IOException, RequestExce * 请求异常 */ default void move(String url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { move(URI.create(url), parameters, callback); } @@ -5379,7 +5395,7 @@ default void move(String url, Map parameters, Callback callback) * @throws RequestException * 请求异常 */ - default void move(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void move(String url, List
headers, Callback callback) throws IOException, RequestException { move(URI.create(url), headers, callback); } @@ -5435,7 +5451,7 @@ default void move(String url, List
headers, Callback callback) throws IO * 请求异常 */ default void move(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { move(URI.create(url), parameters, headers, callback); } @@ -5494,7 +5510,7 @@ void move(URL url, Map parameters, List
headers, Callbac * @throws RequestException * 请求异常 */ - default void move(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void move(String url, int readTimeout, Callback callback) throws IOException, RequestException { move(URI.create(url), readTimeout, callback); } @@ -5550,7 +5566,7 @@ default void move(String url, int readTimeout, Callback callback) throws IOExcep * 请求异常 */ default void move(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { move(URI.create(url), readTimeout, parameters, callback); } @@ -5612,7 +5628,7 @@ void move(URL url, int readTimeout, Map parameters, Callback cal * 请求异常 */ default void move(String url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { move(URI.create(url), readTimeout, headers, callback); } @@ -5674,7 +5690,7 @@ default void move(String url, int readTimeout, List
headers, Callback ca * 请求异常 */ default void move(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { move(URI.create(url), readTimeout, parameters, headers, callback); } @@ -5735,7 +5751,7 @@ void move(URL url, int readTimeout, Map parameters, List
* @throws RequestException * 请求异常 */ - default void head(String url, Callback callback) throws IOException, RequestException{ + default void head(String url, Callback callback) throws IOException, RequestException { head(URI.create(url), callback); } @@ -5785,7 +5801,7 @@ default void head(String url, Callback callback) throws IOException, RequestExce * 请求异常 */ default void head(String url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { head(URI.create(url), parameters, callback); } @@ -5838,7 +5854,7 @@ default void head(String url, Map parameters, Callback callback) * @throws RequestException * 请求异常 */ - default void head(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void head(String url, List
headers, Callback callback) throws IOException, RequestException { head(URI.create(url), headers, callback); } @@ -5894,7 +5910,7 @@ default void head(String url, List
headers, Callback callback) throws IO * 请求异常 */ default void head(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { head(URI.create(url), parameters, headers, callback); } @@ -5953,7 +5969,7 @@ void head(URL url, Map parameters, List
headers, Callbac * @throws RequestException * 请求异常 */ - default void head(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void head(String url, int readTimeout, Callback callback) throws IOException, RequestException { head(URI.create(url), readTimeout, callback); } @@ -6009,7 +6025,7 @@ default void head(String url, int readTimeout, Callback callback) throws IOExcep * 请求异常 */ default void head(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { head(URI.create(url), readTimeout, parameters, callback); } @@ -6071,7 +6087,7 @@ void head(URL url, int readTimeout, Map parameters, Callback cal * 请求异常 */ default void head(String url, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { head(URI.create(url), readTimeout, headers, callback); } @@ -6133,7 +6149,7 @@ default void head(String url, int readTimeout, List
headers, Callback ca * 请求异常 */ default void head(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { head(URI.create(url), readTimeout, parameters, headers, callback); } @@ -6194,7 +6210,7 @@ void head(URL url, int readTimeout, Map parameters, List
* @throws RequestException * 请求异常 */ - default void options(String url, Callback callback) throws IOException, RequestException{ + default void options(String url, Callback callback) throws IOException, RequestException { options(URI.create(url), callback); } @@ -6244,7 +6260,7 @@ default void options(String url, Callback callback) throws IOException, RequestE * 请求异常 */ default void options(String url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { options(URI.create(url), parameters, callback); } @@ -6297,7 +6313,7 @@ default void options(String url, Map parameters, Callback callba * @throws RequestException * 请求异常 */ - default void options(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void options(String url, List
headers, Callback callback) throws IOException, RequestException { options(URI.create(url), headers, callback); } @@ -6353,7 +6369,7 @@ default void options(String url, List
headers, Callback callback) throws * 请求异常 */ default void options(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { options(URI.create(url), parameters, headers, callback); } @@ -6412,7 +6428,7 @@ void options(URL url, Map parameters, List
headers, Call * @throws RequestException * 请求异常 */ - default void options(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void options(String url, int readTimeout, Callback callback) throws IOException, RequestException { options(URI.create(url), readTimeout, callback); } @@ -6468,7 +6484,7 @@ default void options(String url, int readTimeout, Callback callback) throws IOEx * 请求异常 */ default void options(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { options(URI.create(url), readTimeout, parameters, callback); } @@ -6530,7 +6546,7 @@ void options(URL url, int readTimeout, Map parameters, Callback * 请求异常 */ default void options(String url, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { options(URI.create(url), readTimeout, headers, callback); } @@ -6594,7 +6610,7 @@ void options(URL url, int readTimeout, List
headers, Callback callback) * 请求异常 */ default void options(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { options(URI.create(url), readTimeout, parameters, headers, callback); } @@ -6655,7 +6671,7 @@ void options(URL url, int readTimeout, Map parameters, List parameters, Callback callback) throws IOException, - RequestException{ + RequestException { link(URI.create(url), parameters, callback); } @@ -6758,7 +6774,7 @@ default void link(String url, Map parameters, Callback callback) * @throws RequestException * 请求异常 */ - default void link(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void link(String url, List
headers, Callback callback) throws IOException, RequestException { link(URI.create(url), headers, callback); } @@ -6814,7 +6830,7 @@ default void link(String url, List
headers, Callback callback) throws IO * 请求异常 */ default void link(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { link(URI.create(url), parameters, headers, callback); } @@ -6873,7 +6889,7 @@ void link(URL url, Map parameters, List
headers, Callbac * @throws RequestException * 请求异常 */ - default void link(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void link(String url, int readTimeout, Callback callback) throws IOException, RequestException { link(URI.create(url), readTimeout, callback); } @@ -6929,7 +6945,7 @@ default void link(String url, int readTimeout, Callback callback) throws IOExcep * 请求异常 */ default void link(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { link(URI.create(url), readTimeout, parameters, callback); } @@ -6991,7 +7007,7 @@ void link(URL url, int readTimeout, Map parameters, Callback cal * 请求异常 */ default void link(String url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { link(URI.create(url), readTimeout, headers, callback); } @@ -7053,7 +7069,7 @@ default void link(String url, int readTimeout, List
headers, Callback ca * 请求异常 */ default void link(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { link(URI.create(url), readTimeout, parameters, headers, callback); } @@ -7114,7 +7130,7 @@ void link(URL url, int readTimeout, Map parameters, List
* @throws RequestException * 请求异常 */ - default void unlink(String url, Callback callback) throws IOException, RequestException{ + default void unlink(String url, Callback callback) throws IOException, RequestException { unlink(URI.create(url), callback); } @@ -7164,7 +7180,7 @@ default void unlink(String url, Callback callback) throws IOException, RequestEx * 请求异常 */ default void unlink(String url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { unlink(URI.create(url), parameters, callback); } @@ -7217,7 +7233,7 @@ default void unlink(String url, Map parameters, Callback callbac * @throws RequestException * 请求异常 */ - default void unlink(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void unlink(String url, List
headers, Callback callback) throws IOException, RequestException { unlink(URI.create(url), headers, callback); } @@ -7273,7 +7289,7 @@ default void unlink(String url, List
headers, Callback callback) throws * 请求异常 */ default void unlink(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { unlink(URI.create(url), parameters, headers, callback); } @@ -7332,7 +7348,7 @@ void unlink(URL url, Map parameters, List
headers, Callb * @throws RequestException * 请求异常 */ - default void unlink(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void unlink(String url, int readTimeout, Callback callback) throws IOException, RequestException { unlink(URI.create(url), readTimeout, callback); } @@ -7388,7 +7404,7 @@ default void unlink(String url, int readTimeout, Callback callback) throws IOExc * 请求异常 */ default void unlink(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { unlink(URI.create(url), readTimeout, parameters, callback); } @@ -7450,7 +7466,7 @@ void unlink(URL url, int readTimeout, Map parameters, Callback c * 请求异常 */ default void unlink(String url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { unlink(URI.create(url), readTimeout, headers, callback); } @@ -7512,7 +7528,7 @@ default void unlink(String url, int readTimeout, List
headers, Callback * 请求异常 */ default void unlink(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { unlink(URI.create(url), readTimeout, parameters, headers, callback); } @@ -7573,7 +7589,7 @@ void unlink(URL url, int readTimeout, Map parameters, List parameters, Callback callback) throws IOException, - RequestException{ + RequestException { purge(URI.create(url), parameters, callback); } @@ -7676,7 +7692,7 @@ default void purge(String url, Map parameters, Callback callback * @throws RequestException * 请求异常 */ - default void purge(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void purge(String url, List
headers, Callback callback) throws IOException, RequestException { purge(URI.create(url), headers, callback); } @@ -7732,7 +7748,7 @@ default void purge(String url, List
headers, Callback callback) throws I * 请求异常 */ default void purge(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { purge(URI.create(url), parameters, headers, callback); } @@ -7791,7 +7807,7 @@ void purge(URL url, Map parameters, List
headers, Callba * @throws RequestException * 请求异常 */ - default void purge(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void purge(String url, int readTimeout, Callback callback) throws IOException, RequestException { purge(URI.create(url), readTimeout, callback); } @@ -7847,7 +7863,7 @@ default void purge(String url, int readTimeout, Callback callback) throws IOExce * 请求异常 */ default void purge(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { purge(URI.create(url), readTimeout, parameters, callback); } @@ -7909,7 +7925,7 @@ void purge(URL url, int readTimeout, Map parameters, Callback ca * 请求异常 */ default void purge(String url, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { purge(URI.create(url), readTimeout, headers, callback); } @@ -7971,7 +7987,7 @@ default void purge(String url, int readTimeout, List
headers, Callback c * 请求异常 */ default void purge(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { purge(URI.create(url), readTimeout, parameters, headers, callback); } @@ -8032,7 +8048,7 @@ void purge(URL url, int readTimeout, Map parameters, List
parameters, Callback callback) throws IOException, - RequestException{ + RequestException { lock(URI.create(url), parameters, callback); } @@ -8135,7 +8151,7 @@ default void lock(String url, Map parameters, Callback callback) * @throws RequestException * 请求异常 */ - default void lock(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void lock(String url, List
headers, Callback callback) throws IOException, RequestException { lock(URI.create(url), headers, callback); } @@ -8191,7 +8207,7 @@ default void lock(String url, List
headers, Callback callback) throws IO * 请求异常 */ default void lock(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { lock(URI.create(url), parameters, headers, callback); } @@ -8250,7 +8266,7 @@ void lock(URL url, Map parameters, List
headers, Callbac * @throws RequestException * 请求异常 */ - default void lock(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void lock(String url, int readTimeout, Callback callback) throws IOException, RequestException { lock(URI.create(url), readTimeout, callback); } @@ -8306,7 +8322,7 @@ default void lock(String url, int readTimeout, Callback callback) throws IOExcep * 请求异常 */ default void lock(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { lock(URI.create(url), readTimeout, parameters, callback); } @@ -8368,7 +8384,7 @@ void lock(URL url, int readTimeout, Map parameters, Callback cal * 请求异常 */ default void lock(String url, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { lock(URI.create(url), readTimeout, headers, callback); } @@ -8430,7 +8446,7 @@ default void lock(String url, int readTimeout, List
headers, Callback ca * 请求异常 */ default void lock(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { lock(URI.create(url), readTimeout, parameters, headers, callback); } @@ -8491,7 +8507,7 @@ void lock(URL url, int readTimeout, Map parameters, List
* @throws RequestException * 请求异常 */ - default void unlock(String url, Callback callback) throws IOException, RequestException{ + default void unlock(String url, Callback callback) throws IOException, RequestException { unlock(URI.create(url), callback); } @@ -8541,7 +8557,7 @@ default void unlock(String url, Callback callback) throws IOException, RequestEx * 请求异常 */ default void unlock(String url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { unlock(URI.create(url), parameters, callback); } @@ -8594,7 +8610,7 @@ default void unlock(String url, Map parameters, Callback callbac * @throws RequestException * 请求异常 */ - default void unlock(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void unlock(String url, List
headers, Callback callback) throws IOException, RequestException { unlock(URI.create(url), headers, callback); } @@ -8650,7 +8666,7 @@ default void unlock(String url, List
headers, Callback callback) throws * 请求异常 */ default void unlock(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { unlock(URI.create(url), parameters, headers, callback); } @@ -8709,7 +8725,7 @@ void unlock(URL url, Map parameters, List
headers, Callb * @throws RequestException * 请求异常 */ - default void unlock(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void unlock(String url, int readTimeout, Callback callback) throws IOException, RequestException { unlock(URI.create(url), readTimeout, callback); } @@ -8765,7 +8781,7 @@ default void unlock(String url, int readTimeout, Callback callback) throws IOExc * 请求异常 */ default void unlock(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { unlock(URI.create(url), readTimeout, parameters, callback); } @@ -8827,7 +8843,7 @@ void unlock(URL url, int readTimeout, Map parameters, Callback c * 请求异常 */ default void unlock(String url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { unlock(URI.create(url), readTimeout, headers, callback); } @@ -8889,7 +8905,7 @@ default void unlock(String url, int readTimeout, List
headers, Callback * 请求异常 */ default void unlock(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { unlock(URI.create(url), readTimeout, parameters, headers, callback); } @@ -8950,7 +8966,7 @@ void unlock(URL url, int readTimeout, Map parameters, List parameters, Callback callback) throws IOException, - RequestException{ + RequestException { propfind(URI.create(url), parameters, callback); } @@ -9053,7 +9069,7 @@ default void propfind(String url, Map parameters, Callback callb * @throws RequestException * 请求异常 */ - default void propfind(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void propfind(String url, List
headers, Callback callback) throws IOException, RequestException { propfind(URI.create(url), headers, callback); } @@ -9109,7 +9125,7 @@ default void propfind(String url, List
headers, Callback callback) throw * 请求异常 */ default void propfind(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { propfind(URI.create(url), parameters, headers, callback); } @@ -9168,7 +9184,7 @@ void propfind(URL url, Map parameters, List
headers, Cal * @throws RequestException * 请求异常 */ - default void propfind(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void propfind(String url, int readTimeout, Callback callback) throws IOException, RequestException { propfind(URI.create(url), readTimeout, callback); } @@ -9224,7 +9240,7 @@ default void propfind(String url, int readTimeout, Callback callback) throws IOE * 请求异常 */ default void propfind(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { propfind(URI.create(url), readTimeout, parameters, callback); } @@ -9286,7 +9302,7 @@ void propfind(URL url, int readTimeout, Map parameters, Callback * 请求异常 */ default void propfind(String url, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { propfind(URI.create(url), readTimeout, headers, callback); } @@ -9350,7 +9366,7 @@ void propfind(URL url, int readTimeout, List
headers, Callback callback) * 请求异常 */ default void propfind(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { propfind(URI.create(url), readTimeout, parameters, headers, callback); } @@ -9411,7 +9427,7 @@ void propfind(URL url, int readTimeout, Map parameters, List parameters, Callback callback) throws IOException, - RequestException{ + RequestException { proppatch(URI.create(url), parameters, callback); } @@ -9514,7 +9530,7 @@ default void proppatch(String url, Map parameters, Callback call * @throws RequestException * 请求异常 */ - default void proppatch(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void proppatch(String url, List
headers, Callback callback) throws IOException, RequestException { proppatch(URI.create(url), headers, callback); } @@ -9570,7 +9586,7 @@ default void proppatch(String url, List
headers, Callback callback) thro * 请求异常 */ default void proppatch(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { proppatch(URI.create(url), parameters, headers, callback); } @@ -9629,7 +9645,7 @@ void proppatch(URL url, Map parameters, List
headers, Ca * @throws RequestException * 请求异常 */ - default void proppatch(String url, RequestBody data, Callback callback) throws IOException, RequestException{ + default void proppatch(String url, RequestBody data, Callback callback) throws IOException, RequestException { proppatch(URI.create(url), data, callback); } @@ -9685,7 +9701,7 @@ default void proppatch(String url, RequestBody data, Callback callback) throw * 请求异常 */ default void proppatch(String url, RequestBody data, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { proppatch(URI.create(url), data, parameters, callback); } @@ -9747,7 +9763,7 @@ void proppatch(URL url, RequestBody data, Map parameters, Cal * 请求异常 */ default void proppatch(String url, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { proppatch(URI.create(url), data, headers, callback); } @@ -9812,7 +9828,7 @@ void proppatch(URL url, RequestBody data, List
headers, Callback call */ default void proppatch(String url, RequestBody data, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { proppatch(URI.create(url), data, parameters, headers, callback); } @@ -9875,7 +9891,7 @@ void proppatch(URL url, RequestBody data, Map parameters, Lis * @throws RequestException * 请求异常 */ - default void proppatch(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void proppatch(String url, int readTimeout, Callback callback) throws IOException, RequestException { proppatch(URI.create(url), readTimeout, callback); } @@ -9931,7 +9947,7 @@ default void proppatch(String url, int readTimeout, Callback callback) throws IO * 请求异常 */ default void proppatch(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { proppatch(URI.create(url), readTimeout, parameters, callback); } @@ -9993,7 +10009,7 @@ void proppatch(URL url, int readTimeout, Map parameters, Callbac * 请求异常 */ default void proppatch(String url, int readTimeout, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { proppatch(URI.create(url), readTimeout, headers, callback); } @@ -10057,7 +10073,7 @@ void proppatch(URL url, int readTimeout, List
headers, Callback callback * 请求异常 */ default void proppatch(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { proppatch(URI.create(url), readTimeout, parameters, headers, callback); } @@ -10123,7 +10139,7 @@ void proppatch(URL url, int readTimeout, Map parameters, List data, Callback callback) throws IOException, - RequestException{ + RequestException { proppatch(URI.create(url), readTimeout, data, callback); } @@ -10187,7 +10203,7 @@ void proppatch(URL url, int readTimeout, RequestBody data, Callback callback) * 请求异常 */ default void proppatch(String url, int readTimeout, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { proppatch(URI.create(url), readTimeout, data, parameters, callback); } @@ -10255,7 +10271,7 @@ void proppatch(URL url, int readTimeout, RequestBody data, Map data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { proppatch(URI.create(url), readTimeout, data, headers, callback); } @@ -10325,7 +10341,7 @@ void proppatch(URL url, int readTimeout, RequestBody data, List
heade * 请求异常 */ default void proppatch(String url, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { proppatch(URI.create(url), readTimeout, data, parameters, headers, callback); } @@ -10390,7 +10406,7 @@ void proppatch(URL url, int readTimeout, RequestBody data, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { report(URI.create(url), parameters, callback); } @@ -10493,7 +10509,7 @@ default void report(String url, Map parameters, Callback callbac * @throws RequestException * 请求异常 */ - default void report(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void report(String url, List
headers, Callback callback) throws IOException, RequestException { report(URI.create(url), headers, callback); } @@ -10549,7 +10565,7 @@ default void report(String url, List
headers, Callback callback) throws * 请求异常 */ default void report(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { report(URI.create(url), parameters, headers, callback); } @@ -10608,7 +10624,7 @@ void report(URL url, Map parameters, List
headers, Callb * @throws RequestException * 请求异常 */ - default void report(String url, RequestBody data, Callback callback) throws IOException, RequestException{ + default void report(String url, RequestBody data, Callback callback) throws IOException, RequestException { report(URI.create(url), data, callback); } @@ -10664,7 +10680,7 @@ default void report(String url, RequestBody data, Callback callback) throws I * 请求异常 */ default void report(String url, RequestBody data, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { report(URI.create(url), data, parameters, callback); } @@ -10726,7 +10742,7 @@ void report(URL url, RequestBody data, Map parameters, Callba * 请求异常 */ default void report(String url, RequestBody data, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { report(URI.create(url), data, headers, callback); } @@ -10790,7 +10806,7 @@ void report(URL url, RequestBody data, List
headers, Callback callbac * 请求异常 */ default void report(String url, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { report(URI.create(url), data, parameters, headers, callback); } @@ -10853,7 +10869,7 @@ void report(URL url, RequestBody data, Map parameters, List parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { report(URI.create(url), readTimeout, parameters, callback); } @@ -10971,7 +10987,7 @@ void report(URL url, int readTimeout, Map parameters, Callback c * 请求异常 */ default void report(String url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { report(URI.create(url), readTimeout, headers, callback); } @@ -11033,7 +11049,7 @@ default void report(String url, int readTimeout, List
headers, Callback * 请求异常 */ default void report(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { report(URI.create(url), readTimeout, parameters, headers, callback); } @@ -11099,7 +11115,7 @@ void report(URL url, int readTimeout, Map parameters, List data, Callback callback) throws IOException, - RequestException{ + RequestException { report(URI.create(url), readTimeout, data, callback); } @@ -11161,7 +11177,7 @@ default void report(String url, int readTimeout, RequestBody data, Callback c * 请求异常 */ default void report(String url, int readTimeout, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { report(URI.create(url), readTimeout, data, parameters, callback); } @@ -11229,7 +11245,7 @@ void report(URL url, int readTimeout, RequestBody data, Map p * 请求异常 */ default void report(String url, int readTimeout, RequestBody data, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { report(URI.create(url), readTimeout, data, headers, callback); } @@ -11299,7 +11315,7 @@ void report(URL url, int readTimeout, RequestBody data, List
headers, * 请求异常 */ default void report(String url, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { report(URI.create(url), readTimeout, data, parameters, headers, callback); } @@ -11364,7 +11380,7 @@ void report(URL url, int readTimeout, RequestBody data, Map p * @throws RequestException * 请求异常 */ - default void view(String url, Callback callback) throws IOException, RequestException{ + default void view(String url, Callback callback) throws IOException, RequestException { view(URI.create(url), callback); } @@ -11414,7 +11430,7 @@ default void view(String url, Callback callback) throws IOException, RequestExce * 请求异常 */ default void view(String url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { view(URI.create(url), parameters, callback); } @@ -11467,7 +11483,7 @@ default void view(String url, Map parameters, Callback callback) * @throws RequestException * 请求异常 */ - default void view(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void view(String url, List
headers, Callback callback) throws IOException, RequestException { view(URI.create(url), headers, callback); } @@ -11523,7 +11539,7 @@ default void view(String url, List
headers, Callback callback) throws IO * 请求异常 */ default void view(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { view(URI.create(url), parameters, headers, callback); } @@ -11582,7 +11598,7 @@ void view(URL url, Map parameters, List
headers, Callbac * @throws RequestException * 请求异常 */ - default void view(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void view(String url, int readTimeout, Callback callback) throws IOException, RequestException { view(URI.create(url), readTimeout, callback); } @@ -11638,7 +11654,7 @@ default void view(String url, int readTimeout, Callback callback) throws IOExcep * 请求异常 */ default void view(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { view(URI.create(url), readTimeout, parameters, callback); } @@ -11700,7 +11716,7 @@ void view(URL url, int readTimeout, Map parameters, Callback cal * 请求异常 */ default void view(String url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { view(URI.create(url), readTimeout, headers, callback); } @@ -11762,7 +11778,7 @@ default void view(String url, int readTimeout, List
headers, Callback ca * 请求异常 */ default void view(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { view(URI.create(url), readTimeout, parameters, headers, callback); } @@ -11823,7 +11839,7 @@ void view(URL url, int readTimeout, Map parameters, List
* @throws RequestException * 请求异常 */ - default void wrapped(String url, Callback callback) throws IOException, RequestException{ + default void wrapped(String url, Callback callback) throws IOException, RequestException { wrapped(URI.create(url), callback); } @@ -11873,7 +11889,7 @@ default void wrapped(String url, Callback callback) throws IOException, RequestE * 请求异常 */ default void wrapped(String url, Map parameters, Callback callback) throws IOException, - RequestException{ + RequestException { wrapped(URI.create(url), parameters, callback); } @@ -11926,7 +11942,7 @@ default void wrapped(String url, Map parameters, Callback callba * @throws RequestException * 请求异常 */ - default void wrapped(String url, List
headers, Callback callback) throws IOException, RequestException{ + default void wrapped(String url, List
headers, Callback callback) throws IOException, RequestException { wrapped(URI.create(url), headers, callback); } @@ -11982,7 +11998,7 @@ default void wrapped(String url, List
headers, Callback callback) throws * 请求异常 */ default void wrapped(String url, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { wrapped(URI.create(url), parameters, headers, callback); } @@ -12041,7 +12057,7 @@ void wrapped(URL url, Map parameters, List
headers, Call * @throws RequestException * 请求异常 */ - default void wrapped(String url, int readTimeout, Callback callback) throws IOException, RequestException{ + default void wrapped(String url, int readTimeout, Callback callback) throws IOException, RequestException { wrapped(URI.create(url), readTimeout, callback); } @@ -12097,7 +12113,7 @@ default void wrapped(String url, int readTimeout, Callback callback) throws IOEx * 请求异常 */ default void wrapped(String url, int readTimeout, Map parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { wrapped(URI.create(url), readTimeout, parameters, callback); } @@ -12159,7 +12175,7 @@ void wrapped(URL url, int readTimeout, Map parameters, Callback * 请求异常 */ default void wrapped(String url, int readTimeout, List
headers, Callback callback) throws IOException, - RequestException{ + RequestException { wrapped(URI.create(url), readTimeout, headers, callback); } @@ -12223,7 +12239,7 @@ void wrapped(URL url, int readTimeout, List
headers, Callback callback) * 请求异常 */ default void wrapped(String url, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { wrapped(URI.create(url), readTimeout, parameters, headers, callback); } @@ -12287,7 +12303,7 @@ void wrapped(URL url, int readTimeout, Map parameters, List parameters, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { request(URI.create(url), requestMethod, parameters, callback); } @@ -12405,7 +12421,7 @@ void request(URL url, RequestMethod requestMethod, Map parameter * 请求异常 */ default void request(String url, RequestMethod requestMethod, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { request(URI.create(url), requestMethod, headers, callback); } @@ -12469,7 +12485,7 @@ void request(URL url, RequestMethod requestMethod, List
headers, Callbac * 请求异常 */ default void request(String url, RequestMethod requestMethod, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { request(URI.create(url), requestMethod, parameters, headers, callback); } @@ -12535,7 +12551,7 @@ void request(URL url, RequestMethod requestMethod, Map parameter * 请求异常 */ default void request(String url, RequestMethod requestMethod, RequestBody data, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { request(URI.create(url), requestMethod, data, callback); } @@ -12599,7 +12615,7 @@ void request(URL url, RequestMethod requestMethod, RequestBody data, Callback * 请求异常 */ default void request(String url, RequestMethod requestMethod, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { request(URI.create(url), requestMethod, data, parameters, callback); } @@ -12667,7 +12683,7 @@ void request(URL url, RequestMethod requestMethod, RequestBody data, Map data, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { request(URI.create(url), requestMethod, data, headers, callback); } @@ -12737,7 +12753,7 @@ void request(URL url, RequestMethod requestMethod, RequestBody data, List data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { request(URI.create(url), requestMethod, data, parameters, headers, callback); } @@ -12807,7 +12823,7 @@ void request(URL url, RequestMethod requestMethod, RequestBody data, Map parameters, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { request(URI.create(url), requestMethod, readTimeout, parameters, callback); } @@ -12939,7 +12955,7 @@ void request(URL url, RequestMethod requestMethod, int readTimeout, Map headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { request(URI.create(url), requestMethod, readTimeout, headers, callback); } @@ -13009,7 +13025,7 @@ void request(URL url, RequestMethod requestMethod, int readTimeout, List
* 请求异常 */ default void request(String url, RequestMethod requestMethod, int readTimeout, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { request(URI.create(url), requestMethod, readTimeout, parameters, headers, callback); } @@ -13081,7 +13097,7 @@ void request(URL url, RequestMethod requestMethod, int readTimeout, Map data, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { request(URI.create(url), requestMethod, readTimeout, data, callback); } @@ -13151,7 +13167,7 @@ void request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody< * 请求异常 */ default void request(String url, RequestMethod requestMethod, int readTimeout, RequestBody data, - Map parameters, Callback callback) throws IOException, RequestException{ + Map parameters, Callback callback) throws IOException, RequestException { request(URI.create(url), requestMethod, readTimeout, data, parameters, callback); } @@ -13225,7 +13241,7 @@ void request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody< * 请求异常 */ default void request(String url, RequestMethod requestMethod, int readTimeout, RequestBody data, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { request(URI.create(url), requestMethod, readTimeout, data, headers, callback); } @@ -13302,7 +13318,7 @@ void request(URL url, RequestMethod requestMethod, int readTimeout, RequestBody< */ default void request(String url, RequestMethod requestMethod, int readTimeout, RequestBody data, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { request(URI.create(url), requestMethod, readTimeout, data, parameters, headers, callback); } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/HttpClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/HttpClient.java index 85cc9f75b..d0b24c480 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/HttpClient.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/HttpClient.java @@ -24,6 +24,7 @@ */ package com.buession.httpclient; +import com.buession.httpclient.conn.ConnectionManager; import com.buession.httpclient.core.Header; import com.buession.httpclient.core.RequestBody; import com.buession.httpclient.core.RequestMethod; @@ -41,7 +42,22 @@ * * @author Yong.Teng */ -public interface HttpClient extends IBaseHttpClient { +public interface HttpClient extends IBaseHttpClient, IHttpClient { + + /** + * 获取连接管理器 + * + * @return 连接管理器 + */ + ConnectionManager getConnectionManager(); + + /** + * 设置连接管理器 + * + * @param connectionManager + * 连接管理器 + */ + void setConnectionManager(ConnectionManager connectionManager); /** * GET 请求 @@ -56,7 +72,7 @@ public interface HttpClient extends IBaseHttpClient { * @throws RequestException * 请求异常 */ - default Response get(String url) throws IOException, RequestException{ + default Response get(String url) throws IOException, RequestException { return get(URI.create(url)); } @@ -106,7 +122,7 @@ default Response get(String url) throws IOException, RequestException{ * @throws RequestException * 请求异常 */ - default Response get(String url, Map parameters) throws IOException, RequestException{ + default Response get(String url, Map parameters) throws IOException, RequestException { return get(URI.create(url), parameters); } @@ -160,7 +176,7 @@ default Response get(String url, Map parameters) throws IOExcept * @throws RequestException * 请求异常 */ - default Response get(String url, List
headers) throws IOException, RequestException{ + default Response get(String url, List
headers) throws IOException, RequestException { return get(URI.create(url), headers); } @@ -217,7 +233,7 @@ default Response get(String url, List
headers) throws IOException, Reque * 请求异常 */ default Response get(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return get(URI.create(url), parameters, headers); } @@ -276,7 +292,7 @@ default Response get(String url, Map parameters, List
he * 请求异常 * @since 2.3.0 */ - default Response get(String url, int readTimeout) throws IOException, RequestException{ + default Response get(String url, int readTimeout) throws IOException, RequestException { return get(URI.create(url), readTimeout); } @@ -335,7 +351,7 @@ default Response get(String url, int readTimeout) throws IOException, RequestExc * @since 2.3.0 */ default Response get(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return get(URI.create(url), readTimeout, parameters); } @@ -397,7 +413,7 @@ default Response get(String url, int readTimeout, Map parameters * 请求异常 * @since 2.3.0 */ - default Response get(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response get(String url, int readTimeout, List
headers) throws IOException, RequestException { return get(URI.create(url), readTimeout, headers); } @@ -462,7 +478,7 @@ default Response get(String url, int readTimeout, List
headers) throws I * @since 2.3.0 */ default Response get(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return get(URI.create(url), readTimeout, parameters, headers); } @@ -525,7 +541,7 @@ Response get(URL url, int readTimeout, Map parameters, List parameters) throws IOException, RequestException{ + default Response post(String url, Map parameters) throws IOException, RequestException { return post(URI.create(url), parameters); } @@ -629,7 +645,7 @@ default Response post(String url, Map parameters) throws IOExcep * @throws RequestException * 请求异常 */ - default Response post(String url, List
headers) throws IOException, RequestException{ + default Response post(String url, List
headers) throws IOException, RequestException { return post(URI.create(url), headers); } @@ -686,7 +702,7 @@ default Response post(String url, List
headers) throws IOException, Requ * 请求异常 */ default Response post(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return post(URI.create(url), parameters, headers); } @@ -744,7 +760,7 @@ default Response post(String url, Map parameters, List
h * @throws RequestException * 请求异常 */ - default Response post(String url, RequestBody data) throws IOException, RequestException{ + default Response post(String url, RequestBody data) throws IOException, RequestException { return post(URI.create(url), data); } @@ -801,7 +817,7 @@ default Response post(String url, RequestBody data) throws IOException, Reque * 请求异常 */ default Response post(String url, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return post(URI.create(url), data, parameters); } @@ -861,7 +877,7 @@ default Response post(String url, RequestBody data, Map param * @throws RequestException * 请求异常 */ - default Response post(String url, RequestBody data, List
headers) throws IOException, RequestException{ + default Response post(String url, RequestBody data, List
headers) throws IOException, RequestException { return post(URI.create(url), data, headers); } @@ -924,7 +940,7 @@ default Response post(String url, RequestBody data, List
headers) thr * 请求异常 */ default Response post(String url, RequestBody data, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return post(URI.create(url), data, parameters, headers); } @@ -989,7 +1005,7 @@ Response post(URL url, RequestBody data, Map parameters, List * 请求异常 * @since 2.3.0 */ - default Response post(String url, int readTimeout) throws IOException, RequestException{ + default Response post(String url, int readTimeout) throws IOException, RequestException { return post(URI.create(url), readTimeout); } @@ -1048,7 +1064,7 @@ default Response post(String url, int readTimeout) throws IOException, RequestEx * @since 2.3.0 */ default Response post(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return post(URI.create(url), readTimeout, parameters); } @@ -1110,7 +1126,7 @@ default Response post(String url, int readTimeout, Map parameter * 请求异常 * @since 2.3.0 */ - default Response post(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response post(String url, int readTimeout, List
headers) throws IOException, RequestException { return post(URI.create(url), readTimeout, headers); } @@ -1175,7 +1191,7 @@ default Response post(String url, int readTimeout, List
headers) throws * @since 2.3.0 */ default Response post(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return post(URI.create(url), readTimeout, parameters, headers); } @@ -1243,7 +1259,7 @@ Response post(URL url, int readTimeout, Map parameters, List data) throws IOException, RequestException{ + default Response post(String url, int readTimeout, RequestBody data) throws IOException, RequestException { return post(URI.create(url), readTimeout, data); } @@ -1308,7 +1324,7 @@ default Response post(String url, int readTimeout, RequestBody data) throws I * @since 2.3.0 */ default Response post(String url, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return post(URI.create(url), readTimeout, data, parameters); } @@ -1379,7 +1395,7 @@ Response post(URL url, int readTimeout, RequestBody data, Map * @since 2.3.0 */ default Response post(String url, int readTimeout, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return post(URI.create(url), readTimeout, data, headers); } @@ -1452,7 +1468,7 @@ Response post(URL url, int readTimeout, RequestBody data, List
header * @since 2.3.0 */ default Response post(String url, int readTimeout, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return post(URI.create(url), readTimeout, data, parameters, headers); } @@ -1519,7 +1535,7 @@ Response post(URL url, int readTimeout, RequestBody data, Map * @throws RequestException * 请求异常 */ - default Response put(String url) throws IOException, RequestException{ + default Response put(String url) throws IOException, RequestException { return put(URI.create(url)); } @@ -1569,7 +1585,7 @@ default Response put(String url) throws IOException, RequestException{ * @throws RequestException * 请求异常 */ - default Response put(String url, Map parameters) throws IOException, RequestException{ + default Response put(String url, Map parameters) throws IOException, RequestException { return put(URI.create(url), parameters); } @@ -1623,7 +1639,7 @@ default Response put(String url, Map parameters) throws IOExcept * @throws RequestException * 请求异常 */ - default Response put(String url, List
headers) throws IOException, RequestException{ + default Response put(String url, List
headers) throws IOException, RequestException { return put(URI.create(url), headers); } @@ -1680,7 +1696,7 @@ default Response put(String url, List
headers) throws IOException, Reque * 请求异常 */ default Response put(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return put(URI.create(url), parameters, headers); } @@ -1738,7 +1754,7 @@ default Response put(String url, Map parameters, List
he * @throws RequestException * 请求异常 */ - default Response put(String url, RequestBody data) throws IOException, RequestException{ + default Response put(String url, RequestBody data) throws IOException, RequestException { return put(URI.create(url), data); } @@ -1795,7 +1811,7 @@ default Response put(String url, RequestBody data) throws IOException, Reques * 请求异常 */ default Response put(String url, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return put(URI.create(url), data, parameters); } @@ -1855,7 +1871,7 @@ default Response put(String url, RequestBody data, Map parame * @throws RequestException * 请求异常 */ - default Response put(String url, RequestBody data, List
headers) throws IOException, RequestException{ + default Response put(String url, RequestBody data, List
headers) throws IOException, RequestException { return put(URI.create(url), data, headers); } @@ -1918,7 +1934,7 @@ default Response put(String url, RequestBody data, List
headers) thro * 请求异常 */ default Response put(String url, RequestBody data, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return put(URI.create(url), data, parameters, headers); } @@ -1983,7 +1999,7 @@ Response put(URL url, RequestBody data, Map parameters, List< * 请求异常 * @since 2.3.0 */ - default Response put(String url, int readTimeout) throws IOException, RequestException{ + default Response put(String url, int readTimeout) throws IOException, RequestException { return put(URI.create(url), readTimeout); } @@ -2042,7 +2058,7 @@ default Response put(String url, int readTimeout) throws IOException, RequestExc * @since 2.3.0 */ default Response put(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return put(URI.create(url), readTimeout, parameters); } @@ -2104,7 +2120,7 @@ default Response put(String url, int readTimeout, Map parameters * 请求异常 * @since 2.3.0 */ - default Response put(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response put(String url, int readTimeout, List
headers) throws IOException, RequestException { return put(URI.create(url), readTimeout, headers); } @@ -2169,7 +2185,7 @@ default Response put(String url, int readTimeout, List
headers) throws I * @since 2.3.0 */ default Response put(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return put(URI.create(url), readTimeout, parameters, headers); } @@ -2237,7 +2253,7 @@ Response put(URL url, int readTimeout, Map parameters, List data) throws IOException, RequestException{ + default Response put(String url, int readTimeout, RequestBody data) throws IOException, RequestException { return put(URI.create(url), readTimeout, data); } @@ -2302,7 +2318,7 @@ default Response put(String url, int readTimeout, RequestBody data) throws IO * @since 2.3.0 */ default Response put(String url, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return put(URI.create(url), readTimeout, data, parameters); } @@ -2373,7 +2389,7 @@ Response put(URL url, int readTimeout, RequestBody data, Map * @since 2.3.0 */ default Response put(String url, int readTimeout, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return put(URI.create(url), readTimeout, data, headers); } @@ -2446,7 +2462,7 @@ Response put(URL url, int readTimeout, RequestBody data, List
headers * @since 2.3.0 */ default Response put(String url, int readTimeout, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return put(URI.create(url), readTimeout, data, parameters, headers); } @@ -2513,7 +2529,7 @@ Response put(URL url, int readTimeout, RequestBody data, Map * @throws RequestException * 请求异常 */ - default Response patch(String url) throws IOException, RequestException{ + default Response patch(String url) throws IOException, RequestException { return patch(URI.create(url)); } @@ -2563,7 +2579,7 @@ default Response patch(String url) throws IOException, RequestException{ * @throws RequestException * 请求异常 */ - default Response patch(String url, Map parameters) throws IOException, RequestException{ + default Response patch(String url, Map parameters) throws IOException, RequestException { return patch(URI.create(url), parameters); } @@ -2617,7 +2633,7 @@ default Response patch(String url, Map parameters) throws IOExce * @throws RequestException * 请求异常 */ - default Response patch(String url, List
headers) throws IOException, RequestException{ + default Response patch(String url, List
headers) throws IOException, RequestException { return patch(URI.create(url), headers); } @@ -2674,7 +2690,7 @@ default Response patch(String url, List
headers) throws IOException, Req * 请求异常 */ default Response patch(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return patch(URI.create(url), parameters, headers); } @@ -2732,7 +2748,7 @@ default Response patch(String url, Map parameters, List
* @throws RequestException * 请求异常 */ - default Response patch(String url, RequestBody data) throws IOException, RequestException{ + default Response patch(String url, RequestBody data) throws IOException, RequestException { return patch(URI.create(url), data); } @@ -2789,7 +2805,7 @@ default Response patch(String url, RequestBody data) throws IOException, Requ * 请求异常 */ default Response patch(String url, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return patch(URI.create(url), data, parameters); } @@ -2849,7 +2865,7 @@ default Response patch(String url, RequestBody data, Map para * @throws RequestException * 请求异常 */ - default Response patch(String url, RequestBody data, List
headers) throws IOException, RequestException{ + default Response patch(String url, RequestBody data, List
headers) throws IOException, RequestException { return patch(URI.create(url), data, headers); } @@ -2912,7 +2928,7 @@ default Response patch(String url, RequestBody data, List
headers) th * 请求异常 */ default Response patch(String url, RequestBody data, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return patch(URI.create(url), data, parameters, headers); } @@ -2977,7 +2993,7 @@ Response patch(URL url, RequestBody data, Map parameters, Lis * 请求异常 * @since 2.3.0 */ - default Response patch(String url, int readTimeout) throws IOException, RequestException{ + default Response patch(String url, int readTimeout) throws IOException, RequestException { return patch(URI.create(url), readTimeout); } @@ -3036,7 +3052,7 @@ default Response patch(String url, int readTimeout) throws IOException, RequestE * @since 2.3.0 */ default Response patch(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return patch(URI.create(url), readTimeout, parameters); } @@ -3098,7 +3114,7 @@ default Response patch(String url, int readTimeout, Map paramete * 请求异常 * @since 2.3.0 */ - default Response patch(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response patch(String url, int readTimeout, List
headers) throws IOException, RequestException { return patch(URI.create(url), readTimeout, headers); } @@ -3163,7 +3179,7 @@ default Response patch(String url, int readTimeout, List
headers) throws * @since 2.3.0 */ default Response patch(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return patch(URI.create(url), readTimeout, parameters, headers); } @@ -3231,7 +3247,7 @@ Response patch(URL url, int readTimeout, Map parameters, List data) throws IOException, RequestException{ + default Response patch(String url, int readTimeout, RequestBody data) throws IOException, RequestException { return patch(URI.create(url), readTimeout, data); } @@ -3296,7 +3312,7 @@ default Response patch(String url, int readTimeout, RequestBody data) throws * @since 2.3.0 */ default Response patch(String url, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return patch(URI.create(url), readTimeout, data, parameters); } @@ -3367,7 +3383,7 @@ Response patch(URL url, int readTimeout, RequestBody data, Map data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return patch(URI.create(url), readTimeout, data, headers); } @@ -3440,7 +3456,7 @@ Response patch(URL url, int readTimeout, RequestBody data, List
heade * @since 2.3.0 */ default Response patch(String url, int readTimeout, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return patch(URI.create(url), readTimeout, data, parameters, headers); } @@ -3507,7 +3523,7 @@ Response patch(URL url, int readTimeout, RequestBody data, Map parameters) throws IOException, RequestException{ + default Response delete(String url, Map parameters) throws IOException, RequestException { return delete(URI.create(url), parameters); } @@ -3611,7 +3627,7 @@ default Response delete(String url, Map parameters) throws IOExc * @throws RequestException * 请求异常 */ - default Response delete(String url, List
headers) throws IOException, RequestException{ + default Response delete(String url, List
headers) throws IOException, RequestException { return delete(URI.create(url), headers); } @@ -3668,7 +3684,7 @@ default Response delete(String url, List
headers) throws IOException, Re * 请求异常 */ default Response delete(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return delete(URI.create(url), parameters, headers); } @@ -3727,7 +3743,7 @@ default Response delete(String url, Map parameters, List
* 请求异常 * @since 2.3.0 */ - default Response delete(String url, int readTimeout) throws IOException, RequestException{ + default Response delete(String url, int readTimeout) throws IOException, RequestException { return delete(URI.create(url), readTimeout); } @@ -3786,7 +3802,7 @@ default Response delete(String url, int readTimeout) throws IOException, Request * @since 2.3.0 */ default Response delete(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return delete(URI.create(url), readTimeout, parameters); } @@ -3848,7 +3864,7 @@ default Response delete(String url, int readTimeout, Map paramet * 请求异常 * @since 2.3.0 */ - default Response delete(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response delete(String url, int readTimeout, List
headers) throws IOException, RequestException { return delete(URI.create(url), readTimeout, headers); } @@ -3913,7 +3929,7 @@ default Response delete(String url, int readTimeout, List
headers) throw * @since 2.3.0 */ default Response delete(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return delete(URI.create(url), readTimeout, parameters, headers); } @@ -3976,7 +3992,7 @@ Response delete(URL url, int readTimeout, Map parameters, List parameters) throws IOException, RequestException{ + default Response connect(String url, Map parameters) throws IOException, RequestException { return connect(URI.create(url), parameters); } @@ -4080,7 +4096,7 @@ default Response connect(String url, Map parameters) throws IOEx * @throws RequestException * 请求异常 */ - default Response connect(String url, List
headers) throws IOException, RequestException{ + default Response connect(String url, List
headers) throws IOException, RequestException { return connect(URI.create(url), headers); } @@ -4137,7 +4153,7 @@ default Response connect(String url, List
headers) throws IOException, R * 请求异常 */ default Response connect(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return connect(URI.create(url), parameters, headers); } @@ -4198,7 +4214,7 @@ Response connect(URL url, Map parameters, List
headers) * 请求异常 * @since 2.3.0 */ - default Response connect(String url, int readTimeout) throws IOException, RequestException{ + default Response connect(String url, int readTimeout) throws IOException, RequestException { return connect(URI.create(url), readTimeout); } @@ -4257,7 +4273,7 @@ default Response connect(String url, int readTimeout) throws IOException, Reques * @since 2.3.0 */ default Response connect(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return connect(URI.create(url), readTimeout, parameters); } @@ -4319,7 +4335,7 @@ default Response connect(String url, int readTimeout, Map parame * 请求异常 * @since 2.3.0 */ - default Response connect(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response connect(String url, int readTimeout, List
headers) throws IOException, RequestException { return connect(URI.create(url), readTimeout, headers); } @@ -4384,7 +4400,7 @@ default Response connect(String url, int readTimeout, List
headers) thro * @since 2.3.0 */ default Response connect(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return connect(URI.create(url), readTimeout, parameters, headers); } @@ -4447,7 +4463,7 @@ Response connect(URL url, int readTimeout, Map parameters, List< * @throws RequestException * 请求异常 */ - default Response trace(String url) throws IOException, RequestException{ + default Response trace(String url) throws IOException, RequestException { return trace(URI.create(url)); } @@ -4497,7 +4513,7 @@ default Response trace(String url) throws IOException, RequestException{ * @throws RequestException * 请求异常 */ - default Response trace(String url, Map parameters) throws IOException, RequestException{ + default Response trace(String url, Map parameters) throws IOException, RequestException { return trace(URI.create(url), parameters); } @@ -4551,7 +4567,7 @@ default Response trace(String url, Map parameters) throws IOExce * @throws RequestException * 请求异常 */ - default Response trace(String url, List
headers) throws IOException, RequestException{ + default Response trace(String url, List
headers) throws IOException, RequestException { return trace(URI.create(url), headers); } @@ -4608,7 +4624,7 @@ default Response trace(String url, List
headers) throws IOException, Req * 请求异常 */ default Response trace(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return trace(URI.create(url), parameters, headers); } @@ -4667,7 +4683,7 @@ default Response trace(String url, Map parameters, List
* 请求异常 * @since 2.3.0 */ - default Response trace(String url, int readTimeout) throws IOException, RequestException{ + default Response trace(String url, int readTimeout) throws IOException, RequestException { return trace(URI.create(url), readTimeout); } @@ -4726,7 +4742,7 @@ default Response trace(String url, int readTimeout) throws IOException, RequestE * @since 2.3.0 */ default Response trace(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return trace(URI.create(url), readTimeout, parameters); } @@ -4788,7 +4804,7 @@ default Response trace(String url, int readTimeout, Map paramete * 请求异常 * @since 2.3.0 */ - default Response trace(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response trace(String url, int readTimeout, List
headers) throws IOException, RequestException { return trace(URI.create(url), readTimeout, headers); } @@ -4853,7 +4869,7 @@ default Response trace(String url, int readTimeout, List
headers) throws * @since 2.3.0 */ default Response trace(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return trace(URI.create(url), readTimeout, parameters, headers); } @@ -4916,7 +4932,7 @@ Response trace(URL url, int readTimeout, Map parameters, List parameters) throws IOException, RequestException{ + default Response copy(String url, Map parameters) throws IOException, RequestException { return copy(URI.create(url), parameters); } @@ -5020,7 +5036,7 @@ default Response copy(String url, Map parameters) throws IOExcep * @throws RequestException * 请求异常 */ - default Response copy(String url, List
headers) throws IOException, RequestException{ + default Response copy(String url, List
headers) throws IOException, RequestException { return copy(URI.create(url), headers); } @@ -5077,7 +5093,7 @@ default Response copy(String url, List
headers) throws IOException, Requ * 请求异常 */ default Response copy(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return copy(URI.create(url), parameters, headers); } @@ -5136,7 +5152,7 @@ default Response copy(String url, Map parameters, List
h * 请求异常 * @since 2.3.0 */ - default Response copy(String url, int readTimeout) throws IOException, RequestException{ + default Response copy(String url, int readTimeout) throws IOException, RequestException { return copy(URI.create(url), readTimeout); } @@ -5195,7 +5211,7 @@ default Response copy(String url, int readTimeout) throws IOException, RequestEx * @since 2.3.0 */ default Response copy(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return copy(URI.create(url), readTimeout, parameters); } @@ -5257,7 +5273,7 @@ default Response copy(String url, int readTimeout, Map parameter * 请求异常 * @since 2.3.0 */ - default Response copy(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response copy(String url, int readTimeout, List
headers) throws IOException, RequestException { return copy(URI.create(url), readTimeout, headers); } @@ -5322,7 +5338,7 @@ default Response copy(String url, int readTimeout, List
headers) throws * @since 2.3.0 */ default Response copy(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return copy(URI.create(url), readTimeout, parameters, headers); } @@ -5385,7 +5401,7 @@ Response copy(URL url, int readTimeout, Map parameters, List parameters) throws IOException, RequestException{ + default Response move(String url, Map parameters) throws IOException, RequestException { return move(URI.create(url), parameters); } @@ -5489,7 +5505,7 @@ default Response move(String url, Map parameters) throws IOExcep * @throws RequestException * 请求异常 */ - default Response move(String url, List
headers) throws IOException, RequestException{ + default Response move(String url, List
headers) throws IOException, RequestException { return move(URI.create(url), headers); } @@ -5546,7 +5562,7 @@ default Response move(String url, List
headers) throws IOException, Requ * 请求异常 */ default Response move(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return move(URI.create(url), parameters, headers); } @@ -5605,7 +5621,7 @@ default Response move(String url, Map parameters, List
h * 请求异常 * @since 2.3.0 */ - default Response move(String url, int readTimeout) throws IOException, RequestException{ + default Response move(String url, int readTimeout) throws IOException, RequestException { return move(URI.create(url), readTimeout); } @@ -5664,7 +5680,7 @@ default Response move(String url, int readTimeout) throws IOException, RequestEx * @since 2.3.0 */ default Response move(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return move(URI.create(url), readTimeout, parameters); } @@ -5726,7 +5742,7 @@ default Response move(String url, int readTimeout, Map parameter * 请求异常 * @since 2.3.0 */ - default Response move(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response move(String url, int readTimeout, List
headers) throws IOException, RequestException { return move(URI.create(url), readTimeout, headers); } @@ -5791,7 +5807,7 @@ default Response move(String url, int readTimeout, List
headers) throws * @since 2.3.0 */ default Response move(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return move(URI.create(url), readTimeout, parameters, headers); } @@ -5854,7 +5870,7 @@ Response move(URL url, int readTimeout, Map parameters, List parameters) throws IOException, RequestException{ + default Response head(String url, Map parameters) throws IOException, RequestException { return head(URI.create(url), parameters); } @@ -5958,7 +5974,7 @@ default Response head(String url, Map parameters) throws IOExcep * @throws RequestException * 请求异常 */ - default Response head(String url, List
headers) throws IOException, RequestException{ + default Response head(String url, List
headers) throws IOException, RequestException { return head(URI.create(url), headers); } @@ -6015,7 +6031,7 @@ default Response head(String url, List
headers) throws IOException, Requ * 请求异常 */ default Response head(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return head(URI.create(url), parameters, headers); } @@ -6074,7 +6090,7 @@ default Response head(String url, Map parameters, List
h * 请求异常 * @since 2.3.0 */ - default Response head(String url, int readTimeout) throws IOException, RequestException{ + default Response head(String url, int readTimeout) throws IOException, RequestException { return head(URI.create(url), readTimeout); } @@ -6133,7 +6149,7 @@ default Response head(String url, int readTimeout) throws IOException, RequestEx * @since 2.3.0 */ default Response head(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return head(URI.create(url), readTimeout, parameters); } @@ -6195,7 +6211,7 @@ default Response head(String url, int readTimeout, Map parameter * 请求异常 * @since 2.3.0 */ - default Response head(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response head(String url, int readTimeout, List
headers) throws IOException, RequestException { return head(URI.create(url), readTimeout, headers); } @@ -6260,7 +6276,7 @@ default Response head(String url, int readTimeout, List
headers) throws * @since 2.3.0 */ default Response head(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return head(URI.create(url), readTimeout, parameters, headers); } @@ -6323,7 +6339,7 @@ Response head(URL url, int readTimeout, Map parameters, List parameters) throws IOException, RequestException{ + default Response options(String url, Map parameters) throws IOException, RequestException { return options(URI.create(url), parameters); } @@ -6427,7 +6443,7 @@ default Response options(String url, Map parameters) throws IOEx * @throws RequestException * 请求异常 */ - default Response options(String url, List
headers) throws IOException, RequestException{ + default Response options(String url, List
headers) throws IOException, RequestException { return options(URI.create(url), headers); } @@ -6484,7 +6500,7 @@ default Response options(String url, List
headers) throws IOException, R * 请求异常 */ default Response options(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return options(URI.create(url), parameters, headers); } @@ -6545,7 +6561,7 @@ Response options(URL url, Map parameters, List
headers) * 请求异常 * @since 2.3.0 */ - default Response options(String url, int readTimeout) throws IOException, RequestException{ + default Response options(String url, int readTimeout) throws IOException, RequestException { return options(URI.create(url), readTimeout); } @@ -6604,7 +6620,7 @@ default Response options(String url, int readTimeout) throws IOException, Reques * @since 2.3.0 */ default Response options(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return options(URI.create(url), readTimeout, parameters); } @@ -6666,7 +6682,7 @@ default Response options(String url, int readTimeout, Map parame * 请求异常 * @since 2.3.0 */ - default Response options(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response options(String url, int readTimeout, List
headers) throws IOException, RequestException { return options(URI.create(url), readTimeout, headers); } @@ -6731,7 +6747,7 @@ default Response options(String url, int readTimeout, List
headers) thro * @since 2.3.0 */ default Response options(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return options(URI.create(url), readTimeout, parameters, headers); } @@ -6794,7 +6810,7 @@ Response options(URL url, int readTimeout, Map parameters, List< * @throws RequestException * 请求异常 */ - default Response link(String url) throws IOException, RequestException{ + default Response link(String url) throws IOException, RequestException { return link(URI.create(url)); } @@ -6844,7 +6860,7 @@ default Response link(String url) throws IOException, RequestException{ * @throws RequestException * 请求异常 */ - default Response link(String url, Map parameters) throws IOException, RequestException{ + default Response link(String url, Map parameters) throws IOException, RequestException { return link(URI.create(url), parameters); } @@ -6898,7 +6914,7 @@ default Response link(String url, Map parameters) throws IOExcep * @throws RequestException * 请求异常 */ - default Response link(String url, List
headers) throws IOException, RequestException{ + default Response link(String url, List
headers) throws IOException, RequestException { return link(URI.create(url), headers); } @@ -6955,7 +6971,7 @@ default Response link(String url, List
headers) throws IOException, Requ * 请求异常 */ default Response link(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return link(URI.create(url), parameters, headers); } @@ -7014,7 +7030,7 @@ default Response link(String url, Map parameters, List
h * 请求异常 * @since 2.3.0 */ - default Response link(String url, int readTimeout) throws IOException, RequestException{ + default Response link(String url, int readTimeout) throws IOException, RequestException { return link(URI.create(url), readTimeout); } @@ -7073,7 +7089,7 @@ default Response link(String url, int readTimeout) throws IOException, RequestEx * @since 2.3.0 */ default Response link(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return link(URI.create(url), readTimeout, parameters); } @@ -7135,7 +7151,7 @@ default Response link(String url, int readTimeout, Map parameter * 请求异常 * @since 2.3.0 */ - default Response link(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response link(String url, int readTimeout, List
headers) throws IOException, RequestException { return link(URI.create(url), readTimeout, headers); } @@ -7200,7 +7216,7 @@ default Response link(String url, int readTimeout, List
headers) throws * @since 2.3.0 */ default Response link(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return link(URI.create(url), readTimeout, parameters, headers); } @@ -7263,7 +7279,7 @@ Response link(URL url, int readTimeout, Map parameters, List parameters) throws IOException, RequestException{ + default Response unlink(String url, Map parameters) throws IOException, RequestException { return unlink(URI.create(url), parameters); } @@ -7367,7 +7383,7 @@ default Response unlink(String url, Map parameters) throws IOExc * @throws RequestException * 请求异常 */ - default Response unlink(String url, List
headers) throws IOException, RequestException{ + default Response unlink(String url, List
headers) throws IOException, RequestException { return unlink(URI.create(url), headers); } @@ -7424,7 +7440,7 @@ default Response unlink(String url, List
headers) throws IOException, Re * 请求异常 */ default Response unlink(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return unlink(URI.create(url), parameters, headers); } @@ -7483,7 +7499,7 @@ default Response unlink(String url, Map parameters, List
* 请求异常 * @since 2.3.0 */ - default Response unlink(String url, int readTimeout) throws IOException, RequestException{ + default Response unlink(String url, int readTimeout) throws IOException, RequestException { return unlink(URI.create(url), readTimeout); } @@ -7542,7 +7558,7 @@ default Response unlink(String url, int readTimeout) throws IOException, Request * @since 2.3.0 */ default Response unlink(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return unlink(URI.create(url), readTimeout, parameters); } @@ -7604,7 +7620,7 @@ default Response unlink(String url, int readTimeout, Map paramet * 请求异常 * @since 2.3.0 */ - default Response unlink(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response unlink(String url, int readTimeout, List
headers) throws IOException, RequestException { return unlink(URI.create(url), readTimeout, headers); } @@ -7669,7 +7685,7 @@ default Response unlink(String url, int readTimeout, List
headers) throw * @since 2.3.0 */ default Response unlink(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return unlink(URI.create(url), readTimeout, parameters, headers); } @@ -7732,7 +7748,7 @@ Response unlink(URL url, int readTimeout, Map parameters, List parameters) throws IOException, RequestException{ + default Response purge(String url, Map parameters) throws IOException, RequestException { return purge(URI.create(url), parameters); } @@ -7836,7 +7852,7 @@ default Response purge(String url, Map parameters) throws IOExce * @throws RequestException * 请求异常 */ - default Response purge(String url, List
headers) throws IOException, RequestException{ + default Response purge(String url, List
headers) throws IOException, RequestException { return purge(URI.create(url), headers); } @@ -7893,7 +7909,7 @@ default Response purge(String url, List
headers) throws IOException, Req * 请求异常 */ default Response purge(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return purge(URI.create(url), parameters, headers); } @@ -7952,7 +7968,7 @@ default Response purge(String url, Map parameters, List
* 请求异常 * @since 2.3.0 */ - default Response purge(String url, int readTimeout) throws IOException, RequestException{ + default Response purge(String url, int readTimeout) throws IOException, RequestException { return purge(URI.create(url), readTimeout); } @@ -8011,7 +8027,7 @@ default Response purge(String url, int readTimeout) throws IOException, RequestE * @since 2.3.0 */ default Response purge(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return purge(URI.create(url), readTimeout, parameters); } @@ -8073,7 +8089,7 @@ default Response purge(String url, int readTimeout, Map paramete * 请求异常 * @since 2.3.0 */ - default Response purge(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response purge(String url, int readTimeout, List
headers) throws IOException, RequestException { return purge(URI.create(url), readTimeout, headers); } @@ -8138,7 +8154,7 @@ default Response purge(String url, int readTimeout, List
headers) throws * @since 2.3.0 */ default Response purge(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return purge(URI.create(url), readTimeout, parameters, headers); } @@ -8201,7 +8217,7 @@ Response purge(URL url, int readTimeout, Map parameters, List parameters) throws IOException, RequestException{ + default Response lock(String url, Map parameters) throws IOException, RequestException { return lock(URI.create(url), parameters); } @@ -8305,7 +8321,7 @@ default Response lock(String url, Map parameters) throws IOExcep * @throws RequestException * 请求异常 */ - default Response lock(String url, List
headers) throws IOException, RequestException{ + default Response lock(String url, List
headers) throws IOException, RequestException { return lock(URI.create(url), headers); } @@ -8362,7 +8378,7 @@ default Response lock(String url, List
headers) throws IOException, Requ * 请求异常 */ default Response lock(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return lock(URI.create(url), parameters, headers); } @@ -8421,7 +8437,7 @@ default Response lock(String url, Map parameters, List
h * 请求异常 * @since 2.3.0 */ - default Response lock(String url, int readTimeout) throws IOException, RequestException{ + default Response lock(String url, int readTimeout) throws IOException, RequestException { return lock(URI.create(url), readTimeout); } @@ -8480,7 +8496,7 @@ default Response lock(String url, int readTimeout) throws IOException, RequestEx * @since 2.3.0 */ default Response lock(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return lock(URI.create(url), readTimeout, parameters); } @@ -8542,7 +8558,7 @@ default Response lock(String url, int readTimeout, Map parameter * 请求异常 * @since 2.3.0 */ - default Response lock(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response lock(String url, int readTimeout, List
headers) throws IOException, RequestException { return lock(URI.create(url), readTimeout, headers); } @@ -8607,7 +8623,7 @@ default Response lock(String url, int readTimeout, List
headers) throws * @since 2.3.0 */ default Response lock(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return lock(URI.create(url), readTimeout, parameters, headers); } @@ -8670,7 +8686,7 @@ Response lock(URL url, int readTimeout, Map parameters, List parameters) throws IOException, RequestException{ + default Response unlock(String url, Map parameters) throws IOException, RequestException { return unlock(URI.create(url), parameters); } @@ -8774,7 +8790,7 @@ default Response unlock(String url, Map parameters) throws IOExc * @throws RequestException * 请求异常 */ - default Response unlock(String url, List
headers) throws IOException, RequestException{ + default Response unlock(String url, List
headers) throws IOException, RequestException { return unlock(URI.create(url), headers); } @@ -8831,7 +8847,7 @@ default Response unlock(String url, List
headers) throws IOException, Re * 请求异常 */ default Response unlock(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return unlock(URI.create(url), parameters, headers); } @@ -8890,7 +8906,7 @@ default Response unlock(String url, Map parameters, List
* 请求异常 * @since 2.3.0 */ - default Response unlock(String url, int readTimeout) throws IOException, RequestException{ + default Response unlock(String url, int readTimeout) throws IOException, RequestException { return unlock(URI.create(url), readTimeout); } @@ -8949,7 +8965,7 @@ default Response unlock(String url, int readTimeout) throws IOException, Request * @since 2.3.0 */ default Response unlock(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return unlock(URI.create(url), readTimeout, parameters); } @@ -9011,7 +9027,7 @@ default Response unlock(String url, int readTimeout, Map paramet * 请求异常 * @since 2.3.0 */ - default Response unlock(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response unlock(String url, int readTimeout, List
headers) throws IOException, RequestException { return unlock(URI.create(url), readTimeout, headers); } @@ -9076,7 +9092,7 @@ default Response unlock(String url, int readTimeout, List
headers) throw * @since 2.3.0 */ default Response unlock(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return unlock(URI.create(url), readTimeout, parameters, headers); } @@ -9139,7 +9155,7 @@ Response unlock(URL url, int readTimeout, Map parameters, List parameters) throws IOException, RequestException{ + default Response propfind(String url, Map parameters) throws IOException, RequestException { return propfind(URI.create(url), parameters); } @@ -9243,7 +9259,7 @@ default Response propfind(String url, Map parameters) throws IOE * @throws RequestException * 请求异常 */ - default Response propfind(String url, List
headers) throws IOException, RequestException{ + default Response propfind(String url, List
headers) throws IOException, RequestException { return propfind(URI.create(url), headers); } @@ -9300,7 +9316,7 @@ default Response propfind(String url, List
headers) throws IOException, * 请求异常 */ default Response propfind(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return propfind(URI.create(url), parameters, headers); } @@ -9361,7 +9377,7 @@ Response propfind(URL url, Map parameters, List
headers) * 请求异常 * @since 2.3.0 */ - default Response propfind(String url, int readTimeout) throws IOException, RequestException{ + default Response propfind(String url, int readTimeout) throws IOException, RequestException { return propfind(URI.create(url), readTimeout); } @@ -9420,7 +9436,7 @@ default Response propfind(String url, int readTimeout) throws IOException, Reque * @since 2.3.0 */ default Response propfind(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return propfind(URI.create(url), readTimeout, parameters); } @@ -9482,7 +9498,7 @@ default Response propfind(String url, int readTimeout, Map param * 请求异常 * @since 2.3.0 */ - default Response propfind(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response propfind(String url, int readTimeout, List
headers) throws IOException, RequestException { return propfind(URI.create(url), readTimeout, headers); } @@ -9547,7 +9563,7 @@ default Response propfind(String url, int readTimeout, List
headers) thr * @since 2.3.0 */ default Response propfind(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return propfind(URI.create(url), readTimeout, parameters, headers); } @@ -9610,7 +9626,7 @@ Response propfind(URL url, int readTimeout, Map parameters, List * @throws RequestException * 请求异常 */ - default Response proppatch(String url) throws IOException, RequestException{ + default Response proppatch(String url) throws IOException, RequestException { return proppatch(URI.create(url)); } @@ -9660,7 +9676,7 @@ default Response proppatch(String url) throws IOException, RequestException{ * @throws RequestException * 请求异常 */ - default Response proppatch(String url, Map parameters) throws IOException, RequestException{ + default Response proppatch(String url, Map parameters) throws IOException, RequestException { return proppatch(URI.create(url), parameters); } @@ -9714,7 +9730,7 @@ default Response proppatch(String url, Map parameters) throws IO * @throws RequestException * 请求异常 */ - default Response proppatch(String url, List
headers) throws IOException, RequestException{ + default Response proppatch(String url, List
headers) throws IOException, RequestException { return proppatch(URI.create(url), headers); } @@ -9771,7 +9787,7 @@ default Response proppatch(String url, List
headers) throws IOException, * 请求异常 */ default Response proppatch(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return proppatch(URI.create(url), parameters, headers); } @@ -9831,7 +9847,7 @@ Response proppatch(URL url, Map parameters, List
headers * @throws RequestException * 请求异常 */ - default Response proppatch(String url, RequestBody data) throws IOException, RequestException{ + default Response proppatch(String url, RequestBody data) throws IOException, RequestException { return proppatch(URI.create(url), data); } @@ -9888,7 +9904,7 @@ default Response proppatch(String url, RequestBody data) throws IOException, * 请求异常 */ default Response proppatch(String url, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return proppatch(URI.create(url), data, parameters); } @@ -9951,7 +9967,7 @@ Response proppatch(URL url, RequestBody data, Map parameters) * 请求异常 */ default Response proppatch(String url, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return proppatch(URI.create(url), data, headers); } @@ -10014,7 +10030,7 @@ default Response proppatch(String url, RequestBody data, List
headers * 请求异常 */ default Response proppatch(String url, RequestBody data, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return proppatch(URI.create(url), data, parameters, headers); } @@ -10079,7 +10095,7 @@ Response proppatch(URL url, RequestBody data, Map parameters, * 请求异常 * @since 2.3.0 */ - default Response proppatch(String url, int readTimeout) throws IOException, RequestException{ + default Response proppatch(String url, int readTimeout) throws IOException, RequestException { return proppatch(URI.create(url), readTimeout); } @@ -10138,7 +10154,7 @@ default Response proppatch(String url, int readTimeout) throws IOException, Requ * @since 2.3.0 */ default Response proppatch(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return proppatch(URI.create(url), readTimeout, parameters); } @@ -10201,7 +10217,7 @@ default Response proppatch(String url, int readTimeout, Map para * 请求异常 * @since 2.3.0 */ - default Response proppatch(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response proppatch(String url, int readTimeout, List
headers) throws IOException, RequestException { return proppatch(URI.create(url), readTimeout, headers); } @@ -10266,7 +10282,7 @@ default Response proppatch(String url, int readTimeout, List
headers) th * @since 2.3.0 */ default Response proppatch(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return proppatch(URI.create(url), readTimeout, parameters, headers); } @@ -10334,7 +10350,7 @@ Response proppatch(URL url, int readTimeout, Map parameters, Lis * 请求异常 * @since 2.3.0 */ - default Response proppatch(String url, int readTimeout, RequestBody data) throws IOException, RequestException{ + default Response proppatch(String url, int readTimeout, RequestBody data) throws IOException, RequestException { return proppatch(URI.create(url), readTimeout, data); } @@ -10399,7 +10415,7 @@ default Response proppatch(String url, int readTimeout, RequestBody data) thr * @since 2.3.0 */ default Response proppatch(String url, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return proppatch(URI.create(url), readTimeout, data, parameters); } @@ -10470,7 +10486,7 @@ Response proppatch(URL url, int readTimeout, RequestBody data, Map data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return proppatch(URI.create(url), readTimeout, data, headers); } @@ -10543,7 +10559,7 @@ Response proppatch(URL url, int readTimeout, RequestBody data, List
h * @since 2.3.0 */ default Response proppatch(String url, int readTimeout, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return proppatch(URI.create(url), readTimeout, data, parameters, headers); } @@ -10610,7 +10626,7 @@ Response proppatch(URL url, int readTimeout, RequestBody data, Map parameters) throws IOException, RequestException{ + default Response report(String url, Map parameters) throws IOException, RequestException { return report(URI.create(url), parameters); } @@ -10714,7 +10730,7 @@ default Response report(String url, Map parameters) throws IOExc * @throws RequestException * 请求异常 */ - default Response report(String url, List
headers) throws IOException, RequestException{ + default Response report(String url, List
headers) throws IOException, RequestException { return report(URI.create(url), headers); } @@ -10771,7 +10787,7 @@ default Response report(String url, List
headers) throws IOException, Re * 请求异常 */ default Response report(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return report(URI.create(url), parameters, headers); } @@ -10829,7 +10845,7 @@ default Response report(String url, Map parameters, List
* @throws RequestException * 请求异常 */ - default Response report(String url, RequestBody data) throws IOException, RequestException{ + default Response report(String url, RequestBody data) throws IOException, RequestException { return report(URI.create(url), data); } @@ -10886,7 +10902,7 @@ default Response report(String url, RequestBody data) throws IOException, Req * 请求异常 */ default Response report(String url, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return report(URI.create(url), data, parameters); } @@ -10946,7 +10962,8 @@ default Response report(String url, RequestBody data, Map par * @throws RequestException * 请求异常 */ - default Response report(String url, RequestBody data, List
headers) throws IOException, RequestException{ + default Response report(String url, RequestBody data, List
headers) + throws IOException, RequestException { return report(URI.create(url), data, headers); } @@ -11009,7 +11026,7 @@ default Response report(String url, RequestBody data, List
headers) t * 请求异常 */ default Response report(String url, RequestBody data, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return report(URI.create(url), data, parameters, headers); } @@ -11074,7 +11091,7 @@ Response report(URL url, RequestBody data, Map parameters, Li * 请求异常 * @since 2.3.0 */ - default Response report(String url, int readTimeout) throws IOException, RequestException{ + default Response report(String url, int readTimeout) throws IOException, RequestException { return report(URI.create(url), readTimeout); } @@ -11133,7 +11150,7 @@ default Response report(String url, int readTimeout) throws IOException, Request * @since 2.3.0 */ default Response report(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return report(URI.create(url), readTimeout, parameters); } @@ -11195,7 +11212,7 @@ default Response report(String url, int readTimeout, Map paramet * 请求异常 * @since 2.3.0 */ - default Response report(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response report(String url, int readTimeout, List
headers) throws IOException, RequestException { return report(URI.create(url), readTimeout, headers); } @@ -11260,7 +11277,7 @@ default Response report(String url, int readTimeout, List
headers) throw * @since 2.3.0 */ default Response report(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return report(URI.create(url), readTimeout, parameters, headers); } @@ -11328,7 +11345,7 @@ Response report(URL url, int readTimeout, Map parameters, List data) throws IOException, RequestException{ + default Response report(String url, int readTimeout, RequestBody data) throws IOException, RequestException { return report(URI.create(url), readTimeout, data); } @@ -11393,7 +11410,7 @@ default Response report(String url, int readTimeout, RequestBody data) throws * @since 2.3.0 */ default Response report(String url, int readTimeout, RequestBody data, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return report(URI.create(url), readTimeout, data, parameters); } @@ -11464,7 +11481,7 @@ Response report(URL url, int readTimeout, RequestBody data, Map data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return report(URI.create(url), readTimeout, data, headers); } @@ -11537,7 +11554,7 @@ Response report(URL url, int readTimeout, RequestBody data, List
head * @since 2.3.0 */ default Response report(String url, int readTimeout, RequestBody data, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return report(URI.create(url), readTimeout, data, parameters, headers); } @@ -11604,7 +11621,7 @@ Response report(URL url, int readTimeout, RequestBody data, Map parameters) throws IOException, RequestException{ + default Response view(String url, Map parameters) throws IOException, RequestException { return view(URI.create(url), parameters); } @@ -11708,7 +11725,7 @@ default Response view(String url, Map parameters) throws IOExcep * @throws RequestException * 请求异常 */ - default Response view(String url, List
headers) throws IOException, RequestException{ + default Response view(String url, List
headers) throws IOException, RequestException { return view(URI.create(url), headers); } @@ -11765,7 +11782,7 @@ default Response view(String url, List
headers) throws IOException, Requ * 请求异常 */ default Response view(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return view(URI.create(url), parameters, headers); } @@ -11824,7 +11841,7 @@ default Response view(String url, Map parameters, List
h * 请求异常 * @since 2.3.0 */ - default Response view(String url, int readTimeout) throws IOException, RequestException{ + default Response view(String url, int readTimeout) throws IOException, RequestException { return view(URI.create(url), readTimeout); } @@ -11883,7 +11900,7 @@ default Response view(String url, int readTimeout) throws IOException, RequestEx * @since 2.3.0 */ default Response view(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return view(URI.create(url), readTimeout, parameters); } @@ -11945,7 +11962,7 @@ default Response view(String url, int readTimeout, Map parameter * 请求异常 * @since 2.3.0 */ - default Response view(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response view(String url, int readTimeout, List
headers) throws IOException, RequestException { return view(URI.create(url), readTimeout, headers); } @@ -12010,7 +12027,7 @@ default Response view(String url, int readTimeout, List
headers) throws * @since 2.3.0 */ default Response view(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return view(URI.create(url), readTimeout, parameters, headers); } @@ -12073,7 +12090,7 @@ Response view(URL url, int readTimeout, Map parameters, List parameters) throws IOException, RequestException{ + default Response wrapped(String url, Map parameters) throws IOException, RequestException { return wrapped(URI.create(url), parameters); } @@ -12177,7 +12194,7 @@ default Response wrapped(String url, Map parameters) throws IOEx * @throws RequestException * 请求异常 */ - default Response wrapped(String url, List
headers) throws IOException, RequestException{ + default Response wrapped(String url, List
headers) throws IOException, RequestException { return wrapped(URI.create(url), headers); } @@ -12234,7 +12251,7 @@ default Response wrapped(String url, List
headers) throws IOException, R * 请求异常 */ default Response wrapped(String url, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return wrapped(URI.create(url), parameters, headers); } @@ -12295,7 +12312,7 @@ Response wrapped(URL url, Map parameters, List
headers) * 请求异常 * @since 2.3.0 */ - default Response wrapped(String url, int readTimeout) throws IOException, RequestException{ + default Response wrapped(String url, int readTimeout) throws IOException, RequestException { return wrapped(URI.create(url), readTimeout); } @@ -12354,7 +12371,7 @@ default Response wrapped(String url, int readTimeout) throws IOException, Reques * @since 2.3.0 */ default Response wrapped(String url, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return wrapped(URI.create(url), readTimeout, parameters); } @@ -12416,7 +12433,7 @@ default Response wrapped(String url, int readTimeout, Map parame * 请求异常 * @since 2.3.0 */ - default Response wrapped(String url, int readTimeout, List
headers) throws IOException, RequestException{ + default Response wrapped(String url, int readTimeout, List
headers) throws IOException, RequestException { return wrapped(URI.create(url), readTimeout, headers); } @@ -12481,7 +12498,7 @@ default Response wrapped(String url, int readTimeout, List
headers) thro * @since 2.3.0 */ default Response wrapped(String url, int readTimeout, Map parameters, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return wrapped(URI.create(url), readTimeout, parameters, headers); } @@ -12546,7 +12563,7 @@ Response wrapped(URL url, int readTimeout, Map parameters, List< * @throws RequestException * 请求异常 */ - default Response request(String url, RequestMethod requestMethod) throws IOException, RequestException{ + default Response request(String url, RequestMethod requestMethod) throws IOException, RequestException { return request(URI.create(url), requestMethod); } @@ -12603,7 +12620,7 @@ default Response request(String url, RequestMethod requestMethod) throws IOExcep * 请求异常 */ default Response request(String url, RequestMethod requestMethod, Map parameters) throws - IOException, RequestException{ + IOException, RequestException { return request(URI.create(url), requestMethod, parameters); } @@ -12666,7 +12683,7 @@ Response request(URL url, RequestMethod requestMethod, Map param * 请求异常 */ default Response request(String url, RequestMethod requestMethod, List
headers) throws IOException, - RequestException{ + RequestException { return request(URI.create(url), requestMethod, headers); } @@ -12730,7 +12747,7 @@ Response request(URL url, RequestMethod requestMethod, List
headers) thr * 请求异常 */ default Response request(String url, RequestMethod requestMethod, Map parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return request(URI.create(url), requestMethod, parameters, headers); } @@ -12797,7 +12814,7 @@ Response request(URL url, RequestMethod requestMethod, Map param * 请求异常 */ default Response request(String url, RequestMethod requestMethod, RequestBody data) throws IOException, - RequestException{ + RequestException { return request(URI.create(url), requestMethod, data); } @@ -12861,7 +12878,7 @@ Response request(URL url, RequestMethod requestMethod, RequestBody data) thro * 请求异常 */ default Response request(String url, RequestMethod requestMethod, RequestBody data, - Map parameters) throws IOException, RequestException{ + Map parameters) throws IOException, RequestException { return request(URI.create(url), requestMethod, data, parameters); } @@ -12930,7 +12947,7 @@ Response request(URL url, RequestMethod requestMethod, RequestBody data, Map< * 请求异常 */ default Response request(String url, RequestMethod requestMethod, RequestBody data, List
headers) - throws IOException, RequestException{ + throws IOException, RequestException { return request(URI.create(url), requestMethod, data, headers); } @@ -13001,7 +13018,8 @@ Response request(URL url, RequestMethod requestMethod, RequestBody data, List * 请求异常 */ default Response request(String url, RequestMethod requestMethod, RequestBody data, - Map parameters, List
headers) throws IOException, RequestException{ + Map parameters, List
headers) + throws IOException, RequestException { return request(URI.create(url), requestMethod, data, parameters, headers); } @@ -13072,7 +13090,7 @@ Response request(URL url, RequestMethod requestMethod, RequestBody data, Map< * 请求异常 */ default Response request(String url, RequestMethod requestMethod, int readTimeout) - throws IOException, RequestException{ + throws IOException, RequestException { return request(URI.create(url), requestMethod, readTimeout); } @@ -13135,7 +13153,7 @@ default Response request(String url, RequestMethod requestMethod, int readTimeou * 请求异常 */ default Response request(String url, RequestMethod requestMethod, int readTimeout, Map parameters) - throws IOException, RequestException{ + throws IOException, RequestException { return request(URI.create(url), requestMethod, readTimeout, parameters); } @@ -13204,7 +13222,7 @@ Response request(URL url, RequestMethod requestMethod, int readTimeout, Map headers) - throws IOException, RequestException{ + throws IOException, RequestException { return request(URI.create(url), requestMethod, readTimeout, headers); } @@ -13275,7 +13293,7 @@ Response request(URL url, RequestMethod requestMethod, int readTimeout, List parameters, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return request(URI.create(url), requestMethod, readTimeout, parameters, headers); } @@ -13348,7 +13366,7 @@ Response request(URL url, RequestMethod requestMethod, int readTimeout, Map data) - throws IOException, RequestException{ + throws IOException, RequestException { return request(URI.create(url), requestMethod, readTimeout, data); } @@ -13419,7 +13437,7 @@ Response request(URL url, RequestMethod requestMethod, int readTimeout, RequestB * 请求异常 */ default Response request(String url, RequestMethod requestMethod, int readTimeout, RequestBody data, - Map parameters) throws IOException, RequestException{ + Map parameters) throws IOException, RequestException { return request(URI.create(url), requestMethod, readTimeout, data, parameters); } @@ -13494,7 +13512,7 @@ Response request(URL url, RequestMethod requestMethod, int readTimeout, RequestB * 请求异常 */ default Response request(String url, RequestMethod requestMethod, int readTimeout, RequestBody data, - List
headers) throws IOException, RequestException{ + List
headers) throws IOException, RequestException { return request(URI.create(url), requestMethod, readTimeout, data, headers); } @@ -13571,7 +13589,8 @@ Response request(URL url, RequestMethod requestMethod, int readTimeout, RequestB * 请求异常 */ default Response request(String url, RequestMethod requestMethod, int readTimeout, RequestBody data, - Map parameters, List
headers) throws IOException, RequestException{ + Map parameters, List
headers) + throws IOException, RequestException { return request(URI.create(url), requestMethod, readTimeout, data, parameters, headers); } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/IBaseHttpClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/IBaseHttpClient.java index df30e12e9..6a67912d4 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/IBaseHttpClient.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/IBaseHttpClient.java @@ -19,50 +19,18 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient; -import com.buession.httpclient.conn.ConnectionManager; -import com.buession.httpclient.core.ProtocolVersion; - /** * HttpClient 基接口 * * @author Yong.Teng * @since 2.3.0 */ -public interface IBaseHttpClient { - - /** - * 获取连接管理器 - * - * @return 连接管理器 - */ - ConnectionManager getConnectionManager(); - - /** - * 设置连接管理器 - * - * @param connectionManager - * 连接管理器 - */ - void setConnectionManager(ConnectionManager connectionManager); - - /** - * 获取 HTTP 协议版本 - * - * @return HTTP 协议版本 - */ - ProtocolVersion getHttpVersion(); - - /** - * 设置 HTTP 协议版本 - * - * @param httpVersion - * HTTP 协议版本 - */ - void setHttpVersion(ProtocolVersion httpVersion); +@Deprecated +public interface IBaseHttpClient extends IHttpClient { } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/HttpClientBuilder.java b/buession-httpclient/src/main/java/com/buession/httpclient/IHttpClient.java similarity index 77% rename from buession-httpclient/src/main/java/com/buession/httpclient/core/HttpClientBuilder.java rename to buession-httpclient/src/main/java/com/buession/httpclient/IHttpClient.java index 2da3178c4..731f424f5 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/core/HttpClientBuilder.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/IHttpClient.java @@ -19,34 +19,34 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.httpclient.core; +package com.buession.httpclient; -import java.util.function.Consumer; +import com.buession.httpclient.core.ProtocolVersion; /** - * Http Client Builder - * - * @param - * 原生 Http Client Builder - * @param - * 原生 Http Client + * HttpClient 基接口 * * @author Yong.Teng - * @since 2.3.0 + * @since 3.0.0 */ -public interface HttpClientBuilder { +public interface IHttpClient { /** - * 构建原生 Http Client + * 获取 HTTP 协议版本 * - * @param consumer - * 原生 Http Client Builder Consumer + * @return HTTP 协议版本 + */ + ProtocolVersion getHttpVersion(); + + /** + * 设置 HTTP 协议版本 * - * @return 原生 Http Client + * @param httpVersion + * HTTP 协议版本 */ - C build(Consumer consumer); + void setHttpVersion(ProtocolVersion httpVersion); } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/OkHttpHttpAsyncClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/OkHttpHttpAsyncClient.java index 638f82df7..a7e2d334e 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/OkHttpHttpAsyncClient.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/OkHttpHttpAsyncClient.java @@ -19,20 +19,23 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient; +import com.buession.core.converter.mapper.PropertyMapper; import com.buession.httpclient.conn.OkHttpNioClientConnectionManager; +import com.buession.httpclient.core.Configuration; import com.buession.httpclient.core.Header; import com.buession.httpclient.core.RequestBody; import com.buession.httpclient.core.concurrent.Callback; import com.buession.httpclient.exception.RequestException; -import com.buession.httpclient.okhttp.OkHttpHttpAsyncClientBuilder; import com.buession.httpclient.okhttp.OkHttpRequest; import com.buession.httpclient.okhttp.OkHttpRequestBuilder; import com.buession.httpclient.okhttp.nio.DefaultCallback; +import com.buession.net.ssl.SslConfiguration; +import okhttp3.nio.HttpAsyncClientBuilder; import java.io.IOException; import java.net.URI; @@ -52,7 +55,7 @@ public class OkHttpHttpAsyncClient extends AbstractHttpAsyncClient { /** * 构造函数 */ - public OkHttpHttpAsyncClient(){ + public OkHttpHttpAsyncClient() { super(); setConnectionManager(new OkHttpNioClientConnectionManager()); } @@ -63,7 +66,7 @@ public OkHttpHttpAsyncClient(){ * @param connectionManager * 连接管理器 */ - public OkHttpHttpAsyncClient(OkHttpNioClientConnectionManager connectionManager){ + public OkHttpHttpAsyncClient(OkHttpNioClientConnectionManager connectionManager) { super(connectionManager); } @@ -73,291 +76,310 @@ public OkHttpHttpAsyncClient(OkHttpNioClientConnectionManager connectionManager) * @param httpClient * {@link okhttp3.OkHttpClient} 实例 */ - public OkHttpHttpAsyncClient(okhttp3.OkHttpClient httpClient){ + public OkHttpHttpAsyncClient(okhttp3.OkHttpClient httpClient) { this.httpClient = httpClient; } - public okhttp3.OkHttpClient getHttpClient(){ + public okhttp3.OkHttpClient getHttpClient() { if(httpClient == null){ - final OkHttpHttpAsyncClientBuilder httpAsyncClientBuilder = new OkHttpHttpAsyncClientBuilder( - (OkHttpNioClientConnectionManager) getConnectionManager()); - - httpClient = httpAsyncClientBuilder.build((builder)->{ - }); + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); + final OkHttpNioClientConnectionManager okHttpNioClientConnectionManager = + (OkHttpNioClientConnectionManager) getConnectionManager(); + final Configuration configuration = okHttpNioClientConnectionManager.getConfiguration(); + final SslConfiguration sslConfiguration = configuration.getSslConfiguration(); + final HttpAsyncClientBuilder builder = HttpAsyncClientBuilder.create() + .setConnectionManager(okHttpNioClientConnectionManager.getClientConnectionManager()); + + propertyMapper.from(configuration.getConnectTimeout()).to(builder::setConnectTimeout); + propertyMapper.alwaysApplyingWhenPositiveNumber().from(configuration.getReadTimeout()) + .to(builder::setReadTimeout); + propertyMapper.alwaysApplyingWhenPositiveNumber().from(configuration.getWriteTimeout()) + .to(builder::setWriteTimeout); + propertyMapper.from(configuration.getRetryOnConnectionFailure()).to(builder::setRetryOnConnectionFailure); + propertyMapper.from(configuration.isAllowRedirects()).to(builder::setFollowRedirects); + + if(sslConfiguration != null){ + propertyMapper.from(sslConfiguration.getSslSocketFactory()).to(builder::setSSLSocketFactory); + propertyMapper.from(sslConfiguration.getHostnameVerifier()).to(builder::setSSLHostnameVerifier); + propertyMapper.from(sslConfiguration.getSslContext()).to(builder::setSSLContext); + } + + httpClient = builder.build(); } return httpClient; } - public void setHttpClient(okhttp3.OkHttpClient httpClient){ + public void setHttpClient(okhttp3.OkHttpClient httpClient) { this.httpClient = httpClient; } @Override public void get(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).get(), callback); } @Override public void get(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).get(), readTimeout, callback); } @Override public void post(URI uri, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).post(data), callback); } @Override public void post(URI uri, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).post(data), readTimeout, callback); } @Override public void put(URI uri, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).put(data), callback); } @Override public void put(URI uri, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).put(data), readTimeout, callback); } @Override public void patch(URI uri, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).patch(data), callback); } @Override public void patch(URI uri, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).patch(data), readTimeout, callback); } @Override public void delete(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).delete(), callback); } @Override public void delete(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).delete(), readTimeout, callback); } @Override public void connect(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).connect(), callback); } @Override public void connect(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).connect(), readTimeout, callback); } @Override public void trace(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).trace(), callback); } @Override public void trace(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).trace(), readTimeout, callback); } @Override public void copy(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).copy(), callback); } @Override public void copy(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).copy(), readTimeout, callback); } @Override public void move(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).move(), callback); } @Override public void move(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).move(), readTimeout, callback); } @Override public void head(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).head(), callback); } @Override public void head(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).head(), readTimeout, callback); } @Override public void options(URI uri, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).options(), callback); } @Override public void options(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).options(), readTimeout, callback); } @Override public void link(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).link(), callback); } @Override public void link(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).link(), readTimeout, callback); } @Override public void unlink(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).unlink(), callback); } @Override public void unlink(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).unlink(), readTimeout, callback); } @Override public void purge(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).purge(), callback); } @Override public void purge(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).purge(), readTimeout, callback); } @Override public void lock(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).lock(), callback); } @Override public void lock(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).lock(), readTimeout, callback); } @Override public void unlock(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).unlock(), callback); } @Override public void unlock(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).unlock(), readTimeout, callback); } @Override public void propfind(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).propfind(), callback); } @Override public void propfind(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).propfind(), readTimeout, callback); } @Override public void proppatch(URI uri, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).proppatch(data), callback); } @Override public void proppatch(URI uri, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).proppatch(data), readTimeout, callback); } @Override public void report(URI uri, RequestBody data, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).report(data), callback); } @Override public void report(URI uri, int readTimeout, RequestBody data, Map parameters, - List
headers, Callback callback) throws IOException, RequestException{ + List
headers, Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).report(data), readTimeout, callback); } @Override public void view(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).view(), callback); } @Override public void view(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).view(), readTimeout, callback); } @Override public void wrapped(URI uri, Map parameters, List
headers, Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).wrapped(), callback); } @Override public void wrapped(URI uri, int readTimeout, Map parameters, List
headers, - Callback callback) throws IOException, RequestException{ + Callback callback) throws IOException, RequestException { doRequest(OkHttpRequestBuilder.create(uri, parameters, headers).wrapped(), readTimeout, callback); } protected void doRequest(final OkHttpRequestBuilder builder, final Callback callback) throws IOException, - RequestException{ + RequestException { final OkHttpRequest request = builder.setProtocolVersion(getHttpVersion()).build(); doRequest(request, callback); } protected void doRequest(final OkHttpRequestBuilder builder, final int readTimeout, final Callback callback) - throws IOException, RequestException{ + throws IOException, RequestException { final OkHttpRequest request = builder.setProtocolVersion(getHttpVersion()).build(); doRequest(request, callback); } - protected void doRequest(final OkHttpRequest request, final Callback callback) throws IOException, RequestException{ + protected void doRequest(final OkHttpRequest request, final Callback callback) + throws IOException, RequestException { okhttp3.Request okHttpRequest = request.getRequestBuilder().build(); okhttp3.Call call = getHttpClient().newCall(okHttpRequest); diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/OkHttpHttpClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/OkHttpHttpClient.java index 362d1e32f..46fe778f4 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/OkHttpHttpClient.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/OkHttpHttpClient.java @@ -19,23 +19,26 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient; +import com.buession.core.converter.mapper.PropertyMapper; import com.buession.core.validator.Validate; import com.buession.httpclient.conn.OkHttpClientConnectionManager; +import com.buession.httpclient.core.Configuration; import com.buession.httpclient.core.Header; import com.buession.httpclient.core.RequestBody; import com.buession.httpclient.core.Response; import com.buession.httpclient.exception.ConnectTimeoutException; import com.buession.httpclient.exception.ReadTimeoutException; import com.buession.httpclient.exception.RequestException; -import com.buession.httpclient.okhttp.OkHttpHttpClientBuilder; import com.buession.httpclient.okhttp.OkHttpRequest; import com.buession.httpclient.okhttp.OkHttpRequestBuilder; import com.buession.httpclient.okhttp.OkHttpResponseBuilder; +import com.buession.net.ssl.SslConfiguration; +import okhttp3.HttpClientBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -87,11 +90,29 @@ public OkHttpHttpClient(okhttp3.OkHttpClient httpClient) { public okhttp3.OkHttpClient getHttpClient() { if(httpClient == null){ - final OkHttpHttpClientBuilder httpClientBuilder = new OkHttpHttpClientBuilder( - (OkHttpClientConnectionManager) getConnectionManager()); + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); + final OkHttpClientConnectionManager okHttpClientConnectionManager = + (OkHttpClientConnectionManager) getConnectionManager(); + final Configuration configuration = okHttpClientConnectionManager.getConfiguration(); + final SslConfiguration sslConfiguration = configuration.getSslConfiguration(); + final HttpClientBuilder builder = HttpClientBuilder.create() + .setConnectionManager(okHttpClientConnectionManager.getClientConnectionManager()); + + propertyMapper.from(configuration.getConnectTimeout()).to(builder::setConnectTimeout); + propertyMapper.alwaysApplyingWhenPositiveNumber().from(configuration.getReadTimeout()) + .to(builder::setReadTimeout); + propertyMapper.alwaysApplyingWhenPositiveNumber().from(configuration.getWriteTimeout()) + .to(builder::setWriteTimeout); + propertyMapper.from(configuration.getRetryOnConnectionFailure()).to(builder::setRetryOnConnectionFailure); + propertyMapper.from(configuration.isAllowRedirects()).to(builder::setFollowRedirects); + + if(sslConfiguration != null){ + propertyMapper.from(sslConfiguration.getSslSocketFactory()).to(builder::setSSLSocketFactory); + propertyMapper.from(sslConfiguration.getHostnameVerifier()).to(builder::setSSLHostnameVerifier); + propertyMapper.from(sslConfiguration.getSslContext()).to(builder::setSSLContext); + } - httpClient = httpClientBuilder.build((builder)->{ - }); + httpClient = builder.build(); } return httpClient; @@ -374,7 +395,7 @@ protected Response doRequest(final OkHttpRequest request) throws IOException, Re return httpResponseBuilder.build(httpResponse); }catch(IOException e){ if(logger.isErrorEnabled()){ - logger.error("Request({}) url: {} error.", request.getMethod(), request.getUrl(), e); + logger.error("Request({}) url: {} error.", request.getMethod(), request.getUri(), e); } if(e instanceof SocketTimeoutException){ diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/AbstractApacheAsyncClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/AbstractApacheAsyncClient.java new file mode 100644 index 000000000..aaa2f08ce --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/AbstractApacheAsyncClient.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractApacheAsyncClient extends BaseApacheClient implements ApacheAsyncClient { + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/AbstractApacheClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/AbstractApacheClient.java new file mode 100644 index 000000000..309612277 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/AbstractApacheClient.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractApacheClient extends BaseApacheClient implements ApacheClient { + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/Apache4AsyncClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/Apache4AsyncClient.java new file mode 100644 index 000000000..69671b614 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/Apache4AsyncClient.java @@ -0,0 +1,534 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache; + +import com.buession.httpclient.apache.convert.utils.ApacheRequestBodyConverterUtils; +import com.buession.httpclient.apache.nio.DefaultCallback; +import com.buession.httpclient.conn.ApacheNioClientConnectionManager; +import com.buession.httpclient.core.Configuration; +import com.buession.httpclient.core.Header; +import com.buession.httpclient.core.ProtocolVersion; +import com.buession.httpclient.core.RequestBody; +import com.buession.httpclient.core.RequestBodyConverter; +import com.buession.httpclient.core.Response; +import com.buession.httpclient.core.concurrent.Callback; +import com.buession.httpclient.core.utils.HeadersBuilder; +import com.buession.httpclient.exception.RequestException; +import com.buession.net.ssl.SslConfiguration; +import org.apache.http.HttpEntity; +import org.apache.http.HttpHost; +import org.apache.http.HttpResponse; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.*; +import org.apache.http.entity.ContentType; +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; +import org.apache.http.nio.client.HttpAsyncClient; +import org.apache.http.nio.client.methods.HttpAsyncMethods; +import org.apache.http.nio.client.methods.ZeroCopyConsumer; +import org.apache.http.nio.protocol.HttpAsyncRequestProducer; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class Apache4AsyncClient extends AbstractApacheAsyncClient { + + private final static Map, RequestBodyConverter> REQUEST_BODY_CONVERTS = + ApacheRequestBodyConverterUtils.createApache4ClientRequestBodyConverter(); + + private final RequestConfig requestConfig; + + private final HttpAsyncClient httpClient; + + private final org.apache.http.ProtocolVersion protocolVersion; + + public Apache4AsyncClient(final HttpAsyncClient httpClient, + final ApacheNioClientConnectionManager connectionManager, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = createRequestConfig(connectionManager.getConfiguration()); + this.httpClient = httpClient; + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + public Apache4AsyncClient(final HttpAsyncClient httpClient, final RequestConfig requestConfig, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = requestConfig; + this.httpClient = httpClient; + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + public Apache4AsyncClient(final ApacheNioClientConnectionManager connectionManager, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = createRequestConfig(connectionManager.getConfiguration()); + this.httpClient = createHttpClient(connectionManager); + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + public Apache4AsyncClient(final RequestConfig requestConfig, + final ApacheNioClientConnectionManager connectionManager, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = requestConfig; + this.httpClient = createHttpClient(connectionManager); + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + @Override + public void get(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpGet(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void get(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpGet(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void post(final URI uri, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException { + doRequest(new HttpPost(determineRequestUri(uri, parameters)), requestConfig, headers, body, callback); + } + + @Override + public void post(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body, final Callback callback) + throws IOException, RequestException { + doRequest(new HttpPost(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body, callback); + } + + @Override + public void patch(final URI uri, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException { + doRequest(new HttpPatch(determineRequestUri(uri, parameters)), requestConfig, headers, body, callback); + } + + @Override + public void patch(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body, final Callback callback) + throws IOException, RequestException { + doRequest(new HttpPatch(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body, callback); + } + + @Override + public void put(final URI uri, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException { + doRequest(new HttpPut(determineRequestUri(uri, parameters)), requestConfig, headers, body, callback); + } + + @Override + public void put(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body, final Callback callback) + throws IOException, RequestException { + doRequest(new HttpPut(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, body, + callback); + } + + @Override + public void delete(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpDelete(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void delete(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpDelete(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void connect(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpConnect(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void connect(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpConnect(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void trace(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpTrace(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void trace(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpTrace(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void copy(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpCopy(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void copy(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpCopy(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void move(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpMove(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void move(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpMove(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void head(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpHead(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void head(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpHead(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void options(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpOptions(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void options(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpOptions(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void link(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpLink(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void link(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpLink(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void unlink(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpUnlink(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void unlink(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpUnlink(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void purge(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpPurge(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void purge(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpPurge(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void lock(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpLock(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void lock(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpLock(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void unlock(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpUnlock(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void unlock(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpUnlock(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void propfind(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpPropfind(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void propfind(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpPropfind(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + callback); + } + + @Override + public void proppatch(final URI uri, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException { + doRequest(new HttpPropPatch(determineRequestUri(uri, parameters)), requestConfig, headers, body, callback); + } + + @Override + public void proppatch(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body, final Callback callback) + throws IOException, RequestException { + doRequest(new HttpPropPatch(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body, callback); + } + + @Override + public void report(final URI uri, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException { + doRequest(new HttpReport(determineRequestUri(uri, parameters)), requestConfig, headers, body, callback); + } + + @Override + public void report(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body, final Callback callback) + throws IOException, RequestException { + doRequest(new HttpReport(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body, callback); + } + + @Override + public void view(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpView(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void view(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpView(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void wrapped(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpWrapped(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void wrapped(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpWrapped(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + protected RequestConfig createRequestConfig(final Configuration configuration) { + final RequestConfig.Builder builder = RequestConfig.custom(); + + propertyMapper.from(configuration.getConnectTimeout()).to(builder::setConnectTimeout); + propertyMapper.from(configuration.getConnectionRequestTimeout()).to(builder::setConnectionRequestTimeout); + propertyMapper.from(configuration.getReadTimeout()).to(builder::setSocketTimeout); + propertyMapper.from(configuration.isExpectContinueEnabled()).to(builder::setExpectContinueEnabled); + propertyMapper.from(configuration.isAllowRedirects()).to(builder::setRedirectsEnabled); + propertyMapper.from(configuration.getMaxRedirects()).to(builder::setMaxRedirects); + propertyMapper.from(configuration.isCircularRedirectsAllowed()).to(builder::setCircularRedirectsAllowed); + propertyMapper.from(configuration.isRelativeRedirectsAllowed()).to(builder::setRelativeRedirectsAllowed); + propertyMapper.from(configuration.isAuthenticationEnabled()).to(builder::setAuthenticationEnabled); + propertyMapper.from(configuration.isContentCompressionEnabled()).to(builder::setContentCompressionEnabled); + propertyMapper.from(configuration.isNormalizeUri()).to(builder::setNormalizeUri); + propertyMapper.from(configuration.getTargetPreferredAuthSchemes()).to(builder::setTargetPreferredAuthSchemes); + propertyMapper.from(configuration.getProxyPreferredAuthSchemes()).to(builder::setProxyPreferredAuthSchemes); + propertyMapper.from(configuration.getCookieSpec()).to(builder::setCookieSpec); + + final Configuration.Proxy proxy = configuration.getProxy(); + if(proxy != null){ + final String scheme = proxy.getScheme() == null ? null : proxy.getScheme().name(); + final HttpHost proxyHttpHost = proxy.getAddress() == null ? new HttpHost(proxy.getHostname(), + proxy.getPort(), scheme) : new HttpHost(proxy.getAddress(), proxy.getHostname(), proxy.getPort(), + scheme); + + builder.setProxy(proxyHttpHost); + } + + return builder.build(); + } + + protected org.apache.http.ProtocolVersion createProtocolVersion(final ProtocolVersion protocolVersion) { + if(protocolVersion != null){ + return new org.apache.http.ProtocolVersion(protocolVersion.getProtocol(), + protocolVersion.getMajor(), protocolVersion.getMinor()); + }else{ + return null; + } + } + + protected HttpAsyncClient createHttpClient(final ApacheNioClientConnectionManager connectionManager) { + final SslConfiguration sslConfiguration = connectionManager.getConfiguration().getSslConfiguration(); + final HttpAsyncClientBuilder builder = HttpAsyncClientBuilder.create() + .setConnectionManager(connectionManager.getClientConnectionManager()); + + propertyMapper.from(connectionManager.getConnectionManagerShared()).to(builder::setConnectionManagerShared); + + if(sslConfiguration != null){ + propertyMapper.from(sslConfiguration.getHostnameVerifier()).to(builder::setSSLHostnameVerifier); + propertyMapper.from(sslConfiguration.getSslContext()).to(builder::setSSLContext); + } + + return builder.build(); + } + + protected HttpEntity buildHttpEntity(final RequestBody body) { + final RequestBodyConverter, HttpEntity> converter = findBodyConverter(REQUEST_BODY_CONVERTS, + body); + return converter == null ? new UrlEncodedFormEntity(new ArrayList<>(), StandardCharsets.ISO_8859_1) : + converter.convert(body); + } + + protected void doRequest(final HttpRequestBase request, final RequestConfig requestConfig, + final List
headers, final Callback callback) throws IOException, RequestException { + if(headers != null){ + for(Header header : headers){ + request.setHeader(header.getName(), header.getValue()); + } + } + + Optional.ofNullable(requestConfig).ifPresent(request::setConfig); + Optional.ofNullable(protocolVersion).ifPresent(request::setProtocolVersion); + + doRequest(request, callback); + } + + protected void doRequest(final HttpRequestBase request, final RequestConfig requestConfig, + final int readTimeout, final List
headers, final Callback callback) + throws IOException, RequestException { + final RequestConfig.Builder requestConfigBuilder = RequestConfig.copy(requestConfig) + .setSocketTimeout(readTimeout); + doRequest(request, requestConfigBuilder.build(), headers, callback); + } + + protected void doRequest(final HttpEntityEnclosingRequestBase request, final RequestConfig requestConfig, + final List
headers, final RequestBody body, final Callback callback) + throws IOException, RequestException { + Optional.ofNullable(body).map(this::buildHttpEntity).ifPresent(request::setEntity); + final HeadersBuilder headersBuilder = new HeadersBuilder(); + + if(body != null && body.getContentType() != null){ + headersBuilder.add("Content-Type", body.getContentType().getMimeType()); + } + if(headers != null){ + headersBuilder.add(headers); + } + + doRequest(request, requestConfig, headersBuilder.build(), callback); + } + + protected void doRequest(final HttpEntityEnclosingRequestBase request, final RequestConfig requestConfig, + final int readTimeout, final List
headers, final RequestBody body, + final Callback callback) throws IOException, RequestException { + Optional.ofNullable(body).map(this::buildHttpEntity).ifPresent(request::setEntity); + final HeadersBuilder headersBuilder = new HeadersBuilder(); + + if(body != null && body.getContentType() != null){ + headersBuilder.add("Content-Type", body.getContentType().getMimeType()); + } + if(headers != null){ + headersBuilder.add(headers); + } + + doRequest(request, requestConfig, readTimeout, headersBuilder.build(), callback); + } + + protected void doRequest(final HttpRequestBase request, final Callback callback) throws IOException, + RequestException { + final HttpAsyncRequestProducer httpAsyncRequestProducer = HttpAsyncMethods.create(request); + + if(httpClient instanceof CloseableHttpAsyncClient){ + CloseableHttpAsyncClient closeableHttpAsyncClient = (CloseableHttpAsyncClient) httpClient; + + if(closeableHttpAsyncClient.isRunning() == false){ + closeableHttpAsyncClient.start(); + } + } + + try{ + File tempFile = File.createTempFile("buession-httpclient-apache-client4-", null); + Future future = httpClient.execute(httpAsyncRequestProducer, + new DefaultZeroCopyConsumer(tempFile), new DefaultCallback(callback)); + future.get(); + }catch(ExecutionException e){ + throw new RequestException(e.getMessage(), e); + }catch(InterruptedException e){ + throw new RequestException(e.getMessage(), e); + }finally{ + request.releaseConnection(); + } + } + + private final static class DefaultZeroCopyConsumer extends ZeroCopyConsumer { + + public DefaultZeroCopyConsumer(final File file) throws FileNotFoundException { + super(file); + } + + @Override + protected Response process(final HttpResponse response, final File file, final ContentType contentType) { + final ApacheResponseBuilder apacheResponseBuilder = new ApacheResponseBuilder(); + return apacheResponseBuilder.build(response); + } + + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/Apache4Client.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/Apache4Client.java new file mode 100644 index 000000000..8274769a8 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/Apache4Client.java @@ -0,0 +1,515 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache; + +import com.buession.httpclient.apache.convert.utils.ApacheRequestBodyConverterUtils; +import com.buession.httpclient.conn.ApacheClientConnectionManager; +import com.buession.httpclient.core.Configuration; +import com.buession.httpclient.core.Header; +import com.buession.httpclient.core.ProtocolVersion; +import com.buession.httpclient.core.RequestBody; +import com.buession.httpclient.core.RequestBodyConverter; +import com.buession.httpclient.core.Response; +import com.buession.httpclient.exception.ConnectTimeoutException; +import com.buession.httpclient.exception.ConnectionPoolTimeoutException; +import com.buession.httpclient.exception.ReadTimeoutException; +import com.buession.httpclient.exception.RequestAbortedException; +import com.buession.httpclient.exception.RequestException; +import com.buession.net.ssl.SslConfiguration; +import org.apache.http.HttpEntity; +import org.apache.http.HttpHost; +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.HttpClient; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.*; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.HttpClientBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.SocketTimeoutException; +import java.net.URI; +import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class Apache4Client extends AbstractApacheClient { + + private final static Map, RequestBodyConverter> REQUEST_BODY_CONVERTS = + ApacheRequestBodyConverterUtils.createApache4ClientRequestBodyConverter(); + + private final RequestConfig requestConfig; + + private final HttpClient httpClient; + + private final org.apache.http.ProtocolVersion protocolVersion; + + private final static Logger logger = LoggerFactory.getLogger(Apache4Client.class); + + public Apache4Client(final HttpClient httpClient, final ApacheClientConnectionManager connectionManager, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = createRequestConfig(connectionManager.getConfiguration()); + this.httpClient = httpClient; + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + public Apache4Client(final HttpClient httpClient, final RequestConfig requestConfig, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = requestConfig; + this.httpClient = httpClient; + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + public Apache4Client(final ApacheClientConnectionManager connectionManager, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = createRequestConfig(connectionManager.getConfiguration()); + this.httpClient = createHttpClient(connectionManager); + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + public Apache4Client(final RequestConfig requestConfig, final ApacheClientConnectionManager connectionManager, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = requestConfig; + this.httpClient = createHttpClient(connectionManager); + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + @Override + public Response get(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpGet(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response get(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpGet(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response post(final URI uri, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpPost(determineRequestUri(uri, parameters)), requestConfig, headers, body); + } + + @Override + public Response post(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpPost(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body); + } + + @Override + public Response patch(final URI uri, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpPatch(determineRequestUri(uri, parameters)), requestConfig, headers, body); + } + + @Override + public Response patch(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpPatch(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body); + } + + @Override + public Response put(final URI uri, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpPut(determineRequestUri(uri, parameters)), requestConfig, headers, body); + } + + @Override + public Response put(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpPut(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, body); + } + + @Override + public Response delete(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpDelete(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response delete(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpDelete(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response connect(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpConnect(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response connect(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpConnect(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response trace(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpTrace(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response trace(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpTrace(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response copy(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpCopy(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response copy(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpCopy(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response move(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpMove(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response move(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpMove(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response head(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpHead(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response head(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpHead(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response options(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpOptions(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response options(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpOptions(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response link(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpLink(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response link(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpLink(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response unlink(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpUnlink(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response unlink(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpUnlink(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response purge(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpPurge(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response purge(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpPurge(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response lock(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpLock(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response lock(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpLock(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response unlock(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpUnlock(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response unlock(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpUnlock(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response propfind(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpPropfind(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response propfind(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpPropfind(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response proppatch(final URI uri, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpPropPatch(determineRequestUri(uri, parameters)), requestConfig, headers, body); + } + + @Override + public Response proppatch(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body) + throws IOException, RequestException { + return doRequest(new HttpPropPatch(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body); + } + + @Override + public Response report(final URI uri, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpReport(determineRequestUri(uri, parameters)), requestConfig, headers, body); + } + + @Override + public Response report(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body) + throws IOException, RequestException { + return doRequest(new HttpReport(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body); + } + + @Override + public Response view(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpView(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response view(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpView(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response wrapped(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpWrapped(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response wrapped(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpWrapped(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + protected RequestConfig createRequestConfig(final Configuration configuration) { + final RequestConfig.Builder builder = RequestConfig.custom(); + + propertyMapper.from(configuration.getConnectTimeout()).to(builder::setConnectTimeout); + propertyMapper.from(configuration.getConnectionRequestTimeout()).to(builder::setConnectionRequestTimeout); + propertyMapper.from(configuration.getReadTimeout()).to(builder::setSocketTimeout); + propertyMapper.from(configuration.isExpectContinueEnabled()).to(builder::setExpectContinueEnabled); + propertyMapper.from(configuration.isAllowRedirects()).to(builder::setRedirectsEnabled); + propertyMapper.from(configuration.getMaxRedirects()).to(builder::setMaxRedirects); + propertyMapper.from(configuration.isCircularRedirectsAllowed()).to(builder::setCircularRedirectsAllowed); + propertyMapper.from(configuration.isRelativeRedirectsAllowed()).to(builder::setRelativeRedirectsAllowed); + propertyMapper.from(configuration.isAuthenticationEnabled()).to(builder::setAuthenticationEnabled); + propertyMapper.from(configuration.isContentCompressionEnabled()).to(builder::setContentCompressionEnabled); + propertyMapper.from(configuration.isNormalizeUri()).to(builder::setNormalizeUri); + propertyMapper.from(configuration.getTargetPreferredAuthSchemes()).to(builder::setTargetPreferredAuthSchemes); + propertyMapper.from(configuration.getProxyPreferredAuthSchemes()).to(builder::setProxyPreferredAuthSchemes); + propertyMapper.from(configuration.getCookieSpec()).to(builder::setCookieSpec); + + final Configuration.Proxy proxy = configuration.getProxy(); + if(proxy != null){ + final String scheme = proxy.getScheme() == null ? null : proxy.getScheme().name(); + final HttpHost proxyHttpHost = proxy.getAddress() == null ? new HttpHost(proxy.getHostname(), + proxy.getPort(), scheme) : new HttpHost(proxy.getAddress(), proxy.getHostname(), proxy.getPort(), + scheme); + + builder.setProxy(proxyHttpHost); + } + + return builder.build(); + } + + protected org.apache.http.ProtocolVersion createProtocolVersion(final ProtocolVersion protocolVersion) { + if(protocolVersion != null){ + return new org.apache.http.ProtocolVersion(protocolVersion.getProtocol(), + protocolVersion.getMajor(), protocolVersion.getMinor()); + }else{ + return null; + } + } + + protected HttpClient createHttpClient(final ApacheClientConnectionManager connectionManager) { + final SslConfiguration sslConfiguration = connectionManager.getConfiguration().getSslConfiguration(); + final HttpClientBuilder builder = HttpClientBuilder.create() + .setConnectionManager(connectionManager.getClientConnectionManager()); + + propertyMapper.from(connectionManager.getConnectionManagerShared()).to(builder::setConnectionManagerShared); + + if(sslConfiguration != null){ + propertyMapper.from(sslConfiguration.getHostnameVerifier()).to(builder::setSSLHostnameVerifier); + propertyMapper.from(sslConfiguration.getSslContext()).to(builder::setSSLContext); + propertyMapper.from(sslConfiguration.getSslSocketFactory()) + .as((ssf)->new SSLConnectionSocketFactory(ssf, sslConfiguration.getHostnameVerifier())) + .to(builder::setSSLSocketFactory); + } + + return builder.build(); + } + + protected HttpEntity buildHttpEntity(final RequestBody body) { + final RequestBodyConverter, HttpEntity> converter = findBodyConverter(REQUEST_BODY_CONVERTS, + body); + return converter == null ? new UrlEncodedFormEntity(new ArrayList<>(), StandardCharsets.ISO_8859_1) : + converter.convert(body); + } + + protected Response doRequest(final HttpRequestBase request, final RequestConfig requestConfig, + final List
headers) throws IOException, RequestException { + if(headers != null){ + for(Header header : headers){ + request.setHeader(header.getName(), header.getValue()); + } + } + + Optional.ofNullable(requestConfig).ifPresent(request::setConfig); + Optional.ofNullable(protocolVersion).ifPresent(request::setProtocolVersion); + + return doRequest(request); + } + + protected Response doRequest(final HttpRequestBase request, final RequestConfig requestConfig, + final int readTimeout, final List
headers) throws IOException, + RequestException { + final RequestConfig.Builder requestConfigBuilder = RequestConfig.copy(requestConfig) + .setSocketTimeout(readTimeout); + return doRequest(request, requestConfigBuilder.build(), headers); + } + + protected Response doRequest(final HttpEntityEnclosingRequestBase request, final RequestConfig requestConfig, + final List
headers, final RequestBody body) + throws IOException, RequestException { + Optional.ofNullable(body).map(this::buildHttpEntity).ifPresent(request::setEntity); + final List
headersCopy = headers == null ? new ArrayList<>(1) : headers; + + if(body != null && body.getContentType() != null){ + headersCopy.add(new Header("Content-Type", body.getContentType().getMimeType())); + } + + return doRequest(request, requestConfig, headersCopy); + } + + protected Response doRequest(final HttpEntityEnclosingRequestBase request, final RequestConfig requestConfig, + final int readTimeout, final List
headers, final RequestBody body) + throws IOException, RequestException { + Optional.ofNullable(body).map(this::buildHttpEntity).ifPresent(request::setEntity); + final List
headersCopy = headers == null ? new ArrayList<>(1) : headers; + + if(body != null && body.getContentType() != null){ + headersCopy.add(new Header("Content-Type", body.getContentType().getMimeType())); + } + + return doRequest(request, requestConfig, readTimeout, headers); + } + + protected Response doRequest(final HttpRequestBase request) throws IOException, RequestException { + final ApacheResponseBuilder apacheResponseBuilder = new ApacheResponseBuilder(); + + try{ + HttpResponse httpResponse = httpClient.execute(request); + return apacheResponseBuilder.build(httpResponse); + }catch(IOException e){ + if(logger.isErrorEnabled()){ + logger.error("Request({}) url: {} error.", request.getMethod(), request.getURI(), e); + } + + if(e instanceof org.apache.http.conn.ConnectionPoolTimeoutException){ + throw new ConnectionPoolTimeoutException(e.getMessage()); + }else if(e instanceof org.apache.http.conn.ConnectTimeoutException){ + throw new ConnectTimeoutException(e.getMessage()); + }else if(e instanceof SocketTimeoutException){ + throw new ReadTimeoutException(e.getMessage()); + }else if(e instanceof org.apache.http.impl.execchain.RequestAbortedException){ + throw new RequestAbortedException(e.getMessage()); + }else if(e instanceof ClientProtocolException){ + throw new RequestException(e.getMessage(), e); + }else if(e instanceof UnknownHostException){ + throw e; + }else{ + throw new RequestException(e.getMessage(), e); + } + }finally{ + request.releaseConnection(); + } + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/Apache5AsyncClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/Apache5AsyncClient.java new file mode 100644 index 000000000..0ad616c09 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/Apache5AsyncClient.java @@ -0,0 +1,582 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache; + +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.httpclient.apache.convert.utils.ApacheRequestBodyConverterUtils; +import com.buession.httpclient.apache.nio.Default5Callback; +import com.buession.httpclient.conn.Apache5NioClientConnectionManager; +import com.buession.httpclient.conn.nio.IOReactorConfig; +import com.buession.httpclient.core.Configuration; +import com.buession.httpclient.core.Header; +import com.buession.httpclient.core.ProtocolVersion; +import com.buession.httpclient.core.RequestBody; +import com.buession.httpclient.core.RequestBodyConverter; +import com.buession.httpclient.core.Response; +import com.buession.httpclient.core.concurrent.Callback; +import com.buession.httpclient.core.utils.HeadersBuilder; +import com.buession.httpclient.exception.RequestException; +import com.buession.net.ssl.SslConfiguration; +import org.apache.hc.client5.http.async.HttpAsyncClient; +import org.apache.hc.client5.http.classic.methods.*; +import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.entity.UrlEncodedFormEntity; +import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; +import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.HttpException; +import org.apache.hc.core5.http.HttpHost; +import org.apache.hc.core5.http.HttpResponse; +import org.apache.hc.core5.http.nio.AsyncRequestProducer; +import org.apache.hc.core5.http.nio.entity.BasicAsyncEntityConsumer; +import org.apache.hc.core5.http.nio.support.AbstractAsyncResponseConsumer; +import org.apache.hc.core5.http.nio.support.BasicRequestProducer; +import org.apache.hc.core5.http.protocol.HttpContext; +import org.apache.hc.core5.util.TimeValue; +import org.apache.hc.core5.util.Timeout; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class Apache5AsyncClient extends AbstractApacheAsyncClient { + + private final static Map, RequestBodyConverter> REQUEST_BODY_CONVERTS = + ApacheRequestBodyConverterUtils.createApache5ClientRequestBodyConverter(); + + private final RequestConfig requestConfig; + + private final HttpAsyncClient httpClient; + + private final org.apache.hc.core5.http.ProtocolVersion protocolVersion; + + private boolean isRunning = false; + + public Apache5AsyncClient(final HttpAsyncClient httpClient, + final Apache5NioClientConnectionManager connectionManager, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = createRequestConfig(connectionManager.getConfiguration()); + this.httpClient = httpClient; + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + public Apache5AsyncClient(final HttpAsyncClient httpClient, final RequestConfig requestConfig, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = requestConfig; + this.httpClient = httpClient; + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + public Apache5AsyncClient(final Apache5NioClientConnectionManager connectionManager, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = createRequestConfig(connectionManager.getConfiguration()); + this.httpClient = createHttpClient(connectionManager); + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + public Apache5AsyncClient(final RequestConfig requestConfig, + final Apache5NioClientConnectionManager connectionManager, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = requestConfig; + this.httpClient = createHttpClient(connectionManager); + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + @Override + public void get(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpGet(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void get(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpGet(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void post(final URI uri, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException { + doRequest(new HttpPost(determineRequestUri(uri, parameters)), requestConfig, headers, body, callback); + } + + @Override + public void post(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body, final Callback callback) + throws IOException, RequestException { + doRequest(new HttpPost(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body, callback); + } + + @Override + public void patch(final URI uri, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException { + doRequest(new HttpPatch(determineRequestUri(uri, parameters)), requestConfig, headers, body, callback); + } + + @Override + public void patch(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body, final Callback callback) + throws IOException, RequestException { + doRequest(new HttpPatch(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body, callback); + } + + @Override + public void put(final URI uri, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException { + doRequest(new HttpPut(determineRequestUri(uri, parameters)), requestConfig, headers, body, callback); + } + + @Override + public void put(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body, final Callback callback) + throws IOException, RequestException { + doRequest(new HttpPut(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, body, + callback); + } + + @Override + public void delete(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpDelete(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void delete(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpDelete(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void connect(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpConnect(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void connect(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpConnect(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void trace(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpTrace(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void trace(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpTrace(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void copy(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpCopy(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void copy(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpCopy(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void move(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpMove(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void move(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpMove(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void head(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpHead(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void head(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpHead(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void options(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpOptions(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void options(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpOptions(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void link(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpLink(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void link(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpLink(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void unlink(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpUnlink(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void unlink(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpUnlink(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void purge(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpPurge(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void purge(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpPurge(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void lock(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpLock(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void lock(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpLock(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void unlock(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpUnlock(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void unlock(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpUnlock(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void propfind(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpPropfind(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void propfind(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpPropfind(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + callback); + } + + @Override + public void proppatch(final URI uri, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException { + doRequest(new HttpPropPatch(determineRequestUri(uri, parameters)), requestConfig, headers, body, callback); + } + + @Override + public void proppatch(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body, final Callback callback) + throws IOException, RequestException { + doRequest(new HttpPropPatch(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body, callback); + } + + @Override + public void report(final URI uri, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException { + doRequest(new HttpReport(determineRequestUri(uri, parameters)), requestConfig, headers, body, callback); + } + + @Override + public void report(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body, final Callback callback) + throws IOException, RequestException { + doRequest(new HttpReport(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body, callback); + } + + @Override + public void view(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpView(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void view(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpView(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + @Override + public void wrapped(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException { + doRequest(new HttpWrapped(determineRequestUri(uri, parameters)), requestConfig, headers, callback); + } + + @Override + public void wrapped(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException { + doRequest(new HttpWrapped(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, callback); + } + + protected RequestConfig createRequestConfig(final Configuration configuration) { + final RequestConfig.Builder builder = RequestConfig.custom(); + + propertyMapper.from(configuration.getConnectionRequestTimeout()).as(Timeout::ofMilliseconds) + .to(builder::setConnectionRequestTimeout); + propertyMapper.from(configuration.isExpectContinueEnabled()).to(builder::setExpectContinueEnabled); + propertyMapper.from(configuration.isAllowRedirects()).to(builder::setRedirectsEnabled); + propertyMapper.from(configuration.getMaxRedirects()).to(builder::setMaxRedirects); + propertyMapper.from(configuration.isCircularRedirectsAllowed()).to(builder::setCircularRedirectsAllowed); + propertyMapper.from(configuration.isHardCancellationEnabled()).to(builder::setHardCancellationEnabled); + propertyMapper.from(configuration.isAuthenticationEnabled()).to(builder::setAuthenticationEnabled); + propertyMapper.from(configuration.isContentCompressionEnabled()).to(builder::setContentCompressionEnabled); + propertyMapper.from(configuration.getTargetPreferredAuthSchemes()).to(builder::setTargetPreferredAuthSchemes); + propertyMapper.from(configuration.getProxyPreferredAuthSchemes()).to(builder::setProxyPreferredAuthSchemes); + propertyMapper.from(configuration.getCookieSpec()).to(builder::setCookieSpec); + + return builder.build(); + } + + protected org.apache.hc.core5.http.ProtocolVersion createProtocolVersion(final ProtocolVersion protocolVersion) { + if(protocolVersion != null){ + return new org.apache.hc.core5.http.ProtocolVersion(protocolVersion.getProtocol(), + protocolVersion.getMajor(), protocolVersion.getMinor()); + }else{ + return null; + } + } + + protected org.apache.hc.core5.reactor.IOReactorConfig createConnectingIOReactor( + final Apache5NioClientConnectionManager connectionManager) { + IOReactorConfig ioReactorConfig = connectionManager.getIoReactorConfig(); + + if(ioReactorConfig != null){ + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); + final org.apache.hc.core5.reactor.IOReactorConfig.Builder ioReactorConfigBuilder = + org.apache.hc.core5.reactor.IOReactorConfig.custom(); + + propertyMapper.from(ioReactorConfig.getSelectInterval()).as(TimeValue::ofMilliseconds) + .to(ioReactorConfigBuilder::setSelectInterval); + propertyMapper.from(ioReactorConfig.getIoThreadCount()).to(ioReactorConfigBuilder::setIoThreadCount); + propertyMapper.from(ioReactorConfig.getSoTimeout()).as(Timeout::ofMilliseconds) + .to(ioReactorConfigBuilder::setSoTimeout); + propertyMapper.from(ioReactorConfig.isSoReuseAddress()).to(ioReactorConfigBuilder::setSoReuseAddress); + propertyMapper.from(ioReactorConfig.getSoLinger()).as(Timeout::ofMilliseconds) + .to(ioReactorConfigBuilder::setSoLinger); + propertyMapper.from(ioReactorConfig.isSoKeepAlive()).to(ioReactorConfigBuilder::setSoKeepAlive); + propertyMapper.from(ioReactorConfig.isTcpNoDelay()).to(ioReactorConfigBuilder::setTcpNoDelay); + propertyMapper.from(ioReactorConfig.getSndBufSize()).to(ioReactorConfigBuilder::setSndBufSize); + propertyMapper.from(ioReactorConfig.getRcvBufSize()).to(ioReactorConfigBuilder::setRcvBufSize); + propertyMapper.from(ioReactorConfig.getBacklogSize()).to(ioReactorConfigBuilder::setBacklogSize); + + return ioReactorConfigBuilder.build(); + } + + return null; + } + + protected HttpAsyncClient createHttpClient(final Apache5NioClientConnectionManager connectionManager) { + final SslConfiguration sslConfiguration = connectionManager.getConfiguration().getSslConfiguration(); + final HttpAsyncClientBuilder builder = HttpAsyncClientBuilder.create() + .setConnectionManager(connectionManager.getClientConnectionManager()); + + propertyMapper.from(connectionManager.getConnectionManagerShared()).to(builder::setConnectionManagerShared); + propertyMapper.alwaysApplyingWhenNonNull().from(connectionManager.getConfiguration().getProxy()) + .as((v)->new HttpHost(v.getScheme() == null ? null : v.getScheme().name(), v.getAddress(), + v.getHostname(), v.getPort())).to(builder::setProxy); + + builder.setIOReactorConfig(createConnectingIOReactor(connectionManager)); + + if(sslConfiguration != null){ + //propertyMapper.from(sslConfiguration.getHostnameVerifier()).to(builder::setSSLHostnameVerifier); + //propertyMapper.from(sslConfiguration.getSslContext()).to(builder::setSSLContext); + } + + return builder.build(); + } + + protected HttpEntity buildHttpEntity(final RequestBody body) { + final RequestBodyConverter, HttpEntity> converter = findBodyConverter(REQUEST_BODY_CONVERTS, + body); + return converter == null ? new UrlEncodedFormEntity(new ArrayList<>(), StandardCharsets.ISO_8859_1) : + converter.convert(body); + } + + protected void doRequest(final HttpUriRequestBase request, final RequestConfig requestConfig, + final List
headers, final Callback callback) throws IOException, RequestException { + if(headers != null){ + for(Header header : headers){ + request.setHeader(header.getName(), header.getValue()); + } + } + + Optional.ofNullable(requestConfig).ifPresent(request::setConfig); + Optional.ofNullable(protocolVersion).ifPresent(request::setVersion); + + doRequest(request, callback); + } + + protected void doRequest(final HttpUriRequestBase request, final RequestConfig requestConfig, + final int readTimeout, final List
headers, final Callback callback) + throws IOException, RequestException { + final RequestConfig.Builder requestConfigBuilder = RequestConfig.copy(requestConfig) + .setResponseTimeout(readTimeout, TimeUnit.MILLISECONDS); + doRequest(request, requestConfigBuilder.build(), headers, callback); + } + + protected void doRequest(final HttpUriRequestBase request, final RequestConfig requestConfig, + final List
headers, final RequestBody body, final Callback callback) + throws IOException, RequestException { + Optional.ofNullable(body).map(this::buildHttpEntity).ifPresent(request::setEntity); + final HeadersBuilder headersBuilder = new HeadersBuilder(); + + if(body != null && body.getContentType() != null){ + headersBuilder.add("Content-Type", body.getContentType().getMimeType()); + } + if(headers != null){ + headersBuilder.add(headers); + } + + doRequest(request, requestConfig, headersBuilder.build(), callback); + } + + protected void doRequest(final HttpUriRequestBase request, final RequestConfig requestConfig, + final int readTimeout, final List
headers, final RequestBody body, + final Callback callback) throws IOException, RequestException { + Optional.ofNullable(body).map(this::buildHttpEntity).ifPresent(request::setEntity); + final HeadersBuilder headersBuilder = new HeadersBuilder(); + + if(body != null && body.getContentType() != null){ + headersBuilder.add("Content-Type", body.getContentType().getMimeType()); + } + if(headers != null){ + headersBuilder.add(headers); + } + + doRequest(request, requestConfig, readTimeout, headersBuilder.build(), callback); + } + + protected void doRequest(final HttpUriRequestBase request, final Callback callback) throws IOException, + RequestException { + final AsyncRequestProducer httpAsyncRequestProducer = new BasicRequestProducer(request, null); + + if(httpClient instanceof CloseableHttpAsyncClient){ + CloseableHttpAsyncClient closeableHttpAsyncClient = (CloseableHttpAsyncClient) httpClient; + + if(isRunning == false){ + closeableHttpAsyncClient.start(); + isRunning = true; + } + } + + try{ + Future future = httpClient.execute(httpAsyncRequestProducer, new BinaryAsyncResponseConsumer(), + null, null, new Default5Callback(callback)); + future.get(); + }catch(ExecutionException e){ + throw new RequestException(e.getMessage(), e); + }catch(InterruptedException e){ + throw new RequestException(e.getMessage(), e); + }finally{ + //request.releaseConnection(); + } + } + + private final static class BinaryAsyncResponseConsumer extends AbstractAsyncResponseConsumer { + + public BinaryAsyncResponseConsumer() { + super(new BasicAsyncEntityConsumer()); + } + + @Override + public void informationResponse(final HttpResponse response, final HttpContext context) + throws HttpException, IOException { + } + + @Override + protected Response buildResult(final HttpResponse httpResponse, final byte[] entity, + final ContentType contentType) { + Apache5ResponseBuilder responseBuilder = new Apache5ResponseBuilder(); + Response response = responseBuilder.build(httpResponse); + + response.setInputStream(new ByteArrayInputStream(entity)); + response.setBody(new String(entity)); + + try{ + response.setContentLength(Integer.parseInt(httpResponse.getFirstHeader("Content-Length").getValue())); + }catch(NumberFormatException e){ + response.setContentLength(response.getBody().length()); + } + + return response; + } + + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/Apache5Client.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/Apache5Client.java new file mode 100644 index 000000000..0339bd20b --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/Apache5Client.java @@ -0,0 +1,512 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache; + +import com.buession.httpclient.apache.convert.utils.ApacheRequestBodyConverterUtils; +import com.buession.httpclient.conn.Apache5ClientConnectionManager; +import com.buession.httpclient.core.Configuration; +import com.buession.httpclient.core.Header; +import com.buession.httpclient.core.ProtocolVersion; +import com.buession.httpclient.core.RequestBody; +import com.buession.httpclient.core.RequestBodyConverter; +import com.buession.httpclient.core.Response; +import com.buession.httpclient.exception.ConnectTimeoutException; +import com.buession.httpclient.exception.ReadTimeoutException; +import com.buession.httpclient.exception.RequestAbortedException; +import com.buession.httpclient.exception.RequestException; +import com.buession.net.ssl.SslConfiguration; +import org.apache.hc.client5.http.ClientProtocolException; +import org.apache.hc.client5.http.classic.HttpClient; +import org.apache.hc.client5.http.classic.methods.*; +import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.entity.UrlEncodedFormEntity; +import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; +import org.apache.hc.core5.http.ClassicHttpRequest; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.HttpHost; +import org.apache.hc.core5.http.HttpResponse; +import org.apache.hc.core5.util.Timeout; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.SocketTimeoutException; +import java.net.URI; +import java.net.UnknownHostException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class Apache5Client extends AbstractApacheClient { + + private final static Map, RequestBodyConverter> REQUEST_BODY_CONVERTS = + ApacheRequestBodyConverterUtils.createApache5ClientRequestBodyConverter(); + + private final RequestConfig requestConfig; + + private final HttpClient httpClient; + + private final org.apache.hc.core5.http.ProtocolVersion protocolVersion; + + private final static Logger logger = LoggerFactory.getLogger(Apache5Client.class); + + public Apache5Client(final HttpClient httpClient, final Apache5ClientConnectionManager connectionManager, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = createRequestConfig(connectionManager.getConfiguration()); + this.httpClient = httpClient; + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + public Apache5Client(final HttpClient httpClient, final RequestConfig requestConfig, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = requestConfig; + this.httpClient = httpClient; + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + public Apache5Client(final Apache5ClientConnectionManager connectionManager, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = createRequestConfig(connectionManager.getConfiguration()); + this.httpClient = createHttpClient(connectionManager); + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + public Apache5Client(final RequestConfig requestConfig, final Apache5ClientConnectionManager connectionManager, + final ProtocolVersion protocolVersion) { + super(); + this.requestConfig = requestConfig; + this.httpClient = createHttpClient(connectionManager); + this.protocolVersion = createProtocolVersion(protocolVersion); + } + + @Override + public Response get(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpGet(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response get(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpGet(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response post(final URI uri, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpPost(determineRequestUri(uri, parameters)), requestConfig, headers, + body); + } + + @Override + public Response post(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpPost(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body); + } + + @Override + public Response patch(final URI uri, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpPatch(determineRequestUri(uri, parameters)), requestConfig, headers, body); + } + + @Override + public Response patch(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpPatch(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body); + } + + @Override + public Response put(final URI uri, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpPut(determineRequestUri(uri, parameters)), requestConfig, headers, body); + } + + @Override + public Response put(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpPut(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body); + } + + @Override + public Response delete(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpDelete(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response delete(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpDelete(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response connect(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpConnect(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response connect(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpConnect(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response trace(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpTrace(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response trace(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpTrace(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response copy(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpCopy(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response copy(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpCopy(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response move(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpMove(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response move(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpMove(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response head(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpHead(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response head(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpHead(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response options(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpOptions(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response options(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpOptions(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response link(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpLink(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response link(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpLink(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response unlink(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpUnlink(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response unlink(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpUnlink(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response purge(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpPurge(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response purge(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpPurge(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response lock(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpLock(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response lock(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpLock(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response unlock(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpUnlock(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response unlock(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpUnlock(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response propfind(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpPropfind(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response propfind(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpPropfind(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response proppatch(final URI uri, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpPropPatch(determineRequestUri(uri, parameters)), requestConfig, headers, body); + } + + @Override + public Response proppatch(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body) + throws IOException, RequestException { + return doRequest(new HttpPropPatch(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body); + } + + @Override + public Response report(final URI uri, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException { + return doRequest(new HttpReport(determineRequestUri(uri, parameters)), requestConfig, headers, body); + } + + @Override + public Response report(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body) + throws IOException, RequestException { + return doRequest(new HttpReport(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers, + body); + } + + @Override + public Response view(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpView(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response view(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpView(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + @Override + public Response wrapped(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException { + return doRequest(new HttpWrapped(determineRequestUri(uri, parameters)), requestConfig, headers); + } + + @Override + public Response wrapped(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException { + return doRequest(new HttpWrapped(determineRequestUri(uri, parameters)), requestConfig, readTimeout, headers); + } + + protected RequestConfig createRequestConfig(final Configuration configuration) { + final RequestConfig.Builder builder = RequestConfig.custom(); + + propertyMapper.from(configuration.getConnectionRequestTimeout()).as(Timeout::ofMilliseconds) + .to(builder::setConnectionRequestTimeout); + propertyMapper.from(configuration.isExpectContinueEnabled()).to(builder::setExpectContinueEnabled); + propertyMapper.from(configuration.isAllowRedirects()).to(builder::setRedirectsEnabled); + propertyMapper.from(configuration.getMaxRedirects()).to(builder::setMaxRedirects); + propertyMapper.from(configuration.isCircularRedirectsAllowed()).to(builder::setCircularRedirectsAllowed); + propertyMapper.from(configuration.isHardCancellationEnabled()).to(builder::setHardCancellationEnabled); + propertyMapper.from(configuration.isAuthenticationEnabled()).to(builder::setAuthenticationEnabled); + propertyMapper.from(configuration.isContentCompressionEnabled()).to(builder::setContentCompressionEnabled); + propertyMapper.from(configuration.getTargetPreferredAuthSchemes()).to(builder::setTargetPreferredAuthSchemes); + propertyMapper.from(configuration.getProxyPreferredAuthSchemes()).to(builder::setProxyPreferredAuthSchemes); + propertyMapper.from(configuration.getCookieSpec()).to(builder::setCookieSpec); + + return builder.build(); + } + + protected org.apache.hc.core5.http.ProtocolVersion createProtocolVersion(final ProtocolVersion protocolVersion) { + if(protocolVersion != null){ + return new org.apache.hc.core5.http.ProtocolVersion(protocolVersion.getProtocol(), + protocolVersion.getMajor(), protocolVersion.getMinor()); + }else{ + return null; + } + } + + protected HttpClient createHttpClient(final Apache5ClientConnectionManager connectionManager) { + final SslConfiguration sslConfiguration = connectionManager.getConfiguration().getSslConfiguration(); + final HttpClientBuilder builder = HttpClientBuilder.create() + .setConnectionManager(connectionManager.getClientConnectionManager()); + + propertyMapper.from(connectionManager.getConnectionManagerShared()).to(builder::setConnectionManagerShared); + propertyMapper.alwaysApplyingWhenNonNull().from(connectionManager.getConfiguration().getProxy()) + .as((v)->new HttpHost(v.getScheme() == null ? null : v.getScheme().name(), v.getAddress(), + v.getHostname(), v.getPort())).to(builder::setProxy); + + if(sslConfiguration != null){ + /* + propertyMapper.from(sslConfiguration.getHostnameVerifier()).to(builder::setSSLHostnameVerifier); + propertyMapper.from(sslConfiguration.getSslContext()).to(builder::setSSLContext); + + if(sslConfiguration.getSslSocketFactory() != null){ + builder.setSSLSocketFactory(new SSLConnectionSocketFactory(sslConfiguration.getSslSocketFactory(), + sslConfiguration.getHostnameVerifier())); + } + + */ + } + + return builder.build(); + } + + protected HttpEntity buildHttpEntity(final RequestBody body) { + final RequestBodyConverter, HttpEntity> converter = findBodyConverter(REQUEST_BODY_CONVERTS, + body); + return converter == null ? new UrlEncodedFormEntity(new ArrayList<>(), StandardCharsets.ISO_8859_1) : + converter.convert(body); + } + + protected Response doRequest(final HttpUriRequestBase request, final RequestConfig requestConfig, + final List
headers) throws IOException, RequestException { + if(headers != null){ + for(Header header : headers){ + request.setHeader(header.getName(), header.getValue()); + } + } + + Optional.ofNullable(requestConfig).ifPresent(request::setConfig); + Optional.ofNullable(protocolVersion).ifPresent(request::setVersion); + + return doRequest(request); + } + + protected Response doRequest(final HttpUriRequestBase request, final RequestConfig requestConfig, + final int readTimeout, final List
headers) throws IOException, + RequestException { + final RequestConfig.Builder requestConfigBuilder = RequestConfig.copy(requestConfig) + .setResponseTimeout(readTimeout, TimeUnit.MILLISECONDS); + return doRequest(request, requestConfigBuilder.build(), headers); + } + + protected Response doRequest(final HttpUriRequestBase request, final RequestConfig requestConfig, + final List
headers, final RequestBody body) + throws IOException, RequestException { + Optional.ofNullable(body).map(this::buildHttpEntity).ifPresent(request::setEntity); + final List
headersCopy = headers == null ? new ArrayList<>(1) : headers; + + if(body != null && body.getContentType() != null){ + headersCopy.add(new Header("Content-Type", body.getContentType().getMimeType())); + } + + return doRequest(request, requestConfig, headersCopy); + } + + protected Response doRequest(final HttpUriRequestBase request, final RequestConfig requestConfig, + final int readTimeout, final List
headers, final RequestBody body) + throws IOException, RequestException { + Optional.ofNullable(body).map(this::buildHttpEntity).ifPresent(request::setEntity); + final List
headersCopy = headers == null ? new ArrayList<>(1) : headers; + + if(body != null && body.getContentType() != null){ + headersCopy.add(new Header("Content-Type", body.getContentType().getMimeType())); + } + + return doRequest(request, requestConfig, readTimeout, headersCopy); + } + + protected Response doRequest(final ClassicHttpRequest request) throws IOException, RequestException { + final Apache5ResponseBuilder apacheResponseBuilder = new Apache5ResponseBuilder(); + + try{ + HttpResponse httpResponse = httpClient.executeOpen(null, request, null); + return apacheResponseBuilder.build(httpResponse); + }catch(IOException e){ + if(logger.isErrorEnabled()){ + logger.error("Request({}) url: {} error.", request.getMethod(), request.getRequestUri(), e); + } + + if(e instanceof org.apache.hc.client5.http.ConnectTimeoutException){ + throw new ConnectTimeoutException(e.getMessage()); + }else if(e instanceof SocketTimeoutException){ + throw new ReadTimeoutException(e.getMessage()); + }else if(e instanceof org.apache.hc.client5.http.impl.classic.RequestAbortedException){ + throw new RequestAbortedException(e.getMessage()); + }else if(e instanceof ClientProtocolException){ + throw new RequestException(e.getMessage(), e); + }else if(e instanceof UnknownHostException){ + throw e; + }else{ + throw new RequestException(e.getMessage(), e); + } + }finally{ + //request.getHttpRequest().releaseConnection(); + } + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/Apache5ResponseBuilder.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/Apache5ResponseBuilder.java new file mode 100644 index 000000000..0a63eca27 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/Apache5ResponseBuilder.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache; + +import com.buession.httpclient.core.AbstractResponseBuilder; +import com.buession.httpclient.core.AbstractResponseHeaderParse; +import com.buession.httpclient.core.ProtocolVersion; +import com.buession.httpclient.core.Response; +import com.buession.httpclient.core.StatusLine; +import com.google.common.collect.Multimap; +import org.apache.hc.client5.http.async.methods.SimpleHttpResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.ClassicHttpResponse; +import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.ParseException; +import org.apache.hc.core5.http.io.entity.BufferedHttpEntity; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayInputStream; +import java.io.IOException; + +/** + * Apache Http Client 5 响应构建器 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class Apache5ResponseBuilder extends AbstractResponseBuilder { + + private final static Logger logger = LoggerFactory.getLogger(Apache5ResponseBuilder.class); + + @Override + public Response build(org.apache.hc.core5.http.HttpResponse httpResponse) { + final Response response = new Response(); + final org.apache.hc.core5.http.ProtocolVersion responseProtocolVersion = httpResponse.getVersion(); + final ApacheResponseHeaderParse responseHeaderParse = new ApacheResponseHeaderParse(); + + response.setProtocolVersion(ProtocolVersion.createInstance(responseProtocolVersion.getProtocol(), + responseProtocolVersion.getMajor(), responseProtocolVersion.getMinor())); + response.setStatusLine( + new StatusLine(httpResponse.getCode(), httpResponse.getReasonPhrase())); + response.setHeaders(responseHeaderParse.parse(httpResponse.getHeaders())); + + if(httpResponse instanceof SimpleHttpResponse){ + SimpleHttpResponse simpleHttpResponse = (SimpleHttpResponse) httpResponse; + + response.setBody(simpleHttpResponse.getBodyText()); + response.setInputStream(new ByteArrayInputStream(simpleHttpResponse.getBodyBytes())); + + try{ + response.setContentLength( + Long.parseLong(simpleHttpResponse.getFirstHeader("Content-Length").getValue())); + }catch(NumberFormatException e){ + response.setContentLength(response.getBody().length()); + } + }else if(httpResponse instanceof ClassicHttpResponse){ + ClassicHttpResponse classicHttpResponse = (ClassicHttpResponse) httpResponse; + org.apache.hc.core5.http.HttpEntity entity = classicHttpResponse.getEntity(); + + if(entity != null){ + response.setContentLength(entity.getContentLength()); + + try{ + HttpEntity httpEntity = new BufferedHttpEntity(entity); + + response.setInputStream(httpEntity.getContent()); + response.setBody(EntityUtils.toString(httpEntity)); + + if(entity.getContent() != null){ + entity.getContent().close(); + } + }catch(ParseException e){ + logger.error("Response entity to body error.", e); + }catch(IOException e){ + logger.error("Response entity to body error.", e); + } + } + } + + if(httpResponse instanceof CloseableHttpResponse){ + try{ + ((CloseableHttpResponse) httpResponse).close(); + }catch(IOException e){ + logger.error("Close HTTP Response error.", e); + } + } + + return response; + } + + /** + * Apache HttpClient 5 响应头解析器 + * + * @author Yong.Teng + * @since 3.0.0 + */ + private static class ApacheResponseHeaderParse extends AbstractResponseHeaderParse { + + @Override + protected void doParse(final Header[] headers, final Multimap headersMap) { + for(Header header : headers){ + headersMap.put(header.getName(), header.getValue()); + } + } + + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheAsyncClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheAsyncClient.java new file mode 100644 index 000000000..65df302f9 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheAsyncClient.java @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache; + +import com.buession.httpclient.core.Header; +import com.buession.httpclient.core.RequestBody; +import com.buession.httpclient.core.concurrent.Callback; +import com.buession.httpclient.exception.RequestException; + +import java.io.IOException; +import java.net.URI; +import java.util.List; +import java.util.Map; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public interface ApacheAsyncClient { + + void get(final URI uri, final Map parameters, final List
headers, final Callback callback) + throws IOException, RequestException; + + void get(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void post(final URI uri, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException; + + void post(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException; + + void patch(final URI uri, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException; + + void patch(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException; + + void put(final URI uri, final Map parameters, final List
headers, final RequestBody body, + final Callback callback) throws IOException, RequestException; + + void put(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException; + + void delete(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void delete(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void connect(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void connect(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void trace(final URI uri, final Map parameters, final List
headers, final Callback callback) + throws IOException, RequestException; + + void trace(final URI uri, final int readTimeout, final Map parameters, final List
headers + , final Callback callback) throws IOException, RequestException; + + void copy(final URI uri, final Map parameters, final List
headers, final Callback callback) + throws IOException, RequestException; + + void copy(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void move(final URI uri, final Map parameters, final List
headers, final Callback callback) + throws IOException, RequestException; + + void move(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void head(final URI uri, final Map parameters, final List
headers, final Callback callback) + throws IOException, RequestException; + + void head(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void options(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void options(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void link(final URI uri, final Map parameters, final List
headers, final Callback callback) + throws IOException, RequestException; + + void link(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void unlink(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void unlink(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void purge(final URI uri, final Map parameters, final List
headers, final Callback callback) + throws IOException, RequestException; + + void purge(final URI uri, final int readTimeout, final Map parameters, final List
headers + , final Callback callback) throws IOException, RequestException; + + void lock(final URI uri, final Map parameters, final List
headers, final Callback callback) + throws IOException, RequestException; + + void lock(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void unlock(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void unlock(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void propfind(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void propfind(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException; + + void proppatch(final URI uri, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException; + + void proppatch(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body, final Callback callback) + throws IOException, RequestException; + + void report(final URI uri, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException; + + void report(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final RequestBody body, final Callback callback) throws IOException, RequestException; + + void view(final URI uri, final Map parameters, final List
headers, final Callback callback) + throws IOException, RequestException; + + void view(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void wrapped(final URI uri, final Map parameters, final List
headers, + final Callback callback) throws IOException, RequestException; + + void wrapped(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final Callback callback) throws IOException, RequestException; + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheClient.java new file mode 100644 index 000000000..5f32c1f56 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheClient.java @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache; + +import com.buession.httpclient.core.Header; +import com.buession.httpclient.core.RequestBody; +import com.buession.httpclient.core.Response; +import com.buession.httpclient.exception.RequestException; + +import java.io.IOException; +import java.net.URI; +import java.util.List; +import java.util.Map; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public interface ApacheClient { + + Response get(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response get(final URI uri, final int readTimeout, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response post(final URI uri, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException; + + Response post(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body) throws IOException, RequestException; + + Response patch(final URI uri, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException; + + Response patch(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body) throws IOException, RequestException; + + Response put(final URI uri, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException; + + Response put(final URI uri, final int readTimeout, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException; + + Response delete(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response delete(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException; + + Response connect(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response connect(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException; + + Response trace(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response trace(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException; + + Response copy(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response copy(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException; + + Response move(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response move(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException; + + Response head(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response head(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException; + + Response options(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response options(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException; + + Response link(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response link(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException; + + Response unlink(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response unlink(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException; + + Response purge(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response purge(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException; + + Response lock(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response lock(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException; + + Response unlock(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response unlock(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException; + + Response propfind(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response propfind(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException; + + Response proppatch(final URI uri, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException; + + Response proppatch(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body) throws IOException, RequestException; + + Response report(final URI uri, final Map parameters, final List
headers, + final RequestBody body) throws IOException, RequestException; + + Response report(final URI uri, final int readTimeout, final Map parameters, + final List
headers, final RequestBody body) throws IOException, RequestException; + + Response view(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response view(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException; + + Response wrapped(final URI uri, final Map parameters, final List
headers) + throws IOException, RequestException; + + Response wrapped(final URI uri, final int readTimeout, final Map parameters, + final List
headers) throws IOException, RequestException; + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheClientConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheClientConnectionManager.java new file mode 100644 index 000000000..fea18c565 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheClientConnectionManager.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache; + +import com.buession.httpclient.conn.ConnectionManager; + +/** + * Apache 连接管理器 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface ApacheClientConnectionManager extends ConnectionManager { + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheHttpAsyncClientBuilder.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheHttpAsyncClientBuilder.java deleted file mode 100644 index 2776e6d85..000000000 --- a/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheHttpAsyncClientBuilder.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. - * See the NOTICE file distributed with this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - * - * ========================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +-------------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | - * +-------------------------------------------------------------------------------------------------------+ - */ -package com.buession.httpclient.apache; - -import com.buession.core.converter.mapper.PropertyMapper; -import com.buession.httpclient.conn.ApacheNioClientConnectionManager; -import com.buession.httpclient.core.AbstractHttpClientBuilder; -import com.buession.net.ssl.SslConfiguration; -import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; -import org.apache.http.impl.nio.client.HttpAsyncClientBuilder; -import org.apache.http.nio.client.HttpAsyncClient; - -import java.util.function.Consumer; - -/** - * Apache Http Async Client Builder - * - * @author Yong.Teng - * @since 2.3.0 - */ -public class ApacheHttpAsyncClientBuilder - extends AbstractHttpClientBuilder { - - public ApacheHttpAsyncClientBuilder(final ApacheNioClientConnectionManager connectionManager){ - super(connectionManager); - } - - @Override - public HttpAsyncClient build(Consumer consumer){ - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - final SslConfiguration sslConfiguration = connectionManager.getConfiguration().getSslConfiguration(); - final HttpAsyncClientBuilder builder = HttpAsyncClientBuilder.create() - .setConnectionManager(connectionManager.getClientConnectionManager()); - - propertyMapper.from(connectionManager.getConnectionManagerShared()).to(builder::setConnectionManagerShared); - - if(sslConfiguration != null){ - propertyMapper.from(sslConfiguration.getHostnameVerifier()).to(builder::setSSLHostnameVerifier); - propertyMapper.from(sslConfiguration.getSslContext()).to(builder::setSSLContext); - } - - if(consumer != null){ - consumer.accept(builder); - } - - final CloseableHttpAsyncClient closeableHttpAsyncClient = builder.build(); - - closeableHttpAsyncClient.start(); - - return builder.build(); - } - -} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheHttpClientBuilder.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheHttpClientBuilder.java deleted file mode 100644 index d5da83122..000000000 --- a/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheHttpClientBuilder.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. - * See the NOTICE file distributed with this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - * - * ========================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +-------------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | - * +-------------------------------------------------------------------------------------------------------+ - */ -package com.buession.httpclient.apache; - -import com.buession.core.converter.mapper.PropertyMapper; -import com.buession.httpclient.conn.ApacheClientConnectionManager; -import com.buession.httpclient.core.AbstractHttpClientBuilder; -import com.buession.net.ssl.SslConfiguration; -import org.apache.http.client.HttpClient; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.impl.client.HttpClientBuilder; - -import java.util.function.Consumer; - -/** - * Apache Http Client Builder - * - * @author Yong.Teng - * @since 2.3.0 - */ -public class ApacheHttpClientBuilder extends AbstractHttpClientBuilder { - - public ApacheHttpClientBuilder(final ApacheClientConnectionManager connectionManager){ - super(connectionManager); - } - - @Override - public HttpClient build(Consumer consumer){ - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - final SslConfiguration sslConfiguration = connectionManager.getConfiguration().getSslConfiguration(); - final HttpClientBuilder builder = HttpClientBuilder.create() - .setConnectionManager(connectionManager.getClientConnectionManager()); - - propertyMapper.from(connectionManager.getConnectionManagerShared()).to(builder::setConnectionManagerShared); - - if(sslConfiguration != null){ - propertyMapper.from(sslConfiguration.getHostnameVerifier()).to(builder::setSSLHostnameVerifier); - propertyMapper.from(sslConfiguration.getSslContext()).to(builder::setSSLContext); - - if(sslConfiguration.getSslSocketFactory() != null){ - builder.setSSLSocketFactory(new SSLConnectionSocketFactory(sslConfiguration.getSslSocketFactory(), - sslConfiguration.getHostnameVerifier())); - } - } - - if(consumer != null){ - consumer.accept(builder); - } - - return builder.build(); - } - -} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheNioClientConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheNioClientConnectionManager.java new file mode 100644 index 000000000..a94401dc2 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheNioClientConnectionManager.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache; + +import com.buession.httpclient.conn.NioConnectionManager; +import com.buession.httpclient.conn.nio.IOReactorConfig; + +/** + * Apache 异步连接管理器 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface ApacheNioClientConnectionManager extends NioConnectionManager { + + /** + * 返回异步 I/O 线程配置 + * + * @return 异步 I/O 线程配置 + */ + IOReactorConfig getIoReactorConfig(); + + /** + * 设置异步 I/O 线程配置 + * + * @param ioReactorConfig + * 异步 I/O 线程配置 + */ + void setIoReactorConfig(IOReactorConfig ioReactorConfig); + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheRequestBuilder.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheRequestBuilder.java deleted file mode 100644 index e1ae86b0d..000000000 --- a/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheRequestBuilder.java +++ /dev/null @@ -1,403 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. - * See the NOTICE file distributed with this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - * - * ========================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +-------------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | - * +-------------------------------------------------------------------------------------------------------+ - */ -package com.buession.httpclient.apache; - -import com.buession.httpclient.apache.convert.ChunkedInputStreamRequestBodyConverter; -import com.buession.httpclient.apache.convert.InputStreamRequestBodyConvert; -import com.buession.httpclient.apache.convert.MultipartFormRequestBodyConverter; -import com.buession.httpclient.apache.convert.RepeatableInputStreamRequestBodyConvert; -import com.buession.httpclient.core.ChunkedInputStreamRequestBody; -import com.buession.httpclient.core.EncodedFormRequestBody; -import com.buession.httpclient.core.Header; -import com.buession.httpclient.core.HtmlRawRequestBody; -import com.buession.httpclient.core.InputStreamRequestBody; -import com.buession.httpclient.core.JavaScriptRawRequestBody; -import com.buession.httpclient.core.JsonRawRequestBody; -import com.buession.httpclient.core.MultipartFormRequestBody; -import com.buession.httpclient.core.ProtocolVersion; -import com.buession.httpclient.core.RepeatableInputStreamRequestBody; -import com.buession.httpclient.core.RequestBody; -import com.buession.httpclient.core.RequestBodyConverter; -import com.buession.httpclient.core.RequestMethod; -import com.buession.httpclient.core.TextRawRequestBody; -import com.buession.httpclient.core.XmlRawRequestBody; -import com.buession.httpclient.core.AbstractRequestBuilder; -import com.buession.httpclient.apache.convert.EncodedFormRequestBodyConverter; -import com.buession.httpclient.apache.convert.HtmlRawRequestBodyConverter; -import com.buession.httpclient.apache.convert.JavaScriptRawRequestBodyConverter; -import com.buession.httpclient.apache.convert.JsonRawRequestBodyConverter; -import com.buession.httpclient.apache.convert.TextRawRequestBodyConverter; -import com.buession.httpclient.apache.convert.XmlRawRequestBodyConverter; -import org.apache.http.HttpEntity; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.methods.*; - -import java.net.URI; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author Yong.Teng - */ -public class ApacheRequestBuilder extends AbstractRequestBuilder { - - private final static HttpEntity DEFAULT_HTTP_ENTITY = new UrlEncodedFormEntity(new ArrayList<>(), - StandardCharsets.ISO_8859_1); - - private final static Map, RequestBodyConverter> REQUEST_BODY_CONVERTS = - new HashMap<>(16, 0.8F); - - static{ - REQUEST_BODY_CONVERTS.put(ChunkedInputStreamRequestBody.class, new ChunkedInputStreamRequestBodyConverter()); - REQUEST_BODY_CONVERTS.put(EncodedFormRequestBody.class, new EncodedFormRequestBodyConverter()); - REQUEST_BODY_CONVERTS.put(HtmlRawRequestBody.class, new HtmlRawRequestBodyConverter()); - REQUEST_BODY_CONVERTS.put(InputStreamRequestBody.class, new InputStreamRequestBodyConvert()); - REQUEST_BODY_CONVERTS.put(JavaScriptRawRequestBody.class, new JavaScriptRawRequestBodyConverter()); - REQUEST_BODY_CONVERTS.put(JsonRawRequestBody.class, new JsonRawRequestBodyConverter()); - REQUEST_BODY_CONVERTS.put(MultipartFormRequestBody.class, new MultipartFormRequestBodyConverter()); - REQUEST_BODY_CONVERTS.put(RepeatableInputStreamRequestBody.class, - new RepeatableInputStreamRequestBodyConvert()); - REQUEST_BODY_CONVERTS.put(TextRawRequestBody.class, new TextRawRequestBodyConverter()); - REQUEST_BODY_CONVERTS.put(XmlRawRequestBody.class, new XmlRawRequestBodyConverter()); - } - - private ApacheRequestBuilder(){ - request = new ApacheRequest(); - } - - /** - * 创建 {@link ApacheRequestBuilder} 实例 - * - * @return {@link ApacheRequestBuilder} 实例 - */ - public static ApacheRequestBuilder create(){ - return new ApacheRequestBuilder(); - } - - /** - * 创建 {@link ApacheRequestBuilder} 实例 - * - * @param url - * 请求 URL - * - * @return {@link ApacheRequestBuilder} 实例 - */ - @Deprecated - public static ApacheRequestBuilder create(String url){ - final ApacheRequestBuilder builder = create(); - builder.setUrl(url); - return builder; - } - - /** - * 创建 {@link ApacheRequestBuilder} 实例 - * - * @param url - * 请求 URL - * @param parameters - * 请求参数 - * - * @return {@link ApacheRequestBuilder} 实例 - */ - @Deprecated - public static ApacheRequestBuilder create(String url, Map parameters){ - return create(url).setParameters(parameters); - } - - /** - * 创建 {@link ApacheRequestBuilder} 实例 - * - * @param url - * 请求 URL - * @param headers - * 请求头 - * - * @return {@link ApacheRequestBuilder} 实例 - */ - @Deprecated - public static ApacheRequestBuilder create(String url, List
headers){ - return create(url).setHeaders(headers); - } - - /** - * 创建 {@link ApacheRequestBuilder} 实例 - * - * @param url - * 请求 URL - * @param parameters - * 请求参数 - * @param headers - * 请求头 - * - * @return {@link ApacheRequestBuilder} 实例 - */ - @Deprecated - public static ApacheRequestBuilder create(String url, Map parameters, List
headers){ - return create(url, parameters).setHeaders(headers); - } - - /** - * 创建 {@link ApacheRequestBuilder} 实例 - * - * @param uri - * 请求 URL - * - * @return {@link ApacheRequestBuilder} 实例 - * - * @since 2.3.0 - */ - public static ApacheRequestBuilder create(URI uri){ - final ApacheRequestBuilder builder = create(); - builder.setUri(uri); - return builder; - } - - /** - * 创建 {@link ApacheRequestBuilder} 实例 - * - * @param uri - * 请求 URL - * @param parameters - * 请求参数 - * - * @return {@link ApacheRequestBuilder} 实例 - * - * @since 2.3.0 - */ - public static ApacheRequestBuilder create(URI uri, Map parameters){ - return create(uri).setParameters(parameters); - } - - /** - * 创建 {@link ApacheRequestBuilder} 实例 - * - * @param uri - * 请求 URL - * @param headers - * 请求头 - * - * @return {@link ApacheRequestBuilder} 实例 - * - * @since 2.3.0 - */ - public static ApacheRequestBuilder create(URI uri, List
headers){ - return create(uri).setHeaders(headers); - } - - /** - * 创建 {@link ApacheRequestBuilder} 实例 - * - * @param uri - * 请求 URL - * @param parameters - * 请求参数 - * @param headers - * 请求头 - * - * @return {@link ApacheRequestBuilder} 实例 - * - * @since 2.3.0 - */ - public static ApacheRequestBuilder create(URI uri, Map parameters, List
headers){ - return create(uri, parameters).setHeaders(headers); - } - - @Override - public ApacheRequestBuilder setProtocolVersion(ProtocolVersion protocolVersion){ - if(protocolVersion != null){ - request.getHttpRequest().setProtocolVersion( - new org.apache.http.ProtocolVersion(protocolVersion.getProtocol(), protocolVersion.getMajor(), - protocolVersion.getMinor())); - } - - return this; - } - - @Override - public ApacheRequestBuilder setHeaders(List
headers){ - request.setHeaders(headers); - return this; - } - - @Override - public ApacheRequestBuilder setParameters(Map parameters){ - this.parameters = parameters; - return this; - } - - public ApacheRequestBuilder setRequestConfig(RequestConfig config){ - this.request.getHttpRequest().setConfig(config); - return this; - } - - @Override - public ApacheRequestBuilder get(){ - return setRequest(new HttpGet(), RequestMethod.GET); - } - - @Override - public ApacheRequestBuilder post(RequestBody body){ - return setRequest(new HttpPost(), RequestMethod.POST, body); - } - - @Override - public ApacheRequestBuilder patch(RequestBody body){ - return setRequest(new HttpPatch(), RequestMethod.PATCH, body); - } - - @Override - public ApacheRequestBuilder put(RequestBody body){ - return setRequest(new HttpPut(), RequestMethod.PUT, body); - } - - @Override - public ApacheRequestBuilder delete(){ - return setRequest(new HttpDelete(), RequestMethod.DELETE); - } - - @Override - public ApacheRequestBuilder connect(){ - return setRequest(new HttpConnect(), RequestMethod.CONNECT); - } - - @Override - public ApacheRequestBuilder trace(){ - return setRequest(new HttpTrace(), RequestMethod.TRACE); - } - - @Override - public ApacheRequestBuilder copy(){ - return setRequest(new HttpCopy(), RequestMethod.COPY); - } - - @Override - public ApacheRequestBuilder move(){ - return setRequest(new HttpMove(), RequestMethod.MOVE); - } - - @Override - public ApacheRequestBuilder head(){ - return setRequest(new HttpHead(), RequestMethod.HEAD); - } - - @Override - public ApacheRequestBuilder options(){ - return setRequest(new HttpOptions(), RequestMethod.OPTIONS); - } - - @Override - public ApacheRequestBuilder link(){ - return setRequest(new HttpLink(), RequestMethod.LINK); - } - - @Override - public ApacheRequestBuilder unlink(){ - return setRequest(new HttpUnlink(), RequestMethod.UNLINK); - } - - @Override - public ApacheRequestBuilder purge(){ - return setRequest(new HttpPurge(), RequestMethod.PURGE); - } - - @Override - public ApacheRequestBuilder lock(){ - return setRequest(new HttpLock(), RequestMethod.LOCK); - } - - @Override - public ApacheRequestBuilder unlock(){ - return setRequest(new HttpUnlock(), RequestMethod.UNLOCK); - } - - @Override - public ApacheRequestBuilder propfind(){ - return setRequest(new HttpPropfind(), RequestMethod.PROPFIND); - } - - @Override - public ApacheRequestBuilder proppatch(RequestBody body){ - return setRequest(new HttpPropPatch(), RequestMethod.PROPPATCH, body); - } - - @Override - public ApacheRequestBuilder report(RequestBody body){ - return setRequest(new HttpReport(), RequestMethod.REPORT, body); - } - - @Override - public ApacheRequestBuilder view(){ - return setRequest(new HttpView(), RequestMethod.VIEW); - } - - @Override - public ApacheRequestBuilder wrapped(){ - return setRequest(new HttpWrapped(), RequestMethod.WRAPPED); - } - - @Override - public ApacheRequest build(){ - ApacheRequest request = super.build(); - - if(request.getHeaders() != null){ - for(Header header : request.getHeaders()){ - request.getHttpRequest().setHeader(header.getName(), header.getValue()); - } - } - - request.getHttpRequest().setURI(request.getUri()); - - return request; - } - - protected ApacheRequestBuilder setRequest(final HttpRequestBase httpRequest, final RequestMethod method){ - request.setHttpRequest(httpRequest); - request.setMethod(method); - return this; - } - - protected ApacheRequestBuilder setRequest(final HttpEntityEnclosingRequestBase httpRequest, - final RequestMethod method, final RequestBody body){ - setRequest(httpRequest, method); - - if(body != null){ - final RequestBodyConverter, HttpEntity> converter = findBodyConverter(REQUEST_BODY_CONVERTS, - body); - httpRequest.setEntity(converter == null ? DEFAULT_HTTP_ENTITY : converter.convert(body)); - } - - return this; - } - - @Deprecated - public final static class HttpComponentsRequest extends ApacheRequest { - - } - -} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/BaseApacheClient.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/BaseApacheClient.java new file mode 100644 index 000000000..000dea5d7 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/BaseApacheClient.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache; + +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.utils.StringUtils; +import com.buession.core.validator.Validate; +import com.buession.httpclient.core.RequestBody; +import com.buession.httpclient.core.RequestBodyConverter; +import com.buession.httpclient.core.utils.UriUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Map; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +abstract class BaseApacheClient { + + protected final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + protected URI determineRequestUri(final URI uri, final Map parameters) { + if(Validate.isEmpty(parameters)){ + return uri; + } + + final StringBuilder newQuery = new StringBuilder(); + + if(uri.getRawQuery() != null){ + newQuery.append(uri.getRawQuery()); + + if(StringUtils.endsWith(uri.getRawQuery(), '&') == false){ + newQuery.append('&'); + } + } + + newQuery.append(UriUtils.buildQuery(parameters, false)); + + try{ + return new URI(uri.getScheme(), uri.getAuthority(), uri.getHost(), uri.getPort(), uri.getPath(), + newQuery.toString(), uri.getFragment()); + }catch(URISyntaxException e){ + if(logger.isErrorEnabled()){ + logger.error("URL {} add parameters syntax: {}, reason: {}", uri, e.getMessage(), e.getReason()); + } + return uri; + } + } + + @SuppressWarnings({"unchecked"}) + protected static RequestBodyConverter findBodyConverter(final Map, + RequestBodyConverter> converters, final RequestBody body) { + RequestBodyConverter converter; + Class clazz = body.getClass(); + + while(clazz != null){ + converter = converters.get(clazz); + if(converter != null){ + return converter; + } + + clazz = clazz.getSuperclass(); + } + + return null; + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/Apache5RequestBodyConverter.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/Apache5RequestBodyConverter.java new file mode 100644 index 000000000..612d77634 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/Apache5RequestBodyConverter.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache.convert.h5; + +import com.buession.httpclient.core.RequestBodyConverter; +import org.apache.hc.core5.http.HttpEntity; + +/** + * @author Yong.Teng + */ +@FunctionalInterface +public interface Apache5RequestBodyConverter extends RequestBodyConverter { + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/BaseRawRequestBodyConverter.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/BaseRawRequestBodyConverter.java new file mode 100644 index 000000000..f09eb25ee --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/BaseRawRequestBodyConverter.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache.convert.h5; + +import com.buession.httpclient.core.AbstractRawRequestBody; +import org.apache.hc.core5.http.io.entity.StringEntity; + +/** + * 原始请求体转换器基类 + * + * @param + * 请求体 + * + * @author Yong.Teng + * @since 1.2.1 + */ +public abstract class BaseRawRequestBodyConverter> + implements Apache5RequestBodyConverter { + + @Override + public StringEntity convert(final S source) { + if(source == null || source.getContent() == null){ + return null; + } + + final org.apache.hc.core5.http.ContentType contentType = org.apache.hc.core5.http.ContentType.create( + source.getContentType().getMimeType(), source.getContentType().getCharset()); + return new StringEntity(source.getContent(), contentType); + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/ChunkedInputStreamRequestBodyConverter.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/ChunkedInputStreamRequestBodyConverter.java new file mode 100644 index 000000000..ab4284fc7 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/ChunkedInputStreamRequestBodyConverter.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache.convert.h5; + +import com.buession.httpclient.core.ChunkedInputStreamRequestBody; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.io.entity.ChunkedInputStreamEntity; +import org.apache.hc.core5.http.io.entity.InputStreamEntity; + +/** + * @author Yong.Teng + * @since 1.2.0 + */ +public class ChunkedInputStreamRequestBodyConverter + implements Apache5RequestBodyConverter { + + @Override + public HttpEntity convert(final ChunkedInputStreamRequestBody source) { + if(source == null || source.getContent() == null){ + return null; + } + + return new ChunkedInputStreamEntity(source.getContent(), source.getContentLength(), + ContentType.create(source.getContentType().getMimeType(), source.getContentType().getCharset())); + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/EncodedFormRequestBodyConverter.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/EncodedFormRequestBodyConverter.java new file mode 100644 index 000000000..4d41bb0d5 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/EncodedFormRequestBodyConverter.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache.convert.h5; + +import com.buession.httpclient.core.EncodedFormRequestBody; +import org.apache.hc.client5.http.entity.UrlEncodedFormEntity; +import org.apache.hc.core5.http.NameValuePair; +import org.apache.hc.core5.http.message.BasicNameValuePair; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * @author Yong.Teng + */ +public class EncodedFormRequestBodyConverter implements Apache5RequestBodyConverter { + + @Override + public UrlEncodedFormEntity convert(final EncodedFormRequestBody source) { + if(source == null || source.getContent() == null){ + return null; + } + + List data = source.getContent().stream() + .map((element)->new BasicNameValuePair(element.getName(), element.getValue())) + .collect(Collectors.toList()); + + return new UrlEncodedFormEntity(data, source.getContentType().getCharset()); + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/HtmlRawRequestBodyConverter.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/HtmlRawRequestBodyConverter.java new file mode 100644 index 000000000..7e7286b5f --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/HtmlRawRequestBodyConverter.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache.convert.h5; + +import com.buession.httpclient.core.HtmlRawRequestBody; + +/** + * @author Yong.Teng + */ +public class HtmlRawRequestBodyConverter extends BaseRawRequestBodyConverter { + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/InputStreamRequestBodyConvert.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/InputStreamRequestBodyConvert.java new file mode 100644 index 000000000..482523252 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/InputStreamRequestBodyConvert.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache.convert.h5; + +import com.buession.httpclient.core.InputStreamRequestBody; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.io.entity.InputStreamEntity; + +/** + * @author Yong.Teng + * @since 1.2.0 + */ +public class InputStreamRequestBodyConvert implements Apache5RequestBodyConverter { + + @Override + public HttpEntity convert(final InputStreamRequestBody source) { + if(source == null || source.getContent() == null){ + return null; + } + + return new InputStreamEntity(source.getContent(), source.getContentLength(), + ContentType.create(source.getContentType().getMimeType(), source.getContentType().getCharset())); + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/JavaScriptRawRequestBodyConverter.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/JavaScriptRawRequestBodyConverter.java new file mode 100644 index 000000000..42aae3bbe --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/JavaScriptRawRequestBodyConverter.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache.convert.h5; + +import com.buession.httpclient.core.JavaScriptRawRequestBody; + +/** + * @author Yong.Teng + */ +public class JavaScriptRawRequestBodyConverter extends BaseRawRequestBodyConverter { + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/JsonRawRequestBodyConverter.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/JsonRawRequestBodyConverter.java new file mode 100644 index 000000000..044887e14 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/JsonRawRequestBodyConverter.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache.convert.h5; + +import com.buession.httpclient.core.JsonRawRequestBody; +import com.buession.httpclient.core.RequestBodyConverters; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.io.entity.StringEntity; + +/** + * @author Yong.Teng + */ +public class JsonRawRequestBodyConverter implements Apache5RequestBodyConverter> { + + @Override + public StringEntity convert(final JsonRawRequestBody source) { + RequestBodyConverters.JsonRawRequestBodyConverter jsonRawRequestBodyConverter = new RequestBodyConverters.JsonRawRequestBodyConverter<>( + (str)->new StringEntity(str, ContentType.create(source.getContentType().getMimeType(), + source.getContentType().getCharset()))); + return jsonRawRequestBodyConverter.convert(source); + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/MultipartFormRequestBodyConverter.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/MultipartFormRequestBodyConverter.java new file mode 100644 index 000000000..67d630657 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/MultipartFormRequestBodyConverter.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache.convert.h5; + +import com.buession.httpclient.core.MultipartFormRequestBody; +import com.buession.httpclient.core.MultipartRequestBodyElement; +import com.buession.io.MimeType; +import com.buession.io.file.File; +import org.apache.hc.client5.http.entity.mime.HttpMultipartMode; +import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpEntity; + +import java.nio.charset.Charset; + +/** + * @author Yong.Teng + */ +public class MultipartFormRequestBodyConverter implements Apache5RequestBodyConverter { + + @Override + public HttpEntity convert(final MultipartFormRequestBody source) { + if(source == null || source.getContent() == null){ + return null; + } + + final MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + + builder.setContentType(ContentType.MULTIPART_FORM_DATA); + builder.setCharset(source.getContentType().getCharset()); + builder.setMode(HttpMultipartMode.LEGACY); + + for(MultipartRequestBodyElement element : source.getContent()){ + addBody(source, builder, element); + } + + return builder.build(); + } + + private static void addBody(final MultipartFormRequestBody requestBody, final MultipartEntityBuilder builder, + final MultipartRequestBodyElement element) { + if(element.getFile() != null){ + File file = new File(element.getFile()); + ContentType contentType = parseMultipartElementMimeType(file, + requestBody.getContentType().getCharset()); + + builder.addBinaryBody(element.getName(), element.getFile(), contentType, file.getName()); + }else if(element.getInputStream() != null){ + builder.addBinaryBody(element.getName(), element.getInputStream(), ContentType.DEFAULT_BINARY, + element.getFileName()); + }else{ + builder.addTextBody(element.getName(), element.getValue()); + } + } + + private static ContentType parseMultipartElementMimeType(final File file, final Charset charset) { + MimeType mimeType = file.getMimeType(); + + return mimeType == null ? ContentType.DEFAULT_BINARY : ContentType.create(mimeType.toString(), + charset); + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/RepeatableInputStreamRequestBodyConvert.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/RepeatableInputStreamRequestBodyConvert.java new file mode 100644 index 000000000..a7259505d --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/RepeatableInputStreamRequestBodyConvert.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache.convert.h5; + +import com.buession.httpclient.core.RepeatableInputStreamRequestBody; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.io.entity.ReleasableInputStreamEntity; + +/** + * @author Yong.Teng + * @since 1.2.0 + */ +public class RepeatableInputStreamRequestBodyConvert + implements Apache5RequestBodyConverter { + + @Override + public HttpEntity convert(final RepeatableInputStreamRequestBody source) { + if(source == null || source.getContent() == null){ + return null; + } + + return new ReleasableInputStreamEntity(source.getContent(), source.getContentLength(), + ContentType.create(source.getContentType().getMimeType(), source.getContentType().getCharset())); + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/TextRawRequestBodyConverter.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/TextRawRequestBodyConverter.java new file mode 100644 index 000000000..d5c03b5f7 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/TextRawRequestBodyConverter.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache.convert.h5; + +import com.buession.httpclient.core.TextRawRequestBody; + +/** + * @author Yong.Teng + */ +public class TextRawRequestBodyConverter extends BaseRawRequestBodyConverter { + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/XmlRawRequestBodyConverter.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/XmlRawRequestBodyConverter.java new file mode 100644 index 000000000..ed29491d0 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/XmlRawRequestBodyConverter.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache.convert.h5; + +import com.buession.httpclient.core.XmlRawRequestBody; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.io.entity.StringEntity; + +/** + * @author Yong.Teng + */ +public class XmlRawRequestBodyConverter implements Apache5RequestBodyConverter { + + @Override + public StringEntity convert(final XmlRawRequestBody source) { + if(source == null || source.getContent() == null){ + return null; + } + + return new StringEntity(source.getContent().asXML(), + ContentType.create(source.getContentType().getMimeType(), source.getContentType().getCharset())); + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/package-info.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/package-info.java new file mode 100644 index 000000000..6580aa896 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/h5/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.httpclient.apache.convert.h5; \ No newline at end of file diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/package-info.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/package-info.java index c87ea8043..57a824b1b 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/package-info.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/package-info.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ /** diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/utils/ApacheRequestBodyConverterUtils.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/utils/ApacheRequestBodyConverterUtils.java new file mode 100644 index 000000000..f5ece4540 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/utils/ApacheRequestBodyConverterUtils.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache.convert.utils; + +import com.buession.httpclient.core.ChunkedInputStreamRequestBody; +import com.buession.httpclient.core.EncodedFormRequestBody; +import com.buession.httpclient.core.HtmlRawRequestBody; +import com.buession.httpclient.core.InputStreamRequestBody; +import com.buession.httpclient.core.JavaScriptRawRequestBody; +import com.buession.httpclient.core.JsonRawRequestBody; +import com.buession.httpclient.core.MultipartFormRequestBody; +import com.buession.httpclient.core.RepeatableInputStreamRequestBody; +import com.buession.httpclient.core.RequestBody; +import com.buession.httpclient.core.RequestBodyConverter; +import com.buession.httpclient.core.TextRawRequestBody; +import com.buession.httpclient.core.XmlRawRequestBody; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class ApacheRequestBodyConverterUtils { + + private ApacheRequestBodyConverterUtils() { + + } + + public static Map, RequestBodyConverter> createApache4ClientRequestBodyConverter() { + final Map, RequestBodyConverter> result = new HashMap<>(10); + + result.put(ChunkedInputStreamRequestBody.class, + new com.buession.httpclient.apache.convert.ChunkedInputStreamRequestBodyConverter()); + result.put(EncodedFormRequestBody.class, + new com.buession.httpclient.apache.convert.EncodedFormRequestBodyConverter()); + result.put(HtmlRawRequestBody.class, new com.buession.httpclient.apache.convert.HtmlRawRequestBodyConverter()); + result.put(InputStreamRequestBody.class, + new com.buession.httpclient.apache.convert.InputStreamRequestBodyConvert()); + result.put(JavaScriptRawRequestBody.class, + new com.buession.httpclient.apache.convert.JavaScriptRawRequestBodyConverter()); + result.put(JsonRawRequestBody.class, new com.buession.httpclient.apache.convert.JsonRawRequestBodyConverter()); + result.put(MultipartFormRequestBody.class, + new com.buession.httpclient.apache.convert.MultipartFormRequestBodyConverter()); + result.put(RepeatableInputStreamRequestBody.class, + new com.buession.httpclient.apache.convert.RepeatableInputStreamRequestBodyConvert()); + result.put(TextRawRequestBody.class, new com.buession.httpclient.apache.convert.TextRawRequestBodyConverter()); + result.put(XmlRawRequestBody.class, new com.buession.httpclient.apache.convert.XmlRawRequestBodyConverter()); + + return result; + } + + public static Map, RequestBodyConverter> createApache5ClientRequestBodyConverter() { + final Map, RequestBodyConverter> result = new HashMap<>(10); + + result.put(ChunkedInputStreamRequestBody.class, + new com.buession.httpclient.apache.convert.h5.ChunkedInputStreamRequestBodyConverter()); + result.put(EncodedFormRequestBody.class, + new com.buession.httpclient.apache.convert.h5.EncodedFormRequestBodyConverter()); + result.put(HtmlRawRequestBody.class, + new com.buession.httpclient.apache.convert.h5.HtmlRawRequestBodyConverter()); + result.put(InputStreamRequestBody.class, + new com.buession.httpclient.apache.convert.h5.InputStreamRequestBodyConvert()); + result.put(JavaScriptRawRequestBody.class, + new com.buession.httpclient.apache.convert.h5.JavaScriptRawRequestBodyConverter()); + result.put(JsonRawRequestBody.class, + new com.buession.httpclient.apache.convert.h5.JsonRawRequestBodyConverter()); + result.put(MultipartFormRequestBody.class, + new com.buession.httpclient.apache.convert.h5.MultipartFormRequestBodyConverter()); + result.put(RepeatableInputStreamRequestBody.class, + new com.buession.httpclient.apache.convert.h5.RepeatableInputStreamRequestBodyConvert()); + result.put(TextRawRequestBody.class, + new com.buession.httpclient.apache.convert.h5.TextRawRequestBodyConverter()); + result.put(XmlRawRequestBody.class, + new com.buession.httpclient.apache.convert.h5.XmlRawRequestBodyConverter()); + + return result; + + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/utils/package-info.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/utils/package-info.java new file mode 100644 index 000000000..e882a236a --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/convert/utils/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.httpclient.apache.convert.utils; \ No newline at end of file diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/nio/Default5Callback.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/nio/Default5Callback.java new file mode 100644 index 000000000..d118ccbf4 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/nio/Default5Callback.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.apache.nio; + +import com.buession.httpclient.core.Response; +import com.buession.httpclient.core.concurrent.BaseCallback; +import com.buession.httpclient.core.concurrent.Callback; +import org.apache.hc.core5.concurrent.FutureCallback; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class Default5Callback extends BaseCallback implements FutureCallback { + + public Default5Callback(final Callback delegate) { + super(delegate); + } + + @Override + public void completed(Response response) { + delegate.completed(response); + } + + @Override + public void failed(Exception ex) { + delegate.failed(ex); + } + + @Override + public void cancelled() { + delegate.cancelled(); + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/nio/DefaultCallback.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/nio/DefaultCallback.java index 2776675ad..7b5c57818 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/apache/nio/DefaultCallback.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/nio/DefaultCallback.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.apache.nio; @@ -27,12 +27,13 @@ import com.buession.httpclient.core.Response; import com.buession.httpclient.core.concurrent.BaseCallback; import com.buession.httpclient.core.concurrent.Callback; +import org.apache.http.concurrent.FutureCallback; /** * @author Yong.Teng * @since 2.3.0 */ -public class DefaultCallback extends BaseCallback implements org.apache.http.concurrent.FutureCallback { +public class DefaultCallback extends BaseCallback implements FutureCallback { public DefaultCallback(final Callback delegate){ super(delegate); diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/nio/protocol/BasicAsyncResponseConsumer.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/nio/protocol/BasicAsyncResponseConsumer.java deleted file mode 100644 index 820054928..000000000 --- a/buession-httpclient/src/main/java/com/buession/httpclient/apache/nio/protocol/BasicAsyncResponseConsumer.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. - * See the NOTICE file distributed with this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - * - * ========================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +-------------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | - * +-------------------------------------------------------------------------------------------------------+ - */ -package com.buession.httpclient.apache.nio.protocol; - -import com.buession.httpclient.apache.ApacheResponseBuilder; -import com.buession.httpclient.core.Response; -import org.apache.http.ContentTooLongException; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpRequestBase; -import org.apache.http.entity.ContentType; -import org.apache.http.nio.ContentDecoder; -import org.apache.http.nio.IOControl; -import org.apache.http.nio.entity.ContentBufferEntity; -import org.apache.http.nio.protocol.AbstractAsyncResponseConsumer; -import org.apache.http.nio.util.HeapByteBufferAllocator; -import org.apache.http.nio.util.SimpleInputBuffer; -import org.apache.http.protocol.HttpContext; -import org.apache.http.util.Asserts; - -import java.io.IOException; - -/** - * @author Yong.Teng - * @since 2.3.0 - */ -public class BasicAsyncResponseConsumer extends AbstractAsyncResponseConsumer { - - private final static int MAX_INITIAL_BUFFER_SIZE = 262144; - - private volatile HttpRequestBase request; - - private volatile HttpResponse response; - - private volatile SimpleInputBuffer buffer; - - public BasicAsyncResponseConsumer(HttpRequestBase request){ - this.request = request; - } - - @Override - protected void onResponseReceived(HttpResponse response) throws IOException{ - this.response = response; - } - - @Override - protected void onEntityEnclosed(HttpEntity entity, ContentType contentType) throws IOException{ - long contentLength = entity.getContentLength(); - - if(contentLength > 2147483647L){ - throw new ContentTooLongException("Entity content is too long: %,d", new Object[]{contentLength}); - }else{ - if(contentLength < 0L){ - contentLength = 4096L; - } - - int initialBufferSize = Math.min((int) contentLength, MAX_INITIAL_BUFFER_SIZE); - buffer = new SimpleInputBuffer(initialBufferSize, new HeapByteBufferAllocator()); - response.setEntity(new ContentBufferEntity(entity, buffer)); - } - } - - @Override - protected void onContentReceived(ContentDecoder decoder, IOControl ioControl) throws IOException{ - Asserts.notNull(buffer, "Content buffer"); - buffer.consumeContent(decoder); - } - - @Override - protected void releaseResources(){ - if(request != null){ - request.releaseConnection(); - } - response = null; - buffer = null; - } - - @Override - protected Response buildResult(HttpContext context){ - final ApacheResponseBuilder apacheResponseBuilder = new ApacheResponseBuilder(); - return apacheResponseBuilder.build(this.response); - } - -} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/package-info.java b/buession-httpclient/src/main/java/com/buession/httpclient/apache/package-info.java index 0eb0b1561..5875eb40c 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/apache/package-info.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/apache/package-info.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ /** diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/conn/AbstractConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/conn/AbstractConnectionManager.java index 4491b0e3d..aba8b2a4f 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/conn/AbstractConnectionManager.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/conn/AbstractConnectionManager.java @@ -19,13 +19,16 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.conn; +import com.buession.core.converter.mapper.PropertyMapper; import com.buession.httpclient.core.Configuration; +import java.util.Optional; + /** * 连接管理器抽象类 * @@ -36,12 +39,20 @@ */ public abstract class AbstractConnectionManager implements ConnectionManager { + protected final static PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); + + /** + * 配置 + */ private Configuration configuration = new Configuration(); + /** + * 原生连接管理器 + */ private CM clientConnectionManager; /** - * @since 2.3.0 + * @since 3.0.0 */ private Boolean connectionManagerShared; @@ -49,25 +60,23 @@ public abstract class AbstractConnectionManager implements ConnectionManager * 构造函数,创建驱动默认连接管理器 */ public AbstractConnectionManager() { - clientConnectionManager = createDefaultClientConnectionManager(); } /** * 构造函数,创建驱动默认连接管理器 * * @param configuration - * 连接对象 + * 配置 */ public AbstractConnectionManager(Configuration configuration) { this.configuration = configuration; - clientConnectionManager = createDefaultClientConnectionManager(); } /** * 构造函数 * * @param clientConnectionManager - * 驱动连接管理器 + * 原生连接管理器 */ public AbstractConnectionManager(CM clientConnectionManager) { this.clientConnectionManager = clientConnectionManager; @@ -77,9 +86,9 @@ public AbstractConnectionManager(CM clientConnectionManager) { * 构造函数 * * @param configuration - * 连接对象 + * 配置 * @param clientConnectionManager - * 驱动连接管理器 + * 原生连接管理器 */ public AbstractConnectionManager(Configuration configuration, CM clientConnectionManager) { this.configuration = configuration; @@ -87,9 +96,9 @@ public AbstractConnectionManager(Configuration configuration, CM clientConnectio } /** - * 获取连接对象 + * 获取配置 * - * @return 连接对象 + * @return 配置 */ @Override public Configuration getConfiguration() { @@ -97,10 +106,10 @@ public Configuration getConfiguration() { } /** - * 设置连接对象 + * 设置配置 * * @param configuration - * 连接对象 + * 配置 */ @Override public void setConfiguration(Configuration configuration) { @@ -108,19 +117,23 @@ public void setConfiguration(Configuration configuration) { } /** - * 获取驱动连接管理器 + * 获取原生连接管理器 * - * @return 连接管理器 + * @return 原生连接管理器 */ public CM getClientConnectionManager() { + if(clientConnectionManager == null){ + clientConnectionManager = createDefaultClientConnectionManager(); + } + return clientConnectionManager; } /** - * 设置连接管理器 + * 设置原生连接管理器 * * @param clientConnectionManager - * 连接管理器 + * 原生连接管理器 */ public void setClientConnectionManager(CM clientConnectionManager) { this.clientConnectionManager = clientConnectionManager; @@ -131,10 +144,10 @@ public void setClientConnectionManager(CM clientConnectionManager) { * * @return True / False * - * @since 2.3.0 + * @since 3.0.0 */ public Boolean getConnectionManagerShared() { - return connectionManagerShared; + return Optional.ofNullable(connectionManagerShared).orElse(getConfiguration().getConnectionManagerShared()); } /** @@ -143,7 +156,7 @@ public Boolean getConnectionManagerShared() { * @param connectionManagerShared * 链接管理器是否共享 * - * @since 2.3.0 + * @since 3.0.0 */ public void setConnectionManagerShared(Boolean connectionManagerShared) { this.connectionManagerShared = connectionManagerShared; diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/conn/Apache5ClientConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/conn/Apache5ClientConnectionManager.java new file mode 100644 index 000000000..7331ea66d --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/conn/Apache5ClientConnectionManager.java @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.conn; + +import com.buession.httpclient.core.Configuration; +import org.apache.hc.client5.http.config.ConnectionConfig; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; +import org.apache.hc.client5.http.io.HttpClientConnectionManager; +import org.apache.hc.client5.http.socket.ConnectionSocketFactory; +import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory; +import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; +import org.apache.hc.core5.http.URIScheme; +import org.apache.hc.core5.http.config.Registry; +import org.apache.hc.core5.http.config.RegistryBuilder; +import org.apache.hc.core5.pool.PoolConcurrencyPolicy; +import org.apache.hc.core5.util.Timeout; + +/** + * Apache HttpComponents Client 5 连接管理器 + * + * @author Yong.Teng + */ +public class Apache5ClientConnectionManager extends ApacheBaseClientConnectionManager + implements com.buession.httpclient.apache.ApacheClientConnectionManager { + + /** + * 构造函数,创建驱动默认连接管理器 + */ + public Apache5ClientConnectionManager() { + super(); + } + + /** + * 构造函数,创建驱动默认连接管理器 + * + * @param configuration + * 配置 + */ + public Apache5ClientConnectionManager(Configuration configuration) { + super(configuration); + } + + /** + * 构造函数 + * + * @param clientConnectionManager + * 原生连接管理器 + */ + public Apache5ClientConnectionManager(HttpClientConnectionManager clientConnectionManager) { + super(clientConnectionManager); + } + + /** + * 构造函数 + * + * @param configuration + * 配置 + * @param clientConnectionManager + * 原生连接管理器 + */ + public Apache5ClientConnectionManager(Configuration configuration, + HttpClientConnectionManager clientConnectionManager) { + super(configuration, clientConnectionManager); + } + + /** + * 创建驱动默认连接管理器 + * + * @return 连接管理器 + */ + @Override + protected HttpClientConnectionManager createDefaultClientConnectionManager() { + final PoolingHttpClientConnectionManager connectionManager = + getConfiguration().getConnectionTimeToLive() != null ? new PoolingHttpClientConnectionManager( + getDefaultRegistry(), PoolConcurrencyPolicy.STRICT, + Timeout.ofMilliseconds(getConfiguration().getConnectionTimeToLive()), + null) : new PoolingHttpClientConnectionManager(getDefaultRegistry()); + + // 最大连接数 + propertyMapper.from(getConfiguration().getMaxConnections()).to(connectionManager::setMaxTotal); + // 每个路由的最大连接数 + propertyMapper.from(getConfiguration().getMaxPerRoute()).to(connectionManager::setDefaultMaxPerRoute); + // 连接池中最大连接数 + propertyMapper.from(getConfiguration().getMaxRequests()).to(connectionManager::setMaxTotal); + // 空闲连接存活时长 + propertyMapper.from(getConfiguration().getIdleConnectionTime()).as(Timeout::ofMilliseconds) + .to(connectionManager::closeIdle); + + connectionManager.setDefaultConnectionConfig(createDefaultConnectionConfig()); + + return connectionManager; + } + + protected ConnectionConfig createDefaultConnectionConfig() { + final ConnectionConfig.Builder connectionConfigBuilder = ConnectionConfig.custom(); + + propertyMapper.from(getConfiguration().getConnectTimeout()).as(Timeout::ofMilliseconds) + .to(connectionConfigBuilder::setConnectTimeout); + propertyMapper.from(getConfiguration().getReadTimeout()).as(Timeout::ofMilliseconds) + .to(connectionConfigBuilder::setSocketTimeout); + propertyMapper.from(getConfiguration().getConnectionTimeToLive()).as(Timeout::ofMilliseconds) + .to(connectionConfigBuilder::setTimeToLive); + + return connectionConfigBuilder.build(); + } + + private static Registry getDefaultRegistry() { + return RegistryBuilder.create() + .register(URIScheme.HTTP.id, PlainConnectionSocketFactory.getSocketFactory()) + .register(URIScheme.HTTPS.id, SSLConnectionSocketFactory.getSocketFactory()) + .build(); + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/conn/Apache5NioClientConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/conn/Apache5NioClientConnectionManager.java new file mode 100644 index 000000000..0be295e6f --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/conn/Apache5NioClientConnectionManager.java @@ -0,0 +1,350 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.conn; + +import com.buession.httpclient.conn.nio.IOReactorConfig; +import com.buession.httpclient.core.Configuration; +import org.apache.hc.client5.http.config.ConnectionConfig; +import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager; +import org.apache.hc.client5.http.nio.AsyncClientConnectionManager; +import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy; +import org.apache.hc.core5.http.URIScheme; +import org.apache.hc.core5.http.config.Lookup; +import org.apache.hc.core5.http.config.RegistryBuilder; +import org.apache.hc.core5.http.nio.ssl.TlsStrategy; +import org.apache.hc.core5.pool.PoolConcurrencyPolicy; +import org.apache.hc.core5.util.Timeout; + +import java.util.concurrent.ThreadFactory; + +/** + * Apache HttpComponents 5 异步连接管理器 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class Apache5NioClientConnectionManager extends ApacheBaseClientConnectionManager + implements com.buession.httpclient.apache.ApacheNioClientConnectionManager { + + private IOReactorConfig ioReactorConfig; + + /** + * 线程工厂 + */ + private ThreadFactory threadFactory; + + /** + * 构造函数,创建驱动默认连接管理器 + */ + public Apache5NioClientConnectionManager() { + this(new IOReactorConfig()); + } + + /** + * 构造函数,创建驱动默认连接管理器 + * + * @param configuration + * 配置 + */ + public Apache5NioClientConnectionManager(Configuration configuration) { + this(configuration, new IOReactorConfig()); + } + + /** + * 构造函数 + * + * @param clientConnectionManager + * 原生连接管理器 + */ + public Apache5NioClientConnectionManager(AsyncClientConnectionManager clientConnectionManager) { + this(clientConnectionManager, new IOReactorConfig()); + } + + /** + * 构造函数 + * + * @param configuration + * 配置 + * @param clientConnectionManager + * 原生连接管理器 + */ + public Apache5NioClientConnectionManager(Configuration configuration, + AsyncClientConnectionManager clientConnectionManager) { + this(configuration, clientConnectionManager, new IOReactorConfig()); + } + + /** + * 构造函数,创建驱动默认连接管理器 + * + * @param ioReactorConfig + * 异步 I/O 线程配置 + */ + public Apache5NioClientConnectionManager(IOReactorConfig ioReactorConfig) { + super(); + this.ioReactorConfig = ioReactorConfig; + } + + /** + * 构造函数,创建驱动默认连接管理器 + * + * @param configuration + * 配置 + * @param ioReactorConfig + * 异步 I/O 线程配置 + */ + public Apache5NioClientConnectionManager(Configuration configuration, IOReactorConfig ioReactorConfig) { + super(configuration); + this.ioReactorConfig = ioReactorConfig; + } + + /** + * 构造函数 + * + * @param clientConnectionManager + * 原生连接管理器 + * @param ioReactorConfig + * 异步 I/O 线程配置 + */ + public Apache5NioClientConnectionManager(AsyncClientConnectionManager clientConnectionManager, + IOReactorConfig ioReactorConfig) { + super(clientConnectionManager); + this.ioReactorConfig = ioReactorConfig; + } + + /** + * 构造函数 + * + * @param configuration + * 配置 + * @param clientConnectionManager + * 原生连接管理器 + * @param ioReactorConfig + * 异步 I/O 线程配置 + */ + public Apache5NioClientConnectionManager(Configuration configuration, + AsyncClientConnectionManager clientConnectionManager, + IOReactorConfig ioReactorConfig) { + super(configuration, clientConnectionManager); + this.ioReactorConfig = ioReactorConfig; + } + + /** + * 构造函数,创建驱动默认连接管理器 + * + * @param threadFactory + * 线程工厂 + */ + public Apache5NioClientConnectionManager(ThreadFactory threadFactory) { + super(); + this.threadFactory = threadFactory; + } + + /** + * 构造函数,创建驱动默认连接管理器 + * + * @param configuration + * 配置 + * @param threadFactory + * 线程工厂 + */ + public Apache5NioClientConnectionManager(Configuration configuration, ThreadFactory threadFactory) { + super(configuration); + this.threadFactory = threadFactory; + } + + /** + * 构造函数 + * + * @param clientConnectionManager + * 原生连接管理器 + * @param threadFactory + * 线程工厂 + */ + public Apache5NioClientConnectionManager(AsyncClientConnectionManager clientConnectionManager, + ThreadFactory threadFactory) { + super(clientConnectionManager); + this.threadFactory = threadFactory; + } + + /** + * 构造函数 + * + * @param configuration + * 配置 + * @param clientConnectionManager + * 原生连接管理器 + * @param threadFactory + * 线程工厂 + */ + public Apache5NioClientConnectionManager(Configuration configuration, + AsyncClientConnectionManager clientConnectionManager, + ThreadFactory threadFactory) { + super(configuration, clientConnectionManager); + this.threadFactory = threadFactory; + } + + /** + * 构造函数,创建驱动默认连接管理器 + * + * @param ioReactorConfig + * 异步 I/O 线程配置 + * @param threadFactory + * 线程工厂 + */ + public Apache5NioClientConnectionManager(IOReactorConfig ioReactorConfig, ThreadFactory threadFactory) { + super(); + this.ioReactorConfig = ioReactorConfig; + this.threadFactory = threadFactory; + } + + /** + * 构造函数,创建驱动默认连接管理器 + * + * @param configuration + * 配置 + * @param ioReactorConfig + * 异步 I/O 线程配置 + * @param threadFactory + * 线程工厂 + */ + public Apache5NioClientConnectionManager(Configuration configuration, IOReactorConfig ioReactorConfig, + ThreadFactory threadFactory) { + this(configuration, ioReactorConfig); + this.threadFactory = threadFactory; + } + + /** + * 构造函数 + * + * @param clientConnectionManager + * 原生连接管理器 + * @param ioReactorConfig + * 异步 I/O 线程配置 + * @param threadFactory + * 线程工厂 + */ + public Apache5NioClientConnectionManager(AsyncClientConnectionManager clientConnectionManager, + IOReactorConfig ioReactorConfig, ThreadFactory threadFactory) { + this(clientConnectionManager, ioReactorConfig); + this.threadFactory = threadFactory; + } + + /** + * 构造函数 + * + * @param configuration + * 配置 + * @param clientConnectionManager + * 原生连接管理器 + * @param ioReactorConfig + * 异步 I/O 线程配置 + * @param threadFactory + * 线程工厂 + */ + public Apache5NioClientConnectionManager(Configuration configuration, + AsyncClientConnectionManager clientConnectionManager, + IOReactorConfig ioReactorConfig, ThreadFactory threadFactory) { + this(configuration, clientConnectionManager, ioReactorConfig); + this.threadFactory = threadFactory; + } + + @Override + public IOReactorConfig getIoReactorConfig() { + return ioReactorConfig; + } + + @Override + public void setIoReactorConfig(IOReactorConfig ioReactorConfig) { + this.ioReactorConfig = ioReactorConfig; + } + + /** + * 返回线程工厂 + * + * @return 线程工厂 + */ + public ThreadFactory getThreadFactory() { + return threadFactory; + } + + /** + * 设置线程工厂 + * + * @param threadFactory + * 线程工厂 + */ + public void setThreadFactory(ThreadFactory threadFactory) { + this.threadFactory = threadFactory; + } + + /** + * 创建驱动默认连接管理器 + * + * @return 连接管理器 + */ + @Override + protected AsyncClientConnectionManager createDefaultClientConnectionManager() { + final PoolingAsyncClientConnectionManager connectionManager = + getConfiguration().getConnectionTimeToLive() != null ? + new PoolingAsyncClientConnectionManager(getDefaultLookup(), PoolConcurrencyPolicy.STRICT, + Timeout.ofMilliseconds( + getConfiguration().getConnectionTimeToLive())) : new PoolingAsyncClientConnectionManager( + getDefaultLookup()); + + // 最大连接数 + propertyMapper.from(getConfiguration().getMaxConnections()).to(connectionManager::setMaxTotal); + // 每个路由的最大连接数 + propertyMapper.from(getConfiguration().getMaxPerRoute()).to(connectionManager::setDefaultMaxPerRoute); + // 连接池中最大连接数 + propertyMapper.from(getConfiguration().getMaxRequests()).to(connectionManager::setMaxTotal); + // 空闲连接存活时长 + propertyMapper.from(getConfiguration().getIdleConnectionTime()).as(Timeout::ofMilliseconds) + .to(connectionManager::closeIdle); + + connectionManager.setDefaultConnectionConfig(createDefaultConnectionConfig()); + + return connectionManager; + } + + protected ConnectionConfig createDefaultConnectionConfig() { + final ConnectionConfig.Builder connectionConfigBuilder = ConnectionConfig.custom(); + + propertyMapper.from(getConfiguration().getConnectTimeout()).as(Timeout::ofMilliseconds) + .to(connectionConfigBuilder::setConnectTimeout); + propertyMapper.from(getConfiguration().getReadTimeout()).as(Timeout::ofMilliseconds) + .to(connectionConfigBuilder::setSocketTimeout); + propertyMapper.from(getConfiguration().getConnectionTimeToLive()).as(Timeout::ofMilliseconds) + .to(connectionConfigBuilder::setTimeToLive); + + return connectionConfigBuilder.build(); + } + + private static Lookup getDefaultLookup() { + return RegistryBuilder.create() + .register(URIScheme.HTTPS.getId(), DefaultClientTlsStrategy.getDefault()) + .build(); + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/conn/ApacheBaseClientConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/conn/ApacheBaseClientConnectionManager.java index accd81a05..1f47e00e2 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/conn/ApacheBaseClientConnectionManager.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/conn/ApacheBaseClientConnectionManager.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.conn; @@ -40,7 +40,7 @@ public abstract class ApacheBaseClientConnectionManager extends AbstractConn /** * 构造函数,创建驱动默认连接管理器 */ - public ApacheBaseClientConnectionManager(){ + public ApacheBaseClientConnectionManager() { super(); } @@ -48,9 +48,9 @@ public ApacheBaseClientConnectionManager(){ * 构造函数,创建驱动默认连接管理器 * * @param configuration - * 连接对象 + * 配置 */ - public ApacheBaseClientConnectionManager(Configuration configuration){ + public ApacheBaseClientConnectionManager(Configuration configuration) { super(configuration); } @@ -58,9 +58,9 @@ public ApacheBaseClientConnectionManager(Configuration configuration){ * 构造函数 * * @param clientConnectionManager - * 驱动连接管理器 + * 原生连接管理器 */ - public ApacheBaseClientConnectionManager(CM clientConnectionManager){ + public ApacheBaseClientConnectionManager(CM clientConnectionManager) { super(clientConnectionManager); } @@ -68,11 +68,11 @@ public ApacheBaseClientConnectionManager(CM clientConnectionManager){ * 构造函数 * * @param configuration - * 连接对象 + * 配置 * @param clientConnectionManager - * 驱动连接管理器 + * 原生连接管理器 */ - public ApacheBaseClientConnectionManager(Configuration configuration, CM clientConnectionManager){ + public ApacheBaseClientConnectionManager(Configuration configuration, CM clientConnectionManager) { super(configuration, clientConnectionManager); } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/conn/ApacheClientConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/conn/ApacheClientConnectionManager.java index 6233e0d29..65774fba4 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/conn/ApacheClientConnectionManager.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/conn/ApacheClientConnectionManager.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.conn; @@ -31,16 +31,17 @@ import java.util.concurrent.TimeUnit; /** - * Apache HttpComponents 连接管理器 + * Apache HttpComponents Client 连接管理器 * * @author Yong.Teng */ -public class ApacheClientConnectionManager extends ApacheBaseClientConnectionManager { +public class ApacheClientConnectionManager extends ApacheBaseClientConnectionManager + implements com.buession.httpclient.apache.ApacheClientConnectionManager { /** * 构造函数,创建驱动默认连接管理器 */ - public ApacheClientConnectionManager(){ + public ApacheClientConnectionManager() { super(); } @@ -48,9 +49,9 @@ public ApacheClientConnectionManager(){ * 构造函数,创建驱动默认连接管理器 * * @param configuration - * 连接对象 + * 配置 */ - public ApacheClientConnectionManager(Configuration configuration){ + public ApacheClientConnectionManager(Configuration configuration) { super(configuration); } @@ -58,9 +59,9 @@ public ApacheClientConnectionManager(Configuration configuration){ * 构造函数 * * @param clientConnectionManager - * 驱动连接管理器 + * 原生连接管理器 */ - public ApacheClientConnectionManager(HttpClientConnectionManager clientConnectionManager){ + public ApacheClientConnectionManager(HttpClientConnectionManager clientConnectionManager) { super(clientConnectionManager); } @@ -68,12 +69,12 @@ public ApacheClientConnectionManager(HttpClientConnectionManager clientConnectio * 构造函数 * * @param configuration - * 连接对象 + * 配置 * @param clientConnectionManager - * 驱动连接管理器 + * 原生连接管理器 */ public ApacheClientConnectionManager(Configuration configuration, - HttpClientConnectionManager clientConnectionManager){ + HttpClientConnectionManager clientConnectionManager) { super(configuration, clientConnectionManager); } @@ -83,15 +84,22 @@ public ApacheClientConnectionManager(Configuration configuration, * @return 连接管理器 */ @Override - protected HttpClientConnectionManager createDefaultClientConnectionManager(){ - final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); + protected HttpClientConnectionManager createDefaultClientConnectionManager() { + final PoolingHttpClientConnectionManager connectionManager = + getConfiguration().getConnectionTimeToLive() == null ? new PoolingHttpClientConnectionManager() : + new PoolingHttpClientConnectionManager(getConfiguration().getConnectionTimeToLive(), + TimeUnit.MILLISECONDS); - //最大连接数 - connectionManager.setMaxTotal(getConfiguration().getMaxConnections()); - //并发数 - connectionManager.setDefaultMaxPerRoute(getConfiguration().getMaxPerRoute()); + // 最大连接数 + propertyMapper.from(getConfiguration().getMaxConnections()).to(connectionManager::setMaxTotal); + // 每个路由的最大连接数 + propertyMapper.from(getConfiguration().getMaxPerRoute()).to(connectionManager::setDefaultMaxPerRoute); + // 连接池中最大连接数 + propertyMapper.from(getConfiguration().getMaxRequests()).to(connectionManager::setMaxTotal); // 空闲连接存活时长 - connectionManager.closeIdleConnections(getConfiguration().getIdleConnectionTime(), TimeUnit.MILLISECONDS); + if(getConfiguration().getIdleConnectionTime() != null){ + connectionManager.closeIdleConnections(getConfiguration().getIdleConnectionTime(), TimeUnit.MILLISECONDS); + } return connectionManager; } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/conn/ApacheNioClientConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/conn/ApacheNioClientConnectionManager.java index 7e8572092..966aeaa2f 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/conn/ApacheNioClientConnectionManager.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/conn/ApacheNioClientConnectionManager.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.conn; @@ -27,9 +27,14 @@ import com.buession.core.converter.mapper.PropertyMapper; import com.buession.httpclient.conn.nio.IOReactorConfig; import com.buession.httpclient.core.Configuration; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; import org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager; import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor; import org.apache.http.nio.conn.NHttpClientConnectionManager; +import org.apache.http.nio.conn.NoopIOSessionStrategy; +import org.apache.http.nio.conn.SchemeIOSessionStrategy; +import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy; import org.apache.http.nio.reactor.ConnectingIOReactor; import org.apache.http.nio.reactor.IOReactorException; @@ -37,13 +42,13 @@ import java.util.concurrent.TimeUnit; /** - * Apache HttpComponents 异步连接管理器 + * Apache HttpComponents 4 异步连接管理器 * * @author Yong.Teng * @since 2.3.0 */ public class ApacheNioClientConnectionManager extends ApacheBaseClientConnectionManager - implements NioConnectionManager { + implements com.buession.httpclient.apache.ApacheNioClientConnectionManager { private IOReactorConfig ioReactorConfig; @@ -55,7 +60,7 @@ public class ApacheNioClientConnectionManager extends ApacheBaseClientConnection /** * 构造函数,创建驱动默认连接管理器 */ - public ApacheNioClientConnectionManager(){ + public ApacheNioClientConnectionManager() { this(new IOReactorConfig()); } @@ -65,7 +70,7 @@ public ApacheNioClientConnectionManager(){ * @param configuration * 连接对象 */ - public ApacheNioClientConnectionManager(Configuration configuration){ + public ApacheNioClientConnectionManager(Configuration configuration) { this(configuration, new IOReactorConfig()); } @@ -75,7 +80,7 @@ public ApacheNioClientConnectionManager(Configuration configuration){ * @param clientConnectionManager * 驱动连接管理器 */ - public ApacheNioClientConnectionManager(NHttpClientConnectionManager clientConnectionManager){ + public ApacheNioClientConnectionManager(NHttpClientConnectionManager clientConnectionManager) { this(clientConnectionManager, new IOReactorConfig()); } @@ -88,7 +93,7 @@ public ApacheNioClientConnectionManager(NHttpClientConnectionManager clientConne * 驱动连接管理器 */ public ApacheNioClientConnectionManager(Configuration configuration, - NHttpClientConnectionManager clientConnectionManager){ + NHttpClientConnectionManager clientConnectionManager) { this(configuration, clientConnectionManager, new IOReactorConfig()); } @@ -98,7 +103,7 @@ public ApacheNioClientConnectionManager(Configuration configuration, * @param ioReactorConfig * {@link IOReactorConfig} */ - public ApacheNioClientConnectionManager(IOReactorConfig ioReactorConfig){ + public ApacheNioClientConnectionManager(IOReactorConfig ioReactorConfig) { super(); this.ioReactorConfig = ioReactorConfig; } @@ -111,7 +116,7 @@ public ApacheNioClientConnectionManager(IOReactorConfig ioReactorConfig){ * @param ioReactorConfig * {@link IOReactorConfig} */ - public ApacheNioClientConnectionManager(Configuration configuration, IOReactorConfig ioReactorConfig){ + public ApacheNioClientConnectionManager(Configuration configuration, IOReactorConfig ioReactorConfig) { super(configuration); this.ioReactorConfig = ioReactorConfig; } @@ -125,7 +130,7 @@ public ApacheNioClientConnectionManager(Configuration configuration, IOReactorCo * {@link IOReactorConfig} */ public ApacheNioClientConnectionManager(NHttpClientConnectionManager clientConnectionManager, - IOReactorConfig ioReactorConfig){ + IOReactorConfig ioReactorConfig) { super(clientConnectionManager); this.ioReactorConfig = ioReactorConfig; } @@ -142,7 +147,7 @@ public ApacheNioClientConnectionManager(NHttpClientConnectionManager clientConne */ public ApacheNioClientConnectionManager(Configuration configuration, NHttpClientConnectionManager clientConnectionManager, - IOReactorConfig ioReactorConfig){ + IOReactorConfig ioReactorConfig) { super(configuration, clientConnectionManager); this.ioReactorConfig = ioReactorConfig; } @@ -153,7 +158,7 @@ public ApacheNioClientConnectionManager(Configuration configuration, * @param threadFactory * 线程工厂 */ - public ApacheNioClientConnectionManager(ThreadFactory threadFactory){ + public ApacheNioClientConnectionManager(ThreadFactory threadFactory) { super(); this.threadFactory = threadFactory; } @@ -166,7 +171,7 @@ public ApacheNioClientConnectionManager(ThreadFactory threadFactory){ * @param threadFactory * 线程工厂 */ - public ApacheNioClientConnectionManager(Configuration configuration, ThreadFactory threadFactory){ + public ApacheNioClientConnectionManager(Configuration configuration, ThreadFactory threadFactory) { super(configuration); this.threadFactory = threadFactory; } @@ -180,7 +185,7 @@ public ApacheNioClientConnectionManager(Configuration configuration, ThreadFacto * 线程工厂 */ public ApacheNioClientConnectionManager(NHttpClientConnectionManager clientConnectionManager, - ThreadFactory threadFactory){ + ThreadFactory threadFactory) { super(clientConnectionManager); this.threadFactory = threadFactory; } @@ -197,7 +202,7 @@ public ApacheNioClientConnectionManager(NHttpClientConnectionManager clientConne */ public ApacheNioClientConnectionManager(Configuration configuration, NHttpClientConnectionManager clientConnectionManager, - ThreadFactory threadFactory){ + ThreadFactory threadFactory) { super(configuration, clientConnectionManager); this.threadFactory = threadFactory; } @@ -210,7 +215,7 @@ public ApacheNioClientConnectionManager(Configuration configuration, * @param threadFactory * 线程工厂 */ - public ApacheNioClientConnectionManager(IOReactorConfig ioReactorConfig, ThreadFactory threadFactory){ + public ApacheNioClientConnectionManager(IOReactorConfig ioReactorConfig, ThreadFactory threadFactory) { super(); this.ioReactorConfig = ioReactorConfig; this.threadFactory = threadFactory; @@ -227,7 +232,7 @@ public ApacheNioClientConnectionManager(IOReactorConfig ioReactorConfig, ThreadF * 线程工厂 */ public ApacheNioClientConnectionManager(Configuration configuration, IOReactorConfig ioReactorConfig, - ThreadFactory threadFactory){ + ThreadFactory threadFactory) { this(configuration, ioReactorConfig); this.threadFactory = threadFactory; } @@ -243,7 +248,7 @@ public ApacheNioClientConnectionManager(Configuration configuration, IOReactorCo * 线程工厂 */ public ApacheNioClientConnectionManager(NHttpClientConnectionManager clientConnectionManager, - IOReactorConfig ioReactorConfig, ThreadFactory threadFactory){ + IOReactorConfig ioReactorConfig, ThreadFactory threadFactory) { this(clientConnectionManager, ioReactorConfig); this.threadFactory = threadFactory; } @@ -262,18 +267,18 @@ public ApacheNioClientConnectionManager(NHttpClientConnectionManager clientConne */ public ApacheNioClientConnectionManager(Configuration configuration, NHttpClientConnectionManager clientConnectionManager, - IOReactorConfig ioReactorConfig, ThreadFactory threadFactory){ + IOReactorConfig ioReactorConfig, ThreadFactory threadFactory) { this(configuration, clientConnectionManager, ioReactorConfig); this.threadFactory = threadFactory; } @Override - public IOReactorConfig getIoReactorConfig(){ + public IOReactorConfig getIoReactorConfig() { return ioReactorConfig; } @Override - public void setIoReactorConfig(IOReactorConfig ioReactorConfig){ + public void setIoReactorConfig(IOReactorConfig ioReactorConfig) { this.ioReactorConfig = ioReactorConfig; } @@ -282,7 +287,7 @@ public void setIoReactorConfig(IOReactorConfig ioReactorConfig){ * * @return 线程工厂 */ - public ThreadFactory getThreadFactory(){ + public ThreadFactory getThreadFactory() { return threadFactory; } @@ -292,7 +297,7 @@ public ThreadFactory getThreadFactory(){ * @param threadFactory * 线程工厂 */ - public void setThreadFactory(ThreadFactory threadFactory){ + public void setThreadFactory(ThreadFactory threadFactory) { this.threadFactory = threadFactory; } @@ -302,25 +307,32 @@ public void setThreadFactory(ThreadFactory threadFactory){ * @return 连接管理器 */ @Override - protected NHttpClientConnectionManager createDefaultClientConnectionManager(){ - final PoolingNHttpClientConnectionManager connectionManager = new PoolingNHttpClientConnectionManager( - createConnectingIOReactor()); - - //最大连接数 - connectionManager.setMaxTotal(getConfiguration().getMaxConnections()); - //并发数 - connectionManager.setDefaultMaxPerRoute(getConfiguration().getMaxPerRoute()); + protected NHttpClientConnectionManager createDefaultClientConnectionManager() { + final PoolingNHttpClientConnectionManager connectionManager = + getConfiguration().getConnectionTimeToLive() > -1 ? new PoolingNHttpClientConnectionManager( + createConnectingIOReactor(), null, getDefaultRegistry(), null, null, + getConfiguration().getConnectionTimeToLive(), TimeUnit.MILLISECONDS) : + new PoolingNHttpClientConnectionManager(createConnectingIOReactor()); + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenPositiveNumber(); + + // 最大连接数 + propertyMapper.from(getConfiguration().getMaxConnections()).to(connectionManager::setMaxTotal); + // 每个路由的最大连接数 + propertyMapper.from(getConfiguration().getMaxPerRoute()).to(connectionManager::setDefaultMaxPerRoute); + // 连接池中最大连接数 + propertyMapper.from(getConfiguration().getMaxRequests()).to(connectionManager::setMaxTotal); // 空闲连接存活时长 - connectionManager.closeIdleConnections(getConfiguration().getIdleConnectionTime(), TimeUnit.MILLISECONDS); + if(getConfiguration().getIdleConnectionTime() > 0){ + connectionManager.closeIdleConnections(getConfiguration().getIdleConnectionTime(), TimeUnit.MILLISECONDS); + } return connectionManager; } - protected ConnectingIOReactor createConnectingIOReactor(){ + protected ConnectingIOReactor createConnectingIOReactor() { org.apache.http.impl.nio.reactor.IOReactorConfig ioReactorConfig = null; if(getIoReactorConfig() != null){ - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); final org.apache.http.impl.nio.reactor.IOReactorConfig.Builder ioReactorConfigBuilder = org.apache.http.impl.nio.reactor.IOReactorConfig.custom(); @@ -333,7 +345,7 @@ protected ConnectingIOReactor createConnectingIOReactor(){ propertyMapper.from(getIoReactorConfig().getSoTimeout()).to(ioReactorConfigBuilder::setSoTimeout); propertyMapper.from(getIoReactorConfig().isSoReuseAddress()).to(ioReactorConfigBuilder::setSoReuseAddress); propertyMapper.from(getIoReactorConfig().getSoLinger()).to(ioReactorConfigBuilder::setSoLinger); - propertyMapper.from(getIoReactorConfig().isSoKeepalive()).to(ioReactorConfigBuilder::setSoKeepAlive); + propertyMapper.from(getIoReactorConfig().isSoKeepAlive()).to(ioReactorConfigBuilder::setSoKeepAlive); propertyMapper.from(getIoReactorConfig().isTcpNoDelay()).to(ioReactorConfigBuilder::setTcpNoDelay); propertyMapper.from(getIoReactorConfig().getConnectTimeout()).to(ioReactorConfigBuilder::setConnectTimeout); propertyMapper.from(getIoReactorConfig().getSndBufSize()).to(ioReactorConfigBuilder::setSndBufSize); @@ -350,4 +362,11 @@ protected ConnectingIOReactor createConnectingIOReactor(){ } } + private static Registry getDefaultRegistry() { + return RegistryBuilder.create() + .register("http", NoopIOSessionStrategy.INSTANCE) + .register("https", SSLIOSessionStrategy.getDefaultStrategy()) + .build(); + } + } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/conn/ConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/conn/ConnectionManager.java index ad2983453..816de25fe 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/conn/ConnectionManager.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/conn/ConnectionManager.java @@ -19,33 +19,16 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.conn; -import com.buession.httpclient.core.Configuration; - /** * 连接管理器 * * @author Yong.Teng */ -public interface ConnectionManager { - - /** - * 获取连接对象 - * - * @return 连接对象 - */ - Configuration getConfiguration(); - - /** - * 设置连接对象 - * - * @param configuration - * 连接对象 - */ - void setConfiguration(Configuration configuration); +public interface ConnectionManager extends IConnectionManager { } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/conn/IConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/conn/IConnectionManager.java new file mode 100644 index 000000000..39bde876c --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/conn/IConnectionManager.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.conn; + +import com.buession.httpclient.core.Configuration; + +/** + * 连接管理器基本接口 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface IConnectionManager { + + /** + * 获取连接对象 + * + * @return 连接对象 + */ + Configuration getConfiguration(); + + /** + * 设置连接对象 + * + * @param configuration + * 连接对象 + */ + void setConfiguration(Configuration configuration); + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/conn/NioConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/conn/NioConnectionManager.java index 9bf90d8d8..a59db2b0d 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/conn/NioConnectionManager.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/conn/NioConnectionManager.java @@ -19,39 +19,17 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.conn; -import com.buession.httpclient.conn.nio.IOReactorConfig; -import com.buession.httpclient.core.Configuration; - /** * 异步连接管理器 * * @author Yong.Teng - * @since 2.3.0 + * @since 3.0.0 */ -public interface NioConnectionManager { - - /** - * 获取连接对象 - * - * @return 连接对象 - */ - Configuration getConfiguration(); - - /** - * 设置连接对象 - * - * @param configuration - * 连接对象 - */ - void setConfiguration(Configuration configuration); - - IOReactorConfig getIoReactorConfig(); - - void setIoReactorConfig(IOReactorConfig ioReactorConfig); +public interface NioConnectionManager extends IConnectionManager { } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpBaseClientConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpBaseClientConnectionManager.java index 0ee9a1c31..7fe06dbf9 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpBaseClientConnectionManager.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpBaseClientConnectionManager.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.conn; @@ -40,7 +40,7 @@ public abstract class OkHttpBaseClientConnectionManager extends AbstractConn /** * 构造函数,创建驱动默认连接管理器 */ - public OkHttpBaseClientConnectionManager(){ + public OkHttpBaseClientConnectionManager() { super(); } @@ -48,9 +48,9 @@ public OkHttpBaseClientConnectionManager(){ * 构造函数,创建驱动默认连接管理器 * * @param configuration - * 连接对象 + * 配置 */ - public OkHttpBaseClientConnectionManager(Configuration configuration){ + public OkHttpBaseClientConnectionManager(Configuration configuration) { super(configuration); } @@ -58,9 +58,9 @@ public OkHttpBaseClientConnectionManager(Configuration configuration){ * 构造函数 * * @param clientConnectionManager - * 驱动连接管理器 + * 原生连接管理器 */ - public OkHttpBaseClientConnectionManager(CM clientConnectionManager){ + public OkHttpBaseClientConnectionManager(CM clientConnectionManager) { super(clientConnectionManager); } @@ -68,11 +68,11 @@ public OkHttpBaseClientConnectionManager(CM clientConnectionManager){ * 构造函数 * * @param configuration - * 连接对象 + * 配置 * @param clientConnectionManager - * 驱动连接管理器 + * 原生连接管理器 */ - public OkHttpBaseClientConnectionManager(Configuration configuration, CM clientConnectionManager){ + public OkHttpBaseClientConnectionManager(Configuration configuration, CM clientConnectionManager) { super(configuration, clientConnectionManager); } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpClientConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpClientConnectionManager.java index 10dc46833..903cd6830 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpClientConnectionManager.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpClientConnectionManager.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.conn; @@ -32,7 +32,8 @@ * * @author Yong.Teng */ -public class OkHttpClientConnectionManager extends OkHttpBaseClientConnectionManager { +public class OkHttpClientConnectionManager extends OkHttpBaseClientConnectionManager + implements com.buession.httpclient.okhttp.OkHttpClientConnectionManager { /** * 构造函数,创建驱动默认连接管理器 @@ -45,7 +46,7 @@ public OkHttpClientConnectionManager() { * 构造函数,创建驱动默认连接管理器 * * @param configuration - * 连接对象 + * 配置 */ public OkHttpClientConnectionManager(Configuration configuration) { super(configuration); @@ -55,7 +56,7 @@ public OkHttpClientConnectionManager(Configuration configuration) { * 构造函数 * * @param clientConnectionManager - * 驱动连接管理器 + * 原生连接管理器 */ public OkHttpClientConnectionManager(HttpClientConnectionManager clientConnectionManager) { super(clientConnectionManager); @@ -65,9 +66,9 @@ public OkHttpClientConnectionManager(HttpClientConnectionManager clientConnectio * 构造函数 * * @param configuration - * 连接对象 + * 配置 * @param clientConnectionManager - * 驱动连接管理器 + * 原生连接管理器 */ public OkHttpClientConnectionManager(Configuration configuration, HttpClientConnectionManager clientConnectionManager) { @@ -83,14 +84,14 @@ public OkHttpClientConnectionManager(Configuration configuration, protected HttpClientConnectionManager createDefaultClientConnectionManager() { final HttpClientConnectionManager connectionManager = new HttpClientConnectionManager(); - //最大连接数 - connectionManager.setMaxConnections(getConfiguration().getMaxConnections()); - // 默认的最大并发请求数量 - connectionManager.setMaxRequests(getConfiguration().getMaxRequests()); + // 最大连接数 + propertyMapper.from(getConfiguration().getMaxConnections()).to(connectionManager::setMaxConnections); // 同时请求相同主机的请求数量最大值 - connectionManager.setMaxRequestsPerHost(getConfiguration().getMaxPerRoute()); + propertyMapper.from(getConfiguration().getMaxPerRoute()).to(connectionManager::setMaxRequestsPerHost); + // 默认的最大并发请求数量 + propertyMapper.from(getConfiguration().getMaxRequests()).to(connectionManager::setMaxRequests); // 空闲连接存活时长 - connectionManager.setIdleConnectionTime(getConfiguration().getIdleConnectionTime()); + propertyMapper.from(getConfiguration().getIdleConnectionTime()).to(connectionManager::setIdleConnectionTime); return connectionManager; } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpNioClientConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpNioClientConnectionManager.java index b8452ae8e..ec41165d2 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpNioClientConnectionManager.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/conn/OkHttpNioClientConnectionManager.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.conn; @@ -33,13 +33,13 @@ * @author Yong.Teng * @since 2.3.0 */ -public class OkHttpNioClientConnectionManager - extends OkHttpBaseClientConnectionManager { +public class OkHttpNioClientConnectionManager extends OkHttpBaseClientConnectionManager + implements com.buession.httpclient.okhttp.OkHttpNioClientConnectionManager { /** * 构造函数,创建驱动默认连接管理器 */ - public OkHttpNioClientConnectionManager(){ + public OkHttpNioClientConnectionManager() { super(); } @@ -47,9 +47,9 @@ public OkHttpNioClientConnectionManager(){ * 构造函数,创建驱动默认连接管理器 * * @param configuration - * 连接对象 + * 配置 */ - public OkHttpNioClientConnectionManager(Configuration configuration){ + public OkHttpNioClientConnectionManager(Configuration configuration) { super(configuration); } @@ -57,9 +57,9 @@ public OkHttpNioClientConnectionManager(Configuration configuration){ * 构造函数 * * @param clientConnectionManager - * 驱动连接管理器 + * 原生连接管理器 */ - public OkHttpNioClientConnectionManager(NioHttpClientConnectionManager clientConnectionManager){ + public OkHttpNioClientConnectionManager(NioHttpClientConnectionManager clientConnectionManager) { super(clientConnectionManager); } @@ -67,12 +67,12 @@ public OkHttpNioClientConnectionManager(NioHttpClientConnectionManager clientCon * 构造函数 * * @param configuration - * 连接对象 + * 配置 * @param clientConnectionManager - * 驱动连接管理器 + * 原生连接管理器 */ public OkHttpNioClientConnectionManager(Configuration configuration, - NioHttpClientConnectionManager clientConnectionManager){ + NioHttpClientConnectionManager clientConnectionManager) { super(configuration, clientConnectionManager); } @@ -82,17 +82,17 @@ public OkHttpNioClientConnectionManager(Configuration configuration, * @return 连接管理器 */ @Override - protected NioHttpClientConnectionManager createDefaultClientConnectionManager(){ + protected NioHttpClientConnectionManager createDefaultClientConnectionManager() { final NioHttpClientConnectionManager connectionManager = new NioHttpClientConnectionManager(); - //最大连接数 - connectionManager.setMaxConnections(getConfiguration().getMaxConnections()); - // 默认的最大并发请求数量 - //connectionManager.setMaxRequests(getConfiguration().getMaxPerRoute()); + // 最大连接数 + propertyMapper.from(getConfiguration().getMaxConnections()).to(connectionManager::setMaxConnections); // 同时请求相同主机的请求数量最大值 - connectionManager.setMaxRequestsPerHost(getConfiguration().getMaxPerRoute()); + propertyMapper.from(getConfiguration().getMaxPerRoute()).to(connectionManager::setMaxRequestsPerHost); + // 默认的最大并发请求数量 + propertyMapper.from(getConfiguration().getMaxRequests()).to(connectionManager::setMaxRequests); // 空闲连接存活时长 - connectionManager.setIdleConnectionTime(getConfiguration().getIdleConnectionTime()); + propertyMapper.from(getConfiguration().getIdleConnectionTime()).to(connectionManager::setIdleConnectionTime); return connectionManager; } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/conn/nio/IOReactorConfig.java b/buession-httpclient/src/main/java/com/buession/httpclient/conn/nio/IOReactorConfig.java index 01e763932..550be9a55 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/conn/nio/IOReactorConfig.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/conn/nio/IOReactorConfig.java @@ -19,12 +19,14 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.conn.nio; /** + * 异步 I/O 线程配置 + * * @author Yong.Teng * @since 2.3.0 */ @@ -32,157 +34,481 @@ public final class IOReactorConfig implements Cloneable { public final static IOReactorConfig DEFAULT = new IOReactorConfig(); + /** + * 连接超时(单位:毫秒) + */ + private Integer connectTimeout; + + /** + * I/O 操作超时时间(单位:毫秒) + */ + private Integer soTimeout; + + /** + * 选择器的轮询间隔时间(单位:毫秒) + */ private Long selectInterval; + /** + * 优雅关闭等待时长(单位:毫秒) + */ private Long shutdownGracePeriod; + /** + * 是否启用兴趣操作队列 + */ private Boolean interestOpQueued; + /** + * I/O 线程数量 + */ private Integer ioThreadCount; - private Integer soTimeout; - + /** + * 是否启用 SO_REUSEADDR 套接字选项 + */ private Boolean soReuseAddress; + /** + * SO_LINGER + */ private Integer soLinger; + /** + * 是否启用 TCP 的 keep-alive 套接字选项 + */ private Boolean soKeepAlive; + /** + * 是否启用 TCP_NODELAY 选项 + */ private Boolean tcpNoDelay; - private Integer connectTimeout; - + /** + * 发送缓冲区大小(单位:字节) + */ private Integer sndBufSize; + /** + * 接收缓冲区大小(单位:字节) + */ private Integer rcvBufSize; + /** + * 服务端套接字的连接请求队列的大小 + */ private Integer backlogSize; - public IOReactorConfig(){ + /** + * 构造函数 + */ + public IOReactorConfig() { } - public IOReactorConfig(Long selectInterval, Long shutdownGracePeriod, Boolean interestOpQueued, - Integer ioThreadCount, Integer soTimeout, Boolean soReuseAddress, Integer soLinger, - Boolean soKeepAlive, Boolean tcpNoDelay, Integer connectTimeout, Integer sndBufSize, - Integer rcvBufSize, Integer backlogSize){ + /** + * 构造函数 + * + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * I/O 操作超时时间(单位:毫秒) + * @param selectInterval + * 选择器的轮询间隔时间(单位:毫秒) + * @param shutdownGracePeriod + * 优雅关闭等待时长(单位:毫秒) + * @param interestOpQueued + * 是否启用兴趣操作队列 + * @param ioThreadCount + * I/O 线程数量 + * @param soReuseAddress + * 是否启用 SO_REUSEADDR 套接字选项 + * @param soLinger + * SO_LINGER + * @param soKeepAlive + * 是否启用 TCP 的 keep-alive 套接字选项 + * @param tcpNoDelay + * 是否启用 TCP_NODELAY 选项 + * @param sndBufSize + * 发送缓冲区大小(单位:字节) + * @param rcvBufSize + * 接收缓冲区大小(单位:字节) + * @param backlogSize + * 服务端套接字的连接请求队列的大小 + */ + public IOReactorConfig(Integer connectTimeout, Integer soTimeout, Long selectInterval, Long shutdownGracePeriod, + Boolean interestOpQueued, Integer ioThreadCount, Boolean soReuseAddress, Integer soLinger, + Boolean soKeepAlive, Boolean tcpNoDelay, Integer sndBufSize, Integer rcvBufSize, + Integer backlogSize) { + this.connectTimeout = connectTimeout; + this.soTimeout = soTimeout; this.selectInterval = selectInterval; this.shutdownGracePeriod = shutdownGracePeriod; this.interestOpQueued = interestOpQueued; this.ioThreadCount = ioThreadCount; - this.soTimeout = soTimeout; this.soReuseAddress = soReuseAddress; this.soLinger = soLinger; this.soKeepAlive = soKeepAlive; this.tcpNoDelay = tcpNoDelay; - this.connectTimeout = connectTimeout; this.sndBufSize = sndBufSize; this.rcvBufSize = rcvBufSize; this.backlogSize = backlogSize; } - public Long getSelectInterval(){ + /** + * 构造函数 + * + * @param selectInterval + * 选择器的轮询间隔时间(单位:毫秒) + * @param shutdownGracePeriod + * 优雅关闭等待时长(单位:毫秒) + * @param interestOpQueued + * 是否启用兴趣操作队列 + * @param ioThreadCount + * I/O 线程数量 + * @param soTimeout + * I/O 操作超时时间(单位:毫秒) + * @param soReuseAddress + * 是否启用 SO_REUSEADDR 套接字选项 + * @param soLinger + * SO_LINGER + * @param soKeepAlive + * 是否启用 TCP 的 keep-alive 套接字选项 + * @param tcpNoDelay + * 是否启用 TCP_NODELAY 选项 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param sndBufSize + * 发送缓冲区大小(单位:字节) + * @param rcvBufSize + * 接收缓冲区大小(单位:字节) + * @param backlogSize + * 服务端套接字的连接请求队列的大小 + */ + @Deprecated + public IOReactorConfig(Long selectInterval, Long shutdownGracePeriod, Boolean interestOpQueued, + Integer ioThreadCount, Integer soTimeout, Boolean soReuseAddress, Integer soLinger, + Boolean soKeepAlive, Boolean tcpNoDelay, Integer connectTimeout, Integer sndBufSize, + Integer rcvBufSize, Integer backlogSize) { + this(connectTimeout, soTimeout, selectInterval, shutdownGracePeriod, interestOpQueued, ioThreadCount, + soReuseAddress, soLinger, soKeepAlive, tcpNoDelay, sndBufSize, rcvBufSize, backlogSize); + } + + /** + * 返回连接超时(单位:毫秒) + * + * @return 连接超时 + */ + public Integer getConnectTimeout() { + return connectTimeout; + } + + /** + * 设置连接超时(单位:毫秒) + * + * @param connectTimeout + * 连接超时 + */ + public void setConnectTimeout(Integer connectTimeout) { + this.connectTimeout = connectTimeout; + } + + /** + * 返回 I/O 操作超时时间(单位:毫秒) + * + * @return I/O 操作超时时间 + */ + public Integer getSoTimeout() { + return soTimeout; + } + + /** + * 设置 I/O 操作超时时间(单位:毫秒) + * + * @param soTimeout + * I/O 操作超时时间 + */ + public void setSoTimeout(Integer soTimeout) { + this.soTimeout = soTimeout; + } + + /** + * 返回选择器的轮询间隔时间(单位:毫秒) + * + * @return 选择器的轮询间隔时间 + */ + public Long getSelectInterval() { return selectInterval; } - public void setSelectInterval(Long selectInterval){ + /** + * 设置选择器的轮询间隔时间(单位:毫秒) + * + * @param selectInterval + * 选择器的轮询间隔时间 + */ + public void setSelectInterval(Long selectInterval) { this.selectInterval = selectInterval; } - public Long getShutdownGracePeriod(){ + /** + * 返回优雅关闭等待时长(单位:毫秒) + * + * @return 优雅关闭等待时长 + */ + public Long getShutdownGracePeriod() { return shutdownGracePeriod; } - public void setShutdownGracePeriod(Long shutdownGracePeriod){ + /** + * 设置优雅关闭等待时长(单位:毫秒) + * + * @param shutdownGracePeriod + * 优雅关闭等待时长 + */ + public void setShutdownGracePeriod(Long shutdownGracePeriod) { this.shutdownGracePeriod = shutdownGracePeriod; } - public Boolean isInterestOpQueued(){ + /** + * 返回是否启用兴趣操作队列 + * + * @return true / false + */ + public Boolean isInterestOpQueued() { + return getInterestOpQueued(); + } + + /** + * 返回是否启用兴趣操作队列 + * + * @return true / false + * + * @since 3.0.0 + */ + public Boolean getInterestOpQueued() { return interestOpQueued; } - public void setInterestOpQueued(Boolean interestOpQueued){ + /** + * 设置是否启用兴趣操作队列 + * + * @param interestOpQueued + * true / false + */ + public void setInterestOpQueued(Boolean interestOpQueued) { this.interestOpQueued = interestOpQueued; } - public Integer getIoThreadCount(){ + /** + * 返回 I/O 线程数量 + * + * @return I/O 线程数量 + */ + public Integer getIoThreadCount() { return ioThreadCount; } - public void setIoThreadCount(Integer ioThreadCount){ + /** + * 设置 I/O 线程数量 + * + * @param ioThreadCount + * I/O 线程数量 + */ + public void setIoThreadCount(Integer ioThreadCount) { this.ioThreadCount = ioThreadCount; } - public Integer getSoTimeout(){ - return soTimeout; - } - - public void setSoTimeout(Integer soTimeout){ - this.soTimeout = soTimeout; + /** + * 返回是否启用 SO_REUSEADDR 套接字选项 + * + * @return true / false + */ + public Boolean isSoReuseAddress() { + return getSoReuseAddress(); } - public Boolean isSoReuseAddress(){ + /** + * 返回是否启用 SO_REUSEADDR 套接字选项 + * + * @return true / false + */ + public Boolean getSoReuseAddress() { return soReuseAddress; } - public void setSoReuseAddress(Boolean soReuseAddress){ + /** + * 设置是否启用 SO_REUSEADDR 套接字选项 + * + * @param soReuseAddress + * true / false + */ + public void setSoReuseAddress(Boolean soReuseAddress) { this.soReuseAddress = soReuseAddress; } - public Integer getSoLinger(){ + /** + * 返回 SO_LINGER 值 + * + * @return SO_LINGER 值 + */ + public Integer getSoLinger() { return soLinger; } - public void setSoLinger(Integer soLinger){ + /** + * 设置 SO_LINGER 值 + * + * @param soLinger + * SO_LINGER 值 + */ + public void setSoLinger(Integer soLinger) { this.soLinger = soLinger; } - public Boolean isSoKeepalive(){ + /** + * 返回是否启用 TCP 的 keep-alive 套接字选项 + * + * @return true / false + * + * @see #isSoKeepAlive() + */ + @Deprecated + public Boolean isSoKeepalive() { + return getSoKeepAlive(); + } + + /** + * 返回是否启用 TCP 的 keep-alive 套接字选项 + * + * @return true / false + * + * @since 3.0.0 + */ + public Boolean isSoKeepAlive() { + return getSoKeepAlive(); + } + + /** + * 返回是否启用 TCP 的 keep-alive 套接字选项 + * + * @return true / false + * + * @since 3.0 + */ + public Boolean getSoKeepAlive() { return soKeepAlive; } - public void setSoKeepalive(Boolean soKeepAlive){ - this.soKeepAlive = soKeepAlive; + /** + * 设置是否启用 TCP 的 keep-alive 套接字选项 + * + * @param soKeepAlive + * true / false + * + * @see #setSoKeepAlive(Boolean) + */ + @Deprecated + public void setSoKeepalive(Boolean soKeepAlive) { + setSoKeepAlive(soKeepAlive); } - public Boolean isTcpNoDelay(){ - return tcpNoDelay; + /** + * 设置是否启用 TCP 的 keep-alive 套接字选项 + * + * @param soKeepAlive + * true / false + * + * @since 3.0.0 + */ + public void setSoKeepAlive(Boolean soKeepAlive) { + this.soKeepAlive = soKeepAlive; } - public void setTcpNoDelay(Boolean tcpNoDelay){ - this.tcpNoDelay = tcpNoDelay; + /** + * 返回是否启用 TCP_NODELAY 选项 + * + * @return true / false + */ + public Boolean isTcpNoDelay() { + return getTcpNoDelay(); } - public Integer getConnectTimeout(){ - return connectTimeout; + /** + * 返回是否启用 TCP_NODELAY 选项 + * + * @return true / false + * + * @since 3.0.0 + */ + public Boolean getTcpNoDelay() { + return tcpNoDelay; } - public void setConnectTimeout(Integer connectTimeout){ - this.connectTimeout = connectTimeout; + /** + * 设置是否启用 TCP_NODELAY 选项 + * + * @param tcpNoDelay + * true / false + */ + public void setTcpNoDelay(Boolean tcpNoDelay) { + this.tcpNoDelay = tcpNoDelay; } - public Integer getSndBufSize(){ + /** + * 返回发送缓冲区大小(单位:字节) + * + * @return 发送缓冲区大小 + */ + public Integer getSndBufSize() { return sndBufSize; } - public void setSndBufSize(Integer sndBufSize){ + /** + * 设置发送缓冲区大小(单位:字节) + * + * @param sndBufSize + * 发送缓冲区大小(单位:字节) + */ + public void setSndBufSize(Integer sndBufSize) { this.sndBufSize = sndBufSize; } - public Integer getRcvBufSize(){ + /** + * 返回接收缓冲区大小(单位:字节) + * + * @return 接收缓冲区大小(单位:字节) + */ + public Integer getRcvBufSize() { return rcvBufSize; } - public void setRcvBufSize(Integer rcvBufSize){ + /** + * 设置接收缓冲区大小(单位:字节) + * + * @param rcvBufSize + * 接收缓冲区大小(单位:字节) + */ + public void setRcvBufSize(Integer rcvBufSize) { this.rcvBufSize = rcvBufSize; } - public Integer getBacklogSize(){ + /** + * 返回服务端套接字的连接请求队列的大小 + * + * @return 服务端套接字的连接请求队列的大小 + */ + public Integer getBacklogSize() { return backlogSize; } - @Override - protected IOReactorConfig clone() throws CloneNotSupportedException{ - return (IOReactorConfig) super.clone(); + /** + * 设置服务端套接字的连接请求队列的大小 + * + * @param backlogSize + * 服务端套接字的连接请求队列的大小 + */ + public void setBacklogSize(Integer backlogSize) { + this.backlogSize = backlogSize; } } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/AbstractRawRequestBody.java b/buession-httpclient/src/main/java/com/buession/httpclient/core/AbstractRawRequestBody.java index 12f7c50cd..d8358b772 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/core/AbstractRawRequestBody.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/core/AbstractRawRequestBody.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.core; @@ -40,7 +40,7 @@ public abstract class AbstractRawRequestBody extends AbstractRequestBody /** * 构造函数 */ - public AbstractRawRequestBody(){ + public AbstractRawRequestBody() { super(); } @@ -52,7 +52,7 @@ public AbstractRawRequestBody(){ * @param content * 请求体 */ - public AbstractRawRequestBody(ContentType contentType, V content){ + public AbstractRawRequestBody(ContentType contentType, V content) { super(contentType, content); } @@ -68,7 +68,7 @@ public AbstractRawRequestBody(ContentType contentType, V content){ * * @since 2.0.0 */ - public AbstractRawRequestBody(ContentType contentType, V content, Charset charset){ + public AbstractRawRequestBody(ContentType contentType, V content, Charset charset) { super(new ContentType(contentType.getMimeType(), charset), content); } @@ -82,7 +82,7 @@ public AbstractRawRequestBody(ContentType contentType, V content, Charset charse * @param contentLength * 请求体大小 */ - public AbstractRawRequestBody(ContentType contentType, V content, long contentLength){ + public AbstractRawRequestBody(ContentType contentType, V content, long contentLength) { super(contentType, content, contentLength); } @@ -100,7 +100,7 @@ public AbstractRawRequestBody(ContentType contentType, V content, long contentLe * * @since 2.0.0 */ - public AbstractRawRequestBody(ContentType contentType, V content, long contentLength, Charset charset){ + public AbstractRawRequestBody(ContentType contentType, V content, long contentLength, Charset charset) { super(new ContentType(contentType.getMimeType(), charset), content, contentLength); } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/AbstractRequestBuilder.java b/buession-httpclient/src/main/java/com/buession/httpclient/core/AbstractRequestBuilder.java deleted file mode 100644 index 97e13d090..000000000 --- a/buession-httpclient/src/main/java/com/buession/httpclient/core/AbstractRequestBuilder.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - * ================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | - * +------------------------------------------------------------------------------------------------+ - */ -package com.buession.httpclient.core; - -import com.buession.core.utils.StringUtils; -import com.buession.core.validator.Validate; -import com.buession.net.HttpURI; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.List; -import java.util.Map; - -/** - * 请求构建器抽象类 - * - * @param - * {@link Request} 具体实现 - * - * @author Yong.Teng - * @since 2.0.0 - */ -public abstract class AbstractRequestBuilder implements RequestBuilder { - - protected R request; - - protected URI uri; - - protected Map parameters; - - private final static Logger logger = LoggerFactory.getLogger(AbstractRequestBuilder.class); - - @Override - public RequestBuilder setProtocolVersion(ProtocolVersion protocolVersion){ - return this; - } - - @Override - public RequestBuilder setUrl(String url){ - return setUri(URI.create(url)); - } - - @Override - public RequestBuilder setUrl(URL url){ - try{ - uri = url.toURI(); - }catch(URISyntaxException e){ - if(logger.isErrorEnabled()){ - logger.error("URL {} convert to URI syntax: {}, reason: {}", url, e.getMessage(), e.getReason()); - } - throw new IllegalArgumentException(e.getMessage(), e); - } - - return this; - } - - @Override - public RequestBuilder setUri(URI uri){ - this.uri = uri; - return this; - } - - @Override - public RequestBuilder setHeaders(List
headers){ - request.setHeaders(headers); - return this; - } - - @Override - public RequestBuilder setParameters(Map parameters){ - this.parameters = parameters; - return this; - } - - @Override - public R build(){ - if(Validate.isNotEmpty(parameters)){ - request.setUri(determineRequestUri(uri, parameters)); - }else{ - request.setUri(uri); - } - - return request; - } - - private static URI determineRequestUri(final URI uri, final Map parameters){ - if(Validate.isEmpty(uri.getRawQuery())){ - return uri; - } - - final StringBuilder newQuery = new StringBuilder(uri.getRawQuery().length()); - - newQuery.append(uri.getRawQuery()); - - if(StringUtils.endsWith(uri.getRawQuery(), '&') == false){ - newQuery.append('&'); - } - - newQuery.append(HttpURI.toQueryString(parameters, false)); - - try{ - return new URI(uri.getScheme(), uri.getAuthority(), uri.getHost(), uri.getPort(), - uri.getPath(), newQuery.toString(), uri.getFragment()); - }catch(URISyntaxException e){ - if(logger.isErrorEnabled()){ - logger.error("URL {} add parameters syntax: {}, reason: {}", uri, e.getMessage(), e.getReason()); - } - return uri; - } - } - - protected static RequestBodyConverter findBodyConverter( - final Map, RequestBodyConverter> converters, - final RequestBody body){ - RequestBodyConverter converter; - Class clazz = body.getClass(); - - while(clazz != null){ - converter = converters.get(clazz); - if(converter != null){ - return converter; - } - - clazz = clazz.getSuperclass(); - } - - return null; - } - -} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/Configuration.java b/buession-httpclient/src/main/java/com/buession/httpclient/core/Configuration.java index 33369daeb..d1d94cc2f 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/core/Configuration.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/core/Configuration.java @@ -19,13 +19,15 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.core; import com.buession.net.ssl.SslConfiguration; +import java.net.InetAddress; +import java.util.Collection; import java.util.StringJoiner; /** @@ -36,7 +38,9 @@ public class Configuration { /** - * @since 2.3.0 + * 是否在多个实例之间共享连接管理器 + * + * @since 3.0.0 */ private Boolean connectionManagerShared; @@ -50,44 +54,58 @@ public class Configuration { /** * 最大连接数 */ - private int maxConnections = 5000; + private Integer maxConnections = 5000; /** * 每个路由的最大连接数 */ - private int maxPerRoute = 500; + private Integer maxPerRoute = 500; /** * 最大并发请求数量 * * @since 2.3.2 */ - private int maxRequests; + private Integer maxRequests; /** * 空闲连接存活时长,单位:毫秒 */ - private int idleConnectionTime = 60 * 1000; + private Integer idleConnectionTime = 60 * 1000; /** * 连接超时时间,单位:毫秒 */ - private int connectTimeout = 3000; + private Integer connectTimeout = 3000; /** * 从连接池获取连接的超时时间,单位:毫秒 */ - private int connectionRequestTimeout = 5000; + private Integer connectionRequestTimeout = 5000; + + /** + * The maximum time to live for persistent connections. + * + * @since 3.0.0 + */ + private Integer connectionTimeToLive = -1; /** * 读取超时时间,单位:毫秒 */ - private int readTimeout = 5000; + private Integer readTimeout = 5000; /** - * 写超时时间,单位:毫秒;小于等于 0 时,使用原生库默认写超时时间 + * 写超时时间,单位:毫秒 + */ + private Integer writeTimeout = -1; + + /** + * Determines whether the 'Expect: 100-Continue' handshake is enabled for entity enclosing methods. + * + * @since 3.0.0 */ - private int writeTimeout = -1; + private Boolean expectContinueEnabled; /** * 是否允许重定向 @@ -109,20 +127,50 @@ public class Configuration { */ private Integer maxRedirects; + /** + * Determines whether request cancellation, such as through {@code Future#cancel(boolean)}, should kill the + * underlying connection. If this option is set to false, the client will attempt to preserve the underlying + * connection by allowing the request to complete in the background, discarding the response. + * + * @since 3.0.0 + */ + private Boolean hardCancellationEnabled; + /** * 是否开启 Http Basic 认证 */ - private boolean authenticationEnabled; + private Boolean authenticationEnabled; + + /** + * Determines the order of preference for supported authentication schemes by their names when authenticating with the target host. + * + * @since 3.0.0 + */ + private Collection targetPreferredAuthSchemes; + + /** + * Determines the order of preference for supported authentication schemes by their names when authenticating with the proxy host. + * + * @since 3.0.0 + */ + private Collection proxyPreferredAuthSchemes; /** * 是否启用内容压缩 */ - private boolean contentCompressionEnabled; + private Boolean contentCompressionEnabled; /** * 是否标准化 URI */ - private boolean normalizeUri; + private Boolean normalizeUri; + + /** + * Determines the name of the cookie specification to be used for HTTP state management. + * + * @since 3.0.0 + */ + private String cookieSpec; /** * SSL 配置 @@ -132,28 +180,57 @@ public class Configuration { private SslConfiguration sslConfiguration; /** - * 返回链接管理器是否共享 + * 代理配置 + * + * @since 3.0.0 + */ + private Proxy proxy; + + /** + * 返回是否在多个实例之间共享连接管理器 * * @return True / False * - * @since 2.3.0 + * @since 3.0.0 + */ + public Boolean isConnectionManagerShared() { + return getConnectionManagerShared(); + } + + /** + * 返回是否在多个实例之间共享连接管理器 + * + * @return True / False + * + * @since 3.0.0 */ public Boolean getConnectionManagerShared() { return connectionManagerShared; } /** - * 设置链接管理器是否共享 + * 设置是否在多个实例之间共享连接管理器 * * @param connectionManagerShared - * 链接管理器是否共享 + * 是否在多个实例之间共享连接管理器 * - * @since 2.3.0 + * @since 3.0.0 */ public void setConnectionManagerShared(Boolean connectionManagerShared) { this.connectionManagerShared = connectionManagerShared; } + /** + * 返回连接失败是否重试 + * + * @return 连接失败是否重试 + * + * @since 2.3.0 + */ + public Boolean isRetryOnConnectionFailure() { + return getRetryOnConnectionFailure(); + } + /** * 返回连接失败是否重试 * @@ -182,7 +259,7 @@ public void setRetryOnConnectionFailure(Boolean retryOnConnectionFailure) { * * @return 最大连接数 */ - public int getMaxConnections() { + public Integer getMaxConnections() { return maxConnections; } @@ -192,7 +269,7 @@ public int getMaxConnections() { * @param maxConnections * 最大连接数 */ - public void setMaxConnections(int maxConnections) { + public void setMaxConnections(Integer maxConnections) { this.maxConnections = maxConnections; } @@ -201,7 +278,7 @@ public void setMaxConnections(int maxConnections) { * * @return 每个路由的最大连接数 */ - public int getMaxPerRoute() { + public Integer getMaxPerRoute() { return maxPerRoute; } @@ -211,7 +288,7 @@ public int getMaxPerRoute() { * @param maxPerRoute * 每个路由的最大连接数 */ - public void setMaxPerRoute(int maxPerRoute) { + public void setMaxPerRoute(Integer maxPerRoute) { this.maxPerRoute = maxPerRoute; } @@ -220,7 +297,7 @@ public void setMaxPerRoute(int maxPerRoute) { * * @return 最大并发请求数量 */ - public int getMaxRequests() { + public Integer getMaxRequests() { return maxRequests; } @@ -230,7 +307,7 @@ public int getMaxRequests() { * @param maxRequests * 最大并发请求数量 */ - public void setMaxRequests(int maxRequests) { + public void setMaxRequests(Integer maxRequests) { this.maxRequests = maxRequests; } @@ -239,7 +316,7 @@ public void setMaxRequests(int maxRequests) { * * @return 空闲连接存活时长 */ - public int getIdleConnectionTime() { + public Integer getIdleConnectionTime() { return idleConnectionTime; } @@ -249,7 +326,7 @@ public int getIdleConnectionTime() { * @param idleConnectionTime * 空闲连接存活时长,单位:毫秒 */ - public void setIdleConnectionTime(int idleConnectionTime) { + public void setIdleConnectionTime(Integer idleConnectionTime) { this.idleConnectionTime = idleConnectionTime; } @@ -258,7 +335,7 @@ public void setIdleConnectionTime(int idleConnectionTime) { * * @return 连接超时时间 */ - public int getConnectTimeout() { + public Integer getConnectTimeout() { return connectTimeout; } @@ -268,7 +345,7 @@ public int getConnectTimeout() { * @param connectTimeout * 连接超时时间,单位:毫秒 */ - public void setConnectTimeout(int connectTimeout) { + public void setConnectTimeout(Integer connectTimeout) { this.connectTimeout = connectTimeout; } @@ -277,7 +354,7 @@ public void setConnectTimeout(int connectTimeout) { * * @return 从连接池获取连接的超时时间 */ - public int getConnectionRequestTimeout() { + public Integer getConnectionRequestTimeout() { return connectionRequestTimeout; } @@ -287,16 +364,39 @@ public int getConnectionRequestTimeout() { * @param connectionRequestTimeout * 从连接池获取连接的超时时间,单位:毫秒 */ - public void setConnectionRequestTimeout(int connectionRequestTimeout) { + public void setConnectionRequestTimeout(Integer connectionRequestTimeout) { this.connectionRequestTimeout = connectionRequestTimeout; } + /** + * Return maximum time to live for persistent connections. + * + * @return The maximum time to live for persistent connections. + * + * @since 3.0.0 + */ + public Integer getConnectionTimeToLive() { + return connectionTimeToLive; + } + + /** + * Sets maximum time to live for persistent connections. + * + * @param connectionTimeToLive + * The maximum time to live for persistent connections. + * + * @since 3.0.0 + */ + public void setConnectionTimeToLive(Integer connectionTimeToLive) { + this.connectionTimeToLive = connectionTimeToLive; + } + /** * 获取读取超时时间,单位:毫秒 * * @return 读取超时时间 */ - public int getReadTimeout() { + public Integer getReadTimeout() { return readTimeout; } @@ -306,7 +406,7 @@ public int getReadTimeout() { * @param readTimeout * 读取超时时间,单位:毫秒 */ - public void setReadTimeout(int readTimeout) { + public void setReadTimeout(Integer readTimeout) { this.readTimeout = readTimeout; } @@ -317,7 +417,7 @@ public void setReadTimeout(int readTimeout) { * * @since 2.3.0 */ - public int getWriteTimeout() { + public Integer getWriteTimeout() { return writeTimeout; } @@ -329,10 +429,44 @@ public int getWriteTimeout() { * * @since 2.3.0 */ - public void setWriteTimeout(int writeTimeout) { + public void setWriteTimeout(Integer writeTimeout) { this.writeTimeout = writeTimeout; } + /** + * Return determines whether the 'Expect: 100-Continue' handshake is enabled for entity enclosing methods. + * + * @return true / false + * + * @since 3.0.0 + */ + public Boolean isExpectContinueEnabled() { + return getExpectContinueEnabled(); + } + + /** + * Return determines whether the 'Expect: 100-Continue' handshake is enabled for entity enclosing methods. + * + * @return true / false + * + * @since 3.0.0 + */ + public Boolean getExpectContinueEnabled() { + return expectContinueEnabled; + } + + /** + * Sets determines whether the 'Expect: 100-Continue' handshake is enabled for entity enclosing methods. + * + * @param expectContinueEnabled + * true / false + * + * @since 3.0.0 + */ + public void setExpectContinueEnabled(Boolean expectContinueEnabled) { + this.expectContinueEnabled = expectContinueEnabled; + } + /** * 获取是否允许重定向 * @@ -436,12 +570,52 @@ public void setMaxRedirects(Integer maxRedirects) { this.maxRedirects = maxRedirects; } + /** + * Return determines whether request cancellation, such as through {@code Future#cancel(boolean)}, should kill the + * underlying connection. If this option is set to false, the client will attempt to preserve the underlying + * connection by allowing the request to complete in the background, discarding the response. + * + * @return true / false + * + * @since 3.0.0 + */ + public Boolean isHardCancellationEnabled() { + return getHardCancellationEnabled(); + } + + /** + * Return determines whether request cancellation, such as through {@code Future#cancel(boolean)}, should kill the + * underlying connection. If this option is set to false, the client will attempt to preserve the underlying + * connection by allowing the request to complete in the background, discarding the response. + * + * @return true / false + * + * @since 3.0.0 + */ + public Boolean getHardCancellationEnabled() { + return hardCancellationEnabled; + } + + /** + * Sets determines whether request cancellation, such as through {@code Future#cancel(boolean)}, should kill the + * underlying connection. If this option is set to false, the client will attempt to preserve the underlying + * connection by allowing the request to complete in the background, discarding the response. + * + * @param hardCancellationEnabled + * Enabled hard cancellation + * + * @since 3.0.0 + */ + public void setHardCancellationEnabled(Boolean hardCancellationEnabled) { + this.hardCancellationEnabled = hardCancellationEnabled; + } + /** * 获取是否开启 Http Basic 认证 * * @return 是否开启 Http Basic 认证 */ - public boolean isAuthenticationEnabled() { + public Boolean isAuthenticationEnabled() { return getAuthenticationEnabled(); } @@ -450,7 +624,7 @@ public boolean isAuthenticationEnabled() { * * @return 是否开启 Http Basic 认证 */ - public boolean getAuthenticationEnabled() { + public Boolean getAuthenticationEnabled() { return authenticationEnabled; } @@ -460,16 +634,66 @@ public boolean getAuthenticationEnabled() { * @param authenticationEnabled * 是否开启 Http Basic 认证 */ - public void setAuthenticationEnabled(boolean authenticationEnabled) { + public void setAuthenticationEnabled(Boolean authenticationEnabled) { this.authenticationEnabled = authenticationEnabled; } + /** + * Return determines the order of preference for supported authentication schemes by their names when + * authenticating with the target host. + * + * @return Determines the order of preference for supported authentication schemes by their names when authenticating with the target host. + * + * @since 3.0.0 + */ + public Collection getTargetPreferredAuthSchemes() { + return targetPreferredAuthSchemes; + } + + /** + * Sets determines the order of preference for supported authentication schemes by their names when + * authenticating with the target host. + * + * @param targetPreferredAuthSchemes + * Determines the order of preference for supported authentication schemes by their names when authenticating with the target host. + * + * @since 3.0.0 + */ + public void setTargetPreferredAuthSchemes(Collection targetPreferredAuthSchemes) { + this.targetPreferredAuthSchemes = targetPreferredAuthSchemes; + } + + /** + * Return determines the order of preference for supported authentication schemes by their names when + * authenticating with the proxy host. + * + * @return Determines the order of preference for supported authentication schemes by their names when authenticating with the proxy host. + * + * @since 3.0.0 + */ + public Collection getProxyPreferredAuthSchemes() { + return proxyPreferredAuthSchemes; + } + + /** + * Sets determines the order of preference for supported authentication schemes by their names when + * authenticating with the proxy host. + * + * @param proxyPreferredAuthSchemes + * Determines the order of preference for supported authentication schemes by their names when authenticating with the proxy host. + * + * @since 3.0.0 + */ + public void setProxyPreferredAuthSchemes(Collection proxyPreferredAuthSchemes) { + this.proxyPreferredAuthSchemes = proxyPreferredAuthSchemes; + } + /** * 获取是否启用内容压缩 * * @return 是否启用内容压缩 */ - public boolean isContentCompressionEnabled() { + public Boolean isContentCompressionEnabled() { return getContentCompressionEnabled(); } @@ -478,7 +702,7 @@ public boolean isContentCompressionEnabled() { * * @return 是否启用内容压缩 */ - public boolean getContentCompressionEnabled() { + public Boolean getContentCompressionEnabled() { return contentCompressionEnabled; } @@ -488,7 +712,7 @@ public boolean getContentCompressionEnabled() { * @param contentCompressionEnabled * 是否启用内容压缩 */ - public void setContentCompressionEnabled(boolean contentCompressionEnabled) { + public void setContentCompressionEnabled(Boolean contentCompressionEnabled) { this.contentCompressionEnabled = contentCompressionEnabled; } @@ -497,7 +721,7 @@ public void setContentCompressionEnabled(boolean contentCompressionEnabled) { * * @return 是否标准化 URI */ - public boolean isNormalizeUri() { + public Boolean isNormalizeUri() { return getNormalizeUri(); } @@ -506,7 +730,7 @@ public boolean isNormalizeUri() { * * @return 是否标准化 URI */ - public boolean getNormalizeUri() { + public Boolean getNormalizeUri() { return normalizeUri; } @@ -516,10 +740,33 @@ public boolean getNormalizeUri() { * @param normalizeUri * 是否标准化 URI */ - public void setNormalizeUri(boolean normalizeUri) { + public void setNormalizeUri(Boolean normalizeUri) { this.normalizeUri = normalizeUri; } + /** + * Return determines the name of the cookie specification to be used for HTTP state management. + * + * @return Determines the name of the cookie specification to be used for HTTP state management. + * + * @since 3.0.0 + */ + public String getCookieSpec() { + return cookieSpec; + } + + /** + * Sets determines the name of the cookie specification to be used for HTTP state management. + * + * @param cookieSpec + * Determines the name of the cookie specification to be used for HTTP state management. + * + * @since 3.0.0 + */ + public void setCookieSpec(String cookieSpec) { + this.cookieSpec = cookieSpec; + } + /** * 返回 SSL 配置 * @@ -539,6 +786,29 @@ public void setSslConfiguration(SslConfiguration sslConfiguration) { this.sslConfiguration = sslConfiguration; } + /** + * 返回代理配置 + * + * @return 代理配置 + * + * @since 3.0.0 + */ + public Proxy getProxy() { + return proxy; + } + + /** + * 设置代理配置 + * + * @param proxy + * 代理配置 + * + * @since 3.0.0 + */ + public void setProxy(Proxy proxy) { + this.proxy = proxy; + } + @Override public String toString() { return new StringJoiner(", ") @@ -550,17 +820,148 @@ public String toString() { .add("idleConnectionTime: " + idleConnectionTime) .add("connectTimeout: " + connectTimeout) .add("connectionRequestTimeout: " + connectionRequestTimeout) + .add("connectionTimeToLive: " + connectionTimeToLive) .add("readTimeout: " + readTimeout) .add("writeTimeout: " + writeTimeout) + .add("expectContinueEnabled: " + expectContinueEnabled) .add("allowRedirects: " + allowRedirects) .add("relativeRedirectsAllowed: " + relativeRedirectsAllowed) .add("circularRedirectsAllowed: " + circularRedirectsAllowed) .add("maxRedirects: " + maxRedirects) + .add("hardCancellationEnabled: " + hardCancellationEnabled) .add("authenticationEnabled: " + authenticationEnabled) + .add("targetPreferredAuthSchemes: " + targetPreferredAuthSchemes) + .add("proxyPreferredAuthSchemes: " + proxyPreferredAuthSchemes) .add("contentCompressionEnabled: " + contentCompressionEnabled) .add("normalizeUri: " + normalizeUri) + .add("cookieSpec: " + cookieSpec) .add("sslConfiguration: " + sslConfiguration) + .add("proxy: " + proxy) .toString(); } + /** + * 代理配置 + * + * @author yong.teng + * @since 3.0.0 + */ + public final static class Proxy { + + /** + * The name of the scheme. + */ + private Scheme scheme; + + /** + * The inet address. + */ + private InetAddress address; + + /** + * The hostname (IP or DNS name). + */ + private String hostname; + + /** + * The port number. {@code -1} indicates the scheme default port. + */ + private int port; + + /** + * Return the name of the scheme. + * + * @return The name of the scheme. + */ + public Scheme getScheme() { + return scheme; + } + + /** + * Sets the name of the scheme. + * + * @param scheme + * The name of the scheme. + */ + public void setScheme(Scheme scheme) { + this.scheme = scheme; + } + + /** + * Return the inet address. + * + * @return The inet address. + */ + public InetAddress getAddress() { + return address; + } + + /** + * Sets the inet address. + * + * @param address + * The inet address. + */ + public void setAddress(InetAddress address) { + this.address = address; + } + + /** + * Return the hostname (IP or DNS name). + * + * @return The hostname (IP or DNS name). + */ + public String getHostname() { + return hostname; + } + + /** + * Sets the hostname (IP or DNS name). + * + * @param hostname + * The hostname (IP or DNS name). + */ + public void setHostname(String hostname) { + this.hostname = hostname; + } + + /** + * Return the port number. {@code -1} indicates the scheme default port. + * + * @return The port number. + */ + public int getPort() { + return port; + } + + /** + * Sets the port number. {@code -1} indicates the scheme default port. + * + * @param port + * The port number. + */ + public void setPort(int port) { + this.port = port; + } + + @Override + public String toString() { + return new StringJoiner(", ") + .add("scheme: " + scheme) + .add("address: " + address) + .add("hostname: " + hostname) + .add("port: " + port) + .toString(); + } + + public enum Scheme { + + HTTP, + + HTTPS + + } + + } + } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/ContentType.java b/buession-httpclient/src/main/java/com/buession/httpclient/core/ContentType.java index 827036dcd..78e27a790 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/core/ContentType.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/core/ContentType.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.core; @@ -59,34 +59,34 @@ public final class ContentType { private Charset charset; - public ContentType(final String mimeType){ + public ContentType(final String mimeType) { this.mimeType = mimeType; } - public ContentType(final String mimeType, final Charset charset){ + public ContentType(final String mimeType, final Charset charset) { this.mimeType = mimeType; this.charset = charset; } - public String getMimeType(){ + public String getMimeType() { return mimeType; } - public Charset getCharset(){ + public Charset getCharset() { return charset; } - public String valueOf(){ + public String valueOf() { return valueOf(this); } @Override - public int hashCode(){ + public int hashCode() { return Objects.hash(mimeType, charset); } @Override - public boolean equals(Object obj){ + public boolean equals(Object obj) { if(this == obj){ return true; } @@ -100,20 +100,19 @@ public boolean equals(Object obj){ } @Override - public String toString(){ + public String toString() { final StringBuilder sb = new StringBuilder(mimeType.length() + (charset == null ? 0 : 16)); sb.append(mimeType); if(charset != null){ - sb.append("; charset="); - sb.append(charset.name()); + sb.append("; charset=").append(charset.name()); } return sb.toString(); } - public static String valueOf(ContentType contentType){ + public static String valueOf(ContentType contentType) { return contentType == null ? null : contentType.toString(); } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/Header.java b/buession-httpclient/src/main/java/com/buession/httpclient/core/Header.java index 8cf612d96..8a28fee5f 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/core/Header.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/core/Header.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.core; @@ -28,7 +28,6 @@ import java.nio.charset.StandardCharsets; import java.util.Objects; -import java.util.StringJoiner; /** * HTTP 头 @@ -50,7 +49,7 @@ public class Header { /** * 构造函数 */ - public Header(){ + public Header() { } /** @@ -61,7 +60,7 @@ public Header(){ * @param value * HTTP 头值 */ - public Header(String name, String value){ + public Header(String name, String value) { this.name = name; this.value = value; } @@ -76,7 +75,7 @@ public Header(String name, String value){ * * @since 2.0.0 */ - public Header(String name, char value){ + public Header(String name, char value) { this(name, Character.toString(value)); } @@ -90,7 +89,7 @@ public Header(String name, char value){ * * @since 2.0.0 */ - public Header(String name, byte[] value){ + public Header(String name, byte[] value) { this(name, new String(value, StandardCharsets.UTF_8)); } @@ -104,7 +103,7 @@ public Header(String name, byte[] value){ * * @since 2.0.0 */ - public Header(String name, short value){ + public Header(String name, short value) { this(name, Short.toString(value)); } @@ -118,7 +117,7 @@ public Header(String name, short value){ * * @since 2.0.0 */ - public Header(String name, int value){ + public Header(String name, int value) { this(name, Integer.toString(value)); } @@ -132,7 +131,7 @@ public Header(String name, int value){ * * @since 2.0.0 */ - public Header(String name, long value){ + public Header(String name, long value) { this(name, Long.toString(value)); } @@ -146,7 +145,7 @@ public Header(String name, long value){ * * @since 2.0.0 */ - public Header(String name, float value){ + public Header(String name, float value) { this(name, Float.toString(value)); } @@ -160,7 +159,7 @@ public Header(String name, float value){ * * @since 2.0.0 */ - public Header(String name, double value){ + public Header(String name, double value) { this(name, Double.toString(value)); } @@ -169,7 +168,7 @@ public Header(String name, double value){ * * @return HTTP 头名称 */ - public String getName(){ + public String getName() { return name; } @@ -179,7 +178,7 @@ public String getName(){ * @param name * HTTP 头名称 */ - public void setName(final String name){ + public void setName(final String name) { this.name = name; } @@ -188,7 +187,7 @@ public void setName(final String name){ * * @return HTTP 头值 */ - public String getValue(){ + public String getValue() { return value; } @@ -198,17 +197,17 @@ public String getValue(){ * @param value * HTTP 头值 */ - public void setValue(final String value){ + public void setValue(final String value) { this.value = value; } @Override - public int hashCode(){ + public int hashCode() { return Objects.hash(name, value); } @Override - public boolean equals(Object obj){ + public boolean equals(Object obj) { if(this == obj){ return true; } @@ -222,11 +221,8 @@ public boolean equals(Object obj){ } @Override - public String toString(){ - return new StringJoiner(": ") - .add(name) - .add(value) - .toString(); + public String toString() { + return name + ": " + value; } } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/RequestBuilder.java b/buession-httpclient/src/main/java/com/buession/httpclient/core/RequestBuilder.java deleted file mode 100644 index 194f3178a..000000000 --- a/buession-httpclient/src/main/java/com/buession/httpclient/core/RequestBuilder.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. - * See the NOTICE file distributed with this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - * - * ========================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +-------------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | - * +-------------------------------------------------------------------------------------------------------+ - */ -package com.buession.httpclient.core; - -import java.net.URI; -import java.net.URL; -import java.util.List; -import java.util.Map; - -/** - * 请求构建器 - * - * @param - * {@link Request} 具体实现 - * - * @author Yong.Teng - * @since 2.0.0 - */ -public interface RequestBuilder { - - /** - * 设置协议及版本 - * - * @param protocolVersion - * 协议及版本 - * - * @return 请求构建器 - */ - RequestBuilder setProtocolVersion(ProtocolVersion protocolVersion); - - /** - * 设置请求 URL - * - * @param url - * 请求 URL - * - * @return 请求构建器 - */ - RequestBuilder setUrl(String url); - - /** - * 设置请求 URL - * - * @param url - * 请求 URL - * - * @return 请求构建器 - * - * @since 2.3.0 - */ - RequestBuilder setUrl(URL url); - - /** - * 设置请求 URL - * - * @param uri - * 请求 URL - * - * @return 请求构建器 - * - * @since 2.3.0 - */ - RequestBuilder setUri(URI uri); - - /** - * 设置请求头 - * - * @param headers - * 请求头 - * - * @return 请求构建器 - */ - RequestBuilder setHeaders(List
headers); - - /** - * 设置请求参数 - * - * @param parameters - * 请求参数 - * - * @return 请求构建器 - */ - RequestBuilder setParameters(Map parameters); - - /** - * GET 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder get(); - - /** - * POST 请求构建 - * - * @param body - * 请求体 - * - * @return 请求构建器 - */ - RequestBuilder post(RequestBody body); - - /** - * PATCH 请求构建 - * - * @param body - * 请求体 - * - * @return 请求构建器 - */ - RequestBuilder patch(RequestBody body); - - /** - * PUT 请求构建 - * - * @param body - * 请求体 - * - * @return 请求构建器 - */ - RequestBuilder put(RequestBody body); - - /** - * DELETE 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder delete(); - - /** - * CONNECT 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder connect(); - - /** - * TRACE 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder trace(); - - /** - * COPY 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder copy(); - - /** - * MOVE 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder move(); - - /** - * HEAD 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder head(); - - /** - * OPTIONS 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder options(); - - /** - * LINK 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder link(); - - /** - * UNLINK 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder unlink(); - - /** - * PURGE 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder purge(); - - /** - * LOCK 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder lock(); - - /** - * UNLOCK 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder unlock(); - - /** - * PROPFIND 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder propfind(); - - /** - * PROPPATCH 请求构建 - * - * @param body - * 请求体 - * - * @return 请求构建器 - */ - RequestBuilder proppatch(RequestBody body); - - /** - * REPORT 请求构建 - * - * @param body - * 请求体 - * - * @return 请求构建器 - */ - RequestBuilder report(RequestBody body); - - /** - * VIEW 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder view(); - - /** - * WRAPPED 请求构建 - * - * @return 请求构建器 - */ - RequestBuilder wrapped(); - - /** - * 构建请求 {@link Request} - * - * @return 请求 {@link Request} - */ - R build(); - -} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/StatusLine.java b/buession-httpclient/src/main/java/com/buession/httpclient/core/StatusLine.java index fc3687bd8..3f63a5edc 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/core/StatusLine.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/core/StatusLine.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.core; @@ -50,7 +50,7 @@ public class StatusLine { * 构造函数 */ @Deprecated - public StatusLine(){ + public StatusLine() { } /** @@ -61,7 +61,7 @@ public StatusLine(){ * @param statusText * 状态信息 */ - public StatusLine(int statusCode, String statusText){ + public StatusLine(int statusCode, String statusText) { setStatusCode(statusCode); this.statusText = statusText; } @@ -71,7 +71,7 @@ public StatusLine(int statusCode, String statusText){ * * @return 状态码 */ - public int getStatusCode(){ + public int getStatusCode() { return statusCode; } @@ -81,7 +81,7 @@ public int getStatusCode(){ * @param statusCode * 状态码 */ - public void setStatusCode(final int statusCode){ + public void setStatusCode(final int statusCode) { if(statusCode != 0 && (statusCode < 100 || statusCode > 599)){ throw new IllegalArgumentException("Illegal HTTP response status code: " + statusCode); } @@ -93,7 +93,7 @@ public void setStatusCode(final int statusCode){ * * @return 状态信息 */ - public String getStatusText(){ + public String getStatusText() { return statusText; } @@ -103,13 +103,13 @@ public String getStatusText(){ * @param statusText * 状态信息 */ - public void setStatusText(final String statusText){ + public void setStatusText(final String statusText) { Assert.isBlank(statusText, "HTTP response status text cloud not be null or empty."); this.statusText = statusText; } @Override - public int hashCode(){ + public int hashCode() { int result = 16; result = 32 * result + statusCode; @@ -119,7 +119,7 @@ public int hashCode(){ } @Override - public boolean equals(Object obj){ + public boolean equals(Object obj) { if(this == obj){ return true; } @@ -133,12 +133,8 @@ public boolean equals(Object obj){ } @Override - public String toString(){ - final StringBuilder sb = new StringBuilder(50); - - sb.append(statusCode).append(Constants.SPACING_STRING).append(statusText); - - return sb.toString(); + public String toString() { + return statusCode + Constants.SPACING_STRING + statusText; } } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/UrlParameter.java b/buession-httpclient/src/main/java/com/buession/httpclient/core/UrlParameter.java new file mode 100644 index 000000000..11ce9b565 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/core/UrlParameter.java @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.core; + +import com.buession.core.utils.Assert; +import com.buession.core.validator.Validate; +import com.buession.lang.Constants; + +import javax.validation.constraints.NotNull; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Objects; +import java.util.Optional; + +/** + * URL 参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class UrlParameter { + + /** + * 参数名称 + */ + private String name; + + /** + * 参数值 + */ + private String value; + + /** + * 构造函数 + */ + public UrlParameter() { + } + + /** + * 构造函数 + * + * @param name + * 参数名称 + * @param value + * 参数值 + */ + public UrlParameter(@NotNull final String name, final String value) { + setName(name); + setValue(value); + } + + /** + * 构造函数 + * + * @param name + * 参数名称 + * @param value + * 参数值 + * @param encode + * 是否编码 + */ + public UrlParameter(@NotNull final String name, final String value, final boolean encode) { + setName(name); + setValue(value, encode); + } + + /** + * 设置参数名称 + * + * @param name + * 参数名称 + */ + public void setName(@NotNull final String name) { + Assert.isBlank(name, "Parameter name cloud not be null or empty."); + this.name = name; + } + + /** + * 设置参数值 + * + * @param value + * 参数值 + */ + public void setValue(final String value) { + setValue(value, true); + } + + /** + * 设置参数值 + * + * @param value + * 参数值 + * @param encode + * 是否编码 + */ + public void setValue(final String value, final boolean encode) { + if(encode){ + try{ + this.value = value == null ? Constants.EMPTY_STRING : URLEncoder.encode(value, "UTF-8"); + }catch(UnsupportedEncodingException e){ + throw new RuntimeException("UTF-8 encoding does not support."); + } + }else{ + this.value = Optional.ofNullable(value).orElse(Constants.EMPTY_STRING); + } + } + + @Override + public int hashCode() { + return Objects.hash(name, value); + } + + @Override + public boolean equals(Object obj) { + if(this == obj){ + return true; + } + + if(obj instanceof UrlParameter){ + UrlParameter that = (UrlParameter) obj; + return Objects.equals(name, that.name) && Objects.equals(value, that.value); + } + + return false; + } + + @Override + public String toString() { + return Validate.hasText(name) ? name + '=' + value : Constants.EMPTY_STRING; + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/utils/HeaderUtils.java b/buession-httpclient/src/main/java/com/buession/httpclient/core/utils/HeaderUtils.java new file mode 100644 index 000000000..e4251b132 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/core/utils/HeaderUtils.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.core.utils; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class HeaderUtils { + + protected HeaderUtils() { + + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/utils/UriUtils.java b/buession-httpclient/src/main/java/com/buession/httpclient/core/utils/UriUtils.java new file mode 100644 index 000000000..b85b77dc1 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/core/utils/UriUtils.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.core.utils; + +import com.buession.httpclient.core.UrlParameter; +import com.buession.lang.Constants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class UriUtils { + + private final static Logger logger = LoggerFactory.getLogger(UriUtils.class); + + protected UriUtils() { + + } + + public static String buildQuery(final Map data, final boolean urlEncode) { + if(data == null){ + return null; + }else if(data.size() == 0){ + return Constants.EMPTY_STRING; + } + + final StringBuilder sb = new StringBuilder(); + + data.forEach((name, value)->{ + if(sb.length() > 0){ + sb.append('&'); + } + + sb.append(new UrlParameter(name, value == null ? null : value.toString(), urlEncode)); + }); + + return sb.toString(); + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/HttpClientBuilder.java b/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpClientConnectionManager.java similarity index 85% rename from buession-httpclient/src/main/java/com/buession/httpclient/okhttp/HttpClientBuilder.java rename to buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpClientConnectionManager.java index 213ecafc2..283198c19 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/HttpClientBuilder.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpClientConnectionManager.java @@ -19,22 +19,19 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.okhttp; +import com.buession.httpclient.conn.ConnectionManager; + /** + * OkHttp 连接管理器 + * * @author Yong.Teng + * @since 3.0.0 */ -@Deprecated -public class HttpClientBuilder extends okhttp3.HttpClientBuilder { - - private HttpClientBuilder(){ - } - - public static HttpClientBuilder create(){ - return new HttpClientBuilder(); - } +public interface OkHttpClientConnectionManager extends ConnectionManager { } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpHttpAsyncClientBuilder.java b/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpHttpAsyncClientBuilder.java deleted file mode 100644 index 7c773d8a6..000000000 --- a/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpHttpAsyncClientBuilder.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. - * See the NOTICE file distributed with this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - * - * ========================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +-------------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | - * +-------------------------------------------------------------------------------------------------------+ - */ -package com.buession.httpclient.okhttp; - -import com.buession.core.converter.mapper.PropertyMapper; -import com.buession.httpclient.conn.OkHttpNioClientConnectionManager; -import com.buession.httpclient.core.AbstractHttpClientBuilder; -import com.buession.httpclient.core.Configuration; -import com.buession.net.ssl.SslConfiguration; -import okhttp3.OkHttpClient; -import okhttp3.nio.HttpAsyncClientBuilder; - -import java.util.function.Consumer; - -/** - * okhttp3 Http Async Client Builder - * - * @author Yong.Teng - * @since 2.3.0 - */ -public class OkHttpHttpAsyncClientBuilder - extends AbstractHttpClientBuilder { - - public OkHttpHttpAsyncClientBuilder(final OkHttpNioClientConnectionManager connectionManager){ - super(connectionManager); - } - - @Override - public OkHttpClient build(Consumer consumer){ - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - final Configuration configuration = connectionManager.getConfiguration(); - final SslConfiguration sslConfiguration = configuration.getSslConfiguration(); - final HttpAsyncClientBuilder builder = HttpAsyncClientBuilder.create() - .setConnectionManager(connectionManager.getClientConnectionManager()) - .setConnectTimeout(configuration.getConnectTimeout()) - .setReadTimeout(configuration.getReadTimeout()) - .setWriteTimeout(configuration.getWriteTimeout()); - - propertyMapper.from(configuration.isAllowRedirects()).to(builder::setFollowRedirects); - - if(sslConfiguration != null){ - propertyMapper.from(sslConfiguration.getSslSocketFactory()).to(builder::setSSLSocketFactory); - propertyMapper.from(sslConfiguration.getHostnameVerifier()).to(builder::setSSLHostnameVerifier); - propertyMapper.from(sslConfiguration.getSslContext()).to(builder::setSSLContext); - } - - if(consumer != null){ - consumer.accept(builder); - } - - return builder.build(); - } - -} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpHttpClientBuilder.java b/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpHttpClientBuilder.java deleted file mode 100644 index 521f81f5b..000000000 --- a/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpHttpClientBuilder.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. - * See the NOTICE file distributed with this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - * - * ========================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +-------------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | - * +-------------------------------------------------------------------------------------------------------+ - */ -package com.buession.httpclient.okhttp; - -import com.buession.core.converter.mapper.PropertyMapper; -import com.buession.httpclient.conn.OkHttpClientConnectionManager; -import com.buession.httpclient.core.AbstractHttpClientBuilder; -import com.buession.httpclient.core.Configuration; -import com.buession.net.ssl.SslConfiguration; -import okhttp3.HttpClientBuilder; -import okhttp3.OkHttpClient; - -import java.util.function.Consumer; - -/** - * okhttp3 Http Client Builder - * - * @author Yong.Teng - * @since 2.3.0 - */ -public class OkHttpHttpClientBuilder extends AbstractHttpClientBuilder { - - public OkHttpHttpClientBuilder(final OkHttpClientConnectionManager connectionManager){ - super(connectionManager); - } - - @Override - public OkHttpClient build(Consumer consumer){ - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - final Configuration configuration = connectionManager.getConfiguration(); - final SslConfiguration sslConfiguration = configuration.getSslConfiguration(); - final HttpClientBuilder builder = HttpClientBuilder.create() - .setConnectionManager(connectionManager.getClientConnectionManager()) - .setRetryOnConnectionFailure(configuration.getRetryOnConnectionFailure()) - .setConnectTimeout(configuration.getConnectTimeout()) - .setReadTimeout(configuration.getReadTimeout()) - .setWriteTimeout(configuration.getWriteTimeout()); - - propertyMapper.from(configuration.isAllowRedirects()).to(builder::setFollowRedirects); - - if(sslConfiguration != null){ - propertyMapper.from(sslConfiguration.getSslSocketFactory()).to(builder::setSSLSocketFactory); - propertyMapper.from(sslConfiguration.getHostnameVerifier()).to(builder::setSSLHostnameVerifier); - propertyMapper.from(sslConfiguration.getSslContext()).to(builder::setSSLContext); - } - - if(consumer != null){ - consumer.accept(builder); - } - - return builder.build(); - } - -} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpNioClientConnectionManager.java b/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpNioClientConnectionManager.java new file mode 100644 index 000000000..24de6b9f5 --- /dev/null +++ b/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpNioClientConnectionManager.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.httpclient.okhttp; + +import com.buession.httpclient.conn.NioConnectionManager; + +/** + * OkHttp 异步连接管理器 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface OkHttpNioClientConnectionManager extends NioConnectionManager { + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpRequest.java b/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpRequest.java index 298f6ca7a..ec403e8f2 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpRequest.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpRequest.java @@ -24,7 +24,11 @@ */ package com.buession.httpclient.okhttp; -import com.buession.httpclient.core.Request; +import com.buession.httpclient.core.Header; +import com.buession.httpclient.core.RequestMethod; + +import java.net.URI; +import java.util.List; /** * Okhttp3 Request. @@ -32,15 +36,45 @@ * @author Yong.Teng * @since 2.3.0 */ -public class OkHttpRequest extends Request { +public class OkHttpRequest { + + private RequestMethod method; + + private URI uri; + + private List
headers; private okhttp3.Request.Builder builder; - public okhttp3.Request.Builder getRequestBuilder(){ + public RequestMethod getMethod() { + return method; + } + + public void setMethod(RequestMethod method) { + this.method = method; + } + + public URI getUri() { + return uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } + + public List
getHeaders() { + return headers; + } + + public void setHeaders(List
headers) { + this.headers = headers; + } + + public okhttp3.Request.Builder getRequestBuilder() { return builder; } - public void setRequestBuilder(okhttp3.Request.Builder builder){ + public void setRequestBuilder(okhttp3.Request.Builder builder) { this.builder = builder; } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpRequestBuilder.java b/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpRequestBuilder.java index 0e26a13b2..b2da64810 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpRequestBuilder.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/OkHttpRequestBuilder.java @@ -19,12 +19,16 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.okhttp; +import com.buession.core.builder.MapBuilder; +import com.buession.core.utils.StringUtils; +import com.buession.core.validator.Validate; import com.buession.httpclient.core.ChunkedInputStreamRequestBody; +import com.buession.httpclient.core.ContentType; import com.buession.httpclient.core.EncodedFormRequestBody; import com.buession.httpclient.core.Header; import com.buession.httpclient.core.HtmlRawRequestBody; @@ -39,7 +43,7 @@ import com.buession.httpclient.core.RequestMethod; import com.buession.httpclient.core.TextRawRequestBody; import com.buession.httpclient.core.XmlRawRequestBody; -import com.buession.httpclient.core.AbstractRequestBuilder; +import com.buession.httpclient.core.utils.UriUtils; import com.buession.httpclient.okhttp.convert.ChunkedInputStreamRequestBodyConverter; import com.buession.httpclient.okhttp.convert.EncodedFormRequestBodyConverter; import com.buession.httpclient.okhttp.convert.HtmlRawRequestBodyConverter; @@ -52,8 +56,11 @@ import com.buession.httpclient.okhttp.convert.XmlRawRequestBodyConverter; import okhttp3.FormBody; import okhttp3.Headers; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.net.URI; +import java.net.URISyntaxException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -61,14 +68,22 @@ /** * @author Yong.Teng */ -public class OkHttpRequestBuilder extends AbstractRequestBuilder { +public class OkHttpRequestBuilder { private final static okhttp3.RequestBody DEFAULT_REQUEST_BODY = new FormBody.Builder().build(); private final static Map, RequestBodyConverter> REQUEST_BODY_CONVERTS = new HashMap<>( 16, 0.8F); - static{ + protected URI uri; + + protected Map parameters; + + protected OkHttpRequest request; + + private final static Logger logger = LoggerFactory.getLogger(OkHttpRequestBuilder.class); + + static { REQUEST_BODY_CONVERTS.put(ChunkedInputStreamRequestBody.class, new ChunkedInputStreamRequestBodyConverter()); REQUEST_BODY_CONVERTS.put(EncodedFormRequestBody.class, new EncodedFormRequestBodyConverter()); REQUEST_BODY_CONVERTS.put(HtmlRawRequestBody.class, new HtmlRawRequestBodyConverter()); @@ -82,81 +97,10 @@ public class OkHttpRequestBuilder extends AbstractRequestBuilder parameters){ - return create(url).setParameters(parameters); - } - - /** - * 创建 {@link OkHttpRequestBuilder} 实例 - * - * @param url - * 请求 URL - * @param headers - * 请求头 - * - * @return {@link OkHttpRequestBuilder} 实例 - */ - @Deprecated - public static OkHttpRequestBuilder create(String url, List
headers){ - return create(url).setHeaders(headers); - } - - /** - * 创建 {@link OkHttpRequestBuilder} 实例 - * - * @param url - * 请求 URL - * @param parameters - * 请求参数 - * @param headers - * 请求头 - * - * @return {@link OkHttpRequestBuilder} 实例 - */ - @Deprecated - public static OkHttpRequestBuilder create(String url, Map parameters, List
headers){ - return create(url, parameters).setHeaders(headers); - } - /** * 创建 {@link OkHttpRequestBuilder} 实例 * @@ -167,9 +111,9 @@ public static OkHttpRequestBuilder create(String url, Map parame * * @since 2.3.0 */ - public static OkHttpRequestBuilder create(URI uri){ - final OkHttpRequestBuilder builder = create(); - builder.setUri(uri); + public static OkHttpRequestBuilder create(URI uri) { + final OkHttpRequestBuilder builder = new OkHttpRequestBuilder(); + builder.uri = uri; return builder; } @@ -185,7 +129,7 @@ public static OkHttpRequestBuilder create(URI uri){ * * @since 2.3.0 */ - public static OkHttpRequestBuilder create(URI uri, Map parameters){ + public static OkHttpRequestBuilder create(URI uri, Map parameters) { return create(uri).setParameters(parameters); } @@ -201,7 +145,7 @@ public static OkHttpRequestBuilder create(URI uri, Map parameter * * @since 2.3.0 */ - public static OkHttpRequestBuilder create(URI uri, List
headers){ + public static OkHttpRequestBuilder create(URI uri, List
headers) { return create(uri).setHeaders(headers); } @@ -219,143 +163,116 @@ public static OkHttpRequestBuilder create(URI uri, List
headers){ * * @since 2.3.0 */ - public static OkHttpRequestBuilder create(URI uri, Map parameters, List
headers){ + public static OkHttpRequestBuilder create(URI uri, Map parameters, List
headers) { return create(uri, parameters).setHeaders(headers); } - @Override - public OkHttpRequestBuilder setProtocolVersion(ProtocolVersion protocolVersion){ + public OkHttpRequestBuilder setProtocolVersion(ProtocolVersion protocolVersion) { return this; } - @Override - public OkHttpRequestBuilder setHeaders(List
headers){ + public OkHttpRequestBuilder setHeaders(List
headers) { request.setHeaders(headers); return this; } - @Override - public OkHttpRequestBuilder setParameters(Map parameters){ + public OkHttpRequestBuilder setParameters(Map parameters) { this.parameters = parameters; return this; } - @Override - public OkHttpRequestBuilder get(){ + public OkHttpRequestBuilder get() { return setRequest(new okhttp3.RequestBuilder().get(), RequestMethod.GET); } - @Override - public OkHttpRequestBuilder post(RequestBody body){ + public OkHttpRequestBuilder post(RequestBody body) { return setRequest(body == null ? new okhttp3.RequestBuilder().post() : new okhttp3.RequestBuilder().post( - buildRequestBody(body)), RequestMethod.POST); + buildRequestBody(body)).headers(builderHeaders(body)), RequestMethod.POST); } - @Override - public OkHttpRequestBuilder patch(RequestBody body){ + public OkHttpRequestBuilder patch(RequestBody body) { return setRequest(body == null ? new okhttp3.RequestBuilder().patch() : new okhttp3.RequestBuilder().patch( - buildRequestBody(body)), RequestMethod.PATCH); + buildRequestBody(body)).headers(builderHeaders(body)), RequestMethod.PATCH); } - @Override - public OkHttpRequestBuilder put(RequestBody body){ + public OkHttpRequestBuilder put(RequestBody body) { return setRequest(body == null ? new okhttp3.RequestBuilder().put() : new okhttp3.RequestBuilder().put( - buildRequestBody(body)), RequestMethod.PUT); + buildRequestBody(body)).headers(builderHeaders(body)), RequestMethod.PUT); } - @Override - public OkHttpRequestBuilder delete(){ + public OkHttpRequestBuilder delete() { return setRequest(new okhttp3.RequestBuilder().delete(), RequestMethod.DELETE); } - @Override - public OkHttpRequestBuilder connect(){ + public OkHttpRequestBuilder connect() { return setRequest(new okhttp3.RequestBuilder().connect(), RequestMethod.CONNECT); } - @Override - public OkHttpRequestBuilder trace(){ + public OkHttpRequestBuilder trace() { return setRequest(new okhttp3.RequestBuilder().trace(), RequestMethod.TRACE); } - @Override - public OkHttpRequestBuilder copy(){ + public OkHttpRequestBuilder copy() { return setRequest(new okhttp3.RequestBuilder().copy(), RequestMethod.COPY); } - @Override - public OkHttpRequestBuilder move(){ + public OkHttpRequestBuilder move() { return setRequest(new okhttp3.RequestBuilder().move(), RequestMethod.MOVE); } - @Override - public OkHttpRequestBuilder head(){ + public OkHttpRequestBuilder head() { return setRequest(new okhttp3.RequestBuilder().head(), RequestMethod.HEAD); } - @Override - public OkHttpRequestBuilder options(){ + public OkHttpRequestBuilder options() { return setRequest(new okhttp3.RequestBuilder().options(), RequestMethod.OPTIONS); } - @Override - public OkHttpRequestBuilder link(){ + public OkHttpRequestBuilder link() { return setRequest(new okhttp3.RequestBuilder().link(), RequestMethod.LINK); } - @Override - public OkHttpRequestBuilder unlink(){ + public OkHttpRequestBuilder unlink() { return setRequest(new okhttp3.RequestBuilder().unlink(), RequestMethod.UNLINK); } - @Override - public OkHttpRequestBuilder purge(){ + public OkHttpRequestBuilder purge() { return setRequest(new okhttp3.RequestBuilder().purge(), RequestMethod.PURGE); } - @Override - public OkHttpRequestBuilder lock(){ + public OkHttpRequestBuilder lock() { return setRequest(new okhttp3.RequestBuilder().lock(), RequestMethod.LOCK); } - @Override - public OkHttpRequestBuilder unlock(){ + public OkHttpRequestBuilder unlock() { return setRequest(new okhttp3.RequestBuilder().unlock(), RequestMethod.UNLOCK); } - @Override - public OkHttpRequestBuilder propfind(){ + public OkHttpRequestBuilder propfind() { return setRequest(new okhttp3.RequestBuilder().propfind(), RequestMethod.PROPFIND); } - @Override - public OkHttpRequestBuilder proppatch(RequestBody body){ + public OkHttpRequestBuilder proppatch(RequestBody body) { return setRequest( body == null ? new okhttp3.RequestBuilder().proppatch() : new okhttp3.RequestBuilder().proppatch( - buildRequestBody(body)), RequestMethod.PROPPATCH); + buildRequestBody(body)).headers(builderHeaders(body)), RequestMethod.PROPPATCH); } - @Override - public OkHttpRequestBuilder report(RequestBody body){ + public OkHttpRequestBuilder report(RequestBody body) { return setRequest( body == null ? new okhttp3.RequestBuilder().report() : new okhttp3.RequestBuilder().report( - buildRequestBody(body)), RequestMethod.REPORT); + buildRequestBody(body)).headers(builderHeaders(body)), RequestMethod.REPORT); } - @Override - public OkHttpRequestBuilder view(){ + public OkHttpRequestBuilder view() { return setRequest(new okhttp3.RequestBuilder().view(), RequestMethod.VIEW); } - @Override - public OkHttpRequestBuilder wrapped(){ + public OkHttpRequestBuilder wrapped() { return setRequest(new okhttp3.RequestBuilder().wrapped(), RequestMethod.WRAPPED); } - @Override - public com.buession.httpclient.okhttp.OkHttpRequest build(){ - com.buession.httpclient.okhttp.OkHttpRequest request = super.build(); - + public com.buession.httpclient.okhttp.OkHttpRequest build() { final Headers.Builder headersBuilder = new Headers.Builder(); if(request.getHeaders() != null){ @@ -364,20 +281,33 @@ public com.buession.httpclient.okhttp.OkHttpRequest build(){ } } - request.getRequestBuilder().url(request.getUrl()).headers(headersBuilder.build()); + request.getRequestBuilder().url(determineRequestUrl(uri, parameters)).headers(headersBuilder.build()); return request; } protected OkHttpRequestBuilder setRequest(final okhttp3.Request.Builder requestBuilder, - final RequestMethod method){ + final RequestMethod method) { request.setRequestBuilder(requestBuilder); request.setMethod(method); return this; } + private static Headers builderHeaders(final RequestBody body) { + ContentType contentType = body.getContentType(); + if(contentType == null){ + return Headers.of(); + }else{ + final Headers.Builder builder = new Headers.Builder(); + + builder.add("Content-Type", contentType.getMimeType()); + + return builder.build(); + } + } + @SuppressWarnings({"unchecked"}) - private okhttp3.RequestBody buildRequestBody(final RequestBody data){ + private okhttp3.RequestBody buildRequestBody(final RequestBody data) { if(data == null){ return DEFAULT_REQUEST_BODY; } @@ -387,9 +317,30 @@ private okhttp3.RequestBody buildRequestBody(final RequestBody data){ return convert == null ? DEFAULT_REQUEST_BODY : convert.convert(data); } - @Deprecated - public final static class OkHttpRequest extends com.buession.httpclient.okhttp.OkHttpRequest { + private static String determineRequestUrl(final URI uri, final Map parameters) { + if(Validate.isEmpty(uri.getRawQuery())){ + return uri.toString(); + } + + final StringBuilder newQuery = new StringBuilder(uri.getRawQuery().length()); + + newQuery.append(uri.getRawQuery()); + + if(StringUtils.endsWith(uri.getRawQuery(), '&') == false){ + newQuery.append('&'); + } + + newQuery.append(UriUtils.buildQuery(parameters, false)); + try{ + return new URI(uri.getScheme(), uri.getAuthority(), uri.getHost(), uri.getPort(), + uri.getPath(), newQuery.toString(), uri.getFragment()).toString(); + }catch(URISyntaxException e){ + if(logger.isErrorEnabled()){ + logger.error("URL {} add parameters syntax: {}, reason: {}", uri, e.getMessage(), e.getReason()); + } + return uri.toString(); + } } } \ No newline at end of file diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/nio/DefaultCallback.java b/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/nio/DefaultCallback.java index 71431595b..e52ebadc5 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/nio/DefaultCallback.java +++ b/buession-httpclient/src/main/java/com/buession/httpclient/okhttp/nio/DefaultCallback.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient.okhttp.nio; @@ -37,17 +37,17 @@ */ public class DefaultCallback extends BaseCallback implements okhttp3.Callback { - public DefaultCallback(final Callback delegate){ + public DefaultCallback(final Callback delegate) { super(delegate); } @Override - public void onFailure(@NotNull okhttp3.Call call, @NotNull IOException e){ + public void onFailure(@NotNull okhttp3.Call call, @NotNull IOException e) { delegate.failed(e); } @Override - public void onResponse(@NotNull okhttp3.Call call, @NotNull okhttp3.Response response) throws IOException{ + public void onResponse(@NotNull okhttp3.Call call, @NotNull okhttp3.Response response) { final OkHttpResponseBuilder httpResponseBuilder = new OkHttpResponseBuilder(); delegate.completed(httpResponseBuilder.build(response)); } diff --git a/buession-httpclient/src/main/java/okhttp3/HttpClientBuilder.java b/buession-httpclient/src/main/java/okhttp3/HttpClientBuilder.java index f9cc82127..745df694e 100644 --- a/buession-httpclient/src/main/java/okhttp3/HttpClientBuilder.java +++ b/buession-httpclient/src/main/java/okhttp3/HttpClientBuilder.java @@ -48,10 +48,7 @@ public static HttpClientBuilder create() { } public HttpClientBuilder setRetryOnConnectionFailure(Boolean retryOnConnectionFailure) { - if(retryOnConnectionFailure != null){ - builder.retryOnConnectionFailure(retryOnConnectionFailure); - } - + Optional.ofNullable(retryOnConnectionFailure).ifPresent(builder::retryOnConnectionFailure); return this; } @@ -80,33 +77,22 @@ public HttpClientBuilder setWriteTimeout(long writeTimeout) { } public HttpClientBuilder setFollowRedirects(Boolean followRedirects) { - if(followRedirects != null){ - builder.followRedirects(followRedirects); - } - + Optional.ofNullable(followRedirects).ifPresent(builder::followRedirects); + Optional.ofNullable(followRedirects).ifPresent(builder::followSslRedirects); return this; } public HttpClientBuilder setSSLSocketFactory(SSLSocketFactory sslSocketFactory) { - if(sslSocketFactory != null){ - builder.sslSocketFactory(sslSocketFactory); - } - + Optional.ofNullable(sslSocketFactory).ifPresent(builder::sslSocketFactory); return this; } public HttpClientBuilder setSSLHostnameVerifier(HostnameVerifier hostnameVerifier) { - if(hostnameVerifier != null){ - builder.hostnameVerifier(hostnameVerifier); - } - + Optional.ofNullable(hostnameVerifier).ifPresent(builder::hostnameVerifier); return this; } public HttpClientBuilder setSSLContext(SSLContext sslContext) { - if(sslContext != null){ - } - return this; } @@ -116,8 +102,9 @@ public HttpClientBuilder setConnectionManager(HttpClientConnectionManager connec } public OkHttpClient build() { - Optional.ofNullable(connectionManager) - .ifPresent((connectionManager)->builder.connectionPool(connectionManager.getConnectionPool())); + if(connectionManager != null){ + builder.connectionPool(connectionManager.getConnectionPool()); + } OkHttpClient client = builder.build(); @@ -125,7 +112,9 @@ public OkHttpClient build() { if(connectionManager.getMaxRequests() > 0){ client.dispatcher().setMaxRequests(connectionManager.getMaxRequests()); } - client.dispatcher().setMaxRequestsPerHost(connectionManager.getMaxRequestsPerHost()); + if(connectionManager.getMaxRequestsPerHost() > 0){ + client.dispatcher().setMaxRequestsPerHost(connectionManager.getMaxRequestsPerHost()); + } } return client; diff --git a/buession-httpclient/src/main/java/okhttp3/HttpClientConnectionManager.java b/buession-httpclient/src/main/java/okhttp3/HttpClientConnectionManager.java index 370832e19..b2996c023 100644 --- a/buession-httpclient/src/main/java/okhttp3/HttpClientConnectionManager.java +++ b/buession-httpclient/src/main/java/okhttp3/HttpClientConnectionManager.java @@ -37,6 +37,9 @@ */ public class HttpClientConnectionManager implements Closeable { + /** + * 连接池 + */ private ConnectionPool connectionPool; /** @@ -67,13 +70,27 @@ public class HttpClientConnectionManager implements Closeable { */ private int maxRequestsPerHost; + /** + * 构造函数 + */ public HttpClientConnectionManager() { } + /** + * 构造函数 + * + * @param connectionPool + * 连接池 + */ public HttpClientConnectionManager(ConnectionPool connectionPool) { this.connectionPool = connectionPool; } + /** + * 返回连接池 + * + * @return 连接池 + */ public ConnectionPool getConnectionPool() { if(connectionPool == null){ connectionPool = new ConnectionPool(maxConnections, idleConnectionTime, TimeUnit.MILLISECONDS); @@ -82,6 +99,12 @@ public ConnectionPool getConnectionPool() { return connectionPool; } + /** + * 设置连接池 + * + * @param connectionPool + * 连接池 + */ public void setConnectionPool(ConnectionPool connectionPool) { this.connectionPool = connectionPool; } diff --git a/buession-httpclient/src/main/java/okhttp3/nio/HttpAsyncClientBuilder.java b/buession-httpclient/src/main/java/okhttp3/nio/HttpAsyncClientBuilder.java index 1a9e9ae94..e4ed6381c 100644 --- a/buession-httpclient/src/main/java/okhttp3/nio/HttpAsyncClientBuilder.java +++ b/buession-httpclient/src/main/java/okhttp3/nio/HttpAsyncClientBuilder.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package okhttp3.nio; @@ -29,6 +29,7 @@ import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; +import java.util.Optional; import java.util.concurrent.TimeUnit; /** @@ -48,6 +49,11 @@ public static HttpAsyncClientBuilder create() { return new HttpAsyncClientBuilder(); } + public HttpAsyncClientBuilder setRetryOnConnectionFailure(Boolean retryOnConnectionFailure) { + Optional.ofNullable(retryOnConnectionFailure).ifPresent(builder::retryOnConnectionFailure); + return this; + } + public HttpAsyncClientBuilder setConnectTimeout(long connectTimeout) { if(connectTimeout > -1){ builder.connectTimeout(connectTimeout, TimeUnit.MILLISECONDS); @@ -73,26 +79,18 @@ public HttpAsyncClientBuilder setWriteTimeout(long writeTimeout) { } public HttpAsyncClientBuilder setFollowRedirects(Boolean followRedirects) { - if(followRedirects != null){ - builder.followRedirects(followRedirects); - } - + Optional.ofNullable(followRedirects).ifPresent(builder::followRedirects); + Optional.ofNullable(followRedirects).ifPresent(builder::followSslRedirects); return this; } public HttpAsyncClientBuilder setSSLSocketFactory(SSLSocketFactory sslSocketFactory) { - if(sslSocketFactory != null){ - builder.sslSocketFactory(sslSocketFactory); - } - + Optional.ofNullable(sslSocketFactory).ifPresent(builder::sslSocketFactory); return this; } public HttpAsyncClientBuilder setSSLHostnameVerifier(HostnameVerifier hostnameVerifier) { - if(hostnameVerifier != null){ - builder.hostnameVerifier(hostnameVerifier); - } - + Optional.ofNullable(hostnameVerifier).ifPresent(builder::hostnameVerifier); return this; } @@ -116,7 +114,9 @@ public OkHttpClient build() { if(connectionManager.getMaxRequests() > 0){ client.dispatcher().setMaxRequests(connectionManager.getMaxRequests()); } - client.dispatcher().setMaxRequestsPerHost(connectionManager.getMaxRequestsPerHost()); + if(connectionManager.getMaxRequestsPerHost() > 0){ + client.dispatcher().setMaxRequestsPerHost(connectionManager.getMaxRequestsPerHost()); + } } return client; diff --git a/buession-httpclient/src/main/java/okhttp3/nio/NioHttpClientConnectionManager.java b/buession-httpclient/src/main/java/okhttp3/nio/NioHttpClientConnectionManager.java index a127c3366..8fe1e771b 100644 --- a/buession-httpclient/src/main/java/okhttp3/nio/NioHttpClientConnectionManager.java +++ b/buession-httpclient/src/main/java/okhttp3/nio/NioHttpClientConnectionManager.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package okhttp3.nio; @@ -28,6 +28,7 @@ import java.io.Closeable; import java.io.IOException; +import java.util.Optional; import java.util.concurrent.TimeUnit; /** @@ -38,6 +39,9 @@ */ public class NioHttpClientConnectionManager implements Closeable { + /** + * 连接池 + */ private ConnectionPool connectionPool; /** @@ -60,13 +64,27 @@ public class NioHttpClientConnectionManager implements Closeable { */ private int maxRequestsPerHost; + /** + * 构造函数 + */ public NioHttpClientConnectionManager() { } + /** + * 构造函数 + * + * @param connectionPool + * 连接池 + */ public NioHttpClientConnectionManager(ConnectionPool connectionPool) { this.connectionPool = connectionPool; } + /** + * 返回连接池 + * + * @return 连接池 + */ public ConnectionPool getConnectionPool() { if(connectionPool == null){ connectionPool = new ConnectionPool(maxConnections, idleConnectionTime, TimeUnit.MILLISECONDS); @@ -75,6 +93,12 @@ public ConnectionPool getConnectionPool() { return connectionPool; } + /** + * 设置连接池 + * + * @param connectionPool + * 连接池 + */ public void setConnectionPool(ConnectionPool connectionPool) { this.connectionPool = connectionPool; } @@ -159,9 +183,7 @@ public void setMaxRequestsPerHost(int maxRequestsPerHost) { @Override public void close() throws IOException { - if(connectionPool != null){ - connectionPool.evictAll(); - } + Optional.ofNullable(connectionPool).ifPresent(ConnectionPool::evictAll); } } diff --git a/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpConnect.java b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpConnect.java new file mode 100644 index 000000000..4db271171 --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpConnect.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2021 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.hc.client5.http.classic.methods; + +import com.buession.httpclient.core.RequestMethod; + +import java.net.URI; + +/** + * Connect 请求 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HttpConnect extends HttpUriRequestBase { + + private final static long serialVersionUID = -2937305426353458488L; + + public final static String METHOD_NAME = RequestMethod.CONNECT.name(); + + /** + * 构造函数 + * + * @param uri + * URL {@link URI} + */ + public HttpConnect(final URI uri) { + super(METHOD_NAME, uri); + } + + /** + * 构造函数 + * + * @param url + * URL {@link URI} + * + * @throws IllegalArgumentException + * if the uri is invalid. + */ + public HttpConnect(final String url) { + this(URI.create(url)); + } + +} diff --git a/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpCopy.java b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpCopy.java new file mode 100644 index 000000000..f05648c7f --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpCopy.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.hc.client5.http.classic.methods; + +import com.buession.httpclient.core.RequestMethod; + +import java.net.URI; + +/** + * Copy 请求 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HttpCopy extends HttpUriRequestBase { + + private final static long serialVersionUID = 8950154360140445029L; + + public final static String METHOD_NAME = RequestMethod.COPY.name(); + + /** + * 构造函数 + * + * @param uri + * URL {@link URI} + */ + public HttpCopy(final URI uri) { + super(METHOD_NAME, uri); + } + + /** + * 构造函数 + * + * @param url + * URL {@link URI} + * + * @throws IllegalArgumentException + * if the uri is invalid. + */ + public HttpCopy(final String url) { + this(URI.create(url)); + } + +} diff --git a/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpLink.java b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpLink.java new file mode 100644 index 000000000..31eee9ac9 --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpLink.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.hc.client5.http.classic.methods; + +import com.buession.httpclient.core.RequestMethod; +import org.apache.http.client.methods.HttpRequestBase; + +import java.net.URI; + +/** + * Link 请求 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HttpLink extends HttpUriRequestBase { + + private final static long serialVersionUID = 7803319799160829554L; + + public final static String METHOD_NAME = RequestMethod.LINK.name(); + + /** + * 构造函数 + * + * @param uri + * URL {@link URI} + */ + public HttpLink(final URI uri) { + super(METHOD_NAME, uri); + } + + /** + * 构造函数 + * + * @param url + * URL {@link URI} + * + * @throws IllegalArgumentException + * if the uri is invalid. + */ + public HttpLink(final String url) { + this(URI.create(url)); + } + +} diff --git a/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpLock.java b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpLock.java new file mode 100644 index 000000000..cda59a716 --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpLock.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.hc.client5.http.classic.methods; + +import com.buession.httpclient.core.RequestMethod; + +import java.net.URI; + +/** + * Lock 请求 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HttpLock extends HttpUriRequestBase { + + private final static long serialVersionUID = 4113358411193026567L; + + public final static String METHOD_NAME = RequestMethod.LOCK.name(); + + /** + * 构造函数 + * + * @param uri + * URL {@link URI} + */ + public HttpLock(final URI uri) { + super(METHOD_NAME, uri); + } + + /** + * 构造函数 + * + * @param url + * URL {@link URI} + * + * @throws IllegalArgumentException + * if the uri is invalid. + */ + public HttpLock(final String url) { + this(URI.create(url)); + } + +} diff --git a/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpMove.java b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpMove.java new file mode 100644 index 000000000..8a32064a9 --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpMove.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.hc.client5.http.classic.methods; + +import com.buession.httpclient.core.RequestMethod; + +import java.net.URI; + +/** + * Move 请求 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HttpMove extends HttpUriRequestBase { + + private final static long serialVersionUID = 1438500200195481869L; + + public final static String METHOD_NAME = RequestMethod.MOVE.name(); + + /** + * 构造函数 + * + * @param uri + * URL {@link URI} + */ + public HttpMove(final URI uri) { + super(METHOD_NAME, uri); + } + + /** + * 构造函数 + * + * @param url + * URL {@link URI} + * + * @throws IllegalArgumentException + * if the uri is invalid. + */ + public HttpMove(final String url) { + this(URI.create(url)); + } + +} diff --git a/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPropPatch.java b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPropPatch.java new file mode 100644 index 000000000..4255da9b7 --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPropPatch.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.hc.client5.http.classic.methods; + +import com.buession.httpclient.core.RequestMethod; + +import java.net.URI; + +/** + * PropPatch 请求 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HttpPropPatch extends HttpUriRequestBase { + + private final static long serialVersionUID = 3655207024879026336L; + + public final static String METHOD_NAME = RequestMethod.PROPPATCH.name(); + + /** + * 构造函数 + * + * @param uri + * URL {@link URI} + */ + public HttpPropPatch(final URI uri) { + super(METHOD_NAME, uri); + } + + /** + * 构造函数 + * + * @param url + * URL {@link URI} + * + * @throws IllegalArgumentException + * if the uri is invalid. + */ + public HttpPropPatch(final String url) { + this(URI.create(url)); + } + +} diff --git a/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPropfind.java b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPropfind.java new file mode 100644 index 000000000..ba9436871 --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPropfind.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.hc.client5.http.classic.methods; + +import com.buession.httpclient.core.RequestMethod; + +import java.net.URI; + +/** + * Propfind 请求 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HttpPropfind extends HttpUriRequestBase { + + private final static long serialVersionUID = -5431406259309038848L; + + public final static String METHOD_NAME = RequestMethod.PROPFIND.name(); + + /** + * 构造函数 + * + * @param uri + * URL {@link URI} + */ + public HttpPropfind(final URI uri) { + super(METHOD_NAME, uri); + } + + /** + * 构造函数 + * + * @param url + * URL {@link URI} + * + * @throws IllegalArgumentException + * if the uri is invalid. + */ + public HttpPropfind(final String url) { + this(URI.create(url)); + } + +} diff --git a/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPurge.java b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPurge.java new file mode 100644 index 000000000..c1db420dd --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpPurge.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.hc.client5.http.classic.methods; + +import com.buession.httpclient.core.RequestMethod; + +import java.net.URI; + +/** + * Purge 请求 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HttpPurge extends HttpUriRequestBase { + + private final static long serialVersionUID = 6052904597397464895L; + + public final static String METHOD_NAME = RequestMethod.PURGE.name(); + + /** + * 构造函数 + * + * @param uri + * URL {@link URI} + */ + public HttpPurge(final URI uri) { + super(METHOD_NAME, uri); + } + + /** + * 构造函数 + * + * @param url + * URL {@link URI} + * + * @throws IllegalArgumentException + * if the uri is invalid. + */ + public HttpPurge(final String url) { + this(URI.create(url)); + } + +} diff --git a/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpReport.java b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpReport.java new file mode 100644 index 000000000..cabb31965 --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpReport.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.hc.client5.http.classic.methods; + +import com.buession.httpclient.core.RequestMethod; + +import java.net.URI; + +/** + * Report 请求 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HttpReport extends HttpUriRequestBase { + + private final static long serialVersionUID = -8544688758355815948L; + + public final static String METHOD_NAME = RequestMethod.REPORT.name(); + + /** + * 构造函数 + * + * @param uri + * URL {@link URI} + */ + public HttpReport(final URI uri) { + super(METHOD_NAME, uri); + } + + /** + * 构造函数 + * + * @param url + * URL {@link URI} + * + * @throws IllegalArgumentException + * if the uri is invalid. + */ + public HttpReport(final String url) { + this(URI.create(url)); + } + +} diff --git a/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUnlink.java b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUnlink.java new file mode 100644 index 000000000..1d49c8515 --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUnlink.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.hc.client5.http.classic.methods; + +import com.buession.httpclient.core.RequestMethod; + +import java.net.URI; + +/** + * Unlink 请求 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HttpUnlink extends HttpUriRequestBase { + + private final static long serialVersionUID = 9144467318123192891L; + + public final static String METHOD_NAME = RequestMethod.UNLINK.name(); + + /** + * 构造函数 + * + * @param uri + * URL {@link URI} + */ + public HttpUnlink(final URI uri) { + super(METHOD_NAME, uri); + } + + /** + * 构造函数 + * + * @param url + * URL {@link URI} + * + * @throws IllegalArgumentException + * if the uri is invalid. + */ + public HttpUnlink(final String url) { + this(URI.create(url)); + } + +} diff --git a/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUnlock.java b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUnlock.java new file mode 100644 index 000000000..bf40f3c33 --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpUnlock.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.hc.client5.http.classic.methods; + +import com.buession.httpclient.core.RequestMethod; + +import java.net.URI; + +/** + * Unlock 请求 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HttpUnlock extends HttpUriRequestBase { + + private final static long serialVersionUID = 3111166121990510480L; + + public final static String METHOD_NAME = RequestMethod.UNLOCK.name(); + + /** + * 构造函数 + * + * @param uri + * URL {@link URI} + */ + public HttpUnlock(final URI uri) { + super(METHOD_NAME, uri); + } + + /** + * 构造函数 + * + * @param url + * URL {@link URI} + * + * @throws IllegalArgumentException + * if the uri is invalid. + */ + public HttpUnlock(final String url) { + this(URI.create(url)); + } + +} diff --git a/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpView.java b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpView.java new file mode 100644 index 000000000..30613efe9 --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpView.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.hc.client5.http.classic.methods; + +import com.buession.httpclient.core.RequestMethod; + +import java.net.URI; + +/** + * View 请求 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HttpView extends HttpUriRequestBase { + + private final static long serialVersionUID = 4756587476874712045L; + + public final static String METHOD_NAME = RequestMethod.VIEW.name(); + + /** + * 构造函数 + * + * @param uri + * URL {@link URI} + */ + public HttpView(final URI uri) { + super(METHOD_NAME, uri); + } + + /** + * 构造函数 + * + * @param url + * URL {@link URI} + * + * @throws IllegalArgumentException + * if the uri is invalid. + */ + public HttpView(final String url) { + this(URI.create(url)); + } + +} diff --git a/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpWrapped.java b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpWrapped.java new file mode 100644 index 000000000..22ed4b1ab --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/HttpWrapped.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.hc.client5.http.classic.methods; + +import com.buession.httpclient.core.RequestMethod; + +import java.net.URI; + +/** + * Wrapped 请求 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HttpWrapped extends HttpUriRequestBase { + + private final static long serialVersionUID = 1337381773124144587L; + + public final static String METHOD_NAME = RequestMethod.WRAPPED.name(); + + /** + * 构造函数 + * + * @param uri + * URL {@link URI} + */ + public HttpWrapped(final URI uri) { + super(METHOD_NAME, uri); + } + + /** + * 构造函数 + * + * @param url + * URL {@link URI} + * + * @throws IllegalArgumentException + * if the uri is invalid. + */ + public HttpWrapped(final String url) { + this(URI.create(url)); + } + +} diff --git a/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/package-info.java b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/package-info.java new file mode 100644 index 000000000..6d5582820 --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/client5/http/classic/methods/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package org.apache.hc.client5.http.classic.methods; \ No newline at end of file diff --git a/buession-httpclient/src/main/java/org/apache/hc/core5/http/io/entity/ChunkedInputStreamEntity.java b/buession-httpclient/src/main/java/org/apache/hc/core5/http/io/entity/ChunkedInputStreamEntity.java new file mode 100644 index 000000000..5f05e3624 --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/core5/http/io/entity/ChunkedInputStreamEntity.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.hc.core5.http.io.entity; + +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.util.Args; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * A streamed, non-repeatable and chunked entity that obtains its content from an {@link InputStream}. + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class ChunkedInputStreamEntity extends AbstractHttpEntity { + + private final InputStream content; + + private final long length; + + public ChunkedInputStreamEntity(final InputStream inputStream, final long length, final ContentType contentType, + final String contentEncoding) { + super(contentType, contentEncoding, true); + this.content = Args.notNull(inputStream, "Source input stream"); + this.length = length; + } + + public ChunkedInputStreamEntity(final InputStream inputStream, final long length, final ContentType contentType) { + this(inputStream, length, contentType, null); + } + + public ChunkedInputStreamEntity(final InputStream inputStream, final ContentType contentType) { + this(inputStream, -1, contentType, null); + } + + @Override + public final boolean isRepeatable() { + return false; + } + + /** + * @return the content length or {@code -1} if unknown + */ + @Override + public final long getContentLength() { + return this.length; + } + + @Override + public final InputStream getContent() throws IOException { + return this.content; + } + + /** + * Writes bytes from the {@code InputStream} this entity was constructed + * with to an {@code OutputStream}. The content length + * determines how many bytes are written. If the length is unknown ({@code -1}), the + * stream will be completely consumed (to the end of the stream). + */ + @Override + public final void writeTo(final OutputStream outStream) throws IOException { + Args.notNull(outStream, "Output stream"); + try(final InputStream inStream = this.content){ + final byte[] buffer = new byte[OUTPUT_BUFFER_SIZE]; + int readLen; + if(this.length < 0){ + // consume until EOF + while((readLen = inStream.read(buffer)) != -1){ + outStream.write(buffer, 0, readLen); + } + }else{ + // consume no more than length + long remaining = this.length; + while(remaining > 0){ + readLen = inStream.read(buffer, 0, (int) Math.min(OUTPUT_BUFFER_SIZE, remaining)); + if(readLen == -1){ + break; + } + outStream.write(buffer, 0, readLen); + remaining -= readLen; + } + } + } + } + + @Override + public final boolean isStreaming() { + return true; + } + + @Override + public final void close() throws IOException { + content.close(); + } + +} diff --git a/buession-httpclient/src/main/java/org/apache/hc/core5/http/io/entity/ReleasableInputStreamEntity.java b/buession-httpclient/src/main/java/org/apache/hc/core5/http/io/entity/ReleasableInputStreamEntity.java new file mode 100644 index 000000000..e50de30e0 --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/core5/http/io/entity/ReleasableInputStreamEntity.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package org.apache.hc.core5.http.io.entity; + +import com.buession.httpclient.core.io.Releasable; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.util.Args; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * A streamed, repeatable entity that obtains its content from an {@link InputStream}. + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class ReleasableInputStreamEntity extends AbstractHttpEntity implements Releasable { + + private final InputStream content; + + private final long length; + + public ReleasableInputStreamEntity(final InputStream inputStream, final long length, final ContentType contentType, + final String contentEncoding) { + super(contentType, contentEncoding); + this.content = Args.notNull(inputStream, "Source input stream"); + this.length = length; + } + + public ReleasableInputStreamEntity(final InputStream inputStream, final long length, + final ContentType contentType) { + this(inputStream, length, contentType, null); + } + + public ReleasableInputStreamEntity(final InputStream inputStream, final ContentType contentType) { + this(inputStream, -1, contentType, null); + } + + @Override + public final boolean isRepeatable() { + try{ + return getContent().markSupported(); + }catch(IOException e){ + return false; + } + } + + /** + * @return the content length or {@code -1} if unknown + */ + @Override + public final long getContentLength() { + return length; + } + + @Override + public final InputStream getContent() throws IOException { + return content; + } + + /** + * Writes bytes from the {@code InputStream} this entity was constructed + * with to an {@code OutputStream}. The content length + * determines how many bytes are written. If the length is unknown ({@code -1}), the + * stream will be completely consumed (to the end of the stream). + */ + @Override + public final void writeTo(final OutputStream outStream) throws IOException { + Args.notNull(outStream, "Output stream"); + try(final InputStream inStream = this.content){ + final byte[] buffer = new byte[OUTPUT_BUFFER_SIZE]; + int readLen; + if(this.length < 0){ + // consume until EOF + while((readLen = inStream.read(buffer)) != -1){ + outStream.write(buffer, 0, readLen); + } + }else{ + // consume no more than length + long remaining = this.length; + while(remaining > 0){ + readLen = inStream.read(buffer, 0, (int) Math.min(OUTPUT_BUFFER_SIZE, remaining)); + if(readLen == -1){ + break; + } + outStream.write(buffer, 0, readLen); + remaining -= readLen; + } + } + } + } + + @Override + public final boolean isStreaming() { + return true; + } + + @Override + public final void close() throws IOException { + content.close(); + } + + @Override + public void release() { + try{ + this.doRelease(); + }catch(IOException e){ + + } + } + + private void doRelease() throws IOException { + try{ + getContent().close(); + }catch(Exception e){ + throw new IOException("Unexpected io exception when trying to close input stream"); + } + } + +} diff --git a/buession-httpclient/src/main/java/org/apache/hc/core5/http/io/entity/package-info.java b/buession-httpclient/src/main/java/org/apache/hc/core5/http/io/entity/package-info.java new file mode 100644 index 000000000..554d8a9be --- /dev/null +++ b/buession-httpclient/src/main/java/org/apache/hc/core5/http/io/entity/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package org.apache.hc.core5.http.io.entity; \ No newline at end of file diff --git a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpConnect.java b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpConnect.java index bbcc1b55d..e735ad183 100644 --- a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpConnect.java +++ b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpConnect.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package org.apache.http.client.methods; @@ -29,6 +29,8 @@ import java.net.URI; /** + * Connect 请求 + * * @author Yong.Teng */ public class HttpConnect extends HttpRequestBase { @@ -38,7 +40,7 @@ public class HttpConnect extends HttpRequestBase { /** * 构造函数 */ - public HttpConnect(){ + public HttpConnect() { super(); } @@ -48,7 +50,7 @@ public HttpConnect(){ * @param uri * URL {@link URI} */ - public HttpConnect(final URI uri){ + public HttpConnect(final URI uri) { super(); setURI(uri); } @@ -62,13 +64,13 @@ public HttpConnect(final URI uri){ * @throws IllegalArgumentException * if the uri is invalid. */ - public HttpConnect(final String uri){ + public HttpConnect(final String uri) { super(); setURI(URI.create(uri)); } @Override - public String getMethod(){ + public String getMethod() { return METHOD_NAME; } diff --git a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpCopy.java b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpCopy.java index 8b7c2ce3d..e64d16a08 100644 --- a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpCopy.java +++ b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpCopy.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package org.apache.http.client.methods; @@ -29,6 +29,8 @@ import java.net.URI; /** + * Copy 请求 + * * @author Yong.Teng */ public class HttpCopy extends HttpRequestBase { @@ -38,7 +40,7 @@ public class HttpCopy extends HttpRequestBase { /** * 构造函数 */ - public HttpCopy(){ + public HttpCopy() { super(); } @@ -48,7 +50,7 @@ public HttpCopy(){ * @param uri * URL {@link URI} */ - public HttpCopy(final URI uri){ + public HttpCopy(final URI uri) { super(); setURI(uri); } @@ -62,13 +64,13 @@ public HttpCopy(final URI uri){ * @throws IllegalArgumentException * if the uri is invalid. */ - public HttpCopy(final String uri){ + public HttpCopy(final String uri) { super(); setURI(URI.create(uri)); } @Override - public String getMethod(){ + public String getMethod() { return METHOD_NAME; } diff --git a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpLink.java b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpLink.java index 5aa150e42..b650dfb0a 100644 --- a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpLink.java +++ b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpLink.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package org.apache.http.client.methods; @@ -29,6 +29,8 @@ import java.net.URI; /** + * Link 请求 + * * @author Yong.Teng */ public class HttpLink extends HttpRequestBase { @@ -38,7 +40,7 @@ public class HttpLink extends HttpRequestBase { /** * 构造函数 */ - public HttpLink(){ + public HttpLink() { super(); } @@ -48,7 +50,7 @@ public HttpLink(){ * @param uri * URL {@link URI} */ - public HttpLink(final URI uri){ + public HttpLink(final URI uri) { super(); setURI(uri); } @@ -62,13 +64,13 @@ public HttpLink(final URI uri){ * @throws IllegalArgumentException * if the uri is invalid. */ - public HttpLink(final String uri){ + public HttpLink(final String uri) { super(); setURI(URI.create(uri)); } @Override - public String getMethod(){ + public String getMethod() { return METHOD_NAME; } diff --git a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpLock.java b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpLock.java index 2d2d3c2b6..24cf1312e 100644 --- a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpLock.java +++ b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpLock.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package org.apache.http.client.methods; @@ -29,6 +29,8 @@ import java.net.URI; /** + * Lock 请求 + * * @author Yong.Teng */ public class HttpLock extends HttpRequestBase { @@ -38,7 +40,7 @@ public class HttpLock extends HttpRequestBase { /** * 构造函数 */ - public HttpLock(){ + public HttpLock() { super(); } @@ -48,7 +50,7 @@ public HttpLock(){ * @param uri * URL {@link URI} */ - public HttpLock(final URI uri){ + public HttpLock(final URI uri) { super(); setURI(uri); } @@ -62,13 +64,13 @@ public HttpLock(final URI uri){ * @throws IllegalArgumentException * if the uri is invalid. */ - public HttpLock(final String uri){ + public HttpLock(final String uri) { super(); setURI(URI.create(uri)); } @Override - public String getMethod(){ + public String getMethod() { return METHOD_NAME; } diff --git a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpMove.java b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpMove.java index 1029e9c3c..c152338c4 100644 --- a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpMove.java +++ b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpMove.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package org.apache.http.client.methods; @@ -29,6 +29,8 @@ import java.net.URI; /** + * Move 请求 + * * @author Yong.Teng */ public class HttpMove extends HttpRequestBase { @@ -38,7 +40,7 @@ public class HttpMove extends HttpRequestBase { /** * 构造函数 */ - public HttpMove(){ + public HttpMove() { super(); } @@ -48,7 +50,7 @@ public HttpMove(){ * @param uri * URL {@link URI} */ - public HttpMove(final URI uri){ + public HttpMove(final URI uri) { super(); setURI(uri); } @@ -62,13 +64,13 @@ public HttpMove(final URI uri){ * @throws IllegalArgumentException * if the uri is invalid. */ - public HttpMove(final String uri){ + public HttpMove(final String uri) { super(); setURI(URI.create(uri)); } @Override - public String getMethod(){ + public String getMethod() { return METHOD_NAME; } diff --git a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpPropPatch.java b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpPropPatch.java index 3fec05a49..c7c25ba6c 100644 --- a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpPropPatch.java +++ b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpPropPatch.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package org.apache.http.client.methods; @@ -29,6 +29,8 @@ import java.net.URI; /** + * PropPatch 请求 + * * @author Yong.Teng */ public class HttpPropPatch extends HttpEntityEnclosingRequestBase { @@ -38,7 +40,7 @@ public class HttpPropPatch extends HttpEntityEnclosingRequestBase { /** * 构造函数 */ - public HttpPropPatch(){ + public HttpPropPatch() { super(); } @@ -48,7 +50,7 @@ public HttpPropPatch(){ * @param uri * URL {@link URI} */ - public HttpPropPatch(final URI uri){ + public HttpPropPatch(final URI uri) { super(); setURI(uri); } @@ -62,13 +64,13 @@ public HttpPropPatch(final URI uri){ * @throws IllegalArgumentException * if the uri is invalid. */ - public HttpPropPatch(final String uri){ + public HttpPropPatch(final String uri) { super(); setURI(URI.create(uri)); } @Override - public String getMethod(){ + public String getMethod() { return METHOD_NAME; } diff --git a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpPropfind.java b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpPropfind.java index ee7bace48..85f129419 100644 --- a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpPropfind.java +++ b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpPropfind.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package org.apache.http.client.methods; @@ -29,6 +29,8 @@ import java.net.URI; /** + * Propfind 请求 + * * @author Yong.Teng */ public class HttpPropfind extends HttpRequestBase { @@ -38,7 +40,7 @@ public class HttpPropfind extends HttpRequestBase { /** * 构造函数 */ - public HttpPropfind(){ + public HttpPropfind() { super(); } @@ -48,7 +50,7 @@ public HttpPropfind(){ * @param uri * URL {@link URI} */ - public HttpPropfind(final URI uri){ + public HttpPropfind(final URI uri) { super(); setURI(uri); } @@ -62,13 +64,13 @@ public HttpPropfind(final URI uri){ * @throws IllegalArgumentException * if the uri is invalid. */ - public HttpPropfind(final String uri){ + public HttpPropfind(final String uri) { super(); setURI(URI.create(uri)); } @Override - public String getMethod(){ + public String getMethod() { return METHOD_NAME; } diff --git a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpPurge.java b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpPurge.java index 9e89b5083..465af296d 100644 --- a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpPurge.java +++ b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpPurge.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package org.apache.http.client.methods; @@ -29,6 +29,8 @@ import java.net.URI; /** + * Purge 请求 + * * @author Yong.Teng */ public class HttpPurge extends HttpRequestBase { @@ -38,7 +40,7 @@ public class HttpPurge extends HttpRequestBase { /** * 构造函数 */ - public HttpPurge(){ + public HttpPurge() { super(); } @@ -48,7 +50,7 @@ public HttpPurge(){ * @param uri * URL {@link URI} */ - public HttpPurge(final URI uri){ + public HttpPurge(final URI uri) { super(); setURI(uri); } @@ -62,13 +64,13 @@ public HttpPurge(final URI uri){ * @throws IllegalArgumentException * if the uri is invalid. */ - public HttpPurge(final String uri){ + public HttpPurge(final String uri) { super(); setURI(URI.create(uri)); } @Override - public String getMethod(){ + public String getMethod() { return METHOD_NAME; } diff --git a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpReport.java b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpReport.java index 1e1226ea0..3635ead1c 100644 --- a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpReport.java +++ b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpReport.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package org.apache.http.client.methods; @@ -29,6 +29,8 @@ import java.net.URI; /** + * Report 请求 + * * @author Yong.Teng */ public class HttpReport extends HttpEntityEnclosingRequestBase { @@ -38,7 +40,7 @@ public class HttpReport extends HttpEntityEnclosingRequestBase { /** * 构造函数 */ - public HttpReport(){ + public HttpReport() { super(); } @@ -48,7 +50,7 @@ public HttpReport(){ * @param uri * URL {@link URI} */ - public HttpReport(final URI uri){ + public HttpReport(final URI uri) { super(); setURI(uri); } @@ -62,13 +64,13 @@ public HttpReport(final URI uri){ * @throws IllegalArgumentException * if the uri is invalid. */ - public HttpReport(final String uri){ + public HttpReport(final String uri) { super(); setURI(URI.create(uri)); } @Override - public String getMethod(){ + public String getMethod() { return METHOD_NAME; } diff --git a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpUnlink.java b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpUnlink.java index 6209da8cd..7e80f815b 100644 --- a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpUnlink.java +++ b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpUnlink.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package org.apache.http.client.methods; @@ -29,6 +29,8 @@ import java.net.URI; /** + * Unlink 请求 + * * @author Yong.Teng */ public class HttpUnlink extends HttpRequestBase { @@ -38,7 +40,7 @@ public class HttpUnlink extends HttpRequestBase { /** * 构造函数 */ - public HttpUnlink(){ + public HttpUnlink() { super(); } @@ -48,7 +50,7 @@ public HttpUnlink(){ * @param uri * URL {@link URI} */ - public HttpUnlink(final URI uri){ + public HttpUnlink(final URI uri) { super(); setURI(uri); } @@ -62,13 +64,13 @@ public HttpUnlink(final URI uri){ * @throws IllegalArgumentException * if the uri is invalid. */ - public HttpUnlink(final String uri){ + public HttpUnlink(final String uri) { super(); setURI(URI.create(uri)); } @Override - public String getMethod(){ + public String getMethod() { return METHOD_NAME; } diff --git a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpUnlock.java b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpUnlock.java index 27bf93ce0..6c2b4719f 100644 --- a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpUnlock.java +++ b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpUnlock.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package org.apache.http.client.methods; @@ -29,6 +29,8 @@ import java.net.URI; /** + * Unlock 请求 + * * @author Yong.Teng */ public class HttpUnlock extends HttpRequestBase { @@ -38,7 +40,7 @@ public class HttpUnlock extends HttpRequestBase { /** * 构造函数 */ - public HttpUnlock(){ + public HttpUnlock() { super(); } @@ -48,7 +50,7 @@ public HttpUnlock(){ * @param uri * URL {@link URI} */ - public HttpUnlock(final URI uri){ + public HttpUnlock(final URI uri) { super(); setURI(uri); } @@ -62,13 +64,13 @@ public HttpUnlock(final URI uri){ * @throws IllegalArgumentException * if the uri is invalid. */ - public HttpUnlock(final String uri){ + public HttpUnlock(final String uri) { super(); setURI(URI.create(uri)); } @Override - public String getMethod(){ + public String getMethod() { return METHOD_NAME; } diff --git a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpView.java b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpView.java index f9a56a884..aff83c926 100644 --- a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpView.java +++ b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpView.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package org.apache.http.client.methods; @@ -29,6 +29,8 @@ import java.net.URI; /** + * View 请求 + * * @author Yong.Teng */ public class HttpView extends HttpRequestBase { @@ -38,7 +40,7 @@ public class HttpView extends HttpRequestBase { /** * 构造函数 */ - public HttpView(){ + public HttpView() { super(); } @@ -48,7 +50,7 @@ public HttpView(){ * @param uri * URL {@link URI} */ - public HttpView(final URI uri){ + public HttpView(final URI uri) { super(); setURI(uri); } @@ -62,13 +64,13 @@ public HttpView(final URI uri){ * @throws IllegalArgumentException * if the uri is invalid. */ - public HttpView(final String uri){ + public HttpView(final String uri) { super(); setURI(URI.create(uri)); } @Override - public String getMethod(){ + public String getMethod() { return METHOD_NAME; } diff --git a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpWrapped.java b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpWrapped.java index 437c1fb07..b92fbbd51 100644 --- a/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpWrapped.java +++ b/buession-httpclient/src/main/java/org/apache/http/client/methods/HttpWrapped.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package org.apache.http.client.methods; @@ -29,6 +29,8 @@ import java.net.URI; /** + * Wrapped 请求 + * * @author Yong.Teng */ public class HttpWrapped extends HttpRequestBase { @@ -38,7 +40,7 @@ public class HttpWrapped extends HttpRequestBase { /** * 构造函数 */ - public HttpWrapped(){ + public HttpWrapped() { super(); } @@ -48,7 +50,7 @@ public HttpWrapped(){ * @param uri * URL {@link URI} */ - public HttpWrapped(final URI uri){ + public HttpWrapped(final URI uri) { super(); setURI(uri); } @@ -62,13 +64,13 @@ public HttpWrapped(final URI uri){ * @throws IllegalArgumentException * if the uri is invalid. */ - public HttpWrapped(final String uri){ + public HttpWrapped(final String uri) { super(); setURI(URI.create(uri)); } @Override - public String getMethod(){ + public String getMethod() { return METHOD_NAME; } diff --git a/buession-httpclient/src/test/java/com/buession/httpclient/ApacheHttpAsyncClientTest.java b/buession-httpclient/src/test/java/com/buession/httpclient/ApacheHttpAsyncClientTest.java index 4638da232..8217ca49d 100644 --- a/buession-httpclient/src/test/java/com/buession/httpclient/ApacheHttpAsyncClientTest.java +++ b/buession-httpclient/src/test/java/com/buession/httpclient/ApacheHttpAsyncClientTest.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient; @@ -28,7 +28,7 @@ import com.buession.httpclient.core.Response; import com.buession.httpclient.core.concurrent.Callback; import com.buession.httpclient.exception.RequestException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; @@ -41,24 +41,24 @@ public class ApacheHttpAsyncClientTest { private static ApacheHttpAsyncClient httpClient = new ApacheHttpAsyncClient(); @Test - public void responseHeaders() throws IOException, RequestException{ + public void responseHeaders() throws IOException, RequestException { httpClient.get("https://www.baidu.com", new Callback() { @Override - public void completed(Response response){ + public void completed(Response response) { for(Header header : response.getHeaders()){ System.out.println(header.toString()); } } @Override - public void failed(Exception ex){ + public void failed(Exception ex) { } @Override - public void cancelled(){ + public void cancelled() { } }); @@ -69,23 +69,45 @@ public void cancelled(){ new Callback() { @Override - public void completed(Response response){ + public void completed(Response response) { for(Header header : response.getHeaders()){ System.out.println(header.toString()); } } @Override - public void failed(Exception ex){ + public void failed(Exception ex) { } @Override - public void cancelled(){ + public void cancelled() { } }); //response.get(); } + @Test + public void body() throws IOException, RequestException { + httpClient.get("https://www.baidu.com", + new Callback() { + + @Override + public void completed(Response response) { + System.out.println(response.getBody()); + } + + @Override + public void failed(Exception ex) { + + } + + @Override + public void cancelled() { + + } + }); + } + } diff --git a/buession-httpclient/src/test/java/com/buession/httpclient/ApacheHttpClientTest.java b/buession-httpclient/src/test/java/com/buession/httpclient/ApacheHttpClientTest.java index aa8db67ac..450e666c4 100644 --- a/buession-httpclient/src/test/java/com/buession/httpclient/ApacheHttpClientTest.java +++ b/buession-httpclient/src/test/java/com/buession/httpclient/ApacheHttpClientTest.java @@ -19,24 +19,20 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient; -import com.buession.httpclient.core.ChunkedInputStreamRequestBody; +import com.buession.httpclient.core.Configuration; import com.buession.httpclient.core.EncodedFormRequestBody; import com.buession.httpclient.core.Header; -import com.buession.httpclient.core.HtmlRawRequestBody; -import com.buession.httpclient.core.MultipartFormRequestBody; import com.buession.httpclient.core.Response; import com.buession.httpclient.exception.RequestException; import com.buession.lang.Gender; import com.google.common.io.CharStreams; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; @@ -50,7 +46,7 @@ public class ApacheHttpClientTest { private static ApacheHttpClient httpClient = new ApacheHttpClient(); @Test - public void responseHeaders() throws IOException, RequestException{ + public void responseHeaders() throws IOException, RequestException { Response response = httpClient.get("https://shirojs.buession.com/manual/1.1/index.html"); for(Header header : response.getHeaders()){ System.out.println(header.toString()); @@ -58,7 +54,7 @@ public void responseHeaders() throws IOException, RequestException{ } @Test - public void responseBody() throws IOException, RequestException{ + public void responseBody() throws IOException, RequestException { Response response = httpClient.get("https://shirojs.buession.com/support.html"); System.out.println(response.getBody()); @@ -67,7 +63,7 @@ public void responseBody() throws IOException, RequestException{ } @Test - public void encodedFormRequestBody() throws IOException, RequestException{ + public void encodedFormRequestBody() throws IOException, RequestException { EncodedFormRequestBody encodedFormRequestBody = new EncodedFormRequestBody(); encodedFormRequestBody.addRequestBodyElement("username", "username"); @@ -79,4 +75,22 @@ public void encodedFormRequestBody() throws IOException, RequestException{ System.out.println(response.getBody()); } + @Test + public void proxy() throws IOException, RequestException { + Configuration.Proxy proxy = new Configuration.Proxy(); + + proxy.setHostname("127.0.0.1"); + proxy.setPort(7890); + + Configuration configuration = new Configuration(); + + configuration.setProxy(proxy); + + ApacheHttpClient httpClient = new ApacheHttpClient(configuration); + Response response = httpClient.get("https://www.google.com"); + for(Header header : response.getHeaders()){ + System.out.println(header.toString()); + } + } + } diff --git a/buession-httpclient/src/test/java/com/buession/httpclient/GuavaTest.java b/buession-httpclient/src/test/java/com/buession/httpclient/GuavaTest.java index 86c3d8a01..4bf0e476a 100644 --- a/buession-httpclient/src/test/java/com/buession/httpclient/GuavaTest.java +++ b/buession-httpclient/src/test/java/com/buession/httpclient/GuavaTest.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient; @@ -27,9 +27,8 @@ import com.buession.core.utils.StringUtils; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.util.Collections; import java.util.Iterator; /** @@ -39,7 +38,7 @@ public class GuavaTest { @Test - public void testMultimap(){ + public void testMultimap() { Multimap map = HashMultimap.create(); map.put("a", "A1"); @@ -47,7 +46,7 @@ public void testMultimap(){ } @Test - public void forEach(){ + public void forEach() { Multimap map = HashMultimap.create(); map.put("a", "A1"); diff --git a/buession-httpclient/src/test/java/com/buession/httpclient/OkHttpHttpAsyncClientTest.java b/buession-httpclient/src/test/java/com/buession/httpclient/OkHttpHttpAsyncClientTest.java index 07a2f053c..d63c7fbf9 100644 --- a/buession-httpclient/src/test/java/com/buession/httpclient/OkHttpHttpAsyncClientTest.java +++ b/buession-httpclient/src/test/java/com/buession/httpclient/OkHttpHttpAsyncClientTest.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient; @@ -28,7 +28,7 @@ import com.buession.httpclient.core.Response; import com.buession.httpclient.core.concurrent.Callback; import com.buession.httpclient.exception.RequestException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.concurrent.TimeUnit; @@ -42,24 +42,24 @@ public class OkHttpHttpAsyncClientTest { private static OkHttpHttpAsyncClient httpClient = new OkHttpHttpAsyncClient(); @Test - public void responseHeaders() throws IOException, RequestException{ + public void responseHeaders() throws IOException, RequestException { httpClient.get("https://www.baidu.com", new Callback() { @Override - public void completed(Response response){ + public void completed(Response response) { for(Header header : response.getHeaders()){ System.out.println(header.toString()); } } @Override - public void failed(Exception ex){ + public void failed(Exception ex) { System.out.println("failed"); } @Override - public void cancelled(){ + public void cancelled() { System.out.println("cancelled"); } }); @@ -67,7 +67,7 @@ public void cancelled(){ } @Test - public void okhttp3Native(){ + public void okhttp3Native() { // 构建okHttpClient,相当于请求的客户端,Builder设计模式 okhttp3.OkHttpClient okHttpClient = new okhttp3.OkHttpClient.Builder().readTimeout(5, TimeUnit.SECONDS).build(); // 构建一个请求体,同样也是Builder设计模式 @@ -78,12 +78,12 @@ public void okhttp3Native(){ call.enqueue(new okhttp3.Callback() { @Override - public void onFailure(okhttp3.Call call, IOException e){ + public void onFailure(okhttp3.Call call, IOException e) { System.out.println(e); } @Override - public void onResponse(okhttp3.Call call, okhttp3.Response response) throws IOException{ + public void onResponse(okhttp3.Call call, okhttp3.Response response) throws IOException { System.out.println(response.body()); } }); diff --git a/buession-httpclient/src/test/java/com/buession/httpclient/OkHttpHttpClientTest.java b/buession-httpclient/src/test/java/com/buession/httpclient/OkHttpHttpClientTest.java index 1fc9d43ff..e9fb2f074 100644 --- a/buession-httpclient/src/test/java/com/buession/httpclient/OkHttpHttpClientTest.java +++ b/buession-httpclient/src/test/java/com/buession/httpclient/OkHttpHttpClientTest.java @@ -19,24 +19,19 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient; -import com.buession.httpclient.core.ChunkedInputStreamRequestBody; import com.buession.httpclient.core.EncodedFormRequestBody; import com.buession.httpclient.core.Header; -import com.buession.httpclient.core.HtmlRawRequestBody; -import com.buession.httpclient.core.MultipartFormRequestBody; import com.buession.httpclient.core.Response; import com.buession.httpclient.exception.RequestException; import com.buession.lang.Gender; import com.google.common.io.CharStreams; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; @@ -50,7 +45,7 @@ public class OkHttpHttpClientTest { private static OkHttpHttpClient httpClient = new OkHttpHttpClient(); @Test - public void responseHeaders() throws IOException, RequestException{ + public void responseHeaders() throws IOException, RequestException { Response response = httpClient.get("https://shirojs.buession.com/manual/1.1/index.html"); for(Header header : response.getHeaders()){ System.out.println(header.toString()); @@ -58,7 +53,7 @@ public void responseHeaders() throws IOException, RequestException{ } @Test - public void responseBody() throws IOException, RequestException{ + public void responseBody() throws IOException, RequestException { Response response = httpClient.get("https://shirojs.buession.com/support.html"); System.out.println(response.getBody()); @@ -67,7 +62,7 @@ public void responseBody() throws IOException, RequestException{ } @Test - public void encodedFormRequestBody() throws IOException, RequestException{ + public void encodedFormRequestBody() throws IOException, RequestException { EncodedFormRequestBody encodedFormRequestBody = new EncodedFormRequestBody(); encodedFormRequestBody.addRequestBodyElement("username", "username"); diff --git a/buession-httpclient/src/test/java/com/buession/httpclient/ProtocolVersionTest.java b/buession-httpclient/src/test/java/com/buession/httpclient/ProtocolVersionTest.java index 7c73edbed..7e227f2e8 100644 --- a/buession-httpclient/src/test/java/com/buession/httpclient/ProtocolVersionTest.java +++ b/buession-httpclient/src/test/java/com/buession/httpclient/ProtocolVersionTest.java @@ -19,13 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.httpclient; import com.buession.httpclient.core.ProtocolVersion; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Yong.Teng @@ -34,7 +34,7 @@ public class ProtocolVersionTest { @Test - public void createInstance(){ + public void createInstance() { ProtocolVersion protocolVersion = ProtocolVersion.createInstance("http", 1, 1); System.out.println(protocolVersion); } diff --git a/buession-io/pom.xml b/buession-io/pom.xml index 8e22608a6..bccaefeeb 100644 --- a/buession-io/pom.xml +++ b/buession-io/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-io http://www.buession.com/ @@ -86,8 +86,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -131,8 +131,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-io/src/main/java/com/buession/io/MimeType.java b/buession-io/src/main/java/com/buession/io/MimeType.java index b996ddc71..b57e7b53d 100644 --- a/buession-io/src/main/java/com/buession/io/MimeType.java +++ b/buession-io/src/main/java/com/buession/io/MimeType.java @@ -19,18 +19,17 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.io; import com.buession.core.utils.Assert; import com.buession.core.utils.KeyValueParser; +import com.buession.core.utils.StringUtils; import com.buession.core.validator.Validate; import javax.validation.constraints.NotEmpty; -import java.util.Objects; -import java.util.StringJoiner; /** * MimeType @@ -58,7 +57,7 @@ public final class MimeType { * * @since 1.3.2 */ - public MimeType(@NotEmpty String mimeType){ + public MimeType(@NotEmpty String mimeType) { Assert.isBlank(mimeType, "MimeType string cloud empty or null."); if(Validate.isMimeType(mimeType)){ @@ -79,7 +78,7 @@ public MimeType(@NotEmpty String mimeType){ * @param subtype * 子 Type */ - public MimeType(@NotEmpty String type, @NotEmpty String subtype){ + public MimeType(@NotEmpty String type, @NotEmpty String subtype) { this.type = type.toLowerCase(); this.subtype = subtype.toLowerCase(); } @@ -96,7 +95,7 @@ public MimeType(@NotEmpty String type, @NotEmpty String subtype){ * * @since 1.3.2 */ - public MimeType(@NotEmpty String type, @NotEmpty String subtype, String description){ + public MimeType(@NotEmpty String type, @NotEmpty String subtype, String description) { this(type, subtype); this.description = description; } @@ -109,17 +108,17 @@ public MimeType(@NotEmpty String type, @NotEmpty String subtype, String descript * * @return MimeType */ - public static MimeType parse(String mimeType){ + public static MimeType parse(String mimeType) { Assert.isBlank(mimeType, "MimeType string cloud empty or null."); KeyValueParser keyValueParser = new KeyValueParser(mimeType, '/'); return new MimeType(keyValueParser.getKey(), keyValueParser.getValue()); } - public String getType(){ + public String getType() { return type; } - public String getSubtype(){ + public String getSubtype() { return subtype; } @@ -130,7 +129,7 @@ public String getSubtype(){ * * @since 1.3.2 */ - public String getDescription(){ + public String getDescription() { return description; } @@ -140,32 +139,32 @@ public String getDescription(){ * @param description * MimeType 描述 */ - public void setDescription(String description){ + public void setDescription(String description) { this.description = description; } @Override - public int hashCode(){ + public int hashCode() { return 16 * (type.hashCode() + subtype.hashCode()); } @Override - public boolean equals(Object object){ + public boolean equals(Object object) { if(this == object){ return true; } if(object instanceof MimeType){ MimeType that = (MimeType) object; - return Objects.equals(type, that.type) && Objects.equals(subtype, that.subtype); + return StringUtils.equalsIgnoreCase(type, that.type) && StringUtils.equalsIgnoreCase(subtype, that.subtype); } return false; } @Override - public String toString(){ - return new StringJoiner("/").add(type).add(subtype).toString(); + public String toString() { + return type + '/' + subtype; } } diff --git a/buession-io/src/main/java/com/buession/io/file/AbstractMimeTypeDetector.java b/buession-io/src/main/java/com/buession/io/file/AbstractMimeTypeDetector.java index a95431e58..ec2673e29 100644 --- a/buession-io/src/main/java/com/buession/io/file/AbstractMimeTypeDetector.java +++ b/buession-io/src/main/java/com/buession/io/file/AbstractMimeTypeDetector.java @@ -19,11 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.io.file; +import com.buession.core.utils.Assert; import com.buession.core.validator.Validate; import com.buession.io.MimeType; @@ -48,40 +49,31 @@ public abstract class AbstractMimeTypeDetector implements MimeTypeDetector { /** * 构造函数 */ - public AbstractMimeTypeDetector(){ + public AbstractMimeTypeDetector() { initialize(); } @Override - public final MimeType probe(String path) throws IOException{ - if(Validate.hasText(path)){ - return implProbeMimeType(path); - }else{ - throw new NullPointerException("File path is null or empty."); - } + public final MimeType probe(String path) throws IOException { + Assert.isBlank(path, ()->new NullPointerException("File path is null or empty")); + return implProbeMimeType(path); } @Override - public final MimeType probe(File file) throws IOException{ - if(file == null){ - throw new NullPointerException("'file' is null"); - }else{ - return probe(file.toPath()); - } + public final MimeType probe(File file) throws IOException { + Assert.isNull(file, ()->new NullPointerException("'file' is null")); + return probe(file.toPath()); } @Override - public final MimeType probe(Path path){ - if(path == null){ - throw new NullPointerException("'file' is null"); - }else{ - return implProbeMimeType(path); - } + public final MimeType probe(Path path) { + Assert.isNull(path, ()->new NullPointerException("'file' is null")); + return implProbeMimeType(path); } protected abstract void initialize(); - protected static String getExtension(String path){ + protected static String getExtension(String path) { String extension = ""; if(Validate.isNotEmpty(path)){ @@ -98,7 +90,7 @@ protected static String getExtension(String path){ protected abstract MimeType implProbeMimeType(final Path path); - protected void putIfAbsent(final String extension, final String contentType, final String description){ + protected void putIfAbsent(final String extension, final String contentType, final String description) { if(Validate.isNotEmpty(extension) && Validate.isNotEmpty(contentType) && internalMimetypes.containsKey(extension) == false){ MimeType mimeType = MimeType.parse(contentType); @@ -108,7 +100,7 @@ protected void putIfAbsent(final String extension, final String contentType, fin } } - protected static MimeType parse(final String s, final String description){ + protected static MimeType parse(final String s, final String description) { int slash = s.indexOf('/'); int semicolon = s.indexOf(';'); @@ -129,15 +121,15 @@ protected static MimeType parse(final String s, final String description){ return new MimeType(type, subtype, description); } - private static String parseType(final String type){ + private static String parseType(final String type) { return type.trim().toLowerCase(Locale.ENGLISH); } - private static boolean isTokenChar(char c){ - return c > ' ' && c < 127 && "()<>@,;:/[]?=\\\"" .indexOf(c) < 0; + private static boolean isTokenChar(char c) { + return c > ' ' && c < 127 && "()<>@,;:/[]?=\\\"".indexOf(c) < 0; } - private static boolean isValidToken(String str){ + private static boolean isValidToken(String str) { int strLength = str.length(); if(strLength == 0){ diff --git a/buession-io/src/main/java/com/buession/io/file/File.java b/buession-io/src/main/java/com/buession/io/file/File.java index 38a766c33..2fdbdaf63 100644 --- a/buession-io/src/main/java/com/buession/io/file/File.java +++ b/buession-io/src/main/java/com/buession/io/file/File.java @@ -40,12 +40,14 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; /** + * {@link java.io.File} 扩展 + * * @author Yong.Teng */ public class File extends java.io.File { @@ -130,25 +132,11 @@ public MimeType getMimeType() { * IO 异常 */ public byte[] read() throws IOException { - int size = 4096; - BufferedInputStream bis = new FileBufferedInputStream(this); - byte[] tempChars = new byte[size]; - int num = 0; - ArrayList bytes = new ArrayList<>(); - - while((num = bis.read(tempChars)) != -1){ - for(int i = 0; i < num; i++){ - bytes.add(tempChars[i]); - } - } - bis.close(); - - Byte[] oBytes = bytes.toArray(new Byte[0]); - byte[] result = new byte[oBytes.length]; + final BufferedInputStream bis = new FileBufferedInputStream(this); + final byte[] result = new byte[(int) this.length()]; - for(int i = 0; i < oBytes.length; i++){ - result[i] = oBytes[i]; - } + bis.read(result); + bis.close(); return result; } @@ -176,18 +164,8 @@ public void write(final String str) throws IOException { * IO 异常 */ public void write(final char[] chars) throws IOException { - BufferedOutputStream bos = new FileBufferedOutputStream(this); - - for(char c : chars){ - byte[] b = new byte[2]; - b[0] = (byte) ((c & 0xFF00) >> 8); - b[1] = (byte) (c & 0xFF); - - bos.write(b); - } - - bos.flush(); - bos.close(); + final BufferedOutputStream bos = new FileBufferedOutputStream(this); + write(bos, chars); } /** @@ -200,11 +178,25 @@ public void write(final char[] chars) throws IOException { * IO 异常 */ public void write(final byte[] bytes) throws IOException { - BufferedOutputStream bos = new FileBufferedOutputStream(this); + final BufferedOutputStream bos = new FileBufferedOutputStream(this); bos.write(bytes); - bos.flush(); - bos.close(); + afterWrite(bos); + } + + /** + * 将输入流写入文件 + * + * @param stream + * 输入流 + * + * @throws IOException + * IO 异常 + * @since 3.0.0 + */ + public void write(final InputStream stream) throws IOException { + final BufferedOutputStream bos = new FileBufferedOutputStream(this); + write(bos, stream); } /** @@ -236,18 +228,8 @@ public void write(final String str, boolean append) throws IOException { * @since 1.2.0 */ public void write(final char[] chars, boolean append) throws IOException { - BufferedOutputStream bos = new FileBufferedOutputStream(this, append); - - for(char c : chars){ - byte[] b = new byte[2]; - b[0] = (byte) ((c & 0xFF00) >> 8); - b[1] = (byte) (c & 0xFF); - - bos.write(b); - } - - bos.flush(); - bos.close(); + final BufferedOutputStream bos = new FileBufferedOutputStream(this, append); + write(bos, chars); } /** @@ -263,11 +245,27 @@ public void write(final char[] chars, boolean append) throws IOException { * @since 1.2.0 */ public void write(final byte[] bytes, boolean append) throws IOException { - BufferedOutputStream bos = new FileBufferedOutputStream(this, append); + final BufferedOutputStream bos = new FileBufferedOutputStream(this, append); bos.write(bytes); - bos.flush(); - bos.close(); + afterWrite(bos); + } + + /** + * 将输入流写入文件 + * + * @param stream + * 输入流 + * @param append + * 是否追加写入 + * + * @throws IOException + * IO 异常 + * @since 3.0.0 + */ + public void write(final InputStream stream, boolean append) throws IOException { + final BufferedOutputStream bos = new FileBufferedOutputStream(this, append); + write(bos, stream); } /** @@ -290,10 +288,10 @@ public String getMd5() throws IOException { throw new IOException(getPath() + " is not a file."); } - FileInputStream fs = new FileInputStream(this); - String result = DigestUtils.md5Hex(fs); + final FileInputStream fis = new FileInputStream(this); + String result = DigestUtils.md5Hex(fis); - fs.close(); + fis.close(); return result; } @@ -318,10 +316,10 @@ public String getSha1() throws IOException { throw new IOException(getPath() + " is not a file."); } - FileInputStream fs = new FileInputStream(this); - String result = DigestUtils.sha1Hex(fs); + final FileInputStream fis = new FileInputStream(this); + String result = DigestUtils.sha1Hex(fis); - fs.close(); + fis.close(); return result; } @@ -396,7 +394,7 @@ public void createSymbolicLink(final java.io.File dest) throws IOException { * @since 2.3.3 */ public void createSymbolicLink(final java.io.File dest, final boolean overwrite) throws IOException { - Assert.isNull(dest, "Dest path cloud not be null."); + Assert.isNull(dest, "Destination path cloud not be null."); final Path destPath = dest.toPath(); @@ -419,6 +417,34 @@ public void createSymbolicLink(final java.io.File dest, final boolean overwrite) Files.createSymbolicLink(destPath, this.toPath()); } + private void write(final BufferedOutputStream bos, final char[] chars) throws IOException { + for(char c : chars){ + byte[] b = new byte[2]; + b[0] = (byte) ((c & 0xFF00) >> 8); + b[1] = (byte) (c & 0xFF); + + bos.write(b); + } + + afterWrite(bos); + } + + private void write(final BufferedOutputStream bos, final InputStream stream) throws IOException { + final byte[] buffer = new byte[1024]; + int readSize; + + while((readSize = stream.read(buffer)) != -1){ + bos.write(buffer, 0, readSize); + } + + afterWrite(bos); + } + + protected static void afterWrite(final BufferedOutputStream bos) throws IOException { + bos.flush(); + bos.close(); + } + private final static class FileBufferedInputStream extends BufferedInputStream { public FileBufferedInputStream(java.io.File file) throws FileNotFoundException { diff --git a/buession-io/src/main/java/com/buession/io/file/Files.java b/buession-io/src/main/java/com/buession/io/file/Files.java index c2e9e8eaa..8892d7124 100755 --- a/buession-io/src/main/java/com/buession/io/file/Files.java +++ b/buession-io/src/main/java/com/buession/io/file/Files.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.io.file; @@ -40,6 +40,8 @@ import java.util.Set; /** + * {@link java.nio.file.Files} 扩展 + * * @author Yong.Teng */ public class Files { @@ -55,7 +57,7 @@ public class Files { * @throws IOException * IO 异常 */ - public static void changeGroup(final Path path, final String group) throws IOException{ + public static void changeGroup(final Path path, final String group) throws IOException { chgrp(path, group); } @@ -70,7 +72,7 @@ public static void changeGroup(final Path path, final String group) throws IOExc * @throws IOException * IO 异常 */ - public static void changeGroup(final File file, final String group) throws IOException{ + public static void changeGroup(final File file, final String group) throws IOException { chgrp(file, group); } @@ -85,7 +87,7 @@ public static void changeGroup(final File file, final String group) throws IOExc * @throws IOException * IO 异常 */ - public static void changeGroup(final String path, final String group) throws IOException{ + public static void changeGroup(final String path, final String group) throws IOException { chgrp(path, group); } @@ -100,7 +102,7 @@ public static void changeGroup(final String path, final String group) throws IOE * @throws IOException * IO 异常 */ - public static void chgrp(final Path path, final String group) throws IOException{ + public static void chgrp(final Path path, final String group) throws IOException { Assert.isNull(path, "File path cloud not be null."); Assert.isNull(group, "Group cloud not be null."); @@ -109,9 +111,7 @@ public static void chgrp(final Path path, final String group) throws IOException PosixFileAttributeView view = java.nio.file.Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); - if(view == null){ - throw new UnsupportedOperationException(); - } + Assert.isNull(view, UnsupportedOperationException::new); view.setGroup(groupPrincipal); } @@ -127,7 +127,7 @@ public static void chgrp(final Path path, final String group) throws IOException * @throws IOException * IO 异常 */ - public static void chgrp(final File file, final String group) throws IOException{ + public static void chgrp(final File file, final String group) throws IOException { Assert.isNull(file, "File cloud not be null."); chgrp(file.toPath(), group); } @@ -143,7 +143,7 @@ public static void chgrp(final File file, final String group) throws IOException * @throws IOException * IO 异常 */ - public static void chgrp(final String path, final String group) throws IOException{ + public static void chgrp(final String path, final String group) throws IOException { Assert.isBlank(path, "File path must be contain entity string."); chgrp(new File(path), group); } @@ -159,7 +159,7 @@ public static void chgrp(final String path, final String group) throws IOExcepti * @throws IOException * IO 异常 */ - public static void changeOwner(final Path path, final String owner) throws IOException{ + public static void changeOwner(final Path path, final String owner) throws IOException { chown(path, owner); } @@ -174,7 +174,7 @@ public static void changeOwner(final Path path, final String owner) throws IOExc * @throws IOException * IO 异常 */ - public static void changeOwner(final File file, final String owner) throws IOException{ + public static void changeOwner(final File file, final String owner) throws IOException { chown(file, owner); } @@ -189,7 +189,7 @@ public static void changeOwner(final File file, final String owner) throws IOExc * @throws IOException * IO 异常 */ - public static void changeOwner(final String path, final String owner) throws IOException{ + public static void changeOwner(final String path, final String owner) throws IOException { chown(path, owner); } @@ -204,7 +204,7 @@ public static void changeOwner(final String path, final String owner) throws IOE * @throws IOException * IO 异常 */ - public static void chown(final Path path, final String owner) throws IOException{ + public static void chown(final Path path, final String owner) throws IOException { Assert.isNull(path, "File path cloud not be null."); Assert.isNull(owner, "Owner coult not be null."); @@ -223,7 +223,7 @@ public static void chown(final Path path, final String owner) throws IOException * @throws IOException * IO 异常 */ - public static void chown(final File file, final String owner) throws IOException{ + public static void chown(final File file, final String owner) throws IOException { Assert.isNull(file, "File cloud not be null."); chown(file.toPath(), owner); } @@ -239,7 +239,7 @@ public static void chown(final File file, final String owner) throws IOException * @throws IOException * IO 异常 */ - public static void chown(final String path, final String owner) throws IOException{ + public static void chown(final String path, final String owner) throws IOException { Assert.isBlank(path, "File path must be contain entity string."); chown(new File(path), owner); } @@ -259,7 +259,7 @@ public static void chown(final String path, final String owner) throws IOExcepti * @throws IOException * IO 异常 */ - public static void chmod(final Path path, final int mode) throws IOException{ + public static void chmod(final Path path, final int mode) throws IOException { Assert.isNull(path, "File path cloud not be null."); chmod(path, mode2perms(mode)); } @@ -279,7 +279,7 @@ public static void chmod(final Path path, final int mode) throws IOException{ * @throws IOException * IO 异常 */ - public static void chmod(final File file, final int mode) throws IOException{ + public static void chmod(final File file, final int mode) throws IOException { Assert.isNull(file, "File cloud not be null."); chmod(file.toPath(), mode); } @@ -299,7 +299,7 @@ public static void chmod(final File file, final int mode) throws IOException{ * @throws IOException * IO 异常 */ - public static void chmod(final String path, final int mode) throws IOException{ + public static void chmod(final String path, final int mode) throws IOException { Assert.isBlank(path, "File path must be contain entity string."); chmod(new File(path), mode); } @@ -316,7 +316,7 @@ public static void chmod(final String path, final int mode) throws IOException{ * IO 异常 * @see java.nio.file.attribute.PosixFilePermissions */ - public static void chmod(final Path path, final String perms) throws IOException{ + public static void chmod(final Path path, final String perms) throws IOException { Assert.isNull(path, "File path cloud not be null."); Assert.isBlank(perms, "File permission not be empty or null."); @@ -336,7 +336,7 @@ public static void chmod(final Path path, final String perms) throws IOException * IO 异常 * @see java.nio.file.attribute.PosixFilePermissions */ - public static void chmod(final File file, final String perms) throws IOException{ + public static void chmod(final File file, final String perms) throws IOException { Assert.isNull(file, "File cloud not be null."); chmod(file.toPath(), perms); } @@ -353,7 +353,7 @@ public static void chmod(final File file, final String perms) throws IOException * IO 异常 * @see java.nio.file.attribute.PosixFilePermissions */ - public static void chmod(final String path, final String perms) throws IOException{ + public static void chmod(final String path, final String perms) throws IOException { Assert.isBlank(path, "File path must be contain entity string."); chmod(new File(path), perms); } @@ -366,7 +366,7 @@ public static void chmod(final String path, final String perms) throws IOExcepti * * @return 文件权限表示 */ - public static String mode2perms(final int mode){ + public static String mode2perms(final int mode) { char[] perms = new char[9]; perms[0] = getFilePerm(mode, 0x0100, FilePermission.READ); @@ -396,11 +396,11 @@ public static String mode2perms(final int mode){ return new String(perms); } - private static char getFilePerm(final int mode, final int factor, final FilePermission defaultValue){ + private static char getFilePerm(final int mode, final int factor, final FilePermission defaultValue) { return getFilePerm(mode, factor, defaultValue, FilePermission.NONE); } - private static char getFilePerm(final int mode, final int factor, final FilePermission t, final FilePermission f){ + private static char getFilePerm(final int mode, final int factor, final FilePermission t, final FilePermission f) { return (mode & factor) != 0 ? t.getValue() : f.getValue(); } diff --git a/buession-io/src/test/java/com/buession/io/FileTest.java b/buession-io/src/test/java/com/buession/io/FileTest.java index d2a7bf201..133f65b8a 100644 --- a/buession-io/src/test/java/com/buession/io/FileTest.java +++ b/buession-io/src/test/java/com/buession/io/FileTest.java @@ -19,14 +19,14 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.io; import com.buession.io.file.File; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; @@ -37,18 +37,25 @@ public class FileTest { @Test - public void mimeType() throws IOException{ + public void mimeType() throws IOException { File file = new File("tmp.jpeg"); MimeType mimeType = file.getMimeType(); System.out.println(mimeType + ": " + mimeType.getDescription()); } @Test - public void jsonEncode() throws IOException{ + public void jsonEncode() throws IOException { File file = new File("tmp.jpeg"); ObjectMapper objectMapper = new ObjectMapper(); System.out.println(objectMapper.writeValueAsString(file)); } + @Test + public void read() throws IOException { + File file = new File("/Users/tengyong/Downloads/sys_user_role.sql"); + + System.out.println(new String(file.read())); + } + } diff --git a/buession-io/src/test/java/com/buession/io/UmaskTest.java b/buession-io/src/test/java/com/buession/io/UmaskTest.java index b231d2140..4f08f248f 100644 --- a/buession-io/src/test/java/com/buession/io/UmaskTest.java +++ b/buession-io/src/test/java/com/buession/io/UmaskTest.java @@ -19,38 +19,38 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.io; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Yong.Teng */ public class UmaskTest { - @Test - public void mask(){ - int $perms = 0777; + @Test + public void mask() { + int $perms = 0777; - String $info = ""; - // Owner - $info += (($perms & 0x0100) != 0 ? "r" : "-"); - $info += (($perms & 0x0080) != 0 ? "w" : "-"); - $info += (($perms & 0x0040) != 0 ? (($perms & 0x0800) != 0 ? "s" : "x") : (($perms & 0x0800) != 0 ? "s" : "-")); + String $info = ""; + // Owner + $info += (($perms & 0x0100) != 0 ? "r" : "-"); + $info += (($perms & 0x0080) != 0 ? "w" : "-"); + $info += (($perms & 0x0040) != 0 ? (($perms & 0x0800) != 0 ? "s" : "x") : (($perms & 0x0800) != 0 ? "s" : "-")); - // Group - $info += (($perms & 0x0020) != 0 ? "r" : "-"); - $info += (($perms & 0x0010) != 0 ? "w" : "-"); - $info += (($perms & 0x0008) != 0 ? (($perms & 0x0400) != 0 ? "s" : "x") : (($perms & 0x0400) != 0 ? "s" : "-")); + // Group + $info += (($perms & 0x0020) != 0 ? "r" : "-"); + $info += (($perms & 0x0010) != 0 ? "w" : "-"); + $info += (($perms & 0x0008) != 0 ? (($perms & 0x0400) != 0 ? "s" : "x") : (($perms & 0x0400) != 0 ? "s" : "-")); - // World - $info += (($perms & 0x0004) != 0 ? "r" : "-"); - $info += (($perms & 0x0002) != 0 ? "w" : "-"); - $info += (($perms & 0x0001) != 0 ? (($perms & 0x0200) != 0 ? "t" : "x") : (($perms & 0x0200) != 0 ? "t" : "-")); - System.out.println($perms + ": " + $info); - } + // World + $info += (($perms & 0x0004) != 0 ? "r" : "-"); + $info += (($perms & 0x0002) != 0 ? "w" : "-"); + $info += (($perms & 0x0001) != 0 ? (($perms & 0x0200) != 0 ? "t" : "x") : (($perms & 0x0200) != 0 ? "t" : "-")); + System.out.println($perms + ": " + $info); + } } diff --git a/buession-jdbc/pom.xml b/buession-jdbc/pom.xml index 8d6e337ce..d16617c31 100644 --- a/buession-jdbc/pom.xml +++ b/buession-jdbc/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-jdbc http://www.buession.com/ @@ -83,12 +83,28 @@ org.apache.commons commons-dbcp2 provided + + + commons-logging + commons-logging + + com.alibaba druid provided + + com.oracle.database.jdbc + ucp + provided + + + + jakarta.transaction + jakarta.transaction-api + org.slf4j @@ -96,8 +112,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -141,8 +157,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/config/BaseConfig.java b/buession-jdbc/src/main/java/com/buession/jdbc/config/BaseConfig.java new file mode 100644 index 000000000..e9cf44272 --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/config/BaseConfig.java @@ -0,0 +1,449 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.config; + +import com.buession.jdbc.core.Jmx; +import com.buession.jdbc.core.TransactionIsolation; + +import java.time.Duration; + +/** + * 数据源基本配置 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class BaseConfig implements Config { + + /***********************************************************/ + /* 数据源基本配置开始 */ + /***********************************************************/ + + /** + * 登录超时 + * + * @since 3.0.0 + */ + private Duration loginTimeout; + + /** + * 查询超时时间 + */ + private Duration queryTimeout; + + /** + * 默认事务隔离级别 + */ + private TransactionIsolation defaultTransactionIsolation = TransactionIsolation.DEFAULT; + + /** + * 默认连接是否是只读模式 + */ + private Boolean defaultReadOnly; + + /** + * 默认是否自动提交事务 + */ + private Boolean defaultAutoCommit; + + /** + * PoolGuard 是否可以访问底层连接 + */ + private Boolean accessToUnderlyingConnectionAllowed; + + /***********************************************************/ + /* 数据源基本配置结束 */ + /***********************************************************/ + + + /***********************************************************/ + /* 连接池配置开始 */ + /***********************************************************/ + /** + * 连接池的名称 + */ + private String poolName; + + /** + * 初始连接数,池被启动时初始化的创建的连接个数 + */ + private Integer initialSize; + + /** + * 最小空闲连接数,可以在池中保持空闲的最小连接数,低于设置值时,空闲连接将被创建,以努力保持最小空闲连接数 >= minIdle + */ + private Integer minIdle; + + /** + * 最大空闲连接数,在池中,可以保持空闲状态的最大连接数,超出设置值之外的空闲连接在归还到连接池时将被释放,如设置为负数,则不限制 + */ + private Integer maxIdle; + + /** + * 最大连接数,可以在这个池中同一时刻被分配的有效连接数的最大值,如设置为负数,则不限制 + */ + private Integer maxTotal; + + /** + * 从连接池获取一个连接时,最大的等待时间,设置为-1时,如果没有可用连接,连接池会一直无限期等待,直到获取到连接为止 + */ + private Duration maxWait; + + /** + * 连接创建后,马上验证有效性; + * 指明对象在创建后是否需要验证是否有效,如果对象验证失败,则触发对象创建的租借尝试将失败 + */ + private Boolean testOnCreate; + + /** + * 从连接池获取一个连接时,验证有效性; + * 指明在从池中租借对象时是否要进行验证有效,如果对象验证失败,则对象将从池子释放,然后我们将尝试租借另一个 + */ + private Boolean testOnBorrow; + + /** + * 连接被归还到连接池时,验证有效性 + */ + private Boolean testOnReturn; + + /** + * 连接空闲时,验证有效性; + * 指明对象是否需要通过对象驱逐者进行校验(如果有的话),假如一个对象验证失败,则对象将被从池中释放 + */ + private Boolean testWhileIdle; + + /** + * 设置一个SQL语句, 从连接池获取连接时, 先执行改 sql, 验证连接是否可用 + */ + private String validationQuery; + + /** + * 连接有效SQL的执行查询超时时间 + */ + private Duration validationQueryTimeout; + + /** + * 空闲的连接被释放最低要待时间 + */ + private Duration minEvictableIdle; + + /** + * 空闲的连接被释放最高要待时间 + */ + private Duration maxEvictableIdle; + + /** + * 在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 + */ + private Integer numTestsPerEvictionRun; + + /** + * 空闲对象驱逐线程运行时的休眠时间 + */ + private Duration timeBetweenEvictionRuns; + + /** + * 当连接被认为是废弃并且被移除时是否记录日志 + */ + private Boolean logAbandoned; + + /** + * 指定连接在被认为是废弃连接(abandoned connection)之前的超时时间 + */ + private Duration removeAbandonedTimeout; + + /** + * JMX 管理对象配置 + */ + private Jmx jmx; + /***********************************************************/ + /* 连接池配置结束 */ + + /***********************************************************/ + + /** + * 返回登录超时 + * + * @return 登录超时 + * + * @since 3.0.0 + */ + public Duration getLoginTimeout() { + return loginTimeout; + } + + /** + * 设置登录超时 + * + * @param loginTimeout + * 登录超时 + * + * @since 3.0.0 + */ + public void setLoginTimeout(Duration loginTimeout) { + this.loginTimeout = loginTimeout; + } + + @Override + public Duration getQueryTimeout() { + return queryTimeout; + } + + @Override + public void setQueryTimeout(Duration queryTimeout) { + this.queryTimeout = queryTimeout; + } + + @Override + public TransactionIsolation getDefaultTransactionIsolation() { + return defaultTransactionIsolation; + } + + @Override + public void setDefaultTransactionIsolation(TransactionIsolation defaultTransactionIsolation) { + this.defaultTransactionIsolation = defaultTransactionIsolation; + } + + @Override + public Boolean getDefaultReadOnly() { + return defaultReadOnly; + } + + @Override + public void setDefaultReadOnly(Boolean defaultReadOnly) { + this.defaultReadOnly = defaultReadOnly; + } + + @Override + public Boolean getDefaultAutoCommit() { + return defaultAutoCommit; + } + + @Override + public void setDefaultAutoCommit(Boolean defaultAutoCommit) { + this.defaultAutoCommit = defaultAutoCommit; + } + + @Override + public Boolean getAccessToUnderlyingConnectionAllowed() { + return accessToUnderlyingConnectionAllowed; + } + + @Override + public void setAccessToUnderlyingConnectionAllowed(Boolean accessToUnderlyingConnectionAllowed) { + this.accessToUnderlyingConnectionAllowed = accessToUnderlyingConnectionAllowed; + } + + @Override + public String getPoolName() { + return poolName; + } + + @Override + public void setPoolName(String poolName) { + this.poolName = poolName; + } + + @Override + public Integer getInitialSize() { + return initialSize; + } + + @Override + public void setInitialSize(Integer initialSize) { + this.initialSize = initialSize; + } + + @Override + public Integer getMinIdle() { + return minIdle; + } + + @Override + public void setMinIdle(Integer minIdle) { + this.minIdle = minIdle; + } + + @Override + public Integer getMaxIdle() { + return maxIdle; + } + + @Override + public void setMaxIdle(Integer maxIdle) { + this.maxIdle = maxIdle; + } + + @Override + public Integer getMaxTotal() { + return maxTotal; + } + + @Override + public void setMaxTotal(Integer maxTotal) { + this.maxTotal = maxTotal; + } + + @Override + public Duration getMaxWait() { + return maxWait; + } + + @Override + public void setMaxWait(Duration maxWait) { + this.maxWait = maxWait; + } + + @Override + public Boolean getTestOnCreate() { + return testOnCreate; + } + + @Override + public void setTestOnCreate(Boolean testOnCreate) { + this.testOnCreate = testOnCreate; + } + + @Override + public Boolean getTestOnBorrow() { + return testOnBorrow; + } + + @Override + public void setTestOnBorrow(Boolean testOnBorrow) { + this.testOnBorrow = testOnBorrow; + } + + @Override + public Boolean getTestOnReturn() { + return testOnReturn; + } + + @Override + public void setTestOnReturn(Boolean testOnReturn) { + this.testOnReturn = testOnReturn; + } + + @Override + public Boolean getTestWhileIdle() { + return testWhileIdle; + } + + @Override + public void setTestWhileIdle(Boolean testWhileIdle) { + this.testWhileIdle = testWhileIdle; + } + + @Override + public String getValidationQuery() { + return validationQuery; + } + + @Override + public void setValidationQuery(String validationQuery) { + this.validationQuery = validationQuery; + } + + @Override + public Duration getValidationQueryTimeout() { + return validationQueryTimeout; + } + + @Override + public void setValidationQueryTimeout(Duration validationQueryTimeout) { + this.validationQueryTimeout = validationQueryTimeout; + } + + @Override + public Duration getMinEvictableIdle() { + return minEvictableIdle; + } + + @Override + public void setMinEvictableIdle(Duration minEvictableIdle) { + this.minEvictableIdle = minEvictableIdle; + } + + @Override + public Duration getMaxEvictableIdle() { + return maxEvictableIdle; + } + + @Override + public void setMaxEvictableIdle(Duration maxEvictableIdle) { + this.maxEvictableIdle = maxEvictableIdle; + } + + @Override + public Integer getNumTestsPerEvictionRun() { + return numTestsPerEvictionRun; + } + + @Override + public void setNumTestsPerEvictionRun(Integer numTestsPerEvictionRun) { + this.numTestsPerEvictionRun = numTestsPerEvictionRun; + } + + @Override + public Duration getTimeBetweenEvictionRuns() { + return timeBetweenEvictionRuns; + } + + @Override + public void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns) { + this.timeBetweenEvictionRuns = timeBetweenEvictionRuns; + } + + @Override + public Boolean getLogAbandoned() { + return logAbandoned; + } + + @Override + public void setLogAbandoned(Boolean logAbandoned) { + this.logAbandoned = logAbandoned; + } + + @Override + public Duration getRemoveAbandonedTimeout() { + return removeAbandonedTimeout; + } + + @Override + public void setRemoveAbandonedTimeout(Duration removeAbandonedTimeout) { + this.removeAbandonedTimeout = removeAbandonedTimeout; + } + + @Override + public Jmx getJmx() { + return jmx; + } + + @Override + public void setJmx(Jmx jmx) { + this.jmx = jmx; + } + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/config/Config.java b/buession-jdbc/src/main/java/com/buession/jdbc/config/Config.java new file mode 100644 index 000000000..23c00c2df --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/config/Config.java @@ -0,0 +1,400 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.config; + +import com.buession.jdbc.core.Jmx; +import com.buession.jdbc.core.TransactionIsolation; + +import java.time.Duration; + +/** + * 数据源配置 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface Config { + + /** + * 返回查询超时时间 + * + * @return 查询超时时间 + */ + Duration getQueryTimeout(); + + /** + * 设置查询超时时间 + * + * @param queryTimeout + * 查询超时时间 + */ + void setQueryTimeout(Duration queryTimeout); + + /** + * 返回默认事务隔离级别 + * + * @return 默认事务隔离级别 + */ + TransactionIsolation getDefaultTransactionIsolation(); + + /** + * 设置默认事务隔离级别 + * + * @param defaultTransactionIsolation + * 默认事务隔离级别 + */ + void setDefaultTransactionIsolation(TransactionIsolation defaultTransactionIsolation); + + /** + * 返回连接是否是只读模式 + * + * @return 连接是否是只读模式 + */ + Boolean getDefaultReadOnly(); + + /** + * 设置连接是否是只读模式 + * + * @param defaultReadOnly + * 连接是否是只读模式 + */ + void setDefaultReadOnly(Boolean defaultReadOnly); + + /** + * 返回是否自动提交事务 + * + * @return 是否自动提交事务 + */ + Boolean getDefaultAutoCommit(); + + /** + * 设置是否自动提交事务 + * + * @param defaultAutoCommit + * 是否自动提交事务 + */ + void setDefaultAutoCommit(Boolean defaultAutoCommit); + + /** + * 返回 PoolGuard 是否可以访问底层连接 + * + * @return PoolGuard 是否可以访问底层连接 + */ + Boolean getAccessToUnderlyingConnectionAllowed(); + + /** + * 设置 PoolGuard 是否可以访问底层连接 + * + * @param accessToUnderlyingConnectionAllowed + * PoolGuard 是否可以访问底层连接 + */ + void setAccessToUnderlyingConnectionAllowed(Boolean accessToUnderlyingConnectionAllowed); + + /** + * 返回用户定义连接池的名称 + * + * @return 用户定义连接池的名称 + */ + String getPoolName(); + + /** + * 设置连接池的名称 + * + * @param poolName + * 连接池的名称 + */ + void setPoolName(String poolName); + + /** + * 返回初始连接数 + * + * @return 初始连接数 + */ + Integer getInitialSize(); + + /** + * 设置初始连接数 + * + * @param initialSize + * 初始连接数 + */ + void setInitialSize(Integer initialSize); + + /** + * 返回最小空闲连接数 + * + * @return 最小空闲连接数 + */ + Integer getMinIdle(); + + /** + * 设置最小空闲连接数 + * + * @param minIdle + * 最小空闲连接数 + */ + void setMinIdle(Integer minIdle); + + /** + * 返回最大空闲连接数 + * + * @return 最大空闲连接数 + */ + Integer getMaxIdle(); + + /** + * 设置最大空闲连接数,如设置为负数,则不限制 + * + * @param maxIdle + * 最大空闲连接数 + */ + void setMaxIdle(Integer maxIdle); + + /** + * 返回最大连接数 + * + * @return 最大连接数 + */ + Integer getMaxTotal(); + + /** + * 设置最大连接数,如设置为负数,则不限制 + * + * @param maxTotal + * 最大连接数 + */ + void setMaxTotal(Integer maxTotal); + + /** + * 返回从连接池获取一个连接时,最大的等待时间 + * + * @return 从连接池获取一个连接时,最大的等待时间 + */ + Duration getMaxWait(); + + /** + * 设置从连接池获取一个连接时,最大的等待时间 + * + * @param maxWait + * 从连接池获取一个连接时,最大的等待时间 + */ + void setMaxWait(Duration maxWait); + + /** + * 返回连接创建后,是否马上验证有效性 + * + * @return 连接创建后,是否马上验证有效性 + */ + Boolean getTestOnCreate(); + + /** + * 设置连接创建后,是否马上验证有效性 + * + * @param testOnCreate + * 连接创建后,是否马上验证有效性 + */ + void setTestOnCreate(Boolean testOnCreate); + + /** + * 返回从连接池获取一个连接时,是否验证有效性 + * + * @return 从连接池获取一个连接时,验证有效性 + */ + Boolean getTestOnBorrow(); + + /** + * 设置从连接池获取一个连接时,是否验证有效性 + * + * @param testOnBorrow + * 从连接池获取一个连接时,是否验证有效性 + */ + void setTestOnBorrow(Boolean testOnBorrow); + + /** + * 返回连接被归还到连接池时,是否验证有效性 + * + * @return 连接被归还到连接池时,是否验证有效性 + */ + Boolean getTestOnReturn(); + + /** + * 设置连接被归还到连接池时,是否验证有效性 + * + * @param testOnReturn + * 连接被归还到连接池时,是否验证有效性 + */ + void setTestOnReturn(Boolean testOnReturn); + + /** + * 返回连接空闲时,是否验证有效性 + * + * @return 连接空闲时,是否验证有效性 + */ + Boolean getTestWhileIdle(); + + /** + * 设置连接空闲时,是否验证有效性 + * + * @param testWhileIdle + * 连接空闲时,是否验证有效性 + */ + void setTestWhileIdle(Boolean testWhileIdle); + + /** + * 返回从连接池获取连接时, 验证连接是否可用的SQL语句 + * + * @return 从连接池获取连接时, 验证连接是否可用的SQL语句 + */ + String getValidationQuery(); + + /** + * 设置从连接池获取连接时, 验证连接是否可用的SQL语句 + * + * @param validationQuery + * 从连接池获取连接时, 验证连接是否可用的SQL语句 + */ + void setValidationQuery(String validationQuery); + + /** + * 返回连接有效SQL的执行查询超时时间 + * + * @return 连接有效SQL的执行查询超时时间 + */ + Duration getValidationQueryTimeout(); + + /** + * 设置连接有效SQL的执行查询超时时间 + * + * @param validationQueryTimeout + * 连接有效SQL的执行查询超时时间 + */ + void setValidationQueryTimeout(Duration validationQueryTimeout); + + /** + * 返回空闲的连接被释放最低要待时间 + * + * @return 空闲的连接被释放最低要待时间 + */ + Duration getMinEvictableIdle(); + + /** + * 设置空闲的连接被释放最低要待时间 + * + * @param minEvictableIdle + * 空闲的连接被释放最低要待时间 + */ + void setMinEvictableIdle(Duration minEvictableIdle); + + /** + * 返回空闲的连接被释放最高要待时间 + * + * @return 空闲的连接被释放最高要待时间 + */ + Duration getMaxEvictableIdle(); + + /** + * 设置空闲的连接被释放最高要待时间 + * + * @param maxEvictableIdle + * 空闲的连接被释放最高要待时间 + */ + void setMaxEvictableIdle(Duration maxEvictableIdle); + + /** + * 返回在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 + * + * @return 在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 + */ + Integer getNumTestsPerEvictionRun(); + + /** + * 设置在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 + * + * @param numTestsPerEvictionRun + * 在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 + */ + void setNumTestsPerEvictionRun(Integer numTestsPerEvictionRun); + + /** + * 返回空闲对象驱逐线程运行时的休眠时间 + * + * @return 空闲对象驱逐线程运行时的休眠时间 + */ + Duration getTimeBetweenEvictionRuns(); + + /** + * 设置空闲对象驱逐线程运行时的休眠时间 + * + * @param timeBetweenEvictionRuns + * 空闲对象驱逐线程运行时的休眠时间 + */ + void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns); + + /** + * 返回当连接被认为是废弃并且被移除时是否记录日志 + * + * @return 当连接被认为是废弃并且被移除时是否记录日志 + */ + Boolean getLogAbandoned(); + + /** + * 设置当连接被认为是废弃并且被移除时是否记录日志 + * + * @param logAbandoned + * 当连接被认为是废弃并且被移除时是否记录日志 + */ + void setLogAbandoned(Boolean logAbandoned); + + /** + * 返回指定连接在被认为是废弃连接(abandoned connection)之前的超时时间 + * + * @return 指定连接在被认为是废弃连接(abandoned connection)之前的超时时间 + */ + Duration getRemoveAbandonedTimeout(); + + /** + * 设置指定连接在被认为是废弃连接(abandoned connection)之前的超时时间 + * + * @param removeAbandonedTimeout + * 指定连接在被认为是废弃连接(abandoned connection)之前的超时时间 + */ + void setRemoveAbandonedTimeout(Duration removeAbandonedTimeout); + + /** + * 返回 JMX 管理对象配置 + * + * @return JMX 管理对象配置 + */ + Jmx getJmx(); + + /** + * 设置 JMX 管理对象配置 + * + * @param jmx + * JMX 管理对象配置 + */ + void setJmx(Jmx jmx); + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/config/Dbcp2Config.java b/buession-jdbc/src/main/java/com/buession/jdbc/config/Dbcp2Config.java new file mode 100644 index 000000000..dfae43c94 --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/config/Dbcp2Config.java @@ -0,0 +1,459 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.config; + +import java.sql.PreparedStatement; +import java.time.Duration; +import java.util.Set; + +/** + * DBCP2 数据源配置 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class Dbcp2Config extends BaseConfig { + + /** + * 实现 {@link org.apache.commons.dbcp2.ConnectionFactory} 接口,连接工厂实现类 + */ + private String connectionFactoryClassName; + + /** + * 验证快速失败 + */ + private Boolean fastFailValidation; + + /** + * 一个过期的连接被连接池关闭时,写日志标识; + * 如果连接存货时间超过 maxConnLifetimeMillis,连接将被连接池会抽,此时默认输出日志 + */ + private Boolean logExpiredConnections; + + /** + * 连接归还到池时,设置为自动提交 + */ + private Boolean autoCommitOnReturn; + + /** + * 连接归还到池时,是否回滚所有操作 + */ + private Boolean rollbackOnReturn; + + /** + * 缓存状态,如果设置为true, + * 池化的连接将在第一次读或写,以及随后的写的时候缓存当前的只读状态和自动提交设置。 + * 这样就省去了对 getter 的任何进一步的调用时对数据库的额外查询。 + * 如果直接访问底层连接,只读状态和/或自动提交设置改变缓存值将不会被反映到当前的状态,在这种情况下,应该将该属性设置为false以禁用缓存 + */ + private Boolean cacheState; + + /** + * 用于指定一组 SQL 错误代码,当连接池检测到这些错误代码时,会将连接标记为失效并将其从连接池中移除 + */ + private Set disconnectionSqlCodes; + + /** + * 连接的最大存活时间; + * 如果超过这个时间,则连接在下次激活、钝化、校验时都将会失败。如果设置为0或小于0的值,则连接的存活时间是无限的 + */ + private Duration maxConnLifetime; + + /** + * 是否缓存 preparedStatement,也就是PSCache; + * PSCache 对支持游标的数据库性能提升巨大,比如说 oracle,在mysql下建议关闭 + */ + private Boolean poolPreparedStatements; + + /** + * 可以在语句池中同时分配的最大语句数 + */ + private Integer maxOpenPreparedStatements; + + /** + * 是否清除与该连接关联的已缓存的 {@link PreparedStatement} 对象;启用后,每次连接返回到池中时,所有缓存的 PreparedStatement 对象都会被清除 + */ + private Boolean clearStatementPoolOnReturn; + + /** + * 从连接池借用连接时是否对废弃连接的检查 + */ + private Boolean removeAbandonedOnBorrow; + + /** + * 后台维护线程会在运行时定期检查连接池中的连接,并移除那些被认为是废弃的连接 + */ + private Boolean removeAbandonedOnMaintenance; + + /** + * 是否在每次连接被借出时记录当前的堆栈跟踪信息 + */ + private Boolean abandonedUsageTracking; + + /** + * 空闲的连接被释放最低要待时间,但有额外条件 + * 额外的条件是池中至少保留有 minIdle 所指定的个数的连接; + * 当 miniEvictableIdleTime 被设置为一个正数,空闲连接驱逐者首先检测 miniEvictableIdleTime , + * 当空闲连接被驱逐者访问时,首先与 miniEvictableIdleTime 所指定的值进行比较(而不考虑当前池中的空闲连接数), + * 然后比较 softMinEvictableIdleTime 所指定的连接数,包括 minIdle 条件 + */ + private Duration softMinEvictableIdle; + + /** + * 空闲对象驱逐策略名称 + */ + private String evictionPolicyClassName; + + /** + * 后进先出,设置为true表明连接池(如果池中有可用的空闲连接时)将返回最后一次使用的租借对象(最后进入), + * 设置为false则表明池将表现为FIFO队列(先进先出)—将会按照它们被归还的顺序从空闲连接实例池中获取连接 + */ + private Boolean lifo; + + /** + * 返回 {@link org.apache.commons.dbcp2.ConnectionFactory} 接口实现,连接工厂实现 + * + * @return {@link org.apache.commons.dbcp2.ConnectionFactory} 接口实现,连接工厂实现类 + */ + public String getConnectionFactoryClassName() { + return connectionFactoryClassName; + } + + /** + * 设置{@link org.apache.commons.dbcp2.ConnectionFactory} 接口实现,连接工厂实现类 + * + * @param connectionFactoryClassName + * {@link org.apache.commons.dbcp2.ConnectionFactory} 接口实现,连接工厂实现类 + */ + public void setConnectionFactoryClassName(String connectionFactoryClassName) { + this.connectionFactoryClassName = connectionFactoryClassName; + } + + /** + * 返回验证快速失败 + * + * @return 验证快速失败 + */ + public Boolean getFastFailValidation() { + return fastFailValidation; + } + + /** + * 设置验证快速失败 + * + * @param fastFailValidation + * 验证快速失败 + */ + public void setFastFailValidation(Boolean fastFailValidation) { + this.fastFailValidation = fastFailValidation; + } + + /** + * 返回一个过期的连接被连接池关闭时,写日志标识 + * + * @return 一个过期的连接被连接池关闭时,写日志标识 + */ + public Boolean getLogExpiredConnections() { + return logExpiredConnections; + } + + /** + * 设置一个过期的连接被连接池关闭时,写日志标识 + * + * @param logExpiredConnections + * 一个过期的连接被连接池关闭时,写日志标识 + */ + public void setLogExpiredConnections(Boolean logExpiredConnections) { + this.logExpiredConnections = logExpiredConnections; + } + + /** + * 返回连接归还到池时,设置为自动提交 + * + * @return 连接归还到池时,设置为自动提交 + */ + public Boolean getAutoCommitOnReturn() { + return autoCommitOnReturn; + } + + /** + * 设置连接归还到池时,是否自动提交 + * + * @param autoCommitOnReturn + * 连接归还到池时,是否自动提交 + */ + public void setAutoCommitOnReturn(Boolean autoCommitOnReturn) { + this.autoCommitOnReturn = autoCommitOnReturn; + } + + /** + * 返回连接归还到池时,是否回滚所有操作 + * + * @return 连接归还到池时,是否回滚所有操作 + */ + public Boolean getRollbackOnReturn() { + return rollbackOnReturn; + } + + /** + * 设置连接归还到池时,是否回滚所有操作 + * + * @param rollbackOnReturn + * 连接归还到池时,是否回滚所有操作 + */ + public void setRollbackOnReturn(Boolean rollbackOnReturn) { + this.rollbackOnReturn = rollbackOnReturn; + } + + /** + * 返回缓存状态 + * + * @return 缓存状态 + */ + public Boolean getCacheState() { + return cacheState; + } + + /** + * 设置缓存状态 + * + * @param cacheState + * 缓存状态 + */ + public void setCacheState(Boolean cacheState) { + this.cacheState = cacheState; + } + + /** + * 返回指定一组 SQL 错误代码,当连接池检测到这些错误代码时,会将连接标记为失效并将其从连接池中移除 + * + * @return 指定的 SQL 错误代码,当连接池检测到这些错误代码时,会将连接标记为失效并将其从连接池中移除 + */ + public Set getDisconnectionSqlCodes() { + return disconnectionSqlCodes; + } + + /** + * 设置一组 SQL 错误代码,当连接池检测到这些错误代码时,会将连接标记为失效并将其从连接池中移除 + * + * @param disconnectionSqlCodes + * 一组 SQL 错误代码,当连接池检测到这些错误代码时,会将连接标记为失效并将其从连接池中移除 + */ + public void setDisconnectionSqlCodes(Set disconnectionSqlCodes) { + this.disconnectionSqlCodes = disconnectionSqlCodes; + } + + /** + * 返回连接的最大存活时间 + * + * @return 连接的最大存活时间 + */ + public Duration getMaxConnLifetime() { + return maxConnLifetime; + } + + /** + * 设置连接的最大存活时间 + * + * @param maxConnLifetime + * 连接的最大存活时间 + */ + public void setMaxConnLifetime(Duration maxConnLifetime) { + this.maxConnLifetime = maxConnLifetime; + } + + /** + * 返回是否缓存 preparedStatement,也就是PSCache + * + * @return 是否缓存 preparedStatement,也就是PSCache + */ + public Boolean getPoolPreparedStatements() { + return poolPreparedStatements; + } + + /** + * 设置是否缓存 preparedStatement,也就是PSCache; + * PSCache 对支持游标的数据库性能提升巨大,比如说 oracle,在mysql下建议关闭 + * + * @param poolPreparedStatements + * 是否缓存 preparedStatement + */ + public void setPoolPreparedStatements(Boolean poolPreparedStatements) { + this.poolPreparedStatements = poolPreparedStatements; + } + + /** + * 返回可以在语句池中同时分配的最大语句数 + * + * @return 可以在语句池中同时分配的最大语句数 + */ + public Integer getMaxOpenPreparedStatements() { + return maxOpenPreparedStatements; + } + + /** + * 设置可以在语句池中同时分配的最大语句数 + * + * @param maxOpenPreparedStatements + * 可以在语句池中同时分配的最大语句数 + */ + public void setMaxOpenPreparedStatements(Integer maxOpenPreparedStatements) { + this.maxOpenPreparedStatements = maxOpenPreparedStatements; + } + + /** + * 返回是否清除与该连接关联的已缓存的 {@link PreparedStatement} 对象 + * + * @return 是否清除与该连接关联的已缓存的 {@link PreparedStatement} 对象 + */ + public Boolean getClearStatementPoolOnReturn() { + return clearStatementPoolOnReturn; + } + + /** + * 设置是否清除与该连接关联的已缓存的 {@link PreparedStatement} 对象;启用后,每次连接返回到池中时,所有缓存的 PreparedStatement 对象都会被清除 + * + * @param clearStatementPoolOnReturn + * 是否清除与该连接关联的已缓存的 {@link PreparedStatement} 对象 + */ + public void setClearStatementPoolOnReturn(Boolean clearStatementPoolOnReturn) { + this.clearStatementPoolOnReturn = clearStatementPoolOnReturn; + } + + /** + * 返回从连接池借用连接时是否对废弃连接的检查 + * + * @return 从连接池借用连接时是否对废弃连接的检查 + */ + public Boolean getRemoveAbandonedOnBorrow() { + return removeAbandonedOnBorrow; + } + + /** + * 设置从连接池借用连接时是否对废弃连接的检查 + * + * @param removeAbandonedOnBorrow + * 从连接池借用连接时是否对废弃连接的检查 + */ + public void setRemoveAbandonedOnBorrow(Boolean removeAbandonedOnBorrow) { + this.removeAbandonedOnBorrow = removeAbandonedOnBorrow; + } + + /** + * 返回后台维护线程会在运行时定期检查连接池中的连接,并移除那些被认为是废弃的连接 + * + * @return 后台维护线程会在运行时定期检查连接池中的连接,并移除那些被认为是废弃的连接 + */ + public Boolean getRemoveAbandonedOnMaintenance() { + return removeAbandonedOnMaintenance; + } + + /** + * 设置后台维护线程会在运行时定期检查连接池中的连接,并移除那些被认为是废弃的连接 + * + * @param removeAbandonedOnMaintenance + * 后台维护线程会在运行时定期检查连接池中的连接,并移除那些被认为是废弃的连接 + */ + public void setRemoveAbandonedOnMaintenance(Boolean removeAbandonedOnMaintenance) { + this.removeAbandonedOnMaintenance = removeAbandonedOnMaintenance; + } + + /** + * 返回是否在每次连接被借出时记录当前的堆栈跟踪信息 + * + * @return 是否在每次连接被借出时记录当前的堆栈跟踪信息 + */ + public Boolean getAbandonedUsageTracking() { + return abandonedUsageTracking; + } + + /** + * 设置是否在每次连接被借出时记录当前的堆栈跟踪信息 + * + * @param abandonedUsageTracking + * 是否在每次连接被借出时记录当前的堆栈跟踪信息 + */ + public void setAbandonedUsageTracking(Boolean abandonedUsageTracking) { + this.abandonedUsageTracking = abandonedUsageTracking; + } + + /** + * 返回空闲的连接被释放最低要待时间,但有额外条件 + * + * @return 空闲的连接被释放最低要待时间 + */ + public Duration getSoftMinEvictableIdle() { + return softMinEvictableIdle; + } + + /** + * 设置空闲的连接被释放最低要待时间 + * + * @param softMinEvictableIdle + * 空闲的连接被释放最低要待时间 + */ + public void setSoftMinEvictableIdle(Duration softMinEvictableIdle) { + this.softMinEvictableIdle = softMinEvictableIdle; + } + + /** + * 返回空闲对象驱逐策略名称 + * + * @return 空闲对象驱逐策略名称 + */ + public String getEvictionPolicyClassName() { + return evictionPolicyClassName; + } + + /** + * 设置空闲对象驱逐策略名称 + * + * @param evictionPolicyClassName + * 空闲对象驱逐策略名称 + */ + public void setEvictionPolicyClassName(String evictionPolicyClassName) { + this.evictionPolicyClassName = evictionPolicyClassName; + } + + /** + * 是否后进先出 + * + * @return 后进先出 + */ + public Boolean getLifo() { + return lifo; + } + + /** + * 设置后进先出 + * + * @param lifo + * 后进先出 + */ + public void setLifo(Boolean lifo) { + this.lifo = lifo; + } + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/config/DruidConfig.java b/buession-jdbc/src/main/java/com/buession/jdbc/config/DruidConfig.java new file mode 100644 index 000000000..3c6df2e86 --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/config/DruidConfig.java @@ -0,0 +1,1220 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.config; + +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import java.sql.PreparedStatement; +import java.time.Duration; +import java.util.Set; + +/** + * Druid 数据源配置 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class DruidConfig extends BaseConfig { + + /** + * 用户名回调 {@link NameCallback} 类名 + */ + private String userCallbackClassName; + + /** + * 密码回调 {@link PasswordCallback} 类名 + */ + private String passwordCallbackClassName; + + /** + * 连接超时 + */ + private Duration connectTimeout; + + /** + * 网络套接字的读超时 + */ + private Duration socketTimeout; + + /** + * 在发生连接错误后,连接池尝试重新获取连接之间的间隔时间 + */ + private Duration timeBetweenConnectError; + + /** + * 数据库连接发生 Socket 读取超时时,决定是否立即销毁该连接 + */ + private Boolean killWhenSocketReadTimeout; + + /** + * 物理连接的超时时间 + */ + private Duration phyTimeout; + + /** + * 物理数据库连接的最大使用次数,设定每个物理连接在被关闭之前最多可以被重复使用的次数 + */ + private Long phyMaxUseCount; + + /** + * 数据源初始化时是否以异步方式进行 + */ + private Boolean asyncInit; + + /** + * 是否启用特定的变体或选项 + */ + private Boolean initVariants; + + /** + * 在连接池初始化时应用的全局变体或选项 + */ + private Boolean initGlobalVariants; + + /** + * 自定义检查数据库连接的有效性类 + */ + private String validConnectionCheckerClassName; + + /** + * 连接出错重试次数 + */ + private Integer connectionErrorRetryAttempts; + + /** + * 数据源初始化过程中出现异常时,是否抛出异常 + */ + private Boolean initExceptionThrow; + + /** + * 异常分类器 {@link com.alibaba.druid.pool.ExceptionSorter} 名称; + * 用于检测和分类数据库连接中的异常,当检测到某些特定类型的异常时,可以根据分类器的判断来决定是否将当前连接标记为不可用,并从连接池中移除。 + */ + private String exceptionSorterClassName; + + /** + * 是否启用 Oracle JDBC 驱动的隐式连接缓存 + */ + private Boolean useOracleImplicitCache; + + /** + * 是否异步关闭连接 + */ + private Boolean asyncCloseConnectionEnable; + + /** + * 在事务中执行的 SQL 查询的超时时间 + */ + private Duration transactionQueryTimeout; + + /** + * 事务的阈值时间 + */ + private Duration transactionThreshold; + + /** + * 控制连接池内部锁机制的公平性。 + * 当为 {@code true} 时,使用公平锁,公平锁保证线程获取锁的顺序是按照线程请求锁的顺序,即先请求锁的线程会先获得锁;适用于对锁获取顺序有严格要求的场景,但可能会导致较高的上下文切换成本,从而影响性能。 + * 当为 {@code false} 时,使用非公平锁,非公平锁在获取锁时不考虑线程的请求顺序,可能会导致“线程饥饿”现象,但通常能够提供更好的吞吐量和性能。 + */ + private Boolean fairLock; + + /** + * 数据源初始化过程中,如果发生错误,是否立即停止初始化并抛出异常 + */ + private Boolean failFast; + + /** + * 是否监控执行时间 + */ + private Boolean checkExecuteTime; + + /** + * 是否启用全局数据源统计功能 + */ + private Boolean useGlobalDataSourceStat; + + /** + * SQL 监控日志的记录器名称 + */ + private String statLoggerClassName; + + /** + * SQL 监控统计中 SQL 语句的最大数量;当超过这个数量时,Druid 会自动清理掉最早的一些 SQL 监控信息,以保持在设定的最大值以内; + * 这个设置有助于防止在高并发或长时间运行的情况下,SQL 监控信息占用过多的内存。 + */ + private Integer maxSqlSize; + + /** + * 是否启用重置统计 + */ + private Boolean resetStatEnable; + + /** + * 过滤器 + */ + private Set filters; + + /** + * 是否跳过加载 SPI 机制下的 {@link com.alibaba.druid.filter.Filter} + */ + private Boolean loadSpifilterSkip; + + /** + * 是否允许清除过滤器 + */ + private Boolean clearFiltersEnable; + + private Boolean enable; + + /** + * 最大连接数,可以在这个池中同一时刻被分配的有效连接数的最大值,如设置为负数,则不限制 + */ + private Integer maxActive; + + /** + * 数据库连接池中的空闲连接是否保持存活 + */ + private Boolean keepAlive; + + /** + * 连接池中空闲连接的保活间隔时间,这个属性决定了在连接池中,空闲连接每隔多长时间会被检查并进行保活操作,以确保这些连接在空闲时不会被数据库服务器断开 + */ + private Duration keepAliveBetweenTime; + + /** + * 测试连接是否有效时是否使用 PING 方法 + */ + private Boolean usePingMethod; + + /** + * 连接池在将连接返回到连接池时,是否保留连接的原始事务隔离级别 + */ + private Boolean keepConnectionUnderlyingTransactionIsolation; + + /** + * 连接池中创建连接任务的最大数量 + */ + private Integer maxCreateTaskCount; + + /** + * 连接池中等待数据库连接的最大线程数量 + */ + private Integer maxWaitThreadCount; + + /** + * 在发生致命错误(fatal error)时连接池的最大活动连接数 + */ + private Integer onFatalErrorMaxActive; + + /** + * 在获取连接失败后,是否立即断开(标记为不可用)连接池中的所有连接 + */ + private Boolean breakAfterAcquireFailure; + + /** + * 当连接池未满且没有可用连接时,系统在超时前重试获取连接的次数 + */ + private Integer notFullTimeoutRetryCount; + + /** + * 是否使用本地会话状态;这个配置主要用于处理连接池中的数据库连接在会话级别的状态管理。 + */ + private Boolean useLocalSessionState; + + /** + * 是否缓存 {@link PreparedStatement},也就是PSCache; + * PSCache 对支持游标的数据库性能提升巨大,比如说 oracle,在mysql下建议关闭 + */ + private Boolean poolPreparedStatements; + + /** + * 连接池中是否启用 {@link PreparedStatement} 的共享功能 + */ + private Boolean sharePreparedStatements; + + /** + * 每个数据库连接上可以缓存的 {@link PreparedStatement} 对象的最大数量 + */ + private Integer maxPoolPreparedStatementPerConnectionSize; + + /** + * 最大打开 PSCache 数,在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些 + */ + private Integer maxOpenPreparedStatements; + + /** + * 是否移除抛弃的(abandoned)连接,一个连接使用超过了 removeAbandonedTimeout 上限就被视为抛弃的, + * 开启该开关可以恢复那些应用没有关闭的连接 + */ + private Boolean removeAbandoned; + + /** + * 日志统计信息的记录间隔时间 + */ + private Duration timeBetweenLogStats; + + /** + * 是否在连接关闭时记录日志 + */ + private Boolean dupCloseLogEnable; + + /** + * 控制在获取连接和关闭连接时是否记录线程不一致的情况 + */ + private Boolean logDifferentThread; + + /** + * 返回用户名回调 {@link NameCallback} 类名 + * + * @return 用户名回调 {@link NameCallback} 类名 + */ + public String getUserCallbackClassName() { + return userCallbackClassName; + } + + /** + * 设置用户名回调 {@link NameCallback} 类名 + * + * @param userCallbackClassName + * 用户名回调 {@link NameCallback} 类名 + */ + public void setUserCallbackClassName(String userCallbackClassName) { + this.userCallbackClassName = userCallbackClassName; + } + + /** + * 返回密码回调 {@link PasswordCallback} 类名 + * + * @return 密码回调 {@link PasswordCallback} 类名 + */ + public String getPasswordCallbackClassName() { + return passwordCallbackClassName; + } + + /** + * 设置密码回调 {@link PasswordCallback} 类名 + * + * @param passwordCallbackClassName + * 密码回调 {@link PasswordCallback} 类名 + */ + public void setPasswordCallbackClassName(String passwordCallbackClassName) { + this.passwordCallbackClassName = passwordCallbackClassName; + } + + /** + * 返回连接超时 + * + * @return 连接超时 + */ + public Duration getConnectTimeout() { + return connectTimeout; + } + + /** + * 设置连接超时 + * + * @param connectTimeout + * 连接超时 + */ + public void setConnectTimeout(Duration connectTimeout) { + this.connectTimeout = connectTimeout; + } + + /** + * 返回网络套接字的读超时 + * + * @return 网络套接字的读超时 + */ + public Duration getSocketTimeout() { + return socketTimeout; + } + + /** + * 设置网络套接字的读超时 + * + * @param socketTimeout + * 网络套接字的读超时 + */ + public void setSocketTimeout(Duration socketTimeout) { + this.socketTimeout = socketTimeout; + } + + /** + * 返回在发生连接错误后,连接池尝试重新获取连接之间的间隔时间 + * + * @return 在发生连接错误后,连接池尝试重新获取连接之间的间隔时间 + */ + public Duration getTimeBetweenConnectError() { + return timeBetweenConnectError; + } + + /** + * 设置在发生连接错误后,连接池尝试重新获取连接之间的间隔时间 + * + * @param timeBetweenConnectError + * 在发生连接错误后,连接池尝试重新获取连接之间的间隔时间 + */ + public void setTimeBetweenConnectError(Duration timeBetweenConnectError) { + this.timeBetweenConnectError = timeBetweenConnectError; + } + + /** + * 返回数据库连接发生 Socket 读取超时时,决定是否立即销毁该连接 + * + * @return 数据库连接发生 Socket 读取超时时,决定是否立即销毁该连接 + */ + public Boolean getKillWhenSocketReadTimeout() { + return killWhenSocketReadTimeout; + } + + /** + * 设置数据库连接发生 Socket 读取超时时,决定是否立即销毁该连接 + * + * @param killWhenSocketReadTimeout + * 数据库连接发生 Socket 读取超时时,决定是否立即销毁该连接 + */ + public void setKillWhenSocketReadTimeout(Boolean killWhenSocketReadTimeout) { + this.killWhenSocketReadTimeout = killWhenSocketReadTimeout; + } + + /** + * 返回物理连接的超时时间 + * + * @return 物理连接的超时时间 + */ + public Duration getPhyTimeout() { + return phyTimeout; + } + + /** + * 设置物理连接的超时时间 + * + * @param phyTimeout + * 物理连接的超时时间 + */ + public void setPhyTimeout(Duration phyTimeout) { + this.phyTimeout = phyTimeout; + } + + /** + * 返回物理数据库连接的最大使用次数,设定每个物理连接在被关闭之前最多可以被重复使用的次数 + * + * @return 物理数据库连接的最大使用次数 + */ + public Long getPhyMaxUseCount() { + return phyMaxUseCount; + } + + /** + * 设置物理数据库连接的最大使用次数,设定每个物理连接在被关闭之前最多可以被重复使用的次数 + * + * @param phyMaxUseCount + * 物理数据库连接的最大使用次数,设定每个物理连接在被关闭之前最多可以被重复使用的次数 + */ + public void setPhyMaxUseCount(Long phyMaxUseCount) { + this.phyMaxUseCount = phyMaxUseCount; + } + + /** + * 返回数据源初始化时是否以异步方式进行 + * + * @return 数据源初始化时是否以异步方式进行 + */ + public Boolean getAsyncInit() { + return asyncInit; + } + + /** + * 设置数据源初始化时是否以异步方式进行 + * + * @param asyncInit + * 数据源初始化时是否以异步方式进行 + */ + public void setAsyncInit(Boolean asyncInit) { + this.asyncInit = asyncInit; + } + + /** + * 返回是否启用特定的变体或选项 + * + * @return 是否启用特定的变体或选项 + */ + public Boolean getInitVariants() { + return initVariants; + } + + /** + * 设置是否启用特定的变体或选项 + * + * @param initVariants + * 是否启用特定的变体或选项 + */ + public void setInitVariants(Boolean initVariants) { + this.initVariants = initVariants; + } + + /** + * 返回在连接池初始化时应用的全局变体或选项 + * + * @return 在连接池初始化时应用的全局变体或选项 + */ + public Boolean getInitGlobalVariants() { + return initGlobalVariants; + } + + /** + * 设置在连接池初始化时应用的全局变体或选项 + * + * @param initGlobalVariants + * 在连接池初始化时应用的全局变体或选项 + */ + public void setInitGlobalVariants(Boolean initGlobalVariants) { + this.initGlobalVariants = initGlobalVariants; + } + + /** + * 返回自定义检查数据库连接的有效性类 + * + * @return 自定义检查数据库连接的有效性类 + */ + public String getValidConnectionCheckerClassName() { + return validConnectionCheckerClassName; + } + + /** + * 设置自定义检查数据库连接的有效性类 + * + * @param validConnectionCheckerClassName + * 自定义检查数据库连接的有效性类 + */ + public void setValidConnectionCheckerClassName(String validConnectionCheckerClassName) { + this.validConnectionCheckerClassName = validConnectionCheckerClassName; + } + + /** + * 返回连接出错重试次数 + * + * @return 连接出错重试次数 + */ + public Integer getConnectionErrorRetryAttempts() { + return connectionErrorRetryAttempts; + } + + /** + * 设置连接出错重试次数 + * + * @param connectionErrorRetryAttempts + * 连接出错重试次数 + */ + public void setConnectionErrorRetryAttempts(Integer connectionErrorRetryAttempts) { + this.connectionErrorRetryAttempts = connectionErrorRetryAttempts; + } + + /** + * 返回数据源初始化过程中出现异常时,是否抛出异常 + * + * @return 数据源初始化过程中出现异常时,是否抛出异常 + */ + public Boolean getInitExceptionThrow() { + return initExceptionThrow; + } + + /** + * 设置数据源初始化过程中出现异常时,是否抛出异常 + * + * @param initExceptionThrow + * 数据源初始化过程中出现异常时,是否抛出异常 + */ + public void setInitExceptionThrow(Boolean initExceptionThrow) { + this.initExceptionThrow = initExceptionThrow; + } + + /** + * 异常分类器 {@link com.alibaba.druid.pool.ExceptionSorter} 名称 + * + * @return 异常分类器 {@link com.alibaba.druid.pool.ExceptionSorter} 名称 + */ + public String getExceptionSorterClassName() { + return exceptionSorterClassName; + } + + /** + * 设置异常分类器 {@link com.alibaba.druid.pool.ExceptionSorter} 名称 + * + * @param exceptionSorterClassName + * 异常分类器 {@link com.alibaba.druid.pool.ExceptionSorter} 名称 + */ + public void setExceptionSorterClassName(String exceptionSorterClassName) { + this.exceptionSorterClassName = exceptionSorterClassName; + } + + /** + * 返回是否启用 Oracle JDBC 驱动的隐式连接缓存 + * + * @return 是否启用 Oracle JDBC 驱动的隐式连接缓存 + */ + public Boolean getUseOracleImplicitCache() { + return useOracleImplicitCache; + } + + /** + * 设置是否启用 Oracle JDBC 驱动的隐式连接缓存 + * + * @param useOracleImplicitCache + * 是否启用 Oracle JDBC 驱动的隐式连接缓存 + */ + public void setUseOracleImplicitCache(Boolean useOracleImplicitCache) { + this.useOracleImplicitCache = useOracleImplicitCache; + } + + /** + * 返回是否异步关闭连接 + * + * @return 是否异步关闭连接 + */ + public Boolean getAsyncCloseConnectionEnable() { + return asyncCloseConnectionEnable; + } + + /** + * 设置是否异步关闭连接 + * + * @param asyncCloseConnectionEnable + * 是否异步关闭连接 + */ + public void setAsyncCloseConnectionEnable(Boolean asyncCloseConnectionEnable) { + this.asyncCloseConnectionEnable = asyncCloseConnectionEnable; + } + + /** + * 返回在事务中执行的 SQL 查询的超时时间 + * + * @return 在事务中执行的 SQL 查询的超时时间 + */ + public Duration getTransactionQueryTimeout() { + return transactionQueryTimeout; + } + + /** + * 设置在事务中执行的 SQL 查询的超时时间 + * + * @param transactionQueryTimeout + * 在事务中执行的 SQL 查询的超时时间 + */ + public void setTransactionQueryTimeout(Duration transactionQueryTimeout) { + this.transactionQueryTimeout = transactionQueryTimeout; + } + + /** + * 返回事务的阈值时间 + * + * @return 事务的阈值时间 + */ + public Duration getTransactionThreshold() { + return transactionThreshold; + } + + /** + * 设置事务的阈值时间 + * + * @param transactionThreshold + * 事务的阈值时间 + */ + public void setTransactionThreshold(Duration transactionThreshold) { + this.transactionThreshold = transactionThreshold; + } + + /** + * 返回是否使用公平锁 + * + * @return 是否使用公平锁 + */ + public Boolean getFairLock() { + return fairLock; + } + + /** + * 设置是否使用公平锁 + * + * @param fairLock + * 是否使用公平锁 + */ + public void setFairLock(Boolean fairLock) { + this.fairLock = fairLock; + } + + /** + * 返回数据源初始化过程中,如果发生错误,是否立即停止初始化并抛出异常 + * + * @return 数据源初始化过程中,如果发生错误,是否立即停止初始化并抛出异常 + */ + public Boolean getFailFast() { + return failFast; + } + + /** + * 设置数据源初始化过程中,如果发生错误,是否立即停止初始化并抛出异常 + * + * @param failFast + * 数据源初始化过程中,如果发生错误,是否立即停止初始化并抛出异常 + */ + public void setFailFast(Boolean failFast) { + this.failFast = failFast; + } + + /** + * 返回是否监控执行时间 + * + * @return 是否监控执行时间 + */ + public Boolean getCheckExecuteTime() { + return checkExecuteTime; + } + + /** + * 设置是否监控执行时间 + * + * @param checkExecuteTime + * 是否监控执行时间 + */ + public void setCheckExecuteTime(Boolean checkExecuteTime) { + this.checkExecuteTime = checkExecuteTime; + } + + /** + * 返回是否启用全局数据源统计功能 + * + * @return 是否启用全局数据源统计功能 + */ + public Boolean getUseGlobalDataSourceStat() { + return useGlobalDataSourceStat; + } + + /** + * 设置是否启用全局数据源统计功能 + * + * @param useGlobalDataSourceStat + * 是否启用全局数据源统计功能 + */ + public void setUseGlobalDataSourceStat(Boolean useGlobalDataSourceStat) { + this.useGlobalDataSourceStat = useGlobalDataSourceStat; + } + + /** + * 返回 SQL 监控日志的记录器名称 + * + * @return SQL 监控日志的记录器名称 + */ + public String getStatLoggerClassName() { + return statLoggerClassName; + } + + /** + * 设置 SQL 监控日志的记录器名称 + * + * @param statLoggerClassName + * SQL 监控日志的记录器名称 + */ + public void setStatLoggerClassName(String statLoggerClassName) { + this.statLoggerClassName = statLoggerClassName; + } + + /** + * 返回 SQL 监控统计中 SQL 语句的最大数量 + * + * @return SQL 监控统计中 SQL 语句的最大数量 + */ + public Integer getMaxSqlSize() { + return maxSqlSize; + } + + /** + * 设置 SQL 监控统计中 SQL 语句的最大数量 + * + * @param maxSqlSize + * SQL 监控统计中 SQL 语句的最大数量 + */ + public void setMaxSqlSize(Integer maxSqlSize) { + this.maxSqlSize = maxSqlSize; + } + + /** + * 返回是否启用重置统计 + * + * @return 是否启用重置统计 + */ + public Boolean getResetStatEnable() { + return resetStatEnable; + } + + /** + * 设置是否启用重置统计 + * + * @param resetStatEnable + * 是否启用重置统计 + */ + public void setResetStatEnable(Boolean resetStatEnable) { + this.resetStatEnable = resetStatEnable; + } + + /** + * 返回过滤器 + * + * @return 过滤器 + */ + public Set getFilters() { + return filters; + } + + /** + * 设置过滤器 + * + * @param filters + * 过滤器 + */ + public void setFilters(Set filters) { + this.filters = filters; + } + + /** + * 返回是否跳过加载 SPI 机制下的 {@link com.alibaba.druid.filter.Filter} + * + * @return 是否跳过加载 SPI 机制下的 {@link com.alibaba.druid.filter.Filter} + */ + public Boolean getLoadSpifilterSkip() { + return loadSpifilterSkip; + } + + /** + * 设置是否跳过加载 SPI 机制下的 {@link com.alibaba.druid.filter.Filter} + * + * @param loadSpifilterSkip + * 是否跳过加载 SPI 机制下的 {@link com.alibaba.druid.filter.Filter} + */ + public void setLoadSpifilterSkip(Boolean loadSpifilterSkip) { + this.loadSpifilterSkip = loadSpifilterSkip; + } + + /** + * 返回是否允许清除过滤器 + * + * @return 是否允许清除过滤器 + */ + public Boolean getClearFiltersEnable() { + return clearFiltersEnable; + } + + /** + * 设置是否允许清除过滤器 + * + * @param clearFiltersEnable + * 是否允许清除过滤器 + */ + public void setClearFiltersEnable(Boolean clearFiltersEnable) { + this.clearFiltersEnable = clearFiltersEnable; + } + + public Boolean getEnable() { + return enable; + } + + public void setEnable(Boolean enable) { + this.enable = enable; + } + + /** + * 返回最大连接数 + * + * @return 最大连接数 + */ + public Integer getMaxActive() { + return maxActive; + } + + /** + * 设置最大连接数 + * + * @param maxActive + * 最大连接数 + */ + public void setMaxActive(Integer maxActive) { + this.maxActive = maxActive; + super.setMaxTotal(maxActive); + } + + @Override + public void setMaxTotal(Integer maxTotal) { + setMaxActive(maxTotal); + } + + /** + * 返回数据库连接池中的空闲连接是否保持存活 + * + * @return 数据库连接池中的空闲连接是否保持存活 + * + * @since 3.0.0 + */ + public Boolean getKeepAlive() { + return keepAlive; + } + + /** + * 设置数据库连接池中的空闲连接是否保持存活 + * + * @param keepAlive + * 数据库连接池中的空闲连接是否保持存活 + * + * @since 3.0.0 + */ + public void setKeepAlive(Boolean keepAlive) { + this.keepAlive = keepAlive; + } + + /** + * 返回连接池中空闲连接的保活间隔时间 + * + * @return 连接池中空闲连接的保活间隔时间 + */ + public Duration getKeepAliveBetweenTime() { + return keepAliveBetweenTime; + } + + /** + * 设置连接池中空闲连接的保活间隔时间 + * + * @param keepAliveBetweenTime + * 连接池中空闲连接的保活间隔时间 + */ + public void setKeepAliveBetweenTime(Duration keepAliveBetweenTime) { + this.keepAliveBetweenTime = keepAliveBetweenTime; + } + + /** + * 返回测试连接是否有效时是否使用 PING 方法 + * + * @return 测试连接是否有效时是否使用 PING 方法 + */ + public Boolean getUsePingMethod() { + return usePingMethod; + } + + /** + * 设置测试连接是否有效时是否使用 PING 方法 + * + * @param usePingMethod + * 测试连接是否有效时是否使用 PING 方法 + */ + public void setUsePingMethod(Boolean usePingMethod) { + this.usePingMethod = usePingMethod; + } + + /** + * 返回连接池在将连接返回到连接池时,是否保留连接的原始事务隔离级别 + * + * @return 连接池在将连接返回到连接池时,是否保留连接的原始事务隔离级别 + */ + public Boolean getKeepConnectionUnderlyingTransactionIsolation() { + return keepConnectionUnderlyingTransactionIsolation; + } + + /** + * 设置连接池在将连接返回到连接池时,是否保留连接的原始事务隔离级别 + * + * @param keepConnectionUnderlyingTransactionIsolation + * 连接池在将连接返回到连接池时,是否保留连接的原始事务隔离级别 + */ + public void setKeepConnectionUnderlyingTransactionIsolation(Boolean keepConnectionUnderlyingTransactionIsolation) { + this.keepConnectionUnderlyingTransactionIsolation = keepConnectionUnderlyingTransactionIsolation; + } + + /** + * 返回连接池中创建连接任务的最大数量 + * + * @return 连接池中创建连接任务的最大数量 + */ + public Integer getMaxCreateTaskCount() { + return maxCreateTaskCount; + } + + /** + * 设置连接池中创建连接任务的最大数量 + * + * @param maxCreateTaskCount + * 连接池中创建连接任务的最大数量 + */ + public void setMaxCreateTaskCount(Integer maxCreateTaskCount) { + this.maxCreateTaskCount = maxCreateTaskCount; + } + + /** + * 返回连接池中等待数据库连接的最大线程数量 + * + * @return 连接池中等待数据库连接的最大线程数量 + */ + public Integer getMaxWaitThreadCount() { + return maxWaitThreadCount; + } + + /** + * 设置连接池中等待数据库连接的最大线程数量 + * + * @param maxWaitThreadCount + * 连接池中等待数据库连接的最大线程数量 + */ + public void setMaxWaitThreadCount(Integer maxWaitThreadCount) { + this.maxWaitThreadCount = maxWaitThreadCount; + } + + /** + * 返回在发生致命错误(fatal error)时连接池的最大活动连接数 + * + * @return 在发生致命错误(fatal error)时连接池的最大活动连接数 + */ + public Integer getOnFatalErrorMaxActive() { + return onFatalErrorMaxActive; + } + + /** + * 设置在发生致命错误(fatal error)时连接池的最大活动连接数 + * + * @param onFatalErrorMaxActive + * 在发生致命错误(fatal error)时连接池的最大活动连接数 + */ + public void setOnFatalErrorMaxActive(Integer onFatalErrorMaxActive) { + this.onFatalErrorMaxActive = onFatalErrorMaxActive; + } + + /** + * 返回在获取连接失败后,是否立即断开(标记为不可用)连接池中的所有连接 + * + * @return 在获取连接失败后,是否立即断开(标记为不可用)连接池中的所有连接 + */ + public Boolean getBreakAfterAcquireFailure() { + return breakAfterAcquireFailure; + } + + /** + * 设置在获取连接失败后,是否立即断开(标记为不可用)连接池中的所有连接 + * + * @param breakAfterAcquireFailure + * 在获取连接失败后,是否立即断开(标记为不可用)连接池中的所有连接 + */ + public void setBreakAfterAcquireFailure(Boolean breakAfterAcquireFailure) { + this.breakAfterAcquireFailure = breakAfterAcquireFailure; + } + + /** + * 返回当连接池未满且没有可用连接时,系统在超时前重试获取连接的次数 + * + * @return 当连接池未满且没有可用连接时,系统在超时前重试获取连接的次数 + */ + public Integer getNotFullTimeoutRetryCount() { + return notFullTimeoutRetryCount; + } + + /** + * 设置当连接池未满且没有可用连接时,系统在超时前重试获取连接的次数 + * + * @param notFullTimeoutRetryCount + * 当连接池未满且没有可用连接时,系统在超时前重试获取连接的次数 + */ + public void setNotFullTimeoutRetryCount(Integer notFullTimeoutRetryCount) { + this.notFullTimeoutRetryCount = notFullTimeoutRetryCount; + } + + /** + * 返回是否使用本地会话状态 + * + * @return 是否使用本地会话状态 + */ + public Boolean getUseLocalSessionState() { + return useLocalSessionState; + } + + /** + * 设置是否使用本地会话状态 + * + * @param useLocalSessionState + * 是否使用本地会话状态 + */ + public void setUseLocalSessionState(Boolean useLocalSessionState) { + this.useLocalSessionState = useLocalSessionState; + } + + /** + * 返回是否缓存 {@link PreparedStatement},也就是PSCache + * + * @return 是否缓存 preparedStatement,也就是PSCache + */ + public Boolean getPoolPreparedStatements() { + return poolPreparedStatements; + } + + /** + * 设置是否缓存 {@link PreparedStatement},也就是PSCache; + * PSCache 对支持游标的数据库性能提升巨大,比如说 oracle,在mysql下建议关闭 + * + * @param poolPreparedStatements + * 是否缓存 preparedStatement + */ + public void setPoolPreparedStatements(Boolean poolPreparedStatements) { + this.poolPreparedStatements = poolPreparedStatements; + } + + /** + * 返回连接池中是否启用 {@link PreparedStatement} 的共享功能 + * + * @return 连接池中是否启用 {@link PreparedStatement} 的共享功能 + */ + public Boolean getSharePreparedStatements() { + return sharePreparedStatements; + } + + /** + * 设置连接池中是否启用 {@link PreparedStatement} 的共享功能 + * + * @param sharePreparedStatements + * 连接池中是否启用 {@link PreparedStatement} 的共享功能 + */ + public void setSharePreparedStatements(Boolean sharePreparedStatements) { + this.sharePreparedStatements = sharePreparedStatements; + } + + /** + * 返回每个数据库连接上可以缓存的 {@link PreparedStatement} 对象的最大数量 + * + * @return 每个数据库连接上可以缓存的 {@link PreparedStatement} 对象的最大数量 + */ + public Integer getMaxPoolPreparedStatementPerConnectionSize() { + return maxPoolPreparedStatementPerConnectionSize; + } + + /** + * 设置每个数据库连接上可以缓存的 {@link PreparedStatement} 对象的最大数量 + * + * @param maxPoolPreparedStatementPerConnectionSize + * 每个数据库连接上可以缓存的 {@link PreparedStatement} 对象的最大数量 + */ + public void setMaxPoolPreparedStatementPerConnectionSize(Integer maxPoolPreparedStatementPerConnectionSize) { + this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize; + } + + /** + * 返回最大打开 PSCache 数 + * + * @return 最大打开 PSCache 数 + */ + public Integer getMaxOpenPreparedStatements() { + return maxOpenPreparedStatements; + } + + /** + * 设置最大打开 PSCache 数,在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些 + * + * @param maxOpenPreparedStatements + * 最大打开 PSCache 数 + */ + public void setMaxOpenPreparedStatements(Integer maxOpenPreparedStatements) { + this.maxOpenPreparedStatements = maxOpenPreparedStatements; + } + + /** + * 返回是否移除抛弃的(abandoned)连接 + * + * @return 是否移除抛弃的(abandoned)连接 + */ + public Boolean getRemoveAbandoned() { + return removeAbandoned; + } + + /** + * 设置是否移除抛弃的(abandoned)连接 + * + * @param removeAbandoned + * 是否移除抛弃的(abandoned)连接 + */ + public void setRemoveAbandoned(Boolean removeAbandoned) { + this.removeAbandoned = removeAbandoned; + } + + /** + * 返回日志统计信息的记录间隔时间 + * + * @return 日志统计信息的记录间隔时间 + */ + public Duration getTimeBetweenLogStats() { + return timeBetweenLogStats; + } + + /** + * 设置日志统计信息的记录间隔时间 + * + * @param timeBetweenLogStats + * 日志统计信息的记录间隔时间 + */ + public void setTimeBetweenLogStats(Duration timeBetweenLogStats) { + this.timeBetweenLogStats = timeBetweenLogStats; + } + + /** + * 返回是否在连接关闭时记录日志 + * + * @return 是否在连接关闭时记录日志 + */ + public Boolean getDupCloseLogEnable() { + return dupCloseLogEnable; + } + + /** + * 设置是否在连接关闭时记录日志 + * + * @param dupCloseLogEnable + * 是否在连接关闭时记录日志 + */ + public void setDupCloseLogEnable(Boolean dupCloseLogEnable) { + this.dupCloseLogEnable = dupCloseLogEnable; + } + + /** + * 返回是否在获取连接和关闭连接时是否记录线程不一致的情况 + * + * @return 是否在获取连接和关闭连接时是否记录线程不一致的情况 + */ + public Boolean getLogDifferentThread() { + return logDifferentThread; + } + + /** + * 设置在获取连接和关闭连接时是否记录线程不一致的情况 + * + * @param logDifferentThread + * 是否在获取连接和关闭连接时是否记录线程不一致的情况 + */ + public void setLogDifferentThread(Boolean logDifferentThread) { + this.logDifferentThread = logDifferentThread; + } + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/config/GenericConfig.java b/buession-jdbc/src/main/java/com/buession/jdbc/config/GenericConfig.java new file mode 100644 index 000000000..a49ee74a0 --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/config/GenericConfig.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.config; + +/** + * 一般数据源配置 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class GenericConfig extends BaseConfig { + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/config/HikariConfig.java b/buession-jdbc/src/main/java/com/buession/jdbc/config/HikariConfig.java new file mode 100644 index 000000000..1c0d425cf --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/config/HikariConfig.java @@ -0,0 +1,435 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.config; + +import com.zaxxer.hikari.metrics.MetricsTrackerFactory; + +import java.time.Duration; +import java.util.Properties; + +/** + * Hikari 数据源配置 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HikariConfig extends BaseConfig { + + /** + * JNDI 数据源的名称 + */ + private String jndiName; + + /** + * 从连接池获取连接时最大等待时间 + */ + private Duration connectionTimeout; + + /** + * 是否将 HikariCP 执行的内部查询与应用程序的查询隔离 + */ + private Boolean isolateInternalQueries; + + /** + * 连接池无法成功建立连接,是否会立即抛出异常或进行重试,以及重试的超时时间 + */ + private Duration initializationFailTimeout; + + /** + * 接池中最大连接数,如设置为负数,则不限制 + */ + private Integer maxPoolSize; + + /** + * 设置一个SQL语句, 从连接池获取连接时, 先执行改 sql, 验证连接是否可用 + * 如果是使用了 JDBC 4 那么不建议配置这个选项, 因为JDBC 4 使用 ping 命令, 更加高效 + */ + private String connectionTestQuery; + + /** + * 检测连接是否有效的超时时间 + */ + private Duration validationTimeout; + + /** + * 连接允许在池中闲置的最长时间,仅适用于 minimumIdle 定义为小于 maximumPoolSize,值为 0 时空闲连接永远不会从池中删除 + */ + private Duration idleTimeout; + + /** + * 池中连接的最大生存期,值为 0 时表示无限寿命, 推荐设置的比数据库的 wait_timeout 小几秒到几分钟 + */ + private Duration maxLifetime; + + /** + * 连接在空闲时发送“keep-alive”心跳的间隔时间 + */ + private Duration keepaliveTime; + + /** + * 控制在记录消息之前连接可能离开池的时间量,表明可能存在连接泄漏,值为 0 时泄漏检测被禁用 + */ + private Duration leakDetectionThreshold; + + /** + * 是否允许将连接池挂起 + */ + private Boolean allowPoolSuspension; + + /** + * 连接池的性能指标跟踪器 {@link MetricsTrackerFactory} 类名 + */ + private String metricsTrackerFactoryClassName; + + /** + * 允许将 HikariCP 连接池的性能指标集成到基于 Dropwizard Metrics 的监控系统中 + */ + private String metricRegistryClassName; + + /** + * 允许将 HikariCP 连接池的健康检查功能与基于 Dropwizard Metrics 的健康检查机制集成 + */ + private String healthCheckRegistryClassName; + + /** + * 健康检查的参数集合 + */ + private Properties healthCheckProperties; + + /** + * 返回 JNDI 数据源的名称 + * + * @return JNDI 数据源的名称 + */ + public String getJndiName() { + return jndiName; + } + + /** + * 设置 JNDI 数据源的名称 + * + * @param jndiName + * JNDI 数据源的名称 + */ + public void setJndiName(String jndiName) { + this.jndiName = jndiName; + } + + /** + * 返回从连接池获取连接时最大等待时间 + * + * @return 从连接池获取连接时最大等待时间 + */ + public Duration getConnectionTimeout() { + return connectionTimeout; + } + + /** + * 设置从连接池获取连接时最大等待时间 + * + * @param connectionTimeout + * 从连接池获取连接时最大等待时间 + */ + public void setConnectionTimeout(Duration connectionTimeout) { + this.connectionTimeout = connectionTimeout; + } + + /** + * 返回是否将 HikariCP 执行的内部查询与应用程序的查询隔离 + * + * @return 是否将 HikariCP 执行的内部查询与应用程序的查询隔离 + */ + public Boolean getIsolateInternalQueries() { + return isolateInternalQueries; + } + + /** + * 设置是否将 HikariCP 执行的内部查询与应用程序的查询隔离 + * + * @param isolateInternalQueries + * 是否将 HikariCP 执行的内部查询与应用程序的查询隔离 + */ + public void setIsolateInternalQueries(Boolean isolateInternalQueries) { + this.isolateInternalQueries = isolateInternalQueries; + } + + /** + * 返回连接池无法成功建立连接,是否会立即抛出异常或进行重试,以及重试的超时时间 + * + * @return 连接池无法成功建立连接,是否会立即抛出异常或进行重试,以及重试的超时时间 + */ + public Duration getInitializationFailTimeout() { + return initializationFailTimeout; + } + + /** + * 设置连接池无法成功建立连接,是否会立即抛出异常或进行重试,以及重试的超时时间 + * + * @param initializationFailTimeout + * 连接池无法成功建立连接,是否会立即抛出异常或进行重试,以及重试的超时时间 + */ + public void setInitializationFailTimeout(Duration initializationFailTimeout) { + this.initializationFailTimeout = initializationFailTimeout; + } + + /** + * 返回接池中最大连接数 + * + * @return 接池中最大连接数 + */ + public Integer getMaxPoolSize() { + return maxPoolSize; + } + + /** + * 设置接池中最大连接数 + * + * @param maxPoolSize + * 接池中最大连接数 + */ + public void setMaxPoolSize(Integer maxPoolSize) { + this.maxPoolSize = maxPoolSize; + super.setMaxTotal(maxPoolSize); + } + + @Override + public void setMaxTotal(Integer maxTotal) { + setMaxPoolSize(maxTotal); + } + + /** + * 返回从连接池获取连接时, 验证连接是否可用的SQL语句 + * + * @return 从连接池获取连接时, 验证连接是否可用的SQL语句 + */ + public String getConnectionTestQuery() { + return connectionTestQuery; + } + + /** + * 设置从连接池获取连接时, 验证连接是否可用的SQL语句 + * + * @param connectionTestQuery + * 从连接池获取连接时, 验证连接是否可用的SQL语句 + */ + public void setConnectionTestQuery(String connectionTestQuery) { + this.connectionTestQuery = connectionTestQuery; + super.setValidationQuery(connectionTestQuery); + } + + /** + * 返回检测连接是否有效的超时时间 + * + * @return 检测连接是否有效的超时时间 + */ + public Duration getValidationTimeout() { + return validationTimeout; + } + + /** + * 设置检测连接是否有效的超时时间,不能大于 {@link com.buession.jdbc.datasource.HikariDataSource#getConnectionTimeout()} + * + * @param validationTimeout + * 检测连接是否有效的超时时间 + */ + public void setValidationTimeout(Duration validationTimeout) { + this.validationTimeout = validationTimeout; + super.setValidationQueryTimeout(validationTimeout); + } + + /** + * 返回连接允许在池中闲置的最长时间 + * + * @return 连接允许在池中闲置的最长时间 + */ + public Duration getIdleTimeout() { + return idleTimeout; + } + + /** + * 设置连接允许在池中闲置的最长时间,仅适用于 minimumIdle 定义为小于 maximumPoolSize,值为 0 时空闲连接永远不会从池中删除 + * 如果 idleTimeout + 1秒 > maxLifetime 且 maxLifetime > 0,则会被重置为 0; + * 如果 idleTimeout != 0 且小于 10 秒,则会被重置为 10 秒 + * + * @param idleTimeout + * 连接允许在池中闲置的最长时间 + */ + public void setIdleTimeout(Duration idleTimeout) { + this.idleTimeout = idleTimeout; + } + + /** + * 返回池中连接的最大生存期,值为 0 时表示无限寿命 + * + * @return 池中连接的最大生存期 + */ + public Duration getMaxLifetime() { + return maxLifetime; + } + + /** + * 设置池中连接的最大生存期,值为 0 时表示无限寿命, 推荐设置的比数据库的 wait_timeout 小几秒到几分钟 + * + * @param maxLifetime + * 池中连接的最大生存期 + */ + public void setMaxLifetime(Duration maxLifetime) { + this.maxLifetime = maxLifetime; + } + + /** + * 返回连接在空闲时发送“keep-alive”心跳的间隔时间 + * + * @return 连接在空闲时发送“keep-alive”心跳的间隔时间 + */ + public Duration getKeepaliveTime() { + return keepaliveTime; + } + + /** + * 设置连接在空闲时发送“keep-alive”心跳的间隔时间 + * + * @param keepaliveTime + * 连接在空闲时发送“keep-alive”心跳的间隔时间 + */ + public void setKeepaliveTime(Duration keepaliveTime) { + this.keepaliveTime = keepaliveTime; + } + + /** + * 返回记录消息之前连接可能离开池的时间量,表明可能存在连接泄漏,值为 0 时泄漏检测被禁用 + * + * @return 记录消息之前连接可能离开池的时间量 + */ + public Duration getLeakDetectionThreshold() { + return leakDetectionThreshold; + } + + /** + * 设置记录消息之前连接可能离开池的时间量,表明可能存在连接泄漏,值为 0 时泄漏检测被禁用 + * + * @param leakDetectionThreshold + * 记录消息之前连接可能离开池的时间量 + */ + public void setLeakDetectionThreshold(Duration leakDetectionThreshold) { + this.leakDetectionThreshold = leakDetectionThreshold; + } + + /** + * 返回是否允许将连接池挂起 + * + * @return 是否允许将连接池挂起 + */ + public Boolean getAllowPoolSuspension() { + return allowPoolSuspension; + } + + /** + * 设置是否允许将连接池挂起 + * + * @param allowPoolSuspension + * 是否允许将连接池挂起 + */ + public void setAllowPoolSuspension(Boolean allowPoolSuspension) { + this.allowPoolSuspension = allowPoolSuspension; + } + + /** + * 返回连接池的性能指标跟踪器 {@link MetricsTrackerFactory} 类名 + * + * @return 连接池的性能指标跟踪器 {@link MetricsTrackerFactory} 类名 + */ + public String getMetricsTrackerFactoryClassName() { + return metricsTrackerFactoryClassName; + } + + /** + * 设置连接池的性能指标跟踪器 {@link MetricsTrackerFactory} 类名 + * + * @param metricsTrackerFactoryClassName + * 连接池的性能指标跟踪器 {@link MetricsTrackerFactory} 类名 + */ + public void setMetricsTrackerFactoryClassName(String metricsTrackerFactoryClassName) { + this.metricsTrackerFactoryClassName = metricsTrackerFactoryClassName; + } + + /** + * 返回允许将 HikariCP 连接池的性能指标集成到基于 Dropwizard Metrics 的监控系统中 + * + * @return 允许将 HikariCP 连接池的性能指标集成到基于 Dropwizard Metrics 的监控系统中 + */ + public String getMetricRegistryClassName() { + return metricRegistryClassName; + } + + /** + * 设置允许将 HikariCP 连接池的性能指标集成到基于 Dropwizard Metrics 的监控系统中 + * + * @param metricRegistryClassName + * 允许将 HikariCP 连接池的性能指标集成到基于 Dropwizard Metrics 的监控系统中 + */ + public void setMetricRegistryClassName(String metricRegistryClassName) { + this.metricRegistryClassName = metricRegistryClassName; + } + + /** + * 返回允许将 HikariCP 连接池的健康检查功能与基于 Dropwizard Metrics 的健康检查机制集成 + * + * @return 允许将 HikariCP 连接池的健康检查功能与基于 Dropwizard Metrics 的健康检查机制集成 + */ + public String getHealthCheckRegistryClassName() { + return healthCheckRegistryClassName; + } + + /** + * 设置允许将 HikariCP 连接池的健康检查功能与基于 Dropwizard Metrics 的健康检查机制集成 + * + * @param healthCheckRegistryClassName + * 允许将 HikariCP 连接池的健康检查功能与基于 Dropwizard Metrics 的健康检查机制集成 + */ + public void setHealthCheckRegistryClassName(String healthCheckRegistryClassName) { + this.healthCheckRegistryClassName = healthCheckRegistryClassName; + } + + /** + * 返回健康检查的参数集合 + * + * @return 健康检查的参数集合 + */ + public Properties getHealthCheckProperties() { + return healthCheckProperties; + } + + /** + * 设置健康检查的参数集合 + * + * @param healthCheckProperties + * 健康检查的参数集合 + */ + public void setHealthCheckProperties(Properties healthCheckProperties) { + this.healthCheckProperties = healthCheckProperties; + } + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/config/OracleConfig.java b/buession-jdbc/src/main/java/com/buession/jdbc/config/OracleConfig.java new file mode 100644 index 000000000..ddec126f4 --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/config/OracleConfig.java @@ -0,0 +1,788 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.config; + +import java.time.Duration; +import java.util.Properties; + +/** + * Oracle 数据源配置 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class OracleConfig extends BaseConfig { + + /** + * 网络协议 + */ + private String networkProtocol; + + /** + * 数据库服务器的名称或地址 + */ + private String serverName; + + /** + * 数据库服务器的端口 + */ + private Integer portNumber; + + /** + * 连接到 Oracle 数据库服务的服务名,服务名用于在 Oracle 数据库中标识特定的服务或数据库实例 + */ + private String serviceName; + + /** + * 数据源名称 + */ + private String dataSourceName; + + /** + * 数据源描述 + */ + private String dataSourceDescription; + + /** + * 要连接的 Oracle 数据库的名称 + */ + private String databaseName; + + /** + * 角色名称 + */ + private String roleName; + + /** + * 连接到 Oracle Pluggable Database (PDB) 的角色的属性 + */ + private Properties pdbRoles; + + /** + * 连接工厂类名 + */ + private String connectionFactoryClassName; + + /** + * 是否启用快速连接故障切换 + */ + private Boolean fastConnectionFailoverEnabled; + + /** + * Oracle Notification Services (ONS) 的属性 + */ + private String onsConfiguration; + + /** + * 是否启用分片模式 + */ + private Boolean shardingMode; + + /** + * 每个分片(Shard)中允许的最大连接数 + */ + private Integer maxConnectionsPerShard; + + /** + * 每个服务的最大连接数 + */ + private Integer maxConnectionsPerService; + + /** + * 连接池中最小的连接数量,当为 0 时,连接池在空闲时可以完全没有连接 + */ + private Integer minPoolSize; + + /** + * 连接池中可以保留连接的最大数,如设置为负数,则不限制 + */ + private Integer maxPoolSize; + + /** + * 连接在连接池中保持空闲状态的最大时间 + */ + private Duration maxIdleTime; + + /** + * 连接在连接池中的最大生命周期 + */ + private Duration timeToLiveConnectionTimeout; + + /** + * 在一个连接空闲指定时间后,认为该连接仍然有效并且可以直接重用的时间阈值 + */ + private Duration trustIdleConnection; + + /** + * 连接池中的连接在被强制关闭之前可以被重复使用的最长时间 + */ + private Duration maxConnectionReuseTime; + + /** + * 连接池中的连接可以被重复使用的最大次数 + */ + private Integer maxConnectionReuseCount; + + /** + * 定义在连接标签操作中被认为是“高成本”的阈值时间 + */ + private Duration connectionLabelingHighCost; + + /** + * 连接的重用次数在达到这个阈值后会被标记为“高成本重用” + */ + private Integer highCostConnectionReuseThreshold; + + /** + * 定义连接在达到指定的重用次数后,是否应该被重新配置(repurpose) + */ + private Integer connectionRepurposeThreshold; + + /** + * 连接池检查连接超时的间隔时间 + */ + private Duration timeoutCheckInterval; + + /** + * 连接池中每个连接所能缓存的最大 SQL 预编译语句(Prepared Statements)的数量 + */ + private Integer maxStatements; + + /** + * 触发连接池收割(Harvesting)操作的阈值,表示连接池中空闲连接的数量达到多少时触发收割操作 + */ + private Integer connectionHarvestTriggerCount; + + /** + * 在一次连接收割操作中,最多可以从连接池中收回的连接数量 + */ + private Integer connectionHarvestMaxCount; + + /** + * 否允许从只读实例获取连接 + */ + private Boolean readOnlyInstanceAllowed; + + /** + * 是否在借用连接的线程中创建连接 + */ + private Boolean createConnectionInBorrowThread; + + /** + * 返回网络协议 + * + * @return 网络协议 + */ + public String getNetworkProtocol() { + return networkProtocol; + } + + /** + * 设置网络协议 + * + * @param networkProtocol + * 网络协议 + */ + public void setNetworkProtocol(String networkProtocol) { + this.networkProtocol = networkProtocol; + } + + /** + * 返回数据库服务器的名称或地址 + * + * @return 数据库服务器的名称或地址 + */ + public String getServerName() { + return serverName; + } + + /** + * 设置数据库服务器的名称或地址 + * + * @param serverName + * 数据库服务器的名称或地址 + */ + public void setServerName(String serverName) { + this.serverName = serverName; + } + + /** + * 返回数据库服务器的端口 + * + * @return 数据库服务器的端口 + */ + public Integer getPortNumber() { + return portNumber; + } + + /** + * 设置数据库服务器的端口 + * + * @param portNumber + * 数据库服务器的端口 + */ + public void setPortNumber(Integer portNumber) { + this.portNumber = portNumber; + } + + /** + * 返回连接到 Oracle 数据库服务的服务名,服务名用于在 Oracle 数据库中标识特定的服务或数据库实例 + * + * @return 连接到 Oracle 数据库服务的服务名 + */ + public String getServiceName() { + return serviceName; + } + + /** + * 设置连接到 Oracle 数据库服务的服务名,服务名用于在 Oracle 数据库中标识特定的服务或数据库实例 + * + * @param serviceName + * 连接到 Oracle 数据库服务的服务名 + */ + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + /** + * 返回数据源名称 + * + * @return 数据源名称 + */ + public String getDataSourceName() { + return dataSourceName; + } + + /** + * 设置数据源名称 + * + * @param dataSourceName + * 数据源名称 + */ + public void setDataSourceName(String dataSourceName) { + this.dataSourceName = dataSourceName; + } + + /** + * 返回数据源描述 + * + * @return 数据源描述 + */ + public String getDataSourceDescription() { + return dataSourceDescription; + } + + /** + * 设置数据源描述 + * + * @param dataSourceDescription + * 数据源描述 + */ + public void setDataSourceDescription(String dataSourceDescription) { + this.dataSourceDescription = dataSourceDescription; + } + + /** + * 返回要连接的 Oracle 数据库的名称 + * + * @return 要连接的 Oracle 数据库的名称 + */ + public String getDatabaseName() { + return databaseName; + } + + /** + * 设置 + * + * @param databaseName + * 要连接的 Oracle 数据库的名称 + */ + public void setDatabaseName(String databaseName) { + this.databaseName = databaseName; + } + + /** + * 返回角色名称 + * + * @return 角色名称 + */ + public String getRoleName() { + return roleName; + } + + /** + * 设置角色名称 + * + * @param roleName + * 角色名称 + */ + public void setRoleName(String roleName) { + this.roleName = roleName; + } + + /** + * 返回连接到 Oracle Pluggable Database (PDB) 的角色的属性 + * + * @return 连接到 Oracle Pluggable Database (PDB) 的角色的属性 + */ + public Properties getPdbRoles() { + return pdbRoles; + } + + /** + * 设置连接到 Oracle Pluggable Database (PDB) 的角色的属性 + * + * @param pdbRoles + * 连接到 Oracle Pluggable Database (PDB) 的角色的属性 + */ + public void setPdbRoles(Properties pdbRoles) { + this.pdbRoles = pdbRoles; + } + + /** + * 返回连接工厂类名 + * + * @return 连接工厂类名 + */ + public String getConnectionFactoryClassName() { + return connectionFactoryClassName; + } + + /** + * 设置连接工厂类名 + * + * @param connectionFactoryClassName + * 连接工厂类名 + */ + public void setConnectionFactoryClassName(String connectionFactoryClassName) { + this.connectionFactoryClassName = connectionFactoryClassName; + } + + /** + * 返回是否启用快速连接故障切换 + * + * @return 是否启用快速连接故障切换 + */ + public Boolean getFastConnectionFailoverEnabled() { + return fastConnectionFailoverEnabled; + } + + /** + * 设置是否启用快速连接故障切换 + * + * @param fastConnectionFailoverEnabled + * 是否启用快速连接故障切换 + */ + public void setFastConnectionFailoverEnabled(Boolean fastConnectionFailoverEnabled) { + this.fastConnectionFailoverEnabled = fastConnectionFailoverEnabled; + } + + /** + * 返回 Oracle Notification Services (ONS) 的属性 + * + * @return Oracle Notification Services (ONS) 的属性 + */ + public String getOnsConfiguration() { + return onsConfiguration; + } + + /** + * 设置 Oracle Notification Services (ONS) 的属性 + * + * @param onsConfiguration + * Oracle Notification Services (ONS) 的属性 + */ + public void setOnsConfiguration(String onsConfiguration) { + this.onsConfiguration = onsConfiguration; + } + + /** + * 返回是否启用分片模式 + * + * @return 是否启用分片模式 + */ + public Boolean getShardingMode() { + return shardingMode; + } + + /** + * 设置是否启用分片模式 + * + * @param shardingMode + * 是否启用分片模式 + */ + public void setShardingMode(Boolean shardingMode) { + this.shardingMode = shardingMode; + } + + /** + * 返回每个分片(Shard)中允许的最大连接数 + * + * @return 每个分片(Shard)中允许的最大连接数 + */ + public Integer getMaxConnectionsPerShard() { + return maxConnectionsPerShard; + } + + /** + * 设置每个分片(Shard)中允许的最大连接数 + * + * @param maxConnectionsPerShard + * 每个分片(Shard)中允许的最大连接数 + */ + public void setMaxConnectionsPerShard(Integer maxConnectionsPerShard) { + this.maxConnectionsPerShard = maxConnectionsPerShard; + } + + /** + * 返回每个服务的最大连接数 + * + * @return 每个服务的最大连接数 + */ + public Integer getMaxConnectionsPerService() { + return maxConnectionsPerService; + } + + /** + * 设置每个服务的最大连接数 + * + * @param maxConnectionsPerService + * 每个服务的最大连接数 + */ + public void setMaxConnectionsPerService(Integer maxConnectionsPerService) { + this.maxConnectionsPerService = maxConnectionsPerService; + } + + /** + * 返回连接池中最小的连接数量 + * + * @return 连接池中最小的连接数量 + */ + public Integer getMinPoolSize() { + return minPoolSize; + } + + /** + * 设置连接池中最小的连接数量 + * + * @param minPoolSize + * 连接池中最小的连接数量 + */ + public void setMinPoolSize(Integer minPoolSize) { + this.minPoolSize = minPoolSize; + } + + /** + * 返回连接池中可以保留连接的最大数 + * + * @return 连接池中可以保留连接的最大数 + */ + public Integer getMaxPoolSize() { + return maxPoolSize; + } + + /** + * 设置连接池中可以保留连接的最大数 + * + * @param maxPoolSize + * 连接池中可以保留连接的最大数 + */ + public void setMaxPoolSize(Integer maxPoolSize) { + this.maxPoolSize = maxPoolSize; + super.setMaxTotal(maxPoolSize); + } + + @Override + public void setMaxTotal(Integer maxTotal) { + setMaxPoolSize(maxTotal); + } + + /** + * 返回连接在连接池中保持空闲状态的最大时间 + * + * @return 连接在连接池中保持空闲状态的最大时间 + */ + public Duration getMaxIdleTime() { + return maxIdleTime; + } + + /** + * 设置连接在连接池中保持空闲状态的最大时间 + * + * @param maxIdleTime + * 连接在连接池中保持空闲状态的最大时间 + */ + public void setMaxIdleTime(Duration maxIdleTime) { + this.maxIdleTime = maxIdleTime; + } + + /** + * 返回连接在连接池中的最大生命周期 + * + * @return 连接在连接池中的最大生命周期 + */ + public Duration getTimeToLiveConnectionTimeout() { + return timeToLiveConnectionTimeout; + } + + /** + * 设置连接在连接池中的最大生命周期 + * + * @param timeToLiveConnectionTimeout + * 连接在连接池中的最大生命周期 + */ + public void setTimeToLiveConnectionTimeout(Duration timeToLiveConnectionTimeout) { + this.timeToLiveConnectionTimeout = timeToLiveConnectionTimeout; + } + + /** + * 返回在一个连接空闲指定时间后,认为该连接仍然有效并且可以直接重用的时间阈值 + * + * @return 在一个连接空闲指定时间后,认为该连接仍然有效并且可以直接重用的时间阈值 + */ + public Duration getTrustIdleConnection() { + return trustIdleConnection; + } + + /** + * 设置在一个连接空闲指定时间后,认为该连接仍然有效并且可以直接重用的时间阈值 + * + * @param trustIdleConnection + * 在一个连接空闲指定时间后,认为该连接仍然有效并且可以直接重用的时间阈值 + */ + public void setTrustIdleConnection(Duration trustIdleConnection) { + this.trustIdleConnection = trustIdleConnection; + } + + /** + * 返回连接池中的连接在被强制关闭之前可以被重复使用的最长时间 + * + * @return 连接池中的连接在被强制关闭之前可以被重复使用的最长时间 + */ + public Duration getMaxConnectionReuseTime() { + return maxConnectionReuseTime; + } + + /** + * 设置连接池中的连接在被强制关闭之前可以被重复使用的最长时间 + * + * @param maxConnectionReuseTime + * 连接池中的连接在被强制关闭之前可以被重复使用的最长时间 + */ + public void setMaxConnectionReuseTime(Duration maxConnectionReuseTime) { + this.maxConnectionReuseTime = maxConnectionReuseTime; + } + + /** + * 返回连接池中的连接可以被重复使用的最大次数 + * + * @return 连接池中的连接可以被重复使用的最大次数 + */ + public Integer getMaxConnectionReuseCount() { + return maxConnectionReuseCount; + } + + /** + * 设置连接池中的连接可以被重复使用的最大次数 + * + * @param maxConnectionReuseCount + * 连接池中的连接可以被重复使用的最大次数 + */ + public void setMaxConnectionReuseCount(Integer maxConnectionReuseCount) { + this.maxConnectionReuseCount = maxConnectionReuseCount; + } + + /** + * 返回定义在连接标签操作中被认为是“高成本”的阈值时间 + * + * @return 定义在连接标签操作中被认为是“高成本”的阈值时间 + */ + public Duration getConnectionLabelingHighCost() { + return connectionLabelingHighCost; + } + + /** + * 设置定义在连接标签操作中被认为是“高成本”的阈值时间 + * + * @param connectionLabelingHighCost + * 定义在连接标签操作中被认为是“高成本”的阈值时间 + */ + public void setConnectionLabelingHighCost(Duration connectionLabelingHighCost) { + this.connectionLabelingHighCost = connectionLabelingHighCost; + } + + /** + * 返回连接的重用次数在达到这个阈值后会被标记为“高成本重用” + * + * @return 连接的重用次数在达到这个阈值后会被标记为“高成本重用” + */ + public Integer getHighCostConnectionReuseThreshold() { + return highCostConnectionReuseThreshold; + } + + /** + * 设置连接的重用次数在达到这个阈值后会被标记为“高成本重用” + * + * @param highCostConnectionReuseThreshold + * 连接的重用次数在达到这个阈值后会被标记为“高成本重用” + */ + public void setHighCostConnectionReuseThreshold(Integer highCostConnectionReuseThreshold) { + this.highCostConnectionReuseThreshold = highCostConnectionReuseThreshold; + } + + /** + * 返回定义连接在达到指定的重用次数后,是否应该被重新配置(repurpose) + * + * @return 定义连接在达到指定的重用次数后,是否应该被重新配置(repurpose) + */ + public Integer getConnectionRepurposeThreshold() { + return connectionRepurposeThreshold; + } + + /** + * 设置定义连接在达到指定的重用次数后,是否应该被重新配置(repurpose) + * + * @param connectionRepurposeThreshold + * 定义连接在达到指定的重用次数后,是否应该被重新配置(repurpose) + */ + public void setConnectionRepurposeThreshold(Integer connectionRepurposeThreshold) { + this.connectionRepurposeThreshold = connectionRepurposeThreshold; + } + + /** + * 返回连接池检查连接超时的间隔时间 + * + * @return 连接池检查连接超时的间隔时间 + */ + public Duration getTimeoutCheckInterval() { + return timeoutCheckInterval; + } + + /** + * 设置连接池检查连接超时的间隔时间 + * + * @param timeoutCheckInterval + * 连接池检查连接超时的间隔时间 + */ + public void setTimeoutCheckInterval(Duration timeoutCheckInterval) { + this.timeoutCheckInterval = timeoutCheckInterval; + } + + /** + * 返回连接池中每个连接所能缓存的最大 SQL 预编译语句(Prepared Statements)的数量 + * + * @return 连接池中每个连接所能缓存的最大 SQL 预编译语句(Prepared Statements)的数量 + */ + public Integer getMaxStatements() { + return maxStatements; + } + + /** + * 设置连接池中每个连接所能缓存的最大 SQL 预编译语句(Prepared Statements)的数量 + * + * @param maxStatements + * 连接池中每个连接所能缓存的最大 SQL 预编译语句(Prepared Statements)的数量 + */ + public void setMaxStatements(Integer maxStatements) { + this.maxStatements = maxStatements; + } + + /** + * 返回触发连接池收割(Harvesting)操作的阈值,表示连接池中空闲连接的数量达到多少时触发收割操作 + * + * @return 触发连接池收割(Harvesting)操作的阈值,表示连接池中空闲连接的数量达到多少时触发收割操作 + */ + public Integer getConnectionHarvestTriggerCount() { + return connectionHarvestTriggerCount; + } + + /** + * 设置触发连接池收割(Harvesting)操作的阈值,表示连接池中空闲连接的数量达到多少时触发收割操作 + * + * @param connectionHarvestTriggerCount + * 触发连接池收割(Harvesting)操作的阈值,表示连接池中空闲连接的数量达到多少时触发收割操作 + */ + public void setConnectionHarvestTriggerCount(Integer connectionHarvestTriggerCount) { + this.connectionHarvestTriggerCount = connectionHarvestTriggerCount; + } + + /** + * 返回在一次连接收割操作中,最多可以从连接池中收回的连接数量 + * + * @return 在一次连接收割操作中,最多可以从连接池中收回的连接数量 + */ + public Integer getConnectionHarvestMaxCount() { + return connectionHarvestMaxCount; + } + + /** + * 设置在一次连接收割操作中,最多可以从连接池中收回的连接数量 + * + * @param connectionHarvestMaxCount + * 在一次连接收割操作中,最多可以从连接池中收回的连接数量 + */ + public void setConnectionHarvestMaxCount(Integer connectionHarvestMaxCount) { + this.connectionHarvestMaxCount = connectionHarvestMaxCount; + } + + /** + * 返回否允许从只读实例获取连接 + * + * @return 否允许从只读实例获取连接 + */ + public Boolean getReadOnlyInstanceAllowed() { + return readOnlyInstanceAllowed; + } + + /** + * 设置否允许从只读实例获取连接 + * + * @param readOnlyInstanceAllowed + * 否允许从只读实例获取连接 + */ + public void setReadOnlyInstanceAllowed(Boolean readOnlyInstanceAllowed) { + this.readOnlyInstanceAllowed = readOnlyInstanceAllowed; + } + + /** + * 返回是否在借用连接的线程中创建连接 + * + * @return 是否在借用连接的线程中创建连接 + */ + public Boolean getCreateConnectionInBorrowThread() { + return createConnectionInBorrowThread; + } + + /** + * 设置是否在借用连接的线程中创建连接 + * + * @param createConnectionInBorrowThread + * 是否在借用连接的线程中创建连接 + */ + public void setCreateConnectionInBorrowThread(Boolean createConnectionInBorrowThread) { + this.createConnectionInBorrowThread = createConnectionInBorrowThread; + } + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/config/TomcatConfig.java b/buession-jdbc/src/main/java/com/buession/jdbc/config/TomcatConfig.java new file mode 100644 index 000000000..336b984bf --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/config/TomcatConfig.java @@ -0,0 +1,559 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.config; + +import java.beans.Statement; +import java.time.Duration; + +/** + * Tomcat 数据源配置 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class TomcatConfig extends BaseConfig { + + /** + * JNDI 数据源的名称 + */ + private String jndiName; + + /** + * 是否允许在同一个数据库连接中使用不同的用户名进行身份验证 + */ + private Boolean alternateUsernameAllowed; + + /** + * 连接归还到池时,设置为自动提交 + */ + private Boolean commitOnReturn; + + /** + * 连接归还到池时,是否回滚所有操作 + */ + private Boolean rollbackOnReturn; + + /** + * 实现 {@link org.apache.tomcat.jdbc.pool.Validator} 接口并提供无参构造方法的实现类,用来替代连接验证SQL,对连接进行验证 + */ + private String validatorClassName; + + /** + * 验证连接时间间隔 + */ + private Duration validationInterval; + + /** + * JDBC 拦截器,{@link org.apache.tomcat.jdbc.pool.JdbcInterceptor} 的实现 + */ + private String jdbcInterceptors; + + /** + * 最大连接数,可以在这个池中同一时刻被分配的有效连接数的最大值,如设置为负数,则不限制 + */ + private Integer maxActive; + + /** + * 连接在连接池中最大存在的时间 + */ + private Duration maxAge; + + /** + * 创建连接时测试连接的有效性 + */ + private Boolean testOnConnect; + + /** + * 是否使用一个包装的连接 facade 来管理和处理连接池中的连接 + */ + private Boolean useDisposableConnectionFacade; + + /** + * 标记初始化池时是否忽略连接创建错误 + */ + private Boolean ignoreExceptionOnPreLoad; + + /** + * 连接池的请求排队策略,当为 {@code true} 时,为使用公平的排队策略;当为 {@code false} 时,为不使用公平的排队策略 + */ + private Boolean fairQueue; + + /** + * 是否使用包装的 {@link Statement} 对象 + */ + private Boolean useStatementFacade; + + /** + * 是否移除抛弃的(abandoned)连接,一个连接使用超过了 removeAbandonedTimeout 上限就被视为抛弃的, + * 开启该开关可以恢复那些应用没有关闭的连接 + */ + private Boolean removeAbandoned; + + /** + * 连接被认为是可疑的超时时间 + */ + private Duration suspectTimeout; + + /** + * 除非正在使用的连接数超过定义的百分比, + * 否则已放弃(超时)的连接不会关闭并报告 abandonWhenPercentageFull; + * 该值应介于0到100之间。默认值为0,这表示一旦 removeAbandonedTimeout 达到连接就可以关闭连接 + */ + private Integer abandonWhenPercentageFull; + + /** + * 将此值设置为true可以传播已被中断的线程的中断状态(不清除中断状态) + */ + private Boolean propagateInterruptState; + + /** + * 将此属性设置为true可以在验证阶段将错误记录到日志文件中 + */ + private Boolean logValidationErrors; + + /** + * 是否使用锁机制来管理连接池中的连接 + */ + private Boolean useLock; + + /** + * 是否使用 {@link #equals()} 方法来比较连接池中的连接 + */ + private Boolean useEquals; + + /** + * 返回 JNDI 数据源的名称 + * + * @return JNDI 数据源的名称 + */ + public String getJndiName() { + return jndiName; + } + + /** + * 设置 JNDI 数据源的名称 + * + * @param jndiName + * JNDI 数据源的名称 + */ + public void setJndiName(String jndiName) { + this.jndiName = jndiName; + } + + /** + * 返回是否允许在同一个数据库连接中使用不同的用户名进行身份验证 + * + * @return 是否允许在同一个数据库连接中使用不同的用户名进行身份验证 + */ + public Boolean getAlternateUsernameAllowed() { + return alternateUsernameAllowed; + } + + /** + * 设置是否允许在同一个数据库连接中使用不同的用户名进行身份验证 + * + * @param alternateUsernameAllowed + * 是否允许在同一个数据库连接中使用不同的用户名进行身份验证 + */ + public void setAlternateUsernameAllowed(Boolean alternateUsernameAllowed) { + this.alternateUsernameAllowed = alternateUsernameAllowed; + } + + /** + * 返回连接归还到池时,设置为自动提交 + * + * @return 连接归还到池时,设置为自动提交 + */ + public Boolean getCommitOnReturn() { + return commitOnReturn; + } + + /** + * 设置连接归还到池时,是否自动提交 + * + * @param commitOnReturn + * 连接归还到池时,是否自动提交 + */ + public void setCommitOnReturn(Boolean commitOnReturn) { + this.commitOnReturn = commitOnReturn; + } + + /** + * 返回连接归还到池时,是否回滚所有操作 + * + * @return 连接归还到池时,是否回滚所有操作 + */ + public Boolean getRollbackOnReturn() { + return rollbackOnReturn; + } + + /** + * 设置连接归还到池时,是否回滚所有操作 + * + * @param rollbackOnReturn + * 连接归还到池时,是否回滚所有操作 + */ + public void setRollbackOnReturn(Boolean rollbackOnReturn) { + this.rollbackOnReturn = rollbackOnReturn; + } + + /** + * 返回实现 {@link org.apache.tomcat.jdbc.pool.Validator} 接口并提供无参构造方法的实现类,用来替代连接验证SQL,对连接进行验证的类名 + * + * @return 实现 {@link org.apache.tomcat.jdbc.pool.Validator} 接口并提供无参构造方法的实现类,用来替代连接验证SQL,对连接进行验证的类名 + */ + public String getValidatorClassName() { + return validatorClassName; + } + + /** + * 设置实现 {@link org.apache.tomcat.jdbc.pool.Validator} 接口并提供无参构造方法的实现类,用来替代连接验证SQL,对连接进行验证的类名 + * + * @param validatorClassName + * 实现 {@link org.apache.tomcat.jdbc.pool.Validator} 接口并提供无参构造方法的实现类,用来替代连接验证SQL,对连接进行验证的类名 + */ + public void setValidatorClassName(String validatorClassName) { + this.validatorClassName = validatorClassName; + } + + /** + * 返回验证连接时间间隔 + * + * @return 验证连接时间间隔 + */ + public Duration getValidationInterval() { + return validationInterval; + } + + /** + * 设置验证连接时间间隔 + * + * @param validationInterval + * 验证连接时间间隔 + */ + public void setValidationInterval(Duration validationInterval) { + this.validationInterval = validationInterval; + } + + /** + * 返回 JDBC 拦截器,{@link org.apache.tomcat.jdbc.pool.JdbcInterceptor} 的实现 + * + * @return JDBC 拦截器 + */ + public String getJdbcInterceptors() { + return jdbcInterceptors; + } + + /** + * 设置 JDBC 拦截器,{@link org.apache.tomcat.jdbc.pool.JdbcInterceptor} 的实现 + * + * @param jdbcInterceptors + * JDBC 拦截器 + */ + public void setJdbcInterceptors(String jdbcInterceptors) { + this.jdbcInterceptors = jdbcInterceptors; + } + + /** + * 返回最大连接数 + * + * @return 最大连接数 + */ + public Integer getMaxActive() { + return maxActive; + } + + /** + * 设置最大连接数 + * + * @param maxActive + * 最大连接数 + * + * @since 3.0.0 + */ + public void setMaxActive(Integer maxActive) { + this.maxActive = maxActive; + super.setMaxTotal(maxActive); + } + + @Override + public void setMaxTotal(Integer maxTotal) { + setMaxActive(maxTotal); + } + + /** + * 返回连接在连接池中最大存在的时间 + * + * @return 连接在连接池中最大存在的时间 + */ + public Duration getMaxAge() { + return maxAge; + } + + /** + * 设置连接在连接池中最大存在的时间 + * + * @param maxAge + * 连接在连接池中最大存在的时间 + */ + public void setMaxAge(Duration maxAge) { + this.maxAge = maxAge; + } + + /** + * 返回创建连接时是否测试连接的有效性 + * + * @return 创建连接时是否测试连接的有效性 + */ + public Boolean getTestOnConnect() { + return testOnConnect; + } + + /** + * 设置创建连接时是否测试连接的有效性 + * + * @param testOnConnect + * 创建连接时是否测试连接的有效性 + */ + public void setTestOnConnect(Boolean testOnConnect) { + this.testOnConnect = testOnConnect; + super.setTestOnCreate(testOnConnect); + } + + @Override + public void setTestOnCreate(Boolean testOnCreate) { + setTestOnConnect(testOnCreate); + } + + /** + * 返回是否使用一个包装的连接 facade 来管理和处理连接池中的连接 + * + * @return 是否使用一个包装的连接 facade 来管理和处理连接池中的连接 + */ + public Boolean getUseDisposableConnectionFacade() { + return useDisposableConnectionFacade; + } + + /** + * 设置是否使用一个包装的连接 facade 来管理和处理连接池中的连接 + * + * @param useDisposableConnectionFacade + * 是否使用一个包装的连接 facade 来管理和处理连接池中的连接 + */ + public void setUseDisposableConnectionFacade(Boolean useDisposableConnectionFacade) { + this.useDisposableConnectionFacade = useDisposableConnectionFacade; + } + + /** + * 返回标记初始化池时是否忽略连接创建错误 + * + * @return 初始化池时是否忽略连接创建错误 + */ + public Boolean getIgnoreExceptionOnPreLoad() { + return ignoreExceptionOnPreLoad; + } + + /** + * 设置标记初始化池时是否忽略连接创建错误;如果要在初始化池时忽略连接创建错误,请设置为true + * + * @param ignoreExceptionOnPreLoad + * 初始化池时是否忽略连接创建错误 + */ + public void setIgnoreExceptionOnPreLoad(Boolean ignoreExceptionOnPreLoad) { + this.ignoreExceptionOnPreLoad = ignoreExceptionOnPreLoad; + } + + /** + * 返回连接池的请求排队策略,当为 {@code true} 时,为使用公平的排队策略;当为 {@code false} 时,为不使用公平的排队策略 + * + * @return 连接池的请求排队策略 + */ + public Boolean getFairQueue() { + return fairQueue; + } + + /** + * 设置连接池的请求排队策略,当为 {@code true} 时,为使用公平的排队策略;当为 {@code false} 时,为不使用公平的排队策略 + * + * @param fairQueue + * 连接池的请求排队策略 + */ + public void setFairQueue(Boolean fairQueue) { + this.fairQueue = fairQueue; + } + + /** + * 返回使用包装的 {@link Statement} 对象 + * + * @return 使用包装的 {@link Statement} 对象 + */ + public Boolean getUseStatementFacade() { + return useStatementFacade; + } + + /** + * 设置是使用包装的 {@link Statement} 对象 + * + * @param useStatementFacade + * 使用包装的 {@link Statement} 对象 + */ + public void setUseStatementFacade(Boolean useStatementFacade) { + this.useStatementFacade = useStatementFacade; + } + + /** + * 返回是否移除抛弃的(abandoned)连接 + * + * @return 是否移除抛弃的(abandoned)连接 + */ + public Boolean getRemoveAbandoned() { + return removeAbandoned; + } + + /** + * 设置是否移除抛弃的(abandoned)连接 + * + * @param removeAbandoned + * 是否移除抛弃的(abandoned)连接 + */ + public void setRemoveAbandoned(Boolean removeAbandoned) { + this.removeAbandoned = removeAbandoned; + } + + /** + * 连接被认为是可疑的超时时间 + * + * @return 连接被认为是可疑的超时时间 + */ + public Duration getSuspectTimeout() { + return suspectTimeout; + } + + /** + * 连接被认为是可疑的超时时间 + * + * @param suspectTimeout + * 连接被认为是可疑的超时时间 + */ + public void setSuspectTimeout(Duration suspectTimeout) { + this.suspectTimeout = suspectTimeout; + } + + /** + * 返回正在使用的连接数超过定义的百分比 + * + * @return 正在使用的连接数超过定义的百分比 + */ + public Integer getAbandonWhenPercentageFull() { + return abandonWhenPercentageFull; + } + + /** + * 设置正在使用的连接数超过定义的百分比 + * + * @param abandonWhenPercentageFull + * 正在使用的连接数超过定义的百分比 + */ + public void setAbandonWhenPercentageFull(Integer abandonWhenPercentageFull) { + this.abandonWhenPercentageFull = abandonWhenPercentageFull; + } + + /** + * 返回是否传播已被中断的线程的中断状态 + * + * @return 是否传播已被中断的线程的中断状态 + */ + public Boolean getPropagateInterruptState() { + return propagateInterruptState; + } + + /** + * 设置是否传播已被中断的线程的中断状态 + * + * @param propagateInterruptState + * 是否传播已被中断的线程的中断状态 + */ + public void setPropagateInterruptState(Boolean propagateInterruptState) { + this.propagateInterruptState = propagateInterruptState; + } + + /** + * 返回验证阶段将错误记录到日志文件中 + * + * @return 验证阶段将错误记录到日志文件中 + */ + public Boolean getLogValidationErrors() { + return logValidationErrors; + } + + /** + * 设置验证阶段将错误记录到日志文件中 + * + * @param logValidationErrors + * 验证阶段将错误记录到日志文件中 + */ + public void setLogValidationErrors(Boolean logValidationErrors) { + this.logValidationErrors = logValidationErrors; + } + + /** + * 返回是否使用锁机制来管理连接池中的连接 + * + * @return 是否使用锁机制来管理连接池中的连接 + */ + public Boolean getUseLock() { + return useLock; + } + + /** + * 设置是否使用锁机制来管理连接池中的连接 + * + * @param useLock + * 是否使用锁机制来管理连接池中的连接 + */ + public void setUseLock(Boolean useLock) { + this.useLock = useLock; + } + + /** + * 返回是否使用 {@link #equals(Object obj)} 方法来比较连接池中的连接 + * + * @return 是否使用 {@link #equals(Object obj)} 方法来比较连接池中的连接 + */ + public Boolean getUseEquals() { + return useEquals; + } + + /** + * 设置是否使用 {@link #equals(Object obj)} 方法来比较连接池中的连接 + * + * @param useEquals + * 是否使用 {@link #equals(Object obj)} 方法来比较连接池中的连接 + */ + public void setUseEquals(Boolean useEquals) { + this.useEquals = useEquals; + } + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/config/package-info.java b/buession-jdbc/src/main/java/com/buession/jdbc/config/package-info.java new file mode 100644 index 000000000..f1f13cb1d --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/config/package-info.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + * @since 3.0.0 + */ +package com.buession.jdbc.config; \ No newline at end of file diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/core/Jmx.java b/buession-jdbc/src/main/java/com/buession/jdbc/core/Jmx.java new file mode 100644 index 000000000..d53a77865 --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/core/Jmx.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.core; + +/** + * JMX 管理对象配置 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class Jmx { + + /** + * 是否启用 JMX + */ + private Boolean enabled; + + /** + * JMX 管理对象的名称 + */ + private String name; + + /** + * 构造函数 + */ + public Jmx() { + } + + /** + * 构造函数 + * + * @param enabled + * 是否启用 JMX + */ + public Jmx(Boolean enabled) { + this.enabled = enabled; + } + + /** + * 构造函数 + * + * @param name + * JMX 管理对象的名称 + */ + public Jmx(String name) { + this.name = name; + } + + /** + * 构造函数 + * + * @param enabled + * 是否启用 JMX + * @param name + * JMX 管理对象的名称 + */ + public Jmx(Boolean enabled, String name) { + this.enabled = enabled; + this.name = name; + } + + /** + * 返回是否启用 JMX + * + * @return 是否启用 JMX + */ + public Boolean isEnabled() { + return getEnabled(); + } + + /** + * 返回是否启用 JMX + * + * @return 是否启用 JMX + */ + public Boolean getEnabled() { + return enabled; + } + + /** + * 设置是否启用 JMX + * + * @param enabled + * 是否启用 JMX + */ + public void setEnabled(Boolean enabled) { + this.enabled = enabled; + } + + /** + * 返回 JMX 管理对象的名称 + * + * @return JMX 管理对象的名称 + */ + public String getName() { + return name; + } + + /** + * 设置 JMX 管理对象的名称 + * + * @param name + * JMX 管理对象的名称 + */ + public void setName(String name) { + this.name = name; + } + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/Role.java b/buession-jdbc/src/main/java/com/buession/jdbc/core/Role.java similarity index 98% rename from buession-jdbc/src/main/java/com/buession/jdbc/datasource/Role.java rename to buession-jdbc/src/main/java/com/buession/jdbc/core/Role.java index 8e53ed38b..4a0d5c53a 100644 --- a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/Role.java +++ b/buession-jdbc/src/main/java/com/buession/jdbc/core/Role.java @@ -22,7 +22,7 @@ * | Copyright @ 2013-2021 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.jdbc.datasource; +package com.buession.jdbc.core; /** * 角色 diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/core/TransactionIsolation.java b/buession-jdbc/src/main/java/com/buession/jdbc/core/TransactionIsolation.java index 30e11a458..2bcf23611 100644 --- a/buession-jdbc/src/main/java/com/buession/jdbc/core/TransactionIsolation.java +++ b/buession-jdbc/src/main/java/com/buession/jdbc/core/TransactionIsolation.java @@ -37,6 +37,11 @@ public enum TransactionIsolation { */ DEFAULT(-1), + /** + * 不支持事务 + */ + NONE(0), + /** * 读未提交,即能够读取到没有被提交的数据 */ @@ -59,11 +64,11 @@ public enum TransactionIsolation { private final int value; - TransactionIsolation(final int value){ + TransactionIsolation(final int value) { this.value = value; } - public int getValue(){ + public int getValue() { return value; } diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/AbstractDataSource.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/AbstractDataSource.java index 38944fe8b..fb2261755 100644 --- a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/AbstractDataSource.java +++ b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/AbstractDataSource.java @@ -19,17 +19,22 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.jdbc.datasource; -import com.buession.jdbc.datasource.config.PoolConfiguration; +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.jdbc.core.TransactionIsolation; +import com.buession.jdbc.datasource.pool.PoolConfiguration; + +import java.time.Duration; +import java.util.Properties; /** * DataSource 抽象类 * - * @param + * @param * {@link javax.sql.DataSource} 数据源类型 * @param

* 连接池配置 {@link PoolConfiguration} 实现 @@ -37,8 +42,15 @@ * @author Yong.Teng * @since 1.3.2 */ -public abstract class AbstractDataSource - implements DataSource { +public abstract class AbstractDataSource + implements DataSource { + + /** + * {@link ClassLoader} 实例 + * + * @since 3.0.0 + */ + private ClassLoader driverClassLoader; /** * 数据库驱动类名 @@ -68,6 +80,76 @@ public abstract class AbstractDataSource | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.jdbc.datasource; -import com.buession.jdbc.datasource.config.PoolConfiguration; +import com.buession.jdbc.core.TransactionIsolation; +import com.buession.jdbc.datasource.pool.PoolConfiguration; + +import java.time.Duration; +import java.util.Properties; /** * 数据源接口 * - * @param + * @param * {@link javax.sql.DataSource} 数据源类型 * @param

* 连接池配置 * * @author Yong.Teng */ -public interface DataSource { +public interface DataSource { + + /** + * 返回 {@link ClassLoader} 实例 + * + * @return {@link ClassLoader} 实例 + * + * @since 3.0.0 + */ + ClassLoader getDriverClassLoader(); + + /** + * 设置 {@link ClassLoader} 实例 + * + * @param driverClassLoader + * {@link ClassLoader} 实例 + * + * @since 3.0.0 + */ + void setDriverClassLoader(ClassLoader driverClassLoader); /** * 返回数据库驱动类名 @@ -114,6 +137,229 @@ public interface DataSource | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.jdbc.datasource; +import com.buession.core.builder.ListBuilder; import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.jdbc.core.Jmx; import com.buession.jdbc.core.TransactionIsolation; -import com.buession.jdbc.datasource.config.Dbcp2PoolConfiguration; +import com.buession.jdbc.datasource.pool.Dbcp2PoolConfiguration; import org.apache.commons.dbcp2.BasicDataSource; -import java.time.Duration; -import java.util.concurrent.TimeUnit; +import java.util.Collection; +import java.util.Set; /** - * DBCP2 DataSource 抽象类 + * DBCP2 DataSource * * @author Yong.Teng * @since 1.3.2 */ public class Dbcp2DataSource extends AbstractDataSource { + /** + * 在第一次创建时用来初始化物理连接的SQL语句集合,只在配置的连接工厂创建连接时被执行一次 + * + * @since 3.0.0 + */ + private Collection connectionInitSqls; + + /** + * 实现 {@link org.apache.commons.dbcp2.ConnectionFactory} 接口,连接工厂实现类 + * + * @since 3.0.0 + */ + private String connectionFactoryClassName; + + /** + * 验证快速失败 + * + * @since 3.0.0 + */ + private Boolean fastFailValidation; + + /** + * 一个过期的连接被连接池关闭时,写日志标识; + * 如果连接存货时间超过 maxConnLifetimeMillis,连接将被连接池会抽,此时默认输出日志 + * + * @since 3.0.0 + */ + private Boolean logExpiredConnections; + + /** + * 连接归还到池时,设置为自动提交 + * + * @since 3.0.0 + */ + private Boolean autoCommitOnReturn; + + /** + * 连接归还到池时,是否回滚所有操作 + * + * @since 3.0.0 + */ + private Boolean rollbackOnReturn; + + /** + * 缓存状态,如果设置为true, + * 池化的连接将在第一次读或写,以及随后的写的时候缓存当前的只读状态和自动提交设置。 + * 这样就省去了对 getter 的任何进一步的调用时对数据库的额外查询。 + * 如果直接访问底层连接,只读状态和/或自动提交设置改变缓存值将不会被反映到当前的状态,在这种情况下,应该将该属性设置为false以禁用缓存 + * + * @since 3.0.0 + */ + private Boolean cacheState; + + /** + * 用于指定一组 SQL 错误代码,当连接池检测到这些错误代码时,会将连接标记为失效并将其从连接池中移除 + * + * @since 3.0.0 + */ + private Set disconnectionSqlCodes; + /** * 构造函数 */ @@ -162,73 +224,352 @@ public Dbcp2DataSource(String driverClassName, String url, String username, Stri } @Override - public BasicDataSource createDataSource() { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); + public void setInitSQL(String initSQL) { + super.setInitSQL(initSQL); + setConnectionInitSqls(ListBuilder.of(initSQL)); + } + + /** + * 返回在第一次创建时用来初始化物理连接的SQL语句集合 + * + * @return 在第一次创建时用来初始化物理连接的SQL语句集合 + * + * @since 3.0.0 + */ + public Collection getConnectionInitSqls() { + return connectionInitSqls; + } + + /** + * 设置在第一次创建时用来初始化物理连接的SQL语句集合 + * + * @param connectionInitSqls + * 在第一次创建时用来初始化物理连接的SQL语句集合 + * + * @since 3.0.0 + */ + public void setConnectionInitSqls(Collection connectionInitSqls) { + this.connectionInitSqls = connectionInitSqls; + } + + /** + * 返回 {@link org.apache.commons.dbcp2.ConnectionFactory} 接口实现,连接工厂实现 + * + * @return {@link org.apache.commons.dbcp2.ConnectionFactory} 接口实现,连接工厂实现类 + * + * @since 3.0.0 + */ + public String getConnectionFactoryClassName() { + return connectionFactoryClassName; + } + + /** + * 设置{@link org.apache.commons.dbcp2.ConnectionFactory} 接口实现,连接工厂实现类 + * + * @param connectionFactoryClassName + * {@link org.apache.commons.dbcp2.ConnectionFactory} 接口实现,连接工厂实现类 + * + * @since 3.0.0 + */ + public void setConnectionFactoryClassName(String connectionFactoryClassName) { + this.connectionFactoryClassName = connectionFactoryClassName; + } + + /** + * 返回验证快速失败 + * + * @return 验证快速失败 + * + * @since 3.0.0 + */ + public Boolean isFastFailValidation() { + return getFastFailValidation(); + } + + /** + * 返回验证快速失败 + * + * @return 验证快速失败 + * + * @since 3.0.0 + */ + public Boolean getFastFailValidation() { + return fastFailValidation; + } + + /** + * 设置验证快速失败 + * + * @param fastFailValidation + * 验证快速失败 + * + * @since 3.0.0 + */ + public void setFastFailValidation(Boolean fastFailValidation) { + this.fastFailValidation = fastFailValidation; + } + + /** + * 返回一个过期的连接被连接池关闭时,写日志标识 + * + * @return 一个过期的连接被连接池关闭时,写日志标识 + * + * @since 3.0.0 + */ + public Boolean isLogExpiredConnections() { + return getLogExpiredConnections(); + } + + /** + * 返回一个过期的连接被连接池关闭时,写日志标识 + * + * @return 一个过期的连接被连接池关闭时,写日志标识 + * + * @since 3.0.0 + */ + public Boolean getLogExpiredConnections() { + return logExpiredConnections; + } + + /** + * 设置一个过期的连接被连接池关闭时,写日志标识 + * + * @param logExpiredConnections + * 一个过期的连接被连接池关闭时,写日志标识 + * + * @since 3.0.0 + */ + public void setLogExpiredConnections(Boolean logExpiredConnections) { + this.logExpiredConnections = logExpiredConnections; + } + + /** + * 返回连接归还到池时,设置为自动提交 + * + * @return 连接归还到池时,设置为自动提交 + * + * @since 3.0.0 + */ + public Boolean isAutoCommitOnReturn() { + return getAutoCommitOnReturn(); + } + + /** + * 返回连接归还到池时,设置为自动提交 + * + * @return 连接归还到池时,设置为自动提交 + * + * @since 3.0.0 + */ + public Boolean getAutoCommitOnReturn() { + return autoCommitOnReturn; + } + + /** + * 设置连接归还到池时,是否自动提交 + * + * @param autoCommitOnReturn + * 连接归还到池时,是否自动提交 + * + * @since 3.0.0 + */ + public void setAutoCommitOnReturn(Boolean autoCommitOnReturn) { + this.autoCommitOnReturn = autoCommitOnReturn; + } + + /** + * 返回连接归还到池时,是否回滚所有操作 + * + * @return 连接归还到池时,是否回滚所有操作 + * + * @since 3.0.0 + */ + public Boolean isRollbackOnReturn() { + return getRollbackOnReturn(); + } + + /** + * 返回连接归还到池时,是否回滚所有操作 + * + * @return 连接归还到池时,是否回滚所有操作 + * + * @since 3.0.0 + */ + public Boolean getRollbackOnReturn() { + return rollbackOnReturn; + } + + /** + * 设置连接归还到池时,是否回滚所有操作 + * + * @param rollbackOnReturn + * 连接归还到池时,是否回滚所有操作 + * + * @since 3.0.0 + */ + public void setRollbackOnReturn(Boolean rollbackOnReturn) { + this.rollbackOnReturn = rollbackOnReturn; + } + + /** + * 返回缓存状态 + * + * @return 缓存状态 + * + * @since 3.0.0 + */ + public Boolean isCacheState() { + return getCacheState(); + } + + /** + * 返回缓存状态 + * + * @return 缓存状态 + * + * @since 3.0.0 + */ + public Boolean getCacheState() { + return cacheState; + } + + /** + * 设置缓存状态 + * + * @param cacheState + * 缓存状态 + * + * @since 3.0.0 + */ + public void setCacheState(Boolean cacheState) { + this.cacheState = cacheState; + } + + /** + * 返回指定一组 SQL 错误代码,当连接池检测到这些错误代码时,会将连接标记为失效并将其从连接池中移除 + * + * @return 指定的 SQL 错误代码,当连接池检测到这些错误代码时,会将连接标记为失效并将其从连接池中移除 + * + * @since 3.0.0 + */ + public Set getDisconnectionSqlCodes() { + return disconnectionSqlCodes; + } + + /** + * 设置一组 SQL 错误代码,当连接池检测到这些错误代码时,会将连接标记为失效并将其从连接池中移除 + * + * @param disconnectionSqlCodes + * 一组 SQL 错误代码,当连接池检测到这些错误代码时,会将连接标记为失效并将其从连接池中移除 + * + * @since 3.0.0 + */ + public void setDisconnectionSqlCodes(Set disconnectionSqlCodes) { + this.disconnectionSqlCodes = disconnectionSqlCodes; + } + + @Override + protected BasicDataSource createDataSource(final PropertyMapper nullPropertyMapper, + final PropertyMapper hasTextPropertyMapper) { final BasicDataSource dataSource = new BasicDataSource(); - propertyMapper.from(this::getDriverClassName).to(dataSource::setDriverClassName); - propertyMapper.from(this::getUrl).to(dataSource::setUrl); - propertyMapper.from(this::getUsername).to(dataSource::setUsername); - propertyMapper.from(this::getPassword).to(dataSource::setPassword); + nullPropertyMapper.from(this::getDriverClassLoader).to(dataSource::setDriverClassLoader); + hasTextPropertyMapper.from(this::getDriverClassName).to(dataSource::setDriverClassName); - initialize(dataSource); + hasTextPropertyMapper.from(this::getUrl).to(dataSource::setUrl); + hasTextPropertyMapper.from(this::getUsername).to(dataSource::setUsername); + hasTextPropertyMapper.from(this::getPassword).to(dataSource::setPassword); + + hasTextPropertyMapper.from(this::getDefaultCatalog).to(dataSource::setDefaultCatalog); + hasTextPropertyMapper.from(this::getDefaultSchema).to(dataSource::setDefaultSchema); + + hasTextPropertyMapper.from(this::getConnectionFactoryClassName).to(dataSource::setConnectionFactoryClassName); + + hasTextPropertyMapper.from(this::getConnectionInitSqls).to(dataSource::setConnectionInitSqls); + + nullPropertyMapper.from(this::isFastFailValidation).to(dataSource::setFastFailValidation); + + nullPropertyMapper.from(this::getQueryTimeout).to(dataSource::setDefaultQueryTimeout); + + nullPropertyMapper.from(this::getDefaultTransactionIsolation).as(TransactionIsolation::getValue) + .to(dataSource::setDefaultTransactionIsolation); + nullPropertyMapper.from(this::isDefaultAutoCommit).to(dataSource::setDefaultAutoCommit); + nullPropertyMapper.from(this::isAutoCommitOnReturn).to(dataSource::setAutoCommitOnReturn); + nullPropertyMapper.from(this::isRollbackOnReturn).to(dataSource::setRollbackOnReturn); + + nullPropertyMapper.from(this::isDefaultReadOnly).to(dataSource::setDefaultReadOnly); + + nullPropertyMapper.from(this::isAccessToUnderlyingConnectionAllowed) + .to(dataSource::setAccessToUnderlyingConnectionAllowed); + nullPropertyMapper.from(this::isLogExpiredConnections).to(dataSource::setLogExpiredConnections); + nullPropertyMapper.from(this::isCacheState).to(dataSource::setCacheState); + nullPropertyMapper.from(this::getDisconnectionSqlCodes).to(dataSource::setDisconnectionSqlCodes); + + if(this.getConnectionProperties() != null){ + this.getConnectionProperties().forEach((name, value)->{ + if(value != null){ + dataSource.addConnectionProperty(name.toString(), value.toString()); + } + }); + } return dataSource; } @Override protected void applyPoolConfiguration(final BasicDataSource dataSource, - final Dbcp2PoolConfiguration poolConfiguration) { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - - propertyMapper.from(poolConfiguration::getDefaultCatalog).to(dataSource::setDefaultCatalog); - propertyMapper.from(poolConfiguration::getMaxConnLifetime).as( - Duration::toMillis).to(dataSource::setMaxConnLifetimeMillis); - propertyMapper.from(poolConfiguration::getDefaultQueryTimeout) - .as((v)->(int) TimeUnit.MILLISECONDS.toSeconds(v.toMillis())).to(dataSource::setDefaultQueryTimeout); - propertyMapper.from(poolConfiguration::getInitialSize).to(dataSource::setInitialSize); - propertyMapper.from(poolConfiguration::getMinIdle).to(dataSource::setMinIdle); - propertyMapper.from(poolConfiguration::getMaxIdle).to(dataSource::setMaxIdle); - propertyMapper.from(poolConfiguration::getMaxTotal).to(dataSource::setMaxTotal); - propertyMapper.from(poolConfiguration::getMaxWait).as(Duration::toMillis).to(dataSource::setMaxWaitMillis); - propertyMapper.from(poolConfiguration::getTestOnCreate).to(dataSource::setTestOnCreate); - propertyMapper.from(poolConfiguration::getTestOnBorrow).to(dataSource::setTestOnBorrow); - propertyMapper.from(poolConfiguration::getTestOnReturn).to(dataSource::setTestOnReturn); - propertyMapper.from(poolConfiguration::getTestWhileIdle).to(dataSource::setTestWhileIdle); - propertyMapper.from(poolConfiguration::getConnectionFactoryClassName) - .to(dataSource::setConnectionFactoryClassName); - propertyMapper.from(poolConfiguration::getConnectionInitSqls).to(dataSource::setConnectionInitSqls); - propertyMapper.from(poolConfiguration::getValidationQuery).to(dataSource::setValidationQuery); - propertyMapper.from(poolConfiguration::getValidationQueryTimeout).as((v)->(int) v.getSeconds()) - .to(dataSource::setValidationQueryTimeout); - propertyMapper.from(poolConfiguration::getDefaultSchema).to(dataSource::setDefaultSchema); - propertyMapper.from(poolConfiguration::getDefaultTransactionIsolation).as(TransactionIsolation::getValue) - .to(dataSource::setDefaultTransactionIsolation); - propertyMapper.from(poolConfiguration::getDefaultAutoCommit).to(dataSource::setDefaultAutoCommit); - propertyMapper.from(poolConfiguration::getAutoCommitOnReturn).to(dataSource::setAutoCommitOnReturn); - propertyMapper.from(poolConfiguration::getRollbackOnReturn).to(dataSource::setRollbackOnReturn); - propertyMapper.from(poolConfiguration::getDefaultReadOnly).to(dataSource::setDefaultReadOnly); - propertyMapper.from(poolConfiguration::getLogExpiredConnections).to(dataSource::setLogExpiredConnections); - propertyMapper.from(poolConfiguration::getAccessToUnderlyingConnectionAllowed) - .to(dataSource::setAccessToUnderlyingConnectionAllowed); - propertyMapper.from(poolConfiguration::getCacheState).to(dataSource::setCacheState); - propertyMapper.from(poolConfiguration::getPoolPreparedStatements).to(dataSource::setPoolPreparedStatements); - propertyMapper.from(poolConfiguration::getMaxOpenPreparedStatements) + final Dbcp2PoolConfiguration poolConfiguration, + final PropertyMapper nullPropertyMapper, + final PropertyMapper hasTextPropertyMapper) { + nullPropertyMapper.from(poolConfiguration::getInitialSize).to(dataSource::setInitialSize); + nullPropertyMapper.from(poolConfiguration::getMinIdle).to(dataSource::setMinIdle); + nullPropertyMapper.from(poolConfiguration::getMaxIdle).to(dataSource::setMaxIdle); + nullPropertyMapper.from(poolConfiguration::getMaxTotal).to(dataSource::setMaxTotal); + + nullPropertyMapper.from(poolConfiguration::getMaxWait).to(dataSource::setMaxWait); + nullPropertyMapper.from(poolConfiguration::getMaxConnLifetime).to(dataSource::setMaxConn); + + nullPropertyMapper.from(poolConfiguration::isTestOnCreate).to(dataSource::setTestOnCreate); + nullPropertyMapper.from(poolConfiguration::isTestOnBorrow).to(dataSource::setTestOnBorrow); + nullPropertyMapper.from(poolConfiguration::isTestOnReturn).to(dataSource::setTestOnReturn); + nullPropertyMapper.from(poolConfiguration::isTestWhileIdle).to(dataSource::setTestWhileIdle); + + hasTextPropertyMapper.from(poolConfiguration::getValidationQuery).to(dataSource::setValidationQuery); + nullPropertyMapper.from(poolConfiguration::getValidationQueryTimeout).to(dataSource::setValidationQueryTimeout); + + nullPropertyMapper.from(poolConfiguration::getMinEvictableIdle).to(dataSource::setMinEvictableIdle); + nullPropertyMapper.from(poolConfiguration::getSoftMinEvictableIdle).to(dataSource::setSoftMinEvictableIdle); + hasTextPropertyMapper.from(poolConfiguration::getEvictionPolicyClassName) + .to(dataSource::setEvictionPolicyClassName); + + nullPropertyMapper.from(poolConfiguration::getNumTestsPerEvictionRun).to(dataSource::setNumTestsPerEvictionRun); + nullPropertyMapper.from(poolConfiguration::getTimeBetweenEvictionRuns) + .to(dataSource::setDurationBetweenEvictionRuns); + + nullPropertyMapper.from(poolConfiguration::isPoolPreparedStatements).to(dataSource::setPoolPreparedStatements); + nullPropertyMapper.from(poolConfiguration::getMaxOpenPreparedStatements) .to(dataSource::setMaxOpenPreparedStatements); - propertyMapper.from(poolConfiguration::getClearStatementPoolOnReturn) + nullPropertyMapper.from(poolConfiguration::isClearStatementPoolOnReturn) .to(dataSource::setClearStatementPoolOnReturn); - propertyMapper.from(poolConfiguration::getEvictionPolicyClassName).to(dataSource::setEvictionPolicyClassName); - propertyMapper.from(poolConfiguration::getTimeBetweenEvictionRuns).as( - Duration::toMillis).to(dataSource::setTimeBetweenEvictionRunsMillis); - propertyMapper.from(poolConfiguration::getNumTestsPerEvictionRun).to(dataSource::setNumTestsPerEvictionRun); - propertyMapper.from(poolConfiguration::getMinEvictableIdleTime).as( - Duration::toMillis).to(dataSource::setMinEvictableIdleTimeMillis); - propertyMapper.from(poolConfiguration::getSoftMinEvictableIdleTime).as( - Duration::toMillis).to(dataSource::setSoftMinEvictableIdleTimeMillis); - propertyMapper.from(poolConfiguration::getLifo).to(dataSource::setLifo); - propertyMapper.from(poolConfiguration::getFastFailValidation).to(dataSource::setFastFailValidation); - propertyMapper.from(poolConfiguration::getDisconnectionSqlCodes).to(dataSource::setDisconnectionSqlCodes); - propertyMapper.from(poolConfiguration::getJmxName).to(dataSource::setJmxName); + + nullPropertyMapper.from(poolConfiguration::isRemoveAbandonedOnBorrow) + .to(dataSource::setRemoveAbandonedOnBorrow); + nullPropertyMapper.from(poolConfiguration::isRemoveAbandonedOnMaintenance) + .to(dataSource::setRemoveAbandonedOnMaintenance); + nullPropertyMapper.from(poolConfiguration::getRemoveAbandonedTimeout).to(dataSource::setRemoveAbandonedTimeout); + nullPropertyMapper.from(poolConfiguration::isAbandonedUsageTracking).to(dataSource::setAbandonedUsageTracking); + nullPropertyMapper.from(poolConfiguration::isLogAbandoned).to(dataSource::setLogAbandoned); + + nullPropertyMapper.from(poolConfiguration::isLifo).to(dataSource::setLifo); + + nullPropertyMapper.from(poolConfiguration::isRegisterConnectionMBean) + .to(dataSource::setRegisterConnectionMBean); + if(poolConfiguration.getJmx() != null){ + final Jmx jmx = poolConfiguration.getJmx(); + + nullPropertyMapper.from(jmx.isEnabled()).to(dataSource::setRegisterConnectionMBean); + hasTextPropertyMapper.from(jmx::getName).to(dataSource::setJmxName); + } } } diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/DruidDataSource.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/DruidDataSource.java index 48b290af2..6d66d7b20 100644 --- a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/DruidDataSource.java +++ b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/DruidDataSource.java @@ -19,24 +19,35 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.jdbc.datasource; +import com.alibaba.druid.Constants; +import com.alibaba.druid.util.Utils; +import com.buession.core.builder.ListBuilder; import com.buession.core.converter.mapper.PropertyMapper; import com.buession.core.utils.StringUtils; import com.buession.core.validator.Validate; +import com.buession.jdbc.core.Jmx; import com.buession.jdbc.core.TransactionIsolation; -import com.buession.jdbc.datasource.config.DruidPoolConfiguration; +import com.buession.jdbc.datasource.pool.DruidPoolConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; import java.sql.SQLException; import java.time.Duration; +import java.util.Collection; +import java.util.Set; +import java.util.concurrent.ScheduledExecutorService; /** - * Druid DataSource 抽象类 + * Druid DataSource * * @author Yong.Teng * @since 1.3.2 @@ -44,6 +55,231 @@ public class DruidDataSource extends AbstractDataSource { + /** + * 用户名回调 {@link NameCallback} 类名 + * + * @since 3.0.0 + */ + private String userCallbackClassName; + + /** + * 密码回调 {@link PasswordCallback} 类名 + * + * @since 3.0.0 + */ + private String passwordCallbackClassName; + + /** + * 连接超时 + * + * @since 3.0.0 + */ + private Duration connectTimeout; + + /** + * 网络套接字的读超时 + * + * @since 3.0.0 + */ + private Duration socketTimeout; + + /** + * 在发生连接错误后,连接池尝试重新获取连接之间的间隔时间 + * + * @since 3.0.0 + */ + private Duration timeBetweenConnectError; + + /** + * 数据库连接发生 Socket 读取超时时,决定是否立即销毁该连接 + * + * @since 3.0.0 + */ + private Boolean killWhenSocketReadTimeout; + + /** + * 物理连接的超时时间 + * + * @since 3.0.0 + */ + private Duration phyTimeout; + + /** + * 物理数据库连接的最大使用次数,设定每个物理连接在被关闭之前最多可以被重复使用的次数 + * + * @since 3.0.0 + */ + private Long phyMaxUseCount; + + /** + * 数据源初始化时是否以异步方式进行 + * + * @since 3.0.0 + */ + private Boolean asyncInit; + + /** + * 是否启用特定的变体或选项 + * + * @since 3.0.0 + */ + private Boolean initVariants; + + /** + * 在连接池初始化时应用的全局变体或选项 + * + * @since 3.0.0 + */ + private Boolean initGlobalVariants; + + /** + * 在第一次创建时用来初始化物理连接的SQL语句集合,只在配置的连接工厂创建连接时被执行一次 + * + * @since 3.0.0 + */ + private Collection connectionInitSqls; + + /** + * 自定义检查数据库连接的有效性类 + * + * @since 3.0.0 + */ + private String validConnectionCheckerClassName; + + /** + * 连接出错重试次数 + * + * @since 3.0.0 + */ + private Integer connectionErrorRetryAttempts; + + /** + * 数据源初始化过程中出现异常时,是否抛出异常 + * + * @since 3.0.0 + */ + private Boolean initExceptionThrow; + + /** + * 异常分类器 {@link com.alibaba.druid.pool.ExceptionSorter} 名称; + * 用于检测和分类数据库连接中的异常,当检测到某些特定类型的异常时,可以根据分类器的判断来决定是否将当前连接标记为不可用,并从连接池中移除。 + */ + private String exceptionSorterClassName; + + /** + * 是否启用 Oracle JDBC 驱动的隐式连接缓存 + */ + private Boolean useOracleImplicitCache; + + /** + * 是否异步关闭连接 + * + * @since 3.0.0 + */ + private Boolean asyncCloseConnectionEnable; + + /** + * 在事务中执行的 SQL 查询的超时时间 + * + * @since 3.0.0 + */ + private Duration transactionQueryTimeout; + + /** + * 事务的阈值时间 + * + * @since 3.0.0 + */ + private Duration transactionThreshold; + + /** + * 控制连接池内部锁机制的公平性。 + * 当为 {@code true} 时,使用公平锁,公平锁保证线程获取锁的顺序是按照线程请求锁的顺序,即先请求锁的线程会先获得锁;适用于对锁获取顺序有严格要求的场景,但可能会导致较高的上下文切换成本,从而影响性能。 + * 当为 {@code false} 时,使用非公平锁,非公平锁在获取锁时不考虑线程的请求顺序,可能会导致“线程饥饿”现象,但通常能够提供更好的吞吐量和性能。 + * + * @since 3.0.0 + */ + private Boolean fairLock; + + /** + * @since 3.0.0 + */ + private ScheduledExecutorService createScheduler; + + /** + * @since 3.0.0 + */ + private ScheduledExecutorService destroyScheduler; + + /** + * 数据源初始化过程中,如果发生错误,是否立即停止初始化并抛出异常 + * + * @since 3.0.0 + */ + private Boolean failFast; + + /** + * 是否监控执行时间 + * + * @since 3.0.0 + */ + private Boolean checkExecuteTime; + + /** + * 是否启用全局数据源统计功能 + * + * @since 3.0.0 + */ + private Boolean useGlobalDataSourceStat; + + /** + * SQL 监控日志的记录器名称 + * + * @since 3.0.0 + */ + private String statLoggerClassName; + + /** + * SQL 监控统计中 SQL 语句的最大数量;当超过这个数量时,Druid 会自动清理掉最早的一些 SQL 监控信息,以保持在设定的最大值以内; + * 这个设置有助于防止在高并发或长时间运行的情况下,SQL 监控信息占用过多的内存。 + * + * @since 3.0.0 + */ + private Integer maxSqlSize; + + /** + * 是否启用重置统计 + * + * @since 3.0.0 + */ + private Boolean resetStatEnable; + + /** + * 过滤器 + * + * @since 3.0.0 + */ + private Set filters; + + /** + * 是否跳过加载 SPI 机制下的 {@link com.alibaba.druid.filter.Filter} + * + * @since 3.0.0 + */ + private Boolean loadSpifilterSkip; + + /** + * 是否允许清除过滤器 + * + * @since 3.0.0 + */ + private Boolean clearFiltersEnable; + + /** + * @since 3.0.0 + */ + private Boolean enable; + private final static Logger logger = LoggerFactory.getLogger(DruidDataSource.class); /** @@ -167,135 +403,1095 @@ public DruidDataSource(String driverClassName, String url, String username, Stri super(driverClassName, url, username, password, poolConfiguration); } - @Override - public com.alibaba.druid.pool.DruidDataSource createDataSource() { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); - final com.alibaba.druid.pool.DruidDataSource dataSource = new com.alibaba.druid.pool.DruidDataSource(); + /** + * 返回用户名回调 {@link NameCallback} 类名 + * + * @return 用户名回调 {@link NameCallback} 类名 + * + * @since 3.0.0 + */ + public String getUserCallbackClassName() { + return userCallbackClassName; + } - propertyMapper.from(this::getDriverClassName).to(dataSource::setDriverClassName); - propertyMapper.from(this::getUrl).to(dataSource::setUrl); - propertyMapper.from(this::getUsername).to(dataSource::setUsername); - propertyMapper.from(this::getPassword).to(dataSource::setPassword); + /** + * 设置用户名回调 {@link NameCallback} 类名 + * + * @param userCallbackClassName + * 用户名回调 {@link NameCallback} 类名 + * + * @since 3.0.0 + */ + public void setUserCallbackClassName(String userCallbackClassName) { + this.userCallbackClassName = userCallbackClassName; + } - initialize(dataSource); + /** + * 返回密码回调 {@link PasswordCallback} 类名 + * + * @return 密码回调 {@link PasswordCallback} 类名 + * + * @since 3.0.0 + */ + public String getPasswordCallbackClassName() { + return passwordCallbackClassName; + } - return dataSource; + /** + * 设置密码回调 {@link PasswordCallback} 类名 + * + * @param passwordCallbackClassName + * 密码回调 {@link PasswordCallback} 类名 + * + * @since 3.0.0 + */ + public void setPasswordCallbackClassName(String passwordCallbackClassName) { + this.passwordCallbackClassName = passwordCallbackClassName; } - @Override - protected void applyPoolConfiguration(final com.alibaba.druid.pool.DruidDataSource dataSource, - final DruidPoolConfiguration poolConfiguration) { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - - propertyMapper.from(poolConfiguration::getName).to(dataSource::setName); - propertyMapper.from(poolConfiguration::getDefaultCatalog).to(dataSource::setDefaultCatalog); - propertyMapper.from(poolConfiguration::getDbTypeName).to(dataSource::setDbType); - propertyMapper.from(poolConfiguration::getCreateScheduler).to(dataSource::setCreateScheduler); - propertyMapper.from(poolConfiguration::getCreateScheduler).to(dataSource::setCreateScheduler); - propertyMapper.from(poolConfiguration::getDestroyScheduler).to(dataSource::setDestroyScheduler); - propertyMapper.from(poolConfiguration::getInitExceptionThrow).to(dataSource::setInitExceptionThrow); - propertyMapper.from(poolConfiguration::getMaxCreateTaskCount).to(dataSource::setMaxCreateTaskCount); - propertyMapper.from(poolConfiguration::getMaxWaitThreadCount).to(dataSource::setMaxWaitThreadCount); - propertyMapper.from(poolConfiguration::getMaxWaitThreadCount).to(dataSource::setMaxWaitThreadCount); - propertyMapper.from(poolConfiguration::getInitialSize).to(dataSource::setInitialSize); - propertyMapper.from(poolConfiguration::getMaxActive).to(dataSource::setMaxActive); - propertyMapper.from(poolConfiguration::getMinIdle).to(dataSource::setMinIdle); - propertyMapper.from(poolConfiguration::getMaxIdle).to(dataSource::setMaxIdle); - propertyMapper.from(poolConfiguration::getMaxWait).as(Duration::toMillis).to(dataSource::setMaxWait); - propertyMapper.from(poolConfiguration::getTimeBetweenConnectError) - .to(dataSource::setTimeBetweenConnectErrorMillis); - propertyMapper.from(poolConfiguration::getConnectionErrorRetryAttempts) - .to(dataSource::setConnectionErrorRetryAttempts); - propertyMapper.from(poolConfiguration::getConnectionInitSqls).to(dataSource::setConnectionInitSqls); - propertyMapper.from(poolConfiguration::getAsyncCloseConnectionEnable) - .to(dataSource::setAsyncCloseConnectionEnable); - propertyMapper.from(poolConfiguration::getAccessToUnderlyingConnectionAllowed) - .to(dataSource::setAccessToUnderlyingConnectionAllowed); - propertyMapper.from(poolConfiguration::getValidationQuery).to(dataSource::setValidationQuery); + /** + * 返回连接超时 + * + * @return 连接超时 + * + * @since 3.0.0 + */ + public Duration getConnectTimeout() { + return connectTimeout; + } - if(poolConfiguration.getValidConnectionCheckerClassName() != null){ - try{ - dataSource.setValidConnectionCheckerClassName(poolConfiguration.getValidConnectionCheckerClassName()); - }catch(Exception e){ - if(logger.isErrorEnabled()){ - logger.error("Set valid connection checker error: {}", e.getMessage()); - } - } - } + /** + * 设置连接超时 + * + * @param connectTimeout + * 连接超时 + * + * @since 3.0.0 + */ + public void setConnectTimeout(Duration connectTimeout) { + this.connectTimeout = connectTimeout; + } - propertyMapper.from(poolConfiguration::getValidationQueryTimeout).as((v)->(int) v.getSeconds()) - .to(dataSource::setValidationQueryTimeout); - propertyMapper.from(poolConfiguration::getQueryTimeout).as((v)->(int) v.getSeconds()) - .to(dataSource::setQueryTimeout); - propertyMapper.from(poolConfiguration::getNotFullTimeoutRetryCount).to(dataSource::setNotFullTimeoutRetryCount); - propertyMapper.from(poolConfiguration::getTestOnBorrow).to(dataSource::setTestOnBorrow); - propertyMapper.from(poolConfiguration::getTestOnReturn).to(dataSource::setTestOnReturn); - propertyMapper.from(poolConfiguration::getTestWhileIdle).to(dataSource::setTestWhileIdle); - propertyMapper.from(poolConfiguration::getTimeBetweenEvictionRuns).as(Duration::toMillis) - .to(dataSource::setTimeBetweenEvictionRunsMillis); - propertyMapper.from(poolConfiguration::getNumTestsPerEvictionRun).to(dataSource::setNumTestsPerEvictionRun); - propertyMapper.from(poolConfiguration::getMinEvictableIdleTime).as(Duration::toMillis) - .to(dataSource::setMinEvictableIdleTimeMillis); - propertyMapper.from(poolConfiguration::getMaxEvictableIdleTime).as(Duration::toMillis) - .to(dataSource::setMaxEvictableIdleTimeMillis); - propertyMapper.from(poolConfiguration::getKeepAliveBetweenTime).as(Duration::toMillis) - .to(dataSource::setKeepAliveBetweenTimeMillis); - propertyMapper.from(poolConfiguration::getPhyTimeout).as(Duration::toMillis) - .to(dataSource::setPhyTimeoutMillis); - propertyMapper.from(poolConfiguration::getPhyMaxUseCount).to(dataSource::setPhyMaxUseCount); - propertyMapper.from(poolConfiguration::getDefaultTransactionIsolation).as(TransactionIsolation::getValue) - .to(dataSource::setDefaultTransactionIsolation); - propertyMapper.from(poolConfiguration::getTransactionThreshold).to(dataSource::setTransactionThresholdMillis); - propertyMapper.from(poolConfiguration::getTransactionQueryTimeout).as((v)->(int) v.getSeconds()) - .to(dataSource::setTransactionQueryTimeout); - propertyMapper.from(poolConfiguration::getDefaultAutoCommit).to(dataSource::setDefaultAutoCommit); - propertyMapper.from(poolConfiguration::getDefaultReadOnly).to(dataSource::setDefaultReadOnly); - propertyMapper.from(poolConfiguration::getDefaultReadOnly).to(dataSource::setDefaultReadOnly); - propertyMapper.from(poolConfiguration::getPoolPreparedStatements).to(dataSource::setPoolPreparedStatements); - propertyMapper.from(poolConfiguration::getMaxOpenPreparedStatements) - .to(dataSource::setMaxOpenPreparedStatements); - propertyMapper.from(poolConfiguration::getSharePreparedStatements).to(dataSource::setSharePreparedStatements); - propertyMapper.from(poolConfiguration::getMaxPoolPreparedStatementPerConnectionSize) - .to(dataSource::setMaxPoolPreparedStatementPerConnectionSize); + /** + * 返回网络套接字的读超时 + * + * @return 网络套接字的读超时 + * + * @since 3.0.0 + */ + public Duration getSocketTimeout() { + return socketTimeout; + } - if(Validate.isNotEmpty(poolConfiguration.getFilters())){ - try{ - dataSource.setFilters(StringUtils.join(poolConfiguration.getFilters(), ',')); - }catch(SQLException e){ - if(logger.isErrorEnabled()){ - logger.error("Set filters error: {}(errorCode: {}, sqlState: {})", e.getMessage(), e.getErrorCode(), - e.getSQLState()); - } - } - } + /** + * 设置网络套接字的读超时 + * + * @param socketTimeout + * 网络套接字的读超时 + * + * @since 3.0.0 + */ + public void setSocketTimeout(Duration socketTimeout) { + this.socketTimeout = socketTimeout; + } - propertyMapper.from(poolConfiguration::getClearFiltersEnable).to(dataSource::setClearFiltersEnable); + /** + * 返回在发生连接错误后,连接池尝试重新获取连接之间的间隔时间 + * + * @return 在发生连接错误后,连接池尝试重新获取连接之间的间隔时间 + * + * @since 3.0.0 + */ + public Duration getTimeBetweenConnectError() { + return timeBetweenConnectError; + } - try{ - dataSource.setExceptionSorterClassName(poolConfiguration.getExceptionSorterClassName()); - }catch(Exception e){ - if(logger.isErrorEnabled()){ - logger.error("Set exception sorter error: {}", e.getMessage()); - } - } + /** + * 设置在发生连接错误后,连接池尝试重新获取连接之间的间隔时间 + * + * @param timeBetweenConnectError + * 在发生连接错误后,连接池尝试重新获取连接之间的间隔时间 + * + * @since 3.0.0 + */ + public void setTimeBetweenConnectError(Duration timeBetweenConnectError) { + this.timeBetweenConnectError = timeBetweenConnectError; + } - propertyMapper.from(poolConfiguration::getStatLogger).to(dataSource::setStatLogger); - propertyMapper.from(poolConfiguration::getTimeBetweenLogStats).as(Duration::toMillis) - .to(dataSource::setTimeBetweenLogStatsMillis); - propertyMapper.from(poolConfiguration::getRemoveAbandoned).to(dataSource::setRemoveAbandoned); - propertyMapper.from(poolConfiguration::getRemoveAbandonedTimeout).as(Duration::toMillis) - .to(dataSource::setRemoveAbandonedTimeoutMillis); - propertyMapper.from(poolConfiguration::getLogAbandoned).to(dataSource::setLogAbandoned); - propertyMapper.from(poolConfiguration::getUseOracleImplicitCache).to(dataSource::setUseOracleImplicitCache); - propertyMapper.from(poolConfiguration::getInitVariants).to(dataSource::setInitVariants); - propertyMapper.from(poolConfiguration::getInitGlobalVariants).to(dataSource::setInitGlobalVariants); - propertyMapper.from(poolConfiguration::getFailFast).to(dataSource::setFailFast); - propertyMapper.from(poolConfiguration::getOnFatalErrorMaxActive).to(dataSource::setOnFatalErrorMaxActive); - propertyMapper.from(poolConfiguration::getBreakAfterAcquireFailure).to(dataSource::setBreakAfterAcquireFailure); - propertyMapper.from(poolConfiguration::getDupCloseLogEnable).to(dataSource::setDupCloseLogEnable); - propertyMapper.from(poolConfiguration::getUseUnfairLock).to(dataSource::setUseUnfairLock); - propertyMapper.from(poolConfiguration::getUseLocalSessionState).to(dataSource::setUseLocalSessionState); - propertyMapper.from(poolConfiguration::getObjectName).to(dataSource::setObjectName); + /** + * 返回数据库连接发生 Socket 读取超时时,决定是否立即销毁该连接 + * + * @return 数据库连接发生 Socket 读取超时时,决定是否立即销毁该连接 + * + * @since 3.0.0 + */ + public Boolean isKillWhenSocketReadTimeout() { + return getKillWhenSocketReadTimeout(); + } + + /** + * 返回数据库连接发生 Socket 读取超时时,决定是否立即销毁该连接 + * + * @return 数据库连接发生 Socket 读取超时时,决定是否立即销毁该连接 + * + * @since 3.0.0 + */ + public Boolean getKillWhenSocketReadTimeout() { + return killWhenSocketReadTimeout; + } + + /** + * 设置数据库连接发生 Socket 读取超时时,决定是否立即销毁该连接 + * + * @param killWhenSocketReadTimeout + * 数据库连接发生 Socket 读取超时时,决定是否立即销毁该连接 + * + * @since 3.0.0 + */ + public void setKillWhenSocketReadTimeout(Boolean killWhenSocketReadTimeout) { + this.killWhenSocketReadTimeout = killWhenSocketReadTimeout; + } + + /** + * 返回物理连接的超时时间 + * + * @return 物理连接的超时时间 + * + * @since 3.0.0 + */ + public Duration getPhyTimeout() { + return phyTimeout; + } + + /** + * 设置物理连接的超时时间 + * + * @param phyTimeout + * 物理连接的超时时间 + * + * @since 3.0.0 + */ + public void setPhyTimeout(Duration phyTimeout) { + this.phyTimeout = phyTimeout; + } + + /** + * 返回物理数据库连接的最大使用次数,设定每个物理连接在被关闭之前最多可以被重复使用的次数 + * + * @return 物理数据库连接的最大使用次数 + * + * @since 3.0.0 + */ + public Long getPhyMaxUseCount() { + return phyMaxUseCount; + } + + /** + * 设置物理数据库连接的最大使用次数,设定每个物理连接在被关闭之前最多可以被重复使用的次数 + * + * @param phyMaxUseCount + * 物理数据库连接的最大使用次数,设定每个物理连接在被关闭之前最多可以被重复使用的次数 + * + * @since 3.0.0 + */ + public void setPhyMaxUseCount(Long phyMaxUseCount) { + this.phyMaxUseCount = phyMaxUseCount; + } + + /** + * 返回数据源初始化时是否以异步方式进行 + * + * @return 数据源初始化时是否以异步方式进行 + * + * @since 3.0.0 + */ + public Boolean isAsyncInit() { + return getAsyncInit(); + } + + /** + * 返回数据源初始化时是否以异步方式进行 + * + * @return 数据源初始化时是否以异步方式进行 + * + * @since 3.0.0 + */ + public Boolean getAsyncInit() { + return asyncInit; + } + + /** + * 设置数据源初始化时是否以异步方式进行 + * + * @param asyncInit + * 数据源初始化时是否以异步方式进行 + * + * @since 3.0.0 + */ + public void setAsyncInit(Boolean asyncInit) { + this.asyncInit = asyncInit; + } + + /** + * 返回是否启用特定的变体或选项 + * + * @return 是否启用特定的变体或选项 + * + * @since 3.0.0 + */ + public Boolean isInitVariants() { + return getInitVariants(); + } + + /** + * 返回是否启用特定的变体或选项 + * + * @return 是否启用特定的变体或选项 + * + * @since 3.0.0 + */ + public Boolean getInitVariants() { + return initVariants; + } + + /** + * 设置是否启用特定的变体或选项 + * + * @param initVariants + * 是否启用特定的变体或选项 + * + * @since 3.0.0 + */ + public void setInitVariants(Boolean initVariants) { + this.initVariants = initVariants; + } + + /** + * 返回在连接池初始化时应用的全局变体或选项 + * + * @return 在连接池初始化时应用的全局变体或选项 + * + * @since 3.0.0 + */ + public Boolean isInitGlobalVariants() { + return getInitGlobalVariants(); + } + + /** + * 返回在连接池初始化时应用的全局变体或选项 + * + * @return 在连接池初始化时应用的全局变体或选项 + * + * @since 3.0.0 + */ + public Boolean getInitGlobalVariants() { + return initGlobalVariants; + } + + /** + * 设置在连接池初始化时应用的全局变体或选项 + * + * @param initGlobalVariants + * 在连接池初始化时应用的全局变体或选项 + * + * @since 3.0.0 + */ + public void setInitGlobalVariants(Boolean initGlobalVariants) { + this.initGlobalVariants = initGlobalVariants; + } + + @Override + public void setInitSQL(String initSQL) { + super.setInitSQL(initSQL); + setConnectionInitSqls(ListBuilder.of(initSQL)); + } + + /** + * 返回在第一次创建时用来初始化物理连接的SQL语句集合 + * + * @return 在第一次创建时用来初始化物理连接的SQL语句集合 + * + * @since 3.0.0 + */ + public Collection getConnectionInitSqls() { + return connectionInitSqls; + } + + /** + * 设置在第一次创建时用来初始化物理连接的SQL语句集合 + * + * @param connectionInitSqls + * 在第一次创建时用来初始化物理连接的SQL语句集合 + * + * @since 3.0.0 + */ + public void setConnectionInitSqls(Collection connectionInitSqls) { + this.connectionInitSqls = connectionInitSqls; + } + + /** + * 返回自定义检查数据库连接的有效性类 + * + * @return 自定义检查数据库连接的有效性类 + * + * @since 3.0.0 + */ + public String getValidConnectionCheckerClassName() { + return validConnectionCheckerClassName; + } + + /** + * 设置自定义检查数据库连接的有效性类 + * + * @param validConnectionCheckerClassName + * 自定义检查数据库连接的有效性类 + * + * @since 3.0.0 + */ + public void setValidConnectionCheckerClassName(String validConnectionCheckerClassName) { + this.validConnectionCheckerClassName = validConnectionCheckerClassName; + } + + /** + * 返回连接出错重试次数 + * + * @return 连接出错重试次数 + * + * @since 3.0.0 + */ + public Integer getConnectionErrorRetryAttempts() { + return connectionErrorRetryAttempts; + } + + /** + * 设置连接出错重试次数 + * + * @param connectionErrorRetryAttempts + * 连接出错重试次数 + * + * @since 3.0.0 + */ + public void setConnectionErrorRetryAttempts(Integer connectionErrorRetryAttempts) { + this.connectionErrorRetryAttempts = connectionErrorRetryAttempts; + } + + /** + * 返回数据源初始化过程中出现异常时,是否抛出异常 + * + * @return 数据源初始化过程中出现异常时,是否抛出异常 + * + * @since 3.0.0 + */ + public Boolean isInitExceptionThrow() { + return getInitExceptionThrow(); + } + + /** + * 返回数据源初始化过程中出现异常时,是否抛出异常 + * + * @return 数据源初始化过程中出现异常时,是否抛出异常 + * + * @since 3.0.0 + */ + public Boolean getInitExceptionThrow() { + return initExceptionThrow; + } + + /** + * 设置数据源初始化过程中出现异常时,是否抛出异常 + * + * @param initExceptionThrow + * 数据源初始化过程中出现异常时,是否抛出异常 + * + * @since 3.0.0 + */ + public void setInitExceptionThrow(Boolean initExceptionThrow) { + this.initExceptionThrow = initExceptionThrow; + } + + /** + * 异常分类器 {@link com.alibaba.druid.pool.ExceptionSorter} 名称 + * + * @return 异常分类器 {@link com.alibaba.druid.pool.ExceptionSorter} 名称 + */ + public String getExceptionSorterClassName() { + return exceptionSorterClassName; + } + + /** + * 设置异常分类器 {@link com.alibaba.druid.pool.ExceptionSorter} 名称 + * + * @param exceptionSorterClassName + * 异常分类器 {@link com.alibaba.druid.pool.ExceptionSorter} 名称 + */ + public void setExceptionSorterClassName(String exceptionSorterClassName) { + this.exceptionSorterClassName = exceptionSorterClassName; + } + + /** + * 返回是否启用 Oracle JDBC 驱动的隐式连接缓存 + * + * @return 是否启用 Oracle JDBC 驱动的隐式连接缓存 + * + * @since 3.0.0 + */ + public Boolean isUseOracleImplicitCache() { + return getUseOracleImplicitCache(); + } + + /** + * 返回是否启用 Oracle JDBC 驱动的隐式连接缓存 + * + * @return 是否启用 Oracle JDBC 驱动的隐式连接缓存 + * + * @since 3.0.0 + */ + public Boolean getUseOracleImplicitCache() { + return useOracleImplicitCache; + } + + /** + * 设置是否启用 Oracle JDBC 驱动的隐式连接缓存 + * + * @param useOracleImplicitCache + * 是否启用 Oracle JDBC 驱动的隐式连接缓存 + * + * @since 3.0.0 + */ + public void setUseOracleImplicitCache(Boolean useOracleImplicitCache) { + this.useOracleImplicitCache = useOracleImplicitCache; + } + + /** + * 返回是否异步关闭连接 + * + * @return 是否异步关闭连接 + * + * @since 3.0.0 + */ + public Boolean isAsyncCloseConnectionEnable() { + return getAsyncCloseConnectionEnable(); + } + + /** + * 返回是否异步关闭连接 + * + * @return 是否异步关闭连接 + * + * @since 3.0.0 + */ + public Boolean getAsyncCloseConnectionEnable() { + return asyncCloseConnectionEnable; + } + + /** + * 设置是否异步关闭连接 + * + * @param asyncCloseConnectionEnable + * 是否异步关闭连接 + * + * @since 3.0.0 + */ + public void setAsyncCloseConnectionEnable(Boolean asyncCloseConnectionEnable) { + this.asyncCloseConnectionEnable = asyncCloseConnectionEnable; + } + + /** + * 返回在事务中执行的 SQL 查询的超时时间 + * + * @return 在事务中执行的 SQL 查询的超时时间 + * + * @since 3.0.0 + */ + public Duration getTransactionQueryTimeout() { + return transactionQueryTimeout; + } + + /** + * 设置在事务中执行的 SQL 查询的超时时间 + * + * @param transactionQueryTimeout + * 在事务中执行的 SQL 查询的超时时间 + * + * @since 3.0.0 + */ + public void setTransactionQueryTimeout(Duration transactionQueryTimeout) { + this.transactionQueryTimeout = transactionQueryTimeout; + } + + /** + * 返回事务的阈值时间 + * + * @return 事务的阈值时间 + * + * @since 3.0.0 + */ + public Duration getTransactionThreshold() { + return transactionThreshold; + } + + /** + * 设置事务的阈值时间 + * + * @param transactionThreshold + * 事务的阈值时间 + * + * @since 3.0.0 + */ + public void setTransactionThreshold(Duration transactionThreshold) { + this.transactionThreshold = transactionThreshold; + } + + /** + * 返回是否使用公平锁 + * + * @return 是否使用公平锁 + * + * @since 3.0.0 + */ + public Boolean isFairLock() { + return getFairLock(); + } + + /** + * 返回是否使用公平锁 + * + * @return 是否使用公平锁 + * + * @since 3.0.0 + */ + public Boolean getFairLock() { + return fairLock; + } + + /** + * 设置是否使用公平锁 + * + * @param fairLock + * 是否使用公平锁 + * + * @since 3.0.0 + */ + public void setFairLock(Boolean fairLock) { + this.fairLock = fairLock; + } + + public ScheduledExecutorService getCreateScheduler() { + return createScheduler; + } + + public void setCreateScheduler(ScheduledExecutorService createScheduler) { + this.createScheduler = createScheduler; + } + + public ScheduledExecutorService getDestroyScheduler() { + return destroyScheduler; + } + + public void setDestroyScheduler(ScheduledExecutorService destroyScheduler) { + this.destroyScheduler = destroyScheduler; + } + + /** + * 返回数据源初始化过程中,如果发生错误,是否立即停止初始化并抛出异常 + * + * @return 数据源初始化过程中,如果发生错误,是否立即停止初始化并抛出异常 + * + * @since 3.0.0 + */ + public Boolean isFailFast() { + return getFailFast(); + } + + /** + * 返回数据源初始化过程中,如果发生错误,是否立即停止初始化并抛出异常 + * + * @return 数据源初始化过程中,如果发生错误,是否立即停止初始化并抛出异常 + * + * @since 3.0.0 + */ + public Boolean getFailFast() { + return failFast; + } + + /** + * 设置数据源初始化过程中,如果发生错误,是否立即停止初始化并抛出异常 + * + * @param failFast + * 数据源初始化过程中,如果发生错误,是否立即停止初始化并抛出异常 + * + * @since 3.0.0 + */ + public void setFailFast(Boolean failFast) { + this.failFast = failFast; + } + + /** + * 返回是否监控执行时间 + * + * @return 是否监控执行时间 + * + * @since 3.0.0 + */ + public Boolean isCheckExecuteTime() { + return getCheckExecuteTime(); + } + + /** + * 返回是否监控执行时间 + * + * @return 是否监控执行时间 + * + * @since 3.0.0 + */ + public Boolean getCheckExecuteTime() { + return checkExecuteTime; + } + + /** + * 设置是否监控执行时间 + * + * @param checkExecuteTime + * 是否监控执行时间 + * + * @since 3.0.0 + */ + public void setCheckExecuteTime(Boolean checkExecuteTime) { + this.checkExecuteTime = checkExecuteTime; + } + + /** + * 返回是否启用全局数据源统计功能 + * + * @return 是否启用全局数据源统计功能 + * + * @since 3.0.0 + */ + public Boolean isUseGlobalDataSourceStat() { + return getUseGlobalDataSourceStat(); + } + + /** + * 返回是否启用全局数据源统计功能 + * + * @return 是否启用全局数据源统计功能 + * + * @since 3.0.0 + */ + public Boolean getUseGlobalDataSourceStat() { + return useGlobalDataSourceStat; + } + + /** + * 设置是否启用全局数据源统计功能 + * + * @param useGlobalDataSourceStat + * 是否启用全局数据源统计功能 + * + * @since 3.0.0 + */ + public void setUseGlobalDataSourceStat(Boolean useGlobalDataSourceStat) { + this.useGlobalDataSourceStat = useGlobalDataSourceStat; + } + + /** + * 返回 SQL 监控日志的记录器名称 + * + * @return SQL 监控日志的记录器名称 + * + * @since 3.0.0 + */ + public String getStatLoggerClassName() { + return statLoggerClassName; + } + + /** + * 设置 SQL 监控日志的记录器名称 + * + * @param statLoggerClassName + * SQL 监控日志的记录器名称 + * + * @since 3.0.0 + */ + public void setStatLoggerClassName(String statLoggerClassName) { + this.statLoggerClassName = statLoggerClassName; + } + + /** + * 返回 SQL 监控统计中 SQL 语句的最大数量 + * + * @return SQL 监控统计中 SQL 语句的最大数量 + * + * @since 3.0.0 + */ + public Integer getMaxSqlSize() { + return maxSqlSize; + } + + /** + * 设置 SQL 监控统计中 SQL 语句的最大数量 + * + * @param maxSqlSize + * SQL 监控统计中 SQL 语句的最大数量 + * + * @since 3.0.0 + */ + public void setMaxSqlSize(Integer maxSqlSize) { + this.maxSqlSize = maxSqlSize; + } + + /** + * 返回是否启用重置统计 + * + * @return 是否启用重置统计 + * + * @since 3.0.0 + */ + public Boolean isResetStatEnable() { + return getResetStatEnable(); + } + + /** + * 返回是否启用重置统计 + * + * @return 是否启用重置统计 + * + * @since 3.0.0 + */ + public Boolean getResetStatEnable() { + return resetStatEnable; + } + + /** + * 设置是否启用重置统计 + * + * @param resetStatEnable + * 是否启用重置统计 + * + * @since 3.0.0 + */ + public void setResetStatEnable(Boolean resetStatEnable) { + this.resetStatEnable = resetStatEnable; + } + + /** + * 返回过滤器 + * + * @return 过滤器 + * + * @since 3.0.0 + */ + public Set getFilters() { + return filters; + } + + /** + * 设置过滤器 + * + * @param filters + * 过滤器 + * + * @since 3.0.0 + */ + public void setFilters(Set filters) { + this.filters = filters; + } + + /** + * 返回是否跳过加载 SPI 机制下的 {@link com.alibaba.druid.filter.Filter} + * + * @return 是否跳过加载 SPI 机制下的 {@link com.alibaba.druid.filter.Filter} + * + * @since 3.0.0 + */ + public Boolean isLoadSpifilterSkip() { + return getLoadSpifilterSkip(); + } + + /** + * 返回是否跳过加载 SPI 机制下的 {@link com.alibaba.druid.filter.Filter} + * + * @return 是否跳过加载 SPI 机制下的 {@link com.alibaba.druid.filter.Filter} + * + * @since 3.0.0 + */ + public Boolean getLoadSpifilterSkip() { + return loadSpifilterSkip; + } + + /** + * 设置是否跳过加载 SPI 机制下的 {@link com.alibaba.druid.filter.Filter} + * + * @param loadSpifilterSkip + * 是否跳过加载 SPI 机制下的 {@link com.alibaba.druid.filter.Filter} + * + * @since 3.0.0 + */ + public void setLoadSpifilterSkip(Boolean loadSpifilterSkip) { + this.loadSpifilterSkip = loadSpifilterSkip; + } + + /** + * 返回是否允许清除过滤器 + * + * @return 是否允许清除过滤器 + * + * @since 3.0.0 + */ + public Boolean isClearFiltersEnable() { + return getClearFiltersEnable(); + } + + /** + * 返回是否允许清除过滤器 + * + * @return 是否允许清除过滤器 + * + * @since 3.0.0 + */ + public Boolean getClearFiltersEnable() { + return clearFiltersEnable; + } + + /** + * 设置是否允许清除过滤器 + * + * @param clearFiltersEnable + * 是否允许清除过滤器 + * + * @since 3.0.0 + */ + public void setClearFiltersEnable(Boolean clearFiltersEnable) { + this.clearFiltersEnable = clearFiltersEnable; + } + + public Boolean isEnable() { + return getEnable(); + } + + public Boolean getEnable() { + return enable; + } + + public void setEnable(Boolean enable) { + this.enable = enable; + } + + @Override + protected com.alibaba.druid.pool.DruidDataSource createDataSource(final PropertyMapper nullPropertyMapper, + final PropertyMapper hasTextPropertyMapper) { + final com.alibaba.druid.pool.DruidDataSource dataSource = getFairLock() == null ? + new com.alibaba.druid.pool.DruidDataSource() : new com.alibaba.druid.pool.DruidDataSource( + getFairLock()); + + nullPropertyMapper.from(this::getDriverClassLoader).to(dataSource::setDriverClassLoader); + hasTextPropertyMapper.from(this::getDriverClassName).to(dataSource::setDriverClassName); + + hasTextPropertyMapper.from(this::getUrl).to(dataSource::setUrl); + hasTextPropertyMapper.from(this::getUsername).to(dataSource::setUsername); + hasTextPropertyMapper.from(this::getPassword).to(dataSource::setPassword); + + nullPropertyMapper.from(this::getLoginTimeout).as((v)->(int) v.getSeconds()).to(dataSource::setLoginTimeout); + + try{ + if(Validate.hasText(this.getUserCallbackClassName())){ + Class userCallbackClazz = Utils.loadClass(this.getUserCallbackClassName()); + + if(userCallbackClazz != null){ + dataSource.setUserCallback((NameCallback) userCallbackClazz.newInstance()); + }else{ + logger.error("load userCallback error : {}", this.getUserCallbackClassName()); + } + } + }catch(Exception e){ + logger.error("load userCallback[{}] error : {}", this.getUserCallbackClassName(), e.getMessage()); + } + + try{ + if(Validate.hasText(this.getPasswordCallbackClassName())){ + dataSource.setPasswordCallbackClassName(this.getPasswordCallbackClassName()); + } + }catch(Exception e){ + logger.error("load passwordCallback[{}] error : {}", this.getPasswordCallbackClassName(), e.getMessage()); + } + + nullPropertyMapper.from(this::getConnectTimeout).as((v)->(int) v.toMillis()).to(dataSource::setConnectTimeout); + nullPropertyMapper.from(this::getSocketTimeout).as((v)->(int) v.toMillis()).to(dataSource::setSocketTimeout); + nullPropertyMapper.from(this::getLoginTimeout).as((v)->(int) v.getSeconds()).to(dataSource::setLoginTimeout); + + hasTextPropertyMapper.from(this::getDefaultCatalog).to(dataSource::setDefaultCatalog); + + nullPropertyMapper.from(this::getConnectionInitSqls).to(dataSource::setConnectionInitSqls); + + nullPropertyMapper.from(this::getQueryTimeout).as((v)->(int) v.getSeconds()).to(dataSource::setQueryTimeout); + + nullPropertyMapper.from(this::getDefaultTransactionIsolation).as(TransactionIsolation::getValue) + .to(dataSource::setDefaultTransactionIsolation); + nullPropertyMapper.from(this::getTransactionQueryTimeout).as((v)->(int) v.getSeconds()) + .to(dataSource::setTransactionQueryTimeout); + nullPropertyMapper.from(this::getTransactionThreshold).as(Duration::toMillis) + .to(dataSource::setTransactionThresholdMillis); + nullPropertyMapper.from(this::isDefaultAutoCommit).to(dataSource::setDefaultAutoCommit); + + nullPropertyMapper.from(this::isDefaultReadOnly).to(dataSource::setDefaultReadOnly); + + nullPropertyMapper.from(this::getTimeBetweenConnectError).as(Duration::toMillis) + .to(dataSource::setTimeBetweenConnectErrorMillis); + nullPropertyMapper.from(this::isKillWhenSocketReadTimeout).to(dataSource::setKillWhenSocketReadTimeout); + nullPropertyMapper.from(this::isAccessToUnderlyingConnectionAllowed) + .to(dataSource::setAccessToUnderlyingConnectionAllowed); + nullPropertyMapper.from(this::getPhyTimeout).as(Duration::toMillis).to(dataSource::setPhyTimeoutMillis); + nullPropertyMapper.from(this::getPhyMaxUseCount).to(dataSource::setPhyMaxUseCount); + + if(Validate.hasText(this.getValidConnectionCheckerClassName())){ + try{ + dataSource.setValidConnectionCheckerClassName(this.getValidConnectionCheckerClassName()); + }catch(Exception e){ + if(logger.isErrorEnabled()){ + logger.error("Set validConnectionChecker error: {}", e.getMessage()); + } + } + } + + nullPropertyMapper.from(this::getConnectionErrorRetryAttempts).to(dataSource::setConnectionErrorRetryAttempts); + nullPropertyMapper.from(this::isInitExceptionThrow).to(dataSource::setInitExceptionThrow); + + if(Validate.hasText(this.getExceptionSorterClassName())){ + try{ + dataSource.setExceptionSorterClassName(this.getExceptionSorterClassName()); + }catch(Exception e){ + if(logger.isErrorEnabled()){ + logger.error("Set exceptionSorter error: {}", e.getMessage()); + } + } + } + + nullPropertyMapper.from(this::isAsyncCloseConnectionEnable).to(dataSource::setAsyncCloseConnectionEnable); + nullPropertyMapper.from(this::isUseOracleImplicitCache).to(dataSource::setUseOracleImplicitCache); + nullPropertyMapper.from(this::isAsyncInit).to(dataSource::setAsyncInit); + + nullPropertyMapper.from(this::isInitVariants).to(dataSource::setInitVariants); + nullPropertyMapper.from(this::isInitGlobalVariants).to(dataSource::setInitGlobalVariants); + + nullPropertyMapper.from(this::getCreateScheduler).to(dataSource::setCreateScheduler); + nullPropertyMapper.from(this::getDestroyScheduler).to(dataSource::setDestroyScheduler); + + nullPropertyMapper.from(this::isFailFast).to(dataSource::setFailFast); + nullPropertyMapper.from(this::isCheckExecuteTime).to(dataSource::setCheckExecuteTime); + nullPropertyMapper.from(this::isUseGlobalDataSourceStat).to(dataSource::setUseGlobalDataSourceStat); + hasTextPropertyMapper.from(this::getStatLoggerClassName).to(dataSource::setStatLoggerClassName); + nullPropertyMapper.from(this::isResetStatEnable).to(dataSource::setResetStatEnable); + + nullPropertyMapper.from(this::getConnectionProperties).to(dataSource::setConnectProperties); + + if(Validate.isNotEmpty(this.getFilters())){ + try{ + dataSource.setFilters(StringUtils.join(this.getFilters(), ',')); + }catch(SQLException e){ + if(logger.isErrorEnabled()){ + logger.error("Set filters error: {}(errorCode: {}, sqlState: {})", e.getMessage(), e.getErrorCode(), + e.getSQLState()); + } + } + } + + if(this.getMaxSqlSize() != null){ + dataSource.addConnectionProperty(Constants.DRUID_STAT_SQL_MAX_SIZE, Integer.toString(this.getMaxSqlSize())); + } + + if(this.isLoadSpifilterSkip() != null){ + System.setProperty("druid.load.spifilter.skip", Boolean.toString(this.getLoadSpifilterSkip())); + } + + nullPropertyMapper.from(this::isClearFiltersEnable).to(dataSource::setClearFiltersEnable); + nullPropertyMapper.from(this::isEnable).to(dataSource::setEnable); + + return dataSource; + } + + @Override + protected void applyPoolConfiguration(final com.alibaba.druid.pool.DruidDataSource dataSource, + final DruidPoolConfiguration poolConfiguration, + final PropertyMapper nullPropertyMapper, + final PropertyMapper hasTextPropertyMapper) { + hasTextPropertyMapper.from(poolConfiguration::getPoolName).to(dataSource::setName); + + nullPropertyMapper.from(poolConfiguration::getInitialSize).to(dataSource::setInitialSize); + nullPropertyMapper.from(poolConfiguration::getMinIdle).to(dataSource::setMinIdle); + nullPropertyMapper.from(poolConfiguration::getMaxIdle).to(dataSource::setMaxIdle); + nullPropertyMapper.from(poolConfiguration::getMaxActive).to(dataSource::setMaxActive); + nullPropertyMapper.from(poolConfiguration::getOnFatalErrorMaxActive).to(dataSource::setOnFatalErrorMaxActive); + + nullPropertyMapper.from(poolConfiguration::getMaxWait).as(Duration::toMillis).to(dataSource::setMaxWait); + + nullPropertyMapper.from(poolConfiguration::getMaxCreateTaskCount).to(dataSource::setMaxCreateTaskCount); + nullPropertyMapper.from(poolConfiguration::getMaxWaitThreadCount).to(dataSource::setMaxWaitThreadCount); + nullPropertyMapper.from(poolConfiguration::getNotFullTimeoutRetryCount) + .to(dataSource::setNotFullTimeoutRetryCount); + + nullPropertyMapper.from(poolConfiguration::isTestOnBorrow).to(dataSource::setTestOnBorrow); + nullPropertyMapper.from(poolConfiguration::isTestOnReturn).to(dataSource::setTestOnReturn); + nullPropertyMapper.from(poolConfiguration::isTestWhileIdle).to(dataSource::setTestWhileIdle); + + hasTextPropertyMapper.from(poolConfiguration::getValidationQuery).to(dataSource::setValidationQuery); + nullPropertyMapper.from(poolConfiguration::getValidationQueryTimeout).as((v)->(int) v.getSeconds()) + .to(dataSource::setValidationQueryTimeout); + + nullPropertyMapper.from(poolConfiguration::getKeepAlive).to(dataSource::setKeepAlive); + + nullPropertyMapper.from(poolConfiguration::getKeepAliveBetweenTime).as(Duration::toMillis) + .to(dataSource::setKeepAliveBetweenTimeMillis); + + nullPropertyMapper.from(poolConfiguration::isUsePingMethod).to(dataSource::setUsePingMethod); + + nullPropertyMapper.from(poolConfiguration::getMinEvictableIdle).as(Duration::toMillis) + .to(dataSource::setMinEvictableIdleTimeMillis); + nullPropertyMapper.from(poolConfiguration::getMaxEvictableIdle).as(Duration::toMillis) + .to(dataSource::setMaxEvictableIdleTimeMillis); + + nullPropertyMapper.from(poolConfiguration::getNumTestsPerEvictionRun).to(dataSource::setNumTestsPerEvictionRun); + nullPropertyMapper.from(poolConfiguration::getTimeBetweenEvictionRuns).as(Duration::toMillis) + .to(dataSource::setTimeBetweenEvictionRunsMillis); + + nullPropertyMapper.from(poolConfiguration::isKeepConnectionUnderlyingTransactionIsolation) + .to(dataSource::setKeepConnectionUnderlyingTransactionIsolation); + + nullPropertyMapper.from(poolConfiguration::isBreakAfterAcquireFailure) + .to(dataSource::setBreakAfterAcquireFailure); + + nullPropertyMapper.from(poolConfiguration::isPoolPreparedStatements).to(dataSource::setPoolPreparedStatements); + nullPropertyMapper.from(poolConfiguration::isSharePreparedStatements) + .to(dataSource::setSharePreparedStatements); + nullPropertyMapper.from(poolConfiguration::getMaxOpenPreparedStatements) + .to(dataSource::setMaxOpenPreparedStatements); + nullPropertyMapper.from(poolConfiguration::getMaxPoolPreparedStatementPerConnectionSize) + .to(dataSource::setMaxPoolPreparedStatementPerConnectionSize); + + nullPropertyMapper.from(poolConfiguration::isRemoveAbandoned).to(dataSource::setRemoveAbandoned); + nullPropertyMapper.from(poolConfiguration::getRemoveAbandonedTimeout).as(Duration::toMillis) + .to(dataSource::setRemoveAbandonedTimeoutMillis); + nullPropertyMapper.from(poolConfiguration::isLogAbandoned).to(dataSource::setLogAbandoned); + + nullPropertyMapper.from(poolConfiguration::isUseLocalSessionState).to(dataSource::setUseLocalSessionState); + + nullPropertyMapper.from(poolConfiguration::getTimeBetweenLogStats).as(Duration::toMillis) + .to(dataSource::setTimeBetweenLogStatsMillis); + nullPropertyMapper.from(poolConfiguration::isDupCloseLogEnable).to(dataSource::setDupCloseLogEnable); + nullPropertyMapper.from(poolConfiguration::isLogDifferentThread).to(dataSource::setLogDifferentThread); + + if(poolConfiguration.getJmx() != null){ + final Jmx jmx = poolConfiguration.getJmx(); + + if(Validate.hasText(jmx.getName())){ + try{ + dataSource.setObjectName(new ObjectName(jmx.getName())); + }catch(MalformedObjectNameException e){ + if(logger.isErrorEnabled()){ + logger.error("create {} instance error: {}", ObjectName.class.getName(), e.getMessage()); + } + } + } + } } } diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/GenericDataSource.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/GenericDataSource.java index 4fe7a365c..a218ae9e2 100644 --- a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/GenericDataSource.java +++ b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/GenericDataSource.java @@ -19,17 +19,18 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.jdbc.datasource; -import com.buession.jdbc.datasource.config.GenericPoolConfiguration; +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.jdbc.datasource.pool.GenericPoolConfiguration; import javax.sql.DataSource; /** - * 常规 DataSource 抽象类 + * 一般 DataSource * * @author Yong.Teng * @since 1.3.2 @@ -39,7 +40,7 @@ public class GenericDataSource extends AbstractDataSource | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.jdbc.datasource; import com.buession.core.converter.mapper.PropertyMapper; -import com.buession.jdbc.datasource.config.HikariPoolConfiguration; +import com.buession.core.validator.Validate; +import com.buession.jdbc.core.Jmx; +import com.buession.jdbc.core.TransactionIsolation; +import com.buession.jdbc.datasource.pool.HikariPoolConfiguration; +import com.zaxxer.hikari.utils.ObjectUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.time.Duration; +import java.util.Properties; /** - * Hikari DataSource 抽象类 + * Hikari DataSource * * @author Yong.Teng * @since 1.3.2 */ public class HikariDataSource extends AbstractDataSource { + /** + * JNDI 数据源的名称 + * + * @since 3.0.0 + */ + private String jndiName; + + /** + * 从连接池获取连接时最大等待时间 + */ + private Duration connectionTimeout; + + /** + * 为支持 catalog 概念的数据库设置默认 catalog + * + * @since 3.0.0 + */ + private String catalog; + + /** + * 设置的默认模式为支持模式的概念数据库;如果未指定此属性,则使用由JDBC驱动程序定义的默认模式 + * + * @since 3.0.0 + */ + private String schema; + + /** + * 设置一个SQL语句,在将每个新连接创建后,将其添加到池中之前执行该语句 + * + * @since 3.0.0 + */ + private String connectionInitSql; + + /** + * 默认事务隔离级别 + * + * @since 3.0.0 + */ + private TransactionIsolation transactionIsolation = TransactionIsolation.DEFAULT; + + /** + * 是否将 HikariCP 执行的内部查询与应用程序的查询隔离 + */ + private Boolean isolateInternalQueries; + + /** + * 是否自动提交事务 + * + * @since 3.0.0 + */ + private Boolean autoCommit; + + /** + * 连接是否是只读模式 + * + * @since 3.0.0 + */ + private Boolean readOnly; + + /** + * 底层数据源相关的属性 + * + * @since 3.0.0 + */ + private Properties dataSourceProperties; + + private final static Logger logger = LoggerFactory.getLogger(HikariDataSource.class); + /** * 构造函数 */ @@ -158,57 +233,384 @@ public HikariDataSource(String driverClassName, String url, String username, Str super(driverClassName, url, username, password, poolConfiguration); } + /** + * 返回 JNDI 数据源的名称 + * + * @return JNDI 数据源的名称 + * + * @since 3.0.0 + */ + public String getJndiName() { + return jndiName; + } + + /** + * 设置 JNDI 数据源的名称 + * + * @param jndiName + * JNDI 数据源的名称 + * + * @since 3.0.0 + */ + public void setJndiName(String jndiName) { + this.jndiName = jndiName; + } + + /** + * 返回从连接池获取连接时最大等待时间 + * + * @return 从连接池获取连接时最大等待时间 + */ + public Duration getConnectionTimeout() { + return connectionTimeout; + } + + /** + * 设置从连接池获取连接时最大等待时间 + * + * @param connectionTimeout + * 从连接池获取连接时最大等待时间 + */ + public void setConnectionTimeout(Duration connectionTimeout) { + this.connectionTimeout = connectionTimeout; + } + + /** + * 返回为支持 catalog 概念的数据库设置默认 catalog + * + * @return 为支持 catalog 概念的数据库设置默认 catalog + * + * @since 3.0.0 + */ + public String getCatalog() { + return catalog; + } + + /** + * 设置为支持 catalog 概念的数据库设置默认 catalog + * + * @param catalog + * 为支持 catalog 概念的数据库设置默认 catalog + * + * @since 3.0.0 + */ + public void setCatalog(String catalog) { + this.catalog = catalog; + super.setDefaultCatalog(catalog); + } + @Override - public com.zaxxer.hikari.HikariDataSource createDataSource() { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); + public void setDefaultCatalog(String defaultCatalog) { + setCatalog(defaultCatalog); + } + + /** + * 返回默认模式为支持模式的概念数据库 + * + * @return 默认模式为支持模式的概念数据库 + * + * @since 3.0.0 + */ + public String getSchema() { + return schema; + } + + /** + * 设置默认模式为支持模式的概念数据库 + * + * @param schema + * 默认模式为支持模式的概念数据库 + * + * @since 3.0.0 + */ + public void setSchema(String schema) { + this.schema = schema; + super.setDefaultSchema(schema); + } + + @Override + public void setDefaultSchema(String defaultSchema) { + setSchema(defaultSchema); + } + + /** + * 返回在将每个新连接创建后,将其添加到池中之前执行的SQL语句 + * + * @return 每个新连接创建后,将其添加到池中之前执行的SQL语句 + * + * @since 3.0.0 + */ + public String getConnectionInitSql() { + return connectionInitSql; + } + + /** + * 设置每个新连接创建后,将其添加到池中之前执行的SQL语句 + * + * @param connectionInitSql + * 每个新连接创建后,将其添加到池中之前执行的SQL语句 + * + * @since 3.0.0 + */ + public void setConnectionInitSql(String connectionInitSql) { + this.connectionInitSql = connectionInitSql; + super.setInitSQL(connectionInitSql); + } + + @Override + public void setInitSQL(String initSQL) { + setConnectionInitSql(initSQL); + } + + /** + * 返回默认事务隔离级别 + * + * @return 默认事务隔离级别 + */ + public TransactionIsolation getTransactionIsolation() { + return transactionIsolation; + } + + /** + * 设置默认事务隔离级别 + * + * @param transactionIsolation + * 默认事务隔离级别 + */ + public void setTransactionIsolation(TransactionIsolation transactionIsolation) { + this.transactionIsolation = transactionIsolation; + super.setDefaultTransactionIsolation(transactionIsolation); + } + + @Override + public void setDefaultTransactionIsolation(TransactionIsolation defaultTransactionIsolation) { + setTransactionIsolation(defaultTransactionIsolation); + } + + /** + * 返回是否将 HikariCP 执行的内部查询与应用程序的查询隔离 + * + * @return 是否将 HikariCP 执行的内部查询与应用程序的查询隔离 + */ + public Boolean isIsolateInternalQueries() { + return getIsolateInternalQueries(); + } + + /** + * 返回是否将 HikariCP 执行的内部查询与应用程序的查询隔离 + * + * @return 是否将 HikariCP 执行的内部查询与应用程序的查询隔离 + */ + public Boolean getIsolateInternalQueries() { + return isolateInternalQueries; + } + + /** + * 设置是否将 HikariCP 执行的内部查询与应用程序的查询隔离 + * + * @param isolateInternalQueries + * 是否将 HikariCP 执行的内部查询与应用程序的查询隔离 + */ + public void setIsolateInternalQueries(Boolean isolateInternalQueries) { + this.isolateInternalQueries = isolateInternalQueries; + } + + /** + * 返回是否自动提交事务 + * + * @return 是否自动提交事务 + */ + public Boolean isAutoCommit() { + return getAutoCommit(); + } + + /** + * 返回是否自动提交事务 + * + * @return 是否自动提交事务 + */ + public Boolean getAutoCommit() { + return autoCommit; + } + + /** + * 设置是否自动提交事务 + * + * @param autoCommit + * 是否自动提交事务 + */ + public void setAutoCommit(Boolean autoCommit) { + this.autoCommit = autoCommit; + super.setDefaultAutoCommit(autoCommit); + } + + @Override + public void setDefaultAutoCommit(Boolean defaultAutoCommit) { + setAutoCommit(defaultAutoCommit); + } + + /** + * 返回连接是否是只读模式 + * + * @return 连接是否是只读模式 + */ + public Boolean isReadOnly() { + return getReadOnly(); + } + + /** + * 返回连接是否是只读模式 + * + * @return 连接是否是只读模式 + */ + public Boolean getReadOnly() { + return readOnly; + } + + /** + * 设置连接是否是只读模式 + * + * @param readOnly + * 连接是否是只读模式 + */ + public void setReadOnly(Boolean readOnly) { + this.readOnly = readOnly; + super.setDefaultReadOnly(readOnly); + } + + @Override + public void setDefaultReadOnly(Boolean defaultReadOnly) { + setReadOnly(defaultReadOnly); + } + + /** + * 返回底层数据源相关的属性 + * + * @return 底层数据源相关的属性 + */ + public Properties getDataSourceProperties() { + return dataSourceProperties; + } + + /** + * 设置底层数据源相关的属性 + * + * @param dataSourceProperties + * 底层数据源相关的属性 + */ + public void setDataSourceProperties(Properties dataSourceProperties) { + this.dataSourceProperties = dataSourceProperties; + super.setConnectionProperties(dataSourceProperties); + } + + @Override + public void setConnectionProperties(Properties connectionProperties) { + setDataSourceProperties(connectionProperties); + } + + @Override + protected com.zaxxer.hikari.HikariDataSource createDataSource(final PropertyMapper nullPropertyMapper, + final PropertyMapper hasTextPropertyMapper) { final com.zaxxer.hikari.HikariDataSource dataSource = new com.zaxxer.hikari.HikariDataSource(); - propertyMapper.from(this::getDriverClassName).to(dataSource::setDriverClassName); - propertyMapper.from(this::getUrl).to(dataSource::setJdbcUrl); - propertyMapper.from(this::getUsername).to(dataSource::setUsername); - propertyMapper.from(this::getPassword).to(dataSource::setPassword); + hasTextPropertyMapper.from(this::getDriverClassName).to(dataSource::setDriverClassName); + + hasTextPropertyMapper.from(this::getJndiName).to(dataSource::setDataSourceJNDI); + hasTextPropertyMapper.from(this::getUrl).to(dataSource::setJdbcUrl); + hasTextPropertyMapper.from(this::getUsername).to(dataSource::setUsername); + hasTextPropertyMapper.from(this::getPassword).to(dataSource::setPassword); + + nullPropertyMapper.from(this::getConnectionTimeout).as(Duration::toMillis).to(dataSource::setConnectionTimeout); - initialize(dataSource); + hasTextPropertyMapper.from(this::getCatalog).to(dataSource::setCatalog); + hasTextPropertyMapper.from(this::getSchema).to(dataSource::setSchema); + + hasTextPropertyMapper.from(this::getConnectionInitSql).to(dataSource::setConnectionInitSql); + + if(this.getTransactionIsolation() != null){ + if(this.getTransactionIsolation() != TransactionIsolation.DEFAULT){ + dataSource.setTransactionIsolation("TRANSACTION_" + this.getTransactionIsolation().name()); + } + } + + nullPropertyMapper.from(this::isIsolateInternalQueries).to(dataSource::setIsolateInternalQueries); + nullPropertyMapper.from(this::isAutoCommit).to(dataSource::setAutoCommit); + + nullPropertyMapper.from(this::isReadOnly).to(dataSource::setReadOnly); + + nullPropertyMapper.from(this::getDataSourceProperties).to(dataSource::setDataSourceProperties); return dataSource; } @Override protected void applyPoolConfiguration(final com.zaxxer.hikari.HikariDataSource dataSource, - final HikariPoolConfiguration poolConfiguration) { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - - propertyMapper.from(poolConfiguration::getCatalog).to(dataSource::setCatalog); - propertyMapper.from(poolConfiguration::getConnectionTimeout).as( - Duration::toMillis).to(dataSource::setConnectionTimeout); - propertyMapper.from(poolConfiguration::getIdleTimeout).as(Duration::toMillis).to(dataSource::setIdleTimeout); - propertyMapper.from(poolConfiguration::getLeakDetectionThreshold).to(dataSource::setLeakDetectionThreshold); - propertyMapper.from(poolConfiguration::getMaxLifetime).as(Duration::toMillis).to(dataSource::setMaxLifetime); - propertyMapper.from(poolConfiguration::getKeepaliveTime).as(Duration::toMillis) - .to(dataSource::setKeepaliveTime); - propertyMapper.from(poolConfiguration::getMinIdle).to(dataSource::setMinimumIdle); - propertyMapper.from(poolConfiguration::getMaxPoolSize).to(dataSource::setMaximumPoolSize); - propertyMapper.from(poolConfiguration::getInitializationFailTimeout).as(Duration::toMillis) + final HikariPoolConfiguration poolConfiguration, + final PropertyMapper nullPropertyMapper, + final PropertyMapper hasTextPropertyMapper) { + hasTextPropertyMapper.from(poolConfiguration::getPoolName).to(dataSource::setPoolName); + + nullPropertyMapper.from(poolConfiguration::getInitializationFailTimeout).as(Duration::toMillis) .to(dataSource::setInitializationFailTimeout); - propertyMapper.from(poolConfiguration::getConnectionInitSql).to(dataSource::setConnectionInitSql); - propertyMapper.from(poolConfiguration::getConnectionTestQuery).to(dataSource::setConnectionTestQuery); - propertyMapper.from(poolConfiguration::getValidationTimeout).as(Duration::toMillis) + + nullPropertyMapper.from(poolConfiguration::getMinIdle).to(dataSource::setMinimumIdle); + nullPropertyMapper.from(poolConfiguration::getMaxPoolSize).to(dataSource::setMaximumPoolSize); + + hasTextPropertyMapper.from(poolConfiguration::getConnectionTestQuery).to(dataSource::setConnectionTestQuery); + nullPropertyMapper.from(poolConfiguration::getValidationTimeout).as(Duration::toMillis) .to(dataSource::setValidationTimeout); - propertyMapper.from(poolConfiguration::getPoolName).to(dataSource::setPoolName); - propertyMapper.from(poolConfiguration::getTransactionIsolation).as((v)->"TRANSACTION_" + v.name()) - .to(dataSource::setTransactionIsolation); - propertyMapper.from(poolConfiguration::getAutoCommit).to(dataSource::setAutoCommit); - propertyMapper.from(poolConfiguration::getReadOnly).to(dataSource::setReadOnly); - propertyMapper.from(poolConfiguration::getIsolateInternalQueries).to(dataSource::setIsolateInternalQueries); - propertyMapper.from(poolConfiguration::getRegisterMbeans).to(dataSource::setRegisterMbeans); - propertyMapper.from(poolConfiguration::getAllowPoolSuspension).to(dataSource::setAllowPoolSuspension); - propertyMapper.from(poolConfiguration::getThreadFactory).to(dataSource::setThreadFactory); - propertyMapper.from(poolConfiguration::getScheduledExecutor).to(dataSource::setScheduledExecutor); - propertyMapper.from(poolConfiguration::getMetricsTrackerFactory).to(dataSource::setMetricsTrackerFactory); - propertyMapper.from(poolConfiguration::getMetricRegistry).to(dataSource::setMetricRegistry); - propertyMapper.from(poolConfiguration::getHealthCheckRegistry).to(dataSource::setHealthCheckRegistry); - propertyMapper.from(poolConfiguration::getHealthCheckProperties).to(dataSource::setHealthCheckProperties); - propertyMapper.from(poolConfiguration::getProperties).to(dataSource::setDataSourceProperties); + + nullPropertyMapper.from(poolConfiguration::getKeepaliveTime).as(Duration::toMillis) + .to(dataSource::setKeepaliveTime); + nullPropertyMapper.from(poolConfiguration::getIdleTimeout).as(Duration::toMillis) + .to(dataSource::setIdleTimeout); + nullPropertyMapper.from(poolConfiguration::getMaxLifetime).as(Duration::toMillis) + .to(dataSource::setMaxLifetime); + + nullPropertyMapper.from(poolConfiguration::getThreadFactory).to(dataSource::setThreadFactory); + nullPropertyMapper.from(poolConfiguration::getScheduledExecutor).to(dataSource::setScheduledExecutor); + nullPropertyMapper.from(poolConfiguration::getLeakDetectionThreshold).as(Duration::toMillis) + .to(dataSource::setLeakDetectionThreshold); + nullPropertyMapper.from(poolConfiguration::isAllowPoolSuspension).to(dataSource::setAllowPoolSuspension); + + if(Validate.hasText(poolConfiguration.getMetricsTrackerFactoryClassName())){ + try{ + dataSource.setMetricsTrackerFactory( + ObjectUtils.newInstance(poolConfiguration.getMetricsTrackerFactoryClassName())); + }catch(IllegalStateException e){ + logger.error("load metricsTrackerFactory[{}] error : {}", + poolConfiguration.getMetricsTrackerFactoryClassName(), e.getMessage()); + } + } + + if(Validate.hasText(poolConfiguration.getMetricRegistryClassName())){ + try{ + dataSource.setMetricRegistry( + ObjectUtils.newInstance(poolConfiguration.getMetricRegistryClassName())); + }catch(IllegalStateException e){ + logger.error("load metricRegistry[{}] error : {}", poolConfiguration.getMetricRegistryClassName(), + e.getMessage()); + } + } + + if(Validate.hasText(poolConfiguration.getHealthCheckRegistryClassName())){ + try{ + dataSource.setHealthCheckRegistry( + ObjectUtils.newInstance(poolConfiguration.getHealthCheckRegistryClassName())); + }catch(IllegalStateException e){ + logger.error("load healthCheckRegistry[{}] error : {}", + poolConfiguration.getHealthCheckRegistryClassName(), e.getMessage()); + } + } + + nullPropertyMapper.from(poolConfiguration::getHealthCheckProperties).to(dataSource::setHealthCheckProperties); + + nullPropertyMapper.from(poolConfiguration::isRegisterMbeans).to(dataSource::setRegisterMbeans); + if(poolConfiguration.getJmx() != null){ + final Jmx jmx = poolConfiguration.getJmx(); + + nullPropertyMapper.from(jmx::isEnabled).to(dataSource::setRegisterMbeans); + } } } diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/OracleDataSource.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/OracleDataSource.java new file mode 100644 index 000000000..221f6fb19 --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/OracleDataSource.java @@ -0,0 +1,732 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.datasource; + +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.utils.MethodUtils; +import com.buession.core.validator.Validate; +import com.buession.jdbc.datasource.pool.OraclePoolConfiguration; +import oracle.ucp.jdbc.PoolDataSource; +import oracle.ucp.jdbc.PoolDataSourceImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.sql.SQLException; +import java.util.Properties; + +/** + * Oracle DataSource + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class OracleDataSource extends AbstractDataSource { + + /** + * 网络协议 + */ + private String networkProtocol; + + /** + * 数据库服务器的名称或地址 + */ + private String serverName; + + /** + * 数据库服务器的端口 + */ + private Integer portNumber; + + /** + * 连接到 Oracle 数据库服务的服务名,服务名用于在 Oracle 数据库中标识特定的服务或数据库实例 + */ + private String serviceName; + + /** + * 数据源名称 + */ + private String dataSourceName; + + /** + * 数据源描述 + */ + private String dataSourceDescription; + + /** + * 要连接的 Oracle 数据库的名称 + */ + private String databaseName; + + /** + * 角色名称 + */ + private String roleName; + + /** + * 连接到 Oracle Pluggable Database (PDB) 的角色的属性 + */ + private Properties pdbRoles; + + /** + * 连接工厂类名 + */ + private String connectionFactoryClassName; + + /** + * 是否启用快速连接故障切换 + */ + private Boolean fastConnectionFailoverEnabled; + + /** + * Oracle Notification Services (ONS) 的属性 + */ + private String onsConfiguration; + + /** + * 是否启用分片模式 + */ + private Boolean shardingMode; + + /** + * 每个分片(Shard)中允许的最大连接数 + */ + private Integer maxConnectionsPerShard; + + /** + * 每个服务的最大连接数 + */ + private Integer maxConnectionsPerService; + + private final static Logger logger = LoggerFactory.getLogger(OracleDataSource.class); + + /** + * 构造函数 + */ + public OracleDataSource() { + super(); + } + + /** + * 构造函数 + * + * @param driverClassName + * 数据库驱动类名 + * @param url + * JDBC URL + */ + public OracleDataSource(String driverClassName, String url) { + super(driverClassName, url); + } + + /** + * 构造函数 + * + * @param driverClassName + * 数据库驱动类名 + * @param url + * JDBC URL + * @param username + * 数据库账号 + */ + public OracleDataSource(String driverClassName, String url, String username) { + super(driverClassName, url, username); + } + + /** + * 构造函数 + * + * @param driverClassName + * 数据库驱动类名 + * @param url + * JDBC URL + * @param username + * 数据库账号 + * @param password + * 数据库密码 + */ + public OracleDataSource(String driverClassName, String url, String username, String password) { + super(driverClassName, url, username, password); + } + + /** + * 构造函数 + * + * @param poolConfiguration + * 连接池配置 + */ + public OracleDataSource(OraclePoolConfiguration poolConfiguration) { + super(poolConfiguration); + } + + /** + * 构造函数 + * + * @param driverClassName + * 数据库驱动类名 + * @param url + * JDBC URL + * @param poolConfiguration + * 连接池配置 + */ + public OracleDataSource(String driverClassName, String url, OraclePoolConfiguration poolConfiguration) { + super(driverClassName, url, poolConfiguration); + } + + /** + * 构造函数 + * + * @param driverClassName + * 数据库驱动类名 + * @param url + * JDBC URL + * @param username + * 数据库账号 + * @param poolConfiguration + * 连接池配置 + */ + public OracleDataSource(String driverClassName, String url, String username, + OraclePoolConfiguration poolConfiguration) { + super(driverClassName, url, username, poolConfiguration); + } + + /** + * 构造函数 + * + * @param driverClassName + * 数据库驱动类名 + * @param url + * JDBC URL + * @param username + * 数据库账号 + * @param password + * 数据库密码 + * @param poolConfiguration + * 连接池配置 + */ + public OracleDataSource(String driverClassName, String url, String username, String password, + OraclePoolConfiguration poolConfiguration) { + super(driverClassName, url, username, password, poolConfiguration); + } + + /** + * 返回网络协议 + * + * @return 网络协议 + */ + public String getNetworkProtocol() { + return networkProtocol; + } + + /** + * 设置网络协议 + * + * @param networkProtocol + * 网络协议 + */ + public void setNetworkProtocol(String networkProtocol) { + this.networkProtocol = networkProtocol; + } + + /** + * 返回数据库服务器的名称或地址 + * + * @return 数据库服务器的名称或地址 + */ + public String getServerName() { + return serverName; + } + + /** + * 设置数据库服务器的名称或地址 + * + * @param serverName + * 数据库服务器的名称或地址 + */ + public void setServerName(String serverName) { + this.serverName = serverName; + } + + /** + * 返回数据库服务器的端口 + * + * @return 数据库服务器的端口 + */ + public Integer getPortNumber() { + return portNumber; + } + + /** + * 设置数据库服务器的端口 + * + * @param portNumber + * 数据库服务器的端口 + */ + public void setPortNumber(Integer portNumber) { + this.portNumber = portNumber; + } + + /** + * 返回连接到 Oracle 数据库服务的服务名,服务名用于在 Oracle 数据库中标识特定的服务或数据库实例 + * + * @return 连接到 Oracle 数据库服务的服务名 + */ + public String getServiceName() { + return serviceName; + } + + /** + * 设置连接到 Oracle 数据库服务的服务名,服务名用于在 Oracle 数据库中标识特定的服务或数据库实例 + * + * @param serviceName + * 连接到 Oracle 数据库服务的服务名 + */ + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + /** + * 返回数据源名称 + * + * @return 数据源名称 + */ + public String getDataSourceName() { + return dataSourceName; + } + + /** + * 设置数据源名称 + * + * @param dataSourceName + * 数据源名称 + */ + public void setDataSourceName(String dataSourceName) { + this.dataSourceName = dataSourceName; + } + + /** + * 返回数据源描述 + * + * @return 数据源描述 + */ + public String getDataSourceDescription() { + return dataSourceDescription; + } + + /** + * 设置数据源描述 + * + * @param dataSourceDescription + * 数据源描述 + */ + public void setDataSourceDescription(String dataSourceDescription) { + this.dataSourceDescription = dataSourceDescription; + } + + /** + * 返回要连接的 Oracle 数据库的名称 + * + * @return 要连接的 Oracle 数据库的名称 + */ + public String getDatabaseName() { + return databaseName; + } + + /** + * 设置 + * + * @param databaseName + * 要连接的 Oracle 数据库的名称 + */ + public void setDatabaseName(String databaseName) { + this.databaseName = databaseName; + } + + /** + * 返回角色名称 + * + * @return 角色名称 + */ + public String getRoleName() { + return roleName; + } + + /** + * 设置角色名称 + * + * @param roleName + * 角色名称 + */ + public void setRoleName(String roleName) { + this.roleName = roleName; + } + + /** + * 返回连接到 Oracle Pluggable Database (PDB) 的角色的属性 + * + * @return 连接到 Oracle Pluggable Database (PDB) 的角色的属性 + */ + public Properties getPdbRoles() { + return pdbRoles; + } + + /** + * 设置连接到 Oracle Pluggable Database (PDB) 的角色的属性 + * + * @param pdbRoles + * 连接到 Oracle Pluggable Database (PDB) 的角色的属性 + */ + public void setPdbRoles(Properties pdbRoles) { + this.pdbRoles = pdbRoles; + } + + /** + * 返回连接工厂类名 + * + * @return 连接工厂类名 + */ + public String getConnectionFactoryClassName() { + return connectionFactoryClassName; + } + + /** + * 设置连接工厂类名 + * + * @param connectionFactoryClassName + * 连接工厂类名 + */ + public void setConnectionFactoryClassName(String connectionFactoryClassName) { + this.connectionFactoryClassName = connectionFactoryClassName; + } + + /** + * 返回是否启用快速连接故障切换 + * + * @return 是否启用快速连接故障切换 + */ + public Boolean isFastConnectionFailoverEnabled() { + return getFastConnectionFailoverEnabled(); + } + + /** + * 返回是否启用快速连接故障切换 + * + * @return 是否启用快速连接故障切换 + */ + public Boolean getFastConnectionFailoverEnabled() { + return fastConnectionFailoverEnabled; + } + + /** + * 设置是否启用快速连接故障切换 + * + * @param fastConnectionFailoverEnabled + * 是否启用快速连接故障切换 + */ + public void setFastConnectionFailoverEnabled(Boolean fastConnectionFailoverEnabled) { + this.fastConnectionFailoverEnabled = fastConnectionFailoverEnabled; + } + + /** + * 返回 Oracle Notification Services (ONS) 的属性 + * + * @return Oracle Notification Services (ONS) 的属性 + */ + public String getOnsConfiguration() { + return onsConfiguration; + } + + /** + * 设置 Oracle Notification Services (ONS) 的属性 + * + * @param onsConfiguration + * Oracle Notification Services (ONS) 的属性 + */ + public void setOnsConfiguration(String onsConfiguration) { + this.onsConfiguration = onsConfiguration; + } + + /** + * 返回是否启用分片模式 + * + * @return 是否启用分片模式 + */ + public Boolean isShardingMode() { + return getShardingMode(); + } + + /** + * 返回是否启用分片模式 + * + * @return 是否启用分片模式 + */ + public Boolean getShardingMode() { + return shardingMode; + } + + /** + * 设置是否启用分片模式 + * + * @param shardingMode + * 是否启用分片模式 + */ + public void setShardingMode(Boolean shardingMode) { + this.shardingMode = shardingMode; + } + + /** + * 返回每个分片(Shard)中允许的最大连接数 + * + * @return 每个分片(Shard)中允许的最大连接数 + */ + public Integer getMaxConnectionsPerShard() { + return maxConnectionsPerShard; + } + + /** + * 设置每个分片(Shard)中允许的最大连接数 + * + * @param maxConnectionsPerShard + * 每个分片(Shard)中允许的最大连接数 + */ + public void setMaxConnectionsPerShard(Integer maxConnectionsPerShard) { + this.maxConnectionsPerShard = maxConnectionsPerShard; + } + + /** + * 返回每个服务的最大连接数 + * + * @return 每个服务的最大连接数 + */ + public Integer getMaxConnectionsPerService() { + return maxConnectionsPerService; + } + + /** + * 设置每个服务的最大连接数 + * + * @param maxConnectionsPerService + * 每个服务的最大连接数 + */ + public void setMaxConnectionsPerService(Integer maxConnectionsPerService) { + this.maxConnectionsPerService = maxConnectionsPerService; + } + + @Override + protected PoolDataSource createDataSource(final PropertyMapper nullPropertyMapper, + final PropertyMapper hasTextPropertyMapper) { + final PoolDataSource dataSource = new PoolDataSourceImpl(); + + try{ + if(Validate.hasText(this.getNetworkProtocol())){ + dataSource.setNetworkProtocol(this.getNetworkProtocol()); + } + + if(Validate.hasText(this.getUrl())){ + dataSource.setURL(this.getUrl()); + } + if(Validate.hasText(this.getServerName())){ + dataSource.setServerName(this.getServerName()); + } + if(this.getPortNumber() != null){ + dataSource.setPortNumber(this.getPortNumber()); + } + if(Validate.hasText(this.getServiceName())){ + dataSource.setServerName(this.getServiceName()); + } + if(Validate.hasText(this.getDataSourceName())){ + dataSource.setDataSourceName(this.getDataSourceName()); + } + if(Validate.hasText(this.getDataSourceDescription())){ + dataSource.setDescription(this.getDataSourceDescription()); + } + if(Validate.hasText(this.getDatabaseName())){ + dataSource.setDatabaseName(this.getDatabaseName()); + } + if(Validate.hasText(this.getUsername())){ + dataSource.setUser(this.getUsername()); + } + if(Validate.hasText(this.getPassword())){ + dataSource.setPassword(this.getPassword()); + } + + if(this.getLoginTimeout() != null){ + dataSource.setLoginTimeout((int) this.getLoginTimeout().getSeconds()); + } + + if(Validate.hasText(this.getConnectionFactoryClassName())){ + dataSource.setConnectionFactoryClassName(this.getConnectionFactoryClassName()); + } + + if(Validate.hasText(this.getRoleName())){ + dataSource.setRoleName(this.getRoleName()); + } + if(this.getPdbRoles() != null){ + try{ + Method method = dataSource.getClass().getMethod("setPdbRoles", Properties.class); + MethodUtils.setAccessible(method); + method.invoke(dataSource, this.getPdbRoles()); + }catch(NoSuchMethodException e){ + // + }catch(InvocationTargetException e){ + // + }catch(IllegalAccessException e){ + // + } + } + + if(this.isFastConnectionFailoverEnabled() != null){ + dataSource.setFastConnectionFailoverEnabled(this.isFastConnectionFailoverEnabled()); + } + + if(this.getQueryTimeout() != null){ + dataSource.setQueryTimeout((int) this.getQueryTimeout().getSeconds()); + } + + if(Validate.hasText(this.getOnsConfiguration())){ + dataSource.setONSConfiguration(this.getOnsConfiguration()); + } + + if(this.isShardingMode() != null){ + dataSource.setShardingMode(this.isShardingMode()); + } + if(this.getMaxConnectionsPerShard() != null){ + dataSource.setMaxConnectionsPerShard(this.getMaxConnectionsPerShard()); + } + if(this.getMaxConnectionsPerService() != null){ + //dataSource.setMaxConnectionsPerService(); + } + + if(Validate.isNotEmpty(this.getConnectionProperties())){ + dataSource.setConnectionProperties(this.getConnectionProperties()); + } + }catch(SQLException e){ + logger.error("OracleDataSource set error: {}.", e.getMessage(), e); + } + + return dataSource; + } + + @Override + protected void applyPoolConfiguration(final oracle.ucp.jdbc.PoolDataSource dataSource, + final OraclePoolConfiguration poolConfiguration, + final PropertyMapper nullPropertyMapper, + final PropertyMapper hasTextPropertyMapper) { + try{ + if(poolConfiguration.getPoolName() != null){ + dataSource.setConnectionPoolName(poolConfiguration.getPoolName()); + } + + if(poolConfiguration.getInitialPoolSize() != null){ + dataSource.setInitialPoolSize(poolConfiguration.getInitialPoolSize()); + } + if(poolConfiguration.getMinIdle() != null){ + dataSource.setMinIdle(poolConfiguration.getMinIdle()); + } + if(poolConfiguration.getMinPoolSize() != null){ + dataSource.setMinPoolSize(poolConfiguration.getMinPoolSize()); + } + if(poolConfiguration.getMaxPoolSize() != null){ + dataSource.setMaxPoolSize(poolConfiguration.getMaxPoolSize()); + } + + if(poolConfiguration.isValidateConnectionOnBorrow() != null){ + dataSource.setValidateConnectionOnBorrow(poolConfiguration.isValidateConnectionOnBorrow()); + } + + if(Validate.hasText(poolConfiguration.getSqlForValidateConnection())){ + dataSource.setSQLForValidateConnection(poolConfiguration.getSqlForValidateConnection()); + } + if(poolConfiguration.getConnectionValidationTimeout() != null){ + dataSource.setConnectionValidationTimeout( + (int) poolConfiguration.getConnectionValidationTimeout().getSeconds()); + } + + if(poolConfiguration.isCreateConnectionInBorrowThread() != null){ + dataSource.setCreateConnectionInBorrowThread(poolConfiguration.isCreateConnectionInBorrowThread()); + } + + if(poolConfiguration.getConnectionWait() != null){ + dataSource.setConnectionWaitDuration(poolConfiguration.getConnectionWait()); + } + + if(poolConfiguration.getTimeoutCheckInterval() != null){ + dataSource.setTimeoutCheckInterval((int) poolConfiguration.getTimeoutCheckInterval().getSeconds()); + } + + if(poolConfiguration.getInactiveConnectionTimeout() != null){ + dataSource.setInactiveConnectionTimeout( + (int) poolConfiguration.getInactiveConnectionTimeout().getSeconds()); + } + if(poolConfiguration.getTimeToLiveConnectionTimeout() != null){ + dataSource.setTimeToLiveConnectionTimeout( + (int) poolConfiguration.getTimeToLiveConnectionTimeout().getSeconds()); + } + + if(poolConfiguration.getTrustIdleConnection() != null){ + dataSource.setSecondsToTrustIdleConnection( + (int) poolConfiguration.getTrustIdleConnection().getSeconds()); + } + if(poolConfiguration.getMaxConnectionReuseTime() != null){ + dataSource.setMaxConnectionReuseTime(poolConfiguration.getMaxConnectionReuseTime().toMillis()); + } + + if(poolConfiguration.getConnectionLabelingHighCost() != null){ + dataSource.setConnectionLabelingHighCost( + (int) poolConfiguration.getConnectionLabelingHighCost().toMillis()); + } + if(poolConfiguration.getHighCostConnectionReuseThreshold() != null){ + dataSource.setHighCostConnectionReuseThreshold(poolConfiguration.getHighCostConnectionReuseThreshold()); + } + if(poolConfiguration.getConnectionRepurposeThreshold() != null){ + dataSource.setConnectionRepurposeThreshold(poolConfiguration.getConnectionRepurposeThreshold()); + } + + if(poolConfiguration.getConnectionHarvestTriggerCount() != null){ + dataSource.setConnectionHarvestTriggerCount(poolConfiguration.getConnectionHarvestTriggerCount()); + } + if(poolConfiguration.getConnectionHarvestMaxCount() != null){ + dataSource.setConnectionHarvestMaxCount(poolConfiguration.getConnectionHarvestMaxCount()); + } + + if(poolConfiguration.getMaxStatements() != null){ + dataSource.setMaxStatements(poolConfiguration.getMaxStatements()); + } + + if(poolConfiguration.isReadOnlyInstanceAllowed() != null){ + dataSource.setReadOnlyInstanceAllowed(poolConfiguration.isReadOnlyInstanceAllowed()); + } + + if(poolConfiguration.getAbandonedConnectionTimeout() != null){ + dataSource.setAbandonedConnectionTimeout( + (int) poolConfiguration.getAbandonedConnectionTimeout().getSeconds()); + } + }catch(SQLException e){ + logger.error("OracleDataSource pool set error: {}.", e.getMessage(), e); + } + } + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/TomcatDataSource.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/TomcatDataSource.java index 292f1c7e8..69568f042 100644 --- a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/TomcatDataSource.java +++ b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/TomcatDataSource.java @@ -19,19 +19,25 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.jdbc.datasource; import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.validator.Validate; +import com.buession.jdbc.core.Jmx; import com.buession.jdbc.core.TransactionIsolation; -import com.buession.jdbc.datasource.config.TomcatPoolConfiguration; +import com.buession.jdbc.datasource.pool.TomcatPoolConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; import java.time.Duration; /** - * Tomcat DataSource 抽象类 + * Tomcat DataSource * * @author Yong.Teng * @since 1.3.2 @@ -39,6 +45,57 @@ public class TomcatDataSource extends AbstractDataSource { + /** + * JNDI 数据源的名称 + * + * @since 3.0.0 + */ + private String jndiName; + + /** + * 是否允许在同一个数据库连接中使用不同的用户名进行身份验证 + * + * @since 3.0.0 + */ + private Boolean alternateUsernameAllowed; + + /** + * 连接归还到池时,设置为自动提交 + * + * @since 3.0.0 + */ + private Boolean commitOnReturn; + + /** + * 连接归还到池时,是否回滚所有操作 + * + * @since 3.0.0 + */ + private Boolean rollbackOnReturn; + + /** + * 实现 {@link org.apache.tomcat.jdbc.pool.Validator} 接口并提供无参构造方法的实现类,用来替代连接验证SQL,对连接进行验证 + * + * @since 3.0.0 + */ + private String validatorClassName; + + /** + * 验证连接时间间隔 + * + * @since 3.0.0 + */ + private Duration validationInterval; + + /** + * JDBC 拦截器,{@link org.apache.tomcat.jdbc.pool.JdbcInterceptor} 的实现 + * + * @since 3.0.0 + */ + private String jdbcInterceptors; + + private final static Logger logger = LoggerFactory.getLogger(TomcatDataSource.class); + /** * 构造函数 */ @@ -160,78 +217,311 @@ public TomcatDataSource(String driverClassName, String url, String username, Str super(driverClassName, url, username, password, poolConfiguration); } + /** + * 返回 JNDI 数据源的名称 + * + * @return JNDI 数据源的名称 + * + * @since 3.0.0 + */ + public String getJndiName() { + return jndiName; + } + + /** + * 设置 JNDI 数据源的名称 + * + * @param jndiName + * JNDI 数据源的名称 + * + * @since 3.0.0 + */ + public void setJndiName(String jndiName) { + this.jndiName = jndiName; + } + + /** + * 返回是否允许在同一个数据库连接中使用不同的用户名进行身份验证 + * + * @return 是否允许在同一个数据库连接中使用不同的用户名进行身份验证 + * + * @since 3.0.0 + */ + public Boolean isAlternateUsernameAllowed() { + return getAlternateUsernameAllowed(); + } + + /** + * 返回是否允许在同一个数据库连接中使用不同的用户名进行身份验证 + * + * @return 是否允许在同一个数据库连接中使用不同的用户名进行身份验证 + * + * @since 3.0.0 + */ + public Boolean getAlternateUsernameAllowed() { + return alternateUsernameAllowed; + } + + /** + * 设置是否允许在同一个数据库连接中使用不同的用户名进行身份验证 + * + * @param alternateUsernameAllowed + * 是否允许在同一个数据库连接中使用不同的用户名进行身份验证 + * + * @since 3.0.0 + */ + public void setAlternateUsernameAllowed(Boolean alternateUsernameAllowed) { + this.alternateUsernameAllowed = alternateUsernameAllowed; + } + + /** + * 返回连接归还到池时,设置为自动提交 + * + * @return 连接归还到池时,设置为自动提交 + * + * @since 3.0.0 + */ + public Boolean isCommitOnReturn() { + return getCommitOnReturn(); + } + + /** + * 返回连接归还到池时,设置为自动提交 + * + * @return 连接归还到池时,设置为自动提交 + * + * @since 3.0.0 + */ + public Boolean getCommitOnReturn() { + return commitOnReturn; + } + + /** + * 设置连接归还到池时,是否自动提交 + * + * @param commitOnReturn + * 连接归还到池时,是否自动提交 + * + * @since 3.0.0 + */ + public void setCommitOnReturn(Boolean commitOnReturn) { + this.commitOnReturn = commitOnReturn; + } + + /** + * 返回连接归还到池时,是否回滚所有操作 + * + * @return 连接归还到池时,是否回滚所有操作 + * + * @since 3.0.0 + */ + public Boolean isRollbackOnReturn() { + return getRollbackOnReturn(); + } + + /** + * 返回连接归还到池时,是否回滚所有操作 + * + * @return 连接归还到池时,是否回滚所有操作 + * + * @since 3.0.0 + */ + public Boolean getRollbackOnReturn() { + return rollbackOnReturn; + } + + /** + * 设置连接归还到池时,是否回滚所有操作 + * + * @param rollbackOnReturn + * 连接归还到池时,是否回滚所有操作 + * + * @since 3.0.0 + */ + public void setRollbackOnReturn(Boolean rollbackOnReturn) { + this.rollbackOnReturn = rollbackOnReturn; + } + + /** + * 返回实现 {@link org.apache.tomcat.jdbc.pool.Validator} 接口并提供无参构造方法的实现类,用来替代连接验证SQL,对连接进行验证的类名 + * + * @return 实现 {@link org.apache.tomcat.jdbc.pool.Validator} 接口并提供无参构造方法的实现类,用来替代连接验证SQL,对连接进行验证的类名 + * + * @since 3.0.0 + */ + public String getValidatorClassName() { + return validatorClassName; + } + + /** + * 设置实现 {@link org.apache.tomcat.jdbc.pool.Validator} 接口并提供无参构造方法的实现类,用来替代连接验证SQL,对连接进行验证的类名 + * + * @param validatorClassName + * 实现 {@link org.apache.tomcat.jdbc.pool.Validator} 接口并提供无参构造方法的实现类,用来替代连接验证SQL,对连接进行验证的类名 + * + * @since 3.0.0 + */ + public void setValidatorClassName(String validatorClassName) { + this.validatorClassName = validatorClassName; + } + + /** + * 返回验证连接时间间隔 + * + * @return 验证连接时间间隔 + * + * @since 3.0.0 + */ + public Duration getValidationInterval() { + return validationInterval; + } + + /** + * 设置验证连接时间间隔 + * + * @param validationInterval + * 验证连接时间间隔 + * + * @since 3.0.0 + */ + public void setValidationInterval(Duration validationInterval) { + this.validationInterval = validationInterval; + } + + /** + * 返回 JDBC 拦截器,{@link org.apache.tomcat.jdbc.pool.JdbcInterceptor} 的实现 + * + * @return JDBC 拦截器 + * + * @since 3.0.0 + */ + public String getJdbcInterceptors() { + return jdbcInterceptors; + } + + /** + * 设置 JDBC 拦截器,{@link org.apache.tomcat.jdbc.pool.JdbcInterceptor} 的实现 + * + * @param jdbcInterceptors + * JDBC 拦截器 + * + * @since 3.0.0 + */ + public void setJdbcInterceptors(String jdbcInterceptors) { + this.jdbcInterceptors = jdbcInterceptors; + } + @Override - public org.apache.tomcat.jdbc.pool.DataSource createDataSource() { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); + protected org.apache.tomcat.jdbc.pool.DataSource createDataSource(final PropertyMapper nullPropertyMapper, + final PropertyMapper hasTextPropertyMapper) { final org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource(); - propertyMapper.from(this::getDriverClassName).to(dataSource::setDriverClassName); - propertyMapper.from(this::getUrl).to(dataSource::setUrl); - propertyMapper.from(this::getUsername).to(dataSource::setUsername); - propertyMapper.from(this::getPassword).to(dataSource::setPassword); + hasTextPropertyMapper.from(this::getDriverClassName).to(dataSource::setDriverClassName); + + hasTextPropertyMapper.from(this::getJndiName).to(dataSource::setDataSourceJNDI); + hasTextPropertyMapper.from(this::getUrl).to(dataSource::setUrl); + hasTextPropertyMapper.from(this::getUsername).to(dataSource::setUsername); + hasTextPropertyMapper.from(this::getPassword).to(dataSource::setPassword); - initialize(dataSource); + nullPropertyMapper.from(this::getLoginTimeout).as((v)->(int) v.getSeconds()).to(dataSource::setLoginTimeout); + + hasTextPropertyMapper.from(this::getDefaultCatalog).to(dataSource::setDefaultCatalog); + + hasTextPropertyMapper.from(this::getInitSQL).to(dataSource::setInitSQL); + + hasTextPropertyMapper.from(this::getValidatorClassName).to(dataSource::setValidatorClassName); + nullPropertyMapper.from(this::getValidationInterval).as(Duration::toMillis) + .to(dataSource::setValidationInterval); + + nullPropertyMapper.from(this::getDefaultTransactionIsolation).as(TransactionIsolation::getValue) + .to(dataSource::setDefaultTransactionIsolation); + nullPropertyMapper.from(this::isDefaultAutoCommit).to(dataSource::setDefaultAutoCommit); + nullPropertyMapper.from(this::isCommitOnReturn).to(dataSource::setCommitOnReturn); + nullPropertyMapper.from(this::isRollbackOnReturn).to(dataSource::setRollbackOnReturn); + + nullPropertyMapper.from(this::isDefaultReadOnly).to(dataSource::setDefaultReadOnly); + + nullPropertyMapper.from(this::isAlternateUsernameAllowed).to(dataSource::setAlternateUsernameAllowed); + nullPropertyMapper.from(this::isAccessToUnderlyingConnectionAllowed) + .to(dataSource::setAccessToUnderlyingConnectionAllowed); + nullPropertyMapper.from(this::getJdbcInterceptors).to(dataSource::setJdbcInterceptors); + + nullPropertyMapper.from(this::getConnectionProperties).to(dataSource::setDbProperties); return dataSource; } @Override protected void applyPoolConfiguration(final org.apache.tomcat.jdbc.pool.DataSource dataSource, - final TomcatPoolConfiguration poolConfiguration) { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - - propertyMapper.from(poolConfiguration::getName).to(dataSource::setName); - propertyMapper.from(poolConfiguration::getDefaultCatalog).to(dataSource::setDefaultCatalog); - propertyMapper.from(poolConfiguration::getInitialSize).to(dataSource::setInitialSize); - propertyMapper.from(poolConfiguration::getMaxActive).to(dataSource::setMaxActive); - propertyMapper.from(poolConfiguration::getMinIdle).to(dataSource::setMinIdle); - propertyMapper.from(poolConfiguration::getMaxIdle).to(dataSource::setMaxIdle); - propertyMapper.from(poolConfiguration::getMaxWait).as((v)->(int) v.getSeconds()).to(dataSource::setMaxWait); - propertyMapper.from(poolConfiguration::getMaxAge).to(dataSource::setMaxAge); - propertyMapper.from(poolConfiguration::getInitSQL).to(dataSource::setInitSQL); - propertyMapper.from(poolConfiguration::getValidationQuery).to(dataSource::setValidationQuery); - propertyMapper.from(poolConfiguration::getValidationInterval).as(Duration::toMillis) - .to(dataSource::setValidationInterval); - propertyMapper.from(poolConfiguration::getValidationQueryTimeout).as((v)->(int) v.getSeconds()) + final TomcatPoolConfiguration poolConfiguration, + final PropertyMapper nullPropertyMapper, + final PropertyMapper hasTextPropertyMapper) { + hasTextPropertyMapper.from(poolConfiguration::getPoolName).to(dataSource::setName); + + nullPropertyMapper.from(poolConfiguration::getInitialSize).to(dataSource::setInitialSize); + nullPropertyMapper.from(poolConfiguration::getMinIdle).to(dataSource::setMinIdle); + nullPropertyMapper.from(poolConfiguration::getMaxIdle).to(dataSource::setMaxIdle); + nullPropertyMapper.from(poolConfiguration::getMaxActive).to(dataSource::setMaxActive); + + nullPropertyMapper.from(poolConfiguration::getMaxWait).as((v)->(int) v.toMillis()).to(dataSource::setMaxWait); + + nullPropertyMapper.from(poolConfiguration::isTestOnConnect).to(dataSource::setTestOnConnect); + nullPropertyMapper.from(poolConfiguration::isTestOnBorrow).to(dataSource::setTestOnBorrow); + nullPropertyMapper.from(poolConfiguration::isTestOnReturn).to(dataSource::setTestOnReturn); + nullPropertyMapper.from(poolConfiguration::isTestWhileIdle).to(dataSource::setTestWhileIdle); + + hasTextPropertyMapper.from(poolConfiguration::getValidationQuery).to(dataSource::setValidationQuery); + nullPropertyMapper.from(poolConfiguration::getValidationQueryTimeout).as((v)->(int) v.getSeconds()) .to(dataSource::setValidationQueryTimeout); - propertyMapper.from(poolConfiguration::getValidatorClassName).to(dataSource::setValidatorClassName); - propertyMapper.from(poolConfiguration::getLogValidationErrors).to(dataSource::setLogValidationErrors); - propertyMapper.from(poolConfiguration::getTestOnConnect).to(dataSource::setTestOnConnect); - propertyMapper.from(poolConfiguration::getTestOnBorrow).to(dataSource::setTestOnBorrow); - propertyMapper.from(poolConfiguration::getTestOnReturn).to(dataSource::setTestOnReturn); - propertyMapper.from(poolConfiguration::getTestWhileIdle).to(dataSource::setTestWhileIdle); - propertyMapper.from(poolConfiguration::getTimeBetweenEvictionRuns).as((v)->(int) v.getSeconds()) - .to(dataSource::setTimeBetweenEvictionRunsMillis); - propertyMapper.from(poolConfiguration::getNumTestsPerEvictionRun).to(dataSource::setNumTestsPerEvictionRun); - propertyMapper.from(poolConfiguration::getMinEvictableIdleTime).as((v)->(int) v.getSeconds()) + + nullPropertyMapper.from(poolConfiguration::getMaxAge).as(Duration::toMillis).to(dataSource::setMaxAge); + + nullPropertyMapper.from(poolConfiguration::getMinEvictableIdle).as((v)->(int) v.toMillis()) .to(dataSource::setMinEvictableIdleTimeMillis); - propertyMapper.from(poolConfiguration::getDefaultTransactionIsolation).as(TransactionIsolation::getValue) - .to(dataSource::setDefaultTransactionIsolation); - propertyMapper.from(poolConfiguration::getDefaultAutoCommit).to(dataSource::setDefaultAutoCommit); - propertyMapper.from(poolConfiguration::getCommitOnReturn).to(dataSource::setCommitOnReturn); - propertyMapper.from(poolConfiguration::getRollbackOnReturn).to(dataSource::setRollbackOnReturn); - propertyMapper.from(poolConfiguration::getDefaultReadOnly).to(dataSource::setDefaultReadOnly); - propertyMapper.from(poolConfiguration::getRemoveAbandoned).to(dataSource::setRemoveAbandoned); - propertyMapper.from(poolConfiguration::getRemoveAbandonedTimeout).as((v)->(int) v.getSeconds()) + + nullPropertyMapper.from(poolConfiguration::getNumTestsPerEvictionRun).to(dataSource::setNumTestsPerEvictionRun); + nullPropertyMapper.from(poolConfiguration::getTimeBetweenEvictionRuns).as((v)->(int) v.toMillis()) + .to(dataSource::setTimeBetweenEvictionRunsMillis); + + nullPropertyMapper.from(poolConfiguration::isUseDisposableConnectionFacade) + .to(dataSource::setUseDisposableConnectionFacade); + + nullPropertyMapper.from(poolConfiguration::isUseStatementFacade).to(dataSource::setUseStatementFacade); + + nullPropertyMapper.from(poolConfiguration::getSuspectTimeout).as((v)->(int) v.getSeconds()) + .to(dataSource::setSuspectTimeout); + + nullPropertyMapper.from(poolConfiguration::isRemoveAbandoned).to(dataSource::setRemoveAbandoned); + nullPropertyMapper.from(poolConfiguration::getRemoveAbandonedTimeout).as((v)->(int) v.getSeconds()) .to(dataSource::setRemoveAbandonedTimeout); - propertyMapper.from(poolConfiguration::getLogAbandoned).to(dataSource::setLogAbandoned); - propertyMapper.from(poolConfiguration::getAbandonWhenPercentageFull) + nullPropertyMapper.from(poolConfiguration::isLogAbandoned).to(dataSource::setLogAbandoned); + nullPropertyMapper.from(poolConfiguration::getAbandonWhenPercentageFull) .to(dataSource::setAbandonWhenPercentageFull); - propertyMapper.from(poolConfiguration::getSuspectTimeout).as((v)->(int) v.getSeconds()) - .to(dataSource::setSuspectTimeout); - propertyMapper.from(poolConfiguration::getAlternateUsernameAllowed).to(dataSource::setAlternateUsernameAllowed); - propertyMapper.from(poolConfiguration::getJdbcInterceptors).to(dataSource::setJdbcInterceptors); - propertyMapper.from(poolConfiguration::getIgnoreExceptionOnPreLoad).to(dataSource::setIgnoreExceptionOnPreLoad); - propertyMapper.from(poolConfiguration::getUseEquals).to(dataSource::setUseEquals); - propertyMapper.from(poolConfiguration::getUseLock).to(dataSource::setUseLock); - propertyMapper.from(poolConfiguration::getFairQueue).to(dataSource::setFairQueue); - propertyMapper.from(poolConfiguration::getUseDisposableConnectionFacade) - .to(dataSource::setUseDisposableConnectionFacade); - propertyMapper.from(poolConfiguration::getPropagateInterruptState).to(dataSource::setPropagateInterruptState); - propertyMapper.from(poolConfiguration::getUseStatementFacade).to(dataSource::setUseStatementFacade); - propertyMapper.from(poolConfiguration::getAccessToUnderlyingConnectionAllowed) - .to(dataSource::setAccessToUnderlyingConnectionAllowed); - propertyMapper.from(poolConfiguration::getJmxEnabled).to(dataSource::setJmxEnabled); + + nullPropertyMapper.from(poolConfiguration::isIgnoreExceptionOnPreLoad) + .to(dataSource::setIgnoreExceptionOnPreLoad); + nullPropertyMapper.from(poolConfiguration::isFairQueue).to(dataSource::setFairQueue); + nullPropertyMapper.from(poolConfiguration::isPropagateInterruptState) + .to(dataSource::setPropagateInterruptState); + nullPropertyMapper.from(poolConfiguration::isLogValidationErrors).to(dataSource::setLogValidationErrors); + nullPropertyMapper.from(poolConfiguration::isUseLock).to(dataSource::setUseLock); + nullPropertyMapper.from(poolConfiguration::isUseEquals).to(dataSource::setUseEquals); + + if(poolConfiguration.getJmx() != null){ + final Jmx jmx = poolConfiguration.getJmx(); + + nullPropertyMapper.from(jmx::isEnabled).to(dataSource::setJmxEnabled); + + if(Validate.hasText(jmx.getName())){ + try{ + dataSource.createObjectName(new ObjectName(jmx.getName())); + }catch(MalformedObjectNameException e){ + if(logger.isErrorEnabled()){ + logger.error("create {} instance error: {}", ObjectName.class.getName(), e.getMessage()); + } + } + } + } if(Boolean.TRUE.equals(poolConfiguration.getFairQueue()) && "Linux".equalsIgnoreCase(System.getProperties().getProperty("os.name"))){ diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/Dbcp2PoolConfiguration.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/Dbcp2PoolConfiguration.java deleted file mode 100644 index 4efb6be2c..000000000 --- a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/Dbcp2PoolConfiguration.java +++ /dev/null @@ -1,1046 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. - * See the NOTICE file distributed with this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - * - * ========================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +-------------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | - * +-------------------------------------------------------------------------------------------------------+ - */ -package com.buession.jdbc.datasource.config; - -import com.buession.jdbc.core.TransactionIsolation; -import org.apache.commons.dbcp2.BasicDataSource; - -import java.time.Duration; -import java.util.Collection; -import java.util.Set; - -/** - * Dhcp2 数据源连接池配置 {@link BasicDataSource} - * - * @author Yong.Teng - * @since 1.3.2 - */ -public class Dbcp2PoolConfiguration extends AbstractPoolConfiguration { - - /** - * 为支持 catalog 概念的数据库设置默认 catalog - */ - private String defaultCatalog; - - /** - * 连接的最大存活时间; - * 如果超过这个时间,则连接在下次激活、钝化、校验时都将会失败。如果设置为0或小于0的值,则连接的存活时间是无限的 - */ - private Duration maxConnLifetime; - - /** - * 查询超时时间 - */ - private Duration defaultQueryTimeout; - - /** - * 初始连接数,池被启动时初始化的创建的连接个数 - */ - private Integer initialSize; - - /** - * 最小空闲连接数,可以在池中保持空闲的最小连接数,低于设置值时,空闲连接将被创建,以努力保持最小空闲连接数 >= minIdle - */ - private Integer minIdle; - - /** - * 最大空闲连接数,在池中,可以保持空闲状态的最大连接数,超出设置值之外的空闲连接在归还到连接池时将被释放,如设置为负数,则不限制 - */ - private Integer maxIdle; - - /** - * 最大活动连接数,可以在这个池中同一时刻被分配的有效连接数的最大值,如设置为负数,则不限制 - */ - private Integer maxTotal; - - /** - * 从连接池获取一个连接时,最大的等待时间,设置为-1时,如果没有可用连接,连接池会一直无限期等待,直到获取到连接为止 - */ - private Duration maxWait; - - /** - * 连接创建后,马上验证有效性; - * 指明对象在创建后是否需要验证是否有效,如果对象验证失败,则触发对象创建的租借尝试将失败 - */ - private Boolean testOnCreate; - - /** - * 从连接池获取一个连接时,验证有效性; - * 指明在从池中租借对象时是否要进行验证有效,如果对象验证失败,则对象将从池子释放,然后我们将尝试租借另一个 - */ - private Boolean testOnBorrow; - - /** - * 连接被归还到连接池时,验证有效性 - */ - private Boolean testOnReturn; - - /** - * 连接空闲时,验证有效性; - * 指明对象是否需要通过对象驱逐者进行校验(如果有的话),假如一个对象验证失败,则对象将被从池中释放 - */ - private Boolean testWhileIdle; - - /** - * 实现 {@link org.apache.commons.dbcp2.ConnectionFactory} 接口,连接工厂实现类 - */ - private String connectionFactoryClassName; - - /** - * 在第一次创建时用来初始化物理连接的SQL语句集合,只在配置的连接工厂创建连接时被执行一次 - */ - private Collection connectionInitSqls; - - /** - * 设置一个SQL语句, 从连接池获取连接时, 先执行改 sql, 验证连接是否可用 - */ - private String validationQuery; - - /** - * 连接有效SQL的执行查询超时时间 - */ - private Duration validationQueryTimeout; - - /** - * 设置的默认模式为支持模式的概念数据库 - */ - private String defaultSchema; - - /** - * 默认事务隔离级别 - */ - private TransactionIsolation defaultTransactionIsolation = TransactionIsolation.DEFAULT; - - /** - * 默认是否自动提交事务 - */ - private Boolean defaultAutoCommit; - - /** - * 连接归还到池时,设置为自动提交 - */ - private Boolean autoCommitOnReturn; - - /** - * 连接归还到池时,是否回滚所有操作 - */ - private Boolean rollbackOnReturn; - - /** - * 默认连接是否是只读模式 - */ - private Boolean defaultReadOnly; - - /** - * 一个过期的连接被连接池关闭时,写日志标识; - * 如果连接存货时间超过 maxConnLifetimeMillis,连接将被连接池会抽,此时默认输出日志 - */ - private Boolean logExpiredConnections = true; - - /** - * PoolGuard 是否可以访问底层连接 - */ - private Boolean accessToUnderlyingConnectionAllowed; - - /** - * 缓存状态,如果设置为true, - * 池化的连接将在第一次读或写,以及随后的写的时候缓存当前的只读状态和自动提交设置。 - * 这样就省去了对 getter 的任何进一步的调用时对数据库的额外查询。 - * 如果直接访问底层连接,只读状态和/或自动提交设置改变缓存值将不会被反映到当前的状态,在这种情况下,应该将该属性设置为false以禁用缓存 - */ - private Boolean cacheState = true; - - /** - * 该连接池的预处理语句池是否生效 - */ - private Boolean poolPreparedStatements; - - /** - * 可以在语句池中同时分配的最大语句数 - */ - private Integer maxOpenPreparedStatements; - - private Boolean clearStatementPoolOnReturn; - - /** - * 空闲对象驱逐策略名称 - */ - private String evictionPolicyClassName; - - /** - * 空闲对象驱逐线程运行时的休眠时间 - */ - private Duration timeBetweenEvictionRuns; - - /** - * 在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 - */ - private Integer numTestsPerEvictionRun; - - /** - * 空闲的连接被释放最低要待时间 - */ - private Duration minEvictableIdleTime; - - /** - * 空闲的连接被释放最低要待时间,但有额外条件 - * 额外的条件是池中至少保留有 minIdle 所指定的个数的连接; - * 当 miniEvictableIdleTime 被设置为一个正数,空闲连接驱逐者首先检测 miniEvictableIdleTime , - * 当空闲连接被驱逐者访问时,首先与 miniEvictableIdleTime 所指定的值进行比较(而不考虑当前池中的空闲连接数), - * 然后比较 softMinEvictableIdleTime 所指定的连接数,包括 minIdle 条件 - */ - private Duration softMinEvictableIdleTime; - - /** - * 后进先出,设置为true表明连接池(如果池中有可用的空闲连接时)将返回最后一次使用的租借对象(最后进入), - * 设置为false则表明池将表现为FIFO队列(先进先出)—将会按照它们被归还的顺序从空闲连接实例池中获取连接 - */ - private Boolean lifo; - - /** - * 验证快速失败 - */ - private Boolean fastFailValidation; - - private Set disconnectionSqlCodes; - - private String jmxName; - - /** - * 返回为支持 catalog 概念的数据库设置默认 catalog - * - * @return 为支持 catalog 概念的数据库设置默认 catalog - */ - public String getDefaultCatalog(){ - return defaultCatalog; - } - - /** - * 设置为支持 catalog 概念的数据库设置默认 catalog - * - * @param defaultCatalog - * 为支持 catalog 概念的数据库设置默认 catalog - */ - public void setDefaultCatalog(String defaultCatalog){ - this.defaultCatalog = defaultCatalog; - } - - /** - * 返回连接的最大存活时间 - * - * @return 连接的最大存活时间 - */ - public Duration getMaxConnLifetime(){ - return maxConnLifetime; - } - - /** - * 设置连接的最大存活时间 - * - * @param maxConnLifetime - * 连接的最大存活时间 - */ - public void setMaxConnLifetime(Duration maxConnLifetime){ - this.maxConnLifetime = maxConnLifetime; - } - - /** - * 返回查询超时时间 - * - * @return 查询超时时间 - */ - public Duration getDefaultQueryTimeout(){ - return defaultQueryTimeout; - } - - /** - * 设置查询超时时间 - * - * @param defaultQueryTimeout - * 查询超时时间 - */ - public void setDefaultQueryTimeout(Duration defaultQueryTimeout){ - this.defaultQueryTimeout = defaultQueryTimeout; - } - - /** - * 返回初始连接数 - * - * @return 初始连接数 - */ - public Integer getInitialSize(){ - return initialSize; - } - - /** - * 设置初始连接数 - * - * @param initialSize - * 初始连接数 - */ - public void setInitialSize(Integer initialSize){ - this.initialSize = initialSize; - } - - /** - * 返回最小空闲连接数 - * - * @return 最小空闲连接数 - */ - public Integer getMinIdle(){ - return minIdle; - } - - /** - * 设置最小空闲连接数 - * - * @param minIdle - * 最小空闲连接数 - */ - public void setMinIdle(Integer minIdle){ - this.minIdle = minIdle; - } - - /** - * 返回最大空闲连接数 - * - * @return 最大空闲连接数 - */ - public Integer getMaxIdle(){ - return maxIdle; - } - - /** - * 设置最大空闲连接数,如设置为负数,则不限制 - * - * @param maxIdle - * 最大空闲连接数 - */ - public void setMaxIdle(Integer maxIdle){ - this.maxIdle = maxIdle; - } - - /** - * 返回最大活动连接数 - * - * @return 最大活动连接数 - */ - public Integer getMaxTotal(){ - return maxTotal; - } - - /** - * 设置最大活动连接数,如设置为负数,则不限制 - * - * @param maxTotal - * 最大活动连接数 - */ - public void setMaxTotal(Integer maxTotal){ - this.maxTotal = maxTotal; - } - - /** - * 返回从连接池获取一个连接时,最大的等待时间 - * - * @return 从连接池获取一个连接时,最大的等待时间 - */ - public Duration getMaxWait(){ - return maxWait; - } - - /** - * 设置从连接池获取一个连接时,最大的等待时间 - * - * @param maxWait - * 从连接池获取一个连接时,最大的等待时间 - */ - public void setMaxWait(Duration maxWait){ - this.maxWait = maxWait; - } - - /** - * 返回连接创建后,是否马上验证有效性 - * - * @return 连接创建后,是否马上验证有效性 - */ - @Deprecated - public Boolean isTestOnCreate(){ - return getTestOnCreate(); - } - - /** - * 返回连接创建后,是否马上验证有效性 - * - * @return 连接创建后,是否马上验证有效性 - */ - public Boolean getTestOnCreate(){ - return testOnCreate; - } - - /** - * 设置连接创建后,是否马上验证有效性 - * - * @param testOnCreate - * 连接创建后,是否马上验证有效性 - */ - public void setTestOnCreate(Boolean testOnCreate){ - this.testOnCreate = testOnCreate; - } - - /** - * 返回从连接池获取一个连接时,是否验证有效性 - * - * @return 从连接池获取一个连接时,验证有效性 - */ - @Deprecated - public Boolean isTestOnBorrow(){ - return getTestOnBorrow(); - } - - /** - * 返回从连接池获取一个连接时,是否验证有效性 - * - * @return 从连接池获取一个连接时,验证有效性 - */ - public Boolean getTestOnBorrow(){ - return testOnBorrow; - } - - /** - * 设置从连接池获取一个连接时,是否验证有效性 - * - * @param testOnBorrow - * 从连接池获取一个连接时,是否验证有效性 - */ - public void setTestOnBorrow(Boolean testOnBorrow){ - this.testOnBorrow = testOnBorrow; - } - - /** - * 返回连接被归还到连接池时,是否验证有效性 - * - * @return 连接被归还到连接池时,是否验证有效性 - */ - @Deprecated - public Boolean isTestOnReturn(){ - return getTestOnReturn(); - } - - /** - * 返回连接被归还到连接池时,是否验证有效性 - * - * @return 连接被归还到连接池时,是否验证有效性 - */ - public Boolean getTestOnReturn(){ - return testOnReturn; - } - - /** - * 设置连接被归还到连接池时,是否验证有效性 - * - * @param testOnReturn - * 连接被归还到连接池时,是否验证有效性 - */ - public void setTestOnReturn(Boolean testOnReturn){ - this.testOnReturn = testOnReturn; - } - - /** - * 返回连接空闲时,是否验证有效性 - * - * @return 连接空闲时,是否验证有效性 - */ - @Deprecated - public Boolean isTestWhileIdle(){ - return getTestWhileIdle(); - } - - /** - * 返回连接空闲时,是否验证有效性 - * - * @return 连接空闲时,是否验证有效性 - */ - public Boolean getTestWhileIdle(){ - return testWhileIdle; - } - - /** - * 设置连接空闲时,是否验证有效性 - * - * @param testWhileIdle - * 连接空闲时,是否验证有效性 - */ - public void setTestWhileIdle(Boolean testWhileIdle){ - this.testWhileIdle = testWhileIdle; - } - - /** - * 返回 {@link org.apache.commons.dbcp2.ConnectionFactory} 接口实现,连接工厂实现 - * - * @return {@link org.apache.commons.dbcp2.ConnectionFactory} 接口实现,连接工厂实现类 - */ - public String getConnectionFactoryClassName(){ - return connectionFactoryClassName; - } - - /** - * 设置{@link org.apache.commons.dbcp2.ConnectionFactory} 接口实现,连接工厂实现类 - * - * @param connectionFactoryClassName - * {@link org.apache.commons.dbcp2.ConnectionFactory} 接口实现,连接工厂实现类 - */ - public void setConnectionFactoryClassName(String connectionFactoryClassName){ - this.connectionFactoryClassName = connectionFactoryClassName; - } - - /** - * 返回在第一次创建时用来初始化物理连接的SQL语句集合 - * - * @return 在第一次创建时用来初始化物理连接的SQL语句集合 - */ - public Collection getConnectionInitSqls(){ - return connectionInitSqls; - } - - /** - * 设置在第一次创建时用来初始化物理连接的SQL语句集合 - * - * @param connectionInitSqls - * 在第一次创建时用来初始化物理连接的SQL语句集合 - */ - public void setConnectionInitSqls(Collection connectionInitSqls){ - this.connectionInitSqls = connectionInitSqls; - } - - /** - * 返回从连接池获取连接时, 验证连接是否可用的SQL语句 - * - * @return 从连接池获取连接时, 验证连接是否可用的SQL语句 - */ - public String getValidationQuery(){ - return validationQuery; - } - - /** - * 设置从连接池获取连接时, 验证连接是否可用的SQL语句 - * - * @param validationQuery - * 从连接池获取连接时, 验证连接是否可用的SQL语句 - */ - public void setValidationQuery(String validationQuery){ - this.validationQuery = validationQuery; - } - - /** - * 返回连接有效SQL的执行查询超时时间 - * - * @return 连接有效SQL的执行查询超时时间 - */ - public Duration getValidationQueryTimeout(){ - return validationQueryTimeout; - } - - /** - * 设置连接有效SQL的执行查询超时时间 - * - * @param validationQueryTimeout - * 连接有效SQL的执行查询超时时间 - */ - public void setValidationQueryTimeout(Duration validationQueryTimeout){ - this.validationQueryTimeout = validationQueryTimeout; - } - - /** - * 返回设置的默认模式为支持模式的概念数据库 - * - * @return 设置的默认模式为支持模式的概念数据库 - */ - public String getDefaultSchema(){ - return defaultSchema; - } - - /** - * 设置默认模式为支持模式的概念数据库 - * - * @param defaultSchema - * 默认模式为支持模式的概念数据库 - */ - public void setDefaultSchema(String defaultSchema){ - this.defaultSchema = defaultSchema; - } - - /** - * 返回默认事务隔离级别 - * - * @return 默认事务隔离级别 - */ - public TransactionIsolation getDefaultTransactionIsolation(){ - return defaultTransactionIsolation; - } - - /** - * 设置默认事务隔离级别 - * - * @param defaultTransactionIsolation - * 默认事务隔离级别 - */ - public void setDefaultTransactionIsolation(TransactionIsolation defaultTransactionIsolation){ - this.defaultTransactionIsolation = defaultTransactionIsolation; - } - - /** - * 返回是否自动提交事务 - * - * @return 是否自动提交事务 - */ - @Deprecated - public Boolean isDefaultAutoCommit(){ - return getDefaultAutoCommit(); - } - - /** - * 返回是否自动提交事务 - * - * @return 是否自动提交事务 - */ - public Boolean getDefaultAutoCommit(){ - return defaultAutoCommit; - } - - /** - * 设置是否自动提交事务 - * - * @param defaultAutoCommit - * 是否自动提交事务 - */ - public void setDefaultAutoCommit(Boolean defaultAutoCommit){ - this.defaultAutoCommit = defaultAutoCommit; - } - - /** - * 返回连接归还到池时,设置为自动提交 - * - * @return 连接归还到池时,设置为自动提交 - */ - @Deprecated - public Boolean isAutoCommitOnReturn(){ - return getAutoCommitOnReturn(); - } - - /** - * 返回连接归还到池时,设置为自动提交 - * - * @return 连接归还到池时,设置为自动提交 - */ - public Boolean getAutoCommitOnReturn(){ - return autoCommitOnReturn; - } - - /** - * 设置连接归还到池时,是否自动提交 - * - * @param autoCommitOnReturn - * 连接归还到池时,是否自动提交 - */ - public void setAutoCommitOnReturn(Boolean autoCommitOnReturn){ - this.autoCommitOnReturn = autoCommitOnReturn; - } - - /** - * 返回连接归还到池时,是否回滚所有操作 - * - * @return 连接归还到池时,是否回滚所有操作 - */ - @Deprecated - public Boolean isRollbackOnReturn(){ - return getRollbackOnReturn(); - } - - /** - * 返回连接归还到池时,是否回滚所有操作 - * - * @return 连接归还到池时,是否回滚所有操作 - */ - public Boolean getRollbackOnReturn(){ - return rollbackOnReturn; - } - - /** - * 设置连接归还到池时,是否回滚所有操作 - * - * @param rollbackOnReturn - * 连接归还到池时,是否回滚所有操作 - */ - public void setRollbackOnReturn(Boolean rollbackOnReturn){ - this.rollbackOnReturn = rollbackOnReturn; - } - - /** - * 返回连接是否是只读模式 - * - * @return 连接是否是只读模式 - */ - @Deprecated - public Boolean isDefaultReadOnly(){ - return getDefaultReadOnly(); - } - - /** - * 返回连接是否是只读模式 - * - * @return 连接是否是只读模式 - */ - public Boolean getDefaultReadOnly(){ - return defaultReadOnly; - } - - /** - * 设置连接是否是只读模式 - * - * @param defaultReadOnly - * 连接是否是只读模式 - */ - public void setDefaultReadOnly(Boolean defaultReadOnly){ - this.defaultReadOnly = defaultReadOnly; - } - - /** - * 返回一个过期的连接被连接池关闭时,写日志标识 - * - * @return 一个过期的连接被连接池关闭时,写日志标识 - */ - @Deprecated - public Boolean isLogExpiredConnections(){ - return getLogExpiredConnections(); - } - - /** - * 返回一个过期的连接被连接池关闭时,写日志标识 - * - * @return 一个过期的连接被连接池关闭时,写日志标识 - */ - public Boolean getLogExpiredConnections(){ - return logExpiredConnections; - } - - /** - * 设置一个过期的连接被连接池关闭时,写日志标识 - * - * @param logExpiredConnections - * 一个过期的连接被连接池关闭时,写日志标识 - */ - public void setLogExpiredConnections(Boolean logExpiredConnections){ - this.logExpiredConnections = logExpiredConnections; - } - - /** - * 返回 PoolGuard 是否可以访问底层连接 - * - * @return PoolGuard 是否可以访问底层连接 - */ - @Deprecated - public Boolean isAccessToUnderlyingConnectionAllowed(){ - return getAccessToUnderlyingConnectionAllowed(); - } - - /** - * 返回 PoolGuard 是否可以访问底层连接 - * - * @return PoolGuard 是否可以访问底层连接 - */ - public Boolean getAccessToUnderlyingConnectionAllowed(){ - return accessToUnderlyingConnectionAllowed; - } - - /** - * 设置 PoolGuard 是否可以访问底层连接 - * - * @param accessToUnderlyingConnectionAllowed - * PoolGuard 是否可以访问底层连接 - */ - public void setAccessToUnderlyingConnectionAllowed(Boolean accessToUnderlyingConnectionAllowed){ - this.accessToUnderlyingConnectionAllowed = accessToUnderlyingConnectionAllowed; - } - - /** - * 返回缓存状态 - * - * @return 缓存状态 - */ - @Deprecated - public Boolean isCacheState(){ - return getCacheState(); - } - - /** - * 返回缓存状态 - * - * @return 缓存状态 - */ - public Boolean getCacheState(){ - return cacheState; - } - - /** - * 设置缓存状态 - * - * @param cacheState - * 缓存状态 - */ - public void setCacheState(Boolean cacheState){ - this.cacheState = cacheState; - } - - /** - * 返回该连接池的预处理语句池是否生效 - * - * @return 该连接池的预处理语句池是否生效 - */ - @Deprecated - public Boolean isPoolPreparedStatements(){ - return getPoolPreparedStatements(); - } - - /** - * 返回该连接池的预处理语句池是否生效 - * - * @return 该连接池的预处理语句池是否生效 - */ - public Boolean getPoolPreparedStatements(){ - return poolPreparedStatements; - } - - /** - * 设置该连接池的预处理语句池是否生效 - * - * @param poolPreparedStatements - * 该连接池的预处理语句池是否生效 - */ - public void setPoolPreparedStatements(Boolean poolPreparedStatements){ - this.poolPreparedStatements = poolPreparedStatements; - } - - /** - * 返回可以在语句池中同时分配的最大语句数 - * - * @return 可以在语句池中同时分配的最大语句数 - */ - public Integer getMaxOpenPreparedStatements(){ - return maxOpenPreparedStatements; - } - - /** - * 设置可以在语句池中同时分配的最大语句数 - * - * @param maxOpenPreparedStatements - * 可以在语句池中同时分配的最大语句数 - */ - public void setMaxOpenPreparedStatements(Integer maxOpenPreparedStatements){ - this.maxOpenPreparedStatements = maxOpenPreparedStatements; - } - - /** - * 返回空闲对象驱逐策略名称 - * - * @return 空闲对象驱逐策略名称 - */ - public String getEvictionPolicyClassName(){ - return evictionPolicyClassName; - } - - /** - * 设置空闲对象驱逐策略名称 - * - * @param evictionPolicyClassName - * 空闲对象驱逐策略名称 - */ - public void setEvictionPolicyClassName(String evictionPolicyClassName){ - this.evictionPolicyClassName = evictionPolicyClassName; - } - - @Deprecated - public Boolean isClearStatementPoolOnReturn(){ - return getClearStatementPoolOnReturn(); - } - - public Boolean getClearStatementPoolOnReturn(){ - return clearStatementPoolOnReturn; - } - - public void setClearStatementPoolOnReturn(Boolean clearStatementPoolOnReturn){ - this.clearStatementPoolOnReturn = clearStatementPoolOnReturn; - } - - /** - * 返回空闲对象驱逐线程运行时的休眠时间 - * - * @return 空闲对象驱逐线程运行时的休眠时间 - */ - public Duration getTimeBetweenEvictionRuns(){ - return timeBetweenEvictionRuns; - } - - /** - * 设置空闲对象驱逐线程运行时的休眠时间 - * - * @param timeBetweenEvictionRuns - * 空闲对象驱逐线程运行时的休眠时间 - */ - public void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns){ - this.timeBetweenEvictionRuns = timeBetweenEvictionRuns; - } - - /** - * 返回在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 - * - * @return 在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 - */ - public Integer getNumTestsPerEvictionRun(){ - return numTestsPerEvictionRun; - } - - /** - * 设置在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 - * - * @param numTestsPerEvictionRun - * 在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 - */ - public void setNumTestsPerEvictionRun(Integer numTestsPerEvictionRun){ - this.numTestsPerEvictionRun = numTestsPerEvictionRun; - } - - /** - * 返回空闲的连接被释放最低要待时间 - * - * @return 空闲的连接被释放最低要待时间 - */ - public Duration getMinEvictableIdleTime(){ - return minEvictableIdleTime; - } - - /** - * 设置空闲的连接被释放最低要待时间 - * - * @param minEvictableIdleTime - * 空闲的连接被释放最低要待时间 - */ - public void setMinEvictableIdleTime(Duration minEvictableIdleTime){ - this.minEvictableIdleTime = minEvictableIdleTime; - } - - /** - * 返回空闲的连接被释放最低要待时间,但有额外条件 - * - * @return 空闲的连接被释放最低要待时间 - */ - public Duration getSoftMinEvictableIdleTime(){ - return softMinEvictableIdleTime; - } - - /** - * 设置空闲的连接被释放最低要待时间 - * - * @param softMinEvictableIdleTime - * 空闲的连接被释放最低要待时间 - */ - public void setSoftMinEvictableIdleTime(Duration softMinEvictableIdleTime){ - this.softMinEvictableIdleTime = softMinEvictableIdleTime; - } - - /** - * 是否后进先出 - * - * @return 后进先出 - */ - @Deprecated - public Boolean isLifo(){ - return getLifo(); - } - - /** - * 是否后进先出 - * - * @return 后进先出 - */ - public Boolean getLifo(){ - return lifo; - } - - /** - * 设置后进先出 - * - * @param lifo - * 后进先出 - */ - public void setLifo(Boolean lifo){ - this.lifo = lifo; - } - - /** - * 返回验证快速失败 - * - * @return 验证快速失败 - */ - @Deprecated - public Boolean isFastFailValidation(){ - return getFastFailValidation(); - } - - /** - * 返回验证快速失败 - * - * @return 验证快速失败 - */ - public Boolean getFastFailValidation(){ - return fastFailValidation; - } - - /** - * 设置验证快速失败 - * - * @param fastFailValidation - * 验证快速失败 - */ - public void setFastFailValidation(Boolean fastFailValidation){ - this.fastFailValidation = fastFailValidation; - } - - public Set getDisconnectionSqlCodes(){ - return disconnectionSqlCodes; - } - - public void setDisconnectionSqlCodes(Set disconnectionSqlCodes){ - this.disconnectionSqlCodes = disconnectionSqlCodes; - } - - public String getJmxName(){ - return jmxName; - } - - public void setJmxName(String jmxName){ - this.jmxName = jmxName; - } - -} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/DruidPoolConfiguration.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/DruidPoolConfiguration.java deleted file mode 100644 index afa1c11d4..000000000 --- a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/DruidPoolConfiguration.java +++ /dev/null @@ -1,1187 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. - * See the NOTICE file distributed with this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - * - * ========================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +-------------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | - * +-------------------------------------------------------------------------------------------------------+ - */ -package com.buession.jdbc.datasource.config; - -import com.alibaba.druid.pool.DruidAbstractDataSource; -import com.alibaba.druid.pool.DruidDataSourceStatLogger; -import com.buession.jdbc.core.TransactionIsolation; - -import javax.management.ObjectName; -import java.time.Duration; -import java.util.Collection; -import java.util.Set; -import java.util.concurrent.ScheduledExecutorService; - -/** - * Druid 数据源连接池配置 {@link DruidAbstractDataSource} - * - * @author Yong.Teng - * @since 1.3.2 - */ -public class DruidPoolConfiguration extends AbstractPoolConfiguration { - - /** - * 连接池名称 - */ - private String name; - - /** - * 为支持 catalog 概念的数据库设置默认 catalog - */ - private String defaultCatalog; - - /** - * 数据库类型名称 - */ - private String dbTypeName; - - private ScheduledExecutorService createScheduler; - - private ScheduledExecutorService destroyScheduler; - - private Boolean initExceptionThrow; - - private Integer maxCreateTaskCount; - - private volatile Integer maxWaitThreadCount; - - /** - * 初始化时建立连接的个数 - */ - private Integer initialSize = DruidAbstractDataSource.DEFAULT_INITIAL_SIZE; - - /** - * 最大连接池数量 - */ - private Integer maxActive = DruidAbstractDataSource.DEFAULT_MAX_ACTIVE_SIZE; - - /** - * 最小空闲连接数 - */ - private Integer minIdle = DruidAbstractDataSource.DEFAULT_MIN_IDLE; - - /** - * 最大空闲连接数 - */ - private Integer maxIdle = DruidAbstractDataSource.DEFAULT_MAX_IDLE; - - /** - * 获取连接时最大等待时间 - * 配置了 maxWait 之后,缺省启用公平锁,并发效率会有所下降,如果需要可以通过配置 useUnfairLock 属性为 true 使用非公平锁 - */ - private Duration maxWait = Duration.ofMillis(DruidAbstractDataSource.DEFAULT_MAX_WAIT); - - private Long timeBetweenConnectError = DruidAbstractDataSource.DEFAULT_TIME_BETWEEN_CONNECT_ERROR_MILLIS; - - /** - * 连接出错重试次数 - */ - private Integer connectionErrorRetryAttempts; - - /** - * 在第一次创建时用来初始化物理连接的SQL语句集合,只在配置的连接工厂创建连接时被执行一次 - */ - private Collection connectionInitSqls; - - private Boolean asyncCloseConnectionEnable; - - private Boolean accessToUnderlyingConnectionAllowed; - - /** - * 验证连接使用的 SQL - */ - private String validationQuery; - - private String validConnectionCheckerClassName; - - /** - * 验证SQL的执行超时时间,为负数表示关闭连接验证超时 - */ - private Duration validationQueryTimeout; - - private Duration queryTimeout; - - private Integer notFullTimeoutRetryCount; - - /** - * 从连接池获取一个连接时,验证有效性; - * 指明在从池中租借对象时是否要进行验证有效,如果对象验证失败,则对象将从池子释放,然后我们将尝试租借另一个 - */ - private Boolean testOnBorrow = DruidAbstractDataSource.DEFAULT_TEST_ON_BORROW; - - /** - * 连接被归还到连接池时,验证有效性 - */ - private Boolean testOnReturn = DruidAbstractDataSource.DEFAULT_TEST_ON_RETURN; - - /** - * 连接空闲时,验证有效性; - * 指明对象是否需要通过对象驱逐者进行校验(如果有的话),假如一个对象验证失败,则对象将被从池中释放 - */ - private Boolean testWhileIdle = DruidAbstractDataSource.DEFAULT_WHILE_IDLE; - - /** - * 空闲对象驱逐线程运行时的休眠时间 - */ - private Duration timeBetweenEvictionRuns = Duration.ofMillis( - DruidAbstractDataSource.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS); - - /** - * 在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 - */ - private Integer numTestsPerEvictionRun = DruidAbstractDataSource.DEFAULT_NUM_TESTS_PER_EVICTION_RUN; - - /** - * 空闲的连接被释放最低要待时间 - */ - private Duration minEvictableIdleTime = Duration.ofMillis( - DruidAbstractDataSource.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS); - - private Duration maxEvictableIdleTime = Duration.ofMillis( - DruidAbstractDataSource.DEFAULT_MAX_EVICTABLE_IDLE_TIME_MILLIS); - - private Duration keepAliveBetweenTime = Duration.ofMillis( - DruidAbstractDataSource.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS); - - private Duration phyTimeout = Duration.ofMillis(DruidAbstractDataSource.DEFAULT_PHY_TIMEOUT_MILLIS); - - private Long phyMaxUseCount; - - /** - * 默认事务隔离级别 - */ - private TransactionIsolation defaultTransactionIsolation; - - private Long transactionThreshold; - - private Duration transactionQueryTimeout; - - /** - * 默认是否自动提交事务 - */ - private Boolean defaultAutoCommit; - - /** - * 默认连接是否是只读模式 - */ - private Boolean defaultReadOnly; - - /** - * 是否缓存 preparedStatement,也就是PSCache; - * PSCache 对支持游标的数据库性能提升巨大,比如说 oracle,在mysql下建议关闭 - */ - private Boolean poolPreparedStatements; - - /** - * 最大打开 PSCache 数,在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些 - */ - private Integer maxOpenPreparedStatements; - - private Boolean sharePreparedStatements; - - private Integer maxPoolPreparedStatementPerConnectionSize; - - /** - * 插件配置 - */ - private Set filters; - - private Boolean clearFiltersEnable; - - /** - * {@link com.alibaba.druid.pool.ExceptionSorter} 实例名称 - */ - private String exceptionSorterClassName; - - private DruidDataSourceStatLogger statLogger; - - private Duration timeBetweenLogStats; - - /** - * 是否移除抛弃的(abandoned)连接,一个连接使用超过了 removeAbandonedTimeout 上限就被视为抛弃的, - * 开启该开关可以恢复那些应用没有关闭的连接 - */ - private Boolean removeAbandoned; - - /** - * 一个连接使用超过多久就视为抛弃的,该值应该超过你的应用中最长的SQL可能运行的时间 - */ - private Duration removeAbandonedTimeout; - - /** - * 记录抛弃连接的应用的堆栈信息; - * 会增加系统开销,因为为了能够在可能发生的连接被抛弃时记录堆栈 ,应用每次获取连接时都需要生成堆栈信息 - */ - private Boolean logAbandoned; - - private Boolean useOracleImplicitCache; - - private Boolean initVariants; - - private Boolean initGlobalVariants; - - private Boolean failFast; - - private Integer onFatalErrorMaxActive; - - private Boolean breakAfterAcquireFailure; - - private Boolean dupCloseLogEnable; - - private Boolean useUnfairLock; - - private Boolean useLocalSessionState; - - private ObjectName objectName; - - /** - * 返回连接池名称 - * - * @return 连接池名称 - */ - public String getName(){ - return name; - } - - /** - * 设置连接池名称 - * - * @param name - * 连接池名称 - */ - public void setName(String name){ - this.name = name; - } - - /** - * 返回为支持 catalog 概念的数据库设置默认 catalog - * - * @return 为支持 catalog 概念的数据库设置默认 catalog - */ - public String getDefaultCatalog(){ - return defaultCatalog; - } - - /** - * 设置为支持 catalog 概念的数据库设置默认 catalog - * - * @param defaultCatalog - * 为支持 catalog 概念的数据库设置默认 catalog - */ - public void setDefaultCatalog(String defaultCatalog){ - this.defaultCatalog = defaultCatalog; - } - - /** - * 返回数据库类型名称 - * - * @return 数据库类型名称 - */ - public String getDbTypeName(){ - return dbTypeName; - } - - /** - * 设置数据库类型名称 - * - * @param dbTypeName - * 数据库类型名称 - */ - public void setDbTypeName(String dbTypeName){ - this.dbTypeName = dbTypeName; - } - - public ScheduledExecutorService getCreateScheduler(){ - return createScheduler; - } - - public void setCreateScheduler(ScheduledExecutorService createScheduler){ - this.createScheduler = createScheduler; - } - - public ScheduledExecutorService getDestroyScheduler(){ - return destroyScheduler; - } - - public void setDestroyScheduler(ScheduledExecutorService destroyScheduler){ - this.destroyScheduler = destroyScheduler; - } - - @Deprecated - public Boolean isInitExceptionThrow(){ - return getInitExceptionThrow(); - } - - public Boolean getInitExceptionThrow(){ - return initExceptionThrow; - } - - public void setInitExceptionThrow(Boolean initExceptionThrow){ - this.initExceptionThrow = initExceptionThrow; - } - - public Integer getMaxCreateTaskCount(){ - return maxCreateTaskCount; - } - - public void setMaxCreateTaskCount(Integer maxCreateTaskCount){ - this.maxCreateTaskCount = maxCreateTaskCount; - } - - public Integer getMaxWaitThreadCount(){ - return maxWaitThreadCount; - } - - public void setMaxWaitThreadCount(Integer maxWaitThreadCount){ - this.maxWaitThreadCount = maxWaitThreadCount; - } - - /** - * 返回初始化时建立连接的个数 - * - * @return 初始化时建立连接的个数 - */ - public Integer getInitialSize(){ - return initialSize; - } - - /** - * 设置初始化时建立连接的个数 - * - * @param initialSize - * 初始化时建立连接的个数 - */ - public void setInitialSize(Integer initialSize){ - this.initialSize = initialSize; - } - - /** - * 返回最大连接池数量 - * - * @return 最大连接池数量 - */ - public Integer getMaxActive(){ - return maxActive; - } - - /** - * 设置最大连接池数量 - * - * @param maxActive - * 最大连接池数量 - */ - public void setMaxActive(Integer maxActive){ - this.maxActive = maxActive; - } - - /** - * 返回最小空闲连接数 - * - * @return 最小空闲连接数 - */ - public Integer getMinIdle(){ - return minIdle; - } - - /** - * 设置最小空闲连接数 - * - * @param minIdle - * 最小空闲连接数 - */ - public void setMinIdle(Integer minIdle){ - this.minIdle = minIdle; - } - - /** - * 返回最大空闲连接数 - * - * @return 最大空闲连接数 - */ - public Integer getMaxIdle(){ - return maxIdle; - } - - /** - * 设置空闲连接数 - * - * @param maxIdle - * 最大空闲连接数 - */ - public void setMaxIdle(Integer maxIdle){ - this.maxIdle = maxIdle; - } - - /** - * 返回获取连接时最大等待时间 - * - * @return 获取连接时最大等待时间 - */ - public Duration getMaxWait(){ - return maxWait; - } - - /** - * 设置获取连接时最大等待时间 - * - * @param maxWait - * 获取连接时最大等待时间 - */ - public void setMaxWait(Duration maxWait){ - this.maxWait = maxWait; - } - - public Long getTimeBetweenConnectError(){ - return timeBetweenConnectError; - } - - public void setTimeBetweenConnectError(Long timeBetweenConnectError){ - this.timeBetweenConnectError = timeBetweenConnectError; - } - - /** - * 返回连接出错重试次数 - * - * @return 连接出错重试次数 - */ - public Integer getConnectionErrorRetryAttempts(){ - return connectionErrorRetryAttempts; - } - - /** - * 设置连接出错重试次数 - * - * @param connectionErrorRetryAttempts - * 连接出错重试次数 - */ - public void setConnectionErrorRetryAttempts(Integer connectionErrorRetryAttempts){ - this.connectionErrorRetryAttempts = connectionErrorRetryAttempts; - } - - /** - * 返回在第一次创建时用来初始化物理连接的SQL语句集合 - * - * @return 在第一次创建时用来初始化物理连接的SQL语句集合 - */ - public Collection getConnectionInitSqls(){ - return connectionInitSqls; - } - - /** - * 设置在第一次创建时用来初始化物理连接的SQL语句集合 - * - * @param connectionInitSqls - * 在第一次创建时用来初始化物理连接的SQL语句集合 - */ - public void setConnectionInitSqls(Collection connectionInitSqls){ - this.connectionInitSqls = connectionInitSqls; - } - - @Deprecated - public Boolean isAsyncCloseConnectionEnable(){ - return getAsyncCloseConnectionEnable(); - } - - public Boolean getAsyncCloseConnectionEnable(){ - return asyncCloseConnectionEnable; - } - - public void setAsyncCloseConnectionEnable(Boolean asyncCloseConnectionEnable){ - this.asyncCloseConnectionEnable = asyncCloseConnectionEnable; - } - - @Deprecated - public Boolean isAccessToUnderlyingConnectionAllowed(){ - return getAccessToUnderlyingConnectionAllowed(); - } - - public Boolean getAccessToUnderlyingConnectionAllowed(){ - return accessToUnderlyingConnectionAllowed; - } - - public void setAccessToUnderlyingConnectionAllowed(Boolean accessToUnderlyingConnectionAllowed){ - this.accessToUnderlyingConnectionAllowed = accessToUnderlyingConnectionAllowed; - } - - /** - * 返回验证连接使用的 SQL - * - * @return 验证连接使用的 SQL - */ - public String getValidationQuery(){ - return validationQuery; - } - - /** - * 设置验证连接使用的 SQL - * - * @param validationQuery - * 验证连接使用的 SQL - */ - public void setValidationQuery(String validationQuery){ - this.validationQuery = validationQuery; - } - - public String getValidConnectionCheckerClassName(){ - return validConnectionCheckerClassName; - } - - public void setValidConnectionCheckerClassName(String validConnectionCheckerClassName){ - this.validConnectionCheckerClassName = validConnectionCheckerClassName; - } - - /** - * 返回验证SQL的执行超时时间,为负数表示关闭连接验证超时 - * - * @return 验证SQL的执行超时时间 - */ - public Duration getValidationQueryTimeout(){ - return validationQueryTimeout; - } - - /** - * 设置验证SQL的执行超时时间,为负数表示关闭连接验证超时 - * - * @param validationQueryTimeout - * 验证SQL的执行超时时间 - */ - public void setValidationQueryTimeout(Duration validationQueryTimeout){ - this.validationQueryTimeout = validationQueryTimeout; - } - - public Duration getQueryTimeout(){ - return queryTimeout; - } - - public void setQueryTimeout(Duration queryTimeout){ - this.queryTimeout = queryTimeout; - } - - public Integer getNotFullTimeoutRetryCount(){ - return notFullTimeoutRetryCount; - } - - public void setNotFullTimeoutRetryCount(Integer notFullTimeoutRetryCount){ - this.notFullTimeoutRetryCount = notFullTimeoutRetryCount; - } - - /** - * 返回从连接池获取一个连接时,是否验证有效性 - * - * @return 从连接池获取一个连接时,验证有效性 - */ - @Deprecated - public Boolean isTestOnBorrow(){ - return getTestOnBorrow(); - } - - /** - * 返回从连接池获取一个连接时,是否验证有效性 - * - * @return 从连接池获取一个连接时,验证有效性 - */ - public Boolean getTestOnBorrow(){ - return testOnBorrow; - } - - /** - * 设置从连接池获取一个连接时,是否验证有效性 - * - * @param testOnBorrow - * 从连接池获取一个连接时,是否验证有效性 - */ - public void setTestOnBorrow(Boolean testOnBorrow){ - this.testOnBorrow = testOnBorrow; - } - - /** - * 返回连接被归还到连接池时,是否验证有效性 - * - * @return 连接被归还到连接池时,是否验证有效性 - */ - @Deprecated - public Boolean isTestOnReturn(){ - return getTestOnReturn(); - } - - /** - * 返回连接被归还到连接池时,是否验证有效性 - * - * @return 连接被归还到连接池时,是否验证有效性 - */ - public Boolean getTestOnReturn(){ - return testOnReturn; - } - - /** - * 设置连接被归还到连接池时,是否验证有效性 - * - * @param testOnReturn - * 连接被归还到连接池时,是否验证有效性 - */ - public void setTestOnReturn(Boolean testOnReturn){ - this.testOnReturn = testOnReturn; - } - - /** - * 返回连接空闲时,是否验证有效性 - * - * @return 连接空闲时,是否验证有效性 - */ - @Deprecated - public Boolean isTestWhileIdle(){ - return getTestWhileIdle(); - } - - /** - * 返回连接空闲时,是否验证有效性 - * - * @return 连接空闲时,是否验证有效性 - */ - public Boolean getTestWhileIdle(){ - return testWhileIdle; - } - - /** - * 设置连接空闲时,是否验证有效性 - * - * @param testWhileIdle - * 连接空闲时,是否验证有效性 - */ - public void setTestWhileIdle(Boolean testWhileIdle){ - this.testWhileIdle = testWhileIdle; - } - - /** - * 返回空闲对象驱逐线程运行时的休眠时间 - * - * @return 空闲对象驱逐线程运行时的休眠时间 - */ - public Duration getTimeBetweenEvictionRuns(){ - return timeBetweenEvictionRuns; - } - - /** - * 设置空闲对象驱逐线程运行时的休眠时间 - * - * @param timeBetweenEvictionRuns - * 空闲对象驱逐线程运行时的休眠时间 - */ - public void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns){ - this.timeBetweenEvictionRuns = timeBetweenEvictionRuns; - } - - /** - * 返回在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 - * - * @return 在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 - */ - public Integer getNumTestsPerEvictionRun(){ - return numTestsPerEvictionRun; - } - - /** - * 设置在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 - * - * @param numTestsPerEvictionRun - * 在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 - */ - public void setNumTestsPerEvictionRun(Integer numTestsPerEvictionRun){ - this.numTestsPerEvictionRun = numTestsPerEvictionRun; - } - - /** - * 返回空闲的连接被释放最低要待时间 - * - * @return 空闲的连接被释放最低要待时间 - */ - public Duration getMinEvictableIdleTime(){ - return minEvictableIdleTime; - } - - /** - * 设置空闲的连接被释放最低要待时间 - * - * @param minEvictableIdleTime - * 空闲的连接被释放最低要待时间 - */ - public void setMinEvictableIdleTime(Duration minEvictableIdleTime){ - this.minEvictableIdleTime = minEvictableIdleTime; - } - - public Duration getMaxEvictableIdleTime(){ - return maxEvictableIdleTime; - } - - public void setMaxEvictableIdleTime(Duration maxEvictableIdleTime){ - this.maxEvictableIdleTime = maxEvictableIdleTime; - } - - public Duration getKeepAliveBetweenTime(){ - return keepAliveBetweenTime; - } - - public void setKeepAliveBetweenTime(Duration keepAliveBetweenTime){ - this.keepAliveBetweenTime = keepAliveBetweenTime; - } - - public Duration getPhyTimeout(){ - return phyTimeout; - } - - public void setPhyTimeout(Duration phyTimeout){ - this.phyTimeout = phyTimeout; - } - - public Long getPhyMaxUseCount(){ - return phyMaxUseCount; - } - - public void setPhyMaxUseCount(Long phyMaxUseCount){ - this.phyMaxUseCount = phyMaxUseCount; - } - - /** - * 返回默认事务隔离级别 - * - * @return 默认事务隔离级别 - */ - public TransactionIsolation getDefaultTransactionIsolation(){ - return defaultTransactionIsolation; - } - - /** - * 设置默认事务隔离级别 - * - * @param defaultTransactionIsolation - * 默认事务隔离级别 - */ - public void setDefaultTransactionIsolation(TransactionIsolation defaultTransactionIsolation){ - this.defaultTransactionIsolation = defaultTransactionIsolation; - } - - public Long getTransactionThreshold(){ - return transactionThreshold; - } - - public void setTransactionThreshold(Long transactionThreshold){ - this.transactionThreshold = transactionThreshold; - } - - public Duration getTransactionQueryTimeout(){ - return transactionQueryTimeout; - } - - public void setTransactionQueryTimeout(Duration transactionQueryTimeout){ - this.transactionQueryTimeout = transactionQueryTimeout; - } - - /** - * 返回是否自动提交事务 - * - * @return 是否自动提交事务 - */ - @Deprecated - public Boolean isDefaultAutoCommit(){ - return getDefaultAutoCommit(); - } - - /** - * 返回是否自动提交事务 - * - * @return 是否自动提交事务 - */ - public Boolean getDefaultAutoCommit(){ - return defaultAutoCommit; - } - - /** - * 设置是否自动提交事务 - * - * @param defaultAutoCommit - * 是否自动提交事务 - */ - public void setDefaultAutoCommit(Boolean defaultAutoCommit){ - this.defaultAutoCommit = defaultAutoCommit; - } - - /** - * 返回连接是否是只读模式 - * - * @return 连接是否是只读模式 - */ - @Deprecated - public Boolean isDefaultReadOnly(){ - return getDefaultReadOnly(); - } - - /** - * 返回连接是否是只读模式 - * - * @return 连接是否是只读模式 - */ - public Boolean getDefaultReadOnly(){ - return defaultReadOnly; - } - - /** - * 设置连接是否是只读模式 - * - * @param defaultReadOnly - * 连接是否是只读模式 - */ - public void setDefaultReadOnly(Boolean defaultReadOnly){ - this.defaultReadOnly = defaultReadOnly; - } - - /** - * 返回是否缓存 preparedStatement - * - * @return 是否缓存 preparedStatement - */ - @Deprecated - public Boolean isPoolPreparedStatements(){ - return getPoolPreparedStatements(); - } - - /** - * 返回是否缓存 preparedStatement - * - * @return 是否缓存 preparedStatement - */ - public Boolean getPoolPreparedStatements(){ - return poolPreparedStatements; - } - - /** - * 设置是否缓存 preparedStatement,PSCache 对支持游标的数据库性能提升巨大,比如说 oracle,在mysql下建议关闭 - * - * @param poolPreparedStatements - * 是否缓存 preparedStatement - */ - public void setPoolPreparedStatements(Boolean poolPreparedStatements){ - this.poolPreparedStatements = poolPreparedStatements; - } - - /** - * 返回最大打开 PSCache 数 - * - * @return 最大打开 PSCache 数 - */ - public Integer getMaxOpenPreparedStatements(){ - return maxOpenPreparedStatements; - } - - /** - * 设置最大打开 PSCache 数,在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些 - * - * @param maxOpenPreparedStatements - * 最大打开 PSCache 数 - */ - public void setMaxOpenPreparedStatements(Integer maxOpenPreparedStatements){ - this.maxOpenPreparedStatements = maxOpenPreparedStatements; - } - - @Deprecated - public Boolean isSharePreparedStatements(){ - return getSharePreparedStatements(); - } - - public Boolean getSharePreparedStatements(){ - return sharePreparedStatements; - } - - public void setSharePreparedStatements(Boolean sharePreparedStatements){ - this.sharePreparedStatements = sharePreparedStatements; - } - - public Integer getMaxPoolPreparedStatementPerConnectionSize(){ - return maxPoolPreparedStatementPerConnectionSize; - } - - public void setMaxPoolPreparedStatementPerConnectionSize(Integer maxPoolPreparedStatementPerConnectionSize){ - this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize; - } - - /** - * 返回插件配置 - * - * @return 插件配置 - */ - public Set getFilters(){ - return filters; - } - - /** - * 设置插件配置 - * - * @param filters - * 插件配置 - */ - public void setFilters(Set filters){ - this.filters = filters; - } - - @Deprecated - public Boolean isClearFiltersEnable(){ - return getClearFiltersEnable(); - } - - public Boolean getClearFiltersEnable(){ - return clearFiltersEnable; - } - - public void setClearFiltersEnable(Boolean clearFiltersEnable){ - this.clearFiltersEnable = clearFiltersEnable; - } - - /** - * 返回 {@link com.alibaba.druid.pool.ExceptionSorter} 实例名称 - * - * @return {@link com.alibaba.druid.pool.ExceptionSorter} 实例名称 - */ - public String getExceptionSorterClassName(){ - return exceptionSorterClassName; - } - - /** - * 设置 {@link com.alibaba.druid.pool.ExceptionSorter} 实例名称 - * - * @param exceptionSorterClassName - * {@link com.alibaba.druid.pool.ExceptionSorter} 实例名称 - */ - public void setExceptionSorterClassName(String exceptionSorterClassName){ - this.exceptionSorterClassName = exceptionSorterClassName; - } - - public DruidDataSourceStatLogger getStatLogger(){ - return statLogger; - } - - public void setStatLogger(DruidDataSourceStatLogger statLogger){ - this.statLogger = statLogger; - } - - public Duration getTimeBetweenLogStats(){ - return timeBetweenLogStats; - } - - public void setTimeBetweenLogStats(Duration timeBetweenLogStats){ - this.timeBetweenLogStats = timeBetweenLogStats; - } - - /** - * 返回是否移除抛弃的(abandoned)连接 - * - * @return 是否移除抛弃的(abandoned)连接 - */ - @Deprecated - public Boolean isRemoveAbandoned(){ - return getRemoveAbandoned(); - } - - /** - * 返回是否移除抛弃的(abandoned)连接 - * - * @return 是否移除抛弃的(abandoned)连接 - */ - public Boolean getRemoveAbandoned(){ - return removeAbandoned; - } - - /** - * 设置是否移除抛弃的(abandoned)连接 - * - * @param removeAbandoned - * 是否移除抛弃的(abandoned)连接 - */ - public void setRemoveAbandoned(Boolean removeAbandoned){ - this.removeAbandoned = removeAbandoned; - } - - /** - * 返回一个连接使用超过多久就视为抛弃的 - * - * @return 一个连接使用超过多久就视为抛弃的 - */ - public Duration getRemoveAbandonedTimeout(){ - return removeAbandonedTimeout; - } - - /** - * 设置一个连接使用超过多久就视为抛弃的,该值应该超过你的应用中最长的SQL可能运行的时间 - * - * @param removeAbandonedTimeout - * 一个连接使用超过多久就视为抛弃的,该值应该超过你的应用中最长的SQL可能运行的时间 - */ - public void setRemoveAbandonedTimeout(Duration removeAbandonedTimeout){ - this.removeAbandonedTimeout = removeAbandonedTimeout; - } - - /** - * 返回是否记录抛弃连接的应用的堆栈信息 - * - * @return 是否记录抛弃连接的应用的堆栈信息 - */ - @Deprecated - public Boolean isLogAbandoned(){ - return getLogAbandoned(); - } - - /** - * 返回是否记录抛弃连接的应用的堆栈信息 - * - * @return 是否记录抛弃连接的应用的堆栈信息 - */ - public Boolean getLogAbandoned(){ - return logAbandoned; - } - - /** - * 设置是否记录抛弃连接的应用的堆栈信息 - * - * @param logAbandoned - * 是否记录抛弃连接的应用的堆栈信息 - */ - public void setLogAbandoned(Boolean logAbandoned){ - this.logAbandoned = logAbandoned; - } - - @Deprecated - public Boolean isUseOracleImplicitCache(){ - return getUseOracleImplicitCache(); - } - - public Boolean getUseOracleImplicitCache(){ - return useOracleImplicitCache; - } - - public void setUseOracleImplicitCache(Boolean useOracleImplicitCache){ - this.useOracleImplicitCache = useOracleImplicitCache; - } - - @Deprecated - public Boolean isInitVariants(){ - return getInitVariants(); - } - - public Boolean getInitVariants(){ - return initVariants; - } - - public void setInitVariants(Boolean initVariants){ - this.initVariants = initVariants; - } - - @Deprecated - public Boolean isInitGlobalVariants(){ - return getInitGlobalVariants(); - } - - public Boolean getInitGlobalVariants(){ - return initGlobalVariants; - } - - public void setInitGlobalVariants(Boolean initGlobalVariants){ - this.initGlobalVariants = initGlobalVariants; - } - - @Deprecated - public Boolean isFailFast(){ - return getFailFast(); - } - - public Boolean getFailFast(){ - return failFast; - } - - public void setFailFast(Boolean failFast){ - this.failFast = failFast; - } - - public Integer getOnFatalErrorMaxActive(){ - return onFatalErrorMaxActive; - } - - public void setOnFatalErrorMaxActive(Integer onFatalErrorMaxActive){ - this.onFatalErrorMaxActive = onFatalErrorMaxActive; - } - - @Deprecated - public Boolean isBreakAfterAcquireFailure(){ - return getBreakAfterAcquireFailure(); - } - - public Boolean getBreakAfterAcquireFailure(){ - return breakAfterAcquireFailure; - } - - public void setBreakAfterAcquireFailure(Boolean breakAfterAcquireFailure){ - this.breakAfterAcquireFailure = breakAfterAcquireFailure; - } - - @Deprecated - public Boolean isDupCloseLogEnable(){ - return getDupCloseLogEnable(); - } - - public Boolean getDupCloseLogEnable(){ - return dupCloseLogEnable; - } - - public void setDupCloseLogEnable(Boolean dupCloseLogEnable){ - this.dupCloseLogEnable = dupCloseLogEnable; - } - - public Boolean getUseUnfairLock(){ - return useUnfairLock; - } - - public void setUseUnfairLock(Boolean useUnfairLock){ - this.useUnfairLock = useUnfairLock; - } - - @Deprecated - public Boolean isUseLocalSessionState(){ - return getUseLocalSessionState(); - } - - public Boolean getUseLocalSessionState(){ - return useLocalSessionState; - } - - public void setUseLocalSessionState(Boolean useLocalSessionState){ - this.useLocalSessionState = useLocalSessionState; - } - - public ObjectName getObjectName(){ - return objectName; - } - - public void setObjectName(ObjectName objectName){ - this.objectName = objectName; - } - -} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/HikariPoolConfiguration.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/HikariPoolConfiguration.java deleted file mode 100644 index 73ff82e89..000000000 --- a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/HikariPoolConfiguration.java +++ /dev/null @@ -1,633 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. - * See the NOTICE file distributed with this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - * - * ========================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +-------------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | - * +-------------------------------------------------------------------------------------------------------+ - */ -package com.buession.jdbc.datasource.config; - -import com.buession.jdbc.core.TransactionIsolation; -import com.zaxxer.hikari.HikariConfig; -import com.zaxxer.hikari.metrics.MetricsTrackerFactory; - -import java.time.Duration; -import java.util.Properties; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ThreadFactory; - -/** - * Hikari 数据源连接池配置 {@link HikariConfig} - * - * @author Yong.Teng - * @since 1.3.2 - */ -public class HikariPoolConfiguration extends AbstractPoolConfiguration { - - /** - * 为支持 catalog 概念的数据库设置默认 catalog - */ - private String catalog; - - /** - * 从连接池获取连接时最大等待时间 - */ - private Duration connectionTimeout; - - /** - * 连接允许在池中闲置的最长时间,仅适用于 minimumIdle 定义为小于 maximumPoolSize,值为 0 时空闲连接永远不会从池中删除 - */ - private Duration idleTimeout; - - /** - * 控制在记录消息之前连接可能离开池的时间量,表明可能存在连接泄漏,值为 0 时泄漏检测被禁用 - */ - private Long leakDetectionThreshold; - - /** - * 池中连接的最大生存期,值为 0 时表示无限寿命, 推荐设置的比数据库的 wait_timeout 小几秒到几分钟 - */ - private Duration maxLifetime; - - /** - * 连接存活时间,值必须小于 maxLifetime 值 - * 只会发生在空闲的连接上,当对一个给定的连接进行 "keepalive "的时间到了,该连接将从池中移除 - */ - private Duration keepaliveTime; - - /** - * 最小空闲连接数量 - */ - private Integer minIdle; - - /** - * 连接池中可以保留连接的最大数 - */ - private Integer maxPoolSize; - - private Duration initializationFailTimeout; - - /** - * 设置一个SQL语句,在将每个新连接创建后,将其添加到池中之前执行该语句 - */ - private String connectionInitSql; - - /** - * 设置一个SQL语句, 从连接池获取连接时, 先执行改 sql, 验证连接是否可用 - * 如果是使用了 JDBC 4 那么不建议配置这个选项, 因为JDBC 4 使用 ping 命令, 更加高效 - */ - private String connectionTestQuery; - - /** - * 检测连接是否有效的超时时间 - */ - private Duration validationTimeout; - - /** - * 用户定义连接池的名称,主要出现在日志记录和 JMX 管理控制台中以识别池和池配置 - */ - private String poolName; - - /** - * 设置的默认模式为支持模式的概念数据库;如果未指定此属性,则使用由JDBC驱动程序定义的默认模式 - */ - private String schema; - - /** - * 事务隔离级别 - */ - private TransactionIsolation transactionIsolation; - - /** - * 是否自动提交事务 - */ - private Boolean autoCommit; - - /** - * 连接是否是只读模式 - */ - private Boolean readOnly; - - private Boolean isolateInternalQueries; - - /** - * 是否自动注册 JMX 相关的 bean - */ - private Boolean registerMbeans; - - /** - * 是否允许JMX 将连接池挂起 - */ - private Boolean allowPoolSuspension; - - /** - * 线程工厂 - */ - private ThreadFactory threadFactory; - - /** - * 调度任务执行器 - */ - private ScheduledExecutorService scheduledExecutor; - - private MetricsTrackerFactory metricsTrackerFactory; - - private Object metricRegistry; - - private Object healthCheckRegistry; - - private Properties healthCheckProperties; - - /** - * 返回为支持 catalog 概念的数据库设置默认 catalog - * - * @return 为支持 catalog 概念的数据库设置默认 catalog - */ - public String getCatalog(){ - return catalog; - } - - /** - * 设置为支持 catalog 概念的数据库设置默认 catalog - * - * @param catalog - * 为支持 catalog 概念的数据库设置默认 catalog - */ - public void setCatalog(String catalog){ - this.catalog = catalog; - } - - /** - * 返回从连接池获取连接时最大等待时间 - * - * @return 从连接池获取连接时最大等待时间 - */ - public Duration getConnectionTimeout(){ - return connectionTimeout; - } - - /** - * 设置从连接池获取连接时最大等待时间 - * - * @param connectionTimeout - * 从连接池获取连接时最大等待时间 - */ - public void setConnectionTimeout(Duration connectionTimeout){ - this.connectionTimeout = connectionTimeout; - } - - /** - * 返回连接允许在池中闲置的最长时间 - * - * @return 连接允许在池中闲置的最长时间 - */ - public Duration getIdleTimeout(){ - return idleTimeout; - } - - /** - * 设置连接允许在池中闲置的最长时间,仅适用于 minimumIdle 定义为小于 maximumPoolSize,值为 0 时空闲连接永远不会从池中删除 - * 如果 idleTimeout + 1秒 > maxLifetime 且 maxLifetime > 0,则会被重置为 0; - * 如果 idleTimeout != 0 且小于 10 秒,则会被重置为 10 秒 - * - * @param idleTimeout - * 连接允许在池中闲置的最长时间 - */ - public void setIdleTimeout(Duration idleTimeout){ - this.idleTimeout = idleTimeout; - } - - /** - * 返回记录消息之前连接可能离开池的时间量,表明可能存在连接泄漏,值为 0 时泄漏检测被禁用 - * - * @return 记录消息之前连接可能离开池的时间量 - */ - public Long getLeakDetectionThreshold(){ - return leakDetectionThreshold; - } - - /** - * 设置记录消息之前连接可能离开池的时间量,表明可能存在连接泄漏,值为 0 时泄漏检测被禁用 - * - * @param leakDetectionThreshold - * 记录消息之前连接可能离开池的时间量 - */ - public void setLeakDetectionThreshold(Long leakDetectionThreshold){ - this.leakDetectionThreshold = leakDetectionThreshold; - } - - /** - * 返回池中连接的最大生存期,值为 0 时表示无限寿命 - * - * @return 池中连接的最大生存期 - */ - public Duration getMaxLifetime(){ - return maxLifetime; - } - - /** - * 设置池中连接的最大生存期,值为 0 时表示无限寿命, 推荐设置的比数据库的 wait_timeout 小几秒到几分钟 - * - * @param maxLifetime - * 池中连接的最大生存期 - */ - public void setMaxLifetime(Duration maxLifetime){ - this.maxLifetime = maxLifetime; - } - - /** - * 返回连接存活时间,当对一个给定的连接进行 "keepalive "的时间到了,该连接将从池中移除 - * - * @return 连接存活时间 - */ - public Duration getKeepaliveTime(){ - return keepaliveTime; - } - - /** - * 设置连接存活时间,值必须小于 maxLifetime 值 - * - * @param keepaliveTime - * 连接存活时间 - */ - public void setKeepaliveTime(Duration keepaliveTime){ - this.keepaliveTime = keepaliveTime; - } - - /** - * 返回最小空闲连接数量 - * - * @return 最小空闲连接数量 - */ - public Integer getMinIdle(){ - return minIdle; - } - - /** - * 设置最小空闲连接数量 - * - * @param minIdle - * 最小空闲连接数量 - */ - public void setMinIdle(Integer minIdle){ - this.minIdle = minIdle; - } - - /** - * 返回连接池中可以保留连接的最大数 - * - * @return 连接池中可以保留连接的最大数 - */ - public Integer getMaxPoolSize(){ - return maxPoolSize; - } - - /** - * 设置连接池中可以保留连接的最大数 - * - * @param maxPoolSize - * 连接池中可以保留连接的最大数 - */ - public void setMaxPoolSize(Integer maxPoolSize){ - this.maxPoolSize = maxPoolSize; - } - - public Duration getInitializationFailTimeout(){ - return initializationFailTimeout; - } - - public void setInitializationFailTimeout(Duration initializationFailTimeout){ - this.initializationFailTimeout = initializationFailTimeout; - } - - /** - * 返回在将每个新连接创建后,将其添加到池中之前执行的SQL语句 - * - * @return 每个新连接创建后,将其添加到池中之前执行的SQL语句 - */ - public String getConnectionInitSql(){ - return connectionInitSql; - } - - /** - * 设置每个新连接创建后,将其添加到池中之前执行的SQL语句 - * - * @param connectionInitSql - * 每个新连接创建后,将其添加到池中之前执行的SQL语句 - */ - public void setConnectionInitSql(String connectionInitSql){ - this.connectionInitSql = connectionInitSql; - } - - /** - * 返回从连接池获取连接时, 验证连接是否可用的SQL语句 - * - * @return 从连接池获取连接时, 验证连接是否可用的SQL语句 - */ - public String getConnectionTestQuery(){ - return connectionTestQuery; - } - - /** - * 设置从连接池获取连接时, 验证连接是否可用的SQL语句 - * - * @param connectionTestQuery - * 从连接池获取连接时, 验证连接是否可用的SQL语句 - */ - public void setConnectionTestQuery(String connectionTestQuery){ - this.connectionTestQuery = connectionTestQuery; - } - - /** - * 返回检测连接是否有效的超时时间 - * - * @return 检测连接是否有效的超时时间 - */ - public Duration getValidationTimeout(){ - return validationTimeout; - } - - /** - * 设置检测连接是否有效的超时时间,不能大于 {@link #connectionTimeout} - * - * @param validationTimeout - * 检测连接是否有效的超时时间 - */ - public void setValidationTimeout(Duration validationTimeout){ - this.validationTimeout = validationTimeout; - } - - /** - * 返回用户定义连接池的名称 - * - * @return 用户定义连接池的名称 - */ - public String getPoolName(){ - return poolName; - } - - /** - * 设置连接池的名称 - * - * @param poolName - * 连接池的名称 - */ - public void setPoolName(String poolName){ - this.poolName = poolName; - } - - /** - * 返回默认模式为支持模式的概念数据库 - * - * @return 默认模式为支持模式的概念数据库 - */ - public String getSchema(){ - return schema; - } - - /** - * 设置默认模式为支持模式的概念数据库 - * - * @param schema - * 默认模式为支持模式的概念数据库 - */ - public void setSchema(String schema){ - this.schema = schema; - } - - /** - * 返回事务隔离级别 - * - * @return 事务隔离级别 - */ - public TransactionIsolation getTransactionIsolation(){ - return transactionIsolation; - } - - /** - * 设置事务隔离级别 - * - * @param transactionIsolation - * 事务隔离级别 - */ - public void setTransactionIsolation(TransactionIsolation transactionIsolation){ - this.transactionIsolation = transactionIsolation; - } - - /** - * 返回是否自动提交事务 - * - * @return 是否自动提交事务 - */ - @Deprecated - public Boolean isAutoCommit(){ - return getAutoCommit(); - } - - /** - * 返回是否自动提交事务 - * - * @return 是否自动提交事务 - */ - public Boolean getAutoCommit(){ - return autoCommit; - } - - /** - * 设置是否自动提交事务 - * - * @param autoCommit - * 是否自动提交事务 - */ - public void setAutoCommit(Boolean autoCommit){ - this.autoCommit = autoCommit; - } - - /** - * 返回连接是否是只读模式 - * - * @return 连接是否是只读模式 - */ - @Deprecated - public Boolean isReadOnly(){ - return getReadOnly(); - } - - /** - * 返回连接是否是只读模式 - * - * @return 连接是否是只读模式 - */ - public Boolean getReadOnly(){ - return readOnly; - } - - /** - * 设置连接是否是只读模式 - * - * @param readOnly - * 连接是否是只读模式 - */ - public void setReadOnly(Boolean readOnly){ - this.readOnly = readOnly; - } - - @Deprecated - public Boolean isIsolateInternalQueries(){ - return getIsolateInternalQueries(); - } - - public Boolean getIsolateInternalQueries(){ - return isolateInternalQueries; - } - - public void setIsolateInternalQueries(Boolean isolateInternalQueries){ - this.isolateInternalQueries = isolateInternalQueries; - } - - /** - * 返回是否自动注册 JMX 相关的 bean - * - * @return 是否自动注册 JMX 相关的 bean - */ - @Deprecated - public Boolean isRegisterMbeans(){ - return getRegisterMbeans(); - } - - /** - * 返回是否自动注册 JMX 相关的 bean - * - * @return 是否自动注册 JMX 相关的 bean - */ - public Boolean getRegisterMbeans(){ - return registerMbeans; - } - - /** - * 设置是否自动注册 JMX 相关的 bean - * - * @param registerMbeans - * 是否自动注册 JMX 相关的 bean - */ - public void setRegisterMbeans(Boolean registerMbeans){ - this.registerMbeans = registerMbeans; - } - - /** - * 返回是否允许JMX 将连接池挂起 - * - * @return 是否允许JMX 将连接池挂起 - */ - @Deprecated - public Boolean isAllowPoolSuspension(){ - return getAllowPoolSuspension(); - } - - /** - * 返回是否允许JMX 将连接池挂起 - * - * @return 是否允许JMX 将连接池挂起 - */ - public Boolean getAllowPoolSuspension(){ - return allowPoolSuspension; - } - - /** - * 设置是否允许JMX 将连接池挂起 - * - * @param allowPoolSuspension - * 是否允许JMX 将连接池挂起 - */ - public void setAllowPoolSuspension(Boolean allowPoolSuspension){ - this.allowPoolSuspension = allowPoolSuspension; - } - - /** - * 返回线程工厂 - * - * @return 线程工厂 - */ - public ThreadFactory getThreadFactory(){ - return threadFactory; - } - - /** - * 设置线程工厂 - * - * @param threadFactory - * 线程工厂 - */ - public void setThreadFactory(ThreadFactory threadFactory){ - this.threadFactory = threadFactory; - } - - /** - * 返回调度任务执行器 - * - * @return 调度任务执行器 - */ - public ScheduledExecutorService getScheduledExecutor(){ - return scheduledExecutor; - } - - /** - * 设置调度任务执行器 - * - * @param scheduledExecutor - * 调度任务执行器 - */ - public void setScheduledExecutor(ScheduledExecutorService scheduledExecutor){ - this.scheduledExecutor = scheduledExecutor; - } - - public MetricsTrackerFactory getMetricsTrackerFactory(){ - return metricsTrackerFactory; - } - - public void setMetricsTrackerFactory(MetricsTrackerFactory metricsTrackerFactory){ - this.metricsTrackerFactory = metricsTrackerFactory; - } - - public Object getMetricRegistry(){ - return metricRegistry; - } - - public void setMetricRegistry(Object metricRegistry){ - this.metricRegistry = metricRegistry; - } - - public Object getHealthCheckRegistry(){ - return healthCheckRegistry; - } - - public void setHealthCheckRegistry(Object healthCheckRegistry){ - this.healthCheckRegistry = healthCheckRegistry; - } - - public Properties getHealthCheckProperties(){ - return healthCheckProperties; - } - - public void setHealthCheckProperties(Properties healthCheckProperties){ - this.healthCheckProperties = healthCheckProperties; - } - -} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/TomcatPoolConfiguration.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/TomcatPoolConfiguration.java deleted file mode 100644 index 19d43f028..000000000 --- a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/TomcatPoolConfiguration.java +++ /dev/null @@ -1,1180 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. - * See the NOTICE file distributed with this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - * - * ========================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +-------------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | - * +-------------------------------------------------------------------------------------------------------+ - */ -package com.buession.jdbc.datasource.config; - -import com.buession.jdbc.core.TransactionIsolation; -import org.apache.tomcat.jdbc.pool.PoolProperties; - -import java.time.Duration; - -/** - * Tomcat 数据源连接池配置 {@link PoolProperties} - * - * @author Yong.Teng - * @since 1.3.2 - */ -public class TomcatPoolConfiguration extends AbstractPoolConfiguration { - - /** - * 连接池名称 - */ - private String name; - - /** - * 为支持 catalog 概念的数据库设置默认 catalog - */ - private String defaultCatalog; - - /** - * 初始化时建立连接的个数 - */ - private Integer initialSize; - - /** - * 最大连接池数量 - */ - private Integer maxActive; - - /** - * 最小空闲连接数 - */ - private Integer minIdle; - - /** - * 最大空闲连接数 - */ - private Integer maxIdle; - - /** - * 获取连接时最大等待时间,-1 表示不限制 - */ - private Duration maxWait; - - /** - * 以毫秒为单位的时间,以重新建立连接。 - * 当从池中借用连接时,池将检查 now - time-when-connected > maxAge是否已达到,如果是,则在借用之前重新连接; - * 当连接返回到池中时,池将检查 now - time-when-connected > maxAge是否已达到,如果是,则尝试重新连接; - * 当连接处于空闲状态并且 timeBetweenEvictionRunsMillis 大于零时,池将定期检查以查看是否 now - time-when-connected > - * maxAge 已达到,如果是,则尝试重新连接; - * 设置 maxAge 为小于该值 timeBetweenEvictionRunsMillis 将覆盖它(因此,空闲连接验证/清除将更频繁地运行)。 - * 默认值为0,这意味着连接将保持打开状态,并且从池中借用,将连接返回到池中或检查空闲连接时都不会进行年龄检查 - */ - private Long maxAge; - - /** - * 设置一个SQL语句,在将每个新连接创建后,将其添加到池中之前执行该语句 - */ - private String initSQL; - - /** - * 验证连接使用的 SQL - */ - private String validationQuery; - - /** - * 验证连接时间间隔 - */ - private Duration validationInterval; - - /** - * 验证SQL的执行超时时间,为负数表示关闭连接验证超时 - */ - private Duration validationQueryTimeout; - - /** - * 实现 {@link org.apache.tomcat.jdbc.pool.Validator} 接口并提供无参构造方法的实现类,用来替代连接验证SQL,对连接进行验证 - */ - private String validatorClassName; - - /** - * 将此属性设置为true可以在验证阶段将错误记录到日志文件中 - */ - private Boolean logValidationErrors; - - /** - * 创建连接时测试连接的有效性 - */ - private Boolean testOnConnect; - - /** - * 从连接池获取一个连接时,验证有效性; - * 指明在从池中租借对象时是否要进行验证有效,如果对象验证失败,则对象将从池子释放,然后我们将尝试租借另一个 - */ - private Boolean testOnBorrow; - - /** - * 连接被归还到连接池时,验证有效性 - */ - private Boolean testOnReturn; - - /** - * 连接空闲时,验证有效性; - * 指明对象是否需要通过对象驱逐者进行校验(如果有的话),假如一个对象验证失败,则对象将被从池中释放 - */ - private Boolean testWhileIdle; - - /** - * 空闲连接验证/清除线程的运行之间休眠时间 - */ - private Duration timeBetweenEvictionRuns; - - private Integer numTestsPerEvictionRun; - - /** - * 个对象在有资格被驱逐之前可以在池中空闲的最短时间 - */ - private Duration minEvictableIdleTime; - - /** - * 默认事务隔离级别 - */ - private TransactionIsolation defaultTransactionIsolation = TransactionIsolation.DEFAULT; - - /** - * 默认是否自动提交事务 - */ - private Boolean defaultAutoCommit; - - /** - * 连接归还到池时,设置为自动提交 - */ - private Boolean commitOnReturn; - - /** - * 连接归还到池时,是否回滚所有操作 - */ - private Boolean rollbackOnReturn; - - /** - * 默认连接是否是只读模式 - */ - private Boolean defaultReadOnly; - - /** - * 是否移除抛弃的(abandoned)连接,一个连接使用超过了 removeAbandonedTimeout 上限就被视为抛弃的, - * 开启该开关可以恢复那些应用没有关闭的连接 - */ - private Boolean removeAbandoned; - - /** - * 一个连接使用超过多久就视为抛弃的,该值应该超过你的应用中最长的SQL可能运行的时间 - */ - private Duration removeAbandonedTimeout; - - /** - * 记录抛弃连接的应用的堆栈信息; - * 会增加系统开销,因为为了能够在可能发生的连接被抛弃时记录堆栈 ,应用每次获取连接时都需要生成堆栈信息 - */ - private Boolean logAbandoned; - - /** - * 除非正在使用的连接数超过定义的百分比, - * 否则已放弃(超时)的连接不会关闭并报告 abandonWhenPercentageFull; - * 该值应介于0到100之间。默认值为0,这表示一旦 removeAbandonedTimeout 达到连接就可以关闭连接 - */ - private Integer abandonWhenPercentageFull; - - /** - * 与 removeAbandonedTimeout 值类似,但是不是将连接视为已放弃并可能关,而是将警告(如果 logAbandoned 设置为 true)记录下来。 - * 如果该值等于或小于0,将不执行任何可疑检查;仅当超时值大于0并且未放弃连接或禁用放弃检查时,才进行可疑检查; - * 如果怀疑连接,则记录 WARN 消息,并发送一次 JMX 通知 - */ - private Duration suspectTimeout = Duration.ofMillis(0L); - - private Boolean alternateUsernameAllowed; - - /** - * JDBC 拦截器,{@link org.apache.tomcat.jdbc.pool.JdbcInterceptor} 的实现 - */ - private String jdbcInterceptors; - - /** - * 标记初始化池时是否忽略连接创建错误;如果要在初始化池时忽略连接创建错误,请设置为true - */ - private Boolean ignoreExceptionOnPreLoad; - - private Boolean useEquals; - - private Boolean useLock; - - /** - * 如果希望以真正的 FIFO 方式公平对待对 getConnection 的调用,则设置为true。 - * 这将 {@link org.apache.tomcat.jdbc.pool.FairBlockingQueue} 实现用于空闲连接的列表。 - * 默认值为true。当您要使用异步连接检索时,此标志是必需的;设置此标志可确保线程按到达顺序接收连接。 - * 在性能测试期间,实现锁和等待锁的方式有很大的不同。 - * 当 fairQueue=true 存在基于系统在运行什么操作系统的决策过程时。 - * 如果系统在 Linux 上运行(属性 os.name=Linux)要禁用此Linux特定行为并仍使用公平队列,只需 org.apache.tomcat - * .jdbc.pool.FairBlockingQueue.ignoreOS=true 在加载连接池类之前将该属性添加到系统属性中即可 - */ - private Boolean fairQueue; - - /** - * 如果希望在连接上放置外观,则将其设置为true; - * 以使其在关闭后无法重复使用;这样可以防止线程保留已调用的已关闭连接的引用,以对其执行查询 - */ - private Boolean useDisposableConnectionFacade; - - /** - * 将此值设置为true可以传播已被中断的线程的中断状态(不清除中断状态) - */ - private Boolean propagateInterruptState; - - /** - * 如果希望包装语句以便启用,equals()并且hashCode()在设置了任何语句代理的情况下在关闭的语句上调用方法,请将其设置为true - */ - private Boolean useStatementFacade; - - private Boolean accessToUnderlyingConnectionAllowed; - - /** - * 是否启用 JMX - */ - private Boolean jmxEnabled; - - /** - * 返回连接池名称 - * - * @return 连接池名称 - */ - public String getName(){ - return name; - } - - /** - * 设置连接池名称 - * - * @param name - * 连接池名称 - */ - public void setName(String name){ - this.name = name; - } - - /** - * 返回为支持 catalog 概念的数据库设置默认 catalog - * - * @return 为支持 catalog 概念的数据库设置默认 catalog - */ - public String getDefaultCatalog(){ - return defaultCatalog; - } - - /** - * 设置为支持 catalog 概念的数据库设置默认 catalog - * - * @param defaultCatalog - * 为支持 catalog 概念的数据库设置默认 catalog - */ - public void setDefaultCatalog(String defaultCatalog){ - this.defaultCatalog = defaultCatalog; - } - - /** - * 返回初始连接数 - * - * @return 初始连接数 - */ - public Integer getInitialSize(){ - return initialSize; - } - - /** - * 设置初始连接数 - * - * @param initialSize - * 初始连接数 - */ - public void setInitialSize(Integer initialSize){ - this.initialSize = initialSize; - } - - /** - * 返回最大连接池数量 - * - * @return 最大连接池数量 - */ - public Integer getMaxActive(){ - return maxActive; - } - - /** - * 设置最大连接池数量 - * - * @param maxActive - * 最大连接池数量 - */ - public void setMaxActive(Integer maxActive){ - this.maxActive = maxActive; - } - - /** - * 返回最小空闲连接数 - * - * @return 最小空闲连接数 - */ - public Integer getMinIdle(){ - return minIdle; - } - - /** - * 设置最小空闲连接数 - * - * @param minIdle - * 最小空闲连接数 - */ - public void setMinIdle(Integer minIdle){ - this.minIdle = minIdle; - } - - /** - * 返回最大空闲连接数 - * - * @return 最大空闲连接数 - */ - public Integer getMaxIdle(){ - return maxIdle; - } - - /** - * 设置空闲连接数 - * - * @param maxIdle - * 最大空闲连接数 - */ - public void setMaxIdle(Integer maxIdle){ - this.maxIdle = maxIdle; - } - - /** - * 返回获取连接时最大等待时间 - * - * @return 获取连接时最大等待时间 - */ - public Duration getMaxWait(){ - return maxWait; - } - - /** - * 设置获取连接时最大等待时间 - * - * @param maxWait - * 获取连接时最大等待时间 - */ - public void setMaxWait(Duration maxWait){ - this.maxWait = maxWait; - } - - public Long getMaxAge(){ - return maxAge; - } - - public void setMaxAge(Long maxAge){ - this.maxAge = maxAge; - } - - /** - * 返回在将每个新连接创建后,将其添加到池中之前执行的SQL语句 - * - * @return 每个新连接创建后,将其添加到池中之前执行的SQL语句 - */ - public String getInitSQL(){ - return initSQL; - } - - /** - * 设置每个新连接创建后,将其添加到池中之前执行的SQL语句 - * - * @param initSQL - * 每个新连接创建后,将其添加到池中之前执行的SQL语句 - */ - public void setInitSQL(String initSQL){ - this.initSQL = initSQL; - } - - /** - * 返回验证连接使用的 SQL - * - * @return 验证连接使用的 SQL - */ - public String getValidationQuery(){ - return validationQuery; - } - - /** - * 设置验证连接使用的 SQL - * - * @param validationQuery - * 验证连接使用的 SQL - */ - public void setValidationQuery(String validationQuery){ - this.validationQuery = validationQuery; - } - - /** - * 返回验证连接时间间隔 - * - * @return 验证连接时间间隔 - */ - public Duration getValidationInterval(){ - return validationInterval; - } - - /** - * 设置验证连接时间间隔 - * - * @param validationInterval - * 验证连接时间间隔 - */ - public void setValidationInterval(Duration validationInterval){ - this.validationInterval = validationInterval; - } - - /** - * 返回验证SQL的执行超时时间,为负数表示关闭连接验证超时 - * - * @return 验证SQL的执行超时时间 - */ - public Duration getValidationQueryTimeout(){ - return validationQueryTimeout; - } - - /** - * 设置验证SQL的执行超时时间,为负数表示关闭连接验证超时 - * - * @param validationQueryTimeout - * 验证SQL的执行超时时间 - */ - public void setValidationQueryTimeout(Duration validationQueryTimeout){ - this.validationQueryTimeout = validationQueryTimeout; - } - - /** - * 返回实现 org.apache.tomcat.jdbc.pool.Validator 接口并提供无参构造方法的实现类,用来替代连接验证SQL,对连接进行验证的类名 - * - * @return 实现 org.apache.tomcat.jdbc.pool.Validator 接口并提供无参构造方法的实现类,用来替代连接验证SQL,对连接进行验证的类名 - */ - public String getValidatorClassName(){ - return validatorClassName; - } - - /** - * 设置实现 org.apache.tomcat.jdbc.pool.Validator 接口并提供无参构造方法的实现类,用来替代连接验证SQL,对连接进行验证的类名 - * - * @param validatorClassName - * 实现 org.apache.tomcat.jdbc.pool.Validator 接口并提供无参构造方法的实现类,用来替代连接验证SQL,对连接进行验证的类名 - */ - public void setValidatorClassName(String validatorClassName){ - this.validatorClassName = validatorClassName; - } - - /** - * 返回验证阶段将错误记录到日志文件中 - * - * @return 验证阶段将错误记录到日志文件中 - */ - @Deprecated - public Boolean isLogValidationErrors(){ - return getLogValidationErrors(); - } - - /** - * 返回验证阶段将错误记录到日志文件中 - * - * @return 验证阶段将错误记录到日志文件中 - */ - public Boolean getLogValidationErrors(){ - return logValidationErrors; - } - - /** - * 设置验证阶段将错误记录到日志文件中 - * - * @param logValidationErrors - * 验证阶段将错误记录到日志文件中 - */ - public void setLogValidationErrors(Boolean logValidationErrors){ - this.logValidationErrors = logValidationErrors; - } - - /** - * 返回创建连接时是否测试连接的有效性 - * - * @return 创建连接时是否测试连接的有效性 - */ - @Deprecated - public Boolean isTestOnConnect(){ - return getTestOnConnect(); - } - - /** - * 返回创建连接时是否测试连接的有效性 - * - * @return 创建连接时是否测试连接的有效性 - */ - public Boolean getTestOnConnect(){ - return testOnConnect; - } - - /** - * 设置创建连接时是否测试连接的有效性 - * - * @param testOnConnect - * 创建连接时是否测试连接的有效性 - */ - public void setTestOnConnect(Boolean testOnConnect){ - this.testOnConnect = testOnConnect; - } - - /** - * 返回从连接池获取一个连接时,是否验证有效性 - * - * @return 从连接池获取一个连接时,验证有效性 - */ - @Deprecated - public Boolean isTestOnBorrow(){ - return getTestOnBorrow(); - } - - /** - * 返回从连接池获取一个连接时,是否验证有效性 - * - * @return 从连接池获取一个连接时,验证有效性 - */ - public Boolean getTestOnBorrow(){ - return testOnBorrow; - } - - /** - * 设置从连接池获取一个连接时,是否验证有效性 - * - * @param testOnBorrow - * 从连接池获取一个连接时,是否验证有效性 - */ - public void setTestOnBorrow(Boolean testOnBorrow){ - this.testOnBorrow = testOnBorrow; - } - - /** - * 返回连接被归还到连接池时,是否验证有效性 - * - * @return 连接被归还到连接池时,是否验证有效性 - */ - @Deprecated - public Boolean isTestOnReturn(){ - return getTestOnReturn(); - } - - /** - * 返回连接被归还到连接池时,是否验证有效性 - * - * @return 连接被归还到连接池时,是否验证有效性 - */ - public Boolean getTestOnReturn(){ - return testOnReturn; - } - - /** - * 设置连接被归还到连接池时,是否验证有效性 - * - * @param testOnReturn - * 连接被归还到连接池时,是否验证有效性 - */ - @Deprecated - public void setTestOnReturn(Boolean testOnReturn){ - this.testOnReturn = testOnReturn; - } - - /** - * 返回连接空闲时,是否验证有效性 - * - * @return 连接空闲时,是否验证有效性 - */ - @Deprecated - public Boolean isTestWhileIdle(){ - return getTestWhileIdle(); - } - - /** - * 返回连接空闲时,是否验证有效性 - * - * @return 连接空闲时,是否验证有效性 - */ - public Boolean getTestWhileIdle(){ - return testWhileIdle; - } - - /** - * 设置连接空闲时,是否验证有效性 - * - * @param testWhileIdle - * 连接空闲时,是否验证有效性 - */ - public void setTestWhileIdle(Boolean testWhileIdle){ - this.testWhileIdle = testWhileIdle; - } - - /** - * 返回空闲连接验证/清除线程的运行之间休眠时间 - * - * @return 空闲连接验证/清除线程的运行之间休眠时间 - */ - public Duration getTimeBetweenEvictionRuns(){ - return timeBetweenEvictionRuns; - } - - /** - * 设置空闲连接验证/清除线程的运行之间休眠时间 - * - * @param timeBetweenEvictionRuns - * 空闲连接验证/清除线程的运行之间休眠时间 - */ - public void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns){ - this.timeBetweenEvictionRuns = timeBetweenEvictionRuns; - } - - public Integer getNumTestsPerEvictionRun(){ - return numTestsPerEvictionRun; - } - - public void setNumTestsPerEvictionRun(Integer numTestsPerEvictionRun){ - this.numTestsPerEvictionRun = numTestsPerEvictionRun; - } - - /** - * 返回一个对象在有资格被驱逐之前可以在池中空闲的最短时间 - * - * @return 一个对象在有资格被驱逐之前可以在池中空闲的最短时间 - */ - public Duration getMinEvictableIdleTime(){ - return minEvictableIdleTime; - } - - /** - * 设置一个对象在有资格被驱逐之前可以在池中空闲的最短时间 - * - * @param minEvictableIdleTime - * 一个对象在有资格被驱逐之前可以在池中空闲的最短时间 - */ - public void setMinEvictableIdleTime(Duration minEvictableIdleTime){ - this.minEvictableIdleTime = minEvictableIdleTime; - } - - /** - * 返回默认事务隔离级别 - * - * @return 默认事务隔离级别 - */ - public TransactionIsolation getDefaultTransactionIsolation(){ - return defaultTransactionIsolation; - } - - /** - * 设置默认事务隔离级别 - * - * @param defaultTransactionIsolation - * 默认事务隔离级别 - */ - public void setDefaultTransactionIsolation(TransactionIsolation defaultTransactionIsolation){ - this.defaultTransactionIsolation = defaultTransactionIsolation; - } - - /** - * 返回连接归还到池时,设置为自动提交 - * - * @return 连接归还到池时,设置为自动提交 - */ - @Deprecated - public Boolean isCommitOnReturn(){ - return getCommitOnReturn(); - } - - /** - * 返回连接归还到池时,设置为自动提交 - * - * @return 连接归还到池时,设置为自动提交 - */ - public Boolean getCommitOnReturn(){ - return commitOnReturn; - } - - /** - * 设置连接归还到池时,是否自动提交 - * - * @param commitOnReturn - * 连接归还到池时,是否自动提交 - */ - public void setCommitOnReturn(Boolean commitOnReturn){ - this.commitOnReturn = commitOnReturn; - } - - /** - * 返回连接归还到池时,是否回滚所有操作 - * - * @return 连接归还到池时,是否回滚所有操作 - */ - @Deprecated - public Boolean isRollbackOnReturn(){ - return getRollbackOnReturn(); - } - - /** - * 返回连接归还到池时,是否回滚所有操作 - * - * @return 连接归还到池时,是否回滚所有操作 - */ - public Boolean getRollbackOnReturn(){ - return rollbackOnReturn; - } - - /** - * 设置连接归还到池时,是否回滚所有操作 - * - * @param rollbackOnReturn - * 连接归还到池时,是否回滚所有操作 - */ - public void setRollbackOnReturn(Boolean rollbackOnReturn){ - this.rollbackOnReturn = rollbackOnReturn; - } - - /** - * 返回是否自动提交事务 - * - * @return 是否自动提交事务 - */ - @Deprecated - public Boolean isDefaultAutoCommit(){ - return getDefaultAutoCommit(); - } - - /** - * 返回是否自动提交事务 - * - * @return 是否自动提交事务 - */ - public Boolean getDefaultAutoCommit(){ - return defaultAutoCommit; - } - - /** - * 设置是否自动提交事务 - * - * @param defaultAutoCommit - * 是否自动提交事务 - */ - public void setDefaultAutoCommit(Boolean defaultAutoCommit){ - this.defaultAutoCommit = defaultAutoCommit; - } - - /** - * 返回连接是否是只读模式 - * - * @return 连接是否是只读模式 - */ - @Deprecated - public Boolean isDefaultReadOnly(){ - return getDefaultReadOnly(); - } - - /** - * 返回连接是否是只读模式 - * - * @return 连接是否是只读模式 - */ - public Boolean getDefaultReadOnly(){ - return defaultReadOnly; - } - - /** - * 设置连接是否是只读模式 - * - * @param defaultReadOnly - * 连接是否是只读模式 - */ - public void setDefaultReadOnly(Boolean defaultReadOnly){ - this.defaultReadOnly = defaultReadOnly; - } - - /** - * 返回是否移除抛弃的(abandoned)连接 - * - * @return 是否移除抛弃的(abandoned)连接 - */ - @Deprecated - public Boolean isRemoveAbandoned(){ - return getRemoveAbandoned(); - } - - /** - * 返回是否移除抛弃的(abandoned)连接 - * - * @return 是否移除抛弃的(abandoned)连接 - */ - public Boolean getRemoveAbandoned(){ - return removeAbandoned; - } - - /** - * 设置是否移除抛弃的(abandoned)连接 - * - * @param removeAbandoned - * 是否移除抛弃的(abandoned)连接 - */ - public void setRemoveAbandoned(Boolean removeAbandoned){ - this.removeAbandoned = removeAbandoned; - } - - /** - * 返回一个连接使用超过多久就视为抛弃的 - * - * @return 一个连接使用超过多久就视为抛弃的 - */ - public Duration getRemoveAbandonedTimeout(){ - return removeAbandonedTimeout; - } - - /** - * 设置一个连接使用超过多久就视为抛弃的,该值应该超过你的应用中最长的SQL可能运行的时间 - * - * @param removeAbandonedTimeout - * 一个连接使用超过多久就视为抛弃的,该值应该超过你的应用中最长的SQL可能运行的时间 - */ - public void setRemoveAbandonedTimeout(Duration removeAbandonedTimeout){ - this.removeAbandonedTimeout = removeAbandonedTimeout; - } - - /** - * 返回是否记录抛弃连接的应用的堆栈信息 - * - * @return 是否记录抛弃连接的应用的堆栈信息 - */ - @Deprecated - public Boolean isLogAbandoned(){ - return getLogAbandoned(); - } - - /** - * 返回是否记录抛弃连接的应用的堆栈信息 - * - * @return 是否记录抛弃连接的应用的堆栈信息 - */ - public Boolean getLogAbandoned(){ - return logAbandoned; - } - - /** - * 设置是否记录抛弃连接的应用的堆栈信息 - * - * @param logAbandoned - * 是否记录抛弃连接的应用的堆栈信息 - */ - public void setLogAbandoned(Boolean logAbandoned){ - this.logAbandoned = logAbandoned; - } - - /** - * 返回正在使用的连接数超过定义的百分比 - * - * @return 正在使用的连接数超过定义的百分比 - */ - public Integer getAbandonWhenPercentageFull(){ - return abandonWhenPercentageFull; - } - - /** - * 设置正在使用的连接数超过定义的百分比 - * - * @param abandonWhenPercentageFull - * 正在使用的连接数超过定义的百分比 - */ - public void setAbandonWhenPercentageFull(Integer abandonWhenPercentageFull){ - this.abandonWhenPercentageFull = abandonWhenPercentageFull; - } - - /** - * 超时 - * - * @return 超时 - */ - public Duration getSuspectTimeout(){ - return suspectTimeout; - } - - /** - * 超时 - * - * @param suspectTimeout - * 超时 - */ - public void setSuspectTimeout(Duration suspectTimeout){ - this.suspectTimeout = suspectTimeout; - } - - @Deprecated - public Boolean isAlternateUsernameAllowed(){ - return getAlternateUsernameAllowed(); - } - - public Boolean getAlternateUsernameAllowed(){ - return alternateUsernameAllowed; - } - - public void setAlternateUsernameAllowed(Boolean alternateUsernameAllowed){ - this.alternateUsernameAllowed = alternateUsernameAllowed; - } - - /** - * 返回 JDBC 拦截器,{@link org.apache.tomcat.jdbc.pool.JdbcInterceptor} 的实现 - * - * @return JDBC 拦截器 - */ - public String getJdbcInterceptors(){ - return jdbcInterceptors; - } - - /** - * 设置 JDBC 拦截器,{@link org.apache.tomcat.jdbc.pool.JdbcInterceptor} 的实现 - * - * @param jdbcInterceptors - * JDBC 拦截器 - */ - public void setJdbcInterceptors(String jdbcInterceptors){ - this.jdbcInterceptors = jdbcInterceptors; - } - - /** - * 返回标记初始化池时是否忽略连接创建错误 - * - * @return 初始化池时是否忽略连接创建错误 - */ - @Deprecated - public Boolean isIgnoreExceptionOnPreLoad(){ - return getIgnoreExceptionOnPreLoad(); - } - - /** - * 返回标记初始化池时是否忽略连接创建错误 - * - * @return 初始化池时是否忽略连接创建错误 - */ - public Boolean getIgnoreExceptionOnPreLoad(){ - return ignoreExceptionOnPreLoad; - } - - /** - * 设置标记初始化池时是否忽略连接创建错误;如果要在初始化池时忽略连接创建错误,请设置为true - * - * @param ignoreExceptionOnPreLoad - * 初始化池时是否忽略连接创建错误 - */ - public void setIgnoreExceptionOnPreLoad(Boolean ignoreExceptionOnPreLoad){ - this.ignoreExceptionOnPreLoad = ignoreExceptionOnPreLoad; - } - - @Deprecated - public Boolean isUseEquals(){ - return getUseEquals(); - } - - public Boolean getUseEquals(){ - return useEquals; - } - - public void setUseEquals(Boolean useEquals){ - this.useEquals = useEquals; - } - - @Deprecated - public Boolean isUseLock(){ - return getUseLock(); - } - - public Boolean getUseLock(){ - return useLock; - } - - public void setUseLock(Boolean useLock){ - this.useLock = useLock; - } - - /** - * 返回是否以真正的 FIFO 方式公平对待对 getConnection 的调用 - * - * @return 是否以真正的 FIFO 方式公平对待对 getConnection 的调用 - */ - @Deprecated - public Boolean isFairQueue(){ - return getFairQueue(); - } - - /** - * 返回是否以真正的 FIFO 方式公平对待对 getConnection 的调用 - * - * @return 是否以真正的 FIFO 方式公平对待对 getConnection 的调用 - */ - public Boolean getFairQueue(){ - return fairQueue; - } - - /** - * 设置是否以真正的 FIFO 方式公平对待对 getConnection 的调用 - * - * @param fairQueue - * 是否以真正的 FIFO 方式公平对待对 getConnection 的调用 - */ - public void setFairQueue(Boolean fairQueue){ - this.fairQueue = fairQueue; - } - - /** - * 返回希望在连接上放置外观 - * - * @return 希望在连接上放置外观 - */ - @Deprecated - public Boolean isUseDisposableConnectionFacade(){ - return getUseDisposableConnectionFacade(); - } - - /** - * 返回希望在连接上放置外观 - * - * @return 希望在连接上放置外观 - */ - public boolean getUseDisposableConnectionFacade(){ - return useDisposableConnectionFacade; - } - - /** - * 设置希望在连接上放置外观,则将其设置为true,以使其在关闭后无法重复使用; - * 这样可以防止线程保留已调用的已关闭连接的引用 - * - * @param useDisposableConnectionFacade - * 希望在连接上放置外观 - */ - public void setUseDisposableConnectionFacade(Boolean useDisposableConnectionFacade){ - this.useDisposableConnectionFacade = useDisposableConnectionFacade; - } - - /** - * 返回是否传播已被中断的线程的中断状态 - * - * @return 是否传播已被中断的线程的中断状态 - */ - @Deprecated - public Boolean isPropagateInterruptState(){ - return getPropagateInterruptState(); - } - - /** - * 返回是否传播已被中断的线程的中断状态 - * - * @return 是否传播已被中断的线程的中断状态 - */ - public Boolean getPropagateInterruptState(){ - return propagateInterruptState; - } - - /** - * 设置是否传播已被中断的线程的中断状态 - * - * @param propagateInterruptState - * 是否传播已被中断的线程的中断状态 - */ - public void setPropagateInterruptState(Boolean propagateInterruptState){ - this.propagateInterruptState = propagateInterruptState; - } - - /** - * 返回是否希望包装语句以便启用,equals() - * - * @return 是否希望包装语句以便启用,equals() - */ - @Deprecated - public Boolean isUseStatementFacade(){ - return getUseStatementFacade(); - } - - /** - * 返回是否希望包装语句以便启用,equals() - * - * @return 是否希望包装语句以便启用,equals() - */ - public boolean getUseStatementFacade(){ - return useStatementFacade; - } - - /** - * 设置是否希望包装语句以便启用,equals() - * - * @param useStatementFacade - * 是否希望包装语句以便启用,equals() - */ - public void setUseStatementFacade(Boolean useStatementFacade){ - this.useStatementFacade = useStatementFacade; - } - - @Deprecated - public Boolean isAccessToUnderlyingConnectionAllowed(){ - return getAccessToUnderlyingConnectionAllowed(); - } - - public Boolean getAccessToUnderlyingConnectionAllowed(){ - return accessToUnderlyingConnectionAllowed; - } - - public void setAccessToUnderlyingConnectionAllowed(Boolean accessToUnderlyingConnectionAllowed){ - this.accessToUnderlyingConnectionAllowed = accessToUnderlyingConnectionAllowed; - } - - /** - * 返回是否启用 JMX - * - * @return 是否启用 JMX - */ - @Deprecated - public Boolean isJmxEnabled(){ - return getJmxEnabled(); - } - - /** - * 返回是否启用 JMX - * - * @return 是否启用 JMX - */ - public Boolean getJmxEnabled(){ - return jmxEnabled; - } - - /** - * 设置是否启用 JMX - * - * @param jmxEnabled - * 是否启用 JMX - */ - public void setJmxEnabled(Boolean jmxEnabled){ - this.jmxEnabled = jmxEnabled; - } - -} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/AbstractPoolConfiguration.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/AbstractPoolConfiguration.java new file mode 100644 index 000000000..e47c79e65 --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/AbstractPoolConfiguration.java @@ -0,0 +1,304 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.datasource.pool; + +import com.buession.jdbc.core.Jmx; + +import java.time.Duration; + +/** + * 连接池配置基类 + * + * @author Yong.Teng + * @since 1.3.2 + */ +public abstract class AbstractPoolConfiguration implements PoolConfiguration { + + /** + * 连接池的名称 + */ + private String poolName; + + /** + * 初始连接数,池被启动时初始化的创建的连接个数 + */ + private Integer initialSize; + + /** + * 最小空闲连接数,可以在池中保持空闲的最小连接数,低于设置值时,空闲连接将被创建,以努力保持最小空闲连接数 >= minIdle + */ + private Integer minIdle; + + /** + * 最大空闲连接数,在池中,可以保持空闲状态的最大连接数,超出设置值之外的空闲连接在归还到连接池时将被释放,如设置为负数,则不限制 + */ + private Integer maxIdle; + + /** + * 最大连接数,可以在这个池中同一时刻被分配的有效连接数的最大值,如设置为负数,则不限制 + */ + private Integer maxTotal; + + /** + * 从连接池获取一个连接时,最大的等待时间,设置为-1时,如果没有可用连接,连接池会一直无限期等待,直到获取到连接为止 + */ + private Duration maxWait; + + /** + * 连接创建后,马上验证有效性; + * 指明对象在创建后是否需要验证是否有效,如果对象验证失败,则触发对象创建的租借尝试将失败 + */ + private Boolean testOnCreate; + + /** + * 从连接池获取一个连接时,验证有效性; + * 指明在从池中租借对象时是否要进行验证有效,如果对象验证失败,则对象将从池子释放,然后我们将尝试租借另一个 + */ + private Boolean testOnBorrow; + + /** + * 连接被归还到连接池时,验证有效性 + */ + private Boolean testOnReturn; + + /** + * 连接空闲时,验证有效性; + * 指明对象是否需要通过对象驱逐者进行校验(如果有的话),假如一个对象验证失败,则对象将被从池中释放 + */ + private Boolean testWhileIdle; + + /** + * 设置一个SQL语句, 从连接池获取连接时, 先执行改 sql, 验证连接是否可用 + */ + private String validationQuery; + + /** + * 连接有效SQL的执行查询超时时间 + */ + private Duration validationQueryTimeout; + + /** + * 空闲的连接被释放最低要待时间 + */ + private Duration minEvictableIdle; + + /** + * 空闲的连接被释放最高要待时间 + */ + private Duration maxEvictableIdle; + + /** + * 在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 + */ + private Integer numTestsPerEvictionRun; + + /** + * 空闲对象驱逐线程运行时的休眠时间 + */ + private Duration timeBetweenEvictionRuns; + + /** + * 当连接被认为是废弃并且被移除时是否记录日志 + * + * @since 3.0.0 + */ + private Boolean logAbandoned; + + /** + * 指定连接在被认为是废弃连接(abandoned connection)之前的超时时间 + * + * @since 3.0.0 + */ + private Duration removeAbandonedTimeout; + + /** + * JMX 管理对象配置 + */ + private Jmx jmx; + + /** + * 返回用户定义连接池的名称 + * + * @return 用户定义连接池的名称 + */ + public String getPoolName() { + return poolName; + } + + public void setPoolName(String poolName) { + this.poolName = poolName; + } + + public Integer getInitialSize() { + return initialSize; + } + + public void setInitialSize(Integer initialSize) { + this.initialSize = initialSize; + } + + public Integer getMinIdle() { + return minIdle; + } + + public void setMinIdle(Integer minIdle) { + this.minIdle = minIdle; + } + + public Integer getMaxIdle() { + return maxIdle; + } + + public void setMaxIdle(Integer maxIdle) { + this.maxIdle = maxIdle; + } + + public Integer getMaxTotal() { + return maxTotal; + } + + public void setMaxTotal(Integer maxTotal) { + this.maxTotal = maxTotal; + } + + public Duration getMaxWait() { + return maxWait; + } + + public void setMaxWait(Duration maxWait) { + this.maxWait = maxWait; + } + + public Boolean getTestOnCreate() { + return testOnCreate; + } + + public void setTestOnCreate(Boolean testOnCreate) { + this.testOnCreate = testOnCreate; + } + + public Boolean getTestOnBorrow() { + return testOnBorrow; + } + + public void setTestOnBorrow(Boolean testOnBorrow) { + this.testOnBorrow = testOnBorrow; + } + + public Boolean getTestOnReturn() { + return testOnReturn; + } + + public void setTestOnReturn(Boolean testOnReturn) { + this.testOnReturn = testOnReturn; + } + + public Boolean getTestWhileIdle() { + return testWhileIdle; + } + + public void setTestWhileIdle(Boolean testWhileIdle) { + this.testWhileIdle = testWhileIdle; + } + + @Override + public String getValidationQuery() { + return validationQuery; + } + + @Override + public void setValidationQuery(String validationQuery) { + this.validationQuery = validationQuery; + } + + @Override + public Duration getValidationQueryTimeout() { + return validationQueryTimeout; + } + + @Override + public void setValidationQueryTimeout(Duration validationQueryTimeout) { + this.validationQueryTimeout = validationQueryTimeout; + } + + public Duration getMinEvictableIdle() { + return minEvictableIdle; + } + + public void setMinEvictableIdle(Duration minEvictableIdle) { + this.minEvictableIdle = minEvictableIdle; + } + + public Duration getMaxEvictableIdle() { + return maxEvictableIdle; + } + + public void setMaxEvictableIdle(Duration maxEvictableIdle) { + this.maxEvictableIdle = maxEvictableIdle; + } + + public Integer getNumTestsPerEvictionRun() { + return numTestsPerEvictionRun; + } + + public void setNumTestsPerEvictionRun(Integer numTestsPerEvictionRun) { + this.numTestsPerEvictionRun = numTestsPerEvictionRun; + } + + public Duration getTimeBetweenEvictionRuns() { + return timeBetweenEvictionRuns; + } + + public void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns) { + this.timeBetweenEvictionRuns = timeBetweenEvictionRuns; + } + + public Boolean getLogAbandoned() { + return logAbandoned; + } + + public void setLogAbandoned(Boolean logAbandoned) { + this.logAbandoned = logAbandoned; + } + + public Duration getRemoveAbandonedTimeout() { + return removeAbandonedTimeout; + } + + public void setRemoveAbandonedTimeout(Duration removeAbandonedTimeout) { + this.removeAbandonedTimeout = removeAbandonedTimeout; + } + + @Override + public Jmx getJmx() { + return jmx; + } + + @Override + public void setJmx(Jmx jmx) { + this.jmx = jmx; + } + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/Dbcp2PoolConfiguration.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/Dbcp2PoolConfiguration.java new file mode 100644 index 000000000..10c92df02 --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/Dbcp2PoolConfiguration.java @@ -0,0 +1,414 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.datasource.pool; + +import com.buession.jdbc.core.Jmx; +import org.apache.commons.dbcp2.BasicDataSource; + +import java.sql.PreparedStatement; +import java.time.Duration; + +/** + * Dhcp2 数据源连接池配置 {@link BasicDataSource} + * + * @author Yong.Teng + * @since 1.3.2 + */ +public class Dbcp2PoolConfiguration extends AbstractPoolConfiguration { + + /** + * 连接的最大存活时间; + * 如果超过这个时间,则连接在下次激活、钝化、校验时都将会失败。如果设置为0或小于0的值,则连接的存活时间是无限的 + */ + private Duration maxConnLifetime; + + /** + * 是否缓存 preparedStatement,也就是PSCache; + * PSCache 对支持游标的数据库性能提升巨大,比如说 oracle,在mysql下建议关闭 + */ + private Boolean poolPreparedStatements; + + /** + * 可以在语句池中同时分配的最大语句数 + */ + private Integer maxOpenPreparedStatements; + + /** + * 是否清除与该连接关联的已缓存的 {@link PreparedStatement} 对象;启用后,每次连接返回到池中时,所有缓存的 PreparedStatement 对象都会被清除 + */ + private Boolean clearStatementPoolOnReturn; + + /** + * 从连接池借用连接时是否对废弃连接的检查 + * + * @since 3.0.0 + */ + private Boolean removeAbandonedOnBorrow; + + /** + * 后台维护线程会在运行时定期检查连接池中的连接,并移除那些被认为是废弃的连接 + * + * @since 3.0.0 + */ + private Boolean removeAbandonedOnMaintenance; + + /** + * 是否在每次连接被借出时记录当前的堆栈跟踪信息 + * + * @since 3.0.0 + */ + private Boolean abandonedUsageTracking; + + /** + * 空闲的连接被释放最低要待时间,但有额外条件 + * 额外的条件是池中至少保留有 minIdle 所指定的个数的连接; + * 当 miniEvictableIdleTime 被设置为一个正数,空闲连接驱逐者首先检测 miniEvictableIdleTime , + * 当空闲连接被驱逐者访问时,首先与 miniEvictableIdleTime 所指定的值进行比较(而不考虑当前池中的空闲连接数), + * 然后比较 softMinEvictableIdleTime 所指定的连接数,包括 minIdle 条件 + */ + private Duration softMinEvictableIdle; + + /** + * 空闲对象驱逐策略名称 + */ + private String evictionPolicyClassName; + + /** + * 后进先出,设置为true表明连接池(如果池中有可用的空闲连接时)将返回最后一次使用的租借对象(最后进入), + * 设置为false则表明池将表现为FIFO队列(先进先出)—将会按照它们被归还的顺序从空闲连接实例池中获取连接 + */ + private Boolean lifo; + + /** + * 是否将连接池的管理信息注册为 JMX (Java Management Extensions) MBean + * + * @since 3.0.0 + */ + private Boolean registerConnectionMBean; + + /** + * 返回连接的最大存活时间 + * + * @return 连接的最大存活时间 + */ + public Duration getMaxConnLifetime() { + return maxConnLifetime; + } + + /** + * 设置连接的最大存活时间 + * + * @param maxConnLifetime + * 连接的最大存活时间 + */ + public void setMaxConnLifetime(Duration maxConnLifetime) { + this.maxConnLifetime = maxConnLifetime; + } + + /** + * 返回是否缓存 preparedStatement,也就是PSCache + * + * @return 是否缓存 preparedStatement,也就是PSCache + */ + public Boolean isPoolPreparedStatements() { + return getPoolPreparedStatements(); + } + + /** + * 返回是否缓存 preparedStatement,也就是PSCache + * + * @return 是否缓存 preparedStatement,也就是PSCache + */ + public Boolean getPoolPreparedStatements() { + return poolPreparedStatements; + } + + /** + * 设置是否缓存 preparedStatement,也就是PSCache; + * PSCache 对支持游标的数据库性能提升巨大,比如说 oracle,在mysql下建议关闭 + * + * @param poolPreparedStatements + * 是否缓存 preparedStatement + */ + public void setPoolPreparedStatements(Boolean poolPreparedStatements) { + this.poolPreparedStatements = poolPreparedStatements; + } + + /** + * 返回可以在语句池中同时分配的最大语句数 + * + * @return 可以在语句池中同时分配的最大语句数 + */ + public Integer getMaxOpenPreparedStatements() { + return maxOpenPreparedStatements; + } + + /** + * 设置可以在语句池中同时分配的最大语句数 + * + * @param maxOpenPreparedStatements + * 可以在语句池中同时分配的最大语句数 + */ + public void setMaxOpenPreparedStatements(Integer maxOpenPreparedStatements) { + this.maxOpenPreparedStatements = maxOpenPreparedStatements; + } + + /** + * 返回是否清除与该连接关联的已缓存的 {@link PreparedStatement} 对象 + * + * @return 是否清除与该连接关联的已缓存的 {@link PreparedStatement} 对象 + */ + public Boolean isClearStatementPoolOnReturn() { + return getClearStatementPoolOnReturn(); + } + + /** + * 返回是否清除与该连接关联的已缓存的 {@link PreparedStatement} 对象 + * + * @return 是否清除与该连接关联的已缓存的 {@link PreparedStatement} 对象 + */ + public Boolean getClearStatementPoolOnReturn() { + return clearStatementPoolOnReturn; + } + + /** + * 设置是否清除与该连接关联的已缓存的 {@link PreparedStatement} 对象;启用后,每次连接返回到池中时,所有缓存的 PreparedStatement 对象都会被清除 + * + * @param clearStatementPoolOnReturn + * 是否清除与该连接关联的已缓存的 {@link PreparedStatement} 对象 + */ + public void setClearStatementPoolOnReturn(Boolean clearStatementPoolOnReturn) { + this.clearStatementPoolOnReturn = clearStatementPoolOnReturn; + } + + /** + * 返回从连接池借用连接时是否对废弃连接的检查 + * + * @return 从连接池借用连接时是否对废弃连接的检查 + * + * @since 3.0.0 + */ + public Boolean isRemoveAbandonedOnBorrow() { + return getRemoveAbandonedOnBorrow(); + } + + /** + * 返回从连接池借用连接时是否对废弃连接的检查 + * + * @return 从连接池借用连接时是否对废弃连接的检查 + * + * @since 3.0.0 + */ + public Boolean getRemoveAbandonedOnBorrow() { + return removeAbandonedOnBorrow; + } + + /** + * 设置从连接池借用连接时是否对废弃连接的检查 + * + * @param removeAbandonedOnBorrow + * 从连接池借用连接时是否对废弃连接的检查 + * + * @since 3.0.0 + */ + public void setRemoveAbandonedOnBorrow(Boolean removeAbandonedOnBorrow) { + this.removeAbandonedOnBorrow = removeAbandonedOnBorrow; + } + + /** + * 返回后台维护线程会在运行时定期检查连接池中的连接,并移除那些被认为是废弃的连接 + * + * @return 后台维护线程会在运行时定期检查连接池中的连接,并移除那些被认为是废弃的连接 + * + * @since 3.0.0 + */ + public Boolean isRemoveAbandonedOnMaintenance() { + return getRemoveAbandonedOnMaintenance(); + } + + /** + * 返回后台维护线程会在运行时定期检查连接池中的连接,并移除那些被认为是废弃的连接 + * + * @return 后台维护线程会在运行时定期检查连接池中的连接,并移除那些被认为是废弃的连接 + * + * @since 3.0.0 + */ + public Boolean getRemoveAbandonedOnMaintenance() { + return removeAbandonedOnMaintenance; + } + + /** + * 设置后台维护线程会在运行时定期检查连接池中的连接,并移除那些被认为是废弃的连接 + * + * @param removeAbandonedOnMaintenance + * 后台维护线程会在运行时定期检查连接池中的连接,并移除那些被认为是废弃的连接 + * + * @since 3.0.0 + */ + public void setRemoveAbandonedOnMaintenance(Boolean removeAbandonedOnMaintenance) { + this.removeAbandonedOnMaintenance = removeAbandonedOnMaintenance; + } + + /** + * 返回是否在每次连接被借出时记录当前的堆栈跟踪信息 + * + * @return 是否在每次连接被借出时记录当前的堆栈跟踪信息 + * + * @since 3.0.0 + */ + public Boolean isAbandonedUsageTracking() { + return getAbandonedUsageTracking(); + } + + /** + * 返回是否在每次连接被借出时记录当前的堆栈跟踪信息 + * + * @return 是否在每次连接被借出时记录当前的堆栈跟踪信息 + * + * @since 3.0.0 + */ + public Boolean getAbandonedUsageTracking() { + return abandonedUsageTracking; + } + + /** + * 设置是否在每次连接被借出时记录当前的堆栈跟踪信息 + * + * @param abandonedUsageTracking + * 是否在每次连接被借出时记录当前的堆栈跟踪信息 + * + * @since 3.0.0 + */ + public void setAbandonedUsageTracking(Boolean abandonedUsageTracking) { + this.abandonedUsageTracking = abandonedUsageTracking; + } + + /** + * 返回空闲的连接被释放最低要待时间,但有额外条件 + * + * @return 空闲的连接被释放最低要待时间 + */ + public Duration getSoftMinEvictableIdle() { + return softMinEvictableIdle; + } + + /** + * 设置空闲的连接被释放最低要待时间 + * + * @param softMinEvictableIdle + * 空闲的连接被释放最低要待时间 + */ + public void setSoftMinEvictableIdle(Duration softMinEvictableIdle) { + this.softMinEvictableIdle = softMinEvictableIdle; + } + + /** + * 返回空闲对象驱逐策略名称 + * + * @return 空闲对象驱逐策略名称 + */ + public String getEvictionPolicyClassName() { + return evictionPolicyClassName; + } + + /** + * 设置空闲对象驱逐策略名称 + * + * @param evictionPolicyClassName + * 空闲对象驱逐策略名称 + */ + public void setEvictionPolicyClassName(String evictionPolicyClassName) { + this.evictionPolicyClassName = evictionPolicyClassName; + } + + /** + * 是否后进先出 + * + * @return 后进先出 + */ + public Boolean isLifo() { + return getLifo(); + } + + /** + * 是否后进先出 + * + * @return 后进先出 + */ + public Boolean getLifo() { + return lifo; + } + + /** + * 设置后进先出 + * + * @param lifo + * 后进先出 + */ + public void setLifo(Boolean lifo) { + this.lifo = lifo; + } + + /** + * 返回是否将连接池的管理信息注册为 JMX (Java Management Extensions) MBean + * + * @return 是否将连接池的管理信息注册为 JMX (Java Management Extensions) MBean + */ + public Boolean isRegisterConnectionMBean() { + return getRegisterConnectionMBean(); + } + + /** + * 返回是否将连接池的管理信息注册为 JMX (Java Management Extensions) MBean + * + * @return 是否将连接池的管理信息注册为 JMX (Java Management Extensions) MBean + */ + public Boolean getRegisterConnectionMBean() { + if(registerConnectionMBean == null){ + if(getJmx() != null){ + return getJmx().isEnabled(); + } + } + + return registerConnectionMBean; + } + + /** + * 设置是否将连接池的管理信息注册为 JMX (Java Management Extensions) MBean + * + * @param registerConnectionMBean + * 是否将连接池的管理信息注册为 JMX (Java Management Extensions) MBean + */ + public void setRegisterConnectionMBean(Boolean registerConnectionMBean) { + this.registerConnectionMBean = registerConnectionMBean; + + if(getJmx() == null){ + setJmx(new Jmx(registerConnectionMBean)); + }else{ + getJmx().setEnabled(registerConnectionMBean); + } + } + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/DruidPoolConfiguration.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/DruidPoolConfiguration.java new file mode 100644 index 000000000..abb43be20 --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/DruidPoolConfiguration.java @@ -0,0 +1,645 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.datasource.pool; + +import com.alibaba.druid.pool.DruidAbstractDataSource; + +import java.sql.PreparedStatement; +import java.time.Duration; + +/** + * Druid 数据源连接池配置 {@link DruidAbstractDataSource} + * + * @author Yong.Teng + * @since 1.3.2 + */ +public class DruidPoolConfiguration extends AbstractPoolConfiguration { + + /** + * 最大连接数,可以在这个池中同一时刻被分配的有效连接数的最大值,如设置为负数,则不限制 + */ + private Integer maxActive; + + /** + * 数据库连接池中的空闲连接是否保持存活 + * + * @since 3.0.0 + */ + private Boolean keepAlive; + + /** + * 连接池中空闲连接的保活间隔时间,这个属性决定了在连接池中,空闲连接每隔多长时间会被检查并进行保活操作,以确保这些连接在空闲时不会被数据库服务器断开 + */ + private Duration keepAliveBetweenTime; + + /** + * 测试连接是否有效时是否使用 PING 方法 + * + * @since 3.0.0 + */ + private Boolean usePingMethod; + + /** + * 连接池在将连接返回到连接池时,是否保留连接的原始事务隔离级别 + * + * @since 3.0.0 + */ + private Boolean keepConnectionUnderlyingTransactionIsolation; + + /** + * 连接池中创建连接任务的最大数量 + */ + private Integer maxCreateTaskCount; + + /** + * 连接池中等待数据库连接的最大线程数量 + */ + private Integer maxWaitThreadCount; + + /** + * 在发生致命错误(fatal error)时连接池的最大活动连接数 + */ + private Integer onFatalErrorMaxActive; + + /** + * 在获取连接失败后,是否立即断开(标记为不可用)连接池中的所有连接 + */ + private Boolean breakAfterAcquireFailure; + + /** + * 当连接池未满且没有可用连接时,系统在超时前重试获取连接的次数 + */ + private Integer notFullTimeoutRetryCount; + + /** + * 是否使用本地会话状态;这个配置主要用于处理连接池中的数据库连接在会话级别的状态管理。 + */ + private Boolean useLocalSessionState; + + /** + * 是否缓存 {@link PreparedStatement},也就是PSCache; + * PSCache 对支持游标的数据库性能提升巨大,比如说 oracle,在mysql下建议关闭 + */ + private Boolean poolPreparedStatements; + + /** + * 连接池中是否启用 {@link PreparedStatement} 的共享功能 + */ + private Boolean sharePreparedStatements; + + /** + * 每个数据库连接上可以缓存的 {@link PreparedStatement} 对象的最大数量 + */ + private Integer maxPoolPreparedStatementPerConnectionSize; + + /** + * 最大打开 PSCache 数,在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些 + */ + private Integer maxOpenPreparedStatements; + + /** + * 是否移除抛弃的(abandoned)连接,一个连接使用超过了 removeAbandonedTimeout 上限就被视为抛弃的, + * 开启该开关可以恢复那些应用没有关闭的连接 + */ + private Boolean removeAbandoned; + + /** + * 日志统计信息的记录间隔时间 + */ + private Duration timeBetweenLogStats; + + /** + * 是否在连接关闭时记录日志 + */ + private Boolean dupCloseLogEnable; + + /** + * 控制在获取连接和关闭连接时是否记录线程不一致的情况 + * + * @since 3.0.0 + */ + private Boolean logDifferentThread; + + /** + * 返回最大连接数 + * + * @return 最大连接数 + */ + public Integer getMaxActive() { + return maxActive; + } + + /** + * 设置最大连接数 + * + * @param maxActive + * 最大连接数 + */ + public void setMaxActive(Integer maxActive) { + this.maxActive = maxActive; + super.setMaxTotal(maxActive); + } + + @Override + public void setMaxTotal(Integer maxTotal) { + setMaxActive(maxTotal); + } + + /** + * 返回数据库连接池中的空闲连接是否保持存活 + * + * @return 数据库连接池中的空闲连接是否保持存活 + * + * @since 3.0.0 + */ + public Boolean isKeepAlive() { + return getKeepAlive(); + } + + /** + * 返回数据库连接池中的空闲连接是否保持存活 + * + * @return 数据库连接池中的空闲连接是否保持存活 + * + * @since 3.0.0 + */ + public Boolean getKeepAlive() { + return keepAlive; + } + + /** + * 设置数据库连接池中的空闲连接是否保持存活 + * + * @param keepAlive + * 数据库连接池中的空闲连接是否保持存活 + * + * @since 3.0.0 + */ + public void setKeepAlive(Boolean keepAlive) { + this.keepAlive = keepAlive; + } + + /** + * 返回连接池中空闲连接的保活间隔时间 + * + * @return 连接池中空闲连接的保活间隔时间 + */ + public Duration getKeepAliveBetweenTime() { + return keepAliveBetweenTime; + } + + /** + * 设置连接池中空闲连接的保活间隔时间 + * + * @param keepAliveBetweenTime + * 连接池中空闲连接的保活间隔时间 + */ + public void setKeepAliveBetweenTime(Duration keepAliveBetweenTime) { + this.keepAliveBetweenTime = keepAliveBetweenTime; + } + + /** + * 返回测试连接是否有效时是否使用 PING 方法 + * + * @return 测试连接是否有效时是否使用 PING 方法 + * + * @since 3.0.0 + */ + public Boolean isUsePingMethod() { + return getUsePingMethod(); + } + + /** + * 返回测试连接是否有效时是否使用 PING 方法 + * + * @return 测试连接是否有效时是否使用 PING 方法 + * + * @since 3.0.0 + */ + public Boolean getUsePingMethod() { + return usePingMethod; + } + + /** + * 设置测试连接是否有效时是否使用 PING 方法 + * + * @param usePingMethod + * 测试连接是否有效时是否使用 PING 方法 + * + * @since 3.0.0 + */ + public void setUsePingMethod(Boolean usePingMethod) { + this.usePingMethod = usePingMethod; + } + + /** + * 返回连接池在将连接返回到连接池时,是否保留连接的原始事务隔离级别 + * + * @return 连接池在将连接返回到连接池时,是否保留连接的原始事务隔离级别 + * + * @since 3.0.0 + */ + public Boolean isKeepConnectionUnderlyingTransactionIsolation() { + return getKeepConnectionUnderlyingTransactionIsolation(); + } + + /** + * 返回连接池在将连接返回到连接池时,是否保留连接的原始事务隔离级别 + * + * @return 连接池在将连接返回到连接池时,是否保留连接的原始事务隔离级别 + * + * @since 3.0.0 + */ + public Boolean getKeepConnectionUnderlyingTransactionIsolation() { + return keepConnectionUnderlyingTransactionIsolation; + } + + /** + * 设置连接池在将连接返回到连接池时,是否保留连接的原始事务隔离级别 + * + * @param keepConnectionUnderlyingTransactionIsolation + * 连接池在将连接返回到连接池时,是否保留连接的原始事务隔离级别 + * + * @since 3.0.0 + */ + public void setKeepConnectionUnderlyingTransactionIsolation(Boolean keepConnectionUnderlyingTransactionIsolation) { + this.keepConnectionUnderlyingTransactionIsolation = keepConnectionUnderlyingTransactionIsolation; + } + + /** + * 返回获取连接时最大等待时间,配置了 maxWait 之后,缺省启用公平锁,并发效率会有所下降 + * + * @return 获取连接时最大等待时间 + */ + public Duration getMaxWait() { + return super.getMaxWait(); + } + + /** + * 设置获取连接时最大等待时间,配置了 maxWait 之后,缺省启用公平锁,并发效率会有所下降 + * + * @param maxWait + * 获取连接时最大等待时间 + */ + public void setMaxWait(Duration maxWait) { + super.setMaxWait(maxWait); + } + + /** + * 返回连接池中创建连接任务的最大数量 + * + * @return 连接池中创建连接任务的最大数量 + */ + public Integer getMaxCreateTaskCount() { + return maxCreateTaskCount; + } + + /** + * 设置连接池中创建连接任务的最大数量 + * + * @param maxCreateTaskCount + * 连接池中创建连接任务的最大数量 + */ + public void setMaxCreateTaskCount(Integer maxCreateTaskCount) { + this.maxCreateTaskCount = maxCreateTaskCount; + } + + /** + * 返回连接池中等待数据库连接的最大线程数量 + * + * @return 连接池中等待数据库连接的最大线程数量 + */ + public Integer getMaxWaitThreadCount() { + return maxWaitThreadCount; + } + + /** + * 设置连接池中等待数据库连接的最大线程数量 + * + * @param maxWaitThreadCount + * 连接池中等待数据库连接的最大线程数量 + */ + public void setMaxWaitThreadCount(Integer maxWaitThreadCount) { + this.maxWaitThreadCount = maxWaitThreadCount; + } + + /** + * 返回在发生致命错误(fatal error)时连接池的最大活动连接数 + * + * @return 在发生致命错误(fatal error)时连接池的最大活动连接数 + */ + public Integer getOnFatalErrorMaxActive() { + return onFatalErrorMaxActive; + } + + /** + * 设置在发生致命错误(fatal error)时连接池的最大活动连接数 + * + * @param onFatalErrorMaxActive + * 在发生致命错误(fatal error)时连接池的最大活动连接数 + */ + public void setOnFatalErrorMaxActive(Integer onFatalErrorMaxActive) { + this.onFatalErrorMaxActive = onFatalErrorMaxActive; + } + + /** + * 返回在获取连接失败后,是否立即断开(标记为不可用)连接池中的所有连接 + * + * @return 在获取连接失败后,是否立即断开(标记为不可用)连接池中的所有连接 + */ + public Boolean isBreakAfterAcquireFailure() { + return getBreakAfterAcquireFailure(); + } + + /** + * 返回在获取连接失败后,是否立即断开(标记为不可用)连接池中的所有连接 + * + * @return 在获取连接失败后,是否立即断开(标记为不可用)连接池中的所有连接 + */ + public Boolean getBreakAfterAcquireFailure() { + return breakAfterAcquireFailure; + } + + /** + * 设置在获取连接失败后,是否立即断开(标记为不可用)连接池中的所有连接 + * + * @param breakAfterAcquireFailure + * 在获取连接失败后,是否立即断开(标记为不可用)连接池中的所有连接 + */ + public void setBreakAfterAcquireFailure(Boolean breakAfterAcquireFailure) { + this.breakAfterAcquireFailure = breakAfterAcquireFailure; + } + + /** + * 返回当连接池未满且没有可用连接时,系统在超时前重试获取连接的次数 + * + * @return 当连接池未满且没有可用连接时,系统在超时前重试获取连接的次数 + */ + public Integer getNotFullTimeoutRetryCount() { + return notFullTimeoutRetryCount; + } + + /** + * 设置当连接池未满且没有可用连接时,系统在超时前重试获取连接的次数 + * + * @param notFullTimeoutRetryCount + * 当连接池未满且没有可用连接时,系统在超时前重试获取连接的次数 + */ + public void setNotFullTimeoutRetryCount(Integer notFullTimeoutRetryCount) { + this.notFullTimeoutRetryCount = notFullTimeoutRetryCount; + } + + /** + * 返回是否使用本地会话状态 + * + * @return 是否使用本地会话状态 + */ + public Boolean isUseLocalSessionState() { + return getUseLocalSessionState(); + } + + /** + * 返回是否使用本地会话状态 + * + * @return 是否使用本地会话状态 + */ + public Boolean getUseLocalSessionState() { + return useLocalSessionState; + } + + /** + * 设置是否使用本地会话状态 + * + * @param useLocalSessionState + * 是否使用本地会话状态 + */ + public void setUseLocalSessionState(Boolean useLocalSessionState) { + this.useLocalSessionState = useLocalSessionState; + } + + /** + * 返回是否缓存 preparedStatement,也就是PSCache + * + * @return 是否缓存 preparedStatement,也就是PSCache + */ + public Boolean isPoolPreparedStatements() { + return getPoolPreparedStatements(); + } + + /** + * 返回是否缓存 {@link PreparedStatement},也就是PSCache + * + * @return 是否缓存 preparedStatement,也就是PSCache + */ + public Boolean getPoolPreparedStatements() { + return poolPreparedStatements; + } + + /** + * 设置是否缓存 {@link PreparedStatement},也就是PSCache; + * PSCache 对支持游标的数据库性能提升巨大,比如说 oracle,在mysql下建议关闭 + * + * @param poolPreparedStatements + * 是否缓存 preparedStatement + */ + public void setPoolPreparedStatements(Boolean poolPreparedStatements) { + this.poolPreparedStatements = poolPreparedStatements; + } + + /** + * 返回连接池中是否启用 {@link PreparedStatement} 的共享功能 + * + * @return 连接池中是否启用 {@link PreparedStatement} 的共享功能 + */ + public Boolean isSharePreparedStatements() { + return getSharePreparedStatements(); + } + + /** + * 返回连接池中是否启用 {@link PreparedStatement} 的共享功能 + * + * @return 连接池中是否启用 {@link PreparedStatement} 的共享功能 + */ + public Boolean getSharePreparedStatements() { + return sharePreparedStatements; + } + + /** + * 设置连接池中是否启用 {@link PreparedStatement} 的共享功能 + * + * @param sharePreparedStatements + * 连接池中是否启用 {@link PreparedStatement} 的共享功能 + */ + public void setSharePreparedStatements(Boolean sharePreparedStatements) { + this.sharePreparedStatements = sharePreparedStatements; + } + + /** + * 返回每个数据库连接上可以缓存的 {@link PreparedStatement} 对象的最大数量 + * + * @return 每个数据库连接上可以缓存的 {@link PreparedStatement} 对象的最大数量 + */ + public Integer getMaxPoolPreparedStatementPerConnectionSize() { + return maxPoolPreparedStatementPerConnectionSize; + } + + /** + * 设置每个数据库连接上可以缓存的 {@link PreparedStatement} 对象的最大数量 + * + * @param maxPoolPreparedStatementPerConnectionSize + * 每个数据库连接上可以缓存的 {@link PreparedStatement} 对象的最大数量 + */ + public void setMaxPoolPreparedStatementPerConnectionSize(Integer maxPoolPreparedStatementPerConnectionSize) { + this.maxPoolPreparedStatementPerConnectionSize = maxPoolPreparedStatementPerConnectionSize; + } + + /** + * 返回最大打开 PSCache 数 + * + * @return 最大打开 PSCache 数 + */ + public Integer getMaxOpenPreparedStatements() { + return maxOpenPreparedStatements; + } + + /** + * 设置最大打开 PSCache 数,在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些 + * + * @param maxOpenPreparedStatements + * 最大打开 PSCache 数 + */ + public void setMaxOpenPreparedStatements(Integer maxOpenPreparedStatements) { + this.maxOpenPreparedStatements = maxOpenPreparedStatements; + } + + /** + * 返回是否移除抛弃的(abandoned)连接 + * + * @return 是否移除抛弃的(abandoned)连接 + */ + public Boolean isRemoveAbandoned() { + return getRemoveAbandoned(); + } + + /** + * 返回是否移除抛弃的(abandoned)连接 + * + * @return 是否移除抛弃的(abandoned)连接 + */ + public Boolean getRemoveAbandoned() { + return removeAbandoned; + } + + /** + * 设置是否移除抛弃的(abandoned)连接 + * + * @param removeAbandoned + * 是否移除抛弃的(abandoned)连接 + */ + public void setRemoveAbandoned(Boolean removeAbandoned) { + this.removeAbandoned = removeAbandoned; + } + + /** + * 返回日志统计信息的记录间隔时间 + * + * @return 日志统计信息的记录间隔时间 + */ + public Duration getTimeBetweenLogStats() { + return timeBetweenLogStats; + } + + /** + * 设置日志统计信息的记录间隔时间 + * + * @param timeBetweenLogStats + * 日志统计信息的记录间隔时间 + */ + public void setTimeBetweenLogStats(Duration timeBetweenLogStats) { + this.timeBetweenLogStats = timeBetweenLogStats; + } + + /** + * 返回是否在连接关闭时记录日志 + * + * @return 是否在连接关闭时记录日志 + */ + public Boolean isDupCloseLogEnable() { + return getDupCloseLogEnable(); + } + + /** + * 返回是否在连接关闭时记录日志 + * + * @return 是否在连接关闭时记录日志 + */ + public Boolean getDupCloseLogEnable() { + return dupCloseLogEnable; + } + + /** + * 设置是否在连接关闭时记录日志 + * + * @param dupCloseLogEnable + * 是否在连接关闭时记录日志 + */ + public void setDupCloseLogEnable(Boolean dupCloseLogEnable) { + this.dupCloseLogEnable = dupCloseLogEnable; + } + + /** + * 返回是否在获取连接和关闭连接时是否记录线程不一致的情况 + * + * @return 是否在获取连接和关闭连接时是否记录线程不一致的情况 + * + * @since 3.0.0 + */ + public Boolean isLogDifferentThread() { + return getLogDifferentThread(); + } + + /** + * 返回是否在获取连接和关闭连接时是否记录线程不一致的情况 + * + * @return 是否在获取连接和关闭连接时是否记录线程不一致的情况 + * + * @since 3.0.0 + */ + public Boolean getLogDifferentThread() { + return logDifferentThread; + } + + /** + * 设置在获取连接和关闭连接时是否记录线程不一致的情况 + * + * @param logDifferentThread + * 是否在获取连接和关闭连接时是否记录线程不一致的情况 + * + * @since 3.0.0 + */ + public void setLogDifferentThread(Boolean logDifferentThread) { + this.logDifferentThread = logDifferentThread; + } +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/GenericPoolConfiguration.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/GenericPoolConfiguration.java similarity index 93% rename from buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/GenericPoolConfiguration.java rename to buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/GenericPoolConfiguration.java index 6f7b25166..c37b4af1a 100644 --- a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/GenericPoolConfiguration.java +++ b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/GenericPoolConfiguration.java @@ -19,10 +19,10 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.jdbc.datasource.config; +package com.buession.jdbc.datasource.pool; /** * 常规数据源连接池配置 diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/HikariPoolConfiguration.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/HikariPoolConfiguration.java new file mode 100644 index 000000000..4b3ee526b --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/HikariPoolConfiguration.java @@ -0,0 +1,493 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.datasource.pool; + +import com.buession.jdbc.core.Jmx; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.metrics.MetricsTrackerFactory; + +import java.time.Duration; +import java.util.Properties; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; + +/** + * Hikari 数据源连接池配置 {@link HikariConfig} + * + * @author Yong.Teng + * @since 1.3.2 + */ +public class HikariPoolConfiguration extends AbstractPoolConfiguration { + + /** + * 连接池无法成功建立连接,是否会立即抛出异常或进行重试,以及重试的超时时间 + */ + private Duration initializationFailTimeout; + + /** + * 接池中最大连接数,如设置为负数,则不限制 + */ + private Integer maxPoolSize; + + /** + * 设置一个SQL语句, 从连接池获取连接时, 先执行改 sql, 验证连接是否可用 + * 如果是使用了 JDBC 4 那么不建议配置这个选项, 因为JDBC 4 使用 ping 命令, 更加高效 + */ + private String connectionTestQuery; + + /** + * 检测连接是否有效的超时时间 + * + * @since 3.0.0 + */ + private Duration validationTimeout; + + /** + * 连接允许在池中闲置的最长时间,仅适用于 minimumIdle 定义为小于 maximumPoolSize,值为 0 时空闲连接永远不会从池中删除 + */ + private Duration idleTimeout; + + /** + * 池中连接的最大生存期,值为 0 时表示无限寿命, 推荐设置的比数据库的 wait_timeout 小几秒到几分钟 + */ + private Duration maxLifetime; + + /** + * 连接在空闲时发送“keep-alive”心跳的间隔时间 + */ + private Duration keepaliveTime; + + /** + * 线程工厂 + */ + private ThreadFactory threadFactory; + + /** + * 调度任务执行器 + */ + private ScheduledExecutorService scheduledExecutor; + + /** + * 控制在记录消息之前连接可能离开池的时间量,表明可能存在连接泄漏,值为 0 时泄漏检测被禁用 + */ + private Duration leakDetectionThreshold; + + /** + * 是否允许将连接池挂起 + */ + private Boolean allowPoolSuspension; + + /** + * 连接池的性能指标跟踪器 {@link MetricsTrackerFactory} 类名 + * + * @since 3.0.0 + */ + private String metricsTrackerFactoryClassName; + + /** + * 允许将 HikariCP 连接池的性能指标集成到基于 Dropwizard Metrics 的监控系统中 + * + * @since 3.0.0 + */ + private String metricRegistryClassName; + + /** + * 允许将 HikariCP 连接池的健康检查功能与基于 Dropwizard Metrics 的健康检查机制集成 + * + * @since 3.0.0 + */ + private String healthCheckRegistryClassName; + + /** + * 健康检查的参数集合 + */ + private Properties healthCheckProperties; + + /** + * 是否自动注册 JMX 相关的 MBeans + */ + private Boolean registerMbeans; + + /** + * 返回连接池无法成功建立连接,是否会立即抛出异常或进行重试,以及重试的超时时间 + * + * @return 连接池无法成功建立连接,是否会立即抛出异常或进行重试,以及重试的超时时间 + */ + public Duration getInitializationFailTimeout() { + return initializationFailTimeout; + } + + /** + * 设置连接池无法成功建立连接,是否会立即抛出异常或进行重试,以及重试的超时时间 + * + * @param initializationFailTimeout + * 连接池无法成功建立连接,是否会立即抛出异常或进行重试,以及重试的超时时间 + */ + public void setInitializationFailTimeout(Duration initializationFailTimeout) { + this.initializationFailTimeout = initializationFailTimeout; + } + + /** + * 返回接池中最大连接数 + * + * @return 接池中最大连接数 + */ + public Integer getMaxPoolSize() { + return maxPoolSize; + } + + /** + * 设置接池中最大连接数 + * + * @param maxPoolSize + * 接池中最大连接数 + */ + public void setMaxPoolSize(Integer maxPoolSize) { + this.maxPoolSize = maxPoolSize; + super.setMaxTotal(maxPoolSize); + } + + @Override + public void setMaxTotal(Integer maxTotal) { + setMaxPoolSize(maxTotal); + } + + /** + * 返回从连接池获取连接时, 验证连接是否可用的SQL语句 + * + * @return 从连接池获取连接时, 验证连接是否可用的SQL语句 + * + * @since 3.0.0 + */ + public String getConnectionTestQuery() { + return connectionTestQuery; + } + + /** + * 设置从连接池获取连接时, 验证连接是否可用的SQL语句 + * + * @param connectionTestQuery + * 从连接池获取连接时, 验证连接是否可用的SQL语句 + * + * @since 3.0.0 + */ + public void setConnectionTestQuery(String connectionTestQuery) { + this.connectionTestQuery = connectionTestQuery; + super.setValidationQuery(connectionTestQuery); + } + + /** + * 返回检测连接是否有效的超时时间 + * + * @return 检测连接是否有效的超时时间 + * + * @since 3.0.0 + */ + public Duration getValidationTimeout() { + return validationTimeout; + } + + /** + * 设置检测连接是否有效的超时时间,不能大于 {@link com.buession.jdbc.datasource.HikariDataSource#getConnectionTimeout()} + * + * @param validationTimeout + * 检测连接是否有效的超时时间 + * + * @since 3.0.0 + */ + public void setValidationTimeout(Duration validationTimeout) { + this.validationTimeout = validationTimeout; + super.setValidationQueryTimeout(validationTimeout); + } + + /** + * 返回连接允许在池中闲置的最长时间 + * + * @return 连接允许在池中闲置的最长时间 + */ + public Duration getIdleTimeout() { + return idleTimeout; + } + + /** + * 设置连接允许在池中闲置的最长时间,仅适用于 minimumIdle 定义为小于 maximumPoolSize,值为 0 时空闲连接永远不会从池中删除 + * 如果 idleTimeout + 1秒 > maxLifetime 且 maxLifetime > 0,则会被重置为 0; + * 如果 idleTimeout != 0 且小于 10 秒,则会被重置为 10 秒 + * + * @param idleTimeout + * 连接允许在池中闲置的最长时间 + */ + public void setIdleTimeout(Duration idleTimeout) { + this.idleTimeout = idleTimeout; + } + + /** + * 返回池中连接的最大生存期,值为 0 时表示无限寿命 + * + * @return 池中连接的最大生存期 + */ + public Duration getMaxLifetime() { + return maxLifetime; + } + + /** + * 设置池中连接的最大生存期,值为 0 时表示无限寿命, 推荐设置的比数据库的 wait_timeout 小几秒到几分钟 + * + * @param maxLifetime + * 池中连接的最大生存期 + */ + public void setMaxLifetime(Duration maxLifetime) { + this.maxLifetime = maxLifetime; + } + + /** + * 返回连接在空闲时发送“keep-alive”心跳的间隔时间 + * + * @return 连接在空闲时发送“keep-alive”心跳的间隔时间 + */ + public Duration getKeepaliveTime() { + return keepaliveTime; + } + + /** + * 设置连接在空闲时发送“keep-alive”心跳的间隔时间 + * + * @param keepaliveTime + * 连接在空闲时发送“keep-alive”心跳的间隔时间 + */ + public void setKeepaliveTime(Duration keepaliveTime) { + this.keepaliveTime = keepaliveTime; + } + + /** + * 返回线程工厂 + * + * @return 线程工厂 + */ + public ThreadFactory getThreadFactory() { + return threadFactory; + } + + /** + * 设置线程工厂 + * + * @param threadFactory + * 线程工厂 + */ + public void setThreadFactory(ThreadFactory threadFactory) { + this.threadFactory = threadFactory; + } + + /** + * 返回调度任务执行器 + * + * @return 调度任务执行器 + */ + public ScheduledExecutorService getScheduledExecutor() { + return scheduledExecutor; + } + + /** + * 设置调度任务执行器 + * + * @param scheduledExecutor + * 调度任务执行器 + */ + public void setScheduledExecutor(ScheduledExecutorService scheduledExecutor) { + this.scheduledExecutor = scheduledExecutor; + } + + /** + * 返回记录消息之前连接可能离开池的时间量,表明可能存在连接泄漏,值为 0 时泄漏检测被禁用 + * + * @return 记录消息之前连接可能离开池的时间量 + */ + public Duration getLeakDetectionThreshold() { + return leakDetectionThreshold; + } + + /** + * 设置记录消息之前连接可能离开池的时间量,表明可能存在连接泄漏,值为 0 时泄漏检测被禁用 + * + * @param leakDetectionThreshold + * 记录消息之前连接可能离开池的时间量 + */ + public void setLeakDetectionThreshold(Duration leakDetectionThreshold) { + this.leakDetectionThreshold = leakDetectionThreshold; + } + + /** + * 返回是否允许将连接池挂起 + * + * @return 是否允许将连接池挂起 + */ + public Boolean isAllowPoolSuspension() { + return getAllowPoolSuspension(); + } + + /** + * 返回是否允许将连接池挂起 + * + * @return 是否允许将连接池挂起 + */ + public Boolean getAllowPoolSuspension() { + return allowPoolSuspension; + } + + /** + * 设置是否允许将连接池挂起 + * + * @param allowPoolSuspension + * 是否允许将连接池挂起 + */ + public void setAllowPoolSuspension(Boolean allowPoolSuspension) { + this.allowPoolSuspension = allowPoolSuspension; + } + + /** + * 返回连接池的性能指标跟踪器 {@link MetricsTrackerFactory} 类名 + * + * @return 连接池的性能指标跟踪器 {@link MetricsTrackerFactory} 类名 + * + * @since 3.0.0 + */ + public String getMetricsTrackerFactoryClassName() { + return metricsTrackerFactoryClassName; + } + + /** + * 设置连接池的性能指标跟踪器 {@link MetricsTrackerFactory} 类名 + * + * @param metricsTrackerFactoryClassName + * 连接池的性能指标跟踪器 {@link MetricsTrackerFactory} 类名 + * + * @since 3.0.0 + */ + public void setMetricsTrackerFactoryClassName(String metricsTrackerFactoryClassName) { + this.metricsTrackerFactoryClassName = metricsTrackerFactoryClassName; + } + + /** + * 返回允许将 HikariCP 连接池的性能指标集成到基于 Dropwizard Metrics 的监控系统中 + * + * @return 允许将 HikariCP 连接池的性能指标集成到基于 Dropwizard Metrics 的监控系统中 + * + * @since 3.0.0 + */ + public String getMetricRegistryClassName() { + return metricRegistryClassName; + } + + /** + * 设置允许将 HikariCP 连接池的性能指标集成到基于 Dropwizard Metrics 的监控系统中 + * + * @param metricRegistryClassName + * 允许将 HikariCP 连接池的性能指标集成到基于 Dropwizard Metrics 的监控系统中 + * + * @since 3.0.0 + */ + public void setMetricRegistryClassName(String metricRegistryClassName) { + this.metricRegistryClassName = metricRegistryClassName; + } + + /** + * 返回允许将 HikariCP 连接池的健康检查功能与基于 Dropwizard Metrics 的健康检查机制集成 + * + * @return 允许将 HikariCP 连接池的健康检查功能与基于 Dropwizard Metrics 的健康检查机制集成 + */ + public String getHealthCheckRegistryClassName() { + return healthCheckRegistryClassName; + } + + /** + * 设置允许将 HikariCP 连接池的健康检查功能与基于 Dropwizard Metrics 的健康检查机制集成 + * + * @param healthCheckRegistryClassName + * 允许将 HikariCP 连接池的健康检查功能与基于 Dropwizard Metrics 的健康检查机制集成 + */ + public void setHealthCheckRegistryClassName(String healthCheckRegistryClassName) { + this.healthCheckRegistryClassName = healthCheckRegistryClassName; + } + + /** + * 返回健康检查的参数集合 + * + * @return 健康检查的参数集合 + */ + public Properties getHealthCheckProperties() { + return healthCheckProperties; + } + + /** + * 设置健康检查的参数集合 + * + * @param healthCheckProperties + * 健康检查的参数集合 + */ + public void setHealthCheckProperties(Properties healthCheckProperties) { + this.healthCheckProperties = healthCheckProperties; + } + + /** + * 返回是否自动注册 JMX 相关的 MBeans + * + * @return 是否自动注册 JMX 相关的 MBeans + */ + public Boolean isRegisterMbeans() { + return getRegisterMbeans(); + } + + /** + * 返回是否自动注册 JMX 相关的 MBeans + * + * @return 是否自动注册 JMX 相关的 MBeans + */ + public Boolean getRegisterMbeans() { + if(registerMbeans == null){ + if(getJmx() != null){ + return getJmx().isEnabled(); + } + } + + return registerMbeans; + } + + /** + * 设置是否自动注册 JMX 相关的 MBeans + * + * @param registerMbeans + * 是否自动注册 JMX 相关的 MBeans + */ + public void setRegisterMbeans(Boolean registerMbeans) { + this.registerMbeans = registerMbeans; + + if(getJmx() == null){ + setJmx(new Jmx(registerMbeans)); + }else{ + getJmx().setEnabled(registerMbeans); + } + } + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/OraclePoolConfiguration.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/OraclePoolConfiguration.java new file mode 100644 index 000000000..464d543e2 --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/OraclePoolConfiguration.java @@ -0,0 +1,661 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.datasource.pool; + +import java.time.Duration; + +/** + * Oracle 数据源连接池配置 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class OraclePoolConfiguration extends AbstractPoolConfiguration { + + /** + * 初始连接数,池被启动时初始化的创建的连接个数 + */ + private Integer initialPoolSize; + + /** + * 连接池中最小的连接数量,当为 0 时,连接池在空闲时可以完全没有连接 + */ + private Integer minPoolSize; + + /** + * 连接池中可以保留连接的最大数,如设置为负数,则不限制 + */ + private Integer maxPoolSize; + + /** + * 获取连接时最大等待时间 + */ + private Duration connectionWait; + + /** + * 验证连接使用的 SQL + */ + private String sqlForValidateConnection; + + /** + * 连接验证操作的超时时间 + */ + private Duration connectionValidationTimeout; + + /** + * 连接在连接池中保持空闲状态的最大时间 + */ + private Duration inactiveConnectionTimeout; + + /** + * 连接在连接池中保持空闲状态的最大时间 + */ + private Duration maxIdleTime; + + /** + * 连接在连接池中的最大生命周期 + */ + private Duration timeToLiveConnectionTimeout; + + /** + * 在一个连接空闲指定时间后,认为该连接仍然有效并且可以直接重用的时间阈值 + */ + private Duration trustIdleConnection; + + /** + * 连接池中的连接在被强制关闭之前可以被重复使用的最长时间 + */ + private Duration maxConnectionReuseTime; + + /** + * 连接池中的连接可以被重复使用的最大次数 + */ + private Integer maxConnectionReuseCount; + + /** + * 定义在连接标签操作中被认为是“高成本”的阈值时间 + */ + private Duration connectionLabelingHighCost; + + /** + * 连接的重用次数在达到这个阈值后会被标记为“高成本重用” + */ + private Integer highCostConnectionReuseThreshold; + + /** + * 定义连接在达到指定的重用次数后,是否应该被重新配置(repurpose) + */ + private Integer connectionRepurposeThreshold; + + /** + * 连接池检查连接超时的间隔时间 + */ + private Duration timeoutCheckInterval; + + /** + * 连接池中每个连接所能缓存的最大 SQL 预编译语句(Prepared Statements)的数量 + */ + private Integer maxStatements; + + /** + * 触发连接池收割(Harvesting)操作的阈值,表示连接池中空闲连接的数量达到多少时触发收割操作 + */ + private Integer connectionHarvestTriggerCount; + + /** + * 在一次连接收割操作中,最多可以从连接池中收回的连接数量 + */ + private Integer connectionHarvestMaxCount; + + /** + * 从连接池获取一个连接时,验证有效性; + * 指明在从池中租借对象时是否要进行验证有效,如果对象验证失败,则对象将从池子释放,然后我们将尝试租借另一个 + */ + private Boolean validateConnectionOnBorrow; + + /** + * 连接在被认为是“被遗弃”状态下的最大时间 + */ + private Duration abandonedConnectionTimeout; + + /** + * 否允许从只读实例获取连接 + */ + private Boolean readOnlyInstanceAllowed; + + /** + * 是否在借用连接的线程中创建连接 + */ + private Boolean createConnectionInBorrowThread; + + /** + * 返回初始连接数 + * + * @return 初始连接数 + */ + public Integer getInitialPoolSize() { + return initialPoolSize; + } + + /** + * 设置初始连接数 + * + * @param initialPoolSize + * 初始连接数 + */ + public void setInitialPoolSize(Integer initialPoolSize) { + this.initialPoolSize = initialPoolSize; + super.setInitialSize(initialPoolSize); + } + + @Override + public void setInitialSize(Integer initialPoolSize) { + setInitialPoolSize(initialPoolSize); + } + + /** + * 返回连接池中最小的连接数量 + * + * @return 连接池中最小的连接数量 + */ + public Integer getMinPoolSize() { + return minPoolSize; + } + + /** + * 设置连接池中最小的连接数量 + * + * @param minPoolSize + * 连接池中最小的连接数量 + */ + public void setMinPoolSize(Integer minPoolSize) { + this.minPoolSize = minPoolSize; + } + + /** + * 返回连接池中可以保留连接的最大数 + * + * @return 连接池中可以保留连接的最大数 + */ + public Integer getMaxPoolSize() { + return maxPoolSize; + } + + /** + * 设置连接池中可以保留连接的最大数 + * + * @param maxPoolSize + * 连接池中可以保留连接的最大数 + */ + public void setMaxPoolSize(Integer maxPoolSize) { + this.maxPoolSize = maxPoolSize; + super.setMaxTotal(maxPoolSize); + } + + @Override + public void setMaxTotal(Integer maxTotal) { + setMaxPoolSize(maxTotal); + } + + /** + * 返回获取连接时最大等待时间 + * + * @return 获取连接时最大等待时间 + */ + public Duration getConnectionWait() { + return connectionWait; + } + + /** + * 设置获取连接时最大等待时间 + * + * @param connectionWait + * 获取连接时最大等待时间 + */ + public void setConnectionWait(Duration connectionWait) { + this.connectionWait = connectionWait; + super.setMaxWait(connectionWait); + } + + @Override + public void setMaxWait(Duration maxWait) { + setConnectionWait(maxWait); + } + + /** + * 返回验证连接使用的 SQL + * + * @return 验证连接使用的 SQL + */ + public String getSqlForValidateConnection() { + return sqlForValidateConnection; + } + + /** + * 设置验证连接使用的 SQL + * + * @param sqlForValidateConnection + * 验证连接使用的 SQL + */ + public void setSqlForValidateConnection(String sqlForValidateConnection) { + this.sqlForValidateConnection = sqlForValidateConnection; + super.setValidationQuery(sqlForValidateConnection); + } + + @Override + public void setValidationQuery(String validationQuery) { + setSqlForValidateConnection(validationQuery); + } + + /** + * 返回连接验证操作的超时时间 + * + * @return 连接验证操作的超时时间 + */ + public Duration getConnectionValidationTimeout() { + return connectionValidationTimeout; + } + + /** + * 设置连接验证操作的超时时间 + * + * @param connectionValidationTimeout + * 连接验证操作的超时时间 + */ + public void setConnectionValidationTimeout(Duration connectionValidationTimeout) { + this.connectionValidationTimeout = connectionValidationTimeout; + super.setValidationQueryTimeout(connectionValidationTimeout); + } + + @Override + public void setValidationQueryTimeout(Duration validationQueryTimeout) { + setConnectionValidationTimeout(validationQueryTimeout); + } + + /** + * 返回连接在连接池中保持空闲状态的最大时间 + * + * @return 连接在连接池中保持空闲状态的最大时间 + */ + public Duration getInactiveConnectionTimeout() { + return inactiveConnectionTimeout; + } + + /** + * 设置连接在连接池中保持空闲状态的最大时间 + * + * @param inactiveConnectionTimeout + * 连接在连接池中保持空闲状态的最大时间 + */ + public void setInactiveConnectionTimeout(Duration inactiveConnectionTimeout) { + this.inactiveConnectionTimeout = inactiveConnectionTimeout; + this.maxIdleTime = inactiveConnectionTimeout; + } + + /** + * 返回连接在连接池中保持空闲状态的最大时间 + * + * @return 连接在连接池中保持空闲状态的最大时间 + */ + public Duration getMaxIdleTime() { + return maxIdleTime; + } + + /** + * 设置连接在连接池中保持空闲状态的最大时间 + * + * @param maxIdleTime + * 连接在连接池中保持空闲状态的最大时间 + */ + public void setMaxIdleTime(Duration maxIdleTime) { + this.maxIdleTime = maxIdleTime; + this.inactiveConnectionTimeout = maxIdleTime; + } + + /** + * 返回连接在连接池中的最大生命周期 + * + * @return 连接在连接池中的最大生命周期 + */ + public Duration getTimeToLiveConnectionTimeout() { + return timeToLiveConnectionTimeout; + } + + /** + * 设置连接在连接池中的最大生命周期 + * + * @param timeToLiveConnectionTimeout + * 连接在连接池中的最大生命周期 + */ + public void setTimeToLiveConnectionTimeout(Duration timeToLiveConnectionTimeout) { + this.timeToLiveConnectionTimeout = timeToLiveConnectionTimeout; + } + + /** + * 返回在一个连接空闲指定时间后,认为该连接仍然有效并且可以直接重用的时间阈值 + * + * @return 在一个连接空闲指定时间后,认为该连接仍然有效并且可以直接重用的时间阈值 + */ + public Duration getTrustIdleConnection() { + return trustIdleConnection; + } + + /** + * 设置在一个连接空闲指定时间后,认为该连接仍然有效并且可以直接重用的时间阈值 + * + * @param trustIdleConnection + * 在一个连接空闲指定时间后,认为该连接仍然有效并且可以直接重用的时间阈值 + */ + public void setTrustIdleConnection(Duration trustIdleConnection) { + this.trustIdleConnection = trustIdleConnection; + } + + /** + * 返回连接池中的连接在被强制关闭之前可以被重复使用的最长时间 + * + * @return 连接池中的连接在被强制关闭之前可以被重复使用的最长时间 + */ + public Duration getMaxConnectionReuseTime() { + return maxConnectionReuseTime; + } + + /** + * 设置连接池中的连接在被强制关闭之前可以被重复使用的最长时间 + * + * @param maxConnectionReuseTime + * 连接池中的连接在被强制关闭之前可以被重复使用的最长时间 + */ + public void setMaxConnectionReuseTime(Duration maxConnectionReuseTime) { + this.maxConnectionReuseTime = maxConnectionReuseTime; + } + + /** + * 返回连接池中的连接可以被重复使用的最大次数 + * + * @return 连接池中的连接可以被重复使用的最大次数 + */ + public Integer getMaxConnectionReuseCount() { + return maxConnectionReuseCount; + } + + /** + * 设置连接池中的连接可以被重复使用的最大次数 + * + * @param maxConnectionReuseCount + * 连接池中的连接可以被重复使用的最大次数 + */ + public void setMaxConnectionReuseCount(Integer maxConnectionReuseCount) { + this.maxConnectionReuseCount = maxConnectionReuseCount; + } + + /** + * 返回定义在连接标签操作中被认为是“高成本”的阈值时间 + * + * @return 定义在连接标签操作中被认为是“高成本”的阈值时间 + */ + public Duration getConnectionLabelingHighCost() { + return connectionLabelingHighCost; + } + + /** + * 设置定义在连接标签操作中被认为是“高成本”的阈值时间 + * + * @param connectionLabelingHighCost + * 定义在连接标签操作中被认为是“高成本”的阈值时间 + */ + public void setConnectionLabelingHighCost(Duration connectionLabelingHighCost) { + this.connectionLabelingHighCost = connectionLabelingHighCost; + } + + /** + * 返回连接的重用次数在达到这个阈值后会被标记为“高成本重用” + * + * @return 连接的重用次数在达到这个阈值后会被标记为“高成本重用” + */ + public Integer getHighCostConnectionReuseThreshold() { + return highCostConnectionReuseThreshold; + } + + /** + * 设置连接的重用次数在达到这个阈值后会被标记为“高成本重用” + * + * @param highCostConnectionReuseThreshold + * 连接的重用次数在达到这个阈值后会被标记为“高成本重用” + */ + public void setHighCostConnectionReuseThreshold(Integer highCostConnectionReuseThreshold) { + this.highCostConnectionReuseThreshold = highCostConnectionReuseThreshold; + } + + /** + * 返回定义连接在达到指定的重用次数后,是否应该被重新配置(repurpose) + * + * @return 定义连接在达到指定的重用次数后,是否应该被重新配置(repurpose) + */ + public Integer getConnectionRepurposeThreshold() { + return connectionRepurposeThreshold; + } + + /** + * 设置定义连接在达到指定的重用次数后,是否应该被重新配置(repurpose) + * + * @param connectionRepurposeThreshold + * 定义连接在达到指定的重用次数后,是否应该被重新配置(repurpose) + */ + public void setConnectionRepurposeThreshold(Integer connectionRepurposeThreshold) { + this.connectionRepurposeThreshold = connectionRepurposeThreshold; + } + + /** + * 返回连接池检查连接超时的间隔时间 + * + * @return 连接池检查连接超时的间隔时间 + */ + public Duration getTimeoutCheckInterval() { + return timeoutCheckInterval; + } + + /** + * 设置连接池检查连接超时的间隔时间 + * + * @param timeoutCheckInterval + * 连接池检查连接超时的间隔时间 + */ + public void setTimeoutCheckInterval(Duration timeoutCheckInterval) { + this.timeoutCheckInterval = timeoutCheckInterval; + } + + /** + * 返回连接池中每个连接所能缓存的最大 SQL 预编译语句(Prepared Statements)的数量 + * + * @return 连接池中每个连接所能缓存的最大 SQL 预编译语句(Prepared Statements)的数量 + */ + public Integer getMaxStatements() { + return maxStatements; + } + + /** + * 设置连接池中每个连接所能缓存的最大 SQL 预编译语句(Prepared Statements)的数量 + * + * @param maxStatements + * 连接池中每个连接所能缓存的最大 SQL 预编译语句(Prepared Statements)的数量 + */ + public void setMaxStatements(Integer maxStatements) { + this.maxStatements = maxStatements; + } + + /** + * 返回触发连接池收割(Harvesting)操作的阈值,表示连接池中空闲连接的数量达到多少时触发收割操作 + * + * @return 触发连接池收割(Harvesting)操作的阈值,表示连接池中空闲连接的数量达到多少时触发收割操作 + */ + public Integer getConnectionHarvestTriggerCount() { + return connectionHarvestTriggerCount; + } + + /** + * 设置触发连接池收割(Harvesting)操作的阈值,表示连接池中空闲连接的数量达到多少时触发收割操作 + * + * @param connectionHarvestTriggerCount + * 触发连接池收割(Harvesting)操作的阈值,表示连接池中空闲连接的数量达到多少时触发收割操作 + */ + public void setConnectionHarvestTriggerCount(Integer connectionHarvestTriggerCount) { + this.connectionHarvestTriggerCount = connectionHarvestTriggerCount; + } + + /** + * 返回在一次连接收割操作中,最多可以从连接池中收回的连接数量 + * + * @return 在一次连接收割操作中,最多可以从连接池中收回的连接数量 + */ + public Integer getConnectionHarvestMaxCount() { + return connectionHarvestMaxCount; + } + + /** + * 设置在一次连接收割操作中,最多可以从连接池中收回的连接数量 + * + * @param connectionHarvestMaxCount + * 在一次连接收割操作中,最多可以从连接池中收回的连接数量 + */ + public void setConnectionHarvestMaxCount(Integer connectionHarvestMaxCount) { + this.connectionHarvestMaxCount = connectionHarvestMaxCount; + } + + /** + * 返回从连接池获取一个连接时,是否验证有效性 + * + * @return 从连接池获取一个连接时,验证有效性 + */ + public Boolean isValidateConnectionOnBorrow() { + return getValidateConnectionOnBorrow(); + } + + /** + * 返回从连接池获取一个连接时,是否验证有效性 + * + * @return 从连接池获取一个连接时,验证有效性 + */ + public Boolean getValidateConnectionOnBorrow() { + return validateConnectionOnBorrow; + } + + /** + * 设置从连接池获取一个连接时,是否验证有效性 + * + * @param validateConnectionOnBorrow + * 从连接池获取一个连接时,是否验证有效性 + */ + public void setValidateConnectionOnBorrow(Boolean validateConnectionOnBorrow) { + this.validateConnectionOnBorrow = validateConnectionOnBorrow; + super.setTestOnBorrow(validateConnectionOnBorrow); + } + + @Override + public void setTestOnBorrow(Boolean testOnBorrow) { + setValidateConnectionOnBorrow(testOnBorrow); + } + + /** + * 返回连接在被认为是“被遗弃”状态下的最大时间 + * + * @return 连接在被认为是“被遗弃”状态下的最大时间 + */ + public Duration getAbandonedConnectionTimeout() { + return abandonedConnectionTimeout; + } + + /** + * 设置连接在被认为是“被遗弃”状态下的最大时间 + * + * @param abandonedConnectionTimeout + * 连接在被认为是“被遗弃”状态下的最大时间 + */ + public void setAbandonedConnectionTimeout(Duration abandonedConnectionTimeout) { + this.abandonedConnectionTimeout = abandonedConnectionTimeout; + super.setRemoveAbandonedTimeout(abandonedConnectionTimeout); + } + + @Override + public void setRemoveAbandonedTimeout(Duration removeAbandonedTimeout) { + setAbandonedConnectionTimeout(removeAbandonedTimeout); + } + + /** + * 返回否允许从只读实例获取连接 + * + * @return 否允许从只读实例获取连接 + */ + public Boolean isReadOnlyInstanceAllowed() { + return getReadOnlyInstanceAllowed(); + } + + /** + * 返回否允许从只读实例获取连接 + * + * @return 否允许从只读实例获取连接 + */ + public Boolean getReadOnlyInstanceAllowed() { + return readOnlyInstanceAllowed; + } + + /** + * 设置否允许从只读实例获取连接 + * + * @param readOnlyInstanceAllowed + * 否允许从只读实例获取连接 + */ + public void setReadOnlyInstanceAllowed(Boolean readOnlyInstanceAllowed) { + this.readOnlyInstanceAllowed = readOnlyInstanceAllowed; + } + + /** + * 返回是否在借用连接的线程中创建连接 + * + * @return 是否在借用连接的线程中创建连接 + */ + public Boolean isCreateConnectionInBorrowThread() { + return getCreateConnectionInBorrowThread(); + } + + /** + * 返回是否在借用连接的线程中创建连接 + * + * @return 是否在借用连接的线程中创建连接 + */ + public Boolean getCreateConnectionInBorrowThread() { + return createConnectionInBorrowThread; + } + + /** + * 设置是否在借用连接的线程中创建连接 + * + * @param createConnectionInBorrowThread + * 是否在借用连接的线程中创建连接 + */ + public void setCreateConnectionInBorrowThread(Boolean createConnectionInBorrowThread) { + this.createConnectionInBorrowThread = createConnectionInBorrowThread; + } + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/PoolConfiguration.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/PoolConfiguration.java new file mode 100644 index 000000000..cec5b45b0 --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/PoolConfiguration.java @@ -0,0 +1,383 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.datasource.pool; + +import com.buession.jdbc.core.Jmx; + +import java.time.Duration; + +/** + * 连接池配置 + * + * @author Yong.Teng + * @since 1.3.2 + */ +public interface PoolConfiguration { + + /** + * 返回用户定义连接池的名称 + * + * @return 用户定义连接池的名称 + */ + String getPoolName(); + + /** + * 设置连接池的名称 + * + * @param poolName + * 连接池的名称 + */ + void setPoolName(String poolName); + + /** + * 返回初始连接数 + * + * @return 初始连接数 + */ + Integer getInitialSize(); + + /** + * 设置初始连接数 + * + * @param initialSize + * 初始连接数 + */ + void setInitialSize(Integer initialSize); + + /** + * 返回最小空闲连接数 + * + * @return 最小空闲连接数 + */ + Integer getMinIdle(); + + /** + * 设置最小空闲连接数 + * + * @param minIdle + * 最小空闲连接数 + */ + void setMinIdle(Integer minIdle); + + /** + * 返回最大空闲连接数 + * + * @return 最大空闲连接数 + */ + Integer getMaxIdle(); + + /** + * 设置最大空闲连接数,如设置为负数,则不限制 + * + * @param maxIdle + * 最大空闲连接数 + */ + void setMaxIdle(Integer maxIdle); + + /** + * 返回最大连接数 + * + * @return 最大连接数 + */ + Integer getMaxTotal(); + + /** + * 设置最大连接数,如设置为负数,则不限制 + * + * @param maxTotal + * 最大连接数 + */ + void setMaxTotal(Integer maxTotal); + + /** + * 返回从连接池获取一个连接时,最大的等待时间 + * + * @return 从连接池获取一个连接时,最大的等待时间 + */ + Duration getMaxWait(); + + /** + * 设置从连接池获取一个连接时,最大的等待时间 + * + * @param maxWait + * 从连接池获取一个连接时,最大的等待时间 + */ + void setMaxWait(Duration maxWait); + + /** + * 返回连接创建后,是否马上验证有效性 + * + * @return 连接创建后,是否马上验证有效性 + */ + default Boolean isTestOnCreate() { + return getTestOnCreate(); + } + + /** + * 返回连接创建后,是否马上验证有效性 + * + * @return 连接创建后,是否马上验证有效性 + */ + Boolean getTestOnCreate(); + + /** + * 设置连接创建后,是否马上验证有效性 + * + * @param testOnCreate + * 连接创建后,是否马上验证有效性 + */ + void setTestOnCreate(Boolean testOnCreate); + + /** + * 返回从连接池获取一个连接时,是否验证有效性 + * + * @return 从连接池获取一个连接时,验证有效性 + */ + default Boolean isTestOnBorrow() { + return getTestOnBorrow(); + } + + /** + * 返回从连接池获取一个连接时,是否验证有效性 + * + * @return 从连接池获取一个连接时,验证有效性 + */ + Boolean getTestOnBorrow(); + + /** + * 设置从连接池获取一个连接时,是否验证有效性 + * + * @param testOnBorrow + * 从连接池获取一个连接时,是否验证有效性 + */ + void setTestOnBorrow(Boolean testOnBorrow); + + /** + * 返回连接被归还到连接池时,是否验证有效性 + * + * @return 连接被归还到连接池时,是否验证有效性 + */ + default Boolean isTestOnReturn() { + return getTestOnReturn(); + } + + /** + * 返回连接被归还到连接池时,是否验证有效性 + * + * @return 连接被归还到连接池时,是否验证有效性 + */ + Boolean getTestOnReturn(); + + /** + * 设置连接被归还到连接池时,是否验证有效性 + * + * @param testOnReturn + * 连接被归还到连接池时,是否验证有效性 + */ + void setTestOnReturn(Boolean testOnReturn); + + /** + * 返回连接空闲时,是否验证有效性 + * + * @return 连接空闲时,是否验证有效性 + */ + default Boolean isTestWhileIdle() { + return getTestWhileIdle(); + } + + /** + * 返回连接空闲时,是否验证有效性 + * + * @return 连接空闲时,是否验证有效性 + */ + Boolean getTestWhileIdle(); + + /** + * 设置连接空闲时,是否验证有效性 + * + * @param testWhileIdle + * 连接空闲时,是否验证有效性 + */ + void setTestWhileIdle(Boolean testWhileIdle); + + /** + * 返回从连接池获取连接时, 验证连接是否可用的SQL语句 + * + * @return 从连接池获取连接时, 验证连接是否可用的SQL语句 + */ + String getValidationQuery(); + + /** + * 设置从连接池获取连接时, 验证连接是否可用的SQL语句 + * + * @param validationQuery + * 从连接池获取连接时, 验证连接是否可用的SQL语句 + */ + void setValidationQuery(String validationQuery); + + /** + * 返回连接有效SQL的执行查询超时时间 + * + * @return 连接有效SQL的执行查询超时时间 + * + * @since 3.0.0 + */ + Duration getValidationQueryTimeout(); + + /** + * 设置连接有效SQL的执行查询超时时间 + * + * @param validationQueryTimeout + * 连接有效SQL的执行查询超时时间 + * + * @since 3.0.0 + */ + void setValidationQueryTimeout(Duration validationQueryTimeout); + + /** + * 返回空闲的连接被释放最低要待时间 + * + * @return 空闲的连接被释放最低要待时间 + */ + Duration getMinEvictableIdle(); + + /** + * 设置空闲的连接被释放最低要待时间 + * + * @param minEvictableIdle + * 空闲的连接被释放最低要待时间 + */ + void setMinEvictableIdle(Duration minEvictableIdle); + + /** + * 返回空闲的连接被释放最高要待时间 + * + * @return 空闲的连接被释放最高要待时间 + */ + Duration getMaxEvictableIdle(); + + /** + * 设置空闲的连接被释放最高要待时间 + * + * @param maxEvictableIdle + * 空闲的连接被释放最高要待时间 + */ + void setMaxEvictableIdle(Duration maxEvictableIdle); + + /** + * 返回在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 + * + * @return 在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 + */ + Integer getNumTestsPerEvictionRun(); + + /** + * 设置在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 + * + * @param numTestsPerEvictionRun + * 在每个空闲对象驱逐线程运行过程中中进行检查的对象个数 + */ + void setNumTestsPerEvictionRun(Integer numTestsPerEvictionRun); + + /** + * 返回空闲对象驱逐线程运行时的休眠时间 + * + * @return 空闲对象驱逐线程运行时的休眠时间 + */ + Duration getTimeBetweenEvictionRuns(); + + /** + * 设置空闲对象驱逐线程运行时的休眠时间 + * + * @param timeBetweenEvictionRuns + * 空闲对象驱逐线程运行时的休眠时间 + */ + void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns); + + /** + * 返回当连接被认为是废弃并且被移除时是否记录日志 + * + * @return 当连接被认为是废弃并且被移除时是否记录日志 + * + * @since 3.0.0 + */ + default Boolean isLogAbandoned() { + return getLogAbandoned(); + } + + /** + * 返回当连接被认为是废弃并且被移除时是否记录日志 + * + * @return 当连接被认为是废弃并且被移除时是否记录日志 + * + * @since 3.0.0 + */ + Boolean getLogAbandoned(); + + /** + * 设置当连接被认为是废弃并且被移除时是否记录日志 + * + * @param logAbandoned + * 当连接被认为是废弃并且被移除时是否记录日志 + * + * @since 3.0.0 + */ + void setLogAbandoned(Boolean logAbandoned); + + /** + * 返回指定连接在被认为是废弃连接(abandoned connection)之前的超时时间 + * + * @return 指定连接在被认为是废弃连接(abandoned connection)之前的超时时间 + * + * @since 3.0.0 + */ + Duration getRemoveAbandonedTimeout(); + + /** + * 设置指定连接在被认为是废弃连接(abandoned connection)之前的超时时间 + * + * @param removeAbandonedTimeout + * 指定连接在被认为是废弃连接(abandoned connection)之前的超时时间 + * + * @since 3.0.0 + */ + void setRemoveAbandonedTimeout(Duration removeAbandonedTimeout); + + /** + * 返回 JMX 管理对象配置 + * + * @return JMX 管理对象配置 + */ + Jmx getJmx(); + + /** + * 设置 JMX 管理对象配置 + * + * @param jmx + * JMX 管理对象配置 + */ + void setJmx(Jmx jmx); + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/TomcatPoolConfiguration.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/TomcatPoolConfiguration.java new file mode 100644 index 000000000..0382108b0 --- /dev/null +++ b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/TomcatPoolConfiguration.java @@ -0,0 +1,487 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.jdbc.datasource.pool; + +import org.apache.tomcat.jdbc.pool.PoolProperties; + +import java.beans.Statement; +import java.time.Duration; + +/** + * Tomcat 数据源连接池配置 {@link PoolProperties} + * + * @author Yong.Teng + * @since 1.3.2 + */ +public class TomcatPoolConfiguration extends AbstractPoolConfiguration { + + /** + * 最大连接数,可以在这个池中同一时刻被分配的有效连接数的最大值,如设置为负数,则不限制 + * + * @since 3.0.0 + */ + private Integer maxActive; + + /** + * 连接在连接池中最大存在的时间 + */ + private Duration maxAge; + + /** + * 创建连接时测试连接的有效性 + */ + private Boolean testOnConnect; + + /** + * 是否使用一个包装的连接 facade 来管理和处理连接池中的连接 + */ + private Boolean useDisposableConnectionFacade; + + /** + * 标记初始化池时是否忽略连接创建错误 + */ + private Boolean ignoreExceptionOnPreLoad; + + /** + * 连接池的请求排队策略,当为 {@code true} 时,为使用公平的排队策略;当为 {@code false} 时,为不使用公平的排队策略 + */ + private Boolean fairQueue; + + /** + * 是否使用包装的 {@link Statement} 对象 + */ + private Boolean useStatementFacade; + + /** + * 是否移除抛弃的(abandoned)连接,一个连接使用超过了 removeAbandonedTimeout 上限就被视为抛弃的, + * 开启该开关可以恢复那些应用没有关闭的连接 + */ + private Boolean removeAbandoned; + + /** + * 连接被认为是可疑的超时时间 + */ + private Duration suspectTimeout; + + /** + * 除非正在使用的连接数超过定义的百分比, + * 否则已放弃(超时)的连接不会关闭并报告 abandonWhenPercentageFull; + * 该值应介于0到100之间。默认值为0,这表示一旦 removeAbandonedTimeout 达到连接就可以关闭连接 + */ + private Integer abandonWhenPercentageFull; + + /** + * 将此值设置为true可以传播已被中断的线程的中断状态(不清除中断状态) + */ + private Boolean propagateInterruptState; + + /** + * 将此属性设置为true可以在验证阶段将错误记录到日志文件中 + */ + private Boolean logValidationErrors; + + /** + * 是否使用锁机制来管理连接池中的连接 + */ + private Boolean useLock; + + /** + * 是否使用 {@link #equals()} 方法来比较连接池中的连接 + */ + private Boolean useEquals; + + /** + * 返回最大连接数 + * + * @return 最大连接数 + * + * @since 3.0.0 + */ + public Integer getMaxActive() { + return maxActive; + } + + /** + * 设置最大连接数 + * + * @param maxActive + * 最大连接数 + * + * @since 3.0.0 + */ + public void setMaxActive(Integer maxActive) { + this.maxActive = maxActive; + super.setMaxTotal(maxActive); + } + + @Override + public void setMaxTotal(Integer maxTotal) { + setMaxActive(maxTotal); + } + + /** + * 返回连接在连接池中最大存在的时间 + * + * @return 连接在连接池中最大存在的时间 + */ + public Duration getMaxAge() { + return maxAge; + } + + /** + * 设置连接在连接池中最大存在的时间 + * + * @param maxAge + * 连接在连接池中最大存在的时间 + */ + public void setMaxAge(Duration maxAge) { + this.maxAge = maxAge; + } + + /** + * 返回创建连接时是否测试连接的有效性 + * + * @return 创建连接时是否测试连接的有效性 + */ + public Boolean isTestOnConnect() { + return getTestOnConnect(); + } + + /** + * 返回创建连接时是否测试连接的有效性 + * + * @return 创建连接时是否测试连接的有效性 + */ + public Boolean getTestOnConnect() { + return testOnConnect; + } + + /** + * 设置创建连接时是否测试连接的有效性 + * + * @param testOnConnect + * 创建连接时是否测试连接的有效性 + */ + public void setTestOnConnect(Boolean testOnConnect) { + this.testOnConnect = testOnConnect; + super.setTestOnCreate(testOnConnect); + } + + @Override + public void setTestOnCreate(Boolean testOnCreate) { + setTestOnConnect(testOnCreate); + } + + /** + * 返回是否使用一个包装的连接 facade 来管理和处理连接池中的连接 + * + * @return 是否使用一个包装的连接 facade 来管理和处理连接池中的连接 + */ + public Boolean isUseDisposableConnectionFacade() { + return getUseDisposableConnectionFacade(); + } + + /** + * 返回是否使用一个包装的连接 facade 来管理和处理连接池中的连接 + * + * @return 是否使用一个包装的连接 facade 来管理和处理连接池中的连接 + */ + public Boolean getUseDisposableConnectionFacade() { + return useDisposableConnectionFacade; + } + + /** + * 设置是否使用一个包装的连接 facade 来管理和处理连接池中的连接 + * + * @param useDisposableConnectionFacade + * 是否使用一个包装的连接 facade 来管理和处理连接池中的连接 + */ + public void setUseDisposableConnectionFacade(Boolean useDisposableConnectionFacade) { + this.useDisposableConnectionFacade = useDisposableConnectionFacade; + } + + /** + * 返回标记初始化池时是否忽略连接创建错误 + * + * @return 初始化池时是否忽略连接创建错误 + */ + public Boolean isIgnoreExceptionOnPreLoad() { + return getIgnoreExceptionOnPreLoad(); + } + + /** + * 返回标记初始化池时是否忽略连接创建错误 + * + * @return 初始化池时是否忽略连接创建错误 + */ + public Boolean getIgnoreExceptionOnPreLoad() { + return ignoreExceptionOnPreLoad; + } + + /** + * 设置标记初始化池时是否忽略连接创建错误;如果要在初始化池时忽略连接创建错误,请设置为true + * + * @param ignoreExceptionOnPreLoad + * 初始化池时是否忽略连接创建错误 + */ + public void setIgnoreExceptionOnPreLoad(Boolean ignoreExceptionOnPreLoad) { + this.ignoreExceptionOnPreLoad = ignoreExceptionOnPreLoad; + } + + /** + * 返回连接池的请求排队策略,当为 {@code true} 时,为使用公平的排队策略;当为 {@code false} 时,为不使用公平的排队策略 + * + * @return 连接池的请求排队策略 + */ + public Boolean isFairQueue() { + return getFairQueue(); + } + + /** + * 返回连接池的请求排队策略,当为 {@code true} 时,为使用公平的排队策略;当为 {@code false} 时,为不使用公平的排队策略 + * + * @return 连接池的请求排队策略 + */ + public Boolean getFairQueue() { + return fairQueue; + } + + /** + * 设置连接池的请求排队策略,当为 {@code true} 时,为使用公平的排队策略;当为 {@code false} 时,为不使用公平的排队策略 + * + * @param fairQueue + * 连接池的请求排队策略 + */ + public void setFairQueue(Boolean fairQueue) { + this.fairQueue = fairQueue; + } + + /** + * 返回使用包装的 {@link Statement} 对象 + * + * @return 使用包装的 {@link Statement} 对象 + */ + public Boolean isUseStatementFacade() { + return getUseStatementFacade(); + } + + /** + * 返回使用包装的 {@link Statement} 对象 + * + * @return 使用包装的 {@link Statement} 对象 + */ + public Boolean getUseStatementFacade() { + return useStatementFacade; + } + + /** + * 设置是使用包装的 {@link Statement} 对象 + * + * @param useStatementFacade + * 使用包装的 {@link Statement} 对象 + */ + public void setUseStatementFacade(Boolean useStatementFacade) { + this.useStatementFacade = useStatementFacade; + } + + /** + * 返回是否移除抛弃的(abandoned)连接 + * + * @return 是否移除抛弃的(abandoned)连接 + */ + public Boolean isRemoveAbandoned() { + return getRemoveAbandoned(); + } + + /** + * 返回是否移除抛弃的(abandoned)连接 + * + * @return 是否移除抛弃的(abandoned)连接 + */ + public Boolean getRemoveAbandoned() { + return removeAbandoned; + } + + /** + * 设置是否移除抛弃的(abandoned)连接 + * + * @param removeAbandoned + * 是否移除抛弃的(abandoned)连接 + */ + public void setRemoveAbandoned(Boolean removeAbandoned) { + this.removeAbandoned = removeAbandoned; + } + + /** + * 连接被认为是可疑的超时时间 + * + * @return 连接被认为是可疑的超时时间 + */ + public Duration getSuspectTimeout() { + return suspectTimeout; + } + + /** + * 连接被认为是可疑的超时时间 + * + * @param suspectTimeout + * 连接被认为是可疑的超时时间 + */ + public void setSuspectTimeout(Duration suspectTimeout) { + this.suspectTimeout = suspectTimeout; + } + + /** + * 返回正在使用的连接数超过定义的百分比 + * + * @return 正在使用的连接数超过定义的百分比 + */ + public Integer getAbandonWhenPercentageFull() { + return abandonWhenPercentageFull; + } + + /** + * 设置正在使用的连接数超过定义的百分比 + * + * @param abandonWhenPercentageFull + * 正在使用的连接数超过定义的百分比 + */ + public void setAbandonWhenPercentageFull(Integer abandonWhenPercentageFull) { + this.abandonWhenPercentageFull = abandonWhenPercentageFull; + } + + /** + * 返回是否传播已被中断的线程的中断状态 + * + * @return 是否传播已被中断的线程的中断状态 + */ + public Boolean isPropagateInterruptState() { + return getPropagateInterruptState(); + } + + /** + * 返回是否传播已被中断的线程的中断状态 + * + * @return 是否传播已被中断的线程的中断状态 + */ + public Boolean getPropagateInterruptState() { + return propagateInterruptState; + } + + /** + * 设置是否传播已被中断的线程的中断状态 + * + * @param propagateInterruptState + * 是否传播已被中断的线程的中断状态 + */ + public void setPropagateInterruptState(Boolean propagateInterruptState) { + this.propagateInterruptState = propagateInterruptState; + } + + /** + * 返回验证阶段将错误记录到日志文件中 + * + * @return 验证阶段将错误记录到日志文件中 + */ + public Boolean isLogValidationErrors() { + return getLogValidationErrors(); + } + + /** + * 返回验证阶段将错误记录到日志文件中 + * + * @return 验证阶段将错误记录到日志文件中 + */ + public Boolean getLogValidationErrors() { + return logValidationErrors; + } + + /** + * 设置验证阶段将错误记录到日志文件中 + * + * @param logValidationErrors + * 验证阶段将错误记录到日志文件中 + */ + public void setLogValidationErrors(Boolean logValidationErrors) { + this.logValidationErrors = logValidationErrors; + } + + /** + * 返回是否使用锁机制来管理连接池中的连接 + * + * @return 是否使用锁机制来管理连接池中的连接 + */ + public Boolean isUseLock() { + return getUseLock(); + } + + /** + * 返回是否使用锁机制来管理连接池中的连接 + * + * @return 是否使用锁机制来管理连接池中的连接 + */ + public Boolean getUseLock() { + return useLock; + } + + /** + * 设置是否使用锁机制来管理连接池中的连接 + * + * @param useLock + * 是否使用锁机制来管理连接池中的连接 + */ + public void setUseLock(Boolean useLock) { + this.useLock = useLock; + } + + /** + * 返回是否使用 {@link #equals(Object obj)} 方法来比较连接池中的连接 + * + * @return 是否使用 {@link #equals(Object obj)} 方法来比较连接池中的连接 + */ + public Boolean isUseEquals() { + return getUseEquals(); + } + + /** + * 返回是否使用 {@link #equals(Object obj)} 方法来比较连接池中的连接 + * + * @return 是否使用 {@link #equals(Object obj)} 方法来比较连接池中的连接 + */ + public Boolean getUseEquals() { + return useEquals; + } + + /** + * 设置是否使用 {@link #equals(Object obj)} 方法来比较连接池中的连接 + * + * @param useEquals + * 是否使用 {@link #equals(Object obj)} 方法来比较连接池中的连接 + */ + public void setUseEquals(Boolean useEquals) { + this.useEquals = useEquals; + } + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/package-info.java b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/package-info.java similarity index 97% rename from buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/package-info.java rename to buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/package-info.java index af5c83f10..2b6da1364 100644 --- a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/package-info.java +++ b/buession-jdbc/src/main/java/com/buession/jdbc/datasource/pool/package-info.java @@ -26,4 +26,4 @@ * @author Yong.Teng * @since 1.3.2 */ -package com.buession.jdbc.datasource.config; \ No newline at end of file +package com.buession.jdbc.datasource.pool; \ No newline at end of file diff --git a/buession-jdbc/src/main/java/com/zaxxer/hikari/utils/ObjectUtils.java b/buession-jdbc/src/main/java/com/zaxxer/hikari/utils/ObjectUtils.java new file mode 100644 index 000000000..c583edd82 --- /dev/null +++ b/buession-jdbc/src/main/java/com/zaxxer/hikari/utils/ObjectUtils.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.zaxxer.hikari.utils; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class ObjectUtils { + + protected ObjectUtils() { + + } + + public static T newInstance(final String className) throws IllegalStateException { + try{ + Class clazz = loadClass(className); + return (T) clazz.newInstance(); + }catch(ClassNotFoundException e){ + throw new IllegalStateException(e); + }catch(InstantiationException e){ + throw new IllegalStateException(e); + }catch(IllegalAccessException e){ + throw new IllegalStateException(e); + } + } + + public static Class loadClass(final String className) throws ClassNotFoundException { + try{ + return Class.forName(className); + }catch(ClassNotFoundException e){ + ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader(); + + if(ctxClassLoader != null){ + try{ + return ctxClassLoader.loadClass(className); + }catch(ClassNotFoundException ex){ + throw ex; + } + } + } + + return null; + } + +} diff --git a/buession-json/pom.xml b/buession-json/pom.xml index 1e2fde60e..659cf3988 100644 --- a/buession-json/pom.xml +++ b/buession-json/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-json http://www.buession.com/ @@ -59,7 +59,7 @@ org.springframework - spring-context + * @@ -77,27 +77,14 @@ jackson-databind - - org.apache.commons - commons-text - provided - - - - org.jsoup - jsoup - 1.17.2 - provided - - org.slf4j slf4j-api - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -141,8 +128,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-json/src/test/java/com/buession/json/EnumSerializer.java b/buession-json/src/test/java/com/buession/json/EnumSerializer.java index 81924e173..2b4c12320 100644 --- a/buession-json/src/test/java/com/buession/json/EnumSerializer.java +++ b/buession-json/src/test/java/com/buession/json/EnumSerializer.java @@ -19,15 +19,14 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://buession.buession.com.cn/LICENSE | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.json; import com.buession.json.annotation.JsonEnum2Map; -import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.StringJoiner; diff --git a/buession-json/src/test/java/com/buession/json/MapSerializerTest.java b/buession-json/src/test/java/com/buession/json/MapSerializerTest.java index c45c0c28f..342f2efa4 100644 --- a/buession-json/src/test/java/com/buession/json/MapSerializerTest.java +++ b/buession-json/src/test/java/com/buession/json/MapSerializerTest.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://buession.buession.com.cn/LICENSE | * | Author: Yong.Teng | - * | Copyright @ 2013-2018 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.json; @@ -30,7 +30,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.io.Serializable; @@ -42,304 +42,304 @@ */ public class MapSerializerTest { - @Test - public void enum2MapSerializer(){ - Example example = new Example(); + @Test + public void enum2MapSerializer() { + Example example = new Example(); - example.setGender(Gender.FEMALE); + example.setGender(Gender.FEMALE); - ObjectMapper objectMapper = new ObjectMapper(); - try{ - System.out.println(objectMapper.writeValueAsString(example)); - }catch(JsonProcessingException e){ - e.printStackTrace(); - } - } + ObjectMapper objectMapper = new ObjectMapper(); + try{ + System.out.println(objectMapper.writeValueAsString(example)); + }catch(JsonProcessingException e){ + e.printStackTrace(); + } + } - @Test - public void map2EnumDeserizlizer(){ - String str = "[{\"id\":1,\"customerId\":1,\"customer\":null,\"email\":\"webmaster@liangvi.com\"," + - "\"password\":null,\"salt\":null,\"realName\":\"腾勇\",\"mobile\":\"13438174292\"," + - "\"createdAt\":1487421335000,\"createdIp\":\"127.0.0.1\",\"createdLocation\":null,\"loginTimes\":265," + + @Test + public void map2EnumDeserizlizer() { + String str = "[{\"id\":1,\"customerId\":1,\"customer\":null,\"email\":\"webmaster@liangvi.com\"," + + "\"password\":null,\"salt\":null,\"realName\":\"腾勇\",\"mobile\":\"13438174292\"," + + "\"createdAt\":1487421335000,\"createdIp\":\"127.0.0.1\",\"createdLocation\":null,\"loginTimes\":265," + - "\"loginAt\":1524409881000," + "\"loginIp\":\"0:0:0:0:0:0:0:1\"," + "\"loginLocation\":null," + - "\"lastLoginAt\":1524409086000," + "\"lastLoginIp\":\"0:0:0:0:0:0:0:1\"," + - "\"lastLoginLocation\":null," + "\"status\":{\"value\":1," + "\"description\":\"正常\"}}]"; + "\"loginAt\":1524409881000," + "\"loginIp\":\"0:0:0:0:0:0:0:1\"," + "\"loginLocation\":null," + + "\"lastLoginAt\":1524409086000," + "\"lastLoginIp\":\"0:0:0:0:0:0:0:1\"," + + "\"lastLoginLocation\":null," + "\"status\":{\"value\":1," + "\"description\":\"正常\"}}]"; - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - try{ - List users = objectMapper.readValue(str, new TypeReference>() { + try{ + List users = objectMapper.readValue(str, new TypeReference>() { - }); + }); - System.out.println(users.get(0).getStatus()); - }catch(JsonProcessingException e){ - e.printStackTrace(); - }catch(IOException e){ - e.printStackTrace(); - } - } + System.out.println(users.get(0).getStatus()); + }catch(JsonProcessingException e){ + e.printStackTrace(); + }catch(IOException e){ + e.printStackTrace(); + } + } - @Test - public void map2EnumDeserizlizerS(){ - String str = "{\"gender\":{\"value\":1," + "\"desc\":\"女\"}}"; + @Test + public void map2EnumDeserizlizerS() { + String str = "{\"gender\":{\"value\":1," + "\"desc\":\"女\"}}"; - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - try{ - Example user = objectMapper.readValue(str, Example.class); + try{ + Example user = objectMapper.readValue(str, Example.class); - System.out.println(user.getGender()); - }catch(JsonProcessingException e){ - e.printStackTrace(); - }catch(IOException e){ - e.printStackTrace(); - } - } + System.out.println(user.getGender()); + }catch(JsonProcessingException e){ + e.printStackTrace(); + }catch(IOException e){ + e.printStackTrace(); + } + } - private final static class Example { + private final static class Example { - @JsonEnum2Map - private Gender gender; + @JsonEnum2Map + private Gender gender; - @JsonEnum2Map - public Gender getGender(){ - return gender; - } + @JsonEnum2Map + public Gender getGender() { + return gender; + } - public void setGender(Gender gender){ - this.gender = gender; - } - } + public void setGender(Gender gender) { + this.gender = gender; + } + } - private enum Gender { + private enum Gender { - MALE(0, "男"), + MALE(0, "男"), - FEMALE(1, "女"); + FEMALE(1, "女"); - private int value; + private int value; - private String desc; + private String desc; - Gender(int value, String desc){ - this.value = value; - this.desc = desc; - } + Gender(int value, String desc) { + this.value = value; + this.desc = desc; + } - } + } - public final static class User implements Serializable { + public final static class User implements Serializable { - private static final long serialVersionUID = -1924992522420542301L; + private static final long serialVersionUID = -1924992522420542301L; - private int id; + private int id; - private short customerId; + private short customerId; - private String email; + private String email; - private String password; + private String password; - private String salt; + private String salt; - private String realName; + private String realName; - private String mobile; + private String mobile; - private Date createdAt; + private Date createdAt; - private String createdIp; + private String createdIp; - private short loginTimes; + private short loginTimes; - private Date loginAt; + private Date loginAt; - private String loginIp; + private String loginIp; - private Date lastLoginAt; + private Date lastLoginAt; - private String lastLoginIp; + private String lastLoginIp; - @JsonEnum2Map - private Status status; + @JsonEnum2Map + private Status status; - @JsonIgnore - private boolean isDeleted; + @JsonIgnore + private boolean isDeleted; - public int getId(){ - return id; - } + public int getId() { + return id; + } - public void setId(int id){ - this.id = id; - } + public void setId(int id) { + this.id = id; + } - public short getCustomerId(){ - return customerId; - } + public short getCustomerId() { + return customerId; + } - public void setCustomerId(short customerId){ - this.customerId = customerId; - } + public void setCustomerId(short customerId) { + this.customerId = customerId; + } - public String getEmail(){ - return email; - } + public String getEmail() { + return email; + } - public void setEmail(String email){ - this.email = email; - } + public void setEmail(String email) { + this.email = email; + } - public String getPassword(){ - return password; - } + public String getPassword() { + return password; + } - public void setPassword(String password){ - this.password = password; - } + public void setPassword(String password) { + this.password = password; + } - public String getSalt(){ - return salt; - } + public String getSalt() { + return salt; + } - public void setSalt(String salt){ - this.salt = salt; - } + public void setSalt(String salt) { + this.salt = salt; + } - public String getRealName(){ - return realName; - } + public String getRealName() { + return realName; + } - public void setRealName(String realName){ - this.realName = realName; - } + public void setRealName(String realName) { + this.realName = realName; + } - public String getMobile(){ - return mobile; - } + public String getMobile() { + return mobile; + } - public void setMobile(String mobile){ - this.mobile = mobile; - } + public void setMobile(String mobile) { + this.mobile = mobile; + } - public Date getCreatedAt(){ - return createdAt; - } + public Date getCreatedAt() { + return createdAt; + } - public void setCreatedAt(Date createdAt){ - this.createdAt = createdAt; - } + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } - public String getCreatedIp(){ - return createdIp; - } + public String getCreatedIp() { + return createdIp; + } - public void setCreatedIp(String createdIp){ - this.createdIp = createdIp; - } + public void setCreatedIp(String createdIp) { + this.createdIp = createdIp; + } - public short getLoginTimes(){ - return loginTimes; - } + public short getLoginTimes() { + return loginTimes; + } - public void setLoginTimes(short loginTimes){ - this.loginTimes = loginTimes; - } + public void setLoginTimes(short loginTimes) { + this.loginTimes = loginTimes; + } - public Date getLoginAt(){ - return loginAt; - } + public Date getLoginAt() { + return loginAt; + } - public void setLoginAt(Date loginAt){ - this.loginAt = loginAt; - } + public void setLoginAt(Date loginAt) { + this.loginAt = loginAt; + } - public String getLoginIp(){ - return loginIp; - } + public String getLoginIp() { + return loginIp; + } - public void setLoginIp(String loginIp){ - this.loginIp = loginIp; - } + public void setLoginIp(String loginIp) { + this.loginIp = loginIp; + } - public Date getLastLoginAt(){ - return lastLoginAt; - } + public Date getLastLoginAt() { + return lastLoginAt; + } - public void setLastLoginAt(Date lastLoginAt){ - this.lastLoginAt = lastLoginAt; - } + public void setLastLoginAt(Date lastLoginAt) { + this.lastLoginAt = lastLoginAt; + } - public String getLastLoginIp(){ - return lastLoginIp; - } + public String getLastLoginIp() { + return lastLoginIp; + } - public void setLastLoginIp(String lastLoginIp){ - this.lastLoginIp = lastLoginIp; - } + public void setLastLoginIp(String lastLoginIp) { + this.lastLoginIp = lastLoginIp; + } - @JsonEnum2Map - public Status getStatus(){ - return status; - } + @JsonEnum2Map + public Status getStatus() { + return status; + } - public void setStatus(Status status){ - this.status = status; - } + public void setStatus(Status status) { + this.status = status; + } - @JsonIgnore - public boolean isDeleted(){ - return getIsDeleted(); - } + @JsonIgnore + public boolean isDeleted() { + return getIsDeleted(); + } - @JsonIgnore - public boolean getIsDeleted(){ - return isDeleted; - } + @JsonIgnore + public boolean getIsDeleted() { + return isDeleted; + } - public void setDeleted(boolean isDeleted){ - setIsDeleted(isDeleted); - } + public void setDeleted(boolean isDeleted) { + setIsDeleted(isDeleted); + } - public void setIsDeleted(boolean isDeleted){ - this.isDeleted = isDeleted; - } + public void setIsDeleted(boolean isDeleted) { + this.isDeleted = isDeleted; + } - public enum Status { + public enum Status { - // 未激活 - NOT_ACTIVATED(0, "未激活"), + // 未激活 + NOT_ACTIVATED(0, "未激活"), - // 正常 - NORMAL(1, "正常"), + // 正常 + NORMAL(1, "正常"), - // 冻结 - FREEZE(2, "冻结"); + // 冻结 + FREEZE(2, "冻结"); - private int value; + private int value; - private String description; + private String description; - Status(int value, String description){ - this.value = value; - this.description = description; - } + Status(int value, String description) { + this.value = value; + this.description = description; + } - public int getValue(){ - return value; - } + public int getValue() { + return value; + } - public String getDescription(){ - return description; - } + public String getDescription() { + return description; + } - } + } - } + } } diff --git a/buession-json/src/test/java/com/buession/json/ObjectsTest.java b/buession-json/src/test/java/com/buession/json/ObjectsTest.java index 277e2f9bc..901d477a7 100644 --- a/buession-json/src/test/java/com/buession/json/ObjectsTest.java +++ b/buession-json/src/test/java/com/buession/json/ObjectsTest.java @@ -19,12 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.json; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Objects; @@ -35,7 +35,7 @@ public class ObjectsTest { @Test - public void equals(){ + public void equals() { long l = 1L; int i = 1; short s = (short) 1; diff --git a/buession-json/src/test/java/com/buession/json/SensitiveTest.java b/buession-json/src/test/java/com/buession/json/SensitiveTest.java index 4ccda71fd..55fed279a 100644 --- a/buession-json/src/test/java/com/buession/json/SensitiveTest.java +++ b/buession-json/src/test/java/com/buession/json/SensitiveTest.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.json; @@ -28,7 +28,7 @@ import com.buession.json.strategy.SensitiveStrategy; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Yong.Teng diff --git a/buession-json/src/test/java/com/buession/json/UnixTimestampTest.java b/buession-json/src/test/java/com/buession/json/UnixTimestampTest.java index 638e852b2..afd8deefd 100644 --- a/buession-json/src/test/java/com/buession/json/UnixTimestampTest.java +++ b/buession-json/src/test/java/com/buession/json/UnixTimestampTest.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2020 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.json; @@ -30,7 +30,7 @@ import com.buession.json.annotation.TimestampUnixTimestamp; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.sql.Timestamp; import java.util.Calendar; @@ -42,7 +42,7 @@ public class UnixTimestampTest { @Test - public void serialize() throws JsonProcessingException{ + public void serialize() throws JsonProcessingException { User user = new User(); user.setCalendar(Calendar.getInstance()); @@ -56,7 +56,7 @@ public void serialize() throws JsonProcessingException{ } @Test - public void deserialize() throws JsonProcessingException{ + public void deserialize() throws JsonProcessingException { String str = "{\"date\":1588253558,\"sqlDate\":1588253558,\"calendar\":1588253558,\"timestamp\":1588253558}"; ObjectMapper objectMapper = new ObjectMapper(); @@ -80,40 +80,40 @@ private final static class User { @TimestampUnixTimestamp private Timestamp timestamp; - public Date getDate(){ + public Date getDate() { return date; } - public void setDate(Date date){ + public void setDate(Date date) { this.date = date; } - public java.sql.Date getSqlDate(){ + public java.sql.Date getSqlDate() { return sqlDate; } - public void setSqlDate(java.sql.Date sqlDate){ + public void setSqlDate(java.sql.Date sqlDate) { this.sqlDate = sqlDate; } - public Calendar getCalendar(){ + public Calendar getCalendar() { return calendar; } - public void setCalendar(Calendar calendar){ + public void setCalendar(Calendar calendar) { this.calendar = calendar; } - public Timestamp getTimestamp(){ + public Timestamp getTimestamp() { return timestamp; } - public void setTimestamp(Timestamp timestamp){ + public void setTimestamp(Timestamp timestamp) { this.timestamp = timestamp; } @Override - public String toString(){ + public String toString() { return "User{" + "date=" + date + ", sqlDate=" + sqlDate + ", calendar=" + calendar + ", timestamp=" + timestamp + '}'; } diff --git a/buession-lang/pom.xml b/buession-lang/pom.xml index 6c6210bed..319e30c19 100644 --- a/buession-lang/pom.xml +++ b/buession-lang/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-lang http://www.buession.com/ @@ -53,8 +53,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -98,8 +98,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-core/src/main/java/com/buession/core/NamedNode.java b/buession-lang/src/main/java/com/buession/lang/NamedNode.java similarity index 92% rename from buession-core/src/main/java/com/buession/core/NamedNode.java rename to buession-lang/src/main/java/com/buession/lang/NamedNode.java index 3df8d8bd4..95ee00cdd 100644 --- a/buession-core/src/main/java/com/buession/core/NamedNode.java +++ b/buession-lang/src/main/java/com/buession/lang/NamedNode.java @@ -19,17 +19,16 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.core; - -import org.springframework.lang.Nullable; +package com.buession.lang; /** * 名称节点,约定实现该接口的类应该返回一个名称 * * @author Yong.Teng + * @since 3.0.0 */ public interface NamedNode { @@ -38,7 +37,6 @@ public interface NamedNode { * * @return 节点名称 */ - @Nullable String getName(); } diff --git a/buession-lang/src/main/java/com/buession/lang/Value.java b/buession-lang/src/main/java/com/buession/lang/Value.java new file mode 100644 index 000000000..299b7e282 --- /dev/null +++ b/buession-lang/src/main/java/com/buession/lang/Value.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.lang; + +/** + * 值接口 + * + * @param + * 值类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface Value { + + /** + * 返回值 + * + * @return 值 + */ + T getValue(); + +} diff --git a/buession-lang/src/test/java/com/buession/lang/VersionTest.java b/buession-lang/src/test/java/com/buession/lang/VersionTest.java index 1c0fae69e..874e87ca9 100644 --- a/buession-lang/src/test/java/com/buession/lang/VersionTest.java +++ b/buession-lang/src/test/java/com/buession/lang/VersionTest.java @@ -19,13 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.lang; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * @author Yong.Teng @@ -34,40 +34,40 @@ public class VersionTest { @Test - public void create(){ + public void create() { Version version = new Version("1.11.2"); - Assert.assertEquals(version.toString(), "1.11.2"); + Assertions.assertEquals(version.toString(), "1.11.2"); } @Test - public void createBeta(){ + public void createBeta() { Version version = new Version("1.11.2beta"); - Assert.assertEquals(version.toString(), "1.11.2beta"); + Assertions.assertEquals(version.toString(), "1.11.2beta"); } @Test - public void createRc(){ + public void createRc() { Version version = new Version("1.11.2 RC"); - Assert.assertEquals(version.toString(), "1.11.2 RC"); + Assertions.assertEquals(version.toString(), "1.11.2 RC"); } @Test - public void createMajorVersionAndMinorVersion(){ + public void createMajorVersionAndMinorVersion() { Version version = new Version("1.113"); - Assert.assertEquals(version.toString(), "1.113"); + Assertions.assertEquals(version.toString(), "1.113"); } @Test - public void createMajorVersionAndMinorVersionRc(){ + public void createMajorVersionAndMinorVersionRc() { Version version = new Version("1.113 Rc"); - Assert.assertEquals(version.toString(), "1.113 Rc"); + Assertions.assertEquals(version.toString(), "1.113 Rc"); } @Test - public void compare(){ + public void compare() { Version version1 = new Version("1.11.2"); Version version2 = new Version("1.11.2 Beta"); - Assert.assertEquals(version1.compareTo(version2), 1); + Assertions.assertEquals(version1.compareTo(version2), 1); } } diff --git a/buession-net/pom.xml b/buession-net/pom.xml index ec25e1147..35b87fad5 100644 --- a/buession-net/pom.xml +++ b/buession-net/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-net http://www.buession.com/ @@ -70,8 +70,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -115,8 +115,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-net/src/main/java/com/buession/net/utils/InetAddressUtils.java b/buession-net/src/main/java/com/buession/net/utils/InetAddressUtils.java index 6e967f952..7414e6b75 100644 --- a/buession-net/src/main/java/com/buession/net/utils/InetAddressUtils.java +++ b/buession-net/src/main/java/com/buession/net/utils/InetAddressUtils.java @@ -35,7 +35,7 @@ */ public class InetAddressUtils { - private InetAddressUtils(){ + private InetAddressUtils() { } /** @@ -46,7 +46,7 @@ private InetAddressUtils(){ * * @return IPV4 地址 */ - public static String long2ip(long l){ + public static String long2ip(long l) { long[] result = new long[4]; for(int i = 4; i > 0; i--){ result[i - 1] = (l & 0xff); @@ -64,7 +64,7 @@ public static String long2ip(long l){ * * @return IPV4 地址的 InetAddress 对象 */ - public static InetAddress long2InetAddress(long l){ + public static InetAddress long2InetAddress(long l) { String ip = long2ip(l); try{ @@ -82,7 +82,7 @@ public static InetAddress long2InetAddress(long l){ * * @return IPV4 地址的长整型 */ - public static long ip2long(String ip){ + public static long ip2long(String ip) { if(Validate.isIpV4(ip) == false){ throw new IllegalArgumentException("Illegal ip: " + ip + ", must be ipv4."); } diff --git a/buession-net/src/test/java/com/buession/net/InetAddressUtilsTest.java b/buession-net/src/test/java/com/buession/net/InetAddressUtilsTest.java index 9cd40ef25..29e5fb84f 100644 --- a/buession-net/src/test/java/com/buession/net/InetAddressUtilsTest.java +++ b/buession-net/src/test/java/com/buession/net/InetAddressUtilsTest.java @@ -21,13 +21,13 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2020 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.net; import com.buession.net.utils.InetAddressUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Yong.Teng @@ -35,13 +35,13 @@ public class InetAddressUtilsTest { @Test - public void ip2long(){ + public void ip2long() { System.out.println(InetAddressUtils.ip2long("127.0.0.1")); } @Test - public void long2ip(){ - System.out.println(InetAddressUtils.long2ip(3739974408L)); + public void long2ip() { + System.out.println(InetAddressUtils.long2ip(InetAddressUtils.ip2long("256.89.154.222"))); } } diff --git a/buession-parent/pom.xml b/buession-parent/pom.xml index 3787f11d0..096d6e1ca 100644 --- a/buession-parent/pom.xml +++ b/buession-parent/pom.xml @@ -7,13 +7,13 @@ com.buession parent - 2.3.3 + 3.0.0 com.buession buession-parent http://www.buession.com/ Buession Framework Parent - 2.3.3 + 3.0.0 pom @@ -57,7 +57,6 @@ ../buession-aop ../buession-beans ../buession-core - ../buession-cron ../buession-dao ../buession-geoip ../buession-git @@ -68,7 +67,6 @@ ../buession-lang ../buession-net ../buession-redis - ../buession-session ../buession-thesaurus ../buession-velocity ../buession-web @@ -95,20 +93,9 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin - - - - sonatype-nexus-snapshots - https://oss.sonatype.org/content/repositories/snapshots - - - sonatype-nexus-staging - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - \ No newline at end of file diff --git a/buession-redis/pom.xml b/buession-redis/pom.xml index 4067779d3..9c661ee70 100644 --- a/buession-redis/pom.xml +++ b/buession-redis/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-redis http://www.buession.com/ @@ -57,13 +57,6 @@ buession-core ${project.version} - - com.buession - buession-beans - ${project.version} - compile - true - com.buession buession-net @@ -78,7 +71,41 @@ redis.clients jedis + provided + true + + + io.lettuce + lettuce-core + provided + true + + + + com.fasterxml.jackson.core + jackson-databind + provided + true + + + + com.alibaba + fastjson + provided + true + + + + com.google.code.gson + gson + provided true + + + com.google.errorprone + error_prone_annotations + + @@ -92,8 +119,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -137,8 +164,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/AbstractRedisTemplate.java b/buession-redis/src/main-tmp/java/com/buession/redis/AbstractRedisTemplate.java new file mode 100644 index 000000000..a66b9f21a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/AbstractRedisTemplate.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis; + +import com.buession.core.utils.ByteUtils; +import com.buession.core.validator.Validate; +import com.buession.redis.client.connection.datasource.DataSource; +import com.buession.redis.core.command.*; +import com.buession.redis.utils.SafeEncoder; + +import java.util.function.Function; + +/** + * @author Yong.Teng + */ +public abstract class AbstractRedisTemplate extends RedisAccessor implements AclCommands, BitMapCommands, + ClusterCommands, ConnectionCommands, GenericCommand, GeoCommands, HashCommands, HyperLogLogCommands, + KeyCommands, ListCommands, PubSubCommands, ScriptingCommands, ServerCommands, SetCommands, SortedSetCommands, + StreamCommands, StringCommands, TransactionCommands { + + /** + * 构造函数 + */ + public AbstractRedisTemplate() { + super(); + } + + /** + * 构造函数 + * + * @param dataSource + * 数据源 + */ + public AbstractRedisTemplate(DataSource dataSource) { + super(dataSource); + } + + protected final String rawKey(final String key) { + String prefix = getOptions().getPrefix(); + return Validate.isEmpty(prefix) ? key : prefix.concat(key); + } + + protected final byte[] rawKey(byte[] key) { + String prefix = getOptions().getPrefix(); + return Validate.isEmpty(prefix) ? key : ByteUtils.concat(SafeEncoder.encode(prefix), key); + } + + protected final String[] rawKeys(final String[] keys) { + String prefix = getOptions().getPrefix(); + + if(Validate.isEmpty(prefix) || Validate.isEmpty(keys)){ + return keys; + } + + final String[] result = new String[keys.length]; + return rawKeys(keys, result, prefix::concat); + } + + protected final byte[][] rawKeys(final byte[][] keys) { + String prefix = getOptions().getPrefix(); + + if(Validate.isEmpty(prefix) || Validate.isEmpty(keys)){ + return keys; + } + + byte[] prefixByte = SafeEncoder.encode(prefix); + final byte[][] result = new byte[keys.length][]; + + return rawKeys(keys, result, (b)->ByteUtils.concat(prefixByte, b)); + } + + private T[] rawKeys(final T[] keys, final T[] result, final Function fn) { + for(int i = 0; i < keys.length; i++){ + result[i] = fn.apply(keys[i]); + } + + return result; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/BaseRedisTemplate.java b/buession-redis/src/main-tmp/java/com/buession/redis/BaseRedisTemplate.java new file mode 100644 index 000000000..9624acf87 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/BaseRedisTemplate.java @@ -0,0 +1,4140 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis; + +import com.buession.core.collect.Maps; +import com.buession.lang.Geo; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.connection.datasource.DataSource; +import com.buession.redis.core.AclCategory; +import com.buession.redis.core.AclLog; +import com.buession.redis.core.Aggregate; +import com.buession.redis.core.BitType; +import com.buession.redis.core.BitOperation; +import com.buession.redis.core.Direction; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import com.buession.redis.core.GtLt; +import com.buession.redis.core.Info; +import com.buession.redis.core.ListPosition; +import com.buession.redis.core.MemoryStats; +import com.buession.redis.core.Module; +import com.buession.redis.core.NxXx; +import com.buession.redis.core.ObjectEncoding; +import com.buession.redis.core.PubSubListener; +import com.buession.redis.core.RedisMonitor; +import com.buession.redis.core.RedisServerTime; +import com.buession.redis.core.Role; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.SlowLog; +import com.buession.redis.core.Stream; +import com.buession.redis.core.StreamConsumer; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import com.buession.redis.core.StreamGroup; +import com.buession.redis.core.StreamPending; +import com.buession.redis.core.StreamPendingSummary; +import com.buession.redis.core.Tuple; +import com.buession.redis.core.Type; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.ZRangeBy; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.*; +import com.buession.redis.transaction.Transaction; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Redis 基本操作 Template + * + * @author Yong.Teng + */ +public abstract class BaseRedisTemplate extends AbstractRedisTemplate { + + /** + * 构造函数 + */ + public BaseRedisTemplate() { + super(); + } + + /** + * 构造函数 + * + * @param dataSource + * 数据源 + */ + public BaseRedisTemplate(DataSource dataSource) { + super(dataSource); + } + + @Override + public Long bitCount(final String key) { + return execute((client)->client.bitMapOperations().bitCount(rawKey(key))); + } + + @Override + public Long bitCount(final byte[] key) { + return execute((client)->client.bitMapOperations().bitCount(rawKey(key))); + } + + @Override + public Long bitCount(final String key, final long start, final long end) { + return execute((client)->client.bitMapOperations().bitCount(rawKey(key), start, end)); + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end) { + return execute((client)->client.bitMapOperations().bitCount(rawKey(key), start, end)); + } + + @Override + public Long bitCount(final String key, final long start, final long end, final BitType bitType) { + return execute((client)->client.bitMapOperations().bitCount(rawKey(key), start, end, bitType)); + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end, final BitType bitType) { + return execute((client)->client.bitMapOperations().bitCount(rawKey(key), start, end, bitType)); + } + + @Override + public List bitField(final String key) { + return execute((client)->client.bitMapOperations().bitField(rawKey(key))); + } + + @Override + public List bitField(final byte[] key) { + return execute((client)->client.bitMapOperations().bitField(rawKey(key))); + } + + @Override + public List bitField(final String key, final BitFieldArgument argument) { + return execute((client)->client.bitMapOperations().bitField(rawKey(key), argument)); + } + + @Override + public List bitField(final byte[] key, final BitFieldArgument argument) { + return execute((client)->client.bitMapOperations().bitField(rawKey(key), argument)); + } + + @Override + public List bitFieldRo(final String key) { + return execute((client)->client.bitMapOperations().bitFieldRo(rawKey(key))); + } + + @Override + public List bitFieldRo(final byte[] key) { + return execute((client)->client.bitMapOperations().bitFieldRo(rawKey(key))); + } + + @Override + public List bitFieldRo(final String key, final BitFieldRoArgument argument) { + return execute((client)->client.bitMapOperations().bitFieldRo(rawKey(key), argument)); + } + + @Override + public List bitFieldRo(final byte[] key, final BitFieldRoArgument argument) { + return execute((client)->client.bitMapOperations().bitFieldRo(rawKey(key), argument)); + } + + @Override + public Long bitOp(final BitOperation operation, final String destKey, final String... keys) { + return execute((client)->client.bitMapOperations().bitOp(operation, rawKey(destKey), rawKeys(keys))); + } + + @Override + public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys) { + return execute((client)->client.bitMapOperations().bitOp(operation, rawKey(destKey), rawKeys(keys))); + } + + @Override + public Long bitPos(final String key, final boolean value) { + return execute((client)->client.bitMapOperations().bitPos(rawKey(key), value)); + } + + @Override + public Long bitPos(final byte[] key, final boolean value) { + return execute((client)->client.bitMapOperations().bitPos(rawKey(key), value)); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start) { + return execute((client)->client.bitMapOperations().bitPos(rawKey(key), value, start)); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start) { + return execute((client)->client.bitMapOperations().bitPos(rawKey(key), value, start)); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final BitType bitType) { + return execute((client)->client.bitMapOperations().bitPos(rawKey(key), value, start, bitType)); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final BitType bitType) { + return execute((client)->client.bitMapOperations().bitPos(rawKey(key), value, start, bitType)); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final long end) { + return execute((client)->client.bitMapOperations().bitPos(rawKey(key), value, start, end)); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end) { + return execute((client)->client.bitMapOperations().bitPos(rawKey(key), value, start, end)); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final long end, + final BitType bitType) { + return execute((client)->client.bitMapOperations().bitPos(rawKey(key), value, start, end, bitType)); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end, + final BitType bitType) { + return execute((client)->client.bitMapOperations().bitPos(rawKey(key), value, start, end, bitType)); + } + + @Override + public Boolean getBit(final String key, final long offset) { + return execute((client)->client.bitMapOperations().getBit(rawKey(key), offset)); + } + + @Override + public Boolean getBit(final byte[] key, final long offset) { + return execute((client)->client.bitMapOperations().getBit(rawKey(key), offset)); + } + + @Override + public Boolean setBit(final String key, final long offset, final boolean value) { + return execute((client)->client.bitMapOperations().setBit(rawKey(key), offset, value)); + } + + @Override + public Boolean setBit(final byte[] key, final long offset, final boolean value) { + return execute((client)->client.bitMapOperations().setBit(rawKey(key), offset, value)); + } + + @Override + public Long clusterKeySlot(final String key) { + return execute((client)->client.clusterOperations().clusterKeySlot(rawKey(key))); + } + + @Override + public Long clusterKeySlot(final byte[] key) { + return execute((client)->client.clusterOperations().clusterKeySlot(rawKey(key))); + } + + @Override + public Status copy(final String key, final String destKey) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey))); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey))); + } + + @Override + public Status copy(final String key, final String destKey, final int db) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), db)); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), db)); + } + + @Override + public Status copy(final String key, final String destKey, final boolean replace) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), replace)); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final boolean replace) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), replace)); + } + + @Override + public Status copy(final String key, final String destKey, final int db, final boolean replace) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), db, replace)); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), db, replace)); + } + + @Override + public Long del(final String... keys) { + return execute((client)->client.keyOperations().del(rawKeys(keys))); + } + + @Override + public Long del(final byte[]... keys) { + return execute((client)->client.keyOperations().del(rawKeys(keys))); + } + + @Override + public String dump(final String key) { + return execute((client)->client.keyOperations().dump(rawKey(key))); + } + + @Override + public byte[] dump(final byte[] key) { + return execute((client)->client.keyOperations().dump(rawKey(key))); + } + + @Override + public Boolean exists(final String key) { + return execute((client)->client.keyOperations().exists(rawKey(key))); + } + + @Override + public Boolean exists(final byte[] key) { + return execute((client)->client.keyOperations().exists(rawKey(key))); + } + + @Override + public Long exists(final String... keys) { + return execute((client)->client.keyOperations().exists(rawKeys(keys))); + } + + @Override + public Long exists(final byte[]... keys) { + return execute((client)->client.keyOperations().exists(rawKeys(keys))); + } + + @Override + public Status expire(final String key, final int lifetime) { + return execute((client)->client.keyOperations().expire(rawKey(key), lifetime)); + } + + @Override + public Status expire(final byte[] key, final int lifetime) { + return execute((client)->client.keyOperations().expire(rawKey(key), lifetime)); + } + + @Override + public Status expire(final String key, final int lifetime, final ExpireOption expireOption) { + return execute((client)->client.keyOperations().expire(rawKey(key), lifetime, expireOption)); + } + + @Override + public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + return execute((client)->client.keyOperations().expire(rawKey(key), lifetime, expireOption)); + } + + @Override + public Status expireAt(final String key, final long unixTimestamp) { + return execute((client)->client.keyOperations().expireAt(rawKey(key), unixTimestamp)); + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp) { + return execute((client)->client.keyOperations().expireAt(rawKey(key), unixTimestamp)); + } + + @Override + public Status expireAt(final String key, final long unixTimestamp, final ExpireOption expireOption) { + return execute((client)->client.keyOperations().expireAt(rawKey(key), unixTimestamp, expireOption)); + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption) { + return execute((client)->client.keyOperations().expireAt(rawKey(key), unixTimestamp, expireOption)); + } + + @Override + public Long expireTime(final String key) { + return execute((client)->client.keyOperations().expireTime(rawKey(key))); + } + + @Override + public Long expireTime(final byte[] key) { + return execute((client)->client.keyOperations().expireTime(rawKey(key))); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final String... keys) { + return execute((client)->client.keyOperations().migrate(host, port, db, timeout, rawKeys(keys))); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... keys) { + return execute((client)->client.keyOperations().migrate(host, port, db, timeout, rawKeys(keys))); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgument migrateArgument, final String... keys) { + return execute( + (client)->client.keyOperations().migrate(host, port, db, timeout, migrateArgument, rawKeys(keys))); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgument migrateArgument, final byte[]... keys) { + return execute( + (client)->client.keyOperations().migrate(host, port, db, timeout, migrateArgument, rawKeys(keys))); + } + + @Override + public Status move(final String key, final int db) { + return execute((client)->client.keyOperations().move(rawKey(key), db)); + } + + @Override + public Status move(final byte[] key, final int db) { + return execute((client)->client.keyOperations().move(rawKey(key), db)); + } + + @Override + public ObjectEncoding objectEncoding(final String key) { + return execute((client)->client.keyOperations().objectEncoding(rawKey(key))); + } + + @Override + public ObjectEncoding objectEncoding(final byte[] key) { + return execute((client)->client.keyOperations().objectEncoding(rawKey(key))); + } + + @Override + public Long objectFreq(final String key) { + return execute((client)->client.keyOperations().objectFreq(rawKey(key))); + } + + @Override + public Long objectFreq(final byte[] key) { + return execute((client)->client.keyOperations().objectFreq(rawKey(key))); + } + + @Override + public Long objectIdleTime(final String key) { + return execute((client)->client.keyOperations().objectIdleTime(rawKey(key))); + } + + @Override + public Long objectIdleTime(final byte[] key) { + return execute((client)->client.keyOperations().objectIdleTime(rawKey(key))); + } + + @Override + public Long objectRefcount(final String key) { + return execute((client)->client.keyOperations().objectRefcount(rawKey(key))); + } + + @Override + public Long objectRefcount(final byte[] key) { + return execute((client)->client.keyOperations().objectRefcount(rawKey(key))); + } + + @Override + public Status persist(final String key) { + return execute((client)->client.keyOperations().persist(rawKey(key))); + } + + @Override + public Status persist(final byte[] key) { + return execute((client)->client.keyOperations().persist(rawKey(key))); + } + + @Override + public Status pExpire(final String key, final int lifetime) { + return execute((client)->client.keyOperations().pExpire(rawKey(key), lifetime)); + } + + @Override + public Status pExpire(final byte[] key, final int lifetime) { + return execute((client)->client.keyOperations().pExpire(rawKey(key), lifetime)); + } + + @Override + public Status pExpire(final String key, final int lifetime, final ExpireOption expireOption) { + return execute((client)->client.keyOperations().pExpire(rawKey(key), lifetime, expireOption)); + } + + @Override + public Status pExpire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + return execute((client)->client.keyOperations().pExpire(rawKey(key), lifetime, expireOption)); + } + + @Override + public Status pExpireAt(final String key, final long unixTimestamp) { + return execute((client)->client.keyOperations().pExpireAt(rawKey(key), unixTimestamp)); + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp) { + return execute((client)->client.keyOperations().pExpireAt(rawKey(key), unixTimestamp)); + } + + @Override + public Status pExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption) { + return execute((client)->client.keyOperations().pExpireAt(rawKey(key), unixTimestamp, expireOption)); + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption) { + return execute((client)->client.keyOperations().pExpireAt(rawKey(key), unixTimestamp, expireOption)); + } + + @Override + public Long pExpireTime(final String key) { + return execute((client)->client.keyOperations().pExpireTime(rawKey(key))); + } + + @Override + public Long pExpireTime(final byte[] key) { + return execute((client)->client.keyOperations().pExpireTime(rawKey(key))); + } + + @Override + public Long pTtl(final String key) { + return execute((client)->client.keyOperations().pTtl(rawKey(key))); + } + + @Override + public Long pTtl(final byte[] key) { + return execute((client)->client.keyOperations().pTtl(rawKey(key))); + } + + @Override + public Status rename(final String key, final String newKey) { + return execute((client)->client.keyOperations().rename(rawKey(key), rawKey(newKey))); + } + + @Override + public Status rename(final byte[] key, final byte[] newKey) { + return execute((client)->client.keyOperations().rename(rawKey(key), rawKey(newKey))); + } + + @Override + public Status renameNx(final String key, final String newKey) { + return execute((client)->client.keyOperations().renameNx(rawKey(key), rawKey(newKey))); + } + + @Override + public Status renameNx(final byte[] key, final byte[] newKey) { + return execute((client)->client.keyOperations().renameNx(rawKey(key), rawKey(newKey))); + } + + @Override + public Status restore(final String key, final byte[] serializedValue, final int ttl) { + return execute((client)->client.keyOperations().restore(rawKey(key), serializedValue, ttl)); + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl) { + return execute((client)->client.keyOperations().restore(rawKey(key), serializedValue, ttl)); + } + + @Override + public Status restore(final String key, final byte[] serializedValue, final int ttl, + final RestoreArgument restoreArgument) { + return execute((client)->client.keyOperations().restore(rawKey(key), serializedValue, ttl, restoreArgument)); + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl, + final RestoreArgument restoreArgument) { + return execute((client)->client.keyOperations().restore(rawKey(key), serializedValue, ttl, restoreArgument)); + } + + @Override + public ScanResult> scan(final long cursor) { + return execute((client)->client.keyOperations().scan(cursor)); + } + + @Override + public ScanResult> scan(final String cursor) { + return execute((client)->client.keyOperations().scan(cursor)); + } + + @Override + public ScanResult> scan(final byte[] cursor) { + return execute((client)->client.keyOperations().scan(cursor)); + } + + @Override + public ScanResult> scan(final long cursor, final String pattern) { + return execute((client)->client.keyOperations().scan(cursor, pattern)); + } + + @Override + public ScanResult> scan(final long cursor, final byte[] pattern) { + return execute((client)->client.keyOperations().scan(cursor, pattern)); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern) { + return execute((client)->client.keyOperations().scan(cursor, pattern)); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern) { + return execute((client)->client.keyOperations().scan(cursor, pattern)); + } + + @Override + public ScanResult> scan(final long cursor, final int count) { + return execute((client)->client.keyOperations().scan(cursor, count)); + } + + @Override + public ScanResult> scan(final String cursor, final int count) { + return execute((client)->client.keyOperations().scan(cursor, count)); + } + + @Override + public ScanResult> scan(final byte[] cursor, final int count) { + return execute((client)->client.keyOperations().scan(cursor, count)); + } + + @Override + public ScanResult> scan(final long cursor, final String pattern, final int count) { + return execute((client)->client.keyOperations().scan(cursor, pattern, count)); + } + + @Override + public ScanResult> scan(final long cursor, final byte[] pattern, final int count) { + return execute((client)->client.keyOperations().scan(cursor, pattern, count)); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern, final int count) { + return execute((client)->client.keyOperations().scan(cursor, pattern, count)); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern, final int count) { + return execute((client)->client.keyOperations().scan(cursor, pattern, count)); + } + + @Override + public List sort(final String key) { + return execute((client)->client.keyOperations().sort(rawKey(key))); + } + + @Override + public List sort(final byte[] key) { + return execute((client)->client.keyOperations().sort(rawKey(key))); + } + + @Override + public List sort(final String key, final SortArgument sortArgument) { + return execute((client)->client.keyOperations().sort(rawKey(key), sortArgument)); + } + + @Override + public List sort(final byte[] key, final SortArgument sortArgument) { + return execute((client)->client.keyOperations().sort(rawKey(key), sortArgument)); + } + + @Override + public Long sort(final String key, final String destKey) { + return execute((client)->client.keyOperations().sort(rawKey(key), rawKey(destKey))); + } + + @Override + public Long sort(final byte[] key, final byte[] destKey) { + return execute((client)->client.keyOperations().sort(rawKey(key), rawKey(destKey))); + } + + @Override + public Long sort(final String key, final String destKey, final SortArgument sortArgument) { + return execute((client)->client.keyOperations().sort(rawKey(key), rawKey(destKey), sortArgument)); + } + + @Override + public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument) { + return execute((client)->client.keyOperations().sort(rawKey(key), rawKey(destKey), sortArgument)); + } + + @Override + public List sortRo(final String key) { + return execute((client)->client.keyOperations().sortRo(rawKey(key))); + } + + @Override + public List sortRo(final byte[] key) { + return execute((client)->client.keyOperations().sortRo(rawKey(key))); + } + + @Override + public List sortRo(final String key, final SortArgument sortArgument) { + return execute((client)->client.keyOperations().sortRo(rawKey(key), sortArgument)); + } + + @Override + public List sortRo(final byte[] key, final SortArgument sortArgument) { + return execute((client)->client.keyOperations().sortRo(rawKey(key), sortArgument)); + } + + @Override + public Long touch(final String... keys) { + return execute((client)->client.keyOperations().touch(rawKeys(keys))); + } + + @Override + public Long touch(final byte[]... keys) { + return execute((client)->client.keyOperations().touch(rawKeys(keys))); + } + + @Override + public Long ttl(final String key) { + return execute((client)->client.keyOperations().ttl(rawKey(key))); + } + + @Override + public Long ttl(final byte[] key) { + return execute((client)->client.keyOperations().ttl(rawKey(key))); + } + + @Override + public Type type(final String key) { + return execute((client)->client.keyOperations().type(rawKey(key))); + } + + @Override + public Type type(final byte[] key) { + return execute((client)->client.keyOperations().type(rawKey(key))); + } + + @Override + public Long unlink(final String... keys) { + return execute((client)->client.keyOperations().unlink(rawKeys(keys))); + } + + @Override + public Long unlink(final byte[]... keys) { + return execute((client)->client.keyOperations().unlink(rawKeys(keys))); + } + + @Override + public Long geoAdd(final String key, final String member, final double longitude, final double latitude) { + return execute((client)->client.geoOperations().geoAdd(rawKey(key), member, longitude, latitude)); + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude) { + return execute((client)->client.geoOperations().geoAdd(rawKey(key), member, longitude, latitude)); + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates) { + return execute((client)->client.geoOperations().geoAdd(rawKey(key), memberCoordinates)); + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates) { + return execute((client)->client.geoOperations().geoAdd(rawKey(key), memberCoordinates)); + } + + @Override + public Long geoAdd(final String key, final String member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument) { + return execute( + (client)->client.geoOperations().geoAdd(rawKey(key), member, longitude, latitude, geoAddArgument)); + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument) { + return execute( + (client)->client.geoOperations().geoAdd(rawKey(key), member, longitude, latitude, geoAddArgument)); + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument) { + return execute((client)->client.geoOperations().geoAdd(rawKey(key), memberCoordinates, geoAddArgument)); + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument) { + return execute((client)->client.geoOperations().geoAdd(rawKey(key), memberCoordinates, geoAddArgument)); + } + + @Override + public Double geoDist(final String key, final String member1, final String member2) { + return execute((client)->client.geoOperations().geoDist(rawKey(key), member1, member2)); + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2) { + return execute((client)->client.geoOperations().geoDist(rawKey(key), member1, member2)); + } + + @Override + public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit) { + return execute((client)->client.geoOperations().geoDist(rawKey(key), member1, member2, unit)); + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit) { + return execute((client)->client.geoOperations().geoDist(rawKey(key), member1, member2, unit)); + } + + @Override + public List geoHash(final String key, final String... members) { + return execute((client)->client.geoOperations().geoHash(rawKey(key), members)); + } + + @Override + public List geoHash(final byte[] key, final byte[]... members) { + return execute((client)->client.geoOperations().geoHash(rawKey(key), members)); + } + + @Override + public List geoPos(final String key, final String... members) { + return execute((client)->client.geoOperations().geoPos(rawKey(key), members)); + } + + @Override + public List geoPos(final byte[] key, final byte[]... members) { + return execute((client)->client.geoOperations().geoPos(rawKey(key), members)); + } + + @Override + public List geoRadius(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + return execute((client)->client.geoOperations().geoRadius(rawKey(key), longitude, latitude, radius, unit)); + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + return execute((client)->client.geoOperations().geoRadius(rawKey(key), longitude, latitude, radius, unit)); + } + + @Override + public List geoRadius(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + return execute((client)->client.geoOperations() + .geoRadius(rawKey(key), longitude, latitude, radius, unit, geoRadiusArgument)); + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + return execute((client)->client.geoOperations() + .geoRadius(rawKey(key), longitude, latitude, radius, unit, geoRadiusArgument)); + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + return execute((client)->client.geoOperations().geoRadiusRo(rawKey(key), longitude, latitude, radius, unit)); + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + return execute((client)->client.geoOperations().geoRadiusRo(rawKey(key), longitude, latitude, radius, unit)); + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + return execute((client)->client.geoOperations() + .geoRadiusRo(rawKey(key), longitude, latitude, radius, unit, geoRadiusArgument)); + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + return execute((client)->client.geoOperations() + .geoRadiusRo(rawKey(key), longitude, latitude, radius, unit, geoRadiusArgument)); + } + + @Override + public List geoRadiusByMember(final String key, final String member, final double radius, + final GeoUnit unit) { + return execute((client)->client.geoOperations().geoRadiusByMember(rawKey(key), member, radius, unit)); + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + return execute((client)->client.geoOperations().geoRadiusByMember(rawKey(key), member, radius, unit)); + } + + @Override + public List geoRadiusByMember(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + return execute((client)->client.geoOperations() + .geoRadiusByMember(rawKey(key), member, radius, unit, geoRadiusArgument)); + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + return execute((client)->client.geoOperations() + .geoRadiusByMember(rawKey(key), member, radius, unit, geoRadiusArgument)); + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit) { + return execute((client)->client.geoOperations().geoRadiusByMemberRo(rawKey(key), member, radius, unit)); + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + return execute((client)->client.geoOperations().geoRadiusByMemberRo(rawKey(key), member, radius, unit)); + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + return execute((client)->client.geoOperations() + .geoRadiusByMemberRo(rawKey(key), member, radius, unit, geoRadiusArgument)); + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + return execute((client)->client.geoOperations() + .geoRadiusByMemberRo(rawKey(key), member, radius, unit, geoRadiusArgument)); + } + + @Override + public List geoSearch(final String key, final GeoSearchArgument geoSearchArgument) { + return execute((client)->client.geoOperations().geoSearch(rawKey(key), geoSearchArgument)); + } + + @Override + public List geoSearch(final byte[] key, final GeoSearchArgument geoSearchArgument) { + return execute((client)->client.geoOperations().geoSearch(rawKey(key), geoSearchArgument)); + } + + @Override + public Long geoSearchStore(final String destKey, final String key, + final GeoSearchStoreArgument geoSearchStoreArgument) { + return execute( + (client)->client.geoOperations().geoSearchStore(rawKey(destKey), rawKey(key), geoSearchStoreArgument)); + } + + @Override + public Long geoSearchStore(final byte[] destKey, final byte[] key, + final GeoSearchStoreArgument geoSearchStoreArgument) { + return execute( + (client)->client.geoOperations().geoSearchStore(rawKey(destKey), rawKey(key), geoSearchStoreArgument)); + } + + @Override + public Long hDel(final String key, final String... fields) { + return execute((client)->client.hashOperations().hDel(rawKey(key), fields)); + } + + @Override + public Long hDel(final byte[] key, final byte[]... fields) { + return execute((client)->client.hashOperations().hDel(rawKey(key), fields)); + } + + @Override + public Boolean hExists(final String key, final String field) { + return execute((client)->client.hashOperations().hExists(rawKey(key), field)); + } + + @Override + public Boolean hExists(final byte[] key, final byte[] field) { + return execute((client)->client.hashOperations().hExists(rawKey(key), field)); + } + + @Override + public List hExpire(final String key, final int lifetime, final String... fields) { + return execute((client)->client.hashOperations().hExpire(rawKey(key), lifetime, fields)); + } + + @Override + public List hExpire(final byte[] key, final int lifetime, final byte[]... fields) { + return execute((client)->client.hashOperations().hExpire(rawKey(key), lifetime, fields)); + } + + @Override + public List hExpire(final String key, final int lifetime, final ExpireOption expireOption, + final String... fields) { + return execute((client)->client.hashOperations().hExpire(rawKey(key), lifetime, expireOption, fields)); + } + + @Override + public List hExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, + final byte[]... fields) { + return execute((client)->client.hashOperations().hExpire(rawKey(key), lifetime, expireOption, fields)); + } + + @Override + public List hExpireAt(final String key, final long unixTimestamp, final String... fields) { + return execute((client)->client.hashOperations().hExpireAt(rawKey(key), unixTimestamp, fields)); + } + + @Override + public List hExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields) { + return execute((client)->client.hashOperations().hExpireAt(rawKey(key), unixTimestamp, fields)); + } + + @Override + public List hExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption, + final String... fields) { + return execute((client)->client.hashOperations().hExpireAt(rawKey(key), unixTimestamp, expireOption, fields)); + } + + @Override + public List hExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields) { + return execute((client)->client.hashOperations().hExpireAt(rawKey(key), unixTimestamp, expireOption, fields)); + } + + @Override + public List hExpireTime(final String key, final String... fields) { + return execute((client)->client.hashOperations().hExpireTime(rawKey(key), fields)); + } + + @Override + public List hExpireTime(final byte[] key, final byte[]... fields) { + return execute((client)->client.hashOperations().hExpireTime(rawKey(key), fields)); + } + + @Override + public String hGet(final String key, final String field) { + return execute((client)->client.hashOperations().hGet(rawKey(key), field)); + } + + @Override + public byte[] hGet(final byte[] key, final byte[] field) { + return execute((client)->client.hashOperations().hGet(rawKey(key), field)); + } + + @Override + public Map hGetAll(final String key) { + return execute((client)->client.hashOperations().hGetAll(rawKey(key))); + } + + @Override + public Map hGetAll(final byte[] key) { + return execute((client)->client.hashOperations().hGetAll(rawKey(key))); + } + + @Override + public Long hIncrBy(final String key, final String field, final long value) { + return execute((client)->client.hashOperations().hIncrBy(rawKey(key), field, value)); + } + + @Override + public Long hIncrBy(final byte[] key, final byte[] field, final long value) { + return execute((client)->client.hashOperations().hIncrBy(rawKey(key), field, value)); + } + + @Override + public Double hIncrByFloat(final String key, final String field, final double value) { + return execute((client)->client.hashOperations().hIncrByFloat(rawKey(key), field, value)); + } + + @Override + public Double hIncrByFloat(final byte[] key, final byte[] field, final double value) { + return execute((client)->client.hashOperations().hIncrByFloat(rawKey(key), field, value)); + } + + @Override + public Set hKeys(final String key) { + return execute((client)->client.hashOperations().hKeys(rawKey(key))); + } + + @Override + public Set hKeys(final byte[] key) { + return execute((client)->client.hashOperations().hKeys(rawKey(key))); + } + + @Override + public Long hLen(final String key) { + return execute((client)->client.hashOperations().hLen(rawKey(key))); + } + + @Override + public Long hLen(final byte[] key) { + return execute((client)->client.hashOperations().hLen(rawKey(key))); + } + + @Override + public List hMGet(final String key, final String... fields) { + return execute((client)->client.hashOperations().hMGet(rawKey(key), fields)); + } + + @Override + public List hMGet(final byte[] key, final byte[]... fields) { + return execute((client)->client.hashOperations().hMGet(rawKey(key), fields)); + } + + @Override + public Status hMSet(final String key, final Map data) { + return execute((client)->client.hashOperations().hMSet(rawKey(key), data)); + } + + @Override + public Status hMSet(final byte[] key, final Map data) { + return execute((client)->client.hashOperations().hMSet(rawKey(key), data)); + } + + @Override + public List hPersist(final String key, final String... fields) { + return execute((client)->client.hashOperations().hPersist(rawKey(key), fields)); + } + + @Override + public List hPersist(final byte[] key, final byte[]... fields) { + return execute((client)->client.hashOperations().hPersist(rawKey(key), fields)); + } + + @Override + public List hpExpire(final String key, final int lifetime, final String... fields) { + return execute((client)->client.hashOperations().hpExpire(rawKey(key), lifetime, fields)); + } + + @Override + public List hpExpire(final byte[] key, final int lifetime, final byte[]... fields) { + return execute((client)->client.hashOperations().hpExpire(rawKey(key), lifetime, fields)); + } + + @Override + public List hpExpire(final String key, final int lifetime, final ExpireOption expireOption, + final String... fields) { + return execute((client)->client.hashOperations().hpExpire(rawKey(key), lifetime, expireOption, fields)); + } + + @Override + public List hpExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, + final byte[]... fields) { + return execute((client)->client.hashOperations().hpExpire(rawKey(key), lifetime, expireOption, fields)); + } + + @Override + public List hpExpireAt(final String key, final long unixTimestamp, final String... fields) { + return execute((client)->client.hashOperations().hpExpireAt(rawKey(key), unixTimestamp, fields)); + } + + @Override + public List hpExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields) { + return execute((client)->client.hashOperations().hpExpireAt(rawKey(key), unixTimestamp, fields)); + } + + @Override + public List hpExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption, + final String... fields) { + return execute((client)->client.hashOperations().hpExpireAt(rawKey(key), unixTimestamp, expireOption, fields)); + } + + @Override + public List hpExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields) { + return execute((client)->client.hashOperations().hpExpireAt(rawKey(key), unixTimestamp, expireOption, fields)); + } + + @Override + public List hpExpireTime(final String key, final String... fields) { + return execute((client)->client.hashOperations().hpExpireTime(rawKey(key), fields)); + } + + @Override + public List hpExpireTime(final byte[] key, final byte[]... fields) { + return execute((client)->client.hashOperations().hpExpireTime(rawKey(key), fields)); + } + + @Override + public List hpTtl(final String key, final String... fields) { + return execute((client)->client.hashOperations().hpTtl(rawKey(key), fields)); + } + + @Override + public List hpTtl(final byte[] key, final byte[]... fields) { + return execute((client)->client.hashOperations().hpTtl(rawKey(key), fields)); + } + + @Override + public String hRandField(final String key) { + return execute((client)->client.hashOperations().hRandField(rawKey(key))); + } + + @Override + public byte[] hRandField(final byte[] key) { + return execute((client)->client.hashOperations().hRandField(rawKey(key))); + } + + @Override + public List hRandField(final String key, final int count) { + return execute((client)->client.hashOperations().hRandField(rawKey(key), count)); + } + + @Override + public List hRandField(final byte[] key, final int count) { + return execute((client)->client.hashOperations().hRandField(rawKey(key), count)); + } + + @Override + public List> hRandFieldWithValues(final String key, final int count) { + return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count)); + } + + @Override + public List> hRandFieldWithValues(final byte[] key, final int count) { + return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count)); + } + + @Override + public ScanResult> hScan(final String key, final long cursor) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor)); + } + + @Override + public ScanResult> hScan(final byte[] key, final long cursor) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor)); + } + + @Override + public ScanResult> hScan(final String key, final String cursor) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor)); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor)); + } + + @Override + public ScanResult> hScan(final String key, final long cursor, + final HScanArgument scanArgument) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, scanArgument)); + } + + @Override + public ScanResult> hScan(final byte[] key, final long cursor, + final HScanArgument scanArgument) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, scanArgument)); + } + + @Override + public ScanResult> hScan(final String key, final String cursor, + final HScanArgument scanArgument) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, scanArgument)); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, + final HScanArgument scanArgument) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, scanArgument)); + } + + @Override + public Long hSet(final String key, final KeyValue... data) { + return execute((client)->client.hashOperations().hSet(rawKey(key), data)); + } + + @Override + public Long hSet(final byte[] key, final KeyValue... data) { + return execute((client)->client.hashOperations().hSet(rawKey(key), data)); + } + + @Override + public Status hSetNx(final String key, final String field, final String value) { + return execute((client)->client.hashOperations().hSetNx(rawKey(key), field, value)); + } + + @Override + public Status hSetNx(final byte[] key, final byte[] field, final byte[] value) { + return execute((client)->client.hashOperations().hSetNx(rawKey(key), field, value)); + } + + @Override + public Long hStrLen(final String key, final String field) { + return execute((client)->client.hashOperations().hStrLen(rawKey(key), field)); + } + + @Override + public Long hStrLen(final byte[] key, final byte[] field) { + return execute((client)->client.hashOperations().hStrLen(rawKey(key), field)); + } + + @Override + public List hTtl(final String key, final String... fields) { + return execute((client)->client.hashOperations().hTtl(rawKey(key), fields)); + } + + @Override + public List hTtl(final byte[] key, final byte[]... fields) { + return execute((client)->client.hashOperations().hTtl(rawKey(key), fields)); + } + + @Override + public List hVals(final String key) { + return execute((client)->client.hashOperations().hVals(rawKey(key))); + } + + @Override + public List hVals(final byte[] key) { + return execute((client)->client.hashOperations().hVals(rawKey(key))); + } + + @Override + public Status pfAdd(final String key, final String... elements) { + return execute((client)->client.hyperLogLogOperations().pfAdd(rawKey(key), elements)); + } + + @Override + public Status pfAdd(final byte[] key, final byte[]... elements) { + return execute((client)->client.hyperLogLogOperations().pfAdd(rawKey(key), elements)); + } + + @Override + public Long pfCount(final String... keys) { + return execute((client)->client.hyperLogLogOperations().pfCount(rawKeys(keys))); + } + + @Override + public Long pfCount(final byte[]... keys) { + return execute((client)->client.hyperLogLogOperations().pfCount(rawKeys(keys))); + } + + @Override + public Status pfMerge(final String destKey, final String... keys) { + return execute((client)->client.hyperLogLogOperations().pfMerge(rawKey(destKey), rawKeys(keys))); + } + + @Override + public Status pfMerge(final byte[] destKey, final byte[]... keys) { + return execute((client)->client.hyperLogLogOperations().pfMerge(rawKey(destKey), rawKeys(keys))); + } + + @Override + public List aclCat() { + return execute((client)->client.aclOperations().aclCat()); + } + + @Override + public List aclCat(final AclCategory aclCategory) { + return execute((client)->client.aclOperations().aclCat(aclCategory)); + } + + @Override + public Long aclDelUser(final String... usernames) { + return execute((client)->client.aclOperations().aclDelUser(usernames)); + } + + @Override + public Long aclDelUser(final byte[]... username) { + return execute((client)->client.aclOperations().aclDelUser(username)); + } + + @Override + public Status aclDryRun(final String username, final Command command) { + return execute((client)->client.aclOperations().aclDryRun(username, command)); + } + + @Override + public Status aclDryRun(final byte[] username, final Command command) { + return execute((client)->client.aclOperations().aclDryRun(username, command)); + } + + @Override + public Status aclDryRun(final String username, final Command command, final String... arguments) { + return execute((client)->client.aclOperations().aclDryRun(username, command, arguments)); + } + + @Override + public Status aclDryRun(final byte[] username, final Command command, final byte[]... arguments) { + return execute((client)->client.aclOperations().aclDryRun(username, command, arguments)); + } + + @Override + public String aclGenPass() { + return execute((client)->client.aclOperations().aclGenPass()); + } + + @Override + public String aclGenPass(final int bits) { + return execute((client)->client.aclOperations().aclGenPass(bits)); + } + + @Override + public AclUser aclGetUser(final String username) { + return execute((client)->client.aclOperations().aclGetUser(username)); + } + + @Override + public AclUser aclGetUser(final byte[] username) { + return execute((client)->client.aclOperations().aclGetUser(username)); + } + + @Override + public List aclList() { + return execute((client)->client.aclOperations().aclList()); + } + + @Override + public Status aclLoad() { + return execute((client)->client.aclOperations().aclLoad()); + } + + @Override + public List aclLog() { + return execute((client)->client.aclOperations().aclLog()); + } + + @Override + public List aclLog(final int count) { + return execute((client)->client.aclOperations().aclLog(count)); + } + + @Override + public Status aclLogReset() { + return execute((client)->client.aclOperations().aclLogReset()); + } + + @Override + public Status aclSave() { + return execute((client)->client.aclOperations().aclSave()); + } + + @Override + public Status aclSetUser(final String username, final AclSetUserArgument rules) { + return execute((client)->client.aclOperations().aclSetUser(username, rules)); + } + + @Override + public Status aclSetUser(final byte[] username, final AclSetUserArgument rules) { + return execute((client)->client.aclOperations().aclSetUser(username, rules)); + } + + @Override + public List aclUsers() { + return execute((client)->client.aclOperations().aclUsers()); + } + + @Override + public String aclWhoAmI() { + return execute((client)->client.aclOperations().aclWhoAmI()); + } + + @Override + public String lIndex(final String key, final long index) { + return execute((client)->client.listOperations().lIndex(rawKey(key), index)); + } + + @Override + public byte[] lIndex(final byte[] key, final long index) { + return execute((client)->client.listOperations().lIndex(rawKey(key), index)); + } + + @Override + public Long lInsert(final String key, final ListPosition position, final String pivot, final String value) { + return execute((client)->client.listOperations().lInsert(rawKey(key), position, pivot, value)); + } + + @Override + public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value) { + return execute((client)->client.listOperations().lInsert(rawKey(key), position, pivot, value)); + } + + @Override + public Status lSet(final String key, final long index, final String value) { + return execute((client)->client.listOperations().lSet(rawKey(key), index, value)); + } + + @Override + public Status lSet(final byte[] key, final long index, final byte[] value) { + return execute((client)->client.listOperations().lSet(rawKey(key), index, value)); + } + + @Override + public Long lLen(final String key) { + return execute((client)->client.listOperations().lLen(rawKey(key))); + } + + @Override + public Long lLen(final byte[] key) { + return execute((client)->client.listOperations().lLen(rawKey(key))); + } + + @Override + public List lRange(final String key, final long start, final long end) { + return execute((client)->client.listOperations().lRange(rawKey(key), start, end)); + } + + @Override + public List lRange(final byte[] key, final long start, final long end) { + return execute((client)->client.listOperations().lRange(rawKey(key), start, end)); + } + + @Override + public Long lPos(final String key, final String element) { + return execute((client)->client.listOperations().lPos(rawKey(key), element)); + } + + @Override + public Long lPos(final byte[] key, final byte[] element) { + return execute((client)->client.listOperations().lPos(rawKey(key), element)); + } + + @Override + public Long lPos(final String key, final String element, final LPosArgument lPosArgument) { + return execute((client)->client.listOperations().lPos(rawKey(key), element, lPosArgument)); + } + + @Override + public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument) { + return execute((client)->client.listOperations().lPos(rawKey(key), element, lPosArgument)); + } + + @Override + public List lPos(final String key, String element, final LPosArgument lPosArgument, final int count) { + return execute((client)->client.listOperations().lPos(rawKey(key), element, lPosArgument, count)); + } + + @Override + public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final int count) { + return execute((client)->client.listOperations().lPos(rawKey(key), element, lPosArgument, count)); + } + + @Override + public Long lRem(final String key, final String value, final int count) { + return execute((client)->client.listOperations().lRem(rawKey(key), value, count)); + } + + @Override + public Long lRem(final byte[] key, final byte[] value, final int count) { + return execute((client)->client.listOperations().lRem(rawKey(key), value, count)); + } + + @Override + public Status lTrim(final String key, final long start, final long end) { + return execute((client)->client.listOperations().lTrim(rawKey(key), start, end)); + } + + @Override + public Status lTrim(final byte[] key, final long start, final long end) { + return execute((client)->client.listOperations().lTrim(rawKey(key), start, end)); + } + + @Override + public String lMove(final String key, final String destKey, final Direction from, final Direction to) { + return execute((client)->client.listOperations().lMove(rawKey(destKey), rawKey(destKey), from, to)); + } + + @Override + public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { + return execute((client)->client.listOperations().lMove(rawKey(key), rawKey(destKey), from, to)); + } + + @Override + public String blMove(final String key, final String destKey, final Direction from, final Direction to, + final int timeout) { + return execute((client)->client.listOperations().blMove(rawKey(destKey), rawKey(destKey), from, to, timeout)); + } + + @Override + public byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout) { + return execute((client)->client.listOperations().blMove(rawKey(key), rawKey(destKey), from, to, timeout)); + } + + @Override + public List blPop(final String[] keys, final int timeout) { + return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout)); + } + + @Override + public List blPop(final byte[][] keys, final int timeout) { + return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout)); + } + + @Override + public List brPop(final String[] keys, final int timeout) { + return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout)); + } + + @Override + public List brPop(final byte[][] keys, final int timeout) { + return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout)); + } + + @Override + public String brPoplPush(final String key, final String destKey, final int timeout) { + return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout)); + } + + @Override + public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout) { + return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout)); + } + + @Override + public String lPop(final String key) { + return execute((client)->client.listOperations().lPop(rawKey(key))); + } + + @Override + public byte[] lPop(final byte[] key) { + return execute((client)->client.listOperations().lPop(rawKey(key))); + } + + @Override + public Long lPush(final String key, final String... values) { + return execute((client)->client.listOperations().lPush(rawKey(key), values)); + } + + @Override + public Long lPush(final byte[] key, final byte[]... values) { + return execute((client)->client.listOperations().lPush(rawKey(key), values)); + } + + @Override + public Long lPushX(final String key, final String... values) { + return execute((client)->client.listOperations().lPushX(rawKey(key), values)); + } + + @Override + public Long lPushX(final byte[] key, final byte[]... values) { + return execute((client)->client.listOperations().lPushX(rawKey(key), values)); + } + + @Override + public String rPop(final String key) { + return execute((client)->client.listOperations().rPop(rawKey(key))); + } + + @Override + public byte[] rPop(final byte[] key) { + return execute((client)->client.listOperations().rPop(rawKey(key))); + } + + @Override + public String rPoplPush(final String key, final String destKey) { + return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey))); + } + + @Override + public byte[] rPoplPush(final byte[] key, final byte[] destKey) { + return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey))); + } + + @Override + public Long rPush(final String key, final String... values) { + return execute((client)->client.listOperations().rPush(rawKey(key), values)); + } + + @Override + public Long rPush(final byte[] key, final byte[]... values) { + return execute((client)->client.listOperations().rPush(rawKey(key), values)); + } + + @Override + public Long rPushX(final String key, final String... values) { + return execute((client)->client.listOperations().rPushX(rawKey(key), values)); + } + + @Override + public Long rPushX(final byte[] key, final byte[]... values) { + return execute((client)->client.listOperations().rPushX(rawKey(key), values)); + } + + @Override + public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener) { + execute((client)->{ + client.pubSubOperations().pSubscribe(patterns, pubSubListener); + return null; + }); + } + + @Override + public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener) { + execute((client)->{ + client.pubSubOperations().pSubscribe(patterns, pubSubListener); + return null; + }); + } + + @Override + public Long publish(final String channel, final String message) { + return execute((client)->client.pubSubOperations().publish(channel, message)); + } + + @Override + public Long publish(final byte[] channel, final byte[] message) { + return execute((client)->client.pubSubOperations().publish(channel, message)); + } + + @Override + public List pubsubChannels() { + return execute((client)->client.pubSubOperations().pubsubChannels()); + } + + @Override + public List pubsubChannels(final String pattern) { + return execute((client)->client.pubSubOperations().pubsubChannels(pattern)); + } + + @Override + public List pubsubChannels(final byte[] pattern) { + return execute((client)->client.pubSubOperations().pubsubChannels(pattern)); + } + + @Override + public List pubsubShardChannels() { + return execute((client)->client.pubSubOperations().pubsubShardChannels()); + } + + @Override + public List pubsubShardChannels(final String pattern) { + return execute((client)->client.pubSubOperations().pubsubShardChannels(pattern)); + } + + @Override + public List pubsubShardChannels(final byte[] pattern) { + return execute((client)->client.pubSubOperations().pubsubShardChannels(pattern)); + } + + @Override + public Long pubsubNumPat() { + return execute((client)->client.pubSubOperations().pubsubNumPat()); + } + + @Override + public Map pubsubNumSub() { + return execute((client)->client.pubSubOperations().pubsubNumSub()); + } + + @Override + public Map pubsubNumSub(final String... channels) { + return execute((client)->client.pubSubOperations().pubsubNumSub(channels)); + } + + @Override + public Map pubsubNumSub(final byte[]... channels) { + return execute((client)->client.pubSubOperations().pubsubNumSub(channels)); + } + + @Override + public Map pubsubShardNumSub() { + return execute((client)->client.pubSubOperations().pubsubShardNumSub()); + } + + @Override + public Map pubsubShardNumSub(final String... shardChannels) { + return execute((client)->client.pubSubOperations().pubsubShardNumSub(shardChannels)); + } + + @Override + public Map pubsubShardNumSub(final byte[]... shardChannels) { + return execute((client)->client.pubSubOperations().pubsubShardNumSub(shardChannels)); + } + + @Override + public Object pUnSubscribe() { + return execute((client)->client.pubSubOperations().pUnSubscribe()); + } + + @Override + public Object pUnSubscribe(final String... patterns) { + return execute((client)->client.pubSubOperations().pUnSubscribe(patterns)); + } + + @Override + public Object pUnSubscribe(final byte[]... patterns) { + return execute((client)->client.pubSubOperations().pUnSubscribe(patterns)); + } + + @Override + public void subscribe(final String[] channels, final PubSubListener pubSubListener) { + execute((client)->{ + client.pubSubOperations().subscribe(channels, pubSubListener); + return null; + }); + } + + @Override + public void subscribe(final byte[][] channels, final PubSubListener pubSubListener) { + execute((client)->{ + client.pubSubOperations().subscribe(channels, pubSubListener); + return null; + }); + } + + @Override + public Object unSubscribe() { + return execute((client)->client.pubSubOperations().unSubscribe()); + } + + @Override + public Object unSubscribe(final String... channels) { + return execute((client)->client.pubSubOperations().unSubscribe(channels)); + } + + @Override + public Object unSubscribe(final byte[]... channels) { + return execute((client)->client.pubSubOperations().unSubscribe(channels)); + } + + @Override + public Object eval(final String script) { + return execute((client)->client.scriptingOperations().eval(script)); + } + + @Override + public Object eval(final byte[] script) { + return execute((client)->client.scriptingOperations().eval(script)); + } + + @Override + public Object eval(final String script, final String... params) { + return execute((client)->client.scriptingOperations().eval(script, params)); + } + + @Override + public Object eval(final byte[] script, final byte[]... params) { + return execute((client)->client.scriptingOperations().eval(script, params)); + } + + @Override + public Object eval(final String script, final String[] keys, final String[] arguments) { + return execute((client)->client.scriptingOperations().eval(script, rawKeys(keys), arguments)); + } + + @Override + public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments) { + return execute((client)->client.scriptingOperations().eval(script, rawKeys(keys), arguments)); + } + + @Override + public Object evalSha(final String digest) { + return execute((client)->client.scriptingOperations().evalSha(digest)); + } + + @Override + public Object evalSha(final byte[] digest) { + return execute((client)->client.scriptingOperations().evalSha(digest)); + } + + @Override + public Object evalSha(final String digest, final String... params) { + return execute((client)->client.scriptingOperations().evalSha(digest, params)); + } + + @Override + public Object evalSha(final byte[] digest, final byte[]... params) { + return execute((client)->client.scriptingOperations().evalSha(digest, params)); + } + + @Override + public Object evalSha(final String digest, final String[] keys, final String[] arguments) { + return execute((client)->client.scriptingOperations().evalSha(digest, rawKeys(keys), arguments)); + } + + @Override + public Object evalSha(final byte[] digest, final byte[][] keys, final byte[][] arguments) { + return execute((client)->client.scriptingOperations().evalSha(digest, rawKeys(keys), arguments)); + } + + @Override + public List scriptExists(final String... sha1) { + return execute((client)->client.scriptingOperations().scriptExists(sha1)); + } + + @Override + public List scriptExists(final byte[]... sha1) { + return execute((client)->client.scriptingOperations().scriptExists(sha1)); + } + + @Override + public Status scriptFlush() { + return execute((client)->client.scriptingOperations().scriptFlush()); + } + + @Override + public Status scriptFlush(final FlushMode mode) { + return execute((client)->client.scriptingOperations().scriptFlush(mode)); + } + + @Override + public String scriptLoad(final String script) { + return execute((client)->client.scriptingOperations().scriptLoad(script)); + } + + @Override + public byte[] scriptLoad(final byte[] script) { + return execute((client)->client.scriptingOperations().scriptLoad(script)); + } + + @Override + public Status scriptKill() { + return execute((client)->client.scriptingOperations().scriptKill()); + } + + @Override + public String bgRewriteAof() { + return execute((client)->client.serverOperations().bgRewriteAof()); + } + + @Override + public String bgSave() { + return execute((client)->client.serverOperations().bgSave()); + } + + @Override + public Status configSet(final String parameter, final String value) { + return execute((client)->client.serverOperations().configSet(parameter, value)); + } + + @Override + public Status configSet(final byte[] parameter, final byte[] value) { + return execute((client)->client.serverOperations().configSet(parameter, value)); + } + + @Override + public Status configSet(final Map configs) { + return execute((client)->client.serverOperations().configSet(configs)); + } + + @Override + public Map configGet(final String pattern) { + return execute((client)->client.serverOperations().configGet(pattern)); + } + + @Override + public Map configGet(final byte[] pattern) { + return execute((client)->client.serverOperations().configGet(pattern)); + } + + @Override + public Status configResetStat() { + return execute((client)->client.serverOperations().configResetStat()); + } + + @Override + public Status configRewrite() { + return execute((client)->client.serverOperations().configRewrite()); + } + + @Override + public Long dbSize() { + return execute((client)->client.serverOperations().dbSize()); + } + + @Override + public Status failover() { + return execute((client)->client.serverOperations().failover()); + } + + @Override + public Status failover(final String host, final int port) { + return execute((client)->client.serverOperations().failover(host, port)); + } + + @Override + public Status failover(final String host, final int port, final int timeout) { + return execute((client)->client.serverOperations().failover(host, port, timeout)); + } + + @Override + public Status failover(final String host, final int port, final boolean isForce, final int timeout) { + return execute((client)->client.serverOperations().failover(host, port, isForce, timeout)); + } + + @Override + public Status failover(final int timeout) { + return execute((client)->client.serverOperations().failover(timeout)); + } + + @Override + public Status flushAll() { + return execute((client)->client.serverOperations().flushAll()); + } + + @Override + public Status flushAll(final FlushMode mode) { + return execute((client)->client.serverOperations().flushAll(mode)); + } + + @Override + public Status flushDb() { + return execute((client)->client.serverOperations().flushDb()); + } + + @Override + public Status flushDb(final FlushMode mode) { + return execute((client)->client.serverOperations().flushDb(mode)); + } + + @Override + public Info info() { + return execute((client)->client.serverOperations().info()); + } + + @Override + public Info info(final Info.Section section) { + return execute((client)->client.serverOperations().info(section)); + } + + @Override + public Long lastSave() { + return execute((client)->client.serverOperations().lastSave()); + } + + @Override + public String memoryDoctor() { + return execute((client)->client.serverOperations().memoryDoctor()); + } + + @Override + public Status memoryPurge() { + return execute((client)->client.serverOperations().memoryPurge()); + } + + @Override + public MemoryStats memoryStats() { + return execute((client)->client.serverOperations().memoryStats()); + } + + @Override + public Long memoryUsage(final String key) { + return execute((client)->client.serverOperations().memoryUsage(key)); + } + + @Override + public Long memoryUsage(final byte[] key) { + return execute((client)->client.serverOperations().memoryUsage(key)); + } + + @Override + public Long memoryUsage(final String key, final int samples) { + return execute((client)->client.serverOperations().memoryUsage(rawKey(key), samples)); + } + + @Override + public Long memoryUsage(final byte[] key, final int samples) { + return execute((client)->client.serverOperations().memoryUsage(rawKey(key), samples)); + } + + @Override + public List moduleList() { + return execute((client)->client.serverOperations().moduleList()); + } + + @Override + public Status moduleLoad(final String path) { + return execute((client)->client.serverOperations().moduleLoad(path)); + } + + @Override + public Status moduleLoad(final byte[] path) { + return execute((client)->client.serverOperations().moduleLoad(path)); + } + + @Override + public Status moduleLoad(final String path, final String... arguments) { + return execute((client)->client.serverOperations().moduleLoad(path, arguments)); + } + + @Override + public Status moduleLoad(final byte[] path, final byte[]... arguments) { + return execute((client)->client.serverOperations().moduleLoad(path, arguments)); + } + + @Override + public Status moduleUnLoad(final String name) { + return execute((client)->client.serverOperations().moduleUnLoad(name)); + } + + @Override + public Status moduleUnLoad(final byte[] name) { + return execute((client)->client.serverOperations().moduleUnLoad(name)); + } + + @Override + public void monitor(final RedisMonitor redisMonitor) { + execute((client)->{ + client.serverOperations().monitor(redisMonitor); + return null; + }); + } + + @Override + public Object pSync(final String replicationId, final long offset) { + return execute((client)->client.serverOperations().pSync(replicationId, offset)); + } + + @Override + public Object pSync(final byte[] replicationId, final long offset) { + return execute((client)->client.serverOperations().pSync(replicationId, offset)); + } + + @Override + public void sync() { + execute((client)->{ + client.serverOperations().sync(); + return null; + }); + } + + @Override + public Status replicaOf(final String host, final int port) { + return execute((client)->client.serverOperations().replicaOf(host, port)); + } + + @Override + public Status slaveOf(final String host, final int port) { + return execute((client)->client.serverOperations().slaveOf(host, port)); + } + + @Override + public Role role() { + return execute((client)->client.serverOperations().role()); + } + + @Override + public Status save() { + return execute((client)->client.serverOperations().save()); + } + + @Override + public void shutdown() { + execute((client)->{ + client.serverOperations().shutdown(); + return null; + }); + } + + @Override + public void shutdown(final boolean save) { + execute((client)->{ + client.serverOperations().shutdown(save); + return null; + }); + } + + @Override + public List slowLogGet() { + return execute((client)->client.serverOperations().slowLogGet()); + } + + @Override + public List slowLogGet(final int count) { + return execute((client)->client.serverOperations().slowLogGet(count)); + } + + @Override + public Long slowLogLen() { + return execute((client)->client.serverOperations().slowLogLen()); + } + + @Override + public Status slowLogReset() { + return execute((client)->client.serverOperations().slowLogReset()); + } + + @Override + public Status swapdb(final int db1, final int db2) { + return execute((client)->client.serverOperations().swapdb(db1, db2)); + } + + @Override + public RedisServerTime time() { + return execute((client)->client.serverOperations().time()); + } + + @Override + public Long sAdd(final String key, final String... members) { + return execute((client)->client.setOperations().sAdd(rawKey(key), members)); + } + + @Override + public Long sAdd(final byte[] key, final byte[]... members) { + return execute((client)->client.setOperations().sAdd(rawKey(key), members)); + } + + @Override + public Long sCard(final String key) { + return execute((client)->client.setOperations().sCard(rawKey(key))); + } + + @Override + public Long sCard(final byte[] key) { + return execute((client)->client.setOperations().sCard(rawKey(key))); + } + + @Override + public Set sDiff(final String... keys) { + return execute((client)->client.setOperations().sDiff(rawKeys(keys))); + } + + @Override + public Set sDiff(final byte[]... keys) { + return execute((client)->client.setOperations().sDiff(rawKeys(keys))); + } + + @Override + public Long sDiffStore(final String destKey, final String... keys) { + return execute((client)->client.setOperations().sDiffStore(rawKey(destKey), rawKeys(keys))); + } + + @Override + public Long sDiffStore(final byte[] destKey, final byte[]... keys) { + return execute((client)->client.setOperations().sDiffStore(rawKey(destKey), rawKeys(keys))); + } + + @Override + public Set sInter(final String... keys) { + return execute((client)->client.setOperations().sInter(rawKeys(keys))); + } + + @Override + public Set sInter(final byte[]... keys) { + return execute((client)->client.setOperations().sInter(rawKeys(keys))); + } + + @Override + public Long sInterStore(final String destKey, final String... keys) { + return execute((client)->client.setOperations().sDiffStore(rawKey(destKey), rawKeys(keys))); + } + + @Override + public Long sInterStore(final byte[] destKey, final byte[]... keys) { + return execute((client)->client.setOperations().sDiffStore(rawKey(destKey), rawKeys(keys))); + } + + @Override + public Boolean sIsMember(final String key, final String member) { + return execute((client)->client.setOperations().sIsMember(rawKey(key), member)); + } + + @Override + public Boolean sIsMember(final byte[] key, final byte[] member) { + return execute((client)->client.setOperations().sIsMember(rawKey(key), member)); + } + + @Override + public List smIsMember(final String key, final String... members) { + return execute((client)->client.setOperations().smIsMember(rawKey(key), members)); + } + + @Override + public List smIsMember(final byte[] key, final byte[]... members) { + return execute((client)->client.setOperations().smIsMember(rawKey(key), members)); + } + + @Override + public Set sMembers(final String key) { + return execute((client)->client.setOperations().sMembers(rawKey(key))); + } + + @Override + public Set sMembers(final byte[] key) { + return execute((client)->client.setOperations().sMembers(rawKey(key))); + } + + @Override + public Status sMove(final String key, final String destKey, final String member) { + return execute((client)->client.setOperations().sMove(rawKey(key), rawKey(destKey), member)); + } + + @Override + public Status sMove(final byte[] key, final byte[] destKey, final byte[] member) { + return execute((client)->client.setOperations().sMove(rawKey(key), rawKey(destKey), member)); + } + + @Override + public String sPop(final String key) { + return execute((client)->client.setOperations().sPop(rawKey(key))); + } + + @Override + public byte[] sPop(final byte[] key) { + return execute((client)->client.setOperations().sPop(rawKey(key))); + } + + @Override + public Set sPop(final String key, final int count) { + return execute((client)->client.setOperations().sPop(rawKey(key), count)); + } + + @Override + public Set sPop(final byte[] key, final int count) { + return execute((client)->client.setOperations().sPop(rawKey(key), count)); + } + + @Override + public String sRandMember(final String key) { + return execute((client)->client.setOperations().sRandMember(rawKey(key))); + } + + @Override + public byte[] sRandMember(final byte[] key) { + return execute((client)->client.setOperations().sRandMember(rawKey(key))); + } + + @Override + public List sRandMember(final String key, final int count) { + return execute((client)->client.setOperations().sRandMember(rawKey(key), count)); + } + + @Override + public List sRandMember(final byte[] key, final int count) { + return execute((client)->client.setOperations().sRandMember(rawKey(key), count)); + } + + @Override + public Long sRem(final String key, final String... members) { + return execute((client)->client.setOperations().sRem(rawKey(key), members)); + } + + @Override + public Long sRem(final byte[] key, final byte[]... members) { + return execute((client)->client.setOperations().sRem(rawKey(key), members)); + } + + @Override + public ScanResult> sScan(final String key, final long cursor) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor)); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor)); + } + + @Override + public ScanResult> sScan(final String key, final String cursor) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor)); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor)); + } + + @Override + public ScanResult> sScan(final String key, final long cursor, final String pattern) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern)); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor, final byte[] pattern) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern)); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern)); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern)); + } + + @Override + public ScanResult> sScan(final String key, final long cursor, final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count)); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor, final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count)); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count)); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count)); + } + + @Override + public ScanResult> sScan(final String key, final long cursor, final String pattern, final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count)); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor, final byte[] pattern, final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count)); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern, + final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count)); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count)); + } + + @Override + public Set sUnion(final String... keys) { + return execute((client)->client.setOperations().sUnion(rawKeys(keys))); + } + + @Override + public Set sUnion(final byte[]... keys) { + return execute((client)->client.setOperations().sUnion(rawKeys(keys))); + } + + @Override + public Long sUnionStore(final String destKey, final String... keys) { + return execute((client)->client.setOperations().sUnionStore(rawKey(destKey), rawKeys(keys))); + } + + @Override + public Long sUnionStore(final byte[] destKey, final byte[]... keys) { + return execute((client)->client.setOperations().sUnionStore(rawKey(destKey), rawKeys(keys))); + } + + @Override + public Tuple zPopMin(final String key) { + return execute((client)->client.sortedSetOperations().zPopMin(rawKey(key))); + } + + @Override + public Tuple zPopMin(final byte[] key) { + return execute((client)->client.sortedSetOperations().zPopMin(rawKey(key))); + } + + @Override + public List zPopMin(final String key, int count) { + return execute((client)->client.sortedSetOperations().zPopMin(rawKey(key), count)); + } + + @Override + public List zPopMin(final byte[] key, int count) { + return execute((client)->client.sortedSetOperations().zPopMin(rawKey(key), count)); + } + + @Override + public Tuple zPopMax(final String key) { + return execute((client)->client.sortedSetOperations().zPopMax(rawKey(key))); + } + + @Override + public Tuple zPopMax(final byte[] key) { + return execute((client)->client.sortedSetOperations().zPopMax(rawKey(key))); + } + + @Override + public List zPopMax(final String key, final int count) { + return execute((client)->client.sortedSetOperations().zPopMax(rawKey(key), count)); + } + + @Override + public List zPopMax(final byte[] key, final int count) { + return execute((client)->client.sortedSetOperations().zPopMax(rawKey(key), count)); + } + + @Override + public KeyValue bzPopMin(final String[] keys, final int timeout) { + return execute((client)->client.sortedSetOperations().bzPopMin(rawKeys(keys), timeout)); + } + + @Override + public KeyValue bzPopMin(final byte[][] keys, final int timeout) { + return execute((client)->client.sortedSetOperations().bzPopMin(rawKeys(keys), timeout)); + } + + @Override + public KeyValue bzPopMax(final String[] keys, final int timeout) { + return execute((client)->client.sortedSetOperations().bzPopMax(rawKeys(keys), timeout)); + } + + @Override + public KeyValue bzPopMax(final byte[][] keys, final int timeout) { + return execute((client)->client.sortedSetOperations().bzPopMax(rawKeys(keys), timeout)); + } + + @Override + public Long zAdd(final String key, final Map members) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members)); + } + + @Override + public Long zAdd(final byte[] key, final Map members) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members)); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx)); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx)); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, gtLt)); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, gtLt)); + } + + @Override + public Long zAdd(final String key, final Map members, final boolean ch) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, ch)); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final boolean ch) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, ch)); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx, gtLt)); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx, gtLt)); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx, ch)); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx, ch)); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, gtLt, ch)); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, gtLt, ch)); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx, gtLt, ch)); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx, gtLt, ch)); + } + + @Override + public Long zCard(final String key) { + return execute((client)->client.sortedSetOperations().zCard(rawKey(key))); + } + + @Override + public Long zCard(final byte[] key) { + return execute((client)->client.sortedSetOperations().zCard(rawKey(key))); + } + + @Override + public Long zCount(final String key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zCount(rawKey(key), min, max)); + } + + @Override + public Long zCount(final byte[] key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zCount(rawKey(key), min, max)); + } + + @Override + public List zDiff(final String... keys) { + return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys))); + } + + @Override + public List zDiff(final byte[]... keys) { + return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys))); + } + + @Override + public List zDiffWithScores(final String... keys) { + return execute((client)->client.sortedSetOperations().zDiffWithScores(rawKeys(keys))); + } + + @Override + public List zDiffWithScores(final byte[]... keys) { + return execute((client)->client.sortedSetOperations().zDiffWithScores(rawKeys(keys))); + } + + @Override + public Long zDiffStore(final String destKey, final String... keys) { + return execute((client)->client.sortedSetOperations().zDiffStore(rawKey(destKey), rawKeys(keys))); + } + + @Override + public Long zDiffStore(final byte[] destKey, final byte[]... keys) { + return execute((client)->client.sortedSetOperations().zDiffStore(rawKey(destKey), rawKeys(keys))); + } + + @Override + public Double zIncrBy(final String key, final double increment, final String member) { + return execute((client)->client.sortedSetOperations().zIncrBy(rawKey(key), increment, member)); + } + + @Override + public Double zIncrBy(final byte[] key, final double increment, final byte[] member) { + return execute((client)->client.sortedSetOperations().zIncrBy(rawKey(key), increment, member)); + } + + @Override + public List zInter(final String... keys) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys))); + } + + @Override + public List zInter(final byte[]... keys) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys))); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate)); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate)); + } + + @Override + public List zInter(final String[] keys, final double... weights) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights)); + } + + @Override + public List zInter(final byte[][] keys, final double... weights) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights)); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate, final double... weights) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights)); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights)); + } + + @Override + public List zInterWithScores(final String... keys) { + return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys))); + } + + @Override + public List zInterWithScores(final byte[]... keys) { + return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys))); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys), aggregate)); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys), aggregate)); + } + + @Override + public List zInterWithScores(final String[] keys, final double... weights) { + return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys), weights)); + } + + @Override + public List zInterWithScores(final byte[][] keys, final double... weights) { + return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys), weights)); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys), aggregate, weights)); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys), aggregate, weights)); + } + + @Override + public Long zInterStore(final String destKey, final String... keys) { + return execute((client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys))); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[]... keys) { + return execute((client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys))); + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys), aggregate)); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys), aggregate)); + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final double... weights) { + return execute((client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys), weights)); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights) { + return execute((client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys), weights)); + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate, + final double... weights) { + return execute( + (client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys), aggregate, weights)); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + return execute( + (client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys), aggregate, weights)); + } + + @Override + public Long zLexCount(final String key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zLexCount(rawKey(key), min, max)); + } + + @Override + public Long zLexCount(final byte[] key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zLexCount(rawKey(key), min, max)); + } + + @Override + public List zMScore(final String key, final String... members) { + return execute((client)->client.sortedSetOperations().zMScore(rawKey(key), members)); + } + + @Override + public List zMScore(final byte[] key, final byte[]... members) { + return execute((client)->client.sortedSetOperations().zMScore(rawKey(key), members)); + } + + @Override + public String zRandMember(final String key) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key))); + } + + @Override + public byte[] zRandMember(final byte[] key) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key))); + } + + @Override + public List zRandMember(final String key, final int count) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count)); + } + + @Override + public List zRandMember(final byte[] key, final int count) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count)); + } + + @Override + public List zRandMemberWithScores(final String key, final int count) { + return execute((client)->client.sortedSetOperations().zRandMemberWithScores(rawKey(key), count)); + } + + @Override + public List zRandMemberWithScores(final byte[] key, final int count) { + return execute((client)->client.sortedSetOperations().zRandMemberWithScores(rawKey(key), count)); + } + + @Override + public List zRange(final String key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end)); + } + + @Override + public List zRange(final byte[] key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end)); + } + + @Override + public List zRangeWithScores(final String key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRangeWithScores(rawKey(key), start, end)); + } + + @Override + public List zRangeWithScores(final byte[] key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRangeWithScores(rawKey(key), start, end)); + } + + @Override + public List zRangeByLex(final String key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max)); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max)); + } + + @Override + public List zRangeByLex(final String key, final double min, final double max, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max, offset, count)); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max, offset, count)); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max)); + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRangeByScore(rawKey(key), min, max)); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations().zRangeByScore(rawKey(key), min, max, offset, count)); + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations().zRangeByScore(rawKey(key), min, max, offset, count)); + } + + @Override + public List zRangeByScoreWithScores(final String key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRangeByScoreWithScores(rawKey(key), min, max)); + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRangeByScoreWithScores(rawKey(key), min, max)); + } + + @Override + public List zRangeByScoreWithScores(final String key, final double min, final double max, final long offset, + final int count) { + return execute( + (client)->client.sortedSetOperations().zRangeByScoreWithScores(rawKey(key), min, max, offset, count)); + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, + final int count) { + return execute( + (client)->client.sortedSetOperations().zRangeByScoreWithScores(rawKey(key), min, max, offset, count)); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end)); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end)); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by) { + return execute( + (client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end, by)); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by) { + return execute( + (client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end, by)); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final boolean rev) { + return execute( + (client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end, rev)); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final boolean rev) { + return execute( + (client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end, rev)); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations() + .zRangeStore(rawKey(destKey), rawKey(key), start, end, offset, count)); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations() + .zRangeStore(rawKey(destKey), rawKey(key), start, end, offset, count)); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, + final boolean rev) { + return execute( + (client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end, by, rev)); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, + final boolean rev) { + return execute( + (client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end, by, rev)); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, + final long offset, final int count) { + return execute((client)->client.sortedSetOperations() + .zRangeStore(rawKey(destKey), rawKey(key), start, end, by, offset, count)); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, + final long offset, final int count) { + return execute((client)->client.sortedSetOperations() + .zRangeStore(rawKey(destKey), rawKey(key), start, end, by, offset, count)); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev, + final long offset, final int count) { + return execute((client)->client.sortedSetOperations() + .zRangeStore(rawKey(destKey), rawKey(key), start, end, rev, offset, count)); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev, + final long offset, final int count) { + return execute((client)->client.sortedSetOperations() + .zRangeStore(rawKey(destKey), rawKey(key), start, end, rev, offset, count)); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count) { + return execute((client)->client.sortedSetOperations() + .zRangeStore(rawKey(destKey), rawKey(key), start, end, by, rev, offset, count)); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count) { + return execute((client)->client.sortedSetOperations() + .zRangeStore(rawKey(destKey), rawKey(key), start, end, by, rev, offset, count)); + } + + @Override + public Long zRank(final String key, final String member) { + return execute((client)->client.sortedSetOperations().zRank(rawKey(key), member)); + } + + @Override + public Long zRank(final byte[] key, final byte[] member) { + return execute((client)->client.sortedSetOperations().zRank(rawKey(key), member)); + } + + @Override + public Long zRem(final String key, final String... members) { + return execute((client)->client.sortedSetOperations().zRem(rawKey(key), members)); + } + + @Override + public Long zRem(final byte[] key, final byte[]... members) { + return execute((client)->client.sortedSetOperations().zRem(rawKey(key), members)); + } + + @Override + public Long zRemRangeByLex(final String key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRemRangeByLex(rawKey(key), min, max)); + } + + @Override + public Long zRemRangeByLex(final byte[] key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRemRangeByLex(rawKey(key), min, max)); + } + + @Override + public Long zRemRangeByScore(final String key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRemRangeByScore(rawKey(key), min, max)); + } + + @Override + public Long zRemRangeByScore(final byte[] key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRemRangeByScore(rawKey(key), min, max)); + } + + @Override + public Long zRemRangeByRank(final String key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRemRangeByRank(rawKey(key), start, end)); + } + + @Override + public Long zRemRangeByRank(final byte[] key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRemRangeByRank(rawKey(key), start, end)); + } + + @Override + public List zRevRange(final String key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRevRange(rawKey(key), start, end)); + } + + @Override + public List zRevRange(final byte[] key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRevRange(rawKey(key), start, end)); + } + + @Override + public List zRevRangeWithScores(final String key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRevRangeWithScores(rawKey(key), start, end)); + } + + @Override + public List zRevRangeWithScores(final byte[] key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRevRangeWithScores(rawKey(key), start, end)); + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(rawKey(key), min, max)); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(rawKey(key), min, max)); + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(rawKey(key), min, max, offset, count)); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(rawKey(key), min, max, offset, count)); + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(rawKey(key), min, max)); + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(rawKey(key), min, max)); + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(rawKey(key), min, max, offset, count)); + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(rawKey(key), min, max, offset, count)); + } + + @Override + public List zRevRangeByScoreWithScores(final String key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRevRangeByScoreWithScores(rawKey(key), min, max)); + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRevRangeByScoreWithScores(rawKey(key), min, max)); + } + + @Override + public List zRevRangeByScoreWithScores(final String key, final double min, final double max, + final long offset, final int count) { + return execute((client)->client.sortedSetOperations() + .zRevRangeByScoreWithScores(rawKey(key), min, max, offset, count)); + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max, + final long offset, final int count) { + return execute((client)->client.sortedSetOperations() + .zRevRangeByScoreWithScores(rawKey(key), min, max, offset, count)); + } + + @Override + public Long zRevRank(final String key, final String member) { + return execute((client)->client.sortedSetOperations().zRevRank(rawKey(key), member)); + } + + @Override + public Long zRevRank(final byte[] key, final byte[] member) { + return execute((client)->client.sortedSetOperations().zRevRank(rawKey(key), member)); + } + + @Override + public ScanResult> zScan(final String key, final long cursor) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor)); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor)); + } + + @Override + public ScanResult> zScan(final String key, final String cursor) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor)); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor)); + } + + @Override + public ScanResult> zScan(final String key, final long cursor, final String pattern) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern)); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor, final byte[] pattern) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern)); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern)); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern)); + } + + @Override + public ScanResult> zScan(final String key, final long cursor, final int count) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, count)); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor, final int count) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, count)); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final int count) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, count)); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final int count) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, count)); + } + + @Override + public ScanResult> zScan(final String key, final long cursor, final String pattern, final int count) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern, count)); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor, final byte[] pattern, final int count) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern, count)); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern, + final int count) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern, count)); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern, count)); + } + + @Override + public Double zScore(final String key, final String member) { + return execute((client)->client.sortedSetOperations().zScore(rawKey(key), member)); + } + + @Override + public Double zScore(final byte[] key, final byte[] member) { + return execute((client)->client.sortedSetOperations().zScore(rawKey(key), member)); + } + + @Override + public List zUnion(final String... keys) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys))); + } + + @Override + public List zUnion(final byte[]... keys) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys))); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate)); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate)); + } + + @Override + public List zUnion(final String[] keys, final double... weights) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights)); + } + + @Override + public List zUnion(final byte[][] keys, final double... weights) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights)); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate, final double... weights) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights)); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights)); + } + + @Override + public List zUnionWithScores(final String... keys) { + return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys))); + } + + @Override + public List zUnionWithScores(final byte[]... keys) { + return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys))); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys), aggregate)); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys), aggregate)); + } + + @Override + public List zUnionWithScores(final String[] keys, final double... weights) { + return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys), weights)); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final double... weights) { + return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys), weights)); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys), aggregate, weights)); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys), aggregate, weights)); + } + + @Override + public Long zUnionStore(final String destKey, final String... keys) { + return execute((client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys))); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[]... keys) { + return execute((client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys))); + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys), aggregate)); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys), aggregate)); + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final double... weights) { + return execute((client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys), weights)); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights) { + return execute((client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys), weights)); + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate, + final double... weights) { + return execute( + (client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys), aggregate, weights)); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + return execute( + (client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys), aggregate, weights)); + } + + @Override + public Long xAck(final String key, final String groupName, final StreamEntryId... ids) { + return execute((client)->client.streamOperations().xAck(rawKey(key), groupName, ids)); + } + + @Override + public Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId... ids) { + return execute((client)->client.streamOperations().xAck(rawKey(key), groupName, ids)); + } + + @Override + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash) { + return execute((client)->client.streamOperations().xAdd(rawKey(key), id, hash)); + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, Map hash) { + return execute((client)->client.streamOperations().xAdd(rawKey(key), id, hash)); + } + + @Override + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + return execute((client)->client.streamOperations().xAdd(rawKey(key), id, hash, xAddArgument)); + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + return execute((client)->client.streamOperations().xAdd(rawKey(key), id, hash, xAddArgument)); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + return execute((client)->client.streamOperations() + .xAutoClaim(rawKey(key), groupName, consumerName, minIdleTime, start)); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + return execute((client)->client.streamOperations() + .xAutoClaim(rawKey(key), groupName, consumerName, minIdleTime, start)); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + return execute((client)->client.streamOperations() + .xAutoClaim(rawKey(key), groupName, consumerName, minIdleTime, start, count)); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + return execute((client)->client.streamOperations() + .xAutoClaim(rawKey(key), groupName, consumerName, minIdleTime, start, count)); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + return execute((client)->client.streamOperations() + .xAutoClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, start)); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + return execute((client)->client.streamOperations() + .xAutoClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, start)); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + return execute((client)->client.streamOperations() + .xAutoClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, start, count)); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + return execute((client)->client.streamOperations() + .xAutoClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, start, count)); + } + + @Override + public List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId... ids) { + return execute( + (client)->client.streamOperations().xClaim(rawKey(key), groupName, consumerName, minIdleTime, ids)); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + return execute( + (client)->client.streamOperations().xClaim(rawKey(key), groupName, consumerName, minIdleTime, ids)); + } + + @Override + public List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + return execute((client)->client.streamOperations() + .xClaim(rawKey(key), groupName, consumerName, minIdleTime, ids, xClaimArgument)); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + return execute((client)->client.streamOperations() + .xClaim(rawKey(key), groupName, consumerName, minIdleTime, ids, xClaimArgument)); + } + + @Override + public List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId... ids) { + return execute((client)->client.streamOperations() + .xClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, ids)); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + return execute((client)->client.streamOperations() + .xClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, ids)); + } + + @Override + public List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + return execute((client)->client.streamOperations() + .xClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, ids, xClaimArgument)); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + return execute((client)->client.streamOperations() + .xClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, ids, xClaimArgument)); + } + + @Override + public Long xDel(final String key, final StreamEntryId... ids) { + return execute((client)->client.streamOperations().xDel(rawKey(key), ids)); + } + + @Override + public Long xDel(final byte[] key, final StreamEntryId... ids) { + return execute((client)->client.streamOperations().xDel(rawKey(key), ids)); + } + + @Override + public Status xGroupCreate(final String key, final String groupName, final StreamEntryId id, + final boolean makeStream) { + return execute((client)->client.streamOperations().xGroupCreate(rawKey(key), groupName, id, makeStream)); + } + + @Override + public Status xGroupCreate(final byte[] key, final byte[] groupName, final StreamEntryId id, + final boolean makeStream) { + return execute((client)->client.streamOperations().xGroupCreate(rawKey(key), groupName, id, makeStream)); + } + + @Override + public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName) { + return execute((client)->client.streamOperations().xGroupCreateConsumer(rawKey(key), groupName, consumerName)); + } + + @Override + public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + return execute((client)->client.streamOperations().xGroupCreateConsumer(rawKey(key), groupName, consumerName)); + } + + @Override + public Long xGroupDelConsumer(final String key, final String groupName, final String consumerName) { + return execute((client)->client.streamOperations().xGroupDelConsumer(rawKey(key), groupName, consumerName)); + } + + @Override + public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + return execute((client)->client.streamOperations().xGroupDelConsumer(rawKey(key), groupName, consumerName)); + } + + @Override + public Status xGroupDestroy(final String key, final String groupName) { + return execute((client)->client.streamOperations().xGroupDestroy(rawKey(key), groupName)); + } + + @Override + public Status xGroupDestroy(final byte[] key, final byte[] groupName) { + return execute((client)->client.streamOperations().xGroupDestroy(rawKey(key), groupName)); + } + + @Override + public Status xGroupSetId(final String key, final String groupName, final StreamEntryId id) { + return execute((client)->client.streamOperations().xGroupSetId(rawKey(key), groupName, id)); + } + + @Override + public Status xGroupSetId(final byte[] key, final byte[] groupName, final StreamEntryId id) { + return execute((client)->client.streamOperations().xGroupSetId(rawKey(key), groupName, id)); + } + + @Override + public List xInfoConsumers(final String key, final String groupName) { + return execute((client)->client.streamOperations().xInfoConsumers(rawKey(key), groupName)); + } + + @Override + public List xInfoConsumers(final byte[] key, final byte[] groupName) { + return execute((client)->client.streamOperations().xInfoConsumers(rawKey(key), groupName)); + } + + @Override + public List xInfoGroups(final String key) { + return execute((client)->client.streamOperations().xInfoGroups(rawKey(key))); + } + + @Override + public List xInfoGroups(final byte[] key) { + return execute((client)->client.streamOperations().xInfoGroups(rawKey(key))); + } + + @Override + public Stream xInfoStream(final String key) { + return execute((client)->client.streamOperations().xInfoStream(rawKey(key))); + } + + @Override + public Stream xInfoStream(final byte[] key) { + return execute((client)->client.streamOperations().xInfoStream(rawKey(key))); + } + + @Override + public StreamFull xInfoStream(final String key, final boolean full) { + return execute((client)->client.streamOperations().xInfoStream(rawKey(key), full)); + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full) { + return execute((client)->client.streamOperations().xInfoStream(rawKey(key), full)); + } + + @Override + public StreamFull xInfoStream(final String key, final boolean full, final int count) { + return execute((client)->client.streamOperations().xInfoStream(rawKey(key), full, count)); + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full, final int count) { + return execute((client)->client.streamOperations().xInfoStream(rawKey(key), full, count)); + } + + @Override + public Long xLen(final String key) { + return execute((client)->client.streamOperations().xLen(rawKey(key))); + } + + @Override + public Long xLen(final byte[] key) { + return execute((client)->client.streamOperations().xLen(rawKey(key))); + } + + @Override + public StreamPendingSummary xPending(final String key, final String groupName) { + return execute((client)->client.streamOperations().xPending(rawKey(key), groupName)); + } + + @Override + public StreamPendingSummary xPending(final byte[] key, final byte[] groupName) { + return execute((client)->client.streamOperations().xPending(rawKey(key), groupName)); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime) { + return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, minIdleTime)); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime) { + return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, minIdleTime)); + } + + @Override + public List xPending(final String key, final String groupName, final StreamEntryId start, + final StreamEntryId end, final int count) { + return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, start, end, count)); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final int count) { + return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, start, end, count)); + } + + @Override + public List xPending(final String key, final String groupName, final String consumerName) { + return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, consumerName)); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final byte[] consumerName) { + return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, consumerName)); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count) { + return execute( + (client)->client.streamOperations().xPending(rawKey(key), groupName, minIdleTime, start, end, count)); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count) { + return execute( + (client)->client.streamOperations().xPending(rawKey(key), groupName, minIdleTime, start, end, count)); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final String consumerName) { + return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, minIdleTime, consumerName)); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final byte[] consumerName) { + return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, minIdleTime, consumerName)); + } + + @Override + public List xPending(final String key, final String groupName, final StreamEntryId start, + final StreamEntryId end, final int count, final String consumerName) { + return execute( + (client)->client.streamOperations().xPending(rawKey(key), groupName, start, end, count, consumerName)); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final int count, final byte[] consumerName) { + return execute( + (client)->client.streamOperations().xPending(rawKey(key), groupName, start, end, count, consumerName)); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count, + final String consumerName) { + return execute((client)->client.streamOperations() + .xPending(rawKey(key), groupName, minIdleTime, start, end, count, consumerName)); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count, + final byte[] consumerName) { + return execute((client)->client.streamOperations() + .xPending(rawKey(key), groupName, minIdleTime, start, end, count, consumerName)); + } + + @Override + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end) { + return execute((client)->client.streamOperations().xRange(rawKey(key), start, end)); + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end) { + return execute((client)->client.streamOperations().xRange(rawKey(key), start, end)); + } + + @Override + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end, + final int count) { + return execute((client)->client.streamOperations().xRange(rawKey(key), start, end)); + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end, + final int count) { + return execute((client)->client.streamOperations().xRange(rawKey(key), start, end)); + } + + @Override + public List>> xRead(final Map streams) { + return execute((client)->client.streamOperations().xRead(streams)); + } + + @Override + public List>> xRead(final Map streams, + final XReadArgument xReadArgument) { + return execute((client)->client.streamOperations().xRead(streams, xReadArgument)); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams) { + return execute((client)->client.streamOperations().xReadGroup(groupName, consumerName, streams)); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams) { + return execute((client)->client.streamOperations().xReadGroup(groupName, consumerName, streams)); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + return execute( + (client)->client.streamOperations().xReadGroup(groupName, consumerName, streams, xReadGroupArgument)); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + return execute( + (client)->client.streamOperations().xReadGroup(groupName, consumerName, streams, xReadGroupArgument)); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams) { + return execute((client)->client.streamOperations().xReadGroup(groupName, consumerName, isNoAck, streams)); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final boolean isNoAck, + final Map streams) { + return execute((client)->client.streamOperations().xReadGroup(groupName, consumerName, isNoAck, streams)); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + return execute( + (client)->client.streamOperations() + .xReadGroup(groupName, consumerName, isNoAck, streams, xReadGroupArgument)); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final boolean isNoAck, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + return execute( + (client)->client.streamOperations() + .xReadGroup(groupName, consumerName, isNoAck, streams, xReadGroupArgument)); + } + + @Override + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start) { + return execute((client)->client.streamOperations().xRevRange(rawKey(key), end, start)); + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start) { + return execute((client)->client.streamOperations().xRevRange(rawKey(key), end, start)); + } + + @Override + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start, + final int count) { + return execute((client)->client.streamOperations().xRevRange(rawKey(key), end, start, count)); + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start, + final int count) { + return execute((client)->client.streamOperations().xRevRange(rawKey(key), end, start, count)); + } + + @Override + public Long xTrim(final String key, final XTrimArgument xTrimArgument) { + return execute((client)->client.streamOperations().xTrim(rawKey(key), xTrimArgument)); + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument) { + return execute((client)->client.streamOperations().xTrim(rawKey(key), xTrimArgument)); + } + + @Override + public Long xTrim(final String key, final XTrimArgument xTrimArgument, final long limit) { + return execute((client)->client.streamOperations().xTrim(rawKey(key), xTrimArgument, limit)); + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit) { + return execute((client)->client.streamOperations().xTrim(rawKey(key), xTrimArgument, limit)); + } + + @Override + public Long append(final String key, final String value) { + return execute((client)->client.stringOperations().append(rawKey(key), value)); + } + + @Override + public Long append(final byte[] key, final byte[] value) { + return execute((client)->client.stringOperations().append(rawKey(key), value)); + } + + @Override + public Long incr(final String key) { + return execute((client)->client.stringOperations().incr(rawKey(key))); + } + + @Override + public Long incr(final byte[] key) { + return execute((client)->client.stringOperations().incr(rawKey(key))); + } + + @Override + public Long incrBy(final String key, final long value) { + return execute((client)->client.stringOperations().incrBy(rawKey(key), value)); + } + + @Override + public Long incrBy(final byte[] key, final long value) { + return execute((client)->client.stringOperations().incrBy(rawKey(key), value)); + } + + @Override + public Double incrByFloat(final String key, final double value) { + return execute((client)->client.stringOperations().incrByFloat(rawKey(key), value)); + } + + @Override + public Double incrByFloat(final byte[] key, final double value) { + return execute((client)->client.stringOperations().incrByFloat(rawKey(key), value)); + } + + @Override + public Long decr(final String key) { + return execute((client)->client.stringOperations().decr(rawKey(key))); + } + + @Override + public Long decr(final byte[] key) { + return execute((client)->client.stringOperations().decr(rawKey(key))); + } + + @Override + public Long decrBy(final String key, final long value) { + return execute((client)->client.stringOperations().decrBy(rawKey(key), value)); + } + + @Override + public Long decrBy(final byte[] key, final long value) { + return execute((client)->client.stringOperations().decrBy(rawKey(key), value)); + } + + @Override + public String get(final String key) { + return execute((client)->client.stringOperations().get(rawKey(key))); + } + + @Override + public byte[] get(final byte[] key) { + return execute((client)->client.stringOperations().get(rawKey(key))); + } + + @Override + public String getEx(final String key, final GetExArgument getExArgument) { + return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument)); + } + + @Override + public byte[] getEx(final byte[] key, final GetExArgument getExArgument) { + return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument)); + } + + @Override + public String getSet(final String key, final String value) { + return execute((client)->client.stringOperations().getSet(rawKey(key), value)); + } + + @Override + public byte[] getSet(final byte[] key, final byte[] value) { + return execute((client)->client.stringOperations().getSet(rawKey(key), value)); + } + + @Override + public String getDel(final String key) { + return execute((client)->client.stringOperations().getDel(rawKey(key))); + } + + @Override + public byte[] getDel(final byte[] key) { + return execute((client)->client.stringOperations().getDel(rawKey(key))); + } + + @Override + public List mGet(final String... keys) { + return execute((client)->client.stringOperations().mGet(rawKeys(keys))); + } + + @Override + public List mGet(final byte[]... keys) { + return execute((client)->client.stringOperations().mGet(rawKeys(keys))); + } + + @Override + public Status mSet(final Map values) { + final Map newValues = Maps.map(values, this::rawKey, (value)->value, + new LinkedHashMap<>(values.size())); + return execute((client)->client.stringOperations().mSet(newValues)); + } + + @Override + public Status mSetNx(final Map values) { + final Map newValues = Maps.map(values, this::rawKey, (value)->value, + new LinkedHashMap<>(values.size())); + return execute((client)->client.stringOperations().mSetNx(newValues)); + } + + @Override + public Status pSetEx(final String key, String value, int lifetime) { + return execute((client)->client.stringOperations().pSetEx(rawKey(key), value, lifetime)); + } + + @Override + public Status pSetEx(final byte[] key, final byte[] value, final int lifetime) { + return execute((client)->client.stringOperations().pSetEx(rawKey(key), value, lifetime)); + } + + @Override + public Status set(final String key, final String value) { + return execute((client)->client.stringOperations().set(rawKey(key), value)); + } + + @Override + public Status set(final byte[] key, final byte[] value) { + return execute((client)->client.stringOperations().set(rawKey(key), value)); + } + + @Override + public Status set(final String key, final String value, final SetArgument setArgument) { + return execute((client)->client.stringOperations().set(rawKey(key), value, setArgument)); + } + + @Override + public Status set(final byte[] key, final byte[] value, final SetArgument setArgument) { + return execute((client)->client.stringOperations().set(rawKey(key), value, setArgument)); + } + + @Override + public Status setEx(final String key, final String value, final int lifetime) { + return execute((client)->client.stringOperations().setEx(rawKey(key), value, lifetime)); + } + + @Override + public Status setEx(final byte[] key, final byte[] value, final int lifetime) { + return execute((client)->client.stringOperations().setEx(rawKey(key), value, lifetime)); + } + + @Override + public Status setNx(final String key, final String value) { + return execute((client)->client.stringOperations().setNx(rawKey(key), value)); + } + + @Override + public Status setNx(final byte[] key, final byte[] value) { + return execute((client)->client.stringOperations().setNx(rawKey(key), value)); + } + + @Override + public Long setRange(final String key, final long offset, final String value) { + return execute((client)->client.stringOperations().setRange(rawKey(key), offset, value)); + } + + @Override + public Long setRange(final byte[] key, final long offset, final byte[] value) { + return execute((client)->client.stringOperations().setRange(rawKey(key), offset, value)); + } + + @Override + public String getRange(final String key, final long start, final long end) { + return execute((client)->client.stringOperations().getRange(rawKey(key), start, end)); + } + + @Override + public byte[] getRange(final byte[] key, final long start, final long end) { + return execute((client)->client.stringOperations().getRange(rawKey(key), start, end)); + } + + @Override + public Long strlen(final String key) { + return execute((client)->client.stringOperations().strlen(rawKey(key))); + } + + @Override + public Long strlen(final byte[] key) { + return execute((client)->client.stringOperations().strlen(rawKey(key))); + } + + @Override + public String substr(final String key, final int start, final int end) { + return execute((client)->client.stringOperations().substr(rawKey(key), start, end)); + } + + @Override + public byte[] substr(final byte[] key, final int start, final int end) { + return execute((client)->client.stringOperations().substr(rawKey(key), start, end)); + } + + @Override + public Status multi() { + return execute((client)->{ + try{ + final Transaction transaction = client.getConnection().multi(); + return transaction != null ? Status.SUCCESS : Status.FAILURE; + }catch(Exception e){ + return Status.FAILURE; + } + }); + } + + @Override + public List exec() { + return execute((client)->client.getConnection().exec()); + } + + @Override + public void discard() { + execute((client)->{ + client.getConnection().discard(); + return null; + }); + } + + @Override + public Status watch(final String... keys) { + return execute((client)->client.transactionOperations().watch(rawKeys(keys))); + } + + @Override + public Status watch(final byte[]... keys) { + return execute((client)->client.transactionOperations().watch(rawKeys(keys))); + } + + @Override + public Status unwatch() { + return execute((client)->client.transactionOperations().unwatch()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/Converter.java b/buession-redis/src/main-tmp/java/com/buession/redis/Converter.java new file mode 100644 index 000000000..0db4565d7 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/Converter.java @@ -0,0 +1,1373 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis; + +import com.buession.core.collect.Maps; +import com.buession.core.type.TypeReference; +import com.buession.lang.KeyValue; +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.core.ScanResult; +import com.buession.redis.serializer.Serializer; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * @author Yong.Teng + * @since 2.0.0 + */ +@FunctionalInterface +interface Converter { + + TV convert(final RedisConnection connection, final SV value); + + abstract class AbstractConverter implements Converter { + + protected final ThreadLocal index; + + protected final Serializer serializer; + + public AbstractConverter(final RedisAccessor accessor) { + this.index = RedisAccessor.index; + this.serializer = accessor.serializer; + } + + protected static V addConverter(ThreadLocal index, Function function) { + RedisAccessor.getTxConverters().put(index.get(), function); + return null; + } + + protected static V addBinaryConverter(ThreadLocal index, Function function) { + RedisAccessor.getTxConverters().put(index.get(), function); + return null; + } + + protected static List addListConverter(ThreadLocal index, + Function, List> function) { + RedisAccessor.getTxConverters().put(index.get(), function); + return null; + } + + protected static List addListBinaryConverter(ThreadLocal index, + Function, List> function) { + RedisAccessor.getTxConverters().put(index.get(), function); + return null; + } + + protected static Set addSetConverter(ThreadLocal index, + Function, Set> function) { + RedisAccessor.getTxConverters().put(index.get(), function); + return null; + } + + protected static Set addSetBinaryConverter(ThreadLocal index, + Function, Set> function) { + RedisAccessor.getTxConverters().put(index.get(), function); + return null; + } + + protected static Map addMapConverter(ThreadLocal index, + Function, Map> function) { + RedisAccessor.getTxConverters().put(index.get(), function); + return null; + } + + protected static Map addMapBinaryConverter(ThreadLocal index, + Function, Map> function) { + RedisAccessor.getTxConverters().put(index.get(), function); + return null; + } + + protected static ScanResult addScanResultConverter(ThreadLocal index, + Function, ScanResult> function) { + RedisAccessor.getTxConverters().put(index.get(), function); + return null; + } + + protected static List> addKeyValueConverter(ThreadLocal index, + Function>, + List>> function) { + RedisAccessor.getTxConverters().put(index.get(), function); + return null; + } + + protected boolean isTransaction(final RedisConnection connection) { + return connection.isTransaction(); + } + + protected boolean isPipeline(final RedisConnection connection) { + return connection.isPipeline(); + } + + protected boolean isTransactionOrPipeline(final RedisConnection connection) { + return isTransaction(connection) || isPipeline(connection); + } + + } + + abstract class AbstractStringConverter extends AbstractConverter { + + public AbstractStringConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + abstract class AbstractBinaryConverter extends AbstractConverter { + + public AbstractBinaryConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + final class SimpleStringConverter extends AbstractStringConverter { + + public SimpleStringConverter(final RedisAccessor accessor) { + super(accessor); + } + + @Override + public V convert(final RedisConnection connection, final String value) { + if(isTransactionOrPipeline(connection)){ + return addConverter(index, serializer::deserialize); + }else{ + return serializer.deserialize(value); + } + } + + } + + final class SimpleBinaryConverter extends AbstractBinaryConverter { + + public SimpleBinaryConverter(final RedisAccessor accessor) { + super(accessor); + } + + @Override + public V convert(final RedisConnection connection, final byte[] value) { + if(isTransactionOrPipeline(connection)){ + return addBinaryConverter(index, serializer::deserializeBytes); + }else{ + return serializer.deserializeBytes(value); + } + } + + } + + final class ClazzStringConverter extends AbstractStringConverter { + + private final Class clazz; + + public ClazzStringConverter(final RedisAccessor accessor, final Class clazz) { + super(accessor); + this.clazz = clazz; + } + + @Override + public V convert(final RedisConnection connection, final String value) { + if(isTransactionOrPipeline(connection)){ + return addConverter(index, (val)->serializer.deserialize(val, clazz)); + }else{ + return serializer.deserialize(value, clazz); + } + } + + } + + final class ClazzBinaryConverter extends AbstractBinaryConverter { + + private final Class clazz; + + public ClazzBinaryConverter(final RedisAccessor accessor, final Class clazz) { + super(accessor); + this.clazz = clazz; + } + + @Override + public V convert(final RedisConnection connection, final byte[] value) { + if(isTransactionOrPipeline(connection)){ + return addBinaryConverter(index, (val)->serializer.deserializeBytes(val, clazz)); + }else{ + return serializer.deserializeBytes(value, clazz); + } + } + + } + + final class TypeStringConverter extends AbstractStringConverter { + + private final TypeReference typeReference; + + public TypeStringConverter(final RedisAccessor accessor, final TypeReference typeReference) { + super(accessor); + this.typeReference = typeReference; + } + + @Override + public V convert(final RedisConnection connection, final String value) { + if(isTransactionOrPipeline(connection)){ + return addConverter(index, (val)->serializer.deserialize(val, typeReference)); + }else{ + return serializer.deserialize(value, typeReference); + } + } + + } + + final class TypeBinaryConverter extends AbstractBinaryConverter { + + private final TypeReference typeReference; + + public TypeBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference) { + super(accessor); + this.typeReference = typeReference; + } + + @Override + public V convert(final RedisConnection connection, final byte[] value) { + if(isTransactionOrPipeline(connection)){ + return addBinaryConverter(index, (val)->serializer.deserializeBytes(val, typeReference)); + }else{ + return serializer.deserializeBytes(value, typeReference); + } + } + + } + + abstract class AbstractListStringConverter extends AbstractConverter, List> { + + public AbstractListStringConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + abstract class AbstractListBinaryConverter extends AbstractConverter, List> { + + public AbstractListBinaryConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + final class SimpleListStringConverter extends AbstractListStringConverter { + + public SimpleListStringConverter(final RedisAccessor accessor) { + super(accessor); + } + + @Override + public List convert(final RedisConnection connection, final List value) { + final Function, List> function = (data)->{ + if(data != null){ + final List result = new ArrayList<>(data.size()); + + for(String s : data){ + result.add(serializer.deserialize(s)); + } + + return result; + } + + return null; + }; + + if(isTransactionOrPipeline(connection)){ + return addListConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class SimpleListBinaryConverter extends AbstractListBinaryConverter { + + public SimpleListBinaryConverter(final RedisAccessor accessor) { + super(accessor); + } + + @Override + public List convert(final RedisConnection connection, final List value) { + final Function, List> function = (data)->{ + if(data != null){ + final List result = new ArrayList<>(data.size()); + + for(byte[] b : data){ + result.add(serializer.deserializeBytes(b)); + } + + return result; + } + + return null; + }; + + if(isTransactionOrPipeline(connection)){ + return addListBinaryConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class ClazzListStringConverter extends AbstractListStringConverter { + + private final Class clazz; + + public ClazzListStringConverter(final RedisAccessor accessor, final Class clazz) { + super(accessor); + this.clazz = clazz; + } + + @Override + public List convert(final RedisConnection connection, final List value) { + final Function, List> function = (data)->data == null ? null : + data.stream().map((val)->serializer.deserialize(val, clazz)).collect(Collectors.toList()); + + if(isTransactionOrPipeline(connection)){ + return addListConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class ClazzListBinaryConverter extends AbstractListBinaryConverter { + + private final Class clazz; + + public ClazzListBinaryConverter(final RedisAccessor accessor, final Class clazz) { + super(accessor); + this.clazz = clazz; + } + + @Override + public List convert(final RedisConnection connection, final List value) { + final Function, List> function = (data)-> + data == null ? null : data.stream().map((val)->serializer.deserializeBytes(val, clazz)) + .collect(Collectors.toList()); + + if(isTransactionOrPipeline(connection)){ + return addListBinaryConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class TypeListStringConverter extends AbstractListStringConverter { + + private final TypeReference typeReference; + + public TypeListStringConverter(final RedisAccessor accessor, final TypeReference typeReference) { + super(accessor); + this.typeReference = typeReference; + } + + @Override + public List convert(final RedisConnection connection, final List value) { + final Function, List> function = (data)->data == null ? null : + data.stream().map((val)->serializer.deserialize(val, typeReference)).collect(Collectors.toList()); + + if(isTransactionOrPipeline(connection)){ + return addListConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class TypeListBinaryConverter extends AbstractListBinaryConverter { + + private final TypeReference typeReference; + + public TypeListBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference) { + super(accessor); + this.typeReference = typeReference; + } + + @Override + public List convert(final RedisConnection connection, final List value) { + final Function, List> function = (data)->data == null ? null : + data.stream().map((val)->serializer.deserializeBytes(val, typeReference)) + .collect(Collectors.toList()); + + if(isTransactionOrPipeline(connection)){ + return addListBinaryConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + abstract class AbstractSetStringConverter extends AbstractConverter, Set> { + + public AbstractSetStringConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + abstract class AbstractSetBinaryConverter extends AbstractConverter, Set> { + + public AbstractSetBinaryConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + final class SimpleSetStringConverter extends AbstractSetStringConverter { + + public SimpleSetStringConverter(final RedisAccessor accessor) { + super(accessor); + } + + @Override + public Set convert(final RedisConnection connection, final Set value) { + final Function, Set> function = (data)->{ + if(data != null){ + final Set result = new LinkedHashSet<>(data.size()); + + for(String s : data){ + result.add(serializer.deserialize(s)); + } + + return result; + } + + return null; + }; + + if(isTransactionOrPipeline(connection)){ + return addSetConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class SimpleSetBinaryConverter extends AbstractSetBinaryConverter { + + public SimpleSetBinaryConverter(final RedisAccessor accessor) { + super(accessor); + } + + @Override + public Set convert(final RedisConnection connection, final Set value) { + final Function, Set> function = (data)->{ + if(data != null){ + final Set result = new LinkedHashSet<>(data.size()); + + for(byte[] b : data){ + result.add(serializer.deserializeBytes(b)); + } + + return result; + } + + return null; + }; + + if(isTransactionOrPipeline(connection)){ + return addSetBinaryConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class ClazzSetStringConverter extends AbstractSetStringConverter { + + private final Class clazz; + + public ClazzSetStringConverter(final RedisAccessor accessor, final Class clazz) { + super(accessor); + this.clazz = clazz; + } + + @Override + public Set convert(final RedisConnection connection, final Set value) { + final Function, Set> function = (data)->data == null ? null : + data.stream().map((val)->serializer.deserialize(val, clazz)) + .collect(Collectors.toCollection(LinkedHashSet::new)); + + if(isTransactionOrPipeline(connection)){ + return addSetConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class ClazzSetBinaryConverter extends AbstractSetBinaryConverter { + + private final Class clazz; + + public ClazzSetBinaryConverter(final RedisAccessor accessor, final Class clazz) { + super(accessor); + this.clazz = clazz; + } + + @Override + public Set convert(final RedisConnection connection, final Set value) { + final Function, Set> function = (data)->data == null ? null : + data.stream().map((val)->serializer.deserializeBytes(val, clazz)) + .collect(Collectors.toCollection(LinkedHashSet::new)); + + if(isTransactionOrPipeline(connection)){ + return addSetBinaryConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class TypeSetStringConverter extends AbstractSetStringConverter { + + private final TypeReference typeReference; + + public TypeSetStringConverter(final RedisAccessor accessor, final TypeReference typeReference) { + super(accessor); + this.typeReference = typeReference; + } + + @Override + public Set convert(final RedisConnection connection, final Set value) { + final Function, Set> function = (data)->data == null ? null : + data.stream().map((val)->serializer.deserialize(val, typeReference)) + .collect(Collectors.toCollection(LinkedHashSet::new)); + + if(isTransactionOrPipeline(connection)){ + return addSetConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class TypeSetBinaryConverter extends AbstractSetBinaryConverter { + + private final TypeReference typeReference; + + public TypeSetBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference) { + super(accessor); + this.typeReference = typeReference; + } + + @Override + public Set convert(final RedisConnection connection, final Set value) { + final Function, Set> function = (data)->data == null ? null : + data.stream().map((val)->serializer.deserializeBytes(val, typeReference)) + .collect(Collectors.toCollection(LinkedHashSet::new)); + + if(isTransactionOrPipeline(connection)){ + return addSetBinaryConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + abstract class AbstractMapStringConverter extends AbstractConverter, Map> { + + public AbstractMapStringConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + abstract class AbstractMapBinaryConverter extends AbstractConverter, Map> { + + public AbstractMapBinaryConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + final class SimpleMapStringConverter extends AbstractMapStringConverter { + + public SimpleMapStringConverter(final RedisAccessor accessor) { + super(accessor); + } + + @Override + public Map convert(final RedisConnection connection, final Map value) { + final Function, Map> function = (data)->data == null ? null : + Maps.map(data, (key)->key, serializer::deserialize); + + if(isTransactionOrPipeline(connection)){ + return addMapConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class SimpleMapBinaryConverter extends AbstractMapBinaryConverter { + + public SimpleMapBinaryConverter(final RedisAccessor accessor) { + super(accessor); + } + + @Override + public Map convert(final RedisConnection connection, final Map value) { + final Function, Map> function = (data)->data == null ? null : + Maps.map(data, (key)->key, serializer::deserializeBytes); + + if(isTransactionOrPipeline(connection)){ + return addMapBinaryConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class ClazzMapStringConverter extends AbstractMapStringConverter { + + private final Class clazz; + + public ClazzMapStringConverter(final RedisAccessor accessor, final Class clazz) { + super(accessor); + this.clazz = clazz; + } + + @Override + public Map convert(final RedisConnection connection, final Map value) { + final Function, Map> function = (data)->data == null ? null : + Maps.map(data, (key)->key, (val)->serializer.deserialize(val, clazz)); + + if(isTransactionOrPipeline(connection)){ + return addMapConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class ClazzMapBinaryConverter extends AbstractMapBinaryConverter { + + private final Class clazz; + + public ClazzMapBinaryConverter(final RedisAccessor accessor, final Class clazz) { + super(accessor); + this.clazz = clazz; + } + + @Override + public Map convert(final RedisConnection connection, final Map value) { + final Function, Map> function = (data)->data == null ? null : + Maps.map(data, (key)->key, (val)->serializer.deserializeBytes(val, clazz)); + + if(isTransactionOrPipeline(connection)){ + return addMapBinaryConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class TypeMapStringConverter extends AbstractMapStringConverter { + + private final TypeReference typeReference; + + public TypeMapStringConverter(final RedisAccessor accessor, final TypeReference typeReference) { + super(accessor); + this.typeReference = typeReference; + } + + @Override + public Map convert(final RedisConnection connection, final Map value) { + final Function, Map> function = (data)->data == null ? null : + Maps.map(data, (key)->key, (val)->serializer.deserialize(val, typeReference)); + + if(isTransactionOrPipeline(connection)){ + return addMapConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class TypeMapBinaryConverter extends AbstractMapBinaryConverter { + + private final TypeReference typeReference; + + public TypeMapBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference) { + super(accessor); + this.typeReference = typeReference; + } + + @Override + public Map convert(final RedisConnection connection, final Map value) { + final Function, Map> function = (data)->data == null ? null : + Maps.map(data, (key)->key, (val)->serializer.deserializeBytes(val, typeReference)); + + if(isTransactionOrPipeline(connection)){ + return addMapBinaryConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + abstract class AbstractScanResultConverter extends AbstractConverter, ScanResult> { + + public AbstractScanResultConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + abstract class AbstractScanResultMapStringConverter + extends AbstractScanResultConverter, Map> { + + public AbstractScanResultMapStringConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + abstract class AbstractScanResultListStringConverter extends AbstractScanResultConverter, List> { + + public AbstractScanResultListStringConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + abstract class AbstractScanResultListBinaryConverter extends AbstractScanResultConverter, List> { + + public AbstractScanResultListBinaryConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + final class SimpleScanResultListStringConverter extends AbstractScanResultListStringConverter { + + public SimpleScanResultListStringConverter(final RedisAccessor accessor) { + super(accessor); + } + + @Override + public ScanResult> convert(final RedisConnection connection, final ScanResult> value) { + final Function>, ScanResult>> function = (scanResult)->{ + if(scanResult.getResults() == null){ + return new ScanResult<>(scanResult.getCursor(), null); + }else{ + final List result = new ArrayList<>(scanResult.getResults().size()); + + for(String str : scanResult.getResults()){ + result.add(serializer.deserialize(str)); + } + + return new ScanResult<>(scanResult.getCursor(), result); + } + }; + + if(isTransactionOrPipeline(connection)){ + return addScanResultConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class SimpleScanResultListBinaryConverter extends AbstractScanResultListBinaryConverter { + + public SimpleScanResultListBinaryConverter(final RedisAccessor accessor) { + super(accessor); + } + + @Override + public ScanResult> convert(final RedisConnection connection, final ScanResult> value) { + final Function>, ScanResult>> function = (scanResult)->{ + if(scanResult.getResults() == null){ + return new ScanResult<>(scanResult.getCursor(), null); + }else{ + final List result = new ArrayList<>(scanResult.getResults().size()); + + for(byte[] b : scanResult.getResults()){ + result.add(serializer.deserializeBytes(b)); + } + + return new ScanResult<>(scanResult.getCursor(), result); + } + }; + + if(isTransactionOrPipeline(connection)){ + return addScanResultConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class ClazzScanResultListStringConverter extends AbstractScanResultListStringConverter { + + private final Class clazz; + + public ClazzScanResultListStringConverter(final RedisAccessor accessor, final Class clazz) { + super(accessor); + this.clazz = clazz; + } + + @Override + public ScanResult> convert(final RedisConnection connection, final ScanResult> value) { + final Function>, ScanResult>> function = (scanResult)->{ + final List result = value.getResults() == null ? null : value.getResults().stream() + .map((val)->serializer.deserialize(val, clazz)).collect(Collectors.toList()); + return new ScanResult<>(scanResult.getCursor(), result); + }; + + if(isTransactionOrPipeline(connection)){ + return addScanResultConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class ClazzScanResultListBinaryConverter extends AbstractScanResultListBinaryConverter { + + private final Class clazz; + + public ClazzScanResultListBinaryConverter(final RedisAccessor accessor, final Class clazz) { + super(accessor); + this.clazz = clazz; + } + + @Override + public ScanResult> convert(final RedisConnection connection, final ScanResult> value) { + final Function>, ScanResult>> function = (scanResult)->{ + final List result = value.getResults() == null ? null : value.getResults().stream() + .map((val)->serializer.deserializeBytes(val, clazz)).collect(Collectors.toList()); + return new ScanResult<>(scanResult.getCursor(), result); + }; + + if(isTransactionOrPipeline(connection)){ + return addScanResultConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class TypeScanResultListStringConverter extends AbstractScanResultListStringConverter { + + private final TypeReference typeReference; + + public TypeScanResultListStringConverter(final RedisAccessor accessor, final TypeReference typeReference) { + super(accessor); + this.typeReference = typeReference; + } + + @Override + public ScanResult> convert(final RedisConnection connection, final ScanResult> value) { + final Function>, ScanResult>> function = (scanResult)->{ + final List result = value.getResults() == null ? null : value.getResults().stream() + .map((val)->serializer.deserialize(val, typeReference)).collect(Collectors.toList()); + return new ScanResult<>(scanResult.getCursor(), result); + }; + + if(isTransactionOrPipeline(connection)){ + return addScanResultConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class TypeScanResultListBinaryConverter extends AbstractScanResultListBinaryConverter { + + private final TypeReference typeReference; + + public TypeScanResultListBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference) { + super(accessor); + this.typeReference = typeReference; + } + + @Override + public ScanResult> convert(final RedisConnection connection, final ScanResult> value) { + final Function>, ScanResult>> function = (scanResult)->{ + final List result = value.getResults() == null ? null : value.getResults().stream() + .map((val)->serializer.deserializeBytes(val, typeReference)).collect(Collectors.toList()); + return new ScanResult<>(scanResult.getCursor(), result); + }; + + if(isTransactionOrPipeline(connection)){ + return addScanResultConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + abstract class AbstractScanResultMapBinaryConverter + extends AbstractScanResultConverter, Map> { + + public AbstractScanResultMapBinaryConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + final class SimpleScanResultMapStringConverter extends AbstractScanResultMapStringConverter { + + public SimpleScanResultMapStringConverter(final RedisAccessor accessor) { + super(accessor); + } + + @Override + public ScanResult> convert(final RedisConnection connection, + final ScanResult> value) { + final Function>, ScanResult>> function = (scanResult)->{ + if(scanResult.getResults() == null){ + return new ScanResult<>(scanResult.getCursor(), null); + }else{ + final Map result = new LinkedHashMap<>(scanResult.getResults().size()); + + scanResult.getResults().forEach((k, v)->{ + result.put(k, serializer.deserialize(v)); + }); + + return new ScanResult<>(scanResult.getCursor(), result); + } + }; + + if(isTransactionOrPipeline(connection)){ + return addScanResultConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class SimpleScanResultMapBinaryConverter extends AbstractScanResultMapBinaryConverter { + + public SimpleScanResultMapBinaryConverter(final RedisAccessor accessor) { + super(accessor); + } + + @Override + public ScanResult> convert(final RedisConnection connection, + final ScanResult> value) { + final Function>, ScanResult>> function = (scanResult)->{ + if(scanResult.getResults() == null){ + return new ScanResult<>(scanResult.getCursor(), null); + }else{ + final Map result = new LinkedHashMap<>(scanResult.getResults().size()); + + scanResult.getResults().forEach((k, v)->{ + result.put(k, serializer.deserializeBytes(v)); + }); + + return new ScanResult<>(scanResult.getCursor(), result); + } + }; + + if(isTransactionOrPipeline(connection)){ + return addScanResultConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class ClazzScanResultMapStringConverter extends AbstractScanResultMapStringConverter { + + private final Class clazz; + + public ClazzScanResultMapStringConverter(final RedisAccessor accessor, final Class clazz) { + super(accessor); + this.clazz = clazz; + } + + @Override + public ScanResult> convert(final RedisConnection connection, + final ScanResult> value) { + final Function>, ScanResult>> function = (scanResult)->{ + final Map result = scanResult.getResults() == null ? null : Maps.map(value.getResults(), + (key)->key, (val)->serializer.deserialize(val, clazz)); + return new ScanResult<>(scanResult.getCursor(), result); + }; + + if(isTransactionOrPipeline(connection)){ + return addScanResultConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class ClazzScanResultMapBinaryConverter extends AbstractScanResultMapBinaryConverter { + + private final Class clazz; + + public ClazzScanResultMapBinaryConverter(final RedisAccessor accessor, final Class clazz) { + super(accessor); + this.clazz = clazz; + } + + @Override + public ScanResult> convert(final RedisConnection connection, + final ScanResult> value) { + final Function>, ScanResult>> function = (scanResult)->{ + final Map result = scanResult.getResults() == null ? null : Maps.map(value.getResults(), + (key)->key, (val)->serializer.deserializeBytes(val, clazz)); + return new ScanResult<>(scanResult.getCursor(), result); + }; + + if(isTransactionOrPipeline(connection)){ + return addScanResultConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class TypeScanResultMapStringConverter extends AbstractScanResultMapStringConverter { + + private final TypeReference typeReference; + + public TypeScanResultMapStringConverter(final RedisAccessor accessor, final TypeReference typeReference) { + super(accessor); + this.typeReference = typeReference; + } + + @Override + public ScanResult> convert(final RedisConnection connection, + final ScanResult> value) { + final Function>, ScanResult>> function = (scanResult)->{ + final Map result = scanResult.getResults() == null ? null : Maps.map(value.getResults(), + (key)->key, (val)->serializer.deserialize(val, typeReference)); + return new ScanResult<>(scanResult.getCursor(), result); + }; + + if(isTransactionOrPipeline(connection)){ + return addScanResultConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class TypeScanResultMapBinaryConverter extends AbstractScanResultMapBinaryConverter { + + private final TypeReference typeReference; + + public TypeScanResultMapBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference) { + super(accessor); + this.typeReference = typeReference; + } + + @Override + public ScanResult> convert(final RedisConnection connection, + final ScanResult> value) { + final Function>, ScanResult>> function = (scanResult)->{ + final Map result = scanResult.getResults() == null ? null : Maps.map(value.getResults(), + (key)->key, (val)->serializer.deserializeBytes(val, typeReference)); + return new ScanResult<>(scanResult.getCursor(), result); + }; + + if(isTransactionOrPipeline(connection)){ + return addScanResultConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + abstract class AbstractKeyValueListConverter + extends AbstractConverter>, List>> { + + public AbstractKeyValueListConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + abstract class AbstractKeyValueListStringConverter + extends AbstractKeyValueListConverter { + + public AbstractKeyValueListStringConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + abstract class AbstractKeyValueListBinaryConverter + extends AbstractKeyValueListConverter { + + public AbstractKeyValueListBinaryConverter(final RedisAccessor accessor) { + super(accessor); + } + + } + + final class SimpleKeyValueListStringConverter extends AbstractKeyValueListStringConverter { + + public SimpleKeyValueListStringConverter(final RedisAccessor accessor) { + super(accessor); + } + + @Override + public List> convert(final RedisConnection connection, + final List> value) { + final Function>, List>> function = (data)->{ + if(data == null){ + return null; + }else{ + final List> result = new ArrayList<>(data.size()); + + for(KeyValue r : data){ + result.add(new KeyValue<>(r.getKey(), serializer.deserialize(r.getValue()))); + } + + return result; + } + }; + + if(isTransactionOrPipeline(connection)){ + return addKeyValueConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class SimpleKeyValueListBinaryConverter extends AbstractKeyValueListBinaryConverter { + + public SimpleKeyValueListBinaryConverter(final RedisAccessor accessor) { + super(accessor); + } + + @Override + public List> convert(final RedisConnection connection, + final List> value) { + final Function>, List>> function = (data)->{ + if(data == null){ + return null; + }else{ + final List> result = new ArrayList<>(data.size()); + + for(KeyValue r : data){ + result.add(new KeyValue<>(r.getKey(), serializer.deserializeBytes(r.getValue()))); + } + + return result; + } + }; + + if(isTransactionOrPipeline(connection)){ + return addKeyValueConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class ClazzKeyValueListStringConverter extends AbstractKeyValueListStringConverter { + + private final Class clazz; + + public ClazzKeyValueListStringConverter(final RedisAccessor accessor, final Class clazz) { + super(accessor); + this.clazz = clazz; + } + + @Override + public List> convert(final RedisConnection connection, + final List> value) { + final Function>, List>> function = (data)->{ + if(data == null){ + return null; + }else{ + final List> result = new ArrayList<>(data.size()); + + for(KeyValue r : data){ + result.add(new KeyValue<>(r.getKey(), serializer.deserialize(r.getValue(), clazz))); + } + + return result; + } + }; + + if(isTransactionOrPipeline(connection)){ + return addKeyValueConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class ClazzKeyValueListBinaryConverter extends AbstractKeyValueListBinaryConverter { + + private final Class clazz; + + public ClazzKeyValueListBinaryConverter(final RedisAccessor accessor, final Class clazz) { + super(accessor); + this.clazz = clazz; + } + + @Override + public List> convert(final RedisConnection connection, + final List> value) { + final Function>, List>> function = (data)->{ + if(data == null){ + return null; + }else{ + final List> result = new ArrayList<>(data.size()); + + for(KeyValue r : data){ + result.add(new KeyValue<>(r.getKey(), serializer.deserializeBytes(r.getValue(), clazz))); + } + + return result; + } + }; + + if(isTransactionOrPipeline(connection)){ + return addKeyValueConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class TypeKeyValueListStringConverter extends AbstractKeyValueListStringConverter { + + private final TypeReference typeReference; + + public TypeKeyValueListStringConverter(final RedisAccessor accessor, final TypeReference typeReference) { + super(accessor); + this.typeReference = typeReference; + } + + @Override + public List> convert(final RedisConnection connection, + final List> value) { + final Function>, List>> function = (data)->{ + if(data == null){ + return null; + }else{ + final List> result = new ArrayList<>(data.size()); + + for(KeyValue r : data){ + result.add(new KeyValue<>(r.getKey(), serializer.deserialize(r.getValue(), typeReference))); + } + + return result; + } + }; + + if(isTransactionOrPipeline(connection)){ + return addKeyValueConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + + final class TypeKeyValueListBinaryConverter extends AbstractKeyValueListBinaryConverter { + + private final TypeReference typeReference; + + public TypeKeyValueListBinaryConverter(final RedisAccessor accessor, final TypeReference typeReference) { + super(accessor); + this.typeReference = typeReference; + } + + @Override + public List> convert(final RedisConnection connection, + final List> value) { + final Function>, List>> function = (data)->{ + if(data == null){ + return null; + }else{ + final List> result = new ArrayList<>(data.size()); + + for(KeyValue r : data){ + result.add( + new KeyValue<>(r.getKey(), serializer.deserializeBytes(r.getValue(), typeReference))); + } + + return result; + } + }; + + if(isTransactionOrPipeline(connection)){ + return addKeyValueConverter(index, function); + }else{ + return function.apply(value); + } + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/RedisAccessor.java b/buession-redis/src/main-tmp/java/com/buession/redis/RedisAccessor.java new file mode 100644 index 000000000..d3b0d4224 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/RedisAccessor.java @@ -0,0 +1,310 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis; + +import com.buession.core.utils.Assert; +import com.buession.redis.client.RedisClient; +import com.buession.redis.client.connection.JedisConnectionFactory; +import com.buession.redis.client.connection.LettuceConnectionFactory; +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.client.connection.RedisConnectionFactory; +import com.buession.redis.client.connection.RedisConnectionUtils; +import com.buession.redis.client.connection.datasource.DataSource; +import com.buession.redis.client.connection.datasource.jedis.JedisClusterDataSource; +import com.buession.redis.client.connection.datasource.jedis.JedisDataSource; +import com.buession.redis.client.connection.datasource.jedis.JedisSentinelDataSource; +import com.buession.redis.client.connection.datasource.lettuce.LettuceClusterDataSource; +import com.buession.redis.client.connection.datasource.lettuce.LettuceDataSource; +import com.buession.redis.client.connection.datasource.lettuce.LettuceSentinelDataSource; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.Options; +import com.buession.redis.core.SessionCallback; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.exception.RedisException; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.serializer.JacksonJsonSerializer; +import com.buession.redis.serializer.Serializer; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.lang.Nullable; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.function.Function; + +/** + * Base class for {@link RedisTemplate} defining common properties. Not intended to be used directly. + * + * @author Yong.Teng + */ +public abstract class RedisAccessor implements InitializingBean, AutoCloseable { + + protected final static Options DEFAULT_OPTIONS = new Options(); + + /** + * 默认序列化 + */ + protected final static Serializer DEFAULT_SERIALIZER = new JacksonJsonSerializer(); + + protected Options options = DEFAULT_OPTIONS; + + /** + * 序列化 + */ + protected Serializer serializer; + + protected DataSource dataSource; + + protected RedisConnectionFactory connectionFactory; + + protected boolean enableTransactionSupport = false; + + protected RedisClient redisClient; + + protected final static ThreadLocal>> txConverters = new ThreadLocal<>(); + + protected final static ThreadLocal index = new ThreadLocal<>(); + + static { + DEFAULT_OPTIONS.setSerializer(DEFAULT_SERIALIZER); + index.set(-1); + } + + /** + * 构造函数 + */ + public RedisAccessor() { + } + + /** + * 构造函数 + * + * @param dataSource + * 数据源 + */ + public RedisAccessor(DataSource dataSource) { + setDataSource(dataSource); + } + + public Options getOptions() { + return options; + } + + public void setOptions(Options options) { + this.options = options; + } + + @Nullable + public RedisConnectionFactory getConnectionFactory() { + return connectionFactory; + } + + @Nullable + public DataSource getDataSource() { + return dataSource; + } + + public void setDataSource(DataSource dataSource) { + this.dataSource = dataSource; + } + + @Override + public void afterPropertiesSet() throws RedisException { + Assert.isNull(getDataSource(), "DataSource is required"); + + Options options = getOptions(); + if(options != null){ + serializer = options.getSerializer(); + enableTransactionSupport = options.isEnableTransactionSupport(); + } + if(serializer == null){ + serializer = DEFAULT_SERIALIZER; + } + + if(connectionFactory == null){ + DataSource dataSource = getDataSource(); + + if(dataSource instanceof LettuceDataSource){ + connectionFactory = new LettuceConnectionFactory((LettuceDataSource) dataSource); + }else if(dataSource instanceof JedisDataSource){ + connectionFactory = new JedisConnectionFactory((JedisDataSource) dataSource); + }else{ + Assert.isNull(getDataSource(), "DataSource is required"); + } + } + } + + public void pipeline() { + RedisConnection connection = fetchConnection(); + + RedisClient client = doGetRedisClient(); + client.setConnection(connection); + client.execute(new com.buession.redis.core.Command() { + + @Override + public Command getCommand() { + return null; + } + + @Override + public SubCommand getSubCommand() { + return null; + } + + @Override + public Pipeline execute() throws RedisException { + return client.getConnection().openPipeline(); + } + + @Override + public Pipeline run(final CommandArguments arguments) throws RedisException { + return execute(); + } + + }); + } + + public R execute(final SessionCallback callback) throws RedisException { + Assert.isNull(callback, "callback cloud not be null."); + + RedisConnection connection = fetchRequiredConnection(); + + RedisClient client = doGetRedisClient(); + client.setConnection(connection); + + if(isMulti(connection)){ + index.set(index.get() + 1); + } + + try{ + return callback.execute(client); + }finally{ + RedisConnectionUtils.releaseConnection(connectionFactory, connection, enableTransactionSupport); + } + } + + public TR execute(final SessionCallback callback, final Converter converter) + throws RedisException { + Assert.isNull(callback, "callback cloud not be null."); + + RedisConnection connection = fetchRequiredConnection(); + + RedisClient client = doGetRedisClient(); + client.setConnection(connection); + + if(isMulti(connection)){ + index.set(index.get() + 1); + } + + try{ + return converter.convert(connection, callback.execute(client)); + }finally{ + RedisConnectionUtils.releaseConnection(connectionFactory, connection, enableTransactionSupport); + } + } + + @Override + public void close() throws Exception { + // empty + } + + protected RedisConnection fetchConnection() { + return RedisConnectionUtils.bindConnection(connectionFactory, enableTransactionSupport); + } + + protected RedisConnection fetchRequiredConnection() { + checkInitialized(); + return fetchConnection(); + } + + protected RedisClient doGetRedisClient() throws RedisException { + if(redisClient == null){ + DataSource dataSource = getDataSource(); + + if(dataSource instanceof JedisDataSource){ + redisClient = new JedisStandaloneClient(); + }else if(dataSource instanceof JedisSentinelDataSource){ + redisClient = new JedisSentinelClient(); + }else if(dataSource instanceof JedisClusterDataSource){ + redisClient = new JedisClusterClient(); + }else if(dataSource instanceof LettuceDataSource){ + redisClient = new LettuceStandaloneClient(); + }else if(dataSource instanceof LettuceSentinelDataSource){ + redisClient = new LettuceSentinelClient(); + }else if(dataSource instanceof LettuceClusterDataSource){ + redisClient = new LettuceClusterClient(); + }else{ + throw new RedisException("Cloud not initialize RedisClient for: " + dataSource); + } + } + + return redisClient; + } + + protected final void checkInitialized() { + Assert.isNull(connectionFactory, ()->new RedisException( + "RedisConnectionFactory is not initialized. You can call the afterPropertiesSet method for initialize.")); + } + + protected boolean isTransaction(final RedisConnection connection) { + return connection.isTransaction(); + } + + protected boolean isPipeline(final RedisConnection connection) { + return connection.isPipeline(); + } + + @Deprecated + protected boolean isTransactionOrPipeline(final RedisConnection connection) { + return isMulti(connection); + } + + protected boolean isMulti(final RedisConnection connection) { + return isTransaction(connection) || isPipeline(connection); + } + + protected static Map> getTxConverters() { + Map> txResult = txConverters.get(); + + if(txResult == null){ + txResult = new LinkedHashMap<>(16, 0.8F); + txConverters.set(txResult); + } + + return txResult; + } + + protected void resetTransactionOrPipeline() { + index.remove(); + txConverters.remove(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/RedisTemplate.java b/buession-redis/src/main-tmp/java/com/buession/redis/RedisTemplate.java new file mode 100644 index 000000000..9d9662aab --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/RedisTemplate.java @@ -0,0 +1,2846 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis; + +import com.buession.core.type.TypeReference; +import com.buession.core.validator.Validate; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.connection.datasource.DataSource; +import com.buession.redis.core.Aggregate; +import com.buession.redis.core.Direction; +import com.buession.redis.core.GtLt; +import com.buession.redis.core.ListPosition; +import com.buession.redis.core.NxXx; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.args.GetExArgument; +import com.buession.redis.core.command.args.SetArgument; +import com.buession.redis.core.operations.*; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * Redis 命令操作封装扩展,可序列化对象和反序列化为对象 + * + * @author Yong.Teng + * @see BaseRedisTemplate + */ +public class RedisTemplate extends BaseRedisTemplate implements AclOperations, BitMapOperations, ClusterOperations, + ConnectionOperations, GenericOperations, GeoOperations, HashOperations, HyperLogLogOperations, KeyOperations, + ListOperations, PubSubOperations, ScriptingOperations, ServerOperations, SetOperations, SortedSetOperations, + StreamOperations, StringOperations, TransactionOperations { + + /** + * 构造函数 + */ + public RedisTemplate() { + super(); + } + + /** + * 构造函数 + * + * @param dataSource + * 数据源 + */ + public RedisTemplate(DataSource dataSource) { + super(dataSource); + } + + @Override + public V hGetObject(final String key, final String field) { + return execute((client)->client.hashOperations().hGet(rawKey(key), field), + new Converter.SimpleStringConverter<>(this)); + } + + @Override + public V hGetObject(final byte[] key, final byte[] field) { + return execute((client)->client.hashOperations().hGet(rawKey(key), field), + new Converter.SimpleBinaryConverter<>(this)); + } + + @Override + public V hGetObject(final String key, final String field, final Class clazz) { + return execute((client)->client.hashOperations().hGet(rawKey(key), field), + new Converter.ClazzStringConverter<>(this, clazz)); + } + + @Override + public V hGetObject(final byte[] key, final byte[] field, final Class clazz) { + return execute((client)->client.hashOperations().hGet(rawKey(key), field), + new Converter.ClazzBinaryConverter<>(this, clazz)); + } + + @Override + public V hGetObject(final String key, final String field, final TypeReference type) { + return execute((client)->client.hashOperations().hGet(rawKey(key), field), + new Converter.TypeStringConverter<>(this, type)); + } + + @Override + public V hGetObject(final byte[] key, final byte[] field, final TypeReference type) { + return execute((client)->client.hashOperations().hGet(rawKey(key), field), + new Converter.TypeBinaryConverter<>(this, type)); + } + + @Override + public Map hGetAllObject(final String key) { + return execute((client)->client.hashOperations().hGetAll(rawKey(key)), + new Converter.SimpleMapStringConverter<>(this)); + } + + @Override + public Map hGetAllObject(final byte[] key) { + return execute((client)->client.hashOperations().hGetAll(rawKey(key)), + new Converter.SimpleMapBinaryConverter<>(this)); + } + + @Override + public Map hGetAllObject(final String key, final Class clazz) { + return execute((client)->client.hashOperations().hGetAll(rawKey(key)), + new Converter.ClazzMapStringConverter<>(this, clazz)); + } + + @Override + public Map hGetAllObject(final byte[] key, final Class clazz) { + return execute((client)->client.hashOperations().hGetAll(rawKey(key)), + new Converter.ClazzMapBinaryConverter<>(this, clazz)); + } + + @Override + public Map hGetAllObject(final String key, final TypeReference type) { + return execute((client)->client.hashOperations().hGetAll(rawKey(key)), + new Converter.TypeMapStringConverter<>(this, type)); + } + + @Override + public Map hGetAllObject(final byte[] key, final TypeReference type) { + return execute((client)->client.hashOperations().hGetAll(rawKey(key)), + new Converter.TypeMapBinaryConverter<>(this, type)); + } + + @Override + public List hMGetObject(final String key, final String... fields) { + return execute((client)->client.hashOperations().hMGet(rawKey(key), fields), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List hMGetObject(final byte[] key, final byte[]... fields) { + return execute((client)->client.hashOperations().hMGet(rawKey(key), fields), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List hMGetObject(final String key, final String[] fields, final Class clazz) { + return execute((client)->client.hashOperations().hMGet(rawKey(key), fields), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List hMGetObject(final byte[] key, final byte[][] fields, final Class clazz) { + return execute((client)->client.hashOperations().hMGet(rawKey(key), fields), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List hMGetObject(final String key, final String[] fields, final TypeReference type) { + return execute((client)->client.hashOperations().hMGet(rawKey(key), fields), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List hMGetObject(final byte[] key, final byte[][] fields, final TypeReference type) { + return execute((client)->client.hashOperations().hMGet(rawKey(key), fields), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public Status hMSet(final String key, final KeyValue... data) { + final Class clazz = data[0].getValue().getClass(); + Map temp = new LinkedHashMap<>(data.length); + + if(clazz == String.class){ + for(KeyValue kv : data){ + temp.put(kv.getKey(), (String) kv.getValue()); + } + }else{ + for(KeyValue kv : data){ + temp.put(kv.getKey(), serializer.serialize(kv.getValue())); + } + } + + return hMSet(key, temp); + } + + @Override + public Status hMSet(final byte[] key, final KeyValue... data) { + final Class clazz = data[0].getValue().getClass(); + Map temp = new LinkedHashMap<>(data.length); + + if(clazz == byte[].class){ + for(KeyValue kv : data){ + temp.put(kv.getKey(), (byte[]) kv.getValue()); + } + }else{ + for(KeyValue kv : data){ + temp.put(kv.getKey(), serializer.serializeAsBytes(kv.getValue())); + } + } + + return hMSet(key, temp); + } + + @Override + public List> hRandFieldWithValuesObject(final String key, final int count) { + return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count), + new Converter.SimpleKeyValueListStringConverter<>(this)); + } + + @Override + public List> hRandFieldWithValuesObject(final byte[] key, final int count) { + return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count), + new Converter.SimpleKeyValueListBinaryConverter<>(this)); + } + + @Override + public List> hRandFieldWithValuesObject(final String key, int count, + final Class clazz) { + return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count), + new Converter.ClazzKeyValueListStringConverter<>(this, clazz)); + } + + @Override + public List> hRandFieldWithValuesObject(final byte[] key, final int count, + final Class clazz) { + return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count), + new Converter.ClazzKeyValueListBinaryConverter<>(this, clazz)); + } + + @Override + public List> hRandFieldWithValuesObject(final String key, final int count, + final TypeReference type) { + return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count), + new Converter.TypeKeyValueListStringConverter<>(this, type)); + } + + @Override + public List> hRandFieldWithValuesObject(final byte[] key, final int count, + final TypeReference type) { + return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count), + new Converter.TypeKeyValueListBinaryConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final String key, final long cursor) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), + new Converter.SimpleScanResultMapStringConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final long cursor) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), + new Converter.SimpleScanResultMapBinaryConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final String key, final long cursor, final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), + new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final long cursor, final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), + new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final String key, final long cursor, + final TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), + new Converter.TypeScanResultMapStringConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final long cursor, + final TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), + new Converter.TypeScanResultMapBinaryConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final String key, final String cursor) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), + new Converter.SimpleScanResultMapStringConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final byte[] cursor) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), + new Converter.SimpleScanResultMapBinaryConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final String key, final String cursor, final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), + new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), + new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final String key, final String cursor, + final TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), + new Converter.TypeScanResultMapStringConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final byte[] cursor, + final TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), + new Converter.TypeScanResultMapBinaryConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final String key, final long cursor, final String pattern) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), + new Converter.SimpleScanResultMapStringConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), + new Converter.SimpleScanResultMapBinaryConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final String key, final long cursor, final String pattern, + final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), + new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern, + final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), + new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final String key, final long cursor, final String pattern, + final TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), + new Converter.TypeScanResultMapStringConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern, + final TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), + new Converter.TypeScanResultMapBinaryConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final String key, final String cursor, final String pattern) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), + new Converter.SimpleScanResultMapStringConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), + new Converter.SimpleScanResultMapBinaryConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final String key, final String cursor, final String pattern, + final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), + new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), + new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final String key, final String cursor, final String pattern, + final TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), + new Converter.TypeScanResultMapStringConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), + new Converter.TypeScanResultMapBinaryConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final String key, final long cursor, final int count) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), + new Converter.SimpleScanResultMapStringConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final long cursor, final int count) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), + new Converter.SimpleScanResultMapBinaryConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final String key, final long cursor, final int count, + final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), + new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final long cursor, final int count, + final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), + new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final String key, final long cursor, int count, + TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), + new Converter.TypeScanResultMapStringConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final long cursor, final int count, + final TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), + new Converter.TypeScanResultMapBinaryConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final String key, final String cursor, final int count) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), + new Converter.SimpleScanResultMapStringConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final int count) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), + new Converter.SimpleScanResultMapBinaryConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final String key, final String cursor, final int count, + final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), + new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final int count, + final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), + new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final String key, final String cursor, final int count, + final TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), + new Converter.TypeScanResultMapStringConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final int count, + final TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), + new Converter.TypeScanResultMapBinaryConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final String key, final long cursor, final String pattern, + final int count) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), + new Converter.SimpleScanResultMapStringConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern, + final int count) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), + new Converter.SimpleScanResultMapBinaryConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final String key, final long cursor, final String pattern, + final int count, final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), + new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern, + final int count, final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), + new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final String key, final long cursor, final String pattern, + final int count, final TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), + new Converter.TypeScanResultMapStringConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern, + final int count, final TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), + new Converter.TypeScanResultMapBinaryConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final String key, final String cursor, final String pattern, + final int count) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), + new Converter.SimpleScanResultMapStringConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), + new Converter.SimpleScanResultMapBinaryConverter<>(this)); + } + + @Override + public ScanResult> hScanObject(final String key, final String cursor, final String pattern, + final int count, final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), + new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count, final Class clazz) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), + new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> hScanObject(final String key, final String cursor, final String pattern, + final int count, final TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), + new Converter.TypeScanResultMapStringConverter<>(this, type)); + } + + @Override + public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count, final TypeReference type) { + return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), + new Converter.TypeScanResultMapBinaryConverter<>(this, type)); + } + + @Override + public Long hSet(final String key, final String field, final V value) { + return hSet(key, field, serializer.serialize(value)); + } + + @Override + public Long hSet(final byte[] key, final byte[] field, final V value) { + return hSet(key, field, serializer.serializeAsBytes(value)); + } + + @Override + public Status hSetNx(final String key, final String field, final V value) { + return hSetNx(key, field, serializer.serialize(value)); + } + + @Override + public Status hSetNx(final byte[] key, final byte[] field, final V value) { + return hSetNx(key, field, serializer.serializeAsBytes(value)); + } + + @Override + public List hValsObject(final String key) { + return execute((client)->client.hashOperations().hVals(rawKey(key)), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List hValsObject(final byte[] key) { + return execute((client)->client.hashOperations().hVals(rawKey(key)), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List hValsObject(final String key, final Class clazz) { + return execute((client)->client.hashOperations().hVals(rawKey(key)), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List hValsObject(final byte[] key, final Class clazz) { + return execute((client)->client.hashOperations().hVals(rawKey(key)), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List hValsObject(final String key, final TypeReference type) { + return execute((client)->client.hashOperations().hVals(rawKey(key)), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List hValsObject(final byte[] key, final TypeReference type) { + return execute((client)->client.hashOperations().hVals(rawKey(key)), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public V lIndexObject(final String key, final long index) { + return execute((client)->client.listOperations().lIndex(rawKey(key), index), + new Converter.SimpleStringConverter<>(this)); + } + + @Override + public V lIndexObject(final byte[] key, final long index) { + return execute((client)->client.listOperations().lIndex(rawKey(key), index), + new Converter.SimpleBinaryConverter<>(this)); + } + + @Override + public V lIndexObject(final String key, final long index, final Class clazz) { + return execute((client)->client.listOperations().lIndex(rawKey(key), index), + new Converter.ClazzStringConverter<>(this, clazz)); + } + + @Override + public V lIndexObject(final byte[] key, final long index, final Class clazz) { + return execute((client)->client.listOperations().lIndex(rawKey(key), index), + new Converter.ClazzBinaryConverter<>(this, clazz)); + } + + @Override + public V lIndexObject(final String key, final long index, final TypeReference type) { + return execute((client)->client.listOperations().lIndex(rawKey(key), index), + new Converter.TypeStringConverter<>(this, type)); + } + + @Override + public V lIndexObject(final byte[] key, final long index, final TypeReference type) { + return execute((client)->client.listOperations().lIndex(rawKey(key), index), + new Converter.TypeBinaryConverter<>(this, type)); + } + + @Override + public Long lInsert(final String key, final ListPosition position, final V pivot, final V value) { + return lInsert(key, position, serializer.serialize(pivot), serializer.serialize(value)); + } + + @Override + public Long lInsert(final byte[] key, final ListPosition position, final V pivot, final V value) { + return lInsert(key, position, serializer.serializeAsBytes(pivot), serializer.serializeAsBytes(value)); + } + + @Override + public Status lSet(final String key, final long index, final V value) { + return lSet(key, index, serializer.serialize(value)); + } + + @Override + public Status lSet(final byte[] key, final long index, final V value) { + return lSet(key, index, serializer.serializeAsBytes(value)); + } + + @Override + public List lRangeObject(final String key, final long start, final long end) { + return execute((client)->client.listOperations().lRange(rawKey(key), start, end), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List lRangeObject(final byte[] key, final long start, final long end) { + return execute((client)->client.listOperations().lRange(rawKey(key), start, end), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List lRangeObject(final String key, final long start, final long end, final Class clazz) { + return execute((client)->client.listOperations().lRange(rawKey(key), start, end), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List lRangeObject(final byte[] key, final long start, final long end, final Class clazz) { + return execute((client)->client.listOperations().lRange(rawKey(key), start, end), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List lRangeObject(final String key, final long start, final long end, final TypeReference type) { + return execute((client)->client.listOperations().lRange(rawKey(key), start, end), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List lRangeObject(final byte[] key, final long start, final long end, final TypeReference type) { + return execute((client)->client.listOperations().lRange(rawKey(key), start, end), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public V lMoveObject(final String key, final String destKey, final Direction from, final Direction to) { + return execute((client)->client.listOperations().lMove(rawKey(destKey), rawKey(destKey), from, to), + new Converter.SimpleStringConverter<>(this)); + } + + @Override + public V lMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { + return execute((client)->client.listOperations().lMove(rawKey(destKey), rawKey(destKey), from, to), + new Converter.SimpleBinaryConverter<>(this)); + } + + @Override + public V lMoveObject(final String key, final String destKey, final Direction from, final Direction to, + final Class clazz) { + return execute((client)->client.listOperations().lMove(rawKey(destKey), rawKey(destKey), from, to), + new Converter.ClazzStringConverter<>(this, clazz)); + } + + @Override + public V lMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final Class clazz) { + return execute((client)->client.listOperations().lMove(rawKey(destKey), rawKey(destKey), from, to), + new Converter.ClazzBinaryConverter<>(this, clazz)); + } + + @Override + public V lMoveObject(final String key, final String destKey, final Direction from, final Direction to, + final TypeReference type) { + return execute((client)->client.listOperations().lMove(rawKey(destKey), rawKey(destKey), from, to), + new Converter.TypeStringConverter<>(this, type)); + } + + @Override + public V lMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final TypeReference type) { + return execute((client)->client.listOperations().lMove(rawKey(destKey), rawKey(destKey), from, to), + new Converter.TypeBinaryConverter<>(this, type)); + } + + @Override + public V blMoveObject(final String key, final String destKey, final Direction from, final Direction to, + final int timeout) { + return execute((client)->client.listOperations().blMove(rawKey(destKey), rawKey(destKey), from, to, timeout), + new Converter.SimpleStringConverter<>(this)); + } + + @Override + public V blMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout) { + return execute((client)->client.listOperations().blMove(rawKey(destKey), rawKey(destKey), from, to, timeout), + new Converter.SimpleBinaryConverter<>(this)); + } + + @Override + public V blMoveObject(final String key, final String destKey, final Direction from, final Direction to, + final int timeout, final Class clazz) { + return execute((client)->client.listOperations().blMove(rawKey(destKey), rawKey(destKey), from, to, timeout), + new Converter.ClazzStringConverter<>(this, clazz)); + } + + @Override + public V blMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout, final Class clazz) { + return execute((client)->client.listOperations().blMove(rawKey(destKey), rawKey(destKey), from, to, timeout), + new Converter.ClazzBinaryConverter<>(this, clazz)); + } + + @Override + public V blMoveObject(final String key, final String destKey, final Direction from, final Direction to, + final int timeout, final TypeReference type) { + return execute((client)->client.listOperations().blMove(rawKey(destKey), rawKey(destKey), from, to, timeout), + new Converter.TypeStringConverter<>(this, type)); + } + + @Override + public V blMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout, final TypeReference type) { + return execute((client)->client.listOperations().blMove(rawKey(destKey), rawKey(destKey), from, to, timeout), + new Converter.TypeBinaryConverter<>(this, type)); + } + + @Override + public List blPopObject(final String[] keys, final int timeout) { + return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List blPopObject(final byte[][] keys, final int timeout) { + return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List blPopObject(final String[] keys, final int timeout, final Class clazz) { + return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List blPopObject(final byte[][] keys, final int timeout, final Class clazz) { + return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List blPopObject(final String[] keys, final int timeout, final TypeReference type) { + return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List blPopObject(final byte[][] keys, final int timeout, final TypeReference type) { + return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List brPopObject(final String[] keys, final int timeout) { + return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List brPopObject(final byte[][] keys, final int timeout) { + return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List brPopObject(final String[] keys, final int timeout, final Class clazz) { + return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List brPopObject(final byte[][] keys, final int timeout, final Class clazz) { + return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List brPopObject(final String[] keys, final int timeout, final TypeReference type) { + return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List brPopObject(final byte[][] keys, final int timeout, final TypeReference type) { + return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public V brPoplPushObject(final String key, final String destKey, final int timeout) { + return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout), + new Converter.SimpleStringConverter<>(this)); + } + + @Override + public V brPoplPushObject(final byte[] key, final byte[] destKey, final int timeout) { + return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout), + new Converter.SimpleBinaryConverter<>(this)); + } + + @Override + public V brPoplPushObject(final String key, final String destKey, final int timeout, final Class clazz) { + return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout), + new Converter.ClazzStringConverter<>(this, clazz)); + } + + @Override + public V brPoplPushObject(final byte[] key, final byte[] destKey, final int timeout, final Class clazz) { + return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout), + new Converter.ClazzBinaryConverter<>(this, clazz)); + } + + @Override + public V brPoplPushObject(final String key, final String destKey, final int timeout, + final TypeReference type) { + return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout), + new Converter.TypeStringConverter<>(this, type)); + } + + @Override + public V brPoplPushObject(final byte[] key, final byte[] destKey, final int timeout, + final TypeReference type) { + return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout), + new Converter.TypeBinaryConverter<>(this, type)); + } + + @Override + public V lPopObject(final String key) { + return execute((client)->client.listOperations().lPop(rawKey(key)), + new Converter.SimpleStringConverter<>(this)); + } + + @Override + public V lPopObject(final byte[] key) { + return execute((client)->client.listOperations().lPop(rawKey(key)), + new Converter.SimpleBinaryConverter<>(this)); + } + + @Override + public V lPopObject(final String key, final Class clazz) { + return execute((client)->client.listOperations().lPop(rawKey(key)), + new Converter.ClazzStringConverter<>(this, clazz)); + } + + @Override + public V lPopObject(final byte[] key, final Class clazz) { + return execute((client)->client.listOperations().lPop(rawKey(key)), + new Converter.ClazzBinaryConverter<>(this, clazz)); + } + + @Override + public V lPopObject(final String key, final TypeReference type) { + return execute((client)->client.listOperations().lPop(rawKey(key)), + new Converter.TypeStringConverter<>(this, type)); + } + + @Override + public V lPopObject(final byte[] key, final TypeReference type) { + return execute((client)->client.listOperations().lPop(rawKey(key)), + new Converter.TypeBinaryConverter<>(this, type)); + } + + @Override + public Long lPush(final String key, final V value) { + return lPush(key, serializer.serialize(value)); + } + + @Override + public Long lPush(final byte[] key, final V value) { + return lPush(key, serializer.serializeAsBytes(value)); + } + + @Override + public Long lPush(final String key, final V... values) { + return lPush(key, serializer.serialize(values)); + } + + @Override + public Long lPush(final byte[] key, final V... values) { + return lPush(key, serializer.serializeAsBytes(values)); + } + + @Override + public Long lPushX(final String key, final V value) { + return lPushX(key, serializer.serialize(value)); + } + + @Override + public Long lPushX(final byte[] key, final V value) { + return lPushX(key, serializer.serializeAsBytes(value)); + } + + @Override + public Long lPushX(final String key, final V... values) { + return lPushX(key, serializer.serialize(values)); + } + + @Override + public Long lPushX(final byte[] key, final V... values) { + return lPushX(key, serializer.serializeAsBytes(values)); + } + + @Override + public V rPopObject(final String key) { + return execute((client)->client.listOperations().rPop(rawKey(key)), + new Converter.SimpleStringConverter<>(this)); + } + + @Override + public V rPopObject(final byte[] key) { + return execute((client)->client.listOperations().rPop(rawKey(key)), + new Converter.SimpleBinaryConverter<>(this)); + } + + @Override + public V rPopObject(final String key, final Class clazz) { + return execute((client)->client.listOperations().rPop(rawKey(key)), + new Converter.ClazzStringConverter<>(this, clazz)); + } + + @Override + public V rPopObject(final byte[] key, final Class clazz) { + return execute((client)->client.listOperations().rPop(rawKey(key)), + new Converter.ClazzBinaryConverter<>(this, clazz)); + } + + @Override + public V rPopObject(final String key, final TypeReference type) { + return execute((client)->client.listOperations().rPop(rawKey(key)), + new Converter.TypeStringConverter<>(this, type)); + } + + @Override + public V rPopObject(final byte[] key, final TypeReference type) { + return execute((client)->client.listOperations().rPop(rawKey(key)), + new Converter.TypeBinaryConverter<>(this, type)); + } + + @Override + public V rPoplPushObject(final String key, final String destKey) { + return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey)), + new Converter.SimpleStringConverter<>(this)); + } + + @Override + public V rPoplPushObject(final byte[] key, final byte[] destKey) { + return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey)), + new Converter.SimpleBinaryConverter<>(this)); + } + + @Override + public V rPoplPushObject(final String key, final String destKey, final Class clazz) { + return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey)), + new Converter.ClazzStringConverter<>(this, clazz)); + } + + @Override + public V rPoplPushObject(final byte[] key, final byte[] destKey, final Class clazz) { + return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey)), + new Converter.ClazzBinaryConverter<>(this, clazz)); + } + + @Override + public V rPoplPushObject(final String key, final String destKey, final TypeReference type) { + return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey)), + new Converter.TypeStringConverter<>(this, type)); + } + + @Override + public V rPoplPushObject(final byte[] key, final byte[] destKey, final TypeReference type) { + return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey)), + new Converter.TypeBinaryConverter<>(this, type)); + } + + @Override + public Long rPush(final String key, final V value) { + return rPush(key, serializer.serialize(value)); + } + + @Override + public Long rPush(final byte[] key, final V value) { + return rPush(key, serializer.serializeAsBytes(value)); + } + + @Override + public Long rPush(final String key, final V... values) { + return rPush(key, serializer.serialize(values)); + } + + @Override + public Long rPush(final byte[] key, final V... values) { + return rPush(key, serializer.serializeAsBytes(values)); + } + + @Override + public Long rPushX(final String key, final V value) { + return rPushX(key, serializer.serialize(value)); + } + + @Override + public Long rPushX(final byte[] key, final V value) { + return rPushX(key, serializer.serializeAsBytes(value)); + } + + @Override + public Long rPushX(final String key, final V... values) { + return rPushX(key, serializer.serialize(values)); + } + + @Override + public Long rPushX(final byte[] key, final V... values) { + return rPushX(key, serializer.serializeAsBytes(values)); + } + + @Override + public Long sAdd(final String key, final V... members) { + return sAdd(key, serializer.serialize(members)); + } + + @Override + public Long sAdd(final byte[] key, final V... members) { + return sAdd(key, serializer.serializeAsBytes(members)); + } + + @Override + public Set sDiffObject(final String[] keys) { + return execute((client)->client.setOperations().sDiff(rawKeys(keys)), + new Converter.SimpleSetStringConverter<>(this)); + } + + @Override + public Set sDiffObject(final byte[][] keys) { + return execute((client)->client.setOperations().sDiff(rawKeys(keys)), + new Converter.SimpleSetBinaryConverter<>(this)); + } + + @Override + public Set sDiffObject(final String[] keys, final Class clazz) { + return execute((client)->client.setOperations().sDiff(rawKeys(keys)), + new Converter.ClazzSetStringConverter<>(this, clazz)); + } + + @Override + public Set sDiffObject(final byte[][] keys, final Class clazz) { + return execute((client)->client.setOperations().sDiff(rawKeys(keys)), + new Converter.ClazzSetBinaryConverter<>(this, clazz)); + } + + @Override + public Set sDiffObject(final String[] keys, final TypeReference type) { + return execute((client)->client.setOperations().sDiff(rawKeys(keys)), + new Converter.TypeSetStringConverter<>(this, type)); + } + + @Override + public Set sDiffObject(final byte[][] keys, final TypeReference type) { + return execute((client)->client.setOperations().sDiff(rawKeys(keys)), + new Converter.TypeSetBinaryConverter<>(this, type)); + } + + @Override + public Set sInterObject(final String[] keys) { + return execute((client)->client.setOperations().sInter(rawKeys(keys)), + new Converter.SimpleSetStringConverter<>(this)); + } + + @Override + public Set sInterObject(final byte[][] keys) { + return execute((client)->client.setOperations().sInter(rawKeys(keys)), + new Converter.SimpleSetBinaryConverter<>(this)); + } + + @Override + public Set sInterObject(final String[] keys, final Class clazz) { + return execute((client)->client.setOperations().sInter(rawKeys(keys)), + new Converter.ClazzSetStringConverter<>(this, clazz)); + } + + @Override + public Set sInterObject(final byte[][] keys, final Class clazz) { + return execute((client)->client.setOperations().sInter(rawKeys(keys)), + new Converter.ClazzSetBinaryConverter<>(this, clazz)); + } + + @Override + public Set sInterObject(final String[] keys, final TypeReference type) { + return execute((client)->client.setOperations().sInter(rawKeys(keys)), + new Converter.TypeSetStringConverter<>(this, type)); + } + + @Override + public Set sInterObject(final byte[][] keys, final TypeReference type) { + return execute((client)->client.setOperations().sInter(rawKeys(keys)), + new Converter.TypeSetBinaryConverter<>(this, type)); + } + + @Override + public Set sMembersObject(final String key) { + return execute((client)->client.setOperations().sMembers(rawKey(key)), + new Converter.SimpleSetStringConverter<>(this)); + } + + @Override + public Set sMembersObject(final byte[] key) { + return execute((client)->client.setOperations().sMembers(rawKey(key)), + new Converter.SimpleSetBinaryConverter<>(this)); + } + + @Override + public Set sMembersObject(final String key, final Class clazz) { + return execute((client)->client.setOperations().sMembers(rawKey(key)), + new Converter.ClazzSetStringConverter<>(this, clazz)); + } + + @Override + public Set sMembersObject(final byte[] key, final Class clazz) { + return execute((client)->client.setOperations().sMembers(rawKey(key)), + new Converter.ClazzSetBinaryConverter<>(this, clazz)); + } + + @Override + public Set sMembersObject(final String key, final TypeReference type) { + return execute((client)->client.setOperations().sMembers(rawKey(key)), + new Converter.TypeSetStringConverter<>(this, type)); + } + + @Override + public Set sMembersObject(final byte[] key, final TypeReference type) { + return execute((client)->client.setOperations().sMembers(rawKey(key)), + new Converter.TypeSetBinaryConverter<>(this, type)); + } + + @Override + public V sPopObject(final String key) { + return execute((client)->client.setOperations().sPop(rawKey(key)), new Converter.SimpleStringConverter<>(this)); + } + + @Override + public V sPopObject(final byte[] key) { + return execute((client)->client.setOperations().sPop(rawKey(key)), new Converter.SimpleBinaryConverter<>(this)); + } + + @Override + public V sPopObject(final String key, final Class clazz) { + return execute((client)->client.setOperations().sPop(rawKey(key)), + new Converter.ClazzStringConverter<>(this, clazz)); + } + + @Override + public V sPopObject(final byte[] key, final Class clazz) { + return execute((client)->client.setOperations().sPop(rawKey(key)), + new Converter.ClazzBinaryConverter<>(this, clazz)); + } + + @Override + public V sPopObject(final String key, final TypeReference type) { + return execute((client)->client.setOperations().sPop(rawKey(key)), + new Converter.TypeStringConverter<>(this, type)); + } + + @Override + public V sPopObject(final byte[] key, final TypeReference type) { + return execute((client)->client.setOperations().sPop(rawKey(key)), + new Converter.TypeBinaryConverter<>(this, type)); + } + + @Override + public Set sPopObject(final String key, final int count) { + return execute((client)->client.setOperations().sPop(rawKey(key), count), + new Converter.SimpleSetStringConverter<>(this)); + } + + @Override + public Set sPopObject(final byte[] key, final int count) { + return execute((client)->client.setOperations().sPop(rawKey(key), count), + new Converter.SimpleSetBinaryConverter<>(this)); + + } + + @Override + public Set sPopObject(final String key, final int count, final Class clazz) { + return execute((client)->client.setOperations().sPop(rawKey(key), count), + new Converter.ClazzSetStringConverter<>(this, clazz)); + } + + @Override + public Set sPopObject(final byte[] key, final int count, final Class clazz) { + return execute((client)->client.setOperations().sPop(rawKey(key), count), + new Converter.ClazzSetBinaryConverter<>(this, clazz)); + } + + @Override + public Set sPopObject(final String key, final int count, final TypeReference type) { + return execute((client)->client.setOperations().sPop(rawKey(key), count), + new Converter.TypeSetStringConverter<>(this, type)); + } + + @Override + public Set sPopObject(final byte[] key, final int count, final TypeReference type) { + return execute((client)->client.setOperations().sPop(rawKey(key), count), + new Converter.TypeSetBinaryConverter<>(this, type)); + } + + @Override + public V sRandMemberObject(final String key) { + return execute((client)->client.setOperations().sRandMember(rawKey(key)), + new Converter.SimpleStringConverter<>(this)); + } + + @Override + public V sRandMemberObject(final byte[] key) { + return execute((client)->client.setOperations().sRandMember(rawKey(key)), + new Converter.SimpleBinaryConverter<>(this)); + } + + @Override + public V sRandMemberObject(final String key, final Class clazz) { + return execute((client)->client.setOperations().sRandMember(rawKey(key)), + new Converter.ClazzStringConverter<>(this, clazz)); + } + + @Override + public V sRandMemberObject(final byte[] key, final Class clazz) { + return execute((client)->client.setOperations().sRandMember(rawKey(key)), + new Converter.ClazzBinaryConverter<>(this, clazz)); + } + + @Override + public V sRandMemberObject(final String key, final TypeReference type) { + return execute((client)->client.setOperations().sRandMember(rawKey(key)), + new Converter.TypeStringConverter<>(this, type)); + } + + @Override + public V sRandMemberObject(final byte[] key, final TypeReference type) { + return execute((client)->client.setOperations().sRandMember(rawKey(key)), + new Converter.TypeBinaryConverter<>(this, type)); + } + + @Override + public List sRandMemberObject(final String key, final int count) { + return execute((client)->client.setOperations().sRandMember(rawKey(key), count), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List sRandMemberObject(final byte[] key, final int count) { + return execute((client)->client.setOperations().sRandMember(rawKey(key), count), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List sRandMemberObject(final String key, final int count, final Class clazz) { + return execute((client)->client.setOperations().sRandMember(rawKey(key), count), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List sRandMemberObject(final byte[] key, final int count, final Class clazz) { + return execute((client)->client.setOperations().sRandMember(rawKey(key), count), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List sRandMemberObject(final String key, final int count, final TypeReference type) { + return execute((client)->client.setOperations().sRandMember(rawKey(key), count), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List sRandMemberObject(final byte[] key, final int count, final TypeReference type) { + return execute((client)->client.setOperations().sRandMember(rawKey(key), count), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public Long sRem(final String key, final V member) { + return sRem(key, serializer.serialize(member)); + } + + @Override + public Long sRem(final byte[] key, final V member) { + return sRem(key, serializer.serializeAsBytes(member)); + } + + @Override + public Long sRem(final String key, final V... members) { + return sRem(key, serializer.serialize(members)); + } + + @Override + public Long sRem(final byte[] key, final V... members) { + return sRem(key, serializer.serializeAsBytes(members)); + } + + @Override + public ScanResult> sScanObject(final String key, final long cursor) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor), + new Converter.SimpleScanResultListStringConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final long cursor) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor), + new Converter.SimpleScanResultListBinaryConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final String key, final long cursor, final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor), + new Converter.ClazzScanResultListStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final long cursor, final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor), + new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final String key, final long cursor, final TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor), + new Converter.TypeScanResultListStringConverter<>(this, type)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final long cursor, final TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor), + new Converter.TypeScanResultListBinaryConverter<>(this, type)); + } + + @Override + public ScanResult> sScanObject(final String key, final String cursor) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor), + new Converter.SimpleScanResultListStringConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final byte[] cursor) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor), + new Converter.SimpleScanResultListBinaryConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final String key, final String cursor, final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor), + new Converter.ClazzScanResultListStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor), + new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final String key, final String cursor, + final TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor), + new Converter.TypeScanResultListStringConverter<>(this, type)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final byte[] cursor, + final TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor), + new Converter.TypeScanResultListBinaryConverter<>(this, type)); + } + + @Override + public ScanResult> sScanObject(final String key, final long cursor, final String pattern) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), + new Converter.SimpleScanResultListStringConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), + new Converter.SimpleScanResultListBinaryConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final String key, final long cursor, final String pattern, + final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), + new Converter.ClazzScanResultListStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern, + final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), + new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final String key, final long cursor, final String pattern, + final TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), + new Converter.TypeScanResultListStringConverter<>(this, type)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern, + final TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), + new Converter.TypeScanResultListBinaryConverter<>(this, type)); + } + + @Override + public ScanResult> sScanObject(final String key, final String cursor, final String pattern) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), + new Converter.SimpleScanResultListStringConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), + new Converter.SimpleScanResultListBinaryConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final String key, final String cursor, final String pattern, + final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), + new Converter.ClazzScanResultListStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), + new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final String key, final String cursor, final String pattern, + final TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), + new Converter.TypeScanResultListStringConverter<>(this, type)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), + new Converter.TypeScanResultListBinaryConverter<>(this, type)); + } + + @Override + public ScanResult> sScanObject(final String key, final long cursor, final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), + new Converter.SimpleScanResultListStringConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final long cursor, final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), + new Converter.SimpleScanResultListBinaryConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final String key, final long cursor, final int count, + final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), + new Converter.ClazzScanResultListStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final long cursor, final int count, + final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), + new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final String key, final long cursor, int count, + TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), + new Converter.TypeScanResultListStringConverter<>(this, type)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final long cursor, final int count, + final TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), + new Converter.TypeScanResultListBinaryConverter<>(this, type)); + } + + @Override + public ScanResult> sScanObject(final String key, final String cursor, final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), + new Converter.SimpleScanResultListStringConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), + new Converter.SimpleScanResultListBinaryConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final String key, final String cursor, final int count, + final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), + new Converter.ClazzScanResultListStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final int count, + final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), + new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final String key, final String cursor, final int count, + final TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), + new Converter.TypeScanResultListStringConverter<>(this, type)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final int count, + final TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), + new Converter.TypeScanResultListBinaryConverter<>(this, type)); + } + + @Override + public ScanResult> sScanObject(final String key, final long cursor, final String pattern, + final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), + new Converter.SimpleScanResultListStringConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern, + final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), + new Converter.SimpleScanResultListBinaryConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final String key, final long cursor, final String pattern, + final int count, final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), + new Converter.ClazzScanResultListStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern, + final int count, final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), + new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final String key, final long cursor, final String pattern, + final int count, final TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), + new Converter.TypeScanResultListStringConverter<>(this, type)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern, + final int count, final TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), + new Converter.TypeScanResultListBinaryConverter<>(this, type)); + } + + @Override + public ScanResult> sScanObject(final String key, final String cursor, final String pattern, + final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), + new Converter.SimpleScanResultListStringConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), + new Converter.SimpleScanResultListBinaryConverter<>(this)); + } + + @Override + public ScanResult> sScanObject(final String key, final String cursor, final String pattern, + final int count, final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), + new Converter.ClazzScanResultListStringConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count, final Class clazz) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), + new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); + } + + @Override + public ScanResult> sScanObject(final String key, final String cursor, final String pattern, + final int count, final TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), + new Converter.TypeScanResultListStringConverter<>(this, type)); + } + + @Override + public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count, final TypeReference type) { + return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), + new Converter.TypeScanResultListBinaryConverter<>(this, type)); + } + + @Override + public Set sUnionObject(final String[] keys) { + return execute((client)->client.setOperations().sUnion(rawKeys(keys)), + new Converter.SimpleSetStringConverter<>(this)); + } + + @Override + public Set sUnionObject(final byte[][] keys) { + return execute((client)->client.setOperations().sUnion(rawKeys(keys)), + new Converter.SimpleSetBinaryConverter<>(this)); + } + + @Override + public Set sUnionObject(final String[] keys, final Class clazz) { + return execute((client)->client.setOperations().sUnion(rawKeys(keys)), + new Converter.ClazzSetStringConverter<>(this, clazz)); + } + + @Override + public Set sUnionObject(final byte[][] keys, final Class clazz) { + return execute((client)->client.setOperations().sUnion(rawKeys(keys)), + new Converter.ClazzSetBinaryConverter<>(this, clazz)); + } + + @Override + public Set sUnionObject(final String[] keys, final TypeReference type) { + return execute((client)->client.setOperations().sUnion(rawKeys(keys)), + new Converter.TypeSetStringConverter<>(this, type)); + } + + @Override + public Set sUnionObject(final byte[][] keys, final TypeReference type) { + return execute((client)->client.setOperations().sUnion(rawKeys(keys)), + new Converter.TypeSetBinaryConverter<>(this, type)); + } + + @Override + public Long zAdd(final String key, final double score, final V member) { + return zAdd(key, score, serializer.serialize(member)); + } + + @Override + public Long zAdd(final byte[] key, final double score, final V member) { + return zAdd(key, score, serializer.serialize(member)); + } + + @Override + public Long zAdd(final String key, final double score, final V member, final NxXx nxXx) { + return zAdd(key, score, serializer.serialize(member), nxXx); + } + + @Override + public Long zAdd(final byte[] key, final double score, final V member, final NxXx nxXx) { + return zAdd(key, score, serializer.serialize(member), nxXx); + } + + @Override + public Long zAdd(final String key, final double score, final V member, final GtLt gtLt) { + return zAdd(key, score, serializer.serialize(member), gtLt); + } + + @Override + public Long zAdd(final byte[] key, final double score, final V member, final GtLt gtLt) { + return zAdd(key, score, serializer.serialize(member), gtLt); + } + + @Override + public Long zAdd(final String key, final double score, final V member, final boolean ch) { + return zAdd(key, score, serializer.serialize(member), ch); + } + + @Override + public Long zAdd(final byte[] key, final double score, final V member, final boolean ch) { + return zAdd(key, score, serializer.serialize(member), ch); + } + + @Override + public Long zAdd(final String key, final double score, final V member, final NxXx nxXx, final GtLt gtLt) { + return zAdd(key, score, serializer.serialize(member), nxXx, gtLt); + } + + @Override + public Long zAdd(final byte[] key, final double score, final V member, final NxXx nxXx, final GtLt gtLt) { + return zAdd(key, score, serializer.serialize(member), nxXx, gtLt); + } + + @Override + public Long zAdd(final String key, final double score, final V member, final NxXx nxXx, final boolean ch) { + return zAdd(key, score, serializer.serialize(member), nxXx, ch); + } + + @Override + public Long zAdd(final byte[] key, final double score, final V member, final NxXx nxXx, final boolean ch) { + return zAdd(key, score, serializer.serialize(member), nxXx, ch); + } + + @Override + public Long zAdd(final String key, final double score, final V member, final GtLt gtLt, final boolean ch) { + return zAdd(key, score, serializer.serialize(member), gtLt, ch); + } + + @Override + public Long zAdd(final byte[] key, final double score, final V member, final GtLt gtLt, final boolean ch) { + return zAdd(key, score, serializer.serialize(member), gtLt, ch); + } + + @Override + public Long zAdd(final String key, final double score, final V member, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + return zAdd(key, score, serializer.serialize(member), nxXx, gtLt, ch); + } + + @Override + public Long zAdd(final byte[] key, final double score, final V member, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + return zAdd(key, score, serializer.serialize(member), nxXx, gtLt, ch); + } + + @Override + public List zDiffObject(final String[] keys) { + return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys)), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zDiffObject(final byte[][] keys) { + return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys)), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zDiffObject(final String[] keys, final Class clazz) { + return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys)), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zDiffObject(final byte[][] keys, final Class clazz) { + return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys)), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zDiffObject(final String[] keys, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys)), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zDiffObject(final byte[][] keys, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys)), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zInterObject(final String[] keys) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys)), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zInterObject(final byte[][] keys) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys)), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zInterObject(final String[] keys, final Class clazz) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys)), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zInterObject(final byte[][] keys, final Class clazz) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys)), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zInterObject(final String[] keys, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys)), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zInterObject(final byte[][] keys, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys)), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zInterObject(final String[] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zInterObject(final byte[][] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zInterObject(final String[] keys, final Aggregate aggregate, final Class clazz) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zInterObject(final byte[][] keys, final Aggregate aggregate, final Class clazz) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zInterObject(final String[] keys, final Aggregate aggregate, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zInterObject(final byte[][] keys, final Aggregate aggregate, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zInterObject(final String[] keys, final double[] weights) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zInterObject(final byte[][] keys, final double[] weights) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zInterObject(final String[] keys, final double[] weights, final Class clazz) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zInterObject(final byte[][] keys, final double[] weights, final Class clazz) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zInterObject(final String[] keys, final double[] weights, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zInterObject(final byte[][] keys, final double[] weights, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final Class clazz) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final Class clazz) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type) { + return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public V zRandMemberObject(final String key) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key)), + new Converter.SimpleStringConverter<>(this)); + } + + @Override + public V zRandMemberObject(final byte[] key) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key)), + new Converter.SimpleBinaryConverter<>(this)); + } + + @Override + public V zRandMemberObject(final String key, final Class clazz) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key)), + new Converter.ClazzStringConverter<>(this, clazz)); + } + + @Override + public V zRandMemberObject(final byte[] key, final Class clazz) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key)), + new Converter.ClazzBinaryConverter<>(this, clazz)); + } + + @Override + public V zRandMemberObject(final String key, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key)), + new Converter.TypeStringConverter<>(this, type)); + } + + @Override + public V zRandMemberObject(final byte[] key, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key)), + new Converter.TypeBinaryConverter<>(this, type)); + } + + @Override + public List zRandMemberObject(final String key, final int count) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zRandMemberObject(final byte[] key, final int count) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zRandMemberObject(final String key, final int count, final Class clazz) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zRandMemberObject(final byte[] key, final int count, final Class clazz) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zRandMemberObject(final String key, final int count, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zRandMemberObject(final byte[] key, final int count, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zRangeObject(final String key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zRangeObject(final byte[] key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zRangeObject(final String key, final long start, final long end, final Class clazz) { + return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zRangeObject(final byte[] key, final long start, final long end, final Class clazz) { + return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zRangeObject(final String key, final long start, final long end, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zRangeObject(final byte[] key, final long start, final long end, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zRangeByLexObject(final String key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zRangeByLexObject(final byte[] key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zRangeByLexObject(final String key, final double min, final double max, final Class clazz) { + return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zRangeByLexObject(final byte[] key, final double min, final double max, final Class clazz) { + return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zRangeByLexObject(final String key, final double min, final double max, + final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zRangeByLexObject(final byte[] key, final double min, final double max, + final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zRangeByScoreObject(final String key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zRangeByScoreObject(final byte[] key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zRangeByScoreObject(final String key, final double min, final double max, final Class clazz) { + return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zRangeByScoreObject(final byte[] key, final double min, final double max, final Class clazz) { + return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zRangeByScoreObject(final String key, final double min, final double max, + final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zRangeByScoreObject(final byte[] key, final double min, final double max, + final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zRangeByScoreObject(final String key, final double min, final double max, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zRangeByScoreObject(final byte[] key, final double min, final double max, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zRangeByScoreObject(String key, double min, double max, long offset, + int count, Class clazz) { + return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zRangeByScoreObject(byte[] key, double min, double max, long offset, + int count, Class clazz) { + return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zRangeByScoreObject(String key, double min, double max, long offset, + int count, TypeReference type) { + return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zRangeByScoreObject(byte[] key, double min, double max, long offset, + int count, TypeReference type) { + return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zRevRangeObject(final String key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRevRange(key, start, end), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zRevRangeObject(final byte[] key, final long start, final long end) { + return execute((client)->client.sortedSetOperations().zRevRange(key, start, end), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zRevRangeObject(final String key, final long start, final long end, final Class clazz) { + return execute((client)->client.sortedSetOperations().zRevRange(key, start, end), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zRevRangeObject(final byte[] key, final long start, final long end, final Class clazz) { + return execute((client)->client.sortedSetOperations().zRevRange(key, start, end), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zRevRangeObject(final String key, final long start, final long end, + final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRevRange(key, start, end), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zRevRangeObject(final byte[] key, final long start, final long end, + final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRevRange(key, start, end), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zRevRangeByLexObject(final String key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zRevRangeByLexObject(final byte[] key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zRevRangeByLexObject(final String key, final double min, final double max, + final Class clazz) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zRevRangeByLexObject(final byte[] key, final double min, final double max, + final Class clazz) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zRevRangeByLexObject(final String key, final double min, final double max, + final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zRevRangeByLexObject(final byte[] key, final double min, final double max, + final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zRevRangeByLexObject(final String key, final double min, final double max, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zRevRangeByLexObject(final byte[] key, final double min, final double max, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zRevRangeByLexObject(final String key, final double min, final double max, final long offset, + final int count, final Class clazz) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zRevRangeByLexObject(final byte[] key, final double min, final double max, final long offset, + final int count, final Class clazz) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zRevRangeByLexObject(final String key, final double min, final double max, final long offset, + final int count, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zRevRangeByLexObject(final byte[] key, final double min, final double max, final long offset, + final int count, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zRevRangeByScoreObject(final String key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zRevRangeByScoreObject(final byte[] key, final double min, final double max) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zRevRangeByScoreObject(final String key, final double min, final double max, + final Class clazz) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zRevRangeByScoreObject(final byte[] key, final double min, final double max, + final Class clazz) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zRevRangeByScoreObject(final String key, final double min, final double max, + final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zRevRangeByScoreObject(final byte[] key, final double min, final double max, + final TypeReference type) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zRevRangeByScoreObject(final String key, final double min, final double max, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zRevRangeByScoreObject(final byte[] key, final double min, final double max, final long offset, + final int count) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zRevRangeByScoreObject(String key, double min, double max, long offset, + int count, Class clazz) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zRevRangeByScoreObject(byte[] key, double min, double max, long offset, + int count, Class clazz) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zRevRangeByScoreObject(String key, double min, double max, long offset, + int count, TypeReference type) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zRevRangeByScoreObject(byte[] key, double min, double max, long offset, + int count, TypeReference type) { + return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zUnionObject(final String[] keys) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys)), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zUnionObject(final byte[][] keys) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys)), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zUnionObject(final String[] keys, final Class clazz) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys)), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zUnionObject(final byte[][] keys, final Class clazz) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys)), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zUnionObject(final String[] keys, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys)), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zUnionObject(final byte[][] keys, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys)), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zUnionObject(final String[] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zUnionObject(final byte[][] keys, final Aggregate aggregate) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zUnionObject(final String[] keys, final Aggregate aggregate, final Class clazz) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zUnionObject(final byte[][] keys, final Aggregate aggregate, final Class clazz) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zUnionObject(final String[] keys, final Aggregate aggregate, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zUnionObject(final byte[][] keys, final Aggregate aggregate, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zUnionObject(final String[] keys, final double[] weights) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zUnionObject(final byte[][] keys, final double[] weights) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zUnionObject(final String[] keys, final double[] weights, final Class clazz) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zUnionObject(final byte[][] keys, final double[] weights, final Class clazz) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zUnionObject(final String[] keys, final double[] weights, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zUnionObject(final byte[][] keys, final double[] weights, final TypeReference type) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public List zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final Class clazz) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final Class clazz) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type) { + return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public V getObject(final String key) { + return execute((client)->client.stringOperations().get(rawKey(key)), + new Converter.SimpleStringConverter<>(this)); + } + + @Override + public V getObject(final byte[] key) { + return execute((client)->client.stringOperations().get(rawKey(key)), + new Converter.SimpleBinaryConverter<>(this)); + } + + @Override + public V getObject(final String key, final Class clazz) { + return execute((client)->client.stringOperations().get(rawKey(key)), + new Converter.ClazzStringConverter<>(this, clazz)); + } + + @Override + public V getObject(final byte[] key, final Class clazz) { + return execute((client)->client.stringOperations().get(rawKey(key)), + new Converter.ClazzBinaryConverter<>(this, clazz)); + } + + @Override + public V getObject(final String key, final TypeReference type) { + return execute((client)->client.stringOperations().get(rawKey(key)), + new Converter.TypeStringConverter<>(this, type)); + } + + @Override + public V getObject(final byte[] key, final TypeReference type) { + return execute((client)->client.stringOperations().get(rawKey(key)), + new Converter.TypeBinaryConverter<>(this, type)); + } + + @Override + public V getExObject(final String key, final GetExArgument getExArgument) { + return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument), + new Converter.SimpleStringConverter<>(this)); + } + + @Override + public V getExObject(final byte[] key, final GetExArgument getExArgument) { + return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument), + new Converter.SimpleBinaryConverter<>(this)); + } + + @Override + public V getExObject(final String key, final GetExArgument getExArgument, final Class clazz) { + return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument), + new Converter.ClazzStringConverter<>(this, clazz)); + } + + @Override + public V getExObject(final byte[] key, final GetExArgument getExArgument, final Class clazz) { + return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument), + new Converter.ClazzBinaryConverter<>(this, clazz)); + } + + @Override + public V getExObject(final String key, final GetExArgument getExArgument, final TypeReference type) { + return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument), + new Converter.TypeStringConverter<>(this, type)); + } + + @Override + public V getExObject(final byte[] key, final GetExArgument getExArgument, final TypeReference type) { + return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument), + new Converter.TypeBinaryConverter<>(this, type)); + } + + @Override + public V getSet(final String key, final V value) { + return execute((client)->client.stringOperations().getSet(rawKey(key), serializer.serialize(value)), + new Converter.SimpleStringConverter<>(this)); + } + + @Override + public V getSet(final byte[] key, final V value) { + return execute((client)->client.stringOperations().getSet(rawKey(key), serializer.serializeAsBytes(value)), + new Converter.SimpleBinaryConverter<>(this)); + } + + @Override + public V getSet(final String key, final V value, final Class clazz) { + return execute((client)->client.stringOperations().getSet(rawKey(key), serializer.serialize(value)), + new Converter.ClazzStringConverter<>(this, clazz)); + } + + @Override + public V getSet(final byte[] key, final V value, final Class clazz) { + return execute((client)->client.stringOperations().getSet(rawKey(key), serializer.serializeAsBytes(value)), + new Converter.ClazzBinaryConverter<>(this, clazz)); + } + + @Override + public V getSet(final String key, final V value, final TypeReference type) { + return execute((client)->client.stringOperations().getSet(rawKey(key), serializer.serialize(value)), + new Converter.TypeStringConverter<>(this, type)); + } + + @Override + public V getSet(final byte[] key, final V value, final TypeReference type) { + return execute((client)->client.stringOperations().getSet(rawKey(key), serializer.serializeAsBytes(value)), + new Converter.TypeBinaryConverter<>(this, type)); + } + + @Override + public V getDelObject(final String key) { + return execute((client)->client.stringOperations().getDel(rawKey(key)), + new Converter.SimpleStringConverter<>(this)); + } + + @Override + public V getDelObject(final byte[] key) { + return execute((client)->client.stringOperations().getDel(rawKey(key)), + new Converter.SimpleBinaryConverter<>(this)); + } + + @Override + public V getDelObject(final String key, final Class clazz) { + return execute((client)->client.stringOperations().getDel(rawKey(key)), + new Converter.ClazzStringConverter<>(this, clazz)); + } + + @Override + public V getDelObject(final byte[] key, final Class clazz) { + return execute((client)->client.stringOperations().getDel(rawKey(key)), + new Converter.ClazzBinaryConverter<>(this, clazz)); + } + + @Override + public V getDelObject(final String key, final TypeReference type) { + return execute((client)->client.stringOperations().getDel(rawKey(key)), + new Converter.TypeStringConverter<>(this, type)); + } + + @Override + public V getDelObject(final byte[] key, final TypeReference type) { + return execute((client)->client.stringOperations().getDel(rawKey(key)), + new Converter.TypeBinaryConverter<>(this, type)); + } + + @Override + public List mGetObject(final String... keys) { + return execute((client)->client.stringOperations().mGet(rawKeys(keys)), + new Converter.SimpleListStringConverter<>(this)); + } + + @Override + public List mGetObject(final byte[]... keys) { + return execute((client)->client.stringOperations().mGet(rawKeys(keys)), + new Converter.SimpleListBinaryConverter<>(this)); + } + + @Override + public List mGetObject(final String[] keys, final Class clazz) { + return execute((client)->client.stringOperations().mGet(rawKeys(keys)), + new Converter.ClazzListStringConverter<>(this, clazz)); + } + + @Override + public List mGetObject(final byte[][] keys, final Class clazz) { + return execute((client)->client.stringOperations().mGet(rawKeys(keys)), + new Converter.ClazzListBinaryConverter<>(this, clazz)); + } + + @Override + public List mGetObject(final String[] keys, final TypeReference type) { + return execute((client)->client.stringOperations().mGet(rawKeys(keys)), + new Converter.TypeListStringConverter<>(this, type)); + } + + @Override + public List mGetObject(final byte[][] keys, final TypeReference type) { + return execute((client)->client.stringOperations().mGet(rawKeys(keys)), + new Converter.TypeListBinaryConverter<>(this, type)); + } + + @Override + public Status pSetEx(final String key, final V value, final int lifetime) { + return pSetEx(key, serializer.serialize(value), lifetime); + } + + @Override + public Status pSetEx(final byte[] key, final V value, final int lifetime) { + return pSetEx(key, serializer.serializeAsBytes(value), lifetime); + } + + @Override + public Status set(final String key, final V value) { + return set(key, serializer.serialize(value)); + } + + @Override + public Status set(final byte[] key, final V value) { + return set(key, serializer.serializeAsBytes(value)); + } + + @Override + public Status set(final String key, final V value, final SetArgument setArgument) { + return set(key, serializer.serialize(value), setArgument); + } + + @Override + public Status set(final byte[] key, final V value, final SetArgument setArgument) { + return set(key, serializer.serializeAsBytes(value), setArgument); + } + + @Override + public Status setEx(final String key, final V value, final int lifetime) { + return setEx(key, serializer.serialize(value), lifetime); + } + + @Override + public Status setEx(final byte[] key, final V value, final int lifetime) { + return setEx(key, serializer.serializeAsBytes(value), lifetime); + } + + @Override + public Status setNx(final String key, final V value) { + return setNx(key, serializer.serialize(value)); + } + + @Override + public Status setNx(final byte[] key, final V value) { + return setNx(key, serializer.serializeAsBytes(value)); + } + + @Override + public void discard() { + super.discard(); + resetTransactionOrPipeline(); + } + + @Override + public List exec() { + List result = super.exec(); + + if(result != null){ + Map> map = txConverters.get(); + + if(Validate.isNotEmpty(map)){ + for(int i = 0; i < result.size(); i++){ + Function fun = (Function) map.get(i); + + if(fun != null){ + result.set(i, fun.apply(result.get(i))); + } + } + } + } + + resetTransactionOrPipeline(); + + return result; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/AbstractConnectionFactory.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/AbstractConnectionFactory.java new file mode 100644 index 000000000..0160abfb6 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/AbstractConnectionFactory.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection; + +import com.buession.redis.client.connection.datasource.ClusterDataSource; +import com.buession.redis.client.connection.datasource.DataSource; +import com.buession.redis.client.connection.datasource.SentinelDataSource; + +/** + * Redis 连接工厂抽象类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractConnectionFactory implements RedisConnectionFactory { + + private final DS dataSource; + + private RedisConnection redisConnection; + + public AbstractConnectionFactory(final DS dataSource) { + this.dataSource = dataSource; + } + + public boolean isRedisSentinelAware() { + return dataSource instanceof SentinelDataSource; + } + + public boolean isRedisClusterAware() { + return dataSource instanceof ClusterDataSource; + } + + @Override + public RedisConnection getConnection() { + if(redisConnection == null){ + synchronized(this){ + if(isRedisClusterAware()){ + redisConnection = getClusterConnection(); + }else if(isRedisSentinelAware()){ + redisConnection = getSentinelConnection(); + }else{ + redisConnection = getStandaloneConnection(); + } + } + } + + return redisConnection; + } + + protected DS getDataSource() { + return dataSource; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/AbstractRedisConnection.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/AbstractRedisConnection.java new file mode 100644 index 000000000..864ef62ae --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/AbstractRedisConnection.java @@ -0,0 +1,430 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection; + +import com.buession.lang.Status; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.core.Constants; +import com.buession.redis.client.connection.datasource.DataSource; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.exception.RedisConnectionFailureException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +/** + * Redis 连接对象抽象类 + * + * @author Yong.Teng + */ +public abstract class AbstractRedisConnection implements RedisConnection { + + /** + * Redis 数据源 + */ + private DataSource dataSource; + + /** + * 连接池配置 + * + * @since 3.0.0 + */ + private PoolConfig poolConfig; + + /** + * 连接超时(单位:毫秒) + */ + private int connectTimeout = Constants.DEFAULT_CONNECT_TIMEOUT; + + /** + * 读取超时(单位:毫秒) + */ + private int soTimeout = Constants.DEFAULT_SO_TIMEOUT; + + /** + * Infinite 读取超时(单位:毫秒) + * + * @since 2.0.0 + */ + private int infiniteSoTimeout = Constants.DEFAULT_INFINITE_SO_TIMEOUT; + + /** + * SSL 配置 + */ + private SslConfiguration sslConfiguration; + + private volatile boolean initialized = false; + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + /** + * 构造函数 + */ + public AbstractRedisConnection() { + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + */ + public AbstractRedisConnection(DataSource dataSource) { + this.dataSource = dataSource; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public AbstractRedisConnection(DataSource dataSource, int connectTimeout, int soTimeout) { + this.dataSource = dataSource; + this.connectTimeout = connectTimeout; + this.soTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * + * @since 2.0.0 + */ + public AbstractRedisConnection(DataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + this(dataSource, connectTimeout, soTimeout); + this.infiniteSoTimeout = infiniteSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param sslConfiguration + * SSL 配置 + */ + public AbstractRedisConnection(DataSource dataSource, SslConfiguration sslConfiguration) { + this.dataSource = dataSource; + this.sslConfiguration = sslConfiguration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout(单位:毫秒) + * 连接超时 + * @param soTimeout(单位:毫秒) + * 读取超时 + * @param sslConfiguration + * SSL 配置 + */ + public AbstractRedisConnection(DataSource dataSource, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + this(dataSource, connectTimeout, soTimeout); + this.sslConfiguration = sslConfiguration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout(单位:毫秒) + * Infinite 读取超时 + * @param sslConfiguration + * SSL 配置 + * + * @since 2.0.0 + */ + public AbstractRedisConnection(DataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + this(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.infiniteSoTimeout = infiniteSoTimeout; + } + + /** + * 构造函数 + * + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public AbstractRedisConnection(PoolConfig poolConfig) { + this.poolConfig = poolConfig; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public AbstractRedisConnection(DataSource dataSource, PoolConfig poolConfig) { + this(dataSource); + this.poolConfig = poolConfig; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public AbstractRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout) { + this(dataSource, connectTimeout, soTimeout); + this.poolConfig = poolConfig; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public AbstractRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + this(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.poolConfig = poolConfig; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public AbstractRedisConnection(DataSource dataSource, PoolConfig poolConfig, SslConfiguration sslConfiguration) { + this(dataSource, sslConfiguration); + this.poolConfig = poolConfig; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout(单位:毫秒) + * 连接超时 + * @param soTimeout(单位:毫秒) + * 读取超时 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public AbstractRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + this(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.poolConfig = poolConfig; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout(单位:毫秒) + * Infinite 读取超时 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public AbstractRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + this(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.poolConfig = poolConfig; + } + + @Override + public DataSource getDataSource() { + return dataSource; + } + + @Override + public void setDataSource(DataSource dataSource) { + this.dataSource = dataSource; + } + + @Override + public PoolConfig getPoolConfig() { + return poolConfig; + } + + @Override + public void setPoolConfig(PoolConfig poolConfig) { + this.poolConfig = poolConfig; + } + + @Override + public int getConnectTimeout() { + return connectTimeout; + } + + @Override + public void setConnectTimeout(int connectTimeout) { + this.connectTimeout = connectTimeout; + } + + @Override + public int getSoTimeout() { + return soTimeout; + } + + @Override + public void setSoTimeout(int soTimeout) { + this.soTimeout = soTimeout; + } + + @Override + public int getInfiniteSoTimeout() { + return infiniteSoTimeout; + } + + @Override + public void setInfiniteSoTimeout(int infiniteSoTimeout) { + this.infiniteSoTimeout = infiniteSoTimeout; + } + + @Override + public boolean isUseSsl() { + return sslConfiguration != null; + } + + @Override + public SslConfiguration getSslConfiguration() { + return sslConfiguration; + } + + @Override + public void setSslConfiguration(SslConfiguration sslConfiguration) { + this.sslConfiguration = sslConfiguration; + } + + @Override + public Status connect() throws RedisConnectionFailureException { + logger.info("Connection redis server."); + + try{ + initialized(); + doConnect(); + + return Status.SUCCESS; + }catch(Exception e){ + logger.error("Connection redis server error: {}.", e.getMessage()); + throw new RedisConnectionFailureException(e.getMessage(), e); + } + } + + @Override + public void destroy() throws IOException { + logger.info("Destroy redis server."); + doDestroy(); + } + + @Override + public void close() throws IOException { + logger.info("Closing redis server."); + doClose(); + } + + protected void initialized() { + if(initialized == false){ + synchronized(this){ + if(initialized == false){ + internalInit(); + initialized = true; + } + } + } + } + + protected abstract void internalInit(); + + protected abstract void doConnect() throws RedisConnectionFailureException; + + protected abstract void doDestroy() throws IOException; + + protected abstract void doClose() throws IOException; + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/ConnectionSplittingInterceptor.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/ConnectionSplittingInterceptor.java new file mode 100644 index 000000000..f3dc20af7 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/ConnectionSplittingInterceptor.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2021 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection; + +import org.aopalliance.intercept.MethodInvocation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cglib.proxy.MethodProxy; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** + * @author Yong.Teng + */ +class ConnectionSplittingInterceptor implements org.aopalliance.intercept.MethodInterceptor, + org.springframework.cglib.proxy.MethodInterceptor { + + private final RedisConnectionFactory factory; + + private final static Logger logger = LoggerFactory.getLogger(ConnectionSplittingInterceptor.class); + + public ConnectionSplittingInterceptor(RedisConnectionFactory factory){ + this.factory = factory; + } + + @Override + public Object intercept(Object instance, Method method, Object[] args, MethodProxy proxy) throws Throwable{ + if(logger.isDebugEnabled()){ + logger.debug("Invoke '{}' on unbound connection.", method.getName()); + } + + RedisConnection connection = factory.getConnection(); + + try{ + return invoke(method, connection, args); + }finally{ + if(connection.isClosed() == false){ + connection.close(); + } + } + } + + private Object invoke(Method method, Object target, Object[] args) throws Throwable{ + try{ + return method.invoke(target, args); + }catch(InvocationTargetException e){ + throw e.getCause(); + } + } + + @Override + public Object invoke(MethodInvocation invocation) throws Throwable{ + return intercept(invocation.getThis(), invocation.getMethod(), invocation.getArguments(), null); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/JedisConnectionFactory.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/JedisConnectionFactory.java new file mode 100644 index 000000000..b0fc47fee --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/JedisConnectionFactory.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection; + +import com.buession.redis.client.connection.datasource.jedis.JedisClusterDataSource; +import com.buession.redis.client.connection.datasource.jedis.JedisDataSource; +import com.buession.redis.client.connection.datasource.jedis.JedisRedisDataSource; +import com.buession.redis.client.connection.datasource.jedis.JedisSentinelDataSource; +import com.buession.redis.client.connection.jedis.JedisClusterConnection; +import com.buession.redis.client.connection.jedis.JedisConnection; +import com.buession.redis.client.connection.jedis.JedisSentinelConnection; +import com.buession.redis.exception.RedisConnectionFailureException; + +/** + * Jedis Redis 连接工厂 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisConnectionFactory extends AbstractConnectionFactory { + + public JedisConnectionFactory(final JedisRedisDataSource dataSource) { + super(dataSource); + } + + @Override + public RedisStandaloneConnection getStandaloneConnection() { + final JedisDataSource dataSource = (JedisDataSource) getDataSource(); + + if(dataSource.getPoolConfig() == null){ + return new JedisConnection(dataSource, dataSource.getConnectTimeout(), dataSource.getSoTimeout(), + dataSource.getInfiniteSoTimeout(), dataSource.getSslConfiguration()); + }else{ + return new JedisConnection(dataSource, dataSource.getPoolConfig(), dataSource.getConnectTimeout(), + dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), dataSource.getSslConfiguration()); + } + } + + @Override + public RedisSentinelConnection getSentinelConnection() { + if(isRedisSentinelAware()){ + final JedisSentinelDataSource dataSource = (JedisSentinelDataSource) getDataSource(); + + if(dataSource.getPoolConfig() == null){ + return new JedisSentinelConnection(dataSource, dataSource.getConnectTimeout(), + dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), + dataSource.getSentinelConnectTimeout(), dataSource.getSentinelSoTimeout(), + dataSource.getSslConfiguration()); + }else{ + return new JedisSentinelConnection(dataSource, dataSource.getPoolConfig(), + dataSource.getConnectTimeout(), dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), + dataSource.getSentinelConnectTimeout(), dataSource.getSentinelSoTimeout(), + dataSource.getSslConfiguration()); + } + } + + throw new RedisConnectionFailureException("No Sentinels datasource"); + } + + @Override + public RedisClusterConnection getClusterConnection() { + if(isRedisClusterAware()){ + final JedisClusterDataSource dataSource = (JedisClusterDataSource) getDataSource(); + + if(dataSource.getPoolConfig() == null){ + return new JedisClusterConnection(dataSource, dataSource.getConnectTimeout(), + dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), dataSource.getMaxRedirects(), + dataSource.getMaxTotalRetriesDuration(), dataSource.getSslConfiguration()); + }else{ + return new JedisClusterConnection(dataSource, dataSource.getPoolConfig(), + dataSource.getConnectTimeout(), dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), + dataSource.getMaxRedirects(), dataSource.getMaxTotalRetriesDuration(), + dataSource.getSslConfiguration()); + } + } + + throw new RedisConnectionFailureException("No Cluster datasource"); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/LettuceConnectionFactory.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/LettuceConnectionFactory.java new file mode 100644 index 000000000..55e08a653 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/LettuceConnectionFactory.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection; + +import com.buession.redis.client.connection.datasource.jedis.JedisSentinelDataSource; +import com.buession.redis.client.connection.datasource.lettuce.LettuceClusterDataSource; +import com.buession.redis.client.connection.datasource.lettuce.LettuceDataSource; +import com.buession.redis.client.connection.datasource.lettuce.LettuceRedisDataSource; +import com.buession.redis.client.connection.jedis.JedisSentinelConnection; +import com.buession.redis.client.connection.lettuce.LettuceClusterConnection; +import com.buession.redis.client.connection.lettuce.LettuceConnection; +import com.buession.redis.exception.RedisConnectionFailureException; + +/** + * Lettuce Redis 连接工厂 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceConnectionFactory extends AbstractConnectionFactory { + + public LettuceConnectionFactory(final LettuceRedisDataSource dataSource) { + super(dataSource); + } + + @Override + public RedisStandaloneConnection getStandaloneConnection() { + final LettuceDataSource dataSource = (LettuceDataSource) getDataSource(); + + if(dataSource.getPoolConfig() == null){ + return new LettuceConnection(dataSource, dataSource.getConnectTimeout(), dataSource.getSoTimeout(), + dataSource.getInfiniteSoTimeout(), dataSource.getSslConfiguration()); + }else{ + return new LettuceConnection(dataSource, dataSource.getPoolConfig(), dataSource.getConnectTimeout(), + dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), dataSource.getSslConfiguration()); + } + } + + @Override + public RedisSentinelConnection getSentinelConnection() { + if(isRedisSentinelAware()){ + final JedisSentinelDataSource dataSource = (JedisSentinelDataSource) getDataSource(); + + if(dataSource.getPoolConfig() == null){ + return new JedisSentinelConnection(dataSource, dataSource.getConnectTimeout(), + dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), + dataSource.getSentinelConnectTimeout(), dataSource.getSentinelSoTimeout(), + dataSource.getSslConfiguration()); + }else{ + return new JedisSentinelConnection(dataSource, dataSource.getPoolConfig(), + dataSource.getConnectTimeout(), dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), + dataSource.getSentinelConnectTimeout(), dataSource.getSentinelSoTimeout(), + dataSource.getSslConfiguration()); + } + } + + throw new RedisConnectionFailureException("No Sentinels datasource"); + } + + @Override + public RedisClusterConnection getClusterConnection() { + if(isRedisClusterAware()){ + final LettuceClusterDataSource dataSource = (LettuceClusterDataSource) getDataSource(); + + if(dataSource.getPoolConfig() == null){ + return new LettuceClusterConnection(dataSource, dataSource.getConnectTimeout(), + dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), dataSource.getMaxRedirects(), + dataSource.getMaxTotalRetriesDuration(), dataSource.getSslConfiguration()); + }else{ + return new LettuceClusterConnection(dataSource, dataSource.getPoolConfig(), + dataSource.getConnectTimeout(), dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), + dataSource.getMaxRedirects(), dataSource.getMaxTotalRetriesDuration(), + dataSource.getSslConfiguration()); + } + } + + throw new RedisConnectionFailureException("No Cluster datasource"); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisClusterConnection.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisClusterConnection.java new file mode 100644 index 000000000..d25ca4d4a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisClusterConnection.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection; + +import com.buession.redis.core.RedisMode; +import com.buession.redis.core.command.Command; +import com.buession.redis.exception.NotSupportedCommandException; +import com.buession.redis.exception.RedisException; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.transaction.Transaction; + +import java.util.List; + +/** + * Redis 集群连接器 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public interface RedisClusterConnection extends RedisConnection { + + /** + * 返回最大重定向次数 + * + * @return 最大重定向次数 + */ + int getMaxRedirects(); + + /** + * 设置最大重定向次数 + * + * @param maxRedirects + * 最大重定向次数 + */ + void setMaxRedirects(int maxRedirects); + + /** + * 返回最大重试持续时长(单位:秒) + * + * @return 最大重试持续时长 + */ + int getMaxTotalRetriesDuration(); + + /** + * 设置最大重试持续时长(单位:秒) + * + * @param maxTotalRetriesDuration + * 最大重试持续时长 + */ + void setMaxTotalRetriesDuration(int maxTotalRetriesDuration); + + @Override + default Pipeline openPipeline() { + throw new NotSupportedCommandException("Pipeline is currently not supported for JedisClusterConnection."); + } + + @Override + default void closePipeline() { + throw new NotSupportedCommandException("Pipeline is currently not supported for JedisClusterConnection."); + } + + @Override + default Transaction multi() { + throw new NotSupportedCommandException(RedisMode.CLUSTER, Command.MULTI); + } + + @Override + default List exec() throws RedisException { + throw new NotSupportedCommandException(RedisMode.CLUSTER, Command.EXEC); + } + + @Override + default void discard() throws RedisException { + throw new NotSupportedCommandException(RedisMode.CLUSTER, Command.DISCARD); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisConnection.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisConnection.java new file mode 100644 index 000000000..dc57cd3de --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisConnection.java @@ -0,0 +1,239 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection; + +import com.buession.core.Destroyable; +import com.buession.core.Executor; +import com.buession.lang.Status; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.datasource.DataSource; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.exception.RedisConnectionFailureException; +import com.buession.redis.exception.RedisException; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.transaction.Transaction; + +import java.io.Closeable; +import java.util.List; + +/** + * Redis 连接对象 + * + * @author Yong.Teng + */ +public interface RedisConnection extends Destroyable, Closeable { + + /** + * 获取 Redis 数据源 + * + * @return Redis 数据源 + */ + DataSource getDataSource(); + + /** + * 设置 Redis 数据源 + * + * @param dataSource + * Redis 数据源 + */ + void setDataSource(DataSource dataSource); + + /** + * 返回连接池配置 + * + * @return 连接池配置 + * + * @since 3.0.0 + */ + PoolConfig getPoolConfig(); + + /** + * 连接池配置 + * + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + void setPoolConfig(PoolConfig poolConfig); + + /** + * 获取连接超时 + * + * @return 连接超时(单位:毫秒) + */ + int getConnectTimeout(); + + /** + * 设置连接超时 + * + * @param connectTimeout + * 连接超时(单位:毫秒) + */ + void setConnectTimeout(int connectTimeout); + + /** + * 设置读取超时 + * + * @return 读取超时(单位:毫秒) + */ + int getSoTimeout(); + + /** + * 设置读取超时 + * + * @param soTimeout + * 读取超时(单位:毫秒) + */ + void setSoTimeout(int soTimeout); + + /** + * 返回 Infinite 读取超时 + * + * @return Infinite 读取超时(单位:毫秒) + */ + int getInfiniteSoTimeout(); + + /** + * 设置 Infinite 读取超时 + * + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + void setInfiniteSoTimeout(int infiniteSoTimeout); + + /** + * 返回是否启用 SSL 连接 + * + * @return 启用 SSL 连接,返回 true; 否则,返回 false + */ + boolean isUseSsl(); + + /** + * SSL 配置 + * + * @return SSL 配置 + */ + SslConfiguration getSslConfiguration(); + + /** + * 设置 SSL 配置 + * + * @param sslConfiguration + * SSL 配置 + */ + void setSslConfiguration(SslConfiguration sslConfiguration); + + /** + * 连接 Redis + * + * @return 连接成功,则返回 Status.SUCCESS; 否则,返回 Status.FAILURE + * + * @throws RedisConnectionFailureException + * Redis 连接失败异常 + */ + Status connect() throws RedisConnectionFailureException; + + /** + * 执行 Redis 命令 + * + * @param executor + * 命令执行器 + * @param + * 返回值类型 + * + * @return 不同命令,返回不同的结果 + * + * @throws RedisException + * Redis Exception + */ + R execute(final Executor executor) throws RedisException; + + /** + * 当前是否处于管道状态 + * + * @return 处于管道状态,则返回 true; 否则,返回 false + */ + boolean isPipeline(); + + /** + * 打开管道 + * + * @return 管道 + */ + Pipeline openPipeline(); + + /** + * 关闭管道 + */ + void closePipeline(); + + /** + * 当前是否处于事务状态 + * + * @return 处于事务状态,则返回 true; 否则,返回 false + */ + boolean isTransaction(); + + /** + * 标记事务开始 + * + * @return 事务 + */ + Transaction multi(); + + /** + * 执行所有事务块内的命令 + * + * @return 事务块内所有命令的返回值 + * + * @throws RedisException + * Redis Exception + */ + List exec() throws RedisException; + + /** + * 取消事务 + * + * @throws RedisException + * Redis Exception + */ + void discard() throws RedisException; + + /** + * 检测是否处于连接状态 + * + * @return 是否处于连接状态 + */ + boolean isConnect(); + + /** + * 检测连接是否关闭 + * + * @return 连接是否关闭 + */ + boolean isClosed(); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisConnectionFactory.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisConnectionFactory.java new file mode 100644 index 000000000..be8a7b6af --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisConnectionFactory.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection; + +/** + * Redis 连接工厂 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface RedisConnectionFactory { + + /** + * 返回 Redis 连接对象 + * + * @return Redis 连接对象 + */ + RedisConnection getConnection(); + + /** + * 返回 Redis 单机连接对象 + * + * @return Redis 单机连接对象 + */ + RedisStandaloneConnection getStandaloneConnection(); + + /** + * 返回 Redis 哨兵连接对象 + * + * @return Redis 哨兵连接对象 + */ + RedisSentinelConnection getSentinelConnection(); + + /** + * 返回 Redis 集群连接对象 + * + * @return Redis 集群连接对象 + */ + RedisClusterConnection getClusterConnection(); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisConnectionHolder.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisConnectionHolder.java new file mode 100644 index 000000000..1716de0a0 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisConnectionHolder.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection; + +import org.springframework.transaction.support.ResourceHolder; + +/** + * @author Yong.Teng + */ +public class RedisConnectionHolder implements ResourceHolder { + + private boolean unbound; + + private final RedisConnection connection; + + private boolean transactionSyncronisationActive; + + public RedisConnectionHolder(RedisConnection connection){ + this.connection = connection; + } + + public boolean isTransactionSyncronisationActive(){ + return getTransactionSyncronisationActive(); + } + + public boolean getTransactionSyncronisationActive(){ + return transactionSyncronisationActive; + } + + public void setTransactionSyncronisationActive(boolean transactionSyncronisationActive){ + this.transactionSyncronisationActive = transactionSyncronisationActive; + } + + public RedisConnection getConnection(){ + return connection; + } + + @Override + public void reset(){ + } + + @Override + public void unbound(){ + unbound = true; + } + + @Override + public boolean isVoid(){ + return unbound; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisConnectionUtils.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisConnectionUtils.java new file mode 100644 index 000000000..d25948e56 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisConnectionUtils.java @@ -0,0 +1,229 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection; + +import com.buession.core.utils.Assert; +import com.buession.redis.core.RedisMode; +import com.buession.redis.exception.RedisConnectionFailureException; +import com.buession.redis.transaction.TransactionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.aop.framework.ProxyFactory; +import org.springframework.lang.Nullable; + +import java.io.IOException; + +/** + * @author Yong.Teng + */ +public final class RedisConnectionUtils { + + private final static Logger logger = LoggerFactory.getLogger(RedisConnectionUtils.class); + + private RedisConnectionUtils() { + } + + /** + * 根据连接器获取 Redis 模式 + * + * @param connection + * 连接器 + * + * @return Redis 模式 + */ + public static RedisMode getRedisMode(final RedisConnection connection) { + if(connection instanceof RedisSentinelConnection){ + return RedisMode.SENTINEL; + }else if(connection instanceof RedisClusterConnection){ + return RedisMode.CLUSTER; + }else{ + return RedisMode.STANDALONE; + } + } + + public static RedisConnection bindConnection(final RedisConnectionFactory factory) { + return bindConnection(factory, false); + } + + public static RedisConnection bindConnection(final RedisConnectionFactory factory, + final boolean enableTransactionSupport) { + return doGetConnection(factory, true, true, enableTransactionSupport); + } + + public static RedisConnection getConnection(final RedisConnectionFactory factory) { + return getConnection(factory, false); + } + + public static RedisConnection getConnection(final RedisConnectionFactory factory, + final boolean enableTransactionSupport) { + return doGetConnection(factory, true, false, enableTransactionSupport); + } + + public static boolean isConnectionTransactional(final RedisConnectionFactory factory, + final RedisConnection connection) { + Assert.isNull(factory, "No RedisConnectionFactory specified"); + RedisConnectionHolder connHolder = TransactionUtils.getResource(factory); + return (connHolder != null && connection == connHolder.getConnection()); + } + + public static void releaseConnection(final RedisConnectionFactory factory, + final @Nullable RedisConnection connection, final boolean transactionSupport) { + if(connection == null){ + logger.error("Redis connection is null."); + return; + } + + RedisConnectionHolder connectionHolder = TransactionUtils.getResource(factory); + + if(connectionHolder != null && connectionHolder.isTransactionSyncronisationActive()){ + logger.debug("Redis Connection will be closed when transaction finished."); + return; + } + + if(isConnectionTransactional(factory, connection)){ + if(transactionSupport && TransactionUtils.isCurrentTransactionReadOnly()){ + logger.debug("Unbinding Redis Connection."); + unbindConnection(factory); + }else{ + logger.debug("Leaving bound Redis Connection attached."); + } + }else{ + logger.debug("Closing Redis Connection"); + connectionClose(connection); + } + } + + public static void unbindConnection(final RedisConnectionFactory factory) { + RedisConnectionHolder connectionHolder = TransactionUtils.unbindResourceIfPossible(factory); + if(connectionHolder == null){ + return; + } + + if(connectionHolder.isTransactionSyncronisationActive()){ + logger.debug("Redis Connection will be closed when outer transaction finished."); + }else{ + logger.debug("Closing bound connection."); + connectionClose(connectionHolder.getConnection()); + } + } + + private static RedisConnection doGetConnection(final RedisConnectionFactory factory, final boolean allowCreate, + final boolean bind, final boolean enableTransactionSupport) { + Assert.isNull(factory, "No RedisConnectionFactory specified"); + + RedisConnectionHolder connectionHolder = TransactionUtils.getResource(factory); + + if(connectionHolder != null){ + if(enableTransactionSupport){ + potentiallyRegisterTransactionSynchronisation(factory, connectionHolder); + } + + logger.debug("Reopening Redis RedisConnection from transaction resource."); + + return connectionHolder.getConnection(); + } + + Assert.isFalse(allowCreate, "No redisConnection found and allowCreate = false"); + + logger.debug("Opening Redis RedisConnection."); + + RedisConnection connection = factory.getConnection(); + + long startTime = 0; + if(logger.isDebugEnabled()){ + startTime = System.nanoTime(); + } + + if(connection.isConnect() == false){ + try{ + connection.connect(); + }catch(RedisConnectionFailureException e){ + logger.error("Redis connection failure: {}", e.getMessage()); + throw e; + }finally{ + if(logger.isDebugEnabled()){ + long finishTime = System.nanoTime(); + logger.debug("Connection redis execution time: {}", finishTime - startTime); + } + } + } + + if(bind){ + RedisConnection redisConnectionToBind = connection; + + if(enableTransactionSupport && TransactionUtils.isActualNonReadonlyTransactionActive()){ + redisConnectionToBind = createConnectionProxy(factory, connection); + } + + connectionHolder = new RedisConnectionHolder(redisConnectionToBind); + + TransactionUtils.bindResource(factory, connectionHolder); + if(enableTransactionSupport){ + potentiallyRegisterTransactionSynchronisation(factory, connectionHolder); + } + + logger.debug("Bind RedisConnectionHolder."); + return connectionHolder.getConnection(); + } + + return connection; + } + + private static void potentiallyRegisterTransactionSynchronisation(final RedisConnectionFactory factory, + final RedisConnectionHolder connectionHolder) { + if(TransactionUtils.isActualNonReadonlyTransactionActive() && + connectionHolder.isTransactionSyncronisationActive() == false){ + connectionHolder.setTransactionSyncronisationActive(true); + + RedisConnection connection = connectionHolder.getConnection(); + connection.multi(); + + logger.debug("Register Transaction Synchronization."); + TransactionUtils.registerSynchronization(factory, connectionHolder, connection); + } + } + + private static RedisConnection createConnectionProxy(final RedisConnectionFactory factory, + final RedisConnection connection) { + ProxyFactory proxyFactory = new ProxyFactory(connection); + proxyFactory.addAdvice(new ConnectionSplittingInterceptor(factory)); + + logger.debug("Create Redis Connection Proxy."); + return (RedisConnection) proxyFactory.getProxy(); + } + + private static void connectionClose(final RedisConnection connection) { + if(connection == null){ + return; + } + + try{ + connection.close(); + }catch(IOException e){ + logger.error("Closing Redis Connection error.", e); + } + } + +} \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisSentinelConnection.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisSentinelConnection.java new file mode 100644 index 000000000..ac06a874d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisSentinelConnection.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection; + +import com.buession.redis.core.RedisNamedNode; +import com.buession.redis.core.RedisSentinelNode; +import com.buession.redis.core.RedisServer; + +import java.util.List; + +/** + * Redis 哨兵连接器 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public interface RedisSentinelConnection extends RedisConnection { + + /** + * 返回哨兵节点连接超时 + * + * @return 哨兵节点连接超时(单位:毫秒) + */ + int getSentinelConnectTimeout(); + + /** + * 设置哨兵节点连接超时 + * + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + */ + void setSentinelConnectTimeout(int sentinelConnectTimeout); + + /** + * 返回哨兵节点读取超时 + * + * @return 哨兵节点读取超时(单位:毫秒) + */ + int getSentinelSoTimeout(); + + /** + * 设置哨兵节点读取超时 + * + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + */ + void setSentinelSoTimeout(int sentinelSoTimeout); + + /** + * 返回 Master 节点列表 + * + * @return Master 节点列表 + */ + List masters(); + + /** + * 返回 Slave 节点列表 + * + * @param master + * Master 节点 + * + * @return Slave 节点列表 + */ + List slaves(RedisNamedNode master); + + /** + * 返回 Slave 节点列表 + * + * @param masterName + * Master 节点名称 + * + * @return Slave 节点列表 + */ + List slaves(String masterName); + + /** + * failover + * + * @param namedNode + * 节点 + */ + void failover(RedisNamedNode namedNode); + + /** + * 监控节点 + * + * @param server + * 节点 + */ + void monitor(RedisSentinelNode server); + + /** + * 移除节点 + * + * @param master + * 节点 + */ + void remove(RedisNamedNode master); + + /** + * 移除节点 + * + * @param masterName + * 节点名称 + */ + void remove(String masterName); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisStandaloneConnection.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisStandaloneConnection.java new file mode 100644 index 000000000..7e5523c30 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/RedisStandaloneConnection.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2021 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection; + +/** + * Redis 单机连接器 + * + * @author Yong.Teng + * @since 1.3.0 + */ +public interface RedisStandaloneConnection extends RedisConnection { + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/AbstractDataSource.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/AbstractDataSource.java new file mode 100644 index 000000000..62cb61480 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/AbstractDataSource.java @@ -0,0 +1,197 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource; + +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.core.Constants; +import com.buession.redis.core.PoolConfig; + +/** + * Redis 数据源抽象类 + * + * @author Yong.Teng + */ +public abstract class AbstractDataSource implements DataSource { + + /** + * 用户名 + */ + private String username; + + /** + * 密码 + */ + private String password; + + /** + * 客户端名称 + */ + private String clientName; + + /** + * 连接超时(单位:毫秒) + */ + private int connectTimeout = Constants.DEFAULT_CONNECT_TIMEOUT; + + /** + * 读取超时(单位:毫秒) + */ + private int soTimeout = Constants.DEFAULT_SO_TIMEOUT; + + /** + * Infinite 读取超时(单位:毫秒) + * + * @since 2.0.0 + */ + private int infiniteSoTimeout = Constants.DEFAULT_INFINITE_SO_TIMEOUT; + + /** + * 连接池配置 + * + * @since 2.0.0 + */ + private PoolConfig poolConfig; + + /** + * SSL 配置 + * + * @since 2.0.0 + */ + private SslConfiguration sslConfiguration; + + /** + * 返回用户名 + * + * @return 用户名 + */ + @Override + public String getUsername() { + return username; + } + + /** + * 设置用户名 + * + * @param username + * 用户名 + */ + @Override + public void setUsername(String username) { + this.username = username; + } + + /** + * 返回密码 + * + * @return 密码 + */ + @Override + public String getPassword() { + return password; + } + + /** + * 设置密码 + * + * @param password + * 密码 + */ + @Override + public void setPassword(String password) { + this.password = password; + } + + /** + * 返回客户端名称 + * + * @return 客户端名称 + */ + @Override + public String getClientName() { + return clientName; + } + + /** + * 设置客户端名称 + * + * @param clientName + * 客户端名称 + */ + @Override + public void setClientName(String clientName) { + this.clientName = clientName; + } + + @Override + public int getConnectTimeout() { + return connectTimeout; + } + + @Override + public void setConnectTimeout(int connectTimeout) { + this.connectTimeout = connectTimeout; + } + + @Override + public int getSoTimeout() { + return soTimeout; + } + + @Override + public void setSoTimeout(int soTimeout) { + this.soTimeout = soTimeout; + } + + @Override + public int getInfiniteSoTimeout() { + return infiniteSoTimeout; + } + + @Override + public void setInfiniteSoTimeout(int infiniteSoTimeout) { + this.infiniteSoTimeout = infiniteSoTimeout; + } + + @Override + public PoolConfig getPoolConfig() { + return poolConfig; + } + + @Override + public void setPoolConfig(PoolConfig poolConfig) { + this.poolConfig = poolConfig; + } + + @Override + public SslConfiguration getSslConfiguration() { + return sslConfiguration; + } + + @Override + public void setSslConfiguration(SslConfiguration sslConfiguration) { + this.sslConfiguration = sslConfiguration; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/ClusterDataSource.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/ClusterDataSource.java new file mode 100644 index 000000000..855c073cd --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/ClusterDataSource.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource; + +import com.buession.redis.core.RedisNode; + +import java.util.List; + +/** + * Redis 集群(Cluster)模式数据源 + * + * @author Yong.Teng + */ +public interface ClusterDataSource extends DataSource { + + /** + * 默认最大重定向次数 + */ + int DEFAULT_MAX_REDIRECTS = 5; + + /** + * 获取集群主机节点 + * + * @return 集群主机节点 + */ + List getNodes(); + + /** + * 设置集群主机节点 + * + * @param nodes + * 集群主机节点 + */ + void setNodes(List nodes); + + /** + * 返回最大重定向次数 + * + * @return 最大重定向次数 + */ + int getMaxRedirects(); + + /** + * 设置最大重定向次数 + * + * @param maxRedirects + * 最大重定向次数 + */ + void setMaxRedirects(int maxRedirects); + + /** + * 返回最大重试持续时长(单位:秒) + * + * @return 最大重试持续时长 + */ + int getMaxTotalRetriesDuration(); + + /** + * 设置最大重试持续时长(单位:秒) + * + * @param maxTotalRetriesDuration + * 最大重试持续时长 + */ + void setMaxTotalRetriesDuration(int maxTotalRetriesDuration); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/DataSource.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/DataSource.java new file mode 100644 index 000000000..279322258 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/DataSource.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource; + +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.core.PoolConfig; + +/** + * Redis 数据源 + * + * @author Yong.Teng + */ +public interface DataSource { + + /** + * 返回用户名 + * + * @return 用户名 + */ + String getUsername(); + + /** + * 设置用户名 + * + * @param username + * 用户名 + */ + void setUsername(String username); + + /** + * 返回密码 + * + * @return 密码 + */ + String getPassword(); + + /** + * 设置密码 + * + * @param password + * 密码 + */ + void setPassword(String password); + + /** + * 返回客户端名称 + * + * @return 客户端名称 + */ + String getClientName(); + + /** + * 设置客户端名称 + * + * @param clientName + * 客户端名称 + */ + void setClientName(String clientName); + + /** + * 获取连接超时 + * + * @return 连接超时(单位:毫秒) + */ + int getConnectTimeout(); + + /** + * 设置连接超时 + * + * @param connectTimeout + * 连接超时(单位:毫秒) + */ + void setConnectTimeout(int connectTimeout); + + /** + * 设置读取超时 + * + * @return 读取超时(单位:毫秒) + */ + int getSoTimeout(); + + /** + * 设置读取超时 + * + * @param soTimeout + * 读取超时(单位:毫秒) + */ + void setSoTimeout(int soTimeout); + + /** + * 返回 Infinite 读取超时 + * + * @return Infinite 读取超时(单位:毫秒) + */ + int getInfiniteSoTimeout(); + + /** + * 设置 Infinite 读取超时 + * + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + void setInfiniteSoTimeout(int infiniteSoTimeout); + + /** + * 返回连接池配置 + * + * @return 连接池配置 + * + * @since 2.0.0 + */ + PoolConfig getPoolConfig(); + + /** + * 设置连接池配置 + * + * @param poolConfig + * 连接池配置 + * + * @since 2.0.0 + */ + void setPoolConfig(PoolConfig poolConfig); + + /** + * 返回 SSL 配置 + * + * @return SSL 配置 + * + * @since 2.0.0 + */ + SslConfiguration getSslConfiguration(); + + /** + * 设置 SSL 配置 + * + * @param sslConfiguration + * SSL 配置 + * + * @since 2.0.0 + */ + void setSslConfiguration(SslConfiguration sslConfiguration); + + /** + * 获取 Redis 连接实例 {@link RedisConnection} + * + * @return Redis 连接实例 {@link RedisConnection} + * + * @since 2.0.0 + */ + @Deprecated + RedisConnection getConnection(); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/SentinelDataSource.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/SentinelDataSource.java new file mode 100644 index 000000000..1c37d9e80 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/SentinelDataSource.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource; + +import com.buession.redis.core.RedisNode; + +import java.util.List; + +/** + * Redis 哨兵(Sentinel)模式数据源 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public interface SentinelDataSource extends DataSource { + + /** + * 获取数据库 + * + * @return 数据库 + */ + int getDatabase(); + + /** + * 设置数据库 + * + * @param database + * 数据库 + */ + void setDatabase(int database); + + /** + * 返回哨兵节点连接超时(单位:秒) + * + * @return 哨兵节点连接超时 + */ + int getSentinelConnectTimeout(); + + /** + * 设置哨兵节点连接超时 + * + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:秒) + */ + void setSentinelConnectTimeout(int sentinelConnectTimeout); + + /** + * 返回哨兵节点读取超时(单位:秒) + * + * @return 哨兵节点读取超时 + */ + int getSentinelSoTimeout(); + + /** + * 设置哨兵节点读取超时 + * + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:秒) + */ + void setSentinelSoTimeout(int sentinelSoTimeout); + + /** + * 返回 Sentinel Client Name + * + * @return Sentinel Client Name + */ + String getSentinelClientName(); + + /** + * 设置 Sentinel Client Name + * + * @param sentinelClientName + * Sentinel Client Name + */ + void setSentinelClientName(String sentinelClientName); + + /** + * 返回 Master 名称 + * + * @return Master 名称 + */ + String getMasterName(); + + /** + * 设置 Master 名称 + * + * @param masterName + * Master 名称 + */ + void setMasterName(String masterName); + + /** + * 返回哨兵节点 + * + * @return 哨兵节点 + */ + List getSentinels(); + + /** + * 设置哨兵节点 + * + * @param sentinels + * 哨兵节点 + */ + void setSentinels(List sentinels); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/StandaloneDataSource.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/StandaloneDataSource.java new file mode 100644 index 000000000..8a5b16b65 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/StandaloneDataSource.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2020 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource; + +/** + * Redis 单机(Standalone)模式数据源 + * + * @author Yong.Teng + */ +public interface StandaloneDataSource extends DataSource { + + /** + * 返回 Redis 主机地址 + * + * @return Redis 主机地址 + */ + String getHost(); + + /** + * 设置 Redis 主机地址 + * + * @param host + * Redis 主机地址 + */ + void setHost(String host); + + /** + * 返回 Redis 端口 + * + * @return Redis 端口 + */ + int getPort(); + + /** + * 设置 Redis 端口 + * + * @param port + * Redis 端口 + */ + void setPort(int port); + + /** + * 返回数据库 + * + * @return 数据库 + */ + int getDatabase(); + + /** + * 设置数据库 + * + * @param database + * 数据库 + */ + void setDatabase(int database); + +} diff --git a/buession-core/src/main/java/com/buession/core/BuesssionFrameworkVersion.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/AbstractJedisDataSource.java similarity index 85% rename from buession-core/src/main/java/com/buession/core/BuesssionFrameworkVersion.java rename to buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/AbstractJedisDataSource.java index 10c6fd5d6..44799966a 100644 --- a/buession-core/src/main/java/com/buession/core/BuesssionFrameworkVersion.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/AbstractJedisDataSource.java @@ -22,20 +22,15 @@ * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.core; +package com.buession.redis.client.connection.datasource.jedis; + +import com.buession.redis.client.connection.datasource.AbstractDataSource; /** + * Jedis 数据源抽象类 + * * @author Yong.Teng */ -@Deprecated -public final class BuesssionFrameworkVersion { - - private BuesssionFrameworkVersion() { - - } - - public static String getVersion() { - return BuessionFrameworkVersion.getVersion(); - } +public abstract class AbstractJedisDataSource extends AbstractDataSource implements JedisRedisDataSource { } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/JedisClusterDataSource.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/JedisClusterDataSource.java new file mode 100644 index 000000000..8097a6c53 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/JedisClusterDataSource.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource.jedis; + +import com.buession.redis.client.connection.datasource.ClusterDataSource; +import com.buession.redis.client.connection.jedis.JedisClusterConnection; +import com.buession.redis.core.RedisNode; + +import java.util.List; + +/** + * Jedis 集群模式数据源 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public class JedisClusterDataSource extends AbstractJedisDataSource implements ClusterDataSource { + + /** + * 集群主机节点 + */ + private List nodes; + + /** + * 最大重定向次数 + */ + private int maxRedirects = DEFAULT_MAX_REDIRECTS; + + /** + * 最大重数时长(单位:秒) + */ + private int maxTotalRetriesDuration = -1; + + @Override + public List getNodes() { + return nodes; + } + + @Override + public void setNodes(List nodes) { + this.nodes = nodes; + } + + @Override + public int getMaxRedirects() { + return maxRedirects; + } + + @Override + public void setMaxRedirects(int maxRedirects) { + this.maxRedirects = maxRedirects; + } + + @Override + public int getMaxTotalRetriesDuration() { + return maxTotalRetriesDuration; + } + + @Override + public void setMaxTotalRetriesDuration(int maxTotalRetriesDuration) { + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + @Deprecated + @Override + public JedisClusterConnection getConnection() { + if(getPoolConfig() == null){ + return new JedisClusterConnection(this, getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getMaxRedirects(), getMaxTotalRetriesDuration(), getSslConfiguration()); + }else{ + return new JedisClusterConnection(this, getPoolConfig(), getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getMaxRedirects(), getMaxTotalRetriesDuration(), getSslConfiguration()); + } + } + +} \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/JedisDataSource.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/JedisDataSource.java new file mode 100644 index 000000000..c2184f2ce --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/JedisDataSource.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource.jedis; + +import com.buession.redis.client.connection.datasource.StandaloneDataSource; +import com.buession.redis.client.connection.jedis.JedisConnection; +import com.buession.redis.core.RedisNode; + +/** + * Jedis 单机模式数据源 + * + * @author Yong.Teng + */ +public class JedisDataSource extends AbstractJedisDataSource implements StandaloneDataSource { + + /** + * Redis 主机地址 + */ + private String host = RedisNode.DEFAULT_HOST; + + /** + * Redis 端口 + */ + private int port = RedisNode.DEFAULT_PORT; + + /** + * 数据库 + */ + private int database = RedisNode.DEFAULT_DATABASE; + + @Override + public String getHost() { + return host; + } + + @Override + public void setHost(String host) { + this.host = host; + } + + @Override + public int getPort() { + return port; + } + + @Override + public void setPort(int port) { + this.port = port; + } + + @Override + public int getDatabase() { + return database; + } + + @Override + public void setDatabase(int database) { + this.database = database; + } + + @Deprecated + @Override + public JedisConnection getConnection() { + if(getPoolConfig() == null){ + return new JedisConnection(this, getConnectTimeout(), getSoTimeout(), getInfiniteSoTimeout(), + getSslConfiguration()); + }else{ + return new JedisConnection(this, getPoolConfig(), getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getSslConfiguration()); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/JedisRedisDataSource.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/JedisRedisDataSource.java new file mode 100644 index 000000000..26ad1c507 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/JedisRedisDataSource.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2021 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource.jedis; + +import com.buession.redis.client.connection.datasource.DataSource; + +/** + * Jedis 数据源 + * + * @author Yong.Teng + */ +public interface JedisRedisDataSource extends DataSource { + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/JedisSentinelDataSource.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/JedisSentinelDataSource.java new file mode 100644 index 000000000..5f97c4672 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/JedisSentinelDataSource.java @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource.jedis; + +import com.buession.redis.client.connection.datasource.SentinelDataSource; +import com.buession.redis.client.connection.jedis.JedisSentinelConnection; +import com.buession.redis.core.Constants; +import com.buession.redis.core.RedisNode; +import redis.clients.jedis.JedisSentinelPool; + +import java.util.List; + +/** + * Jedis 哨兵模式数据源 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public class JedisSentinelDataSource extends AbstractJedisDataSource implements SentinelDataSource { + + /** + * 数据库 + */ + private int database = RedisNode.DEFAULT_DATABASE; + + /** + * 哨兵节点连接超时(单位:毫秒) + */ + private int sentinelConnectTimeout = Constants.DEFAULT_CONNECT_TIMEOUT; + + /** + * 哨兵节点读取超时(单位:毫秒) + */ + private int sentinelSoTimeout = Constants.DEFAULT_SO_TIMEOUT; + + /** + * Sentinel Client Name + */ + private String sentinelClientName; + + /** + * Master 名称 + */ + private String masterName; + + /** + * 哨兵节点 + */ + private List sentinels; + + private JedisSentinelPool pool; + + @Override + public int getDatabase() { + return database; + } + + @Override + public void setDatabase(int database) { + this.database = database; + } + + @Override + public int getSentinelConnectTimeout() { + return sentinelConnectTimeout; + } + + @Override + public void setSentinelConnectTimeout(int sentinelConnectTimeout) { + this.sentinelConnectTimeout = sentinelConnectTimeout; + } + + @Override + public int getSentinelSoTimeout() { + return sentinelSoTimeout; + } + + @Override + public void setSentinelSoTimeout(int sentinelSoTimeout) { + this.sentinelSoTimeout = sentinelSoTimeout; + } + + @Override + public String getSentinelClientName() { + return sentinelClientName; + } + + @Override + public void setSentinelClientName(String sentinelClientName) { + this.sentinelClientName = sentinelClientName; + } + + @Override + public String getMasterName() { + return masterName; + } + + @Override + public void setMasterName(String masterName) { + this.masterName = masterName; + } + + @Override + public List getSentinels() { + return sentinels; + } + + @Override + public void setSentinels(List sentinels) { + this.sentinels = sentinels; + } + + @Deprecated + @Override + public JedisSentinelConnection getConnection() { + if(getPoolConfig() == null){ + return new JedisSentinelConnection(this, getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getSentinelConnectTimeout(), getSentinelSoTimeout(), getSslConfiguration()); + }else{ + return new JedisSentinelConnection(this, getPoolConfig(), getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getSentinelConnectTimeout(), getSentinelSoTimeout(), getSslConfiguration()); + } + } + +} diff --git a/buession-web/src/test/java/com/buession/web/mvc/ResponseTest.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/package-info.java similarity index 95% rename from buession-web/src/test/java/com/buession/web/mvc/ResponseTest.java rename to buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/package-info.java index d03b86181..8da28783f 100644 --- a/buession-web/src/test/java/com/buession/web/mvc/ResponseTest.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/jedis/package-info.java @@ -22,12 +22,7 @@ * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.web.mvc; - /** * @author Yong.Teng - * @since 0.0.1 */ -public class ResponseTest { - -} +package com.buession.redis.client.connection.datasource.jedis; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/AbstractLettuceDataSource.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/AbstractLettuceDataSource.java new file mode 100644 index 000000000..7b67f5abe --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/AbstractLettuceDataSource.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource.lettuce; + +import com.buession.redis.client.connection.datasource.AbstractDataSource; + +/** + * Lettuce 数据源抽象类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractLettuceDataSource extends AbstractDataSource implements LettuceRedisDataSource { + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/LettuceClusterDataSource.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/LettuceClusterDataSource.java new file mode 100644 index 000000000..530843818 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/LettuceClusterDataSource.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource.lettuce; + +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.client.connection.datasource.ClusterDataSource; +import com.buession.redis.client.connection.lettuce.LettuceClusterConnection; +import com.buession.redis.client.connection.lettuce.LettuceSentinelConnection; +import com.buession.redis.core.RedisNode; + +import java.util.List; + +/** + * Lettuce 集群模式数据源 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceClusterDataSource extends AbstractLettuceDataSource implements ClusterDataSource { + + /** + * 集群主机节点 + */ + private List nodes; + + /** + * 最大重定向次数 + */ + private int maxRedirects = DEFAULT_MAX_REDIRECTS; + + /** + * 最大重数时长(单位:秒) + */ + private int maxTotalRetriesDuration = -1; + + @Override + public List getNodes() { + return nodes; + } + + @Override + public void setNodes(List nodes) { + this.nodes = nodes; + } + + @Override + public int getMaxRedirects() { + return maxRedirects; + } + + @Override + public void setMaxRedirects(int maxRedirects) { + this.maxRedirects = maxRedirects; + } + + @Override + public int getMaxTotalRetriesDuration() { + return maxTotalRetriesDuration; + } + + @Override + public void setMaxTotalRetriesDuration(int maxTotalRetriesDuration) { + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + @Deprecated + @Override + public RedisConnection getConnection() { + if(getPoolConfig() == null){ + return new LettuceClusterConnection(this, getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getMaxRedirects(), getMaxTotalRetriesDuration(), getSslConfiguration()); + }else{ + return new LettuceClusterConnection(this, getPoolConfig(), getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getMaxRedirects(), getMaxTotalRetriesDuration(), getSslConfiguration()); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/LettuceDataSource.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/LettuceDataSource.java new file mode 100644 index 000000000..6d37786e8 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/LettuceDataSource.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource.lettuce; + +import com.buession.redis.client.connection.datasource.StandaloneDataSource; +import com.buession.redis.client.connection.lettuce.LettuceConnection; +import com.buession.redis.core.RedisNode; + +/** + * Lettuce 单机模式数据源 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceDataSource extends AbstractLettuceDataSource implements StandaloneDataSource { + + /** + * Redis 主机地址 + */ + private String host = RedisNode.DEFAULT_HOST; + + /** + * Redis 端口 + */ + private int port = RedisNode.DEFAULT_PORT; + + /** + * 数据库 + */ + private int database = RedisNode.DEFAULT_DATABASE; + + @Override + public String getHost() { + return host; + } + + @Override + public void setHost(String host) { + this.host = host; + } + + @Override + public int getPort() { + return port; + } + + @Override + public void setPort(int port) { + this.port = port; + } + + @Override + public int getDatabase() { + return database; + } + + @Override + public void setDatabase(int database) { + this.database = database; + } + + @Deprecated + @Override + public LettuceConnection getConnection() { + if(getPoolConfig() == null){ + return new LettuceConnection(this, getConnectTimeout(), getSoTimeout(), getInfiniteSoTimeout(), + getSslConfiguration()); + }else{ + return new LettuceConnection(this, getPoolConfig(), getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getSslConfiguration()); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/LettuceRedisDataSource.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/LettuceRedisDataSource.java new file mode 100644 index 000000000..a07272b04 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/LettuceRedisDataSource.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource.lettuce; + +import com.buession.redis.client.connection.datasource.DataSource; + +/** + * Lettuce 数据源 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface LettuceRedisDataSource extends DataSource { + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/LettuceSentinelDataSource.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/LettuceSentinelDataSource.java new file mode 100644 index 000000000..47d6879b6 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/LettuceSentinelDataSource.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource.lettuce; + +import com.buession.redis.client.connection.datasource.SentinelDataSource; +import com.buession.redis.client.connection.lettuce.LettuceSentinelConnection; +import com.buession.redis.core.Constants; +import com.buession.redis.core.RedisNode; + +import java.util.List; + +/** + * Lettuce 哨兵模式数据源 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceSentinelDataSource extends AbstractLettuceDataSource implements SentinelDataSource { + + /** + * 数据库 + */ + private int database = RedisNode.DEFAULT_DATABASE; + + /** + * 哨兵节点连接超时(单位:毫秒) + */ + private int sentinelConnectTimeout = Constants.DEFAULT_CONNECT_TIMEOUT; + + /** + * 哨兵节点读取超时(单位:毫秒) + */ + private int sentinelSoTimeout = Constants.DEFAULT_SO_TIMEOUT; + + /** + * Sentinel Client Name + */ + private String sentinelClientName; + + /** + * Master 名称 + */ + private String masterName; + + /** + * 哨兵节点 + */ + private List sentinels; + + @Override + public int getDatabase() { + return database; + } + + @Override + public void setDatabase(int database) { + this.database = database; + } + + @Override + public int getSentinelConnectTimeout() { + return sentinelConnectTimeout; + } + + @Override + public void setSentinelConnectTimeout(int sentinelConnectTimeout) { + this.sentinelConnectTimeout = sentinelConnectTimeout; + } + + @Override + public int getSentinelSoTimeout() { + return sentinelSoTimeout; + } + + @Override + public void setSentinelSoTimeout(int sentinelSoTimeout) { + this.sentinelSoTimeout = sentinelSoTimeout; + } + + @Override + public String getSentinelClientName() { + return sentinelClientName; + } + + @Override + public void setSentinelClientName(String sentinelClientName) { + this.sentinelClientName = sentinelClientName; + } + + @Override + public String getMasterName() { + return masterName; + } + + @Override + public void setMasterName(String masterName) { + this.masterName = masterName; + } + + @Override + public List getSentinels() { + return sentinels; + } + + @Override + public void setSentinels(List sentinels) { + this.sentinels = sentinels; + } + + @Deprecated + @Override + public LettuceSentinelConnection getConnection() { + if(getPoolConfig() == null){ + return new LettuceSentinelConnection(this, getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getSentinelConnectTimeout(), getSentinelSoTimeout(), getSslConfiguration()); + }else{ + return new LettuceSentinelConnection(this, getPoolConfig(), getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getSentinelConnectTimeout(), getSentinelSoTimeout(), getSslConfiguration()); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/package-info.java new file mode 100644 index 000000000..6c094cc10 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/lettuce/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.client.connection.datasource.lettuce; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/package-info.java new file mode 100644 index 000000000..9edb1b0af --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/datasource/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.client.connection.datasource; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/AbstractJedisRedisConnection.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/AbstractJedisRedisConnection.java new file mode 100644 index 000000000..2ef81eb23 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/AbstractJedisRedisConnection.java @@ -0,0 +1,321 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.jedis; + +import com.buession.core.Executor; +import com.buession.redis.client.connection.AbstractRedisConnection; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.client.connection.datasource.DataSource; +import com.buession.redis.client.connection.datasource.jedis.JedisRedisDataSource; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.exception.JedisRedisExceptionUtils; +import com.buession.redis.exception.RedisException; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.transaction.Transaction; + +import java.io.IOException; + +/** + * Jedis Redis 连接对象抽象类 + * + * @author Yong.Teng + */ +public abstract class AbstractJedisRedisConnection extends AbstractRedisConnection implements JedisRedisConnection { + + /** + * 事务 + */ + protected Transaction transaction; + + /** + * 管道 + */ + protected volatile Pipeline pipeline; + + /** + * 构造函数 + */ + public AbstractJedisRedisConnection() { + super(); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + */ + public AbstractJedisRedisConnection(JedisRedisDataSource dataSource) { + super(dataSource); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public AbstractJedisRedisConnection(JedisRedisDataSource dataSource, int connectTimeout, int soTimeout) { + super(dataSource, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * + * @since 2.0.0 + */ + public AbstractJedisRedisConnection(JedisRedisDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param sslConfiguration + * SSL 配置 + */ + public AbstractJedisRedisConnection(JedisRedisDataSource dataSource, SslConfiguration sslConfiguration) { + super(dataSource, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public AbstractJedisRedisConnection(JedisRedisDataSource dataSource, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 2.0.0 + */ + public AbstractJedisRedisConnection(JedisRedisDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public AbstractJedisRedisConnection(PoolConfig poolConfig) { + super(poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public AbstractJedisRedisConnection(DataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public AbstractJedisRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public AbstractJedisRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public AbstractJedisRedisConnection(DataSource dataSource, PoolConfig poolConfig, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout(单位:毫秒) + * 连接超时 + * @param soTimeout(单位:毫秒) + * 读取超时 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public AbstractJedisRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout(单位:毫秒) + * Infinite 读取超时 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public AbstractJedisRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + @Override + public boolean isPipeline() { + return pipeline != null; + } + + @Override + public boolean isTransaction() { + return transaction != null; + } + + @Override + public R execute(final Executor executor) throws RedisException { + try{ + return executor.execute(this); + }catch(Exception e){ + logger.error("Redis execute command failure: {}", e.getMessage(), e); + throw JedisRedisExceptionUtils.convert(e); + } + } + + @Override + protected void doDestroy() throws IOException { + if(pipeline != null){ + pipeline.close(); + pipeline = null; + } + } + + @Override + protected void doClose() throws IOException { + if(pipeline != null){ + pipeline.close(); + pipeline = null; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/JedisClusterConnection.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/JedisClusterConnection.java new file mode 100644 index 000000000..d8e1dd2f5 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/JedisClusterConnection.java @@ -0,0 +1,970 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.jedis; + +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.RedisClusterConnection; +import com.buession.redis.client.connection.datasource.jedis.JedisClusterDataSource; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.core.RedisNode; +import com.buession.redis.core.internal.jedis.JedisClientConfigBuilder; +import com.buession.redis.exception.RedisConnectionFailureException; +import com.buession.redis.exception.RedisException; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.pipeline.jedis.JedisClusterPipeline; +import com.buession.redis.pipeline.jedis.JedisPipelineProxy; +import com.buession.redis.transaction.Transaction; +import com.buession.redis.transaction.jedis.JedisTransaction; +import com.buession.redis.transaction.jedis.JedisTransactionProxy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import redis.clients.jedis.ConnectionPoolConfig; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.JedisClientConfig; +import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.providers.ClusterConnectionProvider; + +import java.io.IOException; +import java.time.Duration; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Jedis 集群模式连接器 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public class JedisClusterConnection extends AbstractJedisRedisConnection implements RedisClusterConnection { + + /** + * 最大重定向次数 + */ + private int maxRedirects; + + /** + * 最大重数时长(单位:毫秒) + */ + private int maxTotalRetriesDuration; + + /** + * 连接提供者 + * + * @since 3.0.0 + */ + private ClusterConnectionProvider connectionProvider; + + /** + * JedisCluster 对象 + */ + private JedisCluster cluster; + + private final static Logger logger = LoggerFactory.getLogger(JedisClusterConnection.class); + + /** + * 构造函数 + */ + public JedisClusterConnection() { + super(); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource) { + super(dataSource); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout) { + super(dataSource, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int maxRedirects) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.maxRedirects = maxRedirects; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration) { + this(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, maxRedirects); + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param sslConfiguration + * SSL 配置 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, SslConfiguration sslConfiguration) { + super(dataSource, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param sslConfiguration + * SSL 配置 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int maxRedirects, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param cluster + * {@link JedisCluster} + */ + @Deprecated + public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster) { + super(dataSource); + this.cluster = cluster; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param cluster + * {@link JedisCluster} + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + @Deprecated + public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, + int soTimeout) { + super(dataSource, connectTimeout, soTimeout); + this.cluster = cluster; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param cluster + * {@link JedisCluster} + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + @Deprecated + public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, + int soTimeout, int infiniteSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.cluster = cluster; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param cluster + * {@link JedisCluster} + * @param sslConfiguration + * SSL 配置 + */ + @Deprecated + public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, + SslConfiguration sslConfiguration) { + super(dataSource, sslConfiguration); + this.cluster = cluster; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param cluster + * {@link JedisCluster} + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + @Deprecated + public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, + int soTimeout, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.cluster = cluster; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param cluster + * {@link JedisCluster} + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + @Deprecated + public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, + int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.cluster = cluster; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param maxRedirects + * 最大重试次数 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, int maxRedirects) { + super(dataSource); + this.maxRedirects = maxRedirects; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param maxRedirects + * 最大重试次数 + * @param sslConfiguration + * SSL 配置 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, int maxRedirects, + SslConfiguration sslConfiguration) { + this(dataSource, sslConfiguration); + this.maxRedirects = maxRedirects; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param cluster + * {@link JedisCluster} + * @param maxRedirects + * 最大重试次数 + */ + @Deprecated + public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int maxRedirects) { + this(dataSource, cluster); + this.maxRedirects = maxRedirects; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param cluster + * {@link JedisCluster} + * @param maxRedirects + * 最大重试次数 + * @param sslConfiguration + * SSL 配置 + */ + @Deprecated + public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int maxRedirects, + SslConfiguration sslConfiguration) { + this(dataSource, cluster, sslConfiguration); + this.maxRedirects = maxRedirects; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param cluster + * {@link JedisCluster} + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数(单位:毫秒) + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + */ + @Deprecated + public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, + int soTimeout, int maxRedirects, int maxTotalRetriesDuration) { + this(dataSource, cluster, connectTimeout, soTimeout); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param cluster + * {@link JedisCluster} + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + @Deprecated + public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, + int soTimeout, int maxRedirects, int maxTotalRetriesDuration, + SslConfiguration sslConfiguration) { + this(dataSource, cluster, connectTimeout, soTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param cluster + * {@link JedisCluster} + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + */ + @Deprecated + public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration) { + this(dataSource, cluster, connectTimeout, soTimeout, infiniteSoTimeout); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param cluster + * {@link JedisCluster} + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + @Deprecated + public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration, + SslConfiguration sslConfiguration) { + this(dataSource, cluster, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(PoolConfig poolConfig) { + super(poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param maxRedirects + * 最大重试次数 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int maxRedirects) { + super(dataSource, poolConfig); + this.maxRedirects = maxRedirects; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param maxRedirects + * 最大重试次数 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int maxRedirects, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + this.maxRedirects = maxRedirects; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数(单位:毫秒) + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int maxRedirects, int maxTotalRetriesDuration) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int maxRedirects, int maxTotalRetriesDuration, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + @Override + public int getMaxRedirects() { + return maxRedirects; + } + + @Override + public void setMaxRedirects(int maxRedirects) { + this.maxRedirects = maxRedirects; + } + + @Override + public int getMaxTotalRetriesDuration() { + return maxTotalRetriesDuration; + } + + @Override + public void setMaxTotalRetriesDuration(int maxTotalRetriesDuration) { + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + public JedisCluster getCluster() { + return cluster; + } + + @Override + public Pipeline openPipeline() { + if(pipeline == null){ + final redis.clients.jedis.ClusterPipeline pipelineObject = cluster.pipelined(); + pipeline = new JedisPipelineProxy<>(new JedisClusterPipeline(pipelineObject), pipelineObject); + } + + return pipeline; + } + + @Override + public Transaction multi() { + if(transaction == null){ + final redis.clients.jedis.Transaction tran = cluster.multi(); + transaction = new JedisTransactionProxy(new JedisTransaction(tran), tran); + } + + return transaction; + } + + @Override + public List exec() throws RedisException { + if(transaction != null){ + final List result = transaction.exec(); + + transaction.close(); + transaction = null; + + return result; + }else{ + throw new RedisException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + @Override + public void discard() throws RedisException { + if(transaction != null){ + transaction.discard(); + transaction = null; + }else{ + throw new RedisException("ERR DISCARD without MULTI. Did you forget to call multi?"); + } + } + + @Override + public boolean isConnect() { + return cluster != null; + } + + @Override + public boolean isClosed() { + return cluster == null; + } + + @Override + protected void internalInit() { + if(cluster == null){ + connectionProvider = createConnectionProvider(); + } + } + + protected boolean isUsePool() { + return getPoolConfig() != null; + } + + @Override + protected void doConnect() throws RedisConnectionFailureException { + cluster = new JedisCluster(connectionProvider, getMaxRedirects(), + Duration.ofMillis(getMaxTotalRetriesDuration())); + } + + protected ClusterConnectionProvider createConnectionProvider() { + final JedisClusterDataSource dataSource = (JedisClusterDataSource) getDataSource(); + final JedisClientConfig clientConfig = JedisClientConfigBuilder.create(dataSource, getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .build(); + final Set nodes = createHostAndPorts(dataSource); + + if(isUsePool()){ + final ConnectionPoolConfig connectionPoolConfig = new ConnectionPoolConfig(); + + getPoolConfig().toGenericObjectPoolConfig(connectionPoolConfig); + + return new ClusterConnectionProvider(nodes, clientConfig, connectionPoolConfig); + }else{ + return new ClusterConnectionProvider(nodes, clientConfig); + } + } + + @Override + protected void doDestroy() throws IOException { + super.doDestroy(); + logger.info("Jedis cluster destroy."); + } + + @Override + protected void doClose() throws IOException { + super.doClose(); + + logger.info("Jedis cluster close."); + if(cluster != null){ + cluster.close(); + } + } + + private static Set createHostAndPorts(final JedisClusterDataSource clusterDataSource) { + return clusterDataSource.getNodes().stream().map((node)->{ + int port = node.getPort() == 0 ? RedisNode.DEFAULT_PORT : node.getPort(); + return new HostAndPort(node.getHost(), port); + }).collect(Collectors.toSet()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/JedisConnection.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/JedisConnection.java new file mode 100644 index 000000000..3618b16f0 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/JedisConnection.java @@ -0,0 +1,593 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.jedis; + +import com.buession.redis.client.connection.RedisStandaloneConnection; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.datasource.jedis.JedisDataSource; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.core.internal.jedis.JedisClientConfigBuilder; +import com.buession.redis.exception.RedisConnectionFailureException; +import com.buession.redis.exception.RedisException; +import com.buession.redis.exception.JedisRedisExceptionUtils; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.pipeline.jedis.JedisPipeline; +import com.buession.redis.pipeline.jedis.JedisPipelineProxy; +import com.buession.redis.transaction.Transaction; +import com.buession.redis.transaction.jedis.JedisTransaction; +import com.buession.redis.transaction.jedis.JedisTransactionProxy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import redis.clients.jedis.DefaultJedisClientConfig; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; + +import java.io.IOException; +import java.util.List; + +/** + * Jedis 单机模式连接器 + * + * @author Yong.Teng + */ +public class JedisConnection extends AbstractJedisRedisConnection implements RedisStandaloneConnection { + + /** + * 连接池 + */ + private JedisPool pool; + + /** + * Jedis 对象 + */ + private Jedis jedis; + + private final static Logger logger = LoggerFactory.getLogger(JedisConnection.class); + + /** + * 构造函数 + */ + public JedisConnection() { + super(); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + */ + public JedisConnection(JedisDataSource dataSource) { + super(dataSource); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public JedisConnection(JedisDataSource dataSource, int connectTimeout, int soTimeout) { + super(dataSource, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * + * @since 2.0.0 + */ + public JedisConnection(JedisDataSource dataSource, int connectTimeout, int soTimeout, int infiniteSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param sslConfiguration + * SSL 配置 + */ + public JedisConnection(JedisDataSource dataSource, SslConfiguration sslConfiguration) { + super(dataSource, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public JedisConnection(JedisDataSource dataSource, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 2.0.0 + */ + public JedisConnection(JedisDataSource dataSource, int connectTimeout, int soTimeout, int infiniteSoTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + */ + @Deprecated + public JedisConnection(JedisDataSource dataSource, JedisPool pool) { + super(dataSource); + this.pool = pool; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + @Deprecated + public JedisConnection(JedisDataSource dataSource, JedisPool pool, int connectTimeout, int soTimeout) { + super(dataSource, connectTimeout, soTimeout); + this.pool = pool; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + @Deprecated + public JedisConnection(JedisDataSource dataSource, JedisPool pool, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.pool = pool; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + * @param sslConfiguration + * SSL 配置 + */ + @Deprecated + public JedisConnection(JedisDataSource dataSource, JedisPool pool, SslConfiguration sslConfiguration) { + super(dataSource, sslConfiguration); + this.pool = pool; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + @Deprecated + public JedisConnection(JedisDataSource dataSource, JedisPool pool, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.pool = pool; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + @Deprecated + public JedisConnection(JedisDataSource dataSource, JedisPool pool, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.pool = pool; + } + + /** + * 构造函数 + * + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public JedisConnection(PoolConfig poolConfig) { + super(poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public JedisConnection(JedisDataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisConnection(JedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisConnection(JedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisConnection(JedisDataSource dataSource, PoolConfig poolConfig, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisConnection(JedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisConnection(JedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + public Jedis getJedis() { + return jedis; + } + + @Override + public Pipeline openPipeline() { + if(pipeline == null){ + final redis.clients.jedis.Pipeline pipelineObject = jedis.pipelined(); + pipeline = new JedisPipelineProxy<>(new JedisPipeline(pipelineObject), pipelineObject); + } + + return pipeline; + } + + @Override + public void closePipeline() { + pipeline.close(); + pipeline = null; + } + + @Override + public Transaction multi() { + System.out.println("transaction: " + (transaction == null ? "false" : "true")); + if(transaction == null){ + final redis.clients.jedis.Transaction tran = jedis.multi(); + transaction = new JedisTransactionProxy(new JedisTransaction(tran), tran); + } + + return transaction; + } + + @Override + public List exec() throws RedisException { + if(pipeline != null){ + final List result = pipeline.syncAndReturnAll(); + + pipeline.close(); + pipeline = null; + + return result; + }else if(transaction != null){ + final List result = transaction.exec(); + + transaction.close(); + transaction = null; + + return result; + }else{ + throw new RedisException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + @Override + public void discard() throws RedisException { + if(transaction != null){ + transaction.discard(); + transaction = null; + }else{ + throw new RedisException("ERR DISCARD without MULTI. Did you forget to call multi?"); + } + } + + @Override + public boolean isConnect() { + return jedis != null && jedis.isConnected(); + } + + @Override + public boolean isClosed() { + return jedis == null || jedis.isConnected() == false; + } + + @Override + protected void internalInit() { + if(pool == null && getPoolConfig() != null){ + pool = createPool(); + } + } + + protected boolean isUsePool() { + return pool != null; + } + + @Override + protected void doConnect() throws RedisConnectionFailureException { + if(isUsePool()){ + try{ + jedis = pool.getResource(); + + if(logger.isInfoEnabled()){ + logger.info("Jedis initialized with pool success."); + } + }catch(Exception e){ + if(logger.isErrorEnabled()){ + logger.error("Jedis initialized with pool failure: {}", e.getMessage(), e); + } + + throw JedisRedisExceptionUtils.convert(e); + } + }else{ + final JedisDataSource dataSource = (JedisDataSource) getDataSource(); + final DefaultJedisClientConfig clientConfig = JedisClientConfigBuilder.create(dataSource, + getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .database(dataSource.getDatabase()) + .build(); + + jedis = new Jedis(dataSource.getHost(), dataSource.getPort(), clientConfig); + } + } + + protected JedisPool createPool() { + final JedisDataSource dataSource = (JedisDataSource) getDataSource(); + final JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); + final HostAndPort hostAndPort = new HostAndPort(dataSource.getHost(), dataSource.getPort()); + final DefaultJedisClientConfig clientConfig = JedisClientConfigBuilder.create(dataSource, + getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .database(dataSource.getDatabase()) + .build(); + + getPoolConfig().toGenericObjectPoolConfig(jedisPoolConfig); + + if(getSslConfiguration() == null){ + logger.debug("Create JedisPool."); + }else{ + logger.debug("Create JedisPool with ssl."); + } + + return new JedisPool(jedisPoolConfig, hostAndPort, clientConfig); + } + + @Override + protected void doDestroy() throws IOException { + super.doDestroy(); + + logger.info("Jedis destroy."); + if(pool != null){ + if(logger.isInfoEnabled()){ + logger.info("Jedis pool for {} destroy.", pool.getClass().getName()); + } + + try{ + pool.destroy(); + }catch(Exception ex){ + logger.warn("Cannot properly close Jedis pool.", ex); + } + + pool = null; + } + } + + @Override + protected void doClose() throws IOException { + super.doClose(); + + if(isUsePool()){ + logger.info("Jedis close."); + + if(jedis != null){ + jedis.close(); + } + }else{ + logger.info("Jedis disconnect."); + + if(jedis != null){ + Exception ex = null; + + try{ + jedis.disconnect(); + }catch(Exception e){ + ex = e; + } + + if(ex != null){ + throw new RedisException(ex); + } + } + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/JedisRedisConnection.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/JedisRedisConnection.java new file mode 100644 index 000000000..9eeeeeb10 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/JedisRedisConnection.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.jedis; + +import com.buession.redis.client.connection.RedisConnection; + +/** + * Jedis Redis 连接对象 + * + * @author Yong.Teng + */ +public interface JedisRedisConnection extends RedisConnection { + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/JedisSentinelConnection.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/JedisSentinelConnection.java new file mode 100644 index 000000000..cc4622061 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/JedisSentinelConnection.java @@ -0,0 +1,1133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.jedis; + +import com.buession.core.utils.Assert; +import com.buession.core.validator.Validate; +import com.buession.redis.client.connection.RedisSentinelConnection; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.datasource.DataSource; +import com.buession.redis.client.connection.datasource.jedis.JedisSentinelDataSource; +import com.buession.redis.core.Constants; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.core.RedisNamedNode; +import com.buession.redis.core.RedisNode; +import com.buession.redis.core.RedisSentinelNode; +import com.buession.redis.core.RedisServer; +import com.buession.redis.core.Role; +import com.buession.redis.core.internal.jedis.JedisClientConfigBuilder; +import com.buession.redis.exception.RedisConnectionFailureException; +import com.buession.redis.exception.RedisException; +import com.buession.redis.exception.JedisRedisExceptionUtils; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.pipeline.jedis.JedisPipeline; +import com.buession.redis.pipeline.jedis.JedisPipelineProxy; +import com.buession.redis.transaction.Transaction; +import com.buession.redis.transaction.jedis.JedisTransaction; +import com.buession.redis.transaction.jedis.JedisTransactionProxy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import redis.clients.jedis.DefaultJedisClientConfig; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisClientConfig; +import redis.clients.jedis.JedisPoolConfig; +import redis.clients.jedis.JedisSentinelPool; +import redis.clients.jedis.exceptions.JedisException; + +import java.io.IOException; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Jedis 哨兵模式连接器 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public class JedisSentinelConnection extends AbstractJedisRedisConnection implements RedisSentinelConnection { + + /** + * 哨兵节点连接超时(单位:毫秒) + */ + private int sentinelConnectTimeout = Constants.DEFAULT_CONNECT_TIMEOUT; + + /** + * 哨兵节点读取超时(单位:毫秒) + */ + private int sentinelSoTimeout = Constants.DEFAULT_SO_TIMEOUT; + + /** + * 连接池 + */ + private JedisSentinelPool pool; + + /** + * Jedis 对象 + */ + private Jedis jedis; + + private final static Logger logger = LoggerFactory.getLogger(JedisSentinelConnection.class); + + /** + * 构造函数 + */ + public JedisSentinelConnection() { + super(); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource) { + super(dataSource); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTimeout, int soTimeout) { + super(dataSource, connectTimeout, soTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * + * @since 2.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param sslConfiguration + * SSL 配置 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, SslConfiguration sslConfiguration) { + super(dataSource, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 2.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + */ + @Deprecated + public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool) { + super(dataSource); + this.pool = pool; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + @Deprecated + public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, + int soTimeout) { + super(dataSource, connectTimeout, soTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + this.pool = pool; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + @Deprecated + public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, + int soTimeout, int infiniteSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + this.pool = pool; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + * @param sslConfiguration + * SSL 配置 + */ + @Deprecated + public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, + SslConfiguration sslConfiguration) { + super(dataSource, sslConfiguration); + this.pool = pool; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + @Deprecated + public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, + int soTimeout, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + this.pool = pool; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + @Deprecated + public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, + int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + this.pool = pool; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int sentinelConnectTimeout, int sentinelSoTimeout) { + super(dataSource, connectTimeout, soTimeout); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int sentinelConnectTimeout, int sentinelSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int sentinelConnectTimeout, int sentinelSoTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int sentinelConnectTimeout, int sentinelSoTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + */ + @Deprecated + public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, + int soTimeout, int sentinelConnectTimeout, int sentinelSoTimeout) { + this(dataSource, pool, connectTimeout, soTimeout); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + */ + @Deprecated + public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int sentinelConnectTimeout, + int sentinelSoTimeout) { + this(dataSource, pool, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + @Deprecated + public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, + int soTimeout, int sentinelConnectTimeout, int sentinelSoTimeout, + SslConfiguration sslConfiguration) { + this(dataSource, pool, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param pool + * 连接池 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + @Deprecated + public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int sentinelConnectTimeout, + int sentinelSoTimeout, SslConfiguration sslConfiguration) { + this(dataSource, pool, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public JedisSentinelConnection(PoolConfig poolConfig) { + super(poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int sentinelConnectTimeout, int sentinelSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int sentinelConnectTimeout, + int sentinelSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int sentinelConnectTimeout, int sentinelSoTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int sentinelConnectTimeout, + int sentinelSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + @Override + public int getSentinelConnectTimeout() { + return sentinelConnectTimeout; + } + + @Override + public void setSentinelConnectTimeout(int sentinelConnectTimeout) { + this.sentinelConnectTimeout = sentinelConnectTimeout; + } + + @Override + public int getSentinelSoTimeout() { + return sentinelSoTimeout; + } + + @Override + public void setSentinelSoTimeout(int sentinelSoTimeout) { + this.sentinelSoTimeout = sentinelSoTimeout; + } + + @Override + public List masters() { + DataSource dataSource = getDataSource(); + if(dataSource == null){ + return null; + } + + final List> masterNodes = Objects.requireNonNull(createSentinelJedis( + (JedisSentinelDataSource) dataSource)).sentinelMasters(); + return parseRedisServer(masterNodes, Role.MASTER); + } + + @Override + public List slaves(RedisNamedNode master) { + Assert.isNull(master, "Redis master node cloud not be 'null' for loading slaves."); + return slaves(master.getName()); + } + + @Override + public List slaves(String masterName) { + Assert.isBlank(masterName, "Redis master name cloud not be 'null' or empty for loading slaves."); + + DataSource dataSource = getDataSource(); + if(dataSource == null){ + return null; + } + + final List> slaveNodes = Objects.requireNonNull(createSentinelJedis( + (JedisSentinelDataSource) dataSource)).sentinelSlaves(masterName); + return parseRedisServer(slaveNodes, Role.SLAVE); + } + + @Override + public void failover(RedisNamedNode namedNode) { + Assert.isNull(namedNode, "Redis master node cloud not be 'null' for failover."); + Assert.isBlank(namedNode.getName(), "Redis master name cloud not be 'null' or empty for failover."); + + DataSource dataSource = getDataSource(); + if(dataSource == null){ + return; + } + + Objects.requireNonNull(createSentinelJedis((JedisSentinelDataSource) dataSource)) + .sentinelFailover(namedNode.getName()); + } + + @Override + public void monitor(RedisSentinelNode server) { + Assert.isNull(server, "Cannot monitor 'null' server."); + Assert.isBlank(server.getName(), "Name of server to monitor must not be 'null' or empty."); + Assert.isBlank(server.getHost(), "Host must not be 'null' for server to monitor."); + + DataSource dataSource = getDataSource(); + if(dataSource == null){ + return; + } + + Objects.requireNonNull(createSentinelJedis((JedisSentinelDataSource) dataSource)) + .sentinelMonitor(server.getName(), server.getHost(), server.getPort(), server.getQuorum()); + } + + public Jedis getJedis() { + return jedis; + } + + @Override + public Pipeline openPipeline() { + if(pipeline == null){ + final redis.clients.jedis.Pipeline pipelineObject = jedis.pipelined(); + pipeline = new JedisPipelineProxy<>(new JedisPipeline(pipelineObject), pipelineObject); + } + + return pipeline; + } + + @Override + public void closePipeline() { + pipeline.close(); + pipeline = null; + } + + @Override + public Transaction multi() { + if(transaction == null){ + final redis.clients.jedis.Transaction tran = jedis.multi(); + transaction = new JedisTransactionProxy(new JedisTransaction(tran), tran); + } + + return transaction; + } + + @Override + public List exec() throws RedisException { + if(transaction != null){ + final List result = transaction.exec(); + + transaction.close(); + transaction = null; + + return result; + }else{ + throw new RedisException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + @Override + public void discard() throws RedisException { + if(transaction != null){ + transaction.discard(); + transaction = null; + }else{ + throw new RedisException("ERR DISCARD without MULTI. Did you forget to call multi?"); + } + } + + @Override + public void remove(RedisNamedNode master) { + Assert.isNull(master, "Master node cloud be 'null' when trying to remove."); + remove(master.getName()); + } + + @Override + public void remove(String masterName) { + Assert.isBlank(masterName, "Redis master name cloud be 'null' or empty when trying to remove."); + jedis.sentinelRemove(masterName); + } + + @Override + public boolean isConnect() { + return jedis != null && jedis.isConnected(); + } + + @Override + public boolean isClosed() { + return jedis == null || jedis.isConnected() == false; + } + + @Override + protected void internalInit() { + if(pool == null && getPoolConfig() != null){ + pool = createPool(); + } + } + + protected boolean isUsePool() { + return pool != null; + } + + private Jedis createSentinelJedis(final JedisSentinelDataSource dataSource) { + final JedisClientConfig sentinelClientConfig = createSentinelJedisClientConfig(dataSource); + + for(RedisNode node : dataSource.getSentinels()){ + int port = node.getPort() == 0 ? RedisNode.DEFAULT_SENTINEL_PORT : node.getPort(); + HostAndPort sentinel = new HostAndPort(node.getHost(), port); + try(Jedis jedis = new Jedis(sentinel, sentinelClientConfig)){ + return jedis; + }catch(JedisException e){ + logger.warn("Cannot get master address from sentinel running @ {}. Reason: {}. Trying next one.", + sentinel, e); + } + } + + return null; + } + + protected Jedis createJedis() { + final JedisSentinelDataSource dataSource = (JedisSentinelDataSource) getDataSource(); + final JedisClientConfig sentinelClientConfig = createSentinelJedisClientConfig(dataSource); + final DefaultJedisClientConfig clientConfig = JedisClientConfigBuilder.create(dataSource, + getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .database(dataSource.getDatabase()) + .build(); + boolean sentinelAvailable = false; + + for(RedisNode node : dataSource.getSentinels()){ + int port = node.getPort() == 0 ? RedisNode.DEFAULT_SENTINEL_PORT : node.getPort(); + HostAndPort sentinel = new HostAndPort(node.getHost(), port); + try(Jedis jedis = new Jedis(sentinel, sentinelClientConfig)){ + List masterAddr = jedis.sentinelGetMasterAddrByName(dataSource.getMasterName()); + sentinelAvailable = true; + + if(masterAddr == null || masterAddr.size() != 2){ + logger.warn("Can not get master addr, master name: {}. Sentinel: {}", dataSource.getMasterName(), + node); + continue; + } + + return new Jedis(new HostAndPort(masterAddr.get(0), Integer.parseInt(masterAddr.get(1))), + clientConfig); + } + } + + if(sentinelAvailable){ + throw new RedisConnectionFailureException("Can connect to sentinel, but " + dataSource.getMasterName() + + " seems to be not monitored..."); + }else{ + throw new RedisConnectionFailureException("All sentinels down, cannot determine where is " + + dataSource.getMasterName() + " master is running..."); + } + } + + @Override + protected void doConnect() throws RedisConnectionFailureException { + if(isUsePool()){ + try{ + jedis = pool.getResource(); + + if(logger.isInfoEnabled()){ + logger.info("Jedis initialized with pool success."); + } + }catch(Exception e){ + if(logger.isErrorEnabled()){ + logger.error("Jedis initialized with pool failure: {}", e.getMessage(), e); + } + + throw JedisRedisExceptionUtils.convert(e); + } + }else{ + jedis = createJedis(); + } + } + + protected JedisSentinelPool createPool() { + final JedisSentinelDataSource dataSource = (JedisSentinelDataSource) getDataSource(); + final JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); + final Set sentinels = createSentinelHosts(dataSource.getSentinels()); + final JedisClientConfig clientConfig = JedisClientConfigBuilder.create(dataSource, getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .database(dataSource.getDatabase()) + .build(); + final JedisClientConfig sentinelClientConfig = createSentinelJedisClientConfig(dataSource); + + getPoolConfig().toGenericObjectPoolConfig(jedisPoolConfig); + + if(getSslConfiguration() == null){ + logger.debug("Create JedisSentinelPool."); + }else{ + logger.debug("Create JedisSentinelPool with ssl."); + } + + return new JedisSentinelPool(dataSource.getMasterName(), sentinels, jedisPoolConfig, clientConfig, + sentinelClientConfig); + } + + @Override + protected void doDestroy() throws IOException { + super.doDestroy(); + + logger.info("Jedis destroy."); + if(pool != null){ + if(logger.isInfoEnabled()){ + logger.info("Jedis sentinel pool for {} destroy.", pool.getClass().getName()); + } + + try{ + pool.destroy(); + }catch(Exception ex){ + logger.warn("Cannot properly close Jedis sentinel pool.", ex); + } + + pool = null; + } + } + + @Override + protected void doClose() throws IOException { + super.doClose(); + + if(isUsePool()){ + logger.info("Jedis close."); + + if(jedis != null){ + jedis.close(); + } + }else{ + logger.info("Jedis disconnect."); + + if(jedis != null){ + Exception ex = null; + + try{ + jedis.disconnect(); + }catch(Exception e){ + ex = e; + } + + if(ex != null){ + throw new RedisException(ex); + } + } + } + } + + protected JedisClientConfig createSentinelJedisClientConfig(final JedisSentinelDataSource dataSource) { + return JedisClientConfigBuilder.create(dataSource, getSslConfiguration()) + .connectTimeout(getSentinelConnectTimeout()) + .socketTimeout(getSentinelSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .clientName(dataSource.getSentinelClientName()) + .build(); + } + + protected Set createSentinelHosts(final Collection sentinelNodes) { + if(Validate.isEmpty(sentinelNodes)){ + return Collections.emptySet(); + } + + return sentinelNodes.stream().filter(Objects::nonNull).map(node->{ + int port = node.getPort() == 0 ? RedisNode.DEFAULT_SENTINEL_PORT : node.getPort(); + return new HostAndPort(node.getHost(), port); + }).collect(Collectors.toSet()); + } + + protected List parseRedisServer(final List> nodes, final Role role) { + if(nodes == null){ + return null; + } + + return nodes.stream().map((node)->{ + Properties properties = new Properties(); + properties.putAll(node); + + RedisServer redisServer = new RedisServer(node.get("ip"), Integer.parseInt(node.get("port")), properties); + redisServer.setName(node.get("name")); + redisServer.setRole(role); + + return redisServer; + }).collect(Collectors.toList()); + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/nio/protocol/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/package-info.java similarity index 96% rename from buession-httpclient/src/main/java/com/buession/httpclient/apache/nio/protocol/package-info.java rename to buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/package-info.java index 859f9cf1c..6a1246e6f 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/apache/nio/protocol/package-info.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/jedis/package-info.java @@ -25,4 +25,4 @@ /** * @author Yong.Teng */ -package com.buession.httpclient.apache.nio.protocol; \ No newline at end of file +package com.buession.redis.client.connection.jedis; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/AbstractLettuceRedisConnection.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/AbstractLettuceRedisConnection.java new file mode 100644 index 000000000..70241b8cc --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/AbstractLettuceRedisConnection.java @@ -0,0 +1,303 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.lettuce; + +import com.buession.core.Executor; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.AbstractRedisConnection; +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.client.connection.datasource.lettuce.LettuceRedisDataSource; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.exception.LettuceRedisExceptionUtils; +import com.buession.redis.exception.RedisException; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.transaction.Transaction; + +import java.io.IOException; + +/** + * Lettuce Redis 连接对象抽象类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractLettuceRedisConnection extends AbstractRedisConnection implements LettuceRedisConnection { + + /** + * 事务 + */ + protected Transaction transaction; + + /** + * 管道 + */ + protected volatile Pipeline pipeline; + + /** + * 构造函数 + */ + public AbstractLettuceRedisConnection() { + super(); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource) { + super(dataSource); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, int connectTimeout, int soTimeout) { + super(dataSource, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param sslConfiguration + * SSL 配置 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, SslConfiguration sslConfiguration) { + super(dataSource, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param poolConfig + * 连接池配置 + */ + public AbstractLettuceRedisConnection(PoolConfig poolConfig) { + super(poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, PoolConfig poolConfig, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + @Override + public boolean isPipeline() { + return pipeline != null; + } + + @Override + public boolean isTransaction() { + return transaction != null; + } + + @Override + public R execute(final Executor executor) throws RedisException { + try{ + return executor.execute(this); + }catch(Exception e){ + logger.error("Redis execute command failure: {}", e.getMessage(), e); + throw LettuceRedisExceptionUtils.convert(e); + } + } + + @Override + protected void doDestroy() throws IOException { + if(pipeline != null){ + pipeline.close(); + pipeline = null; + } + } + + @Override + protected void doClose() throws IOException { + if(pipeline != null){ + pipeline.close(); + pipeline = null; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/LettuceClusterConnection.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/LettuceClusterConnection.java new file mode 100644 index 000000000..b1bf2f3e3 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/LettuceClusterConnection.java @@ -0,0 +1,707 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.lettuce; + +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.validator.Validate; +import com.buession.net.HostAndPort; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.RedisClusterConnection; +import com.buession.redis.client.connection.datasource.lettuce.LettuceClusterDataSource; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.core.RedisNode; +import com.buession.redis.core.internal.lettuce.LettuceClientConfigBuilder; +import com.buession.redis.exception.LettuceRedisExceptionUtils; +import com.buession.redis.exception.RedisConnectionFailureException; +import com.buession.redis.exception.RedisException; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.pipeline.lettuce.LettucePipeline; +import com.buession.redis.pipeline.lettuce.LettucePipelineProxy; +import com.buession.redis.transaction.Transaction; +import io.lettuce.core.LettuceClientConfig; +import io.lettuce.core.LettuceClusterPool; +import io.lettuce.core.LettucePoolConfig; +import io.lettuce.core.RedisCredentialsProvider; +import io.lettuce.core.RedisURI; +import io.lettuce.core.StaticCredentialsProvider; +import io.lettuce.core.api.PipeliningFlushPolicy; +import io.lettuce.core.api.PipeliningFlushState; +import io.lettuce.core.cluster.RedisClusterClient; +import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; +import io.lettuce.core.codec.ByteArrayCodec; +import io.lettuce.core.codec.RedisCodec; +import io.lettuce.core.support.ConnectionPoolUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.time.Duration; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Lettuce 集群模式连接器 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceClusterConnection extends AbstractLettuceRedisConnection implements RedisClusterConnection { + + /** + * 最大重定向次数 + */ + private int maxRedirects; + + /** + * 最大重数时长(单位:毫秒) + */ + private int maxTotalRetriesDuration; + + /** + * 连接池 + */ + private LettuceClusterPool pool; + + /** + * {@link StatefulRedisClusterConnection} 实例 + */ + private StatefulRedisClusterConnection delegate; + + private final PipeliningFlushPolicy pipeliningFlushPolicy = PipeliningFlushPolicy.flushEachCommand(); + + private final static Logger logger = LoggerFactory.getLogger(LettuceClusterConnection.class); + + /** + * 构造函数 + */ + public LettuceClusterConnection() { + super(); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource) { + super(dataSource); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout) { + super(dataSource, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, SslConfiguration sslConfiguration) { + super(dataSource, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout, + int maxRedirects, int maxTotalRetriesDuration) { + super(dataSource, connectTimeout, soTimeout); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout, + int maxRedirects, int maxTotalRetriesDuration, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int maxRedirects, int maxTotalRetriesDuration) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int maxRedirects, + int maxTotalRetriesDuration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int maxRedirects, int maxTotalRetriesDuration, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + @Override + public int getMaxRedirects() { + return maxRedirects; + } + + @Override + public void setMaxRedirects(int maxRedirects) { + this.maxRedirects = maxRedirects; + } + + @Override + public int getMaxTotalRetriesDuration() { + return maxTotalRetriesDuration; + } + + @Override + public void setMaxTotalRetriesDuration(int maxTotalRetriesDuration) { + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + public StatefulRedisClusterConnection getStatefulRedisClusterConnection() { + return delegate; + } + + @Override + public Pipeline openPipeline() { + if(pipeline == null){ + final PipeliningFlushState flushState = pipeliningFlushPolicy.newPipeline(); + final LettucePipelineProxy lettucePipelineProxy = + new LettucePipelineProxy<>(flushState); + + lettucePipelineProxy.setTarget( + new LettucePipeline(delegate, flushState, lettucePipelineProxy.getTxResults())); + pipeline = lettucePipelineProxy; + } + + return pipeline; + } + + @Override + public void closePipeline() { + pipeline.close(); + pipeline = null; + } + + @Override + public Transaction multi() { + if(transaction == null){ + //final RedisSentinelCommands commands = delegate.sync(); + //transaction = new LettuceTransactionProxy(new LettuceTransaction(commands), commands); + } + + return transaction; + } + + @Override + public List exec() throws RedisException { + if(pipeline != null){ + final List result = pipeline.syncAndReturnAll(); + + pipeline.close(); + pipeline = null; + + return result; + }else if(transaction != null){ + final List result = transaction.exec(); + + transaction.close(); + transaction = null; + + return result; + }else{ + throw new RedisException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + @Override + public void discard() throws RedisException { + if(transaction != null){ + transaction.discard(); + transaction = null; + }else{ + throw new RedisException("ERR DISCARD without MULTI. Did you forget to call multi?"); + } + } + + @Override + public boolean isConnect() { + return delegate != null && delegate.isOpen(); + } + + @Override + public boolean isClosed() { + return delegate == null || delegate.isOpen() == false; + } + + @Override + protected void internalInit() { + if(pool == null && getPoolConfig() != null){ + pool = createPool(); + } + } + + protected boolean isUsePool() { + return pool != null; + } + + protected StatefulRedisClusterConnection createStatefulRedisClusterConnection( + final RedisCodec codec) { + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); + final LettuceClusterDataSource dataSource = (LettuceClusterDataSource) getDataSource(); + final RedisCredentialsProvider redisCredentialsProvider = Validate.hasText(dataSource.getPassword()) ? + new StaticCredentialsProvider(Validate.hasText(dataSource.getUsername()) ? dataSource.getUsername() : + null, dataSource.getPassword().toCharArray()) : null; + final Set redisURIs = dataSource.getNodes().stream().map((node)->{ + int port = node.getPort() == 0 ? RedisNode.DEFAULT_PORT : node.getPort(); + final RedisURI redisURI = RedisURI.create(node.getHost(), port); + + propertyMapper.from(redisCredentialsProvider).to(redisURI::setCredentialsProvider); + propertyMapper.from(dataSource.getClientName()).to(redisURI::setClientName); + + if(dataSource.getConnectTimeout() > 0){ + redisURI.setTimeout(Duration.ofMillis(dataSource.getConnectTimeout())); + } + + redisURI.setSsl(dataSource.getSslConfiguration() != null); + + return redisURI; + }).collect(Collectors.toSet()); + + return RedisClusterClient.create(redisURIs).connect(codec); + } + + @Override + protected void doConnect() throws RedisConnectionFailureException { + if(isUsePool()){ + try{ + delegate = pool.getResource(); + + if(logger.isInfoEnabled()){ + logger.info("StatefulRedisClusterConnection initialized with pool success."); + } + }catch(Exception e){ + if(logger.isErrorEnabled()){ + logger.error("StatefulRedisClusterConnection initialized with pool failure: {}", e.getMessage(), + e); + } + + throw LettuceRedisExceptionUtils.convert(e); + } + }else{ + delegate = createStatefulRedisClusterConnection(new ByteArrayCodec()); + } + } + + protected LettuceClusterPool createPool() { + final LettuceClusterDataSource dataSource = (LettuceClusterDataSource) getDataSource(); + final LettucePoolConfig> lettucePoolConfig = new LettucePoolConfig<>(); + final LettuceClientConfig clientConfig = LettuceClientConfigBuilder.create(dataSource, + getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .build(); + final Set nodes = createHostAndPorts(dataSource); + + getPoolConfig().toGenericObjectPoolConfig(lettucePoolConfig); + + if(getSslConfiguration() == null){ + logger.debug("Create LettuceClusterPool."); + }else{ + logger.debug("Create LettuceClusterPool with ssl."); + } + + return ConnectionPoolUtils.createLettuceClusterPool(lettucePoolConfig, nodes, clientConfig); + } + + @Override + protected void doDestroy() throws IOException { + super.doDestroy(); + + logger.info("Lettuce destroy."); + if(pool != null){ + if(logger.isInfoEnabled()){ + logger.info("Lettuce cluster pool for {} destroy.", pool.getClass().getName()); + } + + try{ + pool.destroy(); + }catch(Exception ex){ + logger.warn("Cannot properly close Lettuce cluster pool.", ex); + } + + pool = null; + } + } + + @Override + protected void doClose() throws IOException { + super.doClose(); + + logger.info("Lettuce close."); + + if(delegate != null){ + delegate.close(); + } + } + + private static Set createHostAndPorts(final LettuceClusterDataSource clusterDataSource) { + return clusterDataSource.getNodes().stream().map((node)->{ + int port = node.getPort() == 0 ? RedisNode.DEFAULT_PORT : node.getPort(); + return new HostAndPort(node.getHost(), port); + }).collect(Collectors.toSet()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/LettuceConnection.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/LettuceConnection.java new file mode 100644 index 000000000..8c193a883 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/LettuceConnection.java @@ -0,0 +1,480 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.lettuce; + +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.validator.Validate; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.RedisStandaloneConnection; +import com.buession.redis.client.connection.datasource.lettuce.LettuceDataSource; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.core.internal.lettuce.LettuceClientConfigBuilder; +import com.buession.redis.exception.LettuceRedisExceptionUtils; +import com.buession.redis.exception.RedisConnectionFailureException; +import com.buession.redis.exception.RedisException; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.pipeline.lettuce.LettucePipeline; +import com.buession.redis.pipeline.lettuce.LettucePipelineProxy; +import com.buession.redis.transaction.Transaction; +import com.buession.redis.transaction.lettuce.LettuceTransaction; +import com.buession.redis.transaction.lettuce.LettuceTransactionProxy; +import io.lettuce.core.LettuceClientConfig; +import io.lettuce.core.LettucePool; +import io.lettuce.core.LettucePoolConfig; +import io.lettuce.core.RedisClient; +import io.lettuce.core.RedisCredentialsProvider; +import io.lettuce.core.RedisURI; +import io.lettuce.core.StaticCredentialsProvider; +import io.lettuce.core.api.PipeliningFlushPolicy; +import io.lettuce.core.api.PipeliningFlushState; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.core.codec.ByteArrayCodec; +import io.lettuce.core.codec.RedisCodec; +import io.lettuce.core.support.ConnectionPoolUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.time.Duration; +import java.util.List; + +/** + * Lettuce 单机模式连接器 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceConnection extends AbstractLettuceRedisConnection implements RedisStandaloneConnection { + + /** + * 连接池 + */ + private LettucePool pool; + + /** + * {@link StatefulRedisConnection} 实例 + */ + private StatefulRedisConnection delegate; + + private final PipeliningFlushPolicy pipeliningFlushPolicy = PipeliningFlushPolicy.flushEachCommand(); + + private final static Logger logger = LoggerFactory.getLogger(LettuceConnection.class); + + /** + * 构造函数 + */ + public LettuceConnection() { + super(); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + */ + public LettuceConnection(LettuceDataSource dataSource) { + super(dataSource); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public LettuceConnection(LettuceDataSource dataSource, int connectTimeout, int soTimeout) { + super(dataSource, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public LettuceConnection(LettuceDataSource dataSource, int connectTimeout, int soTimeout, int infiniteSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param sslConfiguration + * SSL 配置 + */ + public LettuceConnection(LettuceDataSource dataSource, SslConfiguration sslConfiguration) { + super(dataSource, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceConnection(LettuceDataSource dataSource, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceConnection(LettuceDataSource dataSource, int connectTimeout, int soTimeout, int infiniteSoTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param poolConfig + * 连接池配置 + */ + public LettuceConnection(PoolConfig poolConfig) { + super(poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + */ + public LettuceConnection(LettuceDataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public LettuceConnection(LettuceDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public LettuceConnection(LettuceDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + */ + public LettuceConnection(LettuceDataSource dataSource, PoolConfig poolConfig, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceConnection(LettuceDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceConnection(LettuceDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + public StatefulRedisConnection getStatefulConnection() { + return delegate; + } + + @Override + public Pipeline openPipeline() { + if(pipeline == null){ + final PipeliningFlushState flushState = pipeliningFlushPolicy.newPipeline(); + final LettucePipelineProxy lettucePipelineProxy = + new LettucePipelineProxy<>(flushState); + + lettucePipelineProxy.setTarget( + new LettucePipeline(delegate, flushState, lettucePipelineProxy.getTxResults())); + pipeline = lettucePipelineProxy; + } + + return pipeline; + } + + @Override + public void closePipeline() { + pipeline.close(); + pipeline = null; + } + + @Override + public Transaction multi() { + System.out.println("transaction: " + (transaction == null ? "false" : "true")); + if(transaction == null){ + final RedisCommands commands = delegate.sync(); + commands.multi(); + transaction = new LettuceTransactionProxy(new LettuceTransaction(commands), commands); + } + + return transaction; + } + + @Override + public List exec() throws RedisException { + if(pipeline != null){ + final List result = pipeline.syncAndReturnAll(); + + pipeline.close(); + pipeline = null; + + return result; + }else if(transaction != null){ + final List result = transaction.exec(); + + transaction.close(); + transaction = null; + + return result; + }else{ + throw new RedisException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + @Override + public void discard() throws RedisException { + if(transaction != null){ + transaction.discard(); + transaction = null; + }else{ + throw new RedisException("ERR DISCARD without MULTI. Did you forget to call multi?"); + } + } + + @Override + public boolean isConnect() { + return delegate != null && delegate.isOpen(); + } + + @Override + public boolean isClosed() { + return delegate == null || delegate.isOpen() == false; + } + + @Override + protected void internalInit() { + if(pool == null && getPoolConfig() != null){ + pool = createPool(); + } + } + + protected boolean isUsePool() { + return pool != null; + } + + @Override + protected void doConnect() throws RedisConnectionFailureException { + if(isUsePool()){ + try{ + delegate = pool.getResource(); + + if(logger.isInfoEnabled()){ + logger.info("StatefulConnection initialized with pool success."); + } + }catch(Exception e){ + if(logger.isErrorEnabled()){ + logger.error("StatefulConnection initialized with pool failure: {}", e.getMessage(), e); + } + + throw LettuceRedisExceptionUtils.convert(e); + } + }else{ + delegate = createStatefulRedisConnection(new ByteArrayCodec()); + } + } + + protected StatefulRedisConnection createStatefulRedisConnection(final RedisCodec codec) { + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); + final LettuceDataSource dataSource = (LettuceDataSource) getDataSource(); + final RedisURI redisURI = RedisURI.create(dataSource.getHost(), dataSource.getPort()); + final RedisCredentialsProvider redisCredentialsProvider = Validate.hasText(dataSource.getPassword()) ? + new StaticCredentialsProvider(Validate.hasText(dataSource.getUsername()) ? dataSource.getUsername() : + null, dataSource.getPassword().toCharArray()) : null; + + if(dataSource.getDatabase() >= 0){ + redisURI.setDatabase(dataSource.getDatabase()); + } + + propertyMapper.from(redisCredentialsProvider).to(redisURI::setCredentialsProvider); + propertyMapper.from(dataSource.getClientName()).to(redisURI::setClientName); + + if(dataSource.getConnectTimeout() > 0){ + redisURI.setTimeout(Duration.ofMillis(dataSource.getConnectTimeout())); + } + + redisURI.setSsl(dataSource.getSslConfiguration() != null); + + return RedisClient.create(redisURI).connect(codec); + } + + protected LettucePool createPool() { + final LettuceDataSource dataSource = (LettuceDataSource) getDataSource(); + final LettucePoolConfig> lettucePoolConfig = new LettucePoolConfig<>(); + final LettuceClientConfig clientConfig = LettuceClientConfigBuilder.create(dataSource, + getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .database(dataSource.getDatabase()) + .build(); + + getPoolConfig().toGenericObjectPoolConfig(lettucePoolConfig); + + if(getSslConfiguration() == null){ + logger.debug("Create LettucePool."); + }else{ + logger.debug("Create LettucePool with ssl."); + } + + return ConnectionPoolUtils.createLettucePool(lettucePoolConfig, dataSource.getHost(), dataSource.getPort(), + clientConfig); + } + + @Override + protected void doDestroy() throws IOException { + super.doDestroy(); + + logger.info("Lettuce destroy."); + if(pool != null){ + if(logger.isInfoEnabled()){ + logger.info("Lettuce pool for {} destroy.", pool.getClass().getName()); + } + + try{ + pool.destroy(); + }catch(Exception ex){ + logger.warn("Cannot properly close Lettuce pool.", ex); + } + + pool = null; + } + } + + @Override + protected void doClose() throws IOException { + super.doClose(); + + logger.info("Lettuce close."); + + if(delegate != null){ + delegate.close(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/LettuceRedisConnection.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/LettuceRedisConnection.java new file mode 100644 index 000000000..9b3d7ca13 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/LettuceRedisConnection.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.lettuce; + +import com.buession.redis.client.connection.RedisConnection; + +/** + * Lettuce Redis 连接对象 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface LettuceRedisConnection extends RedisConnection { + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/LettuceSentinelConnection.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/LettuceSentinelConnection.java new file mode 100644 index 000000000..3241814d6 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/LettuceSentinelConnection.java @@ -0,0 +1,869 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.lettuce; + +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.utils.Assert; +import com.buession.core.validator.Validate; +import com.buession.net.HostAndPort; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.RedisSentinelConnection; +import com.buession.redis.client.connection.datasource.DataSource; +import com.buession.redis.client.connection.datasource.lettuce.LettuceSentinelDataSource; +import com.buession.redis.core.Constants; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.core.RedisNamedNode; +import com.buession.redis.core.RedisNode; +import com.buession.redis.core.RedisSentinelNode; +import com.buession.redis.core.RedisServer; +import com.buession.redis.core.Role; +import com.buession.redis.core.internal.lettuce.LettuceClientConfigBuilder; +import com.buession.redis.exception.LettuceRedisExceptionUtils; +import com.buession.redis.exception.RedisConnectionFailureException; +import com.buession.redis.exception.RedisException; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.pipeline.lettuce.LettucePipeline; +import com.buession.redis.pipeline.lettuce.LettucePipelineProxy; +import com.buession.redis.transaction.Transaction; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.LettuceClientConfig; +import io.lettuce.core.LettucePoolConfig; +import io.lettuce.core.LettuceSentinelPool; +import io.lettuce.core.RedisClient; +import io.lettuce.core.RedisCredentialsProvider; +import io.lettuce.core.RedisURI; +import io.lettuce.core.StaticCredentialsProvider; +import io.lettuce.core.api.PipeliningFlushPolicy; +import io.lettuce.core.api.PipeliningFlushState; +import io.lettuce.core.codec.ByteArrayCodec; +import io.lettuce.core.codec.RedisCodec; +import io.lettuce.core.sentinel.api.StatefulRedisSentinelConnection; +import io.lettuce.core.sentinel.api.sync.RedisSentinelCommands; +import io.lettuce.core.support.ConnectionPoolUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.time.Duration; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Lettuce 哨兵模式连接器 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceSentinelConnection extends AbstractLettuceRedisConnection implements RedisSentinelConnection { + + /** + * 哨兵节点连接超时(单位:毫秒) + */ + private int sentinelConnectTimeout = Constants.DEFAULT_CONNECT_TIMEOUT; + + /** + * 哨兵节点读取超时(单位:毫秒) + */ + private int sentinelSoTimeout = Constants.DEFAULT_SO_TIMEOUT; + + /** + * 连接池 + */ + private LettuceSentinelPool pool; + + /** + * {@link StatefulRedisSentinelConnection} 实例 + */ + private StatefulRedisSentinelConnection delegate; + + private final PipeliningFlushPolicy pipeliningFlushPolicy = PipeliningFlushPolicy.flushEachCommand(); + + private final static Logger logger = LoggerFactory.getLogger(LettuceSentinelConnection.class); + + /** + * 构造函数 + */ + public LettuceSentinelConnection() { + super(); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource) { + super(dataSource); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout) { + super(dataSource, connectTimeout, soTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, SslConfiguration sslConfiguration) { + super(dataSource, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int sentinelConnectTimeout, int sentinelSoTimeout) { + super(dataSource, connectTimeout, soTimeout); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int sentinelConnectTimeout, int sentinelSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int sentinelConnectTimeout, int sentinelSoTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int sentinelConnectTimeout, int sentinelSoTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param poolConfig + * 连接池配置 + */ + public LettuceSentinelConnection(PoolConfig poolConfig) { + super(poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int sentinelConnectTimeout, int sentinelSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int sentinelConnectTimeout, + int sentinelSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int sentinelConnectTimeout, int sentinelSoTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int sentinelConnectTimeout, + int sentinelSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + @Override + public int getSentinelConnectTimeout() { + return sentinelConnectTimeout; + } + + @Override + public void setSentinelConnectTimeout(int sentinelConnectTimeout) { + this.sentinelConnectTimeout = sentinelConnectTimeout; + } + + @Override + public int getSentinelSoTimeout() { + return sentinelSoTimeout; + } + + @Override + public void setSentinelSoTimeout(int sentinelSoTimeout) { + this.sentinelSoTimeout = sentinelSoTimeout; + } + + @Override + public List masters() { + DataSource dataSource = getDataSource(); + if(dataSource == null){ + return null; + } + + final List> masterNodes = getSentinelCommands( + (LettuceSentinelDataSource) dataSource).masters(); + return parseRedisServer(masterNodes, Role.MASTER); + } + + @Override + public List slaves(RedisNamedNode master) { + Assert.isNull(master, "Redis master node cloud not be 'null' for loading slaves."); + return slaves(master.getName()); + } + + @Override + public List slaves(String masterName) { + Assert.isBlank(masterName, "Redis master name cloud not be 'null' or empty for loading slaves."); + + DataSource dataSource = getDataSource(); + if(dataSource == null){ + return null; + } + + final List> slaveNodes = getSentinelCommands( + (LettuceSentinelDataSource) dataSource).slaves(SafeEncoder.encode(masterName)); + return parseRedisServer(slaveNodes, Role.SLAVE); + } + + @Override + public void failover(RedisNamedNode namedNode) { + Assert.isNull(namedNode, "Redis master node cloud not be 'null' for failover."); + Assert.isBlank(namedNode.getName(), "Redis master name cloud not be 'null' or empty for failover."); + + DataSource dataSource = getDataSource(); + if(dataSource == null){ + return; + } + + Objects.requireNonNull(getSentinelCommands((LettuceSentinelDataSource) dataSource)) + .failover(SafeEncoder.encode(namedNode.getName())); + } + + @Override + public void monitor(RedisSentinelNode server) { + Assert.isNull(server, "Cannot monitor 'null' server."); + Assert.isBlank(server.getName(), "Name of server to monitor must not be 'null' or empty."); + Assert.isBlank(server.getHost(), "Host must not be 'null' for server to monitor."); + + DataSource dataSource = getDataSource(); + if(dataSource == null){ + return; + } + + Objects.requireNonNull(getSentinelCommands((LettuceSentinelDataSource) dataSource)) + .monitor(SafeEncoder.encode(server.getName()), server.getHost(), server.getPort(), server.getQuorum()); + } + + public StatefulRedisSentinelConnection getStatefulRedisSentinelConnection() { + return delegate; + } + + @Override + public Pipeline openPipeline() { + if(pipeline == null){ + final PipeliningFlushState flushState = pipeliningFlushPolicy.newPipeline(); + final LettucePipelineProxy lettucePipelineProxy = + new LettucePipelineProxy<>(flushState); + + lettucePipelineProxy.setTarget( + new LettucePipeline(delegate, flushState, lettucePipelineProxy.getTxResults())); + pipeline = lettucePipelineProxy; + } + + return pipeline; + } + + @Override + public void closePipeline() { + pipeline.close(); + pipeline = null; + } + + @Override + public Transaction multi() { + if(transaction == null){ + final RedisSentinelCommands commands = delegate.sync(); + //transaction = new LettuceTransactionProxy(new LettuceTransaction(commands), commands); + } + + return transaction; + } + + @Override + public List exec() throws RedisException { + if(pipeline != null){ + final List result = pipeline.syncAndReturnAll(); + + pipeline.close(); + pipeline = null; + + return result; + }else if(transaction != null){ + final List result = transaction.exec(); + + transaction.close(); + transaction = null; + + return result; + }else{ + throw new RedisException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + @Override + public void discard() throws RedisException { + if(transaction != null){ + transaction.discard(); + transaction = null; + }else{ + throw new RedisException("ERR DISCARD without MULTI. Did you forget to call multi?"); + } + } + + @Override + public void remove(RedisNamedNode master) { + Assert.isNull(master, "Master node cloud be 'null' when trying to remove."); + remove(master.getName()); + } + + @Override + public void remove(String masterName) { + Assert.isBlank(masterName, "Redis master name cloud be 'null' or empty when trying to remove."); + delegate.async().remove(SafeEncoder.encode(masterName)); + } + + @Override + public boolean isConnect() { + return delegate != null && delegate.isOpen(); + } + + @Override + public boolean isClosed() { + return delegate == null || delegate.isOpen() == false; + } + + @Override + protected void internalInit() { + if(pool == null && getPoolConfig() != null){ + pool = createPool(); + } + } + + private RedisSentinelCommands getSentinelCommands(final LettuceSentinelDataSource dataSource) { + return delegate.sync(); + } + + protected boolean isUsePool() { + return pool != null; + } + + protected StatefulRedisSentinelConnection createStatefulRedisSentinelConnection( + final RedisCodec codec) { + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); + final LettuceSentinelDataSource dataSource = (LettuceSentinelDataSource) getDataSource(); + final RedisURI.Builder redisURIBuilder = RedisURI.builder(); + final RedisCredentialsProvider redisCredentialsProvider = Validate.hasText(dataSource.getPassword()) ? + new StaticCredentialsProvider(Validate.hasText(dataSource.getUsername()) ? dataSource.getUsername() : + null, dataSource.getPassword().toCharArray()) : null; + + if(dataSource.getDatabase() >= 0){ + redisURIBuilder.withDatabase(dataSource.getDatabase()); + } + + propertyMapper.from(redisCredentialsProvider).to(redisURIBuilder::withAuthentication); + propertyMapper.from(dataSource.getClientName()).to(redisURIBuilder::withClientName); + + if(dataSource.getConnectTimeout() > 0){ + redisURIBuilder.withTimeout(Duration.ofMillis(dataSource.getConnectTimeout())); + } + + redisURIBuilder.withSsl(dataSource.getSslConfiguration() != null); + + return RedisClient.create(redisURIBuilder.build()).connectSentinel(codec); + } + + @Override + protected void doConnect() throws RedisConnectionFailureException { + if(isUsePool()){ + try{ + delegate = pool.getResource(); + + if(logger.isInfoEnabled()){ + logger.info("StatefulRedisSentinelConnection initialized with pool success."); + } + }catch(Exception e){ + if(logger.isErrorEnabled()){ + logger.error("StatefulRedisSentinelConnection initialized with pool failure: {}", e.getMessage(), + e); + } + + throw LettuceRedisExceptionUtils.convert(e); + } + }else{ + delegate = createStatefulRedisSentinelConnection(new ByteArrayCodec()); + } + } + + protected LettuceSentinelPool createPool() { + final LettuceSentinelDataSource dataSource = (LettuceSentinelDataSource) getDataSource(); + final LettucePoolConfig> lettucePoolConfig = new LettucePoolConfig<>(); + final Set sentinels = createSentinelHosts(dataSource.getSentinels()); + final LettuceClientConfig clientConfig = LettuceClientConfigBuilder.create(dataSource, + getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .database(dataSource.getDatabase()) + .build(); + final LettuceClientConfig sentinelClientConfig = createSentinelLettuceClientConfig(dataSource); + + getPoolConfig().toGenericObjectPoolConfig(lettucePoolConfig); + + if(getSslConfiguration() == null){ + logger.debug("Create LettuceSentinelPool."); + }else{ + logger.debug("Create LettuceSentinelPool with ssl."); + } + + return ConnectionPoolUtils.createLettuceSentinelPool(dataSource.getMasterName(), lettucePoolConfig, + sentinels, clientConfig, sentinelClientConfig); + } + + @Override + protected void doDestroy() throws IOException { + super.doDestroy(); + + logger.info("Lettuce destroy."); + if(pool != null){ + if(logger.isInfoEnabled()){ + logger.info("Lettuce sentinel pool for {} destroy.", pool.getClass().getName()); + } + + try{ + pool.destroy(); + }catch(Exception ex){ + logger.warn("Cannot properly close Lettuce sentinel pool.", ex); + } + + pool = null; + } + } + + @Override + protected void doClose() throws IOException { + super.doClose(); + + logger.info("Lettuce close."); + + if(delegate != null){ + delegate.close(); + } + } + + protected LettuceClientConfig createSentinelLettuceClientConfig(final LettuceSentinelDataSource dataSource) { + return LettuceClientConfigBuilder.create(dataSource, getSslConfiguration()) + .connectTimeout(getSentinelConnectTimeout()) + .socketTimeout(getSentinelSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .clientName(dataSource.getSentinelClientName()) + .build(); + } + + protected Set createSentinelHosts(final Collection sentinelNodes) { + if(Validate.isEmpty(sentinelNodes)){ + return Collections.emptySet(); + } + + return sentinelNodes.stream().filter(Objects::nonNull).map(node->{ + int port = node.getPort() == 0 ? RedisNode.DEFAULT_SENTINEL_PORT : node.getPort(); + return new HostAndPort(node.getHost(), port); + }).collect(Collectors.toSet()); + } + + protected List parseRedisServer(final List> nodes, final Role role) { + if(nodes == null){ + return null; + } + + return nodes.stream().map((node)->{ + if(node == null){ + return null; + }else{ + final Map sNodes = new HashMap<>(node.size()); + final Properties properties = new Properties(); + + node.forEach((key, value)->{ + sNodes.put(SafeEncoder.encode(key), SafeEncoder.encode(value)); + }); + + properties.putAll(sNodes); + + final RedisServer redisServer = new RedisServer(sNodes.get("ip"), + Integer.parseInt(sNodes.get("port")), properties); + redisServer.setName(sNodes.get("name")); + redisServer.setRole(role); + + return redisServer; + } + }).collect(Collectors.toList()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/package-info.java new file mode 100644 index 000000000..0175f8b94 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/connection/lettuce/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.client.connection.lettuce; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/AbstractJedisRedisClient.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/AbstractJedisRedisClient.java new file mode 100644 index 000000000..f4d260879 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/AbstractJedisRedisClient.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis; + +import com.buession.redis.client.AbstractRedisClient; +import com.buession.redis.client.connection.jedis.JedisRedisConnection; + +/** + * Jedis Redis 客户端抽象类 + * + * @param + * Jedis Redis 连接对象类型 {@link JedisRedisConnection} + * + * @author Yong.Teng + */ +public abstract class AbstractJedisRedisClient extends AbstractRedisClient + implements JedisRedisClient { + + /** + * 构造函数 + */ + public AbstractJedisRedisClient() { + super(); + } + + /** + * 构造函数 + * + * @param connection + * Jedis Redis 连接对象 {@link JedisRedisConnection} + */ + public AbstractJedisRedisClient(final CONN connection) { + super(connection); + } + +} \ No newline at end of file diff --git a/buession-dao/src/test/java/com/buession/dao/DMLTest.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/JedisRedisClient.java similarity index 86% rename from buession-dao/src/test/java/com/buession/dao/DMLTest.java rename to buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/JedisRedisClient.java index f0ccdb676..826879b95 100644 --- a/buession-dao/src/test/java/com/buession/dao/DMLTest.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/JedisRedisClient.java @@ -19,21 +19,18 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.dao; +package com.buession.redis.client.jedis; -import org.junit.Test; +import com.buession.redis.client.RedisClient; /** + * Jedis Redis 客户端 + * * @author Yong.Teng */ -public class DMLTest { - - @Test - public void test(){ - System.out.println(DML.CLEAR == DML.CLEAR); - } +public interface JedisRedisClient extends RedisClient { } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractAclOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractAclOperations.java new file mode 100644 index 000000000..b1bbcb2ce --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractAclOperations.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.AclOperations; +import com.buession.redis.core.command.Command; +import com.buession.redis.utils.SafeEncoder; + +/** + * Jedis 权限命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractAclOperations extends AbstractJedisRedisOperations + implements AclOperations { + + public AbstractAclOperations(final C client) { + super(client); + } + + @Override + public Status aclDryRun(final byte[] username, final Command command) { + return aclDryRun(SafeEncoder.encode(username), command); + } + + @Override + public Status aclDryRun(final byte[] username, final Command command, final byte[]... arguments) { + return aclDryRun(SafeEncoder.encode(username), command, SafeEncoder.encode(arguments)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractBitMapOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractBitMapOperations.java new file mode 100644 index 000000000..920ea2a85 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractBitMapOperations.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.BitMapOperations; + +/** + * Jedis BitMap 命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractBitMapOperations extends AbstractJedisRedisOperations + implements BitMapOperations { + + public AbstractBitMapOperations(final C client) { + super(client); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractClusterOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractClusterOperations.java new file mode 100644 index 000000000..c71195721 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractClusterOperations.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.ClusterOperations; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.ClusterSetSlotOption; +import com.buession.redis.core.SlotRange; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Jedis 集群命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractClusterOperations extends AbstractJedisRedisOperations + implements ClusterOperations { + + public AbstractClusterOperations(final C client) { + super(client); + } + + @Override + public Long clusterCountFailureReports(final byte[] nodeId) { + return clusterCountFailureReports(SafeEncoder.encode(nodeId)); + } + + @Override + public Status clusterForget(final byte[] nodeId) { + return clusterForget(SafeEncoder.encode(nodeId)); + } + + @Override + public Long clusterKeySlot(final byte[] key) { + return clusterKeySlot(SafeEncoder.encode(key)); + } + + @Override + public List clusterReplicas(final byte[] nodeId) { + return clusterReplicas(SafeEncoder.encode(nodeId)); + } + + @Override + public Status clusterReplicate(final byte[] nodeId) { + return clusterReplicate(SafeEncoder.encode(nodeId)); + } + + @Override + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final byte[] nodeId) { + return clusterSetSlot(slot, setSlotOption, SafeEncoder.encode(nodeId)); + } + + @Override + public List clusterSlaves(final byte[] nodeId) { + return clusterSlaves(SafeEncoder.encode(nodeId)); + } + + protected static int[] numberRangeArray(final SlotRange[] values) { + final int[] result = new int[values.length * 2]; + + for(int i = 0; i < values.length; i++){ + result[i] = values[i].getStart(); + result[++i] = values[i].getEnd(); + } + + return result; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractConnectionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractConnectionOperations.java new file mode 100644 index 000000000..f1a71844c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractConnectionOperations.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.ConnectionOperations; +import com.buession.redis.core.command.args.ClientKillArgument; +import com.buession.redis.core.internal.jedis.JedisClientKillParams; +import com.buession.redis.utils.SafeEncoder; +import redis.clients.jedis.params.ClientKillParams; + +import java.util.Optional; + +/** + * Jedis 连接命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractConnectionOperations + extends AbstractJedisRedisOperations implements ConnectionOperations { + + public AbstractConnectionOperations(final C client) { + super(client); + } + + @Override + public Status auth(final byte[] user, final byte[] password) { + return auth(SafeEncoder.encode(user), SafeEncoder.encode(password)); + } + + @Override + public Status auth(final byte[] password) { + return auth(SafeEncoder.encode(password)); + } + + + protected static ClientKillParams createClientKillParamsFromClientKillArgument( + final ClientKillArgument... clientKillArguments) { + if(clientKillArguments != null && clientKillArguments.length > 0){ + final JedisClientKillParams clientKillParams = JedisClientKillParams.from(clientKillArguments[0]); + ClientKillArgument clientKillArgument; + + for(int i = 1; i < clientKillArguments.length; i++){ + clientKillArgument = clientKillArguments[i]; + + Optional.ofNullable(clientKillArgument.getClientId()).ifPresent(clientKillParams::id); + Optional.ofNullable(clientKillArgument.getClientType()).ifPresent(clientKillParams::type); + Optional.ofNullable(clientKillArgument.getUsername()).ifPresent(clientKillParams::user); + Optional.ofNullable(clientKillArgument.getAddr()).ifPresent(clientKillParams::addr); + Optional.ofNullable(clientKillArgument.getLaddr()).ifPresent(clientKillParams::laddr); + Optional.ofNullable(clientKillArgument.getSkipMe()).ifPresent(clientKillParams::skipMe); + } + + return clientKillParams; + }else{ + return null; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractGeoOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractGeoOperations.java new file mode 100644 index 000000000..b8c7af6cf --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractGeoOperations.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.MapConverter; +import com.buession.lang.Geo; +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.GeoOperations; +import com.buession.redis.core.internal.jedis.JedisGeoCoordinate; +import redis.clients.jedis.GeoCoordinate; + +import java.util.Map; + +/** + * Jedis 地理位置命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractGeoOperations extends AbstractJedisRedisOperations + implements GeoOperations { + + public AbstractGeoOperations(final C client) { + super(client); + } + + protected static Map createGeoCoordinateMapFromGeoMap(final Map memberCoordinates) { + final MapConverter geoCoordinateMapConverter = new MapConverter<>((k)->k, + JedisGeoCoordinate::from); + return geoCoordinateMapConverter.convert(memberCoordinates); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractHashOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractHashOperations.java new file mode 100644 index 000000000..c5f687c47 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractHashOperations.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.utils.NumberUtils; +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.HashOperations; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.args.HScanArgument; + +import java.util.Map; + +/** + * Jedis 哈希表命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractHashOperations extends AbstractJedisRedisOperations + implements HashOperations { + + public AbstractHashOperations(final C client) { + super(client); + } + + @Override + public ScanResult> hScan(final String key, final long cursor) { + return hScan(key, Long.toString(cursor)); + } + + @Override + public ScanResult> hScan(final byte[] key, final long cursor) { + return hScan(key, NumberUtils.long2bytes(cursor)); + } + + @Override + public ScanResult> hScan(final String key, final long cursor, + final HScanArgument.StringHScanArgument scanArgument) { + return hScan(key, Long.toString(cursor), scanArgument); + } + + @Override + public ScanResult> hScan(final byte[] key, final long cursor, + final HScanArgument.ByteHScanArgument scanArgument) { + return hScan(key, NumberUtils.long2bytes(cursor), scanArgument); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractHyperLogLogOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractHyperLogLogOperations.java new file mode 100644 index 000000000..b18e16f59 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractHyperLogLogOperations.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.HyperLogLogOperations; + +/** + * Jedis HyperLogLog 命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractHyperLogLogOperations + extends AbstractJedisRedisOperations implements HyperLogLogOperations { + + public AbstractHyperLogLogOperations(final C client){ + super(client); + } + +} \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractJedisRedisOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractJedisRedisOperations.java new file mode 100644 index 000000000..6986580df --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractJedisRedisOperations.java @@ -0,0 +1,214 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.client.operations.AbstractRedisOperations; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; + +/** + * Jedis Redis 命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractJedisRedisOperations extends AbstractRedisOperations + implements JedisRedisOperations { + + public AbstractJedisRedisOperations(final C client) { + super(client); + } + + protected T notCommand(final JedisStandaloneClient client, final Command command) { + if(isPipeline()){ + return new JedisPipelineCommand(client, command) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, command) + .run(); + }else{ + return new JedisCommand(client, command) + .run(); + } + } + + protected T notCommand(final JedisStandaloneClient client, final Command command, final SubCommand subCommand) { + if(isPipeline()){ + return new JedisPipelineCommand(client, command, subCommand) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, command, subCommand) + .run(); + }else{ + return new JedisCommand(client, command, subCommand) + .run(); + } + } + + protected T notCommand(final JedisStandaloneClient client, final Command command, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand(client, command) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, command) + .run(args); + }else{ + return new JedisCommand(client, command) + .run(args); + } + } + + protected T notCommand(final JedisStandaloneClient client, final Command command, final SubCommand subCommand, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand(client, command, subCommand) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, command, subCommand) + .run(args); + }else{ + return new JedisCommand(client, command, subCommand) + .run(args); + } + } + + protected T notCommand(final JedisSentinelClient client, final Command command) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, command) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, command) + .run(); + }else{ + return new JedisSentinelCommand(client, command) + .run(); + } + } + + protected T notCommand(final JedisSentinelClient client, final Command command, final SubCommand subCommand) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, command, subCommand) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, command, subCommand) + .run(); + }else{ + return new JedisSentinelCommand(client, command, subCommand) + .run(); + } + } + + protected T notCommand(final JedisSentinelClient client, final Command command, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, command) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, command) + .run(args); + }else{ + return new JedisSentinelCommand(client, command) + .run(args); + } + } + + protected T notCommand(final JedisSentinelClient client, final Command command, final SubCommand subCommand, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, command, subCommand) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, command, subCommand) + .run(args); + }else{ + return new JedisSentinelCommand(client, command, subCommand) + .run(args); + } + } + + protected T notCommand(final JedisClusterClient client, final Command command) { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, command) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, command) + .run(); + }else{ + return new JedisClusterCommand(client, command) + .run(); + } + } + + protected T notCommand(final JedisClusterClient client, final Command command, final SubCommand subCommand) { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, command, subCommand) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, command, subCommand) + .run(); + }else{ + return new JedisClusterCommand(client, command, subCommand) + .run(); + } + } + + protected T notCommand(final JedisClusterClient client, final Command command, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, command) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, command) + .run(args); + }else{ + return new JedisClusterCommand(client, command) + .run(args); + } + } + + protected T notCommand(final JedisClusterClient client, final Command command, final SubCommand subCommand, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, command, subCommand) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, command, subCommand) + .run(args); + }else{ + return new JedisClusterCommand(client, command, subCommand) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractKeyOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractKeyOperations.java new file mode 100644 index 000000000..1f11a72e9 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractKeyOperations.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.utils.NumberUtils; +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.KeyOperations; +import com.buession.redis.core.ScanResult; + +import java.util.List; + +/** + * Jedis Key 命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractKeyOperations extends AbstractJedisRedisOperations + implements KeyOperations { + + public AbstractKeyOperations(final C client) { + super(client); + } + + @Override + public ScanResult> scan(final long cursor) { + return scan(Long.toString(cursor)); + } + + @Override + public ScanResult> scan(final long cursor, final String pattern) { + return scan(Long.toString(cursor), pattern); + } + + @Override + public ScanResult> scan(final long cursor, final byte[] pattern) { + return scan(NumberUtils.long2bytes(cursor), pattern); + } + + @Override + public ScanResult> scan(final long cursor, final int count) { + return scan(Long.toString(cursor), count); + } + + @Override + public ScanResult> scan(final long cursor, final String pattern, final int count) { + return scan(Long.toString(cursor), pattern, count); + } + + @Override + public ScanResult> scan(final long cursor, final byte[] pattern, final int count) { + return scan(NumberUtils.long2bytes(cursor), pattern, count); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractListOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractListOperations.java new file mode 100644 index 000000000..515475265 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractListOperations.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.ListOperations; + +/** + * Jedis 列表命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractListOperations extends AbstractJedisRedisOperations + implements ListOperations { + + public AbstractListOperations(final C client){ + super(client); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractPubSubOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractPubSubOperations.java new file mode 100644 index 000000000..6042cec1d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractPubSubOperations.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.PubSubOperations; + +/** + * Jedis Pub/Sub 命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractPubSubOperations extends AbstractJedisRedisOperations + implements PubSubOperations { + + public AbstractPubSubOperations(final C client){ + super(client); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractScriptingOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractScriptingOperations.java new file mode 100644 index 000000000..2d8568811 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractScriptingOperations.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.ScriptingOperations; + +/** + * Jedis Script 命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractScriptingOperations extends AbstractJedisRedisOperations + implements ScriptingOperations { + + public AbstractScriptingOperations(final C client){ + super(client); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractServerOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractServerOperations.java new file mode 100644 index 000000000..70c3d759a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractServerOperations.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.ServerOperations; +import com.buession.redis.utils.SafeEncoder; + +/** + * Jedis 服务端命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractServerOperations extends AbstractJedisRedisOperations + implements ServerOperations { + + public AbstractServerOperations(final C client) { + super(client); + } + + @Override + public Status moduleLoad(final byte[] path) { + return moduleLoad(SafeEncoder.encode(path)); + } + + @Override + public Status moduleLoad(final byte[] path, final byte[]... arguments) { + return moduleLoad(SafeEncoder.encode(path), SafeEncoder.encode(arguments)); + } + + @Override + public Status moduleUnLoad(final byte[] name) { + return moduleUnLoad(SafeEncoder.encode(name)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractSetOperations.java new file mode 100644 index 000000000..4f2a9ea63 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractSetOperations.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.utils.NumberUtils; +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.SetOperations; +import com.buession.redis.core.ScanResult; + +import java.util.List; + +/** + * Jedis 集合命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractSetOperations extends AbstractJedisRedisOperations + implements SetOperations { + + public AbstractSetOperations(final C client) { + super(client); + } + + @Override + public ScanResult> sScan(final String key, final long cursor) { + return sScan(key, Long.toString(cursor)); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor) { + return sScan(key, NumberUtils.long2bytes(cursor)); + } + + @Override + public ScanResult> sScan(final String key, final long cursor, final String pattern) { + return sScan(key, Long.toString(cursor), pattern); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor, final byte[] pattern) { + return sScan(key, NumberUtils.long2bytes(cursor), pattern); + } + + @Override + public ScanResult> sScan(final String key, final long cursor, final int count) { + return sScan(key, Long.toString(cursor), count); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor, final int count) { + return sScan(key, NumberUtils.long2bytes(cursor), count); + } + + @Override + public ScanResult> sScan(final String key, final long cursor, final String pattern, final int count) { + return sScan(key, Long.toString(cursor), pattern, count); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor, final byte[] pattern, final int count) { + return sScan(key, NumberUtils.long2bytes(cursor), pattern, count); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractSortedSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractSortedSetOperations.java new file mode 100644 index 000000000..0b55df989 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractSortedSetOperations.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.utils.NumberUtils; +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.SortedSetOperations; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; + +import java.util.List; + +/** + * Jedis 有序集合命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractSortedSetOperations + extends AbstractJedisRedisOperations implements SortedSetOperations { + + public AbstractSortedSetOperations(final C client) { + super(client); + } + + @Override + public Long zRemRangeByLex(final String key, final double min, final double max) { + return 0L;//zRemRangeByLex(key, Double.toString(min), Double.toString(max)); + } + + @Override + public Long zRemRangeByLex(final byte[] key, final double min, final double max) { + return 0L;//zRemRangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max)); + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max) { + return null;//zRevRangeByLex(key, Double.toString(min), Double.toString(max)); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max) { + return null;//zRevRangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max)); + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max, final long offset, + final int count) { + return null;//zRevRangeByLex(key, Double.toString(min), Double.toString(max), offset, count); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max, final long offset, + final int count) { + return null;//zRevRangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max), offset, count); + } + + @Override + public ScanResult> zScan(final String key, final long cursor) { + return zScan(key, Long.toString(cursor)); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor) { + return zScan(key, NumberUtils.long2bytes(cursor)); + } + + @Override + public ScanResult> zScan(final String key, final long cursor, final String pattern) { + return zScan(key, Long.toString(cursor), pattern); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor, final byte[] pattern) { + return zScan(key, NumberUtils.long2bytes(cursor), pattern); + } + + @Override + public ScanResult> zScan(final String key, final long cursor, final int count) { + return zScan(key, Long.toString(cursor), Long.toString(count)); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor, final int count) { + return zScan(key, NumberUtils.long2bytes(cursor), NumberUtils.long2bytes(count)); + } + + @Override + public ScanResult> zScan(final String key, final long cursor, final String pattern, final int count) { + return zScan(key, Long.toString(cursor), pattern, count); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor, final byte[] pattern, final int count) { + return zScan(key, NumberUtils.long2bytes(cursor), pattern, count); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractStreamOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractStreamOperations.java new file mode 100644 index 000000000..a6cea3b08 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractStreamOperations.java @@ -0,0 +1,277 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.collect.Maps; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapConverter; +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.StreamOperations; +import com.buession.redis.core.Stream; +import com.buession.redis.core.StreamConsumer; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import com.buession.redis.core.StreamGroup; +import com.buession.redis.core.StreamPending; +import com.buession.redis.core.StreamPendingSummary; +import com.buession.redis.core.command.args.XClaimArgument; +import com.buession.redis.core.command.args.XReadGroupArgument; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; +import java.util.Map; + +/** + * Jedis Stream 命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractStreamOperations extends AbstractJedisRedisOperations + implements StreamOperations { + + public AbstractStreamOperations(final C client) { + super(client); + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash) { + return xAdd(SafeEncoder.encode(key), id, Converters.mapBinaryToString().convert(hash)); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + return xAutoClaimJustId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), + SafeEncoder.encode(consumerName), minIdleTime, start); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + return xAutoClaimJustId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), + SafeEncoder.encode(consumerName), minIdleTime, start, count); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + return xClaim(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), + minIdleTime, ids); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + return xClaim(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), + minIdleTime, ids, xClaimArgument); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + return xClaimJustId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), + minIdleTime, ids); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + return xClaimJustId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), + minIdleTime, ids, xClaimArgument); + } + + @Override + public Long xDel(final byte[] key, final StreamEntryId... ids) { + return xDel(SafeEncoder.encode(key), ids); + } + + @Override + public Status xGroupCreate(final byte[] key, final byte[] groupName, final StreamEntryId id, + final boolean makeStream) { + return xGroupCreate(SafeEncoder.encode(key), SafeEncoder.encode(groupName), id, makeStream); + } + + @Override + public Status xGroupSetId(final byte[] key, final byte[] groupName, final StreamEntryId id) { + return xGroupSetId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), id); + } + + @Override + public List xInfoConsumers(final byte[] key, final byte[] groupName) { + return xInfoConsumers(SafeEncoder.encode(key), SafeEncoder.encode(groupName)); + } + + @Override + public List xInfoGroups(final byte[] key) { + return xInfoGroups(SafeEncoder.encode(key)); + } + + @Override + public Stream xInfoStream(final byte[] key) { + return xInfoStream(SafeEncoder.encode(key)); + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full) { + return xInfoStream(SafeEncoder.encode(key), full); + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full, final int count) { + return xInfoStream(SafeEncoder.encode(key), full, count); + } + + @Override + public StreamPendingSummary xPending(final byte[] key, final byte[] groupName) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName)); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final int count) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), start, end, count); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final byte[] consumerName) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName)); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime, start, end, count); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final byte[] consumerName) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime, + SafeEncoder.encode(consumerName)); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final int count, final byte[] consumerName) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), start, end, count, + SafeEncoder.encode(consumerName)); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count, + final byte[] consumerName) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime, start, end, count, + SafeEncoder.encode(consumerName)); + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end) { + return xRange(SafeEncoder.encode(key), start, end); + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end, + final int count) { + return xRange(SafeEncoder.encode(key), start, end, count); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams) { + final Map xStreams = Maps.map(streams, SafeEncoder::encode, (id)->id); + return afterBinaryXReadGroup( + xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), xStreams)); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final Map xStreams = Maps.map(streams, SafeEncoder::encode, (id)->id); + return afterBinaryXReadGroup( + xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), xStreams, + xReadGroupArgument)); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final boolean isNoAck, + final Map streams) { + final Map xStreams = Maps.map(streams, SafeEncoder::encode, (id)->id); + return afterBinaryXReadGroup( + xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), isNoAck, xStreams)); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final boolean isNoAck, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final Map xStreams = Maps.map(streams, SafeEncoder::encode, (id)->id); + return afterBinaryXReadGroup( + xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), isNoAck, + xStreams, xReadGroupArgument)); + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start) { + return xRevRange(SafeEncoder.encode(key), end, start); + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start, + final int count) { + return xRevRange(SafeEncoder.encode(key), end, start, count); + } + + protected static List>> afterBinaryXReadGroup( + final List>> data) { + if(data == null){ + return null; + }else{ + final ListConverter>, Map>> converter = + new ListConverter<>(new MapConverter<>(SafeEncoder::encode, (v)->v)); + return converter.convert(data); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractStringOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractStringOperations.java new file mode 100644 index 000000000..f8a47e79a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractStringOperations.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.StringOperations; + +/** + * Jedis 字符串命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractStringOperations extends AbstractJedisRedisOperations + implements StringOperations { + + public AbstractStringOperations(final C client){ + super(client); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractTransactionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractTransactionOperations.java new file mode 100644 index 000000000..4dc979947 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/AbstractTransactionOperations.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.TransactionOperations; + +/** + * Jedis 事务命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractTransactionOperations extends AbstractJedisRedisOperations + implements TransactionOperations { + + public AbstractTransactionOperations(final C client){ + super(client); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisAclOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisAclOperations.java new file mode 100644 index 000000000..16cef873c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisAclOperations.java @@ -0,0 +1,385 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.AclCategory; +import com.buession.redis.core.AclLog; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.AclSetUserArgument; +import com.buession.redis.core.internal.convert.jedis.response.AccessControlLogEntryConverter; +import com.buession.redis.core.internal.convert.jedis.response.AccessControlUserConverter; +import com.buession.redis.core.internal.convert.jedis.response.AclCategoryConverter; +import com.buession.redis.core.internal.convert.jedis.response.ProtocolCommandConverter; +import redis.clients.jedis.resps.AccessControlLogEntry; + +import java.util.List; + +/** + * Jedis 单机模式权限命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisAclOperations extends AbstractAclOperations { + + public JedisAclOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public List aclCat() { + final ListConverter converter = AclCategoryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.ACL, + SubCommand.ACL_CAT) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.ACL, + SubCommand.ACL_CAT) + .run(); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_CAT, (cmd)->cmd.aclCat(), converter) + .run(); + } + } + + @Override + public List aclCat(final AclCategory aclCategory) { + final CommandArguments args = CommandArguments.create(aclCategory); + final ListConverter converter = ProtocolCommandConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.ACL, SubCommand.ACL_CAT) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.ACL, SubCommand.ACL_CAT) + .run(); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_CAT, (cmd)->cmd.aclCat(aclCategory.name()), + converter) + .run(args); + } + } + + @Override + public Long aclDelUser(final String... usernames) { + final CommandArguments args = CommandArguments.create(usernames); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ACL, SubCommand.ACL_DELUSER) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ACL, SubCommand.ACL_DELUSER) + .run(); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_DELUSER, (cmd)->cmd.aclDelUser(usernames), + (v)->v) + .run(args); + } + } + + @Override + public Long aclDelUser(final byte[]... usernames) { + final CommandArguments args = CommandArguments.create(usernames); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ACL, SubCommand.ACL_DELUSER) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ACL, SubCommand.ACL_DELUSER) + .run(); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_DELUSER, (cmd)->cmd.aclDelUser(usernames), + (v)->v) + .run(args); + } + } + + @Override + public Status aclDryRun(final String username, final Command command) { + final CommandArguments args = CommandArguments.create(username).add(command); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ACL, SubCommand.ACL_DRYRUN) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ACL, SubCommand.ACL_DRYRUN) + .run(); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName()), okStatusConverter) + .run(args); + } + } + + @Override + public Status aclDryRun(final String username, final Command command, final String... arguments) { + final CommandArguments args = CommandArguments.create(username).add(command).add(arguments); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ACL, SubCommand.ACL_DRYRUN) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ACL, SubCommand.ACL_DRYRUN) + .run(); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName(), arguments), okStatusConverter) + .run(args); + } + } + + @Override + public String aclGenPass() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ACL, SubCommand.ACL_GENPASS) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ACL, SubCommand.ACL_GENPASS) + .run(); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, (cmd)->cmd.aclGenPass(), (v)->v) + .run(); + } + } + + @Override + public String aclGenPass(final int bits) { + final CommandArguments args = CommandArguments.create(bits); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ACL, SubCommand.ACL_GENPASS) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ACL, SubCommand.ACL_GENPASS) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, (cmd)->cmd.aclGenPass(bits), (v)->v) + .run(args); + } + } + + @Override + public AclUser aclGetUser(final String username) { + final CommandArguments args = CommandArguments.create(username); + final AccessControlUserConverter accessControlUserConverter = new AccessControlUserConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ACL, SubCommand.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ACL, SubCommand.ACL_GETUSER) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_GETUSER, (cmd)->cmd.aclGetUser(username), + accessControlUserConverter) + .run(args); + } + } + + @Override + public AclUser aclGetUser(final byte[] username) { + final CommandArguments args = CommandArguments.create(username); + final AccessControlUserConverter accessControlUserConverter = new AccessControlUserConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ACL, SubCommand.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ACL, SubCommand.ACL_GETUSER) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_GETUSER, (cmd)->cmd.aclGetUser(username), + accessControlUserConverter) + .run(args); + } + } + + @Override + public List aclList() { + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.ACL, SubCommand.LIST) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.ACL, SubCommand.LIST) + .run(); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.LIST, (cmd)->cmd.aclList(), (v)->v) + .run(); + } + } + + @Override + public Status aclLoad() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ACL, SubCommand.LOAD) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ACL, SubCommand.LOAD) + .run(); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.LOAD, (cmd)->cmd.aclLoad(), okStatusConverter) + .run(); + } + } + + @Override + public List aclLog() { + final ListConverter listAccessControlLogEntryConverter = + AccessControlLogEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.ACL, SubCommand.ACL_LOG) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.ACL, SubCommand.ACL_LOG) + .run(); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_LOG, (cmd)->cmd.aclLog(), + listAccessControlLogEntryConverter) + .run(); + } + } + + @Override + public List aclLog(final int count) { + final CommandArguments args = CommandArguments.create(count); + final ListConverter listAccessControlLogEntryConverter = + AccessControlLogEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.ACL, SubCommand.ACL_LOG) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.ACL, SubCommand.ACL_LOG) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_LOG, (cmd)->cmd.aclLog(count), + listAccessControlLogEntryConverter) + .run(args); + } + } + + @Override + public Status aclLogReset() { + final CommandArguments args = CommandArguments.create(SubCommand.RESET); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ACL, SubCommand.ACL_LOG) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ACL, SubCommand.ACL_LOG) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_LOG, (cmd)->cmd.aclLogReset(), + okStatusConverter) + .run(args); + } + } + + @Override + public Status aclSave() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ACL, SubCommand.SAVE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ACL, SubCommand.SAVE) + .run(); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.SAVE, (cmd)->cmd.aclSave(), okStatusConverter) + .run(); + } + } + + @Override + public Status aclSetUser(final String username, final AclSetUserArgument rules) { + final CommandArguments args = CommandArguments.create(username).add(rules); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ACL, SubCommand.ACL_SETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ACL, SubCommand.ACL_SETUSER) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_SETUSER, + (cmd)->cmd.aclSetUser(username, rules.toArray()), okStatusConverter) + .run(args); + } + } + + @Override + public Status aclSetUser(final byte[] username, final AclSetUserArgument rules) { + final CommandArguments args = CommandArguments.create(username).add(rules); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ACL, SubCommand.ACL_SETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ACL, SubCommand.ACL_SETUSER) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_SETUSER, + (cmd)->cmd.aclSetUser(username, rules.toBinaryArray()), okStatusConverter) + .run(args); + } + } + + @Override + public List aclUsers() { + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.ACL, SubCommand.ACL_USERS) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.ACL, SubCommand.ACL_USERS) + .run(); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_USERS, (cmd)->cmd.aclUsers(), (v)->v) + .run(); + } + } + + @Override + public String aclWhoAmI() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ACL, SubCommand.ACL_WHOAMI) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ACL, SubCommand.ACL_WHOAMI) + .run(); + }else{ + return new JedisCommand<>(client, Command.ACL, SubCommand.ACL_WHOAMI, (cmd)->cmd.aclWhoAmI(), (v)->v) + .run(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisBitMapOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisBitMapOperations.java new file mode 100644 index 000000000..748d011c8 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisBitMapOperations.java @@ -0,0 +1,531 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.BitType; +import com.buession.redis.core.BitOperation; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.BitFieldArgument; +import com.buession.redis.core.command.args.BitFieldRoArgument; +import com.buession.redis.core.internal.convert.jedis.params.BitTypeConverter; +import com.buession.redis.core.internal.convert.jedis.params.BitOperationConverter; +import com.buession.redis.core.internal.jedis.JedisBitPosParams; +import redis.clients.jedis.args.BitOP; +import redis.clients.jedis.params.BitPosParams; + +import java.util.List; + +/** + * Jedis 单机模式 BitMap 命令操作抽象类 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisBitMapOperations extends AbstractBitMapOperations { + + public JedisBitMapOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public Long bitCount(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final String key, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end).add(bitType); + final redis.clients.jedis.args.BitCountOption option = (new BitTypeConverter()).convert( + bitType); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end, option), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end, option), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end, option), + (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end).add(bitType); + final redis.clients.jedis.args.BitCountOption option = (new BitTypeConverter()).convert( + bitType); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end, option), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end, option), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end, option), + (v)->v) + .run(args); + } + } + + @Override + public List bitField(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + } + } + + @Override + public List bitField(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + } + } + + @Override + public List bitField(final String key, final BitFieldArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + final String[] arguments = argument.toArray(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + } + } + + @Override + public List bitField(final byte[] key, final BitFieldArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + final byte[][] arguments = argument.toBinaryArray(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + } + } + + @Override + public List bitFieldRo(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), (v)->v) + .run(args); + } + } + + @Override + public List bitFieldRo(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), (v)->v) + .run(args); + } + } + + @Override + public List bitFieldRo(final String key, final BitFieldRoArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + final String[] arguments = argument.toArray(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key, arguments), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + } + } + + @Override + public List bitFieldRo(final byte[] key, final BitFieldRoArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + final byte[][] arguments = argument.toBinaryArray(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key, arguments), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + } + } + + @Override + public Long bitOp(final BitOperation operation, final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create(operation).add(destKey).add(keys); + final BitOP bitOP = (new BitOperationConverter()).convert(operation); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(operation).add(destKey).add(keys); + final BitOP bitOP = (new BitOperationConverter()).convert(operation); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final String key, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final String key, final boolean value, final long start) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start); + final BitPosParams bitPosParams = new JedisBitPosParams(start); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start); + final BitPosParams bitPosParams = new JedisBitPosParams(start); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(bitType); + final BitPosParams bitPosParams = new JedisBitPosParams(start, bitType); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(bitType); + final BitPosParams bitPosParams = new JedisBitPosParams(start); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end); + final BitPosParams bitPosParams = new JedisBitPosParams(start, end); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end); + final BitPosParams bitPosParams = new JedisBitPosParams(start, end); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end).add(bitType); + final BitPosParams bitPosParams = new JedisBitPosParams(start, end, bitType); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end).add(bitType); + final BitPosParams bitPosParams = new JedisBitPosParams(start, end, bitType); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Boolean getBit(final String key, final long offset) { + final CommandArguments args = CommandArguments.create(key).add(offset); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + } + } + + @Override + public Boolean getBit(final byte[] key, final long offset) { + final CommandArguments args = CommandArguments.create(key).add(offset); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + } + } + + @Override + public Boolean setBit(final String key, final long offset, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(offset).add(value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + } + } + + @Override + public Boolean setBit(final byte[] key, final long offset, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(offset).add(value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + } + } + + private Long bitPos(final String key, final boolean value, final BitPosParams bitPosParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, bitPosParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, bitPosParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + } + } + + private Long bitPos(final byte[] key, final boolean value, final BitPosParams bitPosParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, bitPosParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, bitPosParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterAclOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterAclOperations.java new file mode 100644 index 000000000..c5feae365 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterAclOperations.java @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.AclCategory; +import com.buession.redis.core.AclLog; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.AclSetUserArgument; + +import java.util.List; + +/** + * Jedis 集群模式权限命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisClusterAclOperations extends AbstractAclOperations { + + public JedisClusterAclOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public List aclCat() { + return notCommand(client, Command.ACL, SubCommand.ACL_CAT); + } + + @Override + public List aclCat(final AclCategory aclCategory) { + final CommandArguments args = CommandArguments.create(aclCategory); + return notCommand(client, Command.ACL, SubCommand.ACL_CAT, args); + } + + @Override + public Long aclDelUser(final String... usernames) { + final CommandArguments args = CommandArguments.create(usernames); + return notCommand(client, Command.ACL, SubCommand.ACL_DELUSER, args); + } + + @Override + public Long aclDelUser(final byte[]... usernames) { + final CommandArguments args = CommandArguments.create(usernames); + return notCommand(client, Command.ACL, SubCommand.ACL_DELUSER, args); + } + + @Override + public Status aclDryRun(final String username, final Command command) { + final CommandArguments args = CommandArguments.create(username).add(command); + return notCommand(client, Command.ACL, SubCommand.ACL_DRYRUN, args); + } + + @Override + public Status aclDryRun(final byte[] username, final Command command) { + final CommandArguments args = CommandArguments.create(username).add(command); + return notCommand(client, Command.ACL, SubCommand.ACL_DRYRUN, args); + } + + @Override + public Status aclDryRun(final String username, final Command command, final String... arguments) { + final CommandArguments args = CommandArguments.create(username).add(command).add(arguments); + return notCommand(client, Command.ACL, SubCommand.ACL_DRYRUN, args); + } + + @Override + public Status aclDryRun(final byte[] username, final Command command, final byte[]... arguments) { + final CommandArguments args = CommandArguments.create(username).add(command).add(arguments); + return notCommand(client, Command.ACL, SubCommand.ACL_DRYRUN, args); + } + + @Override + public String aclGenPass() { + return notCommand(client, Command.ACL, SubCommand.ACL_GENPASS); + } + + @Override + public String aclGenPass(final int bits) { + final CommandArguments args = CommandArguments.create(bits); + return notCommand(client, Command.ACL, SubCommand.ACL_GENPASS, args); + } + + @Override + public AclUser aclGetUser(final String username) { + final CommandArguments args = CommandArguments.create(username); + return notCommand(client, Command.ACL, SubCommand.ACL_GETUSER, args); + } + + @Override + public AclUser aclGetUser(final byte[] username) { + final CommandArguments args = CommandArguments.create(username); + return notCommand(client, Command.ACL, SubCommand.ACL_GETUSER, args); + } + + @Override + public List aclList() { + return notCommand(client, Command.ACL, SubCommand.LIST); + } + + @Override + public Status aclLoad() { + return notCommand(client, Command.ACL, SubCommand.LOAD); + } + + @Override + public List aclLog() { + return notCommand(client, Command.ACL, SubCommand.ACL_LOG); + } + + @Override + public List aclLog(final int count) { + final CommandArguments args = CommandArguments.create(count); + return notCommand(client, Command.ACL, SubCommand.ACL_LOG, args); + } + + @Override + public Status aclLogReset() { + final CommandArguments args = CommandArguments.create(SubCommand.RESET); + return notCommand(client, Command.ACL, SubCommand.ACL_LOG, args); + } + + @Override + public Status aclSave() { + return notCommand(client, Command.ACL, SubCommand.SAVE); + } + + @Override + public Status aclSetUser(final String username, final AclSetUserArgument rules) { + final CommandArguments args = CommandArguments.create(username).add(rules); + return notCommand(client, Command.ACL, SubCommand.ACL_SETUSER, args); + } + + @Override + public Status aclSetUser(final byte[] username, final AclSetUserArgument rules) { + final CommandArguments args = CommandArguments.create(username).add(rules); + return notCommand(client, Command.ACL, SubCommand.ACL_SETUSER, args); + } + + @Override + public List aclUsers() { + return notCommand(client, Command.ACL, SubCommand.ACL_USERS); + } + + @Override + public String aclWhoAmI() { + return notCommand(client, Command.ACL, SubCommand.ACL_WHOAMI); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterBitMapOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterBitMapOperations.java new file mode 100644 index 000000000..7f65b9daf --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterBitMapOperations.java @@ -0,0 +1,550 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.BitType; +import com.buession.redis.core.BitOperation; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.BitFieldArgument; +import com.buession.redis.core.command.args.BitFieldRoArgument; +import com.buession.redis.core.internal.convert.jedis.params.BitTypeConverter; +import com.buession.redis.core.internal.convert.jedis.params.BitOperationConverter; +import com.buession.redis.core.internal.jedis.JedisBitPosParams; +import redis.clients.jedis.args.BitOP; +import redis.clients.jedis.params.BitPosParams; + +import java.util.List; + +/** + * Jedis 集群模式 BitMap 命令操作抽象类 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterBitMapOperations extends AbstractBitMapOperations { + + public JedisClusterBitMapOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public Long bitCount(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final String key, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end).add(bitType); + final redis.clients.jedis.args.BitCountOption option = (new BitTypeConverter()).convert( + bitType); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end, option), + (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end).add(bitType); + final redis.clients.jedis.args.BitCountOption option = (new BitTypeConverter()).convert( + bitType); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end, option), + (v)->v) + .run(args); + } + } + + @Override + public List bitField(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + } + } + + @Override + public List bitField(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + } + } + + @Override + public List bitField(final String key, final BitFieldArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + final String[] arguments = argument.toArray(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + } + } + + @Override + public List bitField(final byte[] key, final BitFieldArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + final byte[][] arguments = argument.toBinaryArray(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + } + } + + @Override + public List bitFieldRo(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), (v)->v) + .run(args); + } + } + + @Override + public List bitFieldRo(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), (v)->v) + .run(args); + } + } + + @Override + public List bitFieldRo(final String key, final BitFieldRoArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + final String[] arguments = argument.toArray(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key, arguments), + (v)->v) + .run(args); + } + } + + @Override + public List bitFieldRo(final byte[] key, final BitFieldRoArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + final byte[][] arguments = argument.toBinaryArray(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key, arguments), + (v)->v) + .run(args); + } + } + + @Override + public Long bitOp(final BitOperation operation, final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create(operation).add(destKey).add(keys); + final BitOP bitOP = (new BitOperationConverter()).convert(operation); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(operation).add(destKey).add(keys); + final BitOP bitOP = (new BitOperationConverter()).convert(operation); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final String key, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final String key, final boolean value, final long start) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start); + final BitPosParams bitPosParams = new JedisBitPosParams(start); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start); + final BitPosParams bitPosParams = new JedisBitPosParams(start); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(bitType); + final BitPosParams bitPosParams = new JedisBitPosParams(start, bitType); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(bitType); + final BitPosParams bitPosParams = new JedisBitPosParams(start); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end); + final BitPosParams bitPosParams = new JedisBitPosParams(start, end); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end); + final BitPosParams bitPosParams = new JedisBitPosParams(start, end); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end).add(bitType); + final BitPosParams bitPosParams = new JedisBitPosParams(start, end, bitType); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end).add(bitType); + final BitPosParams bitPosParams = new JedisBitPosParams(start, end, bitType); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Boolean getBit(final String key, final long offset) { + final CommandArguments args = CommandArguments.create(key).add(offset); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + } + } + + @Override + public Boolean getBit(final byte[] key, final long offset) { + final CommandArguments args = CommandArguments.create(key).add(offset); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + } + } + + @Override + public Boolean setBit(final String key, final long offset, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(offset).add(value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + } + } + + @Override + public Boolean setBit(final byte[] key, final long offset, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(offset).add(value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + } + } + + private Long bitPos(final String key, final boolean value, final BitPosParams bitPosParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, bitPosParams), + (v)->v) + .run(args); + } + } + + private Long bitPos(final byte[] key, final boolean value, final BitPosParams bitPosParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, bitPosParams), + (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterClusterOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterClusterOperations.java new file mode 100644 index 000000000..47dea0cbd --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterClusterOperations.java @@ -0,0 +1,272 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.BumpEpoch; +import com.buession.redis.core.ClusterFailoverOption; +import com.buession.redis.core.ClusterInfo; +import com.buession.redis.core.ClusterLink; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.ClusterResetOption; +import com.buession.redis.core.ClusterSetSlotOption; +import com.buession.redis.core.ClusterRedisShard; +import com.buession.redis.core.ClusterSlot; +import com.buession.redis.core.SlotRange; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; + +import java.util.List; + +/** + * Jedis 集群模式集群命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterClusterOperations extends AbstractClusterOperations { + + public JedisClusterClusterOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public Status asking() { + return notCommand(client, Command.ASKING); + } + + @Override + public Status clusterAddSlots(final int... slots) { + final CommandArguments args = CommandArguments.create(slots); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTS, args); + } + + @Override + public Status clusterAddSlotsRange(final SlotRange... slots) { + final CommandArguments args = CommandArguments.create(slots); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTSRANGE, args); + } + + @Override + public KeyValue clusterBumpEpoch() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_BUMPEPOCH); + } + + @Override + public Long clusterCountFailureReports(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTFAILUREREPORTS, args); + } + + @Override + public Long clusterCountFailureReports(final byte[] nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTFAILUREREPORTS, args); + } + + @Override + public Long clusterCountKeysInSlot(final int slot) { + final CommandArguments args = CommandArguments.create(slot); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTKEYSINSLOT, args); + } + + @Override + public Status clusterDelSlots(final int... slots) { + final CommandArguments args = CommandArguments.create(slots); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTS, args); + } + + @Override + public Status clusterDelSlotsRange(final SlotRange... slots) { + final CommandArguments args = CommandArguments.create(slots); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTSRANGE, args); + } + + @Override + public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption) { + final CommandArguments args = CommandArguments.create(clusterFailoverOption); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_FAILOVER, args); + } + + @Override + public Status clusterFlushSlots() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_FLUSHSLOTS); + } + + @Override + public Status clusterForget(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_FORGET, args); + } + + @Override + public Status clusterForget(final byte[] nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_FORGET, args); + } + + @Override + public List clusterGetKeysInSlot(final int slot, final int count) { + final CommandArguments args = CommandArguments.create(slot).add(count); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, args); + } + + @Override + public ClusterInfo clusterInfo() { + return notCommand(client, Command.CLUSTER, SubCommand.INFO); + } + + @Override + public Long clusterKeySlot(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_KEYSLOT, args); + } + + @Override + public Long clusterKeySlot(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_KEYSLOT, args); + } + + @Override + public List clusterLinks() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_LINKS); + } + + @Override + public Status clusterMeet(final String ip, final int port) { + final CommandArguments args = CommandArguments.create(ip).add(port); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MEET, args); + } + + @Override + public String clusterMyId() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MYID); + } + + @Override + public String clusterMyShardId() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MYSHARDID); + } + + @Override + public List clusterNodes() { + return notCommand(client, Command.CLUSTER, SubCommand.NODES); + } + + @Override + public List clusterReplicas(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICAS, args); + } + + @Override + public List clusterReplicas(final byte[] nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICAS, args); + } + + @Override + public Status clusterReplicate(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICATE, args); + } + + @Override + public Status clusterReplicate(final byte[] nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICATE, args); + } + + @Override + public Status clusterReset() { + return notCommand(client, Command.CLUSTER, SubCommand.RESET); + } + + @Override + public Status clusterReset(final ClusterResetOption clusterResetOption) { + final CommandArguments args = CommandArguments.create(clusterResetOption); + return notCommand(client, Command.CLUSTER, SubCommand.RESET, args); + } + + @Override + public Status clusterSaveConfig() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SAVECONFIG); + } + + @Override + public Status clusterSetConfigEpoch(final long configEpoch) { + final CommandArguments args = CommandArguments.create(configEpoch); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SETCONFIGEPOCH, args); + } + + @Override + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId) { + final CommandArguments args = CommandArguments.create(slot).add(setSlotOption).add(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SETSLOT, args); + } + + @Override + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final byte[] nodeId) { + final CommandArguments args = CommandArguments.create(slot).add(setSlotOption).add(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SETSLOT, args); + } + + @Override + public List clusterShards() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SHARDS); + } + + @Override + public List clusterSlaves(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.SLAVES, args); + } + + @Override + public List clusterSlaves(final byte[] nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.SLAVES, args); + } + + @Override + public List clusterSlots() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SLOTS); + } + + @Override + public Status readOnly() { + return notCommand(client, Command.READONLY); + } + + @Override + public Status readWrite() { + return notCommand(client, Command.READWRITE); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterConnectionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterConnectionOperations.java new file mode 100644 index 000000000..0c8b1b10b --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterConnectionOperations.java @@ -0,0 +1,274 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.Client; +import com.buession.redis.core.ClientAttributeOption; +import com.buession.redis.core.ClientPauseMode; +import com.buession.redis.core.ClientReply; +import com.buession.redis.core.ClientTrackingInfo; +import com.buession.redis.core.ClientType; +import com.buession.redis.core.ClientUnblockType; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.RedisServer; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.ClientKillArgument; +import com.buession.redis.core.command.args.ClientTracking; +import com.buession.redis.core.command.args.HelloArgument; +import com.buession.redis.core.internal.convert.response.PingResultConverter; + +import java.util.List; + +/** + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterConnectionOperations extends AbstractConnectionOperations { + + public JedisClusterConnectionOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public Status auth(final String user, final String password) { + final CommandArguments args = CommandArguments.create(user).add(password); + return notCommand(client, Command.AUTH, args); + } + + @Override + public Status auth(final byte[] user, final byte[] password) { + final CommandArguments args = CommandArguments.create(user).add(password); + return notCommand(client, Command.AUTH, args); + } + + @Override + public Status auth(final String password) { + final CommandArguments args = CommandArguments.create(password); + return notCommand(client, Command.AUTH, args); + } + + @Override + public Status auth(final byte[] password) { + final CommandArguments args = CommandArguments.create(password); + return notCommand(client, Command.AUTH, args); + } + + @Override + public Status clientCaching() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_CACHING); + } + + @Override + public Status clientCaching(final boolean isYes) { + final CommandArguments args = CommandArguments.create(isYes ? Keyword.Common.YES : Keyword.Common.NO); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_CACHING, args); + } + + @Override + public String clientGetName() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_GETNAME); + } + + @Override + public Integer clientGetRedir() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_GETREDIR); + } + + @Override + public Long clientId() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_ID); + } + + @Override + public Client clientInfo() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_INFO); + } + + @Override + public Status clientKill(final String host, final int port) { + final CommandArguments args = CommandArguments.create(host).add(port); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_KILL, args); + } + + @Override + public Long clientKill(final ClientKillArgument... clientKillArguments) { + final CommandArguments args = CommandArguments.create(clientKillArguments); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_KILL, args); + } + + @Override + public List clientList() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_LIST); + } + + @Override + public List clientList(final ClientType clientType) { + final CommandArguments args = CommandArguments.create(clientType); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_LIST, args); + } + + @Override + public List clientList(final long... clientIds) { + final CommandArguments args = CommandArguments.create(clientIds); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_LIST, args); + } + + @Override + public Status clientNoEvict(final boolean on) { + final CommandArguments args = CommandArguments.create(on ? Keyword.Common.ON : Keyword.Common.OFF); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_NO_EVICT, args); + } + + @Override + public Status clientNoTouch(final boolean on) { + final CommandArguments args = CommandArguments.create(on ? Keyword.Common.ON : Keyword.Common.OFF); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_NO_TOUCH, args); + } + + @Override + public Status clientPause(final int timeout) { + final CommandArguments args = CommandArguments.create(timeout); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, args); + } + + @Override + public Status clientPause(final int timeout, final ClientPauseMode pauseMode) { + final CommandArguments args = CommandArguments.create(timeout).add(pauseMode); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, args); + } + + @Override + public Status clientReply(final ClientReply option) { + final CommandArguments args = CommandArguments.create(option); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_REPLY, args); + } + + @Override + public Status clientSetInfo(final ClientAttributeOption clientAttributeOption, final String value) { + final CommandArguments args = CommandArguments.create(clientAttributeOption).add(value); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_SETINFO, args); + } + + @Override + public Status clientSetInfo(final ClientAttributeOption clientAttributeOption, final byte[] value) { + final CommandArguments args = CommandArguments.create(clientAttributeOption).add(value); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_SETINFO, args); + } + + @Override + public Status clientSetName(final String name) { + final CommandArguments args = CommandArguments.create(name); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_SETNAME, args); + } + + @Override + public Status clientSetName(final byte[] name) { + final CommandArguments args = CommandArguments.create(name); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_SETNAME, args); + } + + @Override + public Status clientTracking(final ClientTracking clientTracking) { + final CommandArguments args = CommandArguments.create(clientTracking); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_TRACKING, args); + } + + @Override + public ClientTrackingInfo clientTrackingInfo() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_TRACKINGINFO); + } + + @Override + public Status clientUnblock(final int clientId) { + final CommandArguments args = CommandArguments.create(clientId); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK, args); + } + + @Override + public Status clientUnblock(final int clientId, final ClientUnblockType type) { + final CommandArguments args = CommandArguments.create(clientId).add(type); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK, args); + } + + @Override + public Status clientUnPause() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_UNPAUSE); + } + + @Override + public String echo(final String str) { + final CommandArguments args = CommandArguments.create(str); + return notCommand(client, Command.ECHO, args); + } + + @Override + public byte[] echo(final byte[] str) { + final CommandArguments args = CommandArguments.create(str); + return notCommand(client, Command.ECHO, args); + } + + @Override + public RedisServer hello(final HelloArgument helloArgument) { + final CommandArguments args = CommandArguments.create(helloArgument); + return notCommand(client, Command.HELLO, args); + } + + @Override + public Status ping() { + final PingResultConverter pingResultConverter = new PingResultConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, Command.PING) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, Command.PING) + .run(); + }else{ + return new JedisClusterCommand<>(client, Command.PING, (cmd)->cmd.ping(), pingResultConverter) + .run(); + } + } + + @Override + public Status quit() { + return notCommand(client, Command.QUIT); + } + + @Override + public Status reset() { + return notCommand(client, Command.RESET); + } + + @Override + public Status select(final int db) { + final CommandArguments args = CommandArguments.create(db); + return notCommand(client, Command.SELECT, args); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterGeoOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterGeoOperations.java new file mode 100644 index 000000000..bf4b471f5 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterGeoOperations.java @@ -0,0 +1,875 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.builder.MapBuilder; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Geo; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.GeoAddArgument; +import com.buession.redis.core.command.args.GeoRadiusArgument; +import com.buession.redis.core.command.args.GeoSearchArgument; +import com.buession.redis.core.command.args.GeoSearchStoreArgument; +import com.buession.redis.core.internal.convert.jedis.params.GeoUnitConverter; +import com.buession.redis.core.internal.convert.jedis.response.GeoCoordinateConverter; +import com.buession.redis.core.internal.convert.jedis.response.GeoRadiusResponseConverter; +import com.buession.redis.core.internal.jedis.JedisGeoAddParam; +import com.buession.redis.core.internal.jedis.JedisGeoRadiusParam; +import com.buession.redis.core.internal.jedis.JedisGeoSearchParam; +import com.buession.redis.core.internal.jedis.JedisGeoSearchStoreParam; +import redis.clients.jedis.GeoCoordinate; +import redis.clients.jedis.params.GeoAddParams; +import redis.clients.jedis.params.GeoRadiusParam; +import redis.clients.jedis.params.GeoSearchParam; +import redis.clients.jedis.resps.GeoRadiusResponse; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 集群模式地理位置命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterGeoOperations extends AbstractGeoOperations { + + public JedisClusterGeoOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public Long geoAdd(final String key, final String member, final double longitude, final double latitude) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(member); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, longitude, latitude, + member), (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(member); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, longitude, latitude, + member), (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + final Map geoCoordinates = createGeoCoordinateMapFromGeoMap(memberCoordinates); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + final Map geoCoordinates = createGeoCoordinateMapFromGeoMap(memberCoordinates); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final String key, final String member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(longitude).add(latitude) + .add(member); + final Map memberCoordinates = + MapBuilder.create(1).put(member, new Geo(longitude, latitude)).build(); + + return geoAdd(key, memberCoordinates, geoAddArgument, args); + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(longitude).add(latitude) + .add(member); + final Map memberCoordinates = + MapBuilder.create(1).put(member, new Geo(longitude, latitude)).build(); + + return geoAdd(key, memberCoordinates, geoAddArgument, args); + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + return geoAdd(key, memberCoordinates, geoAddArgument, args); + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(memberCoordinates); + return geoAdd(key, memberCoordinates, geoAddArgument, args); + } + + @Override + public Double geoDist(final String key, final String member1, final String member2) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + } + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + } + } + + @Override + public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + } + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + } + } + + @Override + public List geoHash(final String key, final String... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + } + } + + @Override + public List geoHash(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + } + } + + @Override + public List geoPos(final String key, final String... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } + } + + @Override + public List geoPos(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } + } + + @Override + public List geoRadius(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadius(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = + CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit).add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = + CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit).add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final String key, final String member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoSearch(final String key, final GeoSearchArgument geoSearchArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoSearchArgument); + final GeoSearchParam geoSearchParam = JedisGeoSearchParam.from(geoSearchArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEOSEARCH, + (cmd)->cmd.geosearch(key, geoSearchParam), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEOSEARCH, + (cmd)->cmd.geosearch(key, geoSearchParam), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEOSEARCH, + (cmd)->cmd.geosearch(key, geoSearchParam), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoSearch(final byte[] key, final GeoSearchArgument geoSearchArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoSearchArgument); + final GeoSearchParam geoSearchParam = JedisGeoSearchParam.from(geoSearchArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEOSEARCH, + (cmd)->cmd.geosearch(key, geoSearchParam), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEOSEARCH, + (cmd)->cmd.geosearch(key, geoSearchParam), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEOSEARCH, + (cmd)->cmd.geosearch(key, geoSearchParam), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public Long geoSearchStore(final String destKey, final String key, + final GeoSearchStoreArgument geoSearchStoreArgument) { + final CommandArguments args = CommandArguments.create(destKey).add(key).add(geoSearchStoreArgument); + final GeoSearchParam geoSearchParam = JedisGeoSearchStoreParam.from(geoSearchStoreArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + } + } + + @Override + public Long geoSearchStore(final byte[] destKey, final byte[] key, + final GeoSearchStoreArgument geoSearchStoreArgument) { + final CommandArguments args = CommandArguments.create(destKey).add(key).add(geoSearchStoreArgument); + final GeoSearchParam geoSearchParam = JedisGeoSearchStoreParam.from(geoSearchStoreArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + } + } + + private Long geoAdd(final String key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument, final CommandArguments args) { + final Map geoCoordinates = createGeoCoordinateMapFromGeoMap(memberCoordinates); + final GeoAddParams geoAddParams = JedisGeoAddParam.from(geoAddArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + } + } + + private Long geoAdd(final byte[] key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument, final CommandArguments args) { + final Map geoCoordinates = createGeoCoordinateMapFromGeoMap(memberCoordinates); + final GeoAddParams geoAddParams = JedisGeoAddParam.from(geoAddArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterHashOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterHashOperations.java new file mode 100644 index 000000000..d40d37819 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterHashOperations.java @@ -0,0 +1,905 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapEntryKeyValueConverter; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.HScanArgument; +import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; +import com.buession.redis.core.internal.jedis.JedisScanParams; +import redis.clients.jedis.params.ScanParams; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Jedis 集群模式哈希表命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterHashOperations extends AbstractHashOperations { + + public JedisClusterHashOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public Long hDel(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } + } + + @Override + public Long hDel(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } + } + + @Override + public Boolean hExists(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } + } + + @Override + public Boolean hExists(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } + } + + @Override + public List hExpire(final String key, final int lifetime, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, + fields.length).add(fields); + return notCommand(client, Command.HEXPIRE, args); + } + + @Override + public List hExpire(final byte[] key, final int lifetime, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, + fields.length).add(fields); + return notCommand(client, Command.HEXPIRE, args); + } + + @Override + public List hExpire(final String key, final int lifetime, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIRE, args); + } + + @Override + public List hExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireAt(final String key, final long unixTimestamp, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(Keyword.Hash.FIELDS, + fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(Keyword.Hash.FIELDS, + fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireTime(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIRETIME, args); + } + + @Override + public List hExpireTime(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIRETIME, args); + } + + @Override + public String hGet(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + } + } + + @Override + public byte[] hGet(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + } + } + + @Override + public Map hGetAll(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + } + } + + @Override + public Map hGetAll(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + } + } + + @Override + public Long hIncrBy(final String key, final String field, final long value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Long hIncrBy(final byte[] key, final byte[] field, final long value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Double hIncrByFloat(final String key, final String field, final double value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HINCRBYFLOAT, (cmd)->cmd.hincrByFloat(key, field, value), + (v)->v) + .run(args); + } + } + + @Override + public Double hIncrByFloat(final byte[] key, final byte[] field, final double value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HINCRBYFLOAT, (cmd)->cmd.hincrByFloat(key, field, value), + (v)->v) + .run(args); + } + } + + @Override + public Set hKeys(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + } + } + + @Override + public Set hKeys(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + } + } + + @Override + public Long hLen(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } + } + + @Override + public Long hLen(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } + } + + @Override + public List hMGet(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + } + } + + @Override + public List hMGet(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + } + } + + @Override + public Status hMSet(final String key, final Map data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), okStatusConverter) + .run(args); + } + } + + @Override + public Status hMSet(final byte[] key, final Map data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), okStatusConverter) + .run(args); + } + } + + @Override + public List hPersist(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPERSIST, args); + } + + @Override + public List hPersist(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPERSIST, args); + } + + @Override + public List hpExpire(final String key, final int lifetime, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpire(final byte[] key, final int lifetime, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpire(final String key, final int lifetime, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = + CommandArguments.create(key).add(lifetime).add(expireOption).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = + CommandArguments.create(key).add(lifetime).add(expireOption).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpireAt(final String key, final long unixTimestamp, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireTime(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRETIME, args); + } + + @Override + public List hpExpireTime(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRETIME, args); + } + + @Override + public List hpTtl(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public List hpTtl(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public String hRandField(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] hRandField(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + } + } + + @Override + public List hRandField(final String key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + } + } + + @Override + public List hRandField(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + } + } + + @Override + public List> hRandFieldWithValues(final String key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count).add(Keyword.Hash.WITHVALUES); + final ListConverter, KeyValue> converter = + new ListConverter<>(new MapEntryKeyValueConverter<>((k)->k, (v)->v)); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfieldWithValues(key, count), + converter) + .run(args); + } + } + + @Override + public List> hRandFieldWithValues(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count).add(Keyword.Hash.WITHVALUES); + final ListConverter, KeyValue> converter = + new ListConverter<>(new MapEntryKeyValueConverter<>((k)->k, (v)->v)); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfieldWithValues(key, count), + converter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create(key).add(cursor); + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create(key).add(cursor); + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final String key, final String cursor, + final HScanArgument scanArgument) { + final CommandArguments args = CommandArguments.create(key).add(cursor).add(scanArgument); + final ScanParams scanParams = JedisScanParams.from(scanArgument); + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanParams), mapScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, + final HScanArgument scanArgument) { + final CommandArguments args = CommandArguments.create(key).add(cursor).add(scanArgument); + final ScanParams scanParams = JedisScanParams.from(scanArgument); + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanParams), mapScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + } + } + + @Override + public Long hSet(final String key, final KeyValue... data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HSET, + (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Long hSet(final byte[] key, final KeyValue... data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HSET, + (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Status hSetNx(final String key, final String field, final String value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status hSetNx(final byte[] key, final byte[] field, final byte[] value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + } + } + + @Override + public Long hStrLen(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } + } + + @Override + public Long hStrLen(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } + } + + @Override + public List hTtl(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public List hTtl(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public List hVals(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + } + } + + @Override + public List hVals(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterHyperLogLogOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterHyperLogLogOperations.java new file mode 100644 index 000000000..c19c23998 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterHyperLogLogOperations.java @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; + +/** + * Jedis 集群模式 HyperLogLog 命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterHyperLogLogOperations extends AbstractHyperLogLogOperations { + + public JedisClusterHyperLogLogOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public Status pfAdd(final String key, final String... elements) { + final CommandArguments args = CommandArguments.create(key).add(elements); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), oneStatusConverter) + .run(args); + } + } + + @Override + public Status pfAdd(final byte[] key, final byte[]... elements) { + final CommandArguments args = CommandArguments.create(key).add(elements); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), oneStatusConverter) + .run(args); + } + } + + @Override + public Long pfCount(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } + } + + @Override + public Long pfCount(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } + } + + @Override + public Status pfMerge(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create(destKey).add(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + } + } + + @Override + public Status pfMerge(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(destKey).add(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterKeyOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterKeyOperations.java new file mode 100644 index 000000000..f413e6e99 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterKeyOperations.java @@ -0,0 +1,1658 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.ObjectEncoding; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Type; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.MigrateArgument; +import com.buession.redis.core.command.args.RestoreArgument; +import com.buession.redis.core.command.args.SortArgument; +import com.buession.redis.core.internal.convert.jedis.params.ExpireOptionConverter; +import com.buession.redis.core.internal.convert.response.BinaryObjectEncodingConverter; +import com.buession.redis.core.internal.convert.response.ObjectEncodingConverter; +import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; +import com.buession.redis.core.internal.convert.response.TypeConverter; +import com.buession.redis.core.internal.jedis.JedisMigrateParams; +import com.buession.redis.core.internal.jedis.JedisRestoreParams; +import com.buession.redis.core.internal.jedis.JedisScanParams; +import com.buession.redis.core.internal.jedis.JedisSortingParams; +import com.buession.redis.utils.SafeEncoder; +import redis.clients.jedis.args.ExpiryOption; +import redis.clients.jedis.params.MigrateParams; +import redis.clients.jedis.params.RestoreParams; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.params.SortingParams; + +import java.util.List; +import java.util.Set; + +/** + * Jedis 集群模式 Key 命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterKeyOperations extends AbstractKeyOperations { + + public JedisClusterKeyOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public Status copy(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + return copy(key, destKey, false, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + return copy(key, destKey, false, args); + } + + @Override + public Status copy(final String key, final String destKey, final int db) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + return copy(key, destKey, false, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + return copy(key, destKey, false, args); + } + + @Override + public Status copy(final String key, final String destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, replace, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, replace, args); + } + + @Override + public Status copy(final String key, final String destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, replace, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, replace, args); + } + + @Override + public Long del(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } + } + + @Override + public Long del(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } + } + + @Override + public String dump(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), + SafeEncoder::encode) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), + SafeEncoder::encode) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), SafeEncoder::encode) + .run(args); + } + } + + @Override + public byte[] dump(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + } + } + + @Override + public Boolean exists(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + } + } + + @Override + public Boolean exists(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + } + } + + @Override + public Long exists(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } + } + + @Override + public Long exists(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } + } + + @Override + public Status expire(final String key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expire(final String key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final String key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final String key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + } + } + + @Override + public Long expireTime(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + } + } + + @Override + public Long expireTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + } + } + + @Override + public Set keys(final String pattern) { + final CommandArguments args = CommandArguments.create(pattern); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + } + } + + @Override + public Set keys(final byte[] pattern) { + final CommandArguments args = CommandArguments.create(pattern); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + } + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final String... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(keys); + final MigrateParams migrateParams = new JedisMigrateParams(); + + return migrate(host, port, db, timeout, keys, migrateParams, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(keys); + final MigrateParams migrateParams = new JedisMigrateParams(); + + return migrate(host, port, db, timeout, keys, migrateParams, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgument migrateArgument, final String... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(migrateArgument) + .add(keys); + final MigrateParams migrateParams = JedisMigrateParams.from(migrateArgument); + + return migrate(host, port, db, timeout, keys, migrateParams, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgument migrateArgument, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(migrateArgument) + .add(keys); + final MigrateParams migrateParams = JedisMigrateParams.from(migrateArgument); + + return migrate(host, port, db, timeout, keys, migrateParams, args); + } + + @Override + public Status move(final String key, final int db) { + final CommandArguments args = CommandArguments.create(key).add(db); + return notCommand(client, Command.MOVE, args); + } + + @Override + public Status move(final byte[] key, final int db) { + final CommandArguments args = CommandArguments.create(key).add(db); + return notCommand(client, Command.MOVE, args); + } + + @Override + public ObjectEncoding objectEncoding(final String key) { + final CommandArguments args = CommandArguments.create(key); + final ObjectEncodingConverter objectEncodingConverter = new ObjectEncodingConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + } + } + + @Override + public ObjectEncoding objectEncoding(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final BinaryObjectEncodingConverter binaryObjectEncodingConverter = new BinaryObjectEncodingConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), binaryObjectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), binaryObjectEncodingConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), binaryObjectEncodingConverter) + .run(args); + } + } + + @Override + public Long objectFreq(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + } + } + + @Override + public Long objectFreq(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + } + } + + @Override + public Long objectIdleTime(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectIdleTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectRefcount(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectRefcount(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + } + } + + @Override + public Status persist(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), oneStatusConverter) + .run(args); + } + } + + @Override + public Status persist(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final String key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final String key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final String key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PEXPIREAT, (cmd)->cmd.pexpireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PEXPIREAT, (cmd)->cmd.pexpireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + } + } + + @Override + public Long pExpireTime(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + } + } + + @Override + public Long pTtl(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } + } + + @Override + public Long pTtl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } + } + + @Override + public Long pExpireTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + } + } + + @Override + public String randomKey() { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RANDOMKEY, (cmd)->cmd.randomKey(), (v)->v) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RANDOMKEY, (cmd)->cmd.randomKey(), + (v)->v) + .run(); + }else{ + return new JedisClusterCommand<>(client, Command.RANDOMKEY, (cmd)->cmd.randomKey(), (v)->v) + .run(); + } + } + + @Override + public Status rename(final String key, final String newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + } + } + + @Override + public Status rename(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + } + } + + @Override + public Status renameNx(final String key, final String newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status renameNx(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final String key, final byte[] serializedValue, final int ttl) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RESTORE, (cmd)->cmd.restore(key, ttl, serializedValue), + okStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RESTORE, (cmd)->cmd.restore(key, ttl, serializedValue), + okStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final String key, final byte[] serializedValue, final int ttl, + final RestoreArgument restoreArgument) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl).add(restoreArgument); + final RestoreParams restoreParams = JedisRestoreParams.from(restoreArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl, + final RestoreArgument restoreArgument) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl).add(restoreArgument); + final RestoreParams restoreParams = JedisRestoreParams.from(restoreArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final String cursor) { + final CommandArguments args = CommandArguments.create(cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final byte[] cursor) { + final CommandArguments args = CommandArguments.create(cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return scan(cursor, scanParams, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return scan(cursor, scanParams, args); + } + + @Override + public ScanResult> scan(final String cursor, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(count); + final ScanParams scanParams = new JedisScanParams(count); + + return scan(cursor, scanParams, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(count); + final ScanParams scanParams = new JedisScanParams(count); + + return scan(cursor, scanParams, args); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern).add(count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return scan(cursor, scanParams, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern).add(count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return scan(cursor, scanParams, args); + } + + @Override + public List sort(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + } + } + + @Override + public List sort(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + } + } + + @Override + public List sort(final String key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + } + } + + @Override + public List sort(final byte[] key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + } + } + + @Override + public Long sort(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + } + } + + @Override + public Long sort(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + } + } + + @Override + public Long sort(final String key, final String destKey, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), + (v)->v) + .run(args); + } + } + + @Override + public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + } + } + + @Override + public List sortRo(final String key) { + final CommandArguments args = CommandArguments.create(key); + final SortingParams sortingParams = new JedisSortingParams(); + + return sortRo(key, sortingParams, args); + } + + @Override + public List sortRo(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final SortingParams sortingParams = new JedisSortingParams(); + + return sortRo(key, sortingParams, args); + } + + @Override + public List sortRo(final String key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + return sortRo(key, sortingParams, args); + } + + @Override + public List sortRo(final byte[] key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + return sortRo(key, sortingParams, args); + } + + @Override + public Long touch(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } + } + + @Override + public Long touch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } + } + + @Override + public Long ttl(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } + } + + @Override + public Long ttl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } + } + + @Override + public Type type(final String key) { + final CommandArguments args = CommandArguments.create(key); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } + } + + @Override + public Type type(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), + typeConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } + } + + @Override + public Long unlink(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } + } + + @Override + public Long unlink(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } + } + + private Status copy(final String key, final String destKey, final boolean replace, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final byte[] key, final byte[] destKey, final boolean replace, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, final String[] keys, + final MigrateParams migrateParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, final byte[][] keys, + final MigrateParams migrateParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + } + } + + private List sortRo(final String key, final SortingParams sortingParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SORT_RO, + (cmd)->cmd.sortReadonly(key, sortingParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SORT_RO, + (cmd)->cmd.sortReadonly(key, sortingParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadonly(key, sortingParams), + (v)->v) + .run(args); + } + } + + private List sortRo(final byte[] key, final SortingParams sortingParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SORT_RO, + (cmd)->cmd.sortReadonly(key, sortingParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SORT_RO, + (cmd)->cmd.sortReadonly(key, sortingParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadonly(key, sortingParams), + (v)->v) + .run(args); + } + } + + private ScanResult> scan(final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + + private ScanResult> scan(final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterListOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterListOperations.java new file mode 100644 index 000000000..e1657b878 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterListOperations.java @@ -0,0 +1,882 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.Direction; +import com.buession.redis.core.ListPosition; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.LPosArgument; +import com.buession.redis.core.internal.convert.jedis.params.DirectionConverter; +import com.buession.redis.core.internal.convert.jedis.params.ListPositionConverter; +import com.buession.redis.core.internal.jedis.JedisLPosParams; +import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.params.LPosParams; + +import java.util.List; + +/** + * Jedis 集群模式列表命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterListOperations extends AbstractListOperations { + + public JedisClusterListOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public String lIndex(final String key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + } + } + + @Override + public byte[] lIndex(final byte[] key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + } + } + + @Override + public Long lInsert(final String key, final ListPosition position, final String pivot, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) + .put("value", value); + final redis.clients.jedis.args.ListPosition listPosition = (new ListPositionConverter()).convert(position); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + } + } + + @Override + public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) + .put("value", value); + final redis.clients.jedis.args.ListPosition listPosition = (new ListPositionConverter()).convert(position); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + } + } + + @Override + public Status lSet(final String key, final long index, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status lSet(final byte[] key, final long index, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Long lLen(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } + } + + @Override + public Long lLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } + } + + @Override + public List lRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LRANGE, + (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List lRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LRANGE, + (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final String key, final String element) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final byte[] key, final byte[] element) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final String key, final String element, final LPosArgument lPosArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), + (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), + (v)->v) + .run(args); + } + } + + @Override + public List lPos(final String key, final String element, final LPosArgument lPosArgument, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) + .put("count", count); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + } + } + + @Override + public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) + .put("count", count); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + } + } + + @Override + public Long lRem(final String key, final String value, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LREM, + (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } + } + + @Override + public Long lRem(final byte[] key, final byte[] value, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LREM, + (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } + } + + @Override + public Status lTrim(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LTRIM, + (cmd)->cmd.ltrim(key, start, end), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } + } + + @Override + public Status lTrim(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LTRIM, + (cmd)->cmd.ltrim(key, start, end), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } + } + + @Override + public String lMove(final String key, final String destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + } + } + + @Override + public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + } + } + + @Override + public String blMove(final String key, final String destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to).put("timeout", timeout); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + } + } + + @Override + public byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to).put("timeout", timeout); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + } + } + + @Override + public List blPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + } + } + + @Override + public List blPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + } + } + + @Override + public List brPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + } + } + + @Override + public List brPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + } + } + + @Override + public String brPoplPush(final String key, final String destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + } + } + + @Override + public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + } + } + + @Override + public String lPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] lPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + } + } + + @Override + public Long lPush(final String key, final String... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long lPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long lPushX(final String key, final String... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long lPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } + } + + @Override + public String rPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] rPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + } + } + + @Override + public String rPoplPush(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + } + } + + @Override + public byte[] rPoplPush(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + } + } + + @Override + public Long rPush(final String key, final String... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long rPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long rPushX(final String key, final String... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long rPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterOperations.java new file mode 100644 index 000000000..38bb46fe1 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterOperations.java @@ -0,0 +1,616 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.BumpEpoch; +import com.buession.redis.core.ClusterFailoverOption; +import com.buession.redis.core.ClusterInfo; +import com.buession.redis.core.ClusterLink; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.ClusterResetOption; +import com.buession.redis.core.ClusterSetSlotOption; +import com.buession.redis.core.ClusterRedisShard; +import com.buession.redis.core.ClusterSlot; +import com.buession.redis.core.SlotRange; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.internal.convert.jedis.params.ClusterFailoverOptionConverter; +import com.buession.redis.core.internal.convert.jedis.response.ClusterLinkConverter; +import com.buession.redis.core.internal.convert.response.BumpEpochConverter; +import com.buession.redis.core.internal.convert.response.ClusterInfoConverter; +import com.buession.redis.core.internal.convert.response.ClusterNodesConverter; +import com.buession.redis.core.internal.convert.jedis.response.ClusterReplicasConverter; +import com.buession.redis.core.internal.convert.jedis.response.ClusterResetOptionConverter; +import com.buession.redis.core.internal.convert.response.ClusterNodeConverter; +import com.buession.redis.core.internal.convert.response.ClusterSlotConverter; +import redis.clients.jedis.args.ClusterResetType; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 单机模式集群命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterOperations extends AbstractClusterOperations { + + public JedisClusterOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public Status asking() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ASKING) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ASKING) + .run(); + }else{ + return new JedisCommand<>(client, Command.ASKING, (cmd)->cmd.asking(), okStatusConverter) + .run(); + } + } + + @Override + public Status clusterAddSlots(final int... slots) { + final CommandArguments args = CommandArguments.create(slots); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTS) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTS) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTS, + (cmd)->cmd.clusterAddSlots(slots), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterAddSlotsRange(final SlotRange... slots) { + final CommandArguments args = CommandArguments.create(slots); + final int[] slotRanges = numberRangeArray(slots); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTSRANGE) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_ADDSLOTSRANGE) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTSRANGE, + (cmd)->cmd.clusterAddSlotsRange(slotRanges), okStatusConverter) + .run(args); + } + } + + @Override + public KeyValue clusterBumpEpoch() { + final BumpEpochConverter bumpEpochConverter = new BumpEpochConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, KeyValue>(client, + Command.CLUSTER, SubCommand.CLUSTER_BUMPEPOCH) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, KeyValue>(client, + Command.CLUSTER, SubCommand.CLUSTER_BUMPEPOCH) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_BUMPEPOCH, + (cmd)->cmd.clusterBumpEpoch(), bumpEpochConverter) + .run(); + } + } + + @Override + public Long clusterCountFailureReports(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTFAILUREREPORTS) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_COUNTFAILUREREPORTS) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTFAILUREREPORTS, + (cmd)->cmd.clusterCountFailureReports(nodeId), (v)->v) + .run(args); + } + } + + @Override + public Long clusterCountKeysInSlot(final int slot) { + final CommandArguments args = CommandArguments.create(slot); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTKEYSINSLOT) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + } + } + + @Override + public Status clusterDelSlots(final int... slots) { + final CommandArguments args = CommandArguments.create(slots); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTS) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTS) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTS, + (cmd)->cmd.clusterDelSlots(slots), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterDelSlotsRange(final SlotRange... slots) { + final CommandArguments args = CommandArguments.create(slots); + final int[] slotRanges = numberRangeArray(slots); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTSRANGE) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_DELSLOTSRANGE) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTSRANGE, + (cmd)->cmd.clusterDelSlots(slotRanges), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption) { + final CommandArguments args = CommandArguments.create(clusterFailoverOption); + final redis.clients.jedis.args.ClusterFailoverOption failoverOption = + (new ClusterFailoverOptionConverter()).convert(clusterFailoverOption); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_FAILOVER) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.CLUSTER_FAILOVER) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FAILOVER, + (cmd)->cmd.clusterFailover(failoverOption), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterFlushSlots() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_FLUSHSLOTS) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.CLUSTER_FLUSHSLOTS) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FLUSHSLOTS, + (cmd)->cmd.clusterFlushSlots(), okStatusConverter) + .run(); + } + } + + @Override + public Status clusterForget(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_FORGET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.CLUSTER_FORGET) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FORGET, + (cmd)->cmd.clusterForget(nodeId), okStatusConverter) + .run(args); + } + } + + @Override + public List clusterGetKeysInSlot(final int slot, final int count) { + final CommandArguments args = CommandArguments.create(slot).add(count); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.CLUSTER, + SubCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.CLUSTER, + SubCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, count), (v)->v) + .run(args); + } + } + + @Override + public ClusterInfo clusterInfo() { + final ClusterInfoConverter clusterInfoConverter = new ClusterInfoConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.INFO) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.INFO) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.INFO, (cmd)->cmd.clusterInfo(), + clusterInfoConverter) + .run(); + } + } + + @Override + public Long clusterKeySlot(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_KEYSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.CLUSTER_KEYSLOT) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_KEYSLOT, + (cmd)->cmd.clusterKeySlot(key), (v)->v) + .run(args); + } + } + + @Override + public List clusterLinks() { + final ListConverter, ClusterLink> listConverter = ClusterLinkConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.CLUSTER, + SubCommand.CLUSTER_LINKS) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.CLUSTER, + SubCommand.CLUSTER_LINKS) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_LINKS, (cmd)->cmd.clusterLinks(), + listConverter) + .run(); + } + } + + @Override + public Status clusterMeet(final String ip, final int port) { + final CommandArguments args = CommandArguments.create(ip).add(port); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MEET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MEET) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MEET, + (cmd)->cmd.clusterMeet(ip, port), okStatusConverter) + .run(args); + } + } + + @Override + public String clusterMyId() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MYID) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MYID) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MYID, (cmd)->cmd.clusterMyId(), + (v)->v) + .run(); + } + } + + @Override + public String clusterMyShardId() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MYSHARDID) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MYSHARDID) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MYSHARDID, + (cmd)->cmd.clusterMyShardId(), (v)->v) + .run(); + } + } + + @Override + public List clusterNodes() { + final ClusterNodesConverter clusterNodesConverter = new ClusterNodesConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, + Command.CLUSTER, SubCommand.NODES) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, + Command.CLUSTER, SubCommand.NODES) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.NODES, (cmd)->cmd.clusterNodes(), + clusterNodesConverter) + .run(); + } + } + + @Override + public List clusterReplicas(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + final ListConverter listClusterReplicasConverter = ClusterReplicasConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, + Command.CLUSTER, SubCommand.CLUSTER_REPLICAS) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, + Command.CLUSTER, SubCommand.CLUSTER_REPLICAS) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICAS, + (cmd)->cmd.clusterReplicas(nodeId), listClusterReplicasConverter) + .run(args); + } + } + + @Override + public Status clusterReplicate(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICATE) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICATE) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICATE, + (cmd)->cmd.clusterReplicate(nodeId), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterReset() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.RESET) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.RESET) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.RESET, (cmd)->cmd.clusterReset(), + okStatusConverter) + .run(); + } + } + + @Override + public Status clusterReset(final ClusterResetOption clusterResetOption) { + final CommandArguments args = CommandArguments.create(clusterResetOption); + final ClusterResetType clusterResetType = (new ClusterResetOptionConverter()).convert(clusterResetOption); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.RESET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.RESET) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.RESET, + (cmd)->cmd.clusterReset(clusterResetType), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterSaveConfig() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SAVECONFIG) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SAVECONFIG) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SAVECONFIG, + (cmd)->cmd.clusterSaveConfig(), okStatusConverter) + .run(); + } + } + + @Override + public Status clusterSetConfigEpoch(final long configEpoch) { + final CommandArguments args = CommandArguments.create(configEpoch); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SETCONFIGEPOCH) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_SETCONFIGEPOCH) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId) { + final CommandArguments args = CommandArguments.create(slot).add(setSlotOption).add(nodeId); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SETSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SETSLOT) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + } + } + + @Override + public List clusterShards() { + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.CLUSTER, + SubCommand.CLUSTER_SHARDS) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, + Command.CLUSTER, + SubCommand.CLUSTER_SHARDS) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SHARDS, (cmd)->cmd.clusterShards(), + okStatusConverter) + .run(); + } + } + + @Override + public List clusterSlaves(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + final ListConverter listClusterNodeConverter = ClusterNodeConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.CLUSTER, + SubCommand.SLAVES) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.CLUSTER, + SubCommand.SLAVES) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.SLAVES, (cmd)->cmd.clusterSlaves(nodeId), + listClusterNodeConverter) + .run(args); + } + } + + @Override + public List clusterSlots() { + final ListConverter listClusterSlotConverter = ClusterSlotConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.CLUSTER, + SubCommand.CLUSTER_SLOTS) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, + Command.CLUSTER, SubCommand.CLUSTER_SLOTS) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SLOTS, (cmd)->cmd.clusterSlots(), + listClusterSlotConverter) + .run(); + } + } + + @Override + public Status readOnly() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.READONLY) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.READONLY) + .run(); + }else{ + return new JedisCommand<>(client, Command.READONLY, (cmd)->cmd.readonly(), okStatusConverter) + .run(); + } + } + + @Override + public Status readWrite() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.READWRITE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.READWRITE) + .run(); + }else{ + return new JedisCommand<>(client, Command.READWRITE, (cmd)->cmd.readwrite(), okStatusConverter) + .run(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterPubSubOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterPubSubOperations.java new file mode 100644 index 000000000..22c45b72f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterPubSubOperations.java @@ -0,0 +1,272 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.PubSubListener; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.pubsub.jedis.DefaultBinaryJedisPubSub; +import com.buession.redis.pubsub.jedis.DefaultJedisPubSub; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 集群模式 Pub/Sub 命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public class JedisClusterPubSubOperations extends AbstractPubSubOperations { + + public JedisClusterPubSubOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + + if(isPipeline()){ + new JedisClusterPipelineCommand<>(client, Command.PSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisClusterTransactionCommand<>(client, Command.PSUBSCRIBE) + .run(args); + }else{ + new JedisClusterCommand<>(client, Command.PSUBSCRIBE, (cmd)->{ + cmd.psubscribe(new DefaultJedisPubSub(pubSubListener), patterns); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + + if(isPipeline()){ + new JedisClusterPipelineCommand<>(client, Command.PSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisClusterTransactionCommand<>(client, Command.PSUBSCRIBE) + .run(args); + }else{ + new JedisClusterCommand<>(client, Command.PSUBSCRIBE, (cmd)->{ + cmd.psubscribe(new DefaultBinaryJedisPubSub(pubSubListener), patterns); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public Long publish(final String channel, final String message) { + final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PUBLISH, + (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, Command.PUBLISH) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + } + } + + @Override + public Long publish(final byte[] channel, final byte[] message) { + final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PUBLISH, + (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, Command.PUBLISH) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + } + } + + @Override + public List pubsubChannels() { + return notCommand(client, Command.PUBSUB_CHANNELS); + } + + @Override + public List pubsubChannels(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return notCommand(client, Command.PUBSUB_CHANNELS, args); + } + + @Override + public List pubsubChannels(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return notCommand(client, Command.PUBSUB_CHANNELS, args); + } + + @Override + public List pubsubShardChannels() { + return notCommand(client, Command.PUBSUB_SHARDCHANNELS); + } + + @Override + public List pubsubShardChannels(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return notCommand(client, Command.PUBSUB_SHARDCHANNELS, args); + } + + @Override + public List pubsubShardChannels(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return notCommand(client, Command.PUBSUB_SHARDCHANNELS, args); + } + + @Override + public Long pubsubNumPat() { + return notCommand(client, Command.PUBSUB_NUMPAT); + } + + @Override + public Map pubsubNumSub() { + return notCommand(client, Command.PUBSUB_NUMSUB); + } + + @Override + public Map pubsubNumSub(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return notCommand(client, Command.PUBSUB_NUMSUB, args); + } + + @Override + public Map pubsubNumSub(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return notCommand(client, Command.PUBSUB_NUMSUB, args); + } + + @Override + public Map pubsubShardNumSub() { + return notCommand(client, Command.PUBSUB_SHARDNUMSUB); + } + + @Override + public Map pubsubShardNumSub(final String... shardChannels) { + final CommandArguments args = CommandArguments.create("shardChannels", (Object[]) shardChannels); + return notCommand(client, Command.PUBSUB_SHARDNUMSUB, args); + } + + @Override + public Map pubsubShardNumSub(final byte[]... shardChannels) { + final CommandArguments args = CommandArguments.create("shardChannels", (Object[]) shardChannels); + return notCommand(client, Command.PUBSUB_SHARDNUMSUB, args); + } + + @Override + public Object pUnSubscribe() { + return notCommand(client, Command.PUNSUBSCRIBE); + } + + @Override + public Object pUnSubscribe(final String... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return notCommand(client, Command.PUNSUBSCRIBE, args); + } + + @Override + public Object pUnSubscribe(final byte[]... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return notCommand(client, Command.PUNSUBSCRIBE, args); + } + + @Override + public void subscribe(final String[] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + + if(isPipeline()){ + new JedisClusterPipelineCommand<>(client, Command.SUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisClusterTransactionCommand<>(client, Command.SUBSCRIBE) + .run(args); + }else{ + new JedisClusterCommand<>(client, Command.SUBSCRIBE, (cmd)->{ + cmd.subscribe(new DefaultJedisPubSub(pubSubListener), channels); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public void subscribe(final byte[][] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + + if(isPipeline()){ + new JedisClusterPipelineCommand<>(client, Command.SUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisClusterTransactionCommand<>(client, Command.SUBSCRIBE) + .run(args); + }else{ + new JedisClusterCommand<>(client, Command.SUBSCRIBE, (cmd)->{ + cmd.subscribe(new DefaultBinaryJedisPubSub(pubSubListener), channels); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public Object unSubscribe() { + return notCommand(client, Command.UNSUBSCRIBE); + } + + @Override + public Object unSubscribe(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return notCommand(client, Command.UNSUBSCRIBE, args); + } + + @Override + public Object unSubscribe(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return notCommand(client, Command.UNSUBSCRIBE, args); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterScriptingOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterScriptingOperations.java new file mode 100644 index 000000000..68ce2810d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterScriptingOperations.java @@ -0,0 +1,415 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.jedis.params.FlushModeConverter; +import com.buession.redis.utils.SafeEncoder; + +import java.util.Arrays; +import java.util.List; + +/** + * Jedis 集群模式 Script 命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterScriptingOperations extends AbstractScriptingOperations { + + public JedisClusterScriptingOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public Object eval(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final byte[] script) { + final CommandArguments args = CommandArguments.create("script", script); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final String script, final String... params) { + final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + final int paramsSize = params == null ? 0 : params.length; + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script, paramsSize, params), + (v)->v) + .run(args); + } + } + + @Override + public Object eval(final byte[] script, final byte[]... params) { + final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + final int paramsSize = params == null ? 0 : params.length; + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script, paramsSize, params), + (v)->v) + .run(args); + } + } + + @Override + public Object eval(final String script, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments) { + final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final String digest) { + final CommandArguments args = CommandArguments.create("digest", digest); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final byte[] digest) { + final CommandArguments args = CommandArguments.create("digest", digest); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final String digest, final String... params) { + final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); + final int paramsSize = params == null ? 0 : params.length; + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final byte[] digest, final byte[]... params) { + final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); + final int paramsSize = params == null ? 0 : params.length; + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final String digest, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final byte[] digest, final byte[][] keys, final byte[][] arguments) { + final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + } + } + + @Override + public List scriptExists(final String... sha1) { + final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + } + } + + @Override + public List scriptExists(final byte[]... sha1) { + final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + } + } + + @Override + public Status scriptFlush() { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null), okStatusConverter) + .run(); + }else{ + return new JedisClusterCommand<>(client, Command.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(); + } + } + + @Override + public Status scriptFlush(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + final redis.clients.jedis.args.FlushMode flushMode = (new FlushModeConverter()).convert(mode); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null, flushMode), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null, flushMode), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null, flushMode), okStatusConverter) + .run(args); + } + } + + @Override + public String scriptLoad(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), (v)->v) + .run(args); + } + } + + @Override + public byte[] scriptLoad(final byte[] script) { + final CommandArguments args = CommandArguments.create("script", script); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(SafeEncoder.encode(script)), SafeEncoder::encode) + .run(args); + } + } + + @Override + public Status scriptKill() { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SCRIPT_KILL, + (cmd)->cmd.scriptKill((String) null), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SCRIPT_KILL, + (cmd)->cmd.scriptKill((String) null), okStatusConverter) + .run(); + }else{ + return new JedisClusterCommand<>(client, Command.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterServerOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterServerOperations.java new file mode 100644 index 000000000..f7a2ab342 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterServerOperations.java @@ -0,0 +1,516 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.Info; +import com.buession.redis.core.MemoryStats; +import com.buession.redis.core.Module; +import com.buession.redis.core.RedisMonitor; +import com.buession.redis.core.RedisServerTime; +import com.buession.redis.core.Role; +import com.buession.redis.core.SlowLog; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 集群模式服务端命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterServerOperations extends AbstractServerOperations { + + public JedisClusterServerOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public String bgRewriteAof() { + return notCommand(client, Command.BGREWRITEAOF); + } + + @Override + public String bgSave() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, Command.BGSAVE) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, Command.BGSAVE) + .run(); + }else{ + return new JedisClusterCommand(client, Command.BGSAVE) + .run(); + } + } + + @Override + public Status configSet(final String parameter, final String value) { + final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); + return configSet(parameter, value, args); + } + + @Override + public Status configSet(final byte[] parameter, final byte[] value) { + final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); + final String sParameter = SafeEncoder.encode(parameter); + final String sValue = SafeEncoder.encode(value); + + return configSet(sParameter, sValue, args); + } + + @Override + public Status configSet(final Map configs) { + final CommandArguments args = CommandArguments.create("configs", configs); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, Command.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, Command.CONFIG_SET) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.CONFIG_SET, (cmd)->{ + configs.forEach(cmd::configSet); + return Status.SUCCESS; + }, (v)->v) + .run(args); + } + } + + @Override + public Map configGet(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return notCommand(client, Command.CONFIG_GET, args); + } + + @Override + public Map configGet(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return notCommand(client, Command.CONFIG_GET, args); + } + + @Override + public Status configResetStat() { + return notCommand(client, Command.CONFIG_RESETSTAT); + } + + @Override + public Status configRewrite() { + return notCommand(client, Command.CONFIG_REWRITE); + } + + @Override + public Long dbSize() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, Command.DBSIZE) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, Command.DBSIZE) + .run(); + }else{ + return new JedisClusterCommand<>(client, Command.DBSIZE, (cmd)->cmd.dbSize(), (v)->v) + .run(); + } + } + + @Override + public Status failover() { + return notCommand(client, Command.FAILOVER); + } + + @Override + public Status failover(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + return notCommand(client, Command.FAILOVER, args); + } + + @Override + public Status failover(final String host, final int port, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("timeout", timeout); + return notCommand(client, Command.FAILOVER, args); + } + + @Override + public Status failover(final String host, final int port, final boolean isForce, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("isForce", isForce) + .put("timeout", timeout); + return notCommand(client, Command.FAILOVER, args); + } + + @Override + public Status failover(final int timeout) { + final CommandArguments args = CommandArguments.create("timeout", timeout); + return notCommand(client, Command.FAILOVER, args); + } + + @Override + public Status flushAll() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, Command.FLUSHALL) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, Command.FLUSHALL) + .run(); + }else{ + return new JedisClusterCommand<>(client, Command.FLUSHALL, (cmd)->cmd.flushAll(), okStatusConverter) + .run(); + } + } + + @Override + public Status flushAll(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, Command.FLUSHALL) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, Command.FLUSHALL) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.FLUSHALL, (cmd)->cmd.flushAll(), + okStatusConverter) + .run(args); + } + } + + @Override + public Status flushDb() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, Command.FLUSHDB) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, Command.FLUSHDB) + .run(); + }else{ + return new JedisClusterCommand<>(client, Command.FLUSHDB, (cmd)->cmd.flushDB(), okStatusConverter) + .run(); + } + } + + @Override + public Status flushDb(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, Command.FLUSHDB) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, Command.FLUSHDB) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.FLUSHDB, (cmd)->cmd.flushDB(), + okStatusConverter) + .run(args); + } + } + + @Override + public Info info() { + return notCommand(client, Command.INFO); + } + + @Override + public Info info(final Info.Section section) { + final CommandArguments args = CommandArguments.create("section", section); + return notCommand(client, Command.INFO, args); + } + + @Override + public Long lastSave() { + return notCommand(client, Command.LASTSAVE); + } + + @Override + public String memoryDoctor() { + return notCommand(client, Command.MEMORY_DOCTOR); + } + + @Override + public Status memoryPurge() { + return notCommand(client, Command.MEMORY_PURGE); + } + + @Override + public MemoryStats memoryStats() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, Command.MEMORY_STATS) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, Command.MEMORY_STATS) + .run(); + }else{ + return new JedisClusterCommand(client, Command.MEMORY_STATS) + .run(); + } + } + + @Override + public Long memoryUsage(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } + } + + @Override + public Long memoryUsage(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } + } + + @Override + public Long memoryUsage(final String key, final int samples) { + final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key, samples), + (v)->v) + .run(args); + } + } + + @Override + public Long memoryUsage(final byte[] key, final int samples) { + final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key, samples), + (v)->v) + .run(args); + } + } + + @Override + public List moduleList() { + return notCommand(client, Command.MODULE_LIST); + } + + @Override + public Status moduleLoad(final String path) { + final CommandArguments args = CommandArguments.create("path", path); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleLoad(final byte[] path) { + final CommandArguments args = CommandArguments.create("path", path); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleLoad(final String path, final String... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleLoad(final byte[] path, final byte[]... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleUnLoad(final String name) { + final CommandArguments args = CommandArguments.create("name", name); + return notCommand(client, Command.MODULE_UNLOAD, args); + } + + @Override + public Status moduleUnLoad(final byte[] name) { + final CommandArguments args = CommandArguments.create("name", name); + return notCommand(client, Command.MODULE_UNLOAD, args); + } + + @Override + public void monitor(final RedisMonitor redisMonitor) { + final CommandArguments args = CommandArguments.create("redisMonitor", redisMonitor); + notCommand(client, Command.MONITOR, args); + } + + @Override + public Object pSync(final String replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return notCommand(client, Command.PSYNC, args); + } + + @Override + public Object pSync(final byte[] replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return notCommand(client, Command.PSYNC, args); + } + + @Override + public void sync() { + if(isPipeline()){ + new JedisClusterPipelineCommand<>(client, Command.SYNC, (cmd)->{ + cmd.sync(); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new JedisClusterTransactionCommand<>(client, Command.SYNC) + .run(); + }else{ + new JedisClusterCommand<>(client, Command.SYNC) + .run(); + } + } + + @Override + public Status replicaOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + return notCommand(client, Command.REPLICAOF, args); + } + + @Override + public Status slaveOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + return notCommand(client, Command.SLAVEOF, args); + } + + @Override + public Role role() { + return notCommand(client, Command.ROLE); + } + + @Override + public Status save() { + return notCommand(client, Command.SAVE); + } + + @Override + public void shutdown() { + notCommand(client, Command.SHUTDOWN); + } + + @Override + public void shutdown(final boolean save) { + final CommandArguments args = CommandArguments.create("save", save); + notCommand(client, Command.SHUTDOWN, args); + } + + @Override + public List slowLogGet() { + return notCommand(client, Command.SLOWLOG_GET); + } + + @Override + public List slowLogGet(final int count) { + final CommandArguments args = CommandArguments.create("count", count); + return notCommand(client, Command.SLOWLOG_GET, args); + } + + @Override + public Long slowLogLen() { + return notCommand(client, Command.SLOWLOG_LEN); + } + + @Override + public Status slowLogReset() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, Command.SLOWLOG_RESET) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, Command.SLOWLOG_RESET) + .run(); + }else{ + return new JedisClusterCommand<>(client, Command.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + } + } + + @Override + public Status swapdb(final int db1, final int db2) { + final CommandArguments args = CommandArguments.create("db1", db1).put("db2", db2); + return notCommand(client, Command.SWAPDB, args); + } + + @Override + public RedisServerTime time() { + return notCommand(client, Command.TIME); + } + + private Status configSet(final String parameter, final String value, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, Command.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, Command.CONFIG_SET) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.CONFIG_SET, (cmd)->cmd.configSet(parameter, value), + okStatusConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterSetOperations.java new file mode 100644 index 000000000..5f065dee6 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterSetOperations.java @@ -0,0 +1,787 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; +import com.buession.redis.core.internal.jedis.JedisScanParams; +import redis.clients.jedis.params.ScanParams; + +import java.util.List; +import java.util.Set; + +/** + * Jedis 集群模式集合命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterSetOperations extends AbstractSetOperations { + + public JedisClusterSetOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public Long sAdd(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long sAdd(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long sCard(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } + } + + @Override + public Long sCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } + } + + @Override + public Set sDiff(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + } + } + + @Override + public Set sDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + } + } + + @Override + public Long sDiffStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long sDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Set sInter(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + } + } + + @Override + public Set sInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + } + } + + @Override + public Long sInterStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SINTERSTORE, (cmd)->cmd.sinterstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long sInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SINTERSTORE, (cmd)->cmd.sinterstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Boolean sIsMember(final String key, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + } + } + + @Override + public Boolean sIsMember(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + } + } + + @Override + public List smIsMember(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SMISMEMBER, (cmd)->cmd.smismember(key, members), + (v)->v) + .run(args); + } + } + + @Override + public List smIsMember(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SMISMEMBER, (cmd)->cmd.smismember(key, members), + (v)->v) + .run(args); + } + } + + @Override + public Set sMembers(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + } + } + + @Override + public Set sMembers(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + } + } + + @Override + public Status sMove(final String key, final String destKey, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status sMove(final byte[] key, final byte[] destKey, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + } + } + + @Override + public String sPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] sPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + } + } + + @Override + public Set sPop(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + } + } + + @Override + public Set sPop(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + } + } + + @Override + public String sRandMember(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] sRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + } + } + + @Override + public List sRandMember(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + } + } + + @Override + public List sRandMember(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + } + } + + @Override + public Long sRem(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long sRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } + } + + @Override + public ScanResult> sScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanParams scanParams = new JedisScanParams(count); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanParams scanParams = new JedisScanParams(count); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public Set sUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + } + } + + @Override + public Set sUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + } + } + + @Override + public Long sUnionStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SUNIONSTORE, (cmd)->cmd.sunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long sUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SUNIONSTORE, (cmd)->cmd.sunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + private ScanResult> sScan(final String key, final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterSortedSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterSortedSetOperations.java new file mode 100644 index 000000000..5ad17403a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterSortedSetOperations.java @@ -0,0 +1,2704 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.NumberUtils; +import com.buession.lang.KeyValue; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.Aggregate; +import com.buession.redis.core.GtLt; +import com.buession.redis.core.NxXx; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; +import com.buession.redis.core.ZRangeBy; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.jedis.response.KeyValueConverter; +import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; +import com.buession.redis.core.internal.convert.jedis.response.TupleConverter; +import com.buession.redis.core.internal.jedis.JedisScanParams; +import com.buession.redis.core.internal.jedis.JedisZAddParams; +import com.buession.redis.core.internal.jedis.JedisZParams; +import com.buession.redis.core.internal.jedis.JedisZRangeParams; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.params.ZAddParams; +import redis.clients.jedis.params.ZParams; +import redis.clients.jedis.params.ZRangeParams; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 集群模式模式模式有序集合命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterSortedSetOperations extends AbstractSortedSetOperations { + + public JedisClusterSortedSetOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public Tuple zPopMin(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + } + } + + @Override + public Tuple zPopMin(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + } + } + + @Override + public List zPopMin(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + } + } + + @Override + public List zPopMin(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + } + } + + @Override + public Tuple zPopMax(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + } + } + + @Override + public Tuple zPopMax(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + } + } + + @Override + public List zPopMax(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + } + } + + @Override + public List zPopMax(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMin(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMin(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public Long zAdd(final String key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long zAdd(final byte[] key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddParams zAddParams = new JedisZAddParams(nxXx); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddParams zAddParams = new JedisZAddParams(nxXx); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddParams zAddParams = new JedisZAddParams(gtLt); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddParams zAddParams = new JedisZAddParams(gtLt); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(gtLt, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(gtLt, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zCard(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } + } + + @Override + public Long zCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } + } + + @Override + public Long zCount(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZCOUNT, + (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public Long zCount(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZCOUNT, + (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zDiff(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + } + } + + @Override + public List zDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + } + } + + @Override + public List zDiffWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + } + } + + @Override + public List zDiffWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + } + } + + @Override + public Long zDiffStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Double zIncrBy(final String key, final double increment, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) + .put("member", member); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + } + } + + @Override + public Double zIncrBy(final byte[] key, final double increment, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) + .put("member", member); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + } + } + + @Override + public List zInter(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInter(keys, zParams, args); + } + + @Override + public List zInterWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public Long zInterStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZINTERSTORE, (cmd)->cmd.zinterstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZINTERSTORE, (cmd)->cmd.zinterstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zLexCount(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zLexCount(key, sMin, sMax, args); + } + + @Override + public Long zLexCount(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zLexCount(key, bMin, bMax, args); + } + + @Override + public List zMScore(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZMSCORE, (cmd)->cmd.zmscore(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZMSCORE, + (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + } + } + + @Override + public List zMScore(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZMSCORE, (cmd)->cmd.zmscore(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZMSCORE, + (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + } + } + + @Override + public String zRandMember(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] zRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + } + } + + @Override + public List zRandMember(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), + (v)->v) + .run(args); + } + } + + @Override + public List zRandMember(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), + (v)->v) + .run(args); + } + } + + @Override + public List zRandMemberWithScores(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + } + } + + @Override + public List zRandMemberWithScores(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + } + } + + @Override + public List zRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List zRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List zRangeWithScores(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } + } + + @Override + public List zRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } + } + + @Override + public List zRangeByLex(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zRangeByLex(key, sMin, sMax, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, args); + } + + @Override + public List zRangeByLex(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zRangeByLex(key, sMin, sMax, offset, count, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, offset, count, args); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zRangeByScore(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRank(final String key, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public Long zRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public Long zRem(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long zRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByRank(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByRank(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List zRevRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public List zRevRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public List zRevRangeWithScores(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } + } + + @Override + public List zRevRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final String key, final double min, final double max, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } + } + + @Override + public Long zRevRank(final String key, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public Long zRevRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public ScanResult> zScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanParams scanParams = new JedisScanParams(count); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanParams scanParams = new JedisScanParams(count); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public Double zScore(final String key, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } + } + + @Override + public Double zScore(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } + } + + @Override + public List zUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public Long zUnionStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZUNIONSTORE, (cmd)->cmd.zunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZUNIONSTORE, (cmd)->cmd.zunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionStore(destKey, keys, zParams, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionStore(destKey, keys, zParams, args); + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnionStore(destKey, keys, zParams, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnionStore(destKey, keys, zParams, args); + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionStore(destKey, keys, zParams, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionStore(destKey, keys, zParams, args); + } + + private Long zAdd(final String key, final Map members, final ZAddParams zAddParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), + (v)->v) + .run(args); + } + } + + private Long zAdd(final byte[] key, final Map members, final ZAddParams zAddParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), + (v)->v) + .run(args); + } + } + + private List zInter(final String[] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZINTER, (cmd)->cmd.zinter(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + } + } + + private List zInter(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZINTER, (cmd)->cmd.zinter(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + } + } + + private List zInterWithScores(final String[] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZINTER, (cmd)->cmd.zinterWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private List zInterWithScores(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZINTER, (cmd)->cmd.zinterWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private Long zInterStore(final String destKey, final String[] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zInterStore(final byte[] destKey, final byte[][] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zLexCount(final String key, final String min, final String max, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + } + } + + private Long zLexCount(final byte[] key, final byte[] min, final byte[] max, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + } + } + + private List zRangeByLex(final String key, final String min, final String max, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGEBYLEX, (cmd)->cmd.zrangeByLex(key, min, max), + (v)->v) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGEBYLEX, (cmd)->cmd.zrangeByLex(key, min, max), + (v)->v) + .run(args); + } + } + + private List zRangeByLex(final String key, final String min, final String max, final long offset, + final int count, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final int count, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + private Long zRangeStore(final String destKey, final String key, final ZRangeParams zRangeParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + } + } + + private Long zRangeStore(final byte[] destKey, final byte[] key, final ZRangeParams zRangeParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + } + } + + private ScanResult> zScan(final String key, final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + } + } + + private List zUnion(final String[] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZUNION, (cmd)->cmd.zunion(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + } + } + + private List zUnion(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZUNION, (cmd)->cmd.zunion(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + } + } + + private List zUnionWithScores(final String[] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZUNION, (cmd)->cmd.zunionWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private List zUnionWithScores(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZUNION, (cmd)->cmd.zunionWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private Long zUnionStore(final String destKey, final String[] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zUnionStore(final byte[] destKey, final byte[][] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterStreamOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterStreamOperations.java new file mode 100644 index 000000000..77b29476e --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterStreamOperations.java @@ -0,0 +1,1136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapEntryMapConverter; +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.Stream; +import com.buession.redis.core.StreamConsumer; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import com.buession.redis.core.StreamGroup; +import com.buession.redis.core.StreamPending; +import com.buession.redis.core.StreamPendingSummary; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.XAddArgument; +import com.buession.redis.core.command.args.XClaimArgument; +import com.buession.redis.core.command.args.XReadArgument; +import com.buession.redis.core.command.args.XReadGroupArgument; +import com.buession.redis.core.command.args.XTrimArgument; +import com.buession.redis.core.internal.convert.jedis.params.StreamEntryIdConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamConsumersInfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamEntryConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamEntryIDConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamFullInfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamGroupInfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamInfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamPendingEntryConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamPendingSummaryConverter; +import com.buession.redis.core.internal.jedis.JedisStreamEntryID; +import com.buession.redis.core.internal.jedis.JedisXAddParams; +import com.buession.redis.core.internal.jedis.JedisXAutoClaimParams; +import com.buession.redis.core.internal.jedis.JedisXClaimParams; +import com.buession.redis.core.internal.jedis.JedisXPendingParams; +import com.buession.redis.core.internal.jedis.JedisXReadGroupParams; +import com.buession.redis.core.internal.jedis.JedisXReadParams; +import com.buession.redis.core.internal.jedis.JedisXTrimParams; +import redis.clients.jedis.StreamEntryID; +import redis.clients.jedis.params.XAddParams; +import redis.clients.jedis.params.XAutoClaimParams; +import redis.clients.jedis.params.XClaimParams; +import redis.clients.jedis.params.XPendingParams; +import redis.clients.jedis.params.XReadGroupParams; +import redis.clients.jedis.params.XReadParams; +import redis.clients.jedis.params.XTrimParams; +import redis.clients.jedis.resps.StreamConsumersInfo; +import redis.clients.jedis.resps.StreamGroupInfo; +import redis.clients.jedis.resps.StreamPendingEntry; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 集群模式 Stream 命令操作抽象类 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterStreamOperations extends AbstractStreamOperations { + + public JedisClusterStreamOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public Long xAck(final String key, final String groupName, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("ids", (Object[]) ids); + final StreamEntryID[] streamEntryIDS = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + } + } + + @Override + public Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("ids", (Object[]) ids); + final byte[][] streamEntryIDS = StreamEntryIdConverter.binaryArrayConverter().convert(ids); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + } + } + + @Override + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XADD, + (cmd)->cmd.xadd(key, streamEntryID, hash), streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XADD, + (cmd)->cmd.xadd(key, streamEntryID, hash), streamEntryIDConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, streamEntryID, hash), + streamEntryIDConverter) + .run(args); + } + } + + @Override + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) + .put("xAddArgument", xAddArgument); + final XAddParams xAddParams = JedisXAddParams.from(xAddArgument).id(id); + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), streamEntryIDConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + streamEntryIDConverter) + .run(args); + } + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) + .put("xAddArgument", xAddArgument); + final XAddParams xAddParams = JedisXAddParams.from(xAddArgument).id(id); + final StreamEntryIDConverter.BinaryStreamEntryIdConverter binaryStreamEntryIdConverter = + new StreamEntryIDConverter.BinaryStreamEntryIdConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), binaryStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), binaryStreamEntryIdConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + binaryStreamEntryIdConverter) + .run(args); + } + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(count); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(count); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count"); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final XClaimParams xClaimParams = new JedisXClaimParams(); + + return xClaim(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); + } + + @Override + public List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final XClaimParams xClaimParams = JedisXClaimParams.from(xClaimArgument); + + return xClaim(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); + } + + @Override + public List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final XClaimParams xClaimParams = new JedisXClaimParams(); + + return xClaimJustId(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); + } + + @Override + public List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final XClaimParams xClaimParams = JedisXClaimParams.from(xClaimArgument); + + return xClaimJustId(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); + } + + @Override + public Long xDel(final String key, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("ids", (Object[]) ids); + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XDEL, (cmd)->cmd.xdel(key, streamEntryIDs), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XDEL, + (cmd)->cmd.xdel(key, streamEntryIDs), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XDEL, (cmd)->cmd.xdel(key, streamEntryIDs), (v)->v) + .run(args); + } + } + + @Override + public Status xGroupCreate(final String key, final String groupName, final StreamEntryId id, + final boolean makeStream) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("id", id); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + } + } + + @Override + public Long xGroupDelConsumer(final String key, final String groupName, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + } + } + + @Override + public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + } + } + + @Override + public Status xGroupDestroy(final String key, final String groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupDestroy(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupSetId(final String key, final String groupName, final StreamEntryId id) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName).put("id", id); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + } + } + + @Override + public List xInfoConsumers(final String key, final String groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + final ListConverter listStreamConsumersInfoConverter = + StreamConsumersInfoConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + } + } + + @Override + public List xInfoGroups(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final ListConverter listStreamGroupInfoConverter = + StreamGroupInfoConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XINFO_GROUPS, + (cmd)->cmd.xinfoGroups(key), listStreamGroupInfoConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + } + } + + @Override + public Stream xInfoStream(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final StreamInfoConverter streamInfoConverter = new StreamInfoConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStream(key), streamInfoConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamInfoConverter) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final String key, final boolean full) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key), streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key), streamFullInfoConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStreamFull(key), + streamFullInfoConverter) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final String key, final boolean full, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full).put("count", count); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + } + } + + @Override + public Long xLen(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } + } + + @Override + public Long xLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } + } + + @Override + public StreamPendingSummary xPending(final String key, final String groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + final StreamPendingSummaryConverter streamPendingSummaryConverter = new StreamPendingSummaryConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName), streamPendingSummaryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName), streamPendingSummaryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XPENDING, (cmd)->cmd.xpending(key, groupName), + streamPendingSummaryConverter) + .run(args); + } + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final StreamEntryId start, + final StreamEntryId end, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("start", start).put("end", end).put("count", count); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final XPendingParams xPendingParams = new JedisXPendingParams(consumerName); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("start", start).put("end", end).put("count", count); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count, minIdleTime); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime, consumerName); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final StreamEntryId start, + final StreamEntryId end, final int count, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count, consumerName); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count, + final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count, minIdleTime, consumerName); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, startID, endID), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, startID, endID), listStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, startID, endID), listStreamEntryConverter) + .run(args); + } + } + + @Override + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, startID, endID, (int) count), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, startID, endID, (int) count), listStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, startID, endID, (int) count), listStreamEntryConverter) + .run(args); + } + } + + @Override + public List>> xRead(final Map streams) { + final CommandArguments args = CommandArguments.create("streams", streams); + final XReadParams xReadParams = new JedisXReadParams(); + + return xRead(streams, xReadParams, args); + } + + @Override + public List>> xRead(final Map streams, + final XReadArgument xReadArgument) { + final CommandArguments args = CommandArguments.create("streams", streams).put("xReadArgument", xReadArgument); + final XReadParams xReadParams = JedisXReadParams.from(xReadArgument); + + return xRead(streams, xReadParams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadGroupParams xReadGroupParams = JedisXReadGroupParams.from(xReadGroupArgument); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadGroupParams xReadGroupParams = JedisXReadGroupParams.from(xReadGroupArgument); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); + } + + @Override + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), listStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), listStreamEntryConverter) + .run(args); + } + } + + @Override + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start) + .put("count", count); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + } + } + + @Override + public Long xTrim(final String key, final XTrimArgument xTrimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument); + + return xTrim(key, xTrimParams, args); + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument); + + return xTrim(key, xTrimParams, args); + } + + @Override + public Long xTrim(final String key, final XTrimArgument xTrimArgument, final long limit) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) + .put("limit", limit); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument).limit(limit); + + return xTrim(key, xTrimParams, args); + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) + .put("limit", limit); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument).limit(limit); + + return xTrim(key, xTrimParams, args); + } + + private Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, + final XAutoClaimParams xAutoClaimParams, + final CommandArguments args) { + final StreamEntryID startID = JedisStreamEntryID.from(start); + final StreamEntryConverter.MapEntryStreamEntryConverter mapEntryStreamEntryConverter = + new StreamEntryConverter.MapEntryStreamEntryConverter<>(new StreamEntryIDConverter()); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + mapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + mapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + mapEntryStreamEntryConverter) + .run(args); + } + } + + private Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, + final XAutoClaimParams xAutoClaimParams, + final CommandArguments args) { + final byte[] startID = start.getRaw(); + final StreamEntryConverter.MapEntryStreamEntryConverter mapEntryStreamEntryConverter = + new StreamEntryConverter.MapEntryStreamEntryConverter<>(new StreamEntryIDConverter()); + final Converter, Map>> converter = null; + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + converter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + converter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + converter) + .run(args); + } + } + + private Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, + final XAutoClaimParams xAutoClaimParams, + final CommandArguments args) { + final StreamEntryID startID = JedisStreamEntryID.from(start); + final MapEntryMapConverter, StreamEntryId, List> mapEntryStreamEntryIdConverter = StreamEntryIDConverter.mapEntryMapConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams) + , mapEntryStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams) + , mapEntryStreamEntryIdConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams) + , mapEntryStreamEntryIdConverter) + .run(args); + } + } + + private List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, final XClaimParams xClaimParams, + final CommandArguments args) { + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + } + } + + private List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimParams xClaimParams, final CommandArguments args) { + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter listStreamEntryIDConverter = StreamEntryIDConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + } + } + + private List xPending(final String key, final String groupName, + final XPendingParams xPendingParams, final CommandArguments args) { + final ListConverter listStreamPendingEntryConverter = + StreamPendingEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + } + } + + private List>> xRead(final Map streams, + final XReadParams xReadParams, final CommandArguments args) { + final Map stringStreamEntryIDMap = StreamEntryIdConverter.mapConverter().convert( + streams); + final StreamEntryConverter.ListMapEntryStreamEntryConverter listMapEntryStreamEntryConverter = + new StreamEntryConverter.ListMapEntryStreamEntryConverter<>((k)->k); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadGroupParams xReadGroupParams, + final CommandArguments args) { + final Map stringStreamEntryIDMap = StreamEntryIdConverter.mapConverter().convert( + streams); + final StreamEntryConverter.ListMapEntryStreamEntryConverter listMapEntryStreamEntryConverter = + new StreamEntryConverter.ListMapEntryStreamEntryConverter<>((k)->k); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + } + } + + private Long xTrim(final String key, final XTrimParams xTrimParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XTRIM, + (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + } + } + + private Long xTrim(final byte[] key, final XTrimParams xTrimParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.XTRIM, + (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterStringOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterStringOperations.java new file mode 100644 index 000000000..84d28cfd2 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterStringOperations.java @@ -0,0 +1,822 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.GetExArgument; +import com.buession.redis.core.command.args.SetArgument; +import com.buession.redis.core.internal.jedis.JedisGetExParams; +import com.buession.redis.core.internal.jedis.JedisSetParams; +import redis.clients.jedis.params.GetExParams; +import redis.clients.jedis.params.SetParams; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Jedis 集群模式字符串命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterStringOperations extends AbstractStringOperations { + + public JedisClusterStringOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public Long append(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long append(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long incr(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } + } + + @Override + public Long incr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } + } + + @Override + public Long incrBy(final String key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long incrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + } + } + + @Override + public Double incrByFloat(final String key, final double value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), + (v)->v) + .run(args); + } + } + + @Override + public Double incrByFloat(final byte[] key, final double value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), + (v)->v) + .run(args); + } + } + + @Override + public Long decr(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } + } + + @Override + public Long decr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } + } + + @Override + public Long decrBy(final String key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long decrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + } + } + + @Override + public String get(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] get(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + } + } + + @Override + public String getEx(final String key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + final GetExParams getExParams = JedisGetExParams.from(getExArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GETEX, (cmd)->cmd.getEx(key, getExParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GETEX, + (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + } + } + + @Override + public byte[] getEx(final byte[] key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + final GetExParams getExParams = JedisGetExParams.from(getExArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GETEX, (cmd)->cmd.getEx(key, getExParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GETEX, + (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + } + } + + @Override + public String getSet(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + } + } + + @Override + public byte[] getSet(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + } + } + + @Override + public String getDel(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] getDel(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + } + } + + @Override + public List mGet(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + } + } + + @Override + public List mGet(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + } + } + + @Override + public Status mSet(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final List temp = new ArrayList<>(values.size() * 2); + + values.forEach((key, value)->{ + temp.add(key); + temp.add(value); + }); + + final String[] keysValues = temp.toArray(new String[0]); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + } + } + + @Override + public Status mSetNx(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final List temp = new ArrayList<>(values.size() * 2); + + values.forEach((key, value)->{ + temp.add(key); + temp.add(value); + }); + + final String[] keysValues = temp.toArray(new String[0]); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pSetEx(final String key, final String value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status pSetEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final String key, final String value, final SetArgument setArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final SetParams setParams = JedisSetParams.from(setArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SET, + (cmd)->cmd.set(key, value, setParams), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value, final SetArgument setArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final SetParams setParams = JedisSetParams.from(setArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SET, + (cmd)->cmd.set(key, value, setParams), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setEx(final String key, final String value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setNx(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status setNx(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + } + } + + @Override + public Long setRange(final String key, final long offset, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SETRANGE, (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + } + } + + @Override + public Long setRange(final byte[] key, final long offset, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SETRANGE, (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + } + } + + @Override + public String getRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public byte[] getRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public Long strlen(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } + } + + @Override + public Long strlen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } + } + + @Override + public String substr(final String key, final int start, final int end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SUBSTR, (cmd)->cmd.substr(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SUBSTR, + (cmd)->cmd.substr(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SUBSTR, (cmd)->cmd.substr(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public byte[] substr(final byte[] key, final int start, final int end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.SUBSTR, (cmd)->cmd.substr(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.SUBSTR, + (cmd)->cmd.substr(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, Command.SUBSTR, (cmd)->cmd.substr(key, start, end), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterTransactionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterTransactionOperations.java new file mode 100644 index 000000000..75d55e0ec --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisClusterTransactionOperations.java @@ -0,0 +1,235 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import redis.clients.jedis.Builder; +import redis.clients.jedis.Response; + +import java.util.List; + +/** + * Jedis 集群模式事务命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisClusterTransactionOperations extends AbstractTransactionOperations { + + public JedisClusterTransactionOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public Status multi() { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.MULTI, (cmd)->{ + RedisConnection connection = client.getConnection(); + + return new Response<>(new Builder() { + + @Override + public Status build(Object data) { + try{ + connection.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; + } + } + + }); + }, (v)->v) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.MULTI, (cmd)->{ + RedisConnection connection = client.getConnection(); + + return new Response<>(new Builder() { + + @Override + public Status build(Object data) { + try{ + connection.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; + } + } + + }); + }, (v)->v) + .run(); + }else{ + return new JedisClusterCommand<>(client, Command.MULTI, (cmd)->{ + RedisConnection connection = client.getConnection(); + try{ + connection.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; + } + }, (v)->v) + .run(); + } + } + + @Override + public List exec() { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, Command.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); + + return new Response<>(new Builder>() { + + @Override + public List build(Object data) { + return connection.exec(); + } + + }); + }, (v)->v).run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); + + return new Response<>(new Builder>() { + + @Override + public List build(Object data) { + return connection.exec(); + } + + }); + }, (v)->v).run(); + }else{ + return new JedisClusterCommand<>(client, Command.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); + return connection.exec(); + }, (v)->v).run(); + } + } + + @Override + public void discard() { + if(isPipeline()){ + new JedisClusterPipelineCommand<>(client, Command.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new JedisClusterTransactionCommand<>(client, Command.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + }else{ + new JedisClusterCommand<>(client, Command.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + } + } + + @Override + public Status watch(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, Command.WATCH) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.WATCH, + (cmd)->new Response<>(new Builder() { + + @Override + public String build(Object data) { + return cmd.watch(keys); + } + + }), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand(client, Command.WATCH) + .run(args); + } + } + + @Override + public Status watch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, Command.WATCH) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.WATCH, + (cmd)->new Response<>(new Builder() { + + @Override + public String build(Object data) { + return cmd.watch(keys); + } + + }), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand(client, Command.WATCH) + .run(args); + } + } + + @Override + public Status unwatch() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, Command.UNWATCH) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, Command.UNWATCH, + (cmd)->new Response<>(new Builder() { + + @Override + public String build(Object data) { + return cmd.unwatch(); + } + + }), okStatusConverter) + .run(); + }else{ + return new JedisClusterCommand(client, Command.UNWATCH) + .run(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisConnectionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisConnectionOperations.java new file mode 100644 index 000000000..f65aa2d89 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisConnectionOperations.java @@ -0,0 +1,553 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.Client; +import com.buession.redis.core.ClientAttributeOption; +import com.buession.redis.core.ClientPauseMode; +import com.buession.redis.core.ClientReply; +import com.buession.redis.core.ClientTrackingInfo; +import com.buession.redis.core.ClientType; +import com.buession.redis.core.ClientUnblockType; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.RedisServer; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.ClientKillArgument; +import com.buession.redis.core.command.args.ClientTracking; +import com.buession.redis.core.command.args.HelloArgument; +import com.buession.redis.core.internal.convert.jedis.params.ClientAttributeOptionConverter; +import com.buession.redis.core.internal.convert.jedis.params.ClientPauseModeConverter; +import com.buession.redis.core.internal.convert.jedis.params.ClientTypeConverter; +import com.buession.redis.core.internal.convert.jedis.params.ClientUnblockTypeConverter; +import com.buession.redis.core.internal.convert.response.ClientConverter; +import com.buession.redis.core.internal.convert.response.PingResultConverter; +import redis.clients.jedis.args.UnblockType; +import redis.clients.jedis.params.ClientKillParams; + +import java.util.List; + +/** + * Jedis 单机模式连接命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisConnectionOperations extends AbstractConnectionOperations { + + public JedisConnectionOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public Status auth(final String user, final String password) { + final CommandArguments args = CommandArguments.create(user).add(password); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.AUTH) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.AUTH) + .run(args); + }else{ + return new JedisCommand<>(client, Command.AUTH, (cmd)->cmd.auth(user, password), okStatusConverter) + .run(args); + } + } + + @Override + public Status auth(final String password) { + final CommandArguments args = CommandArguments.create(password); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.AUTH) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.AUTH) + .run(args); + }else{ + return new JedisCommand<>(client, Command.AUTH, (cmd)->cmd.auth(password), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientCaching() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_CACHING); + } + + @Override + public Status clientCaching(final boolean isYes) { + final CommandArguments args = CommandArguments.create(isYes ? Keyword.Common.YES : Keyword.Common.NO); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_CACHING, args); + } + + @Override + public String clientGetName() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_GETNAME) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_GETNAME) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_GETNAME, (cmd)->cmd.clientGetname(), + (v)->v) + .run(); + } + } + + @Override + public Integer clientGetRedir() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_GETREDIR); + } + + @Override + public Long clientId() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_ID) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_ID) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_ID, (cmd)->cmd.clientId(), (v)->v) + .run(); + } + } + + @Override + public Client clientInfo() { + final ClientConverter clientConverter = new ClientConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_INFO) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_INFO) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_INFO, (cmd)->cmd.clientInfo(), + clientConverter) + .run(); + } + } + + @Override + public Status clientKill(final String host, final int port) { + final CommandArguments args = CommandArguments.create(host).add(port); + final String addr = host + ':' + port; + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_KILL) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_KILL) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, (cmd)->cmd.clientKill(addr), + okStatusConverter) + .run(args); + } + } + + @Override + public Long clientKill(final ClientKillArgument... clientKillArguments) { + final CommandArguments args = CommandArguments.create(clientKillArguments); + final ClientKillParams clientKillParams = createClientKillParamsFromClientKillArgument(clientKillArguments); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_KILL) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_KILL) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(clientKillParams), (v)->v) + .run(args); + } + } + + @Override + public List clientList() { + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.CLIENT, SubCommand.CLIENT_LIST) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.CLIENT, + SubCommand.CLIENT_LIST) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + } + } + + @Override + public List clientList(final ClientType clientType) { + final CommandArguments args = CommandArguments.create(clientType); + final redis.clients.jedis.args.ClientType jClientType = (new ClientTypeConverter()).convert(clientType); + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.CLIENT, SubCommand.CLIENT_LIST) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.CLIENT, + SubCommand.CLIENT_LIST) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(jClientType), clientListConverter) + .run(args); + } + } + + @Override + public List clientList(final long... clientIds) { + final CommandArguments args = CommandArguments.create(clientIds); + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.CLIENT, SubCommand.CLIENT_LIST) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.CLIENT, + SubCommand.CLIENT_LIST) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, (cmd)->cmd.clientList(clientIds), + clientListConverter) + .run(args); + } + } + + @Override + public Status clientNoEvict(final boolean on) { + final CommandArguments args = CommandArguments.create(on ? Keyword.Common.ON : Keyword.Common.OFF); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_NO_EVICT) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_NO_EVICT) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_NO_EVICT, + (cmd)->(on ? cmd.clientNoEvictOn() : cmd.clientNoEvictOff()), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientNoTouch(final boolean on) { + final CommandArguments args = CommandArguments.create(on ? Keyword.Common.ON : Keyword.Common.OFF); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_NO_TOUCH) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_NO_TOUCH) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_NO_TOUCH, + (cmd)->(on ? cmd.clientNoTouchOn() : cmd.clientNoTouchOff()), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientPause(final int timeout) { + final CommandArguments args = CommandArguments.create(timeout); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_PAUSE) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_PAUSE) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, (cmd)->cmd.clientPause(timeout), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clientPause(final int timeout, final ClientPauseMode pauseMode) { + final CommandArguments args = CommandArguments.create(timeout).add(pauseMode); + final redis.clients.jedis.args.ClientPauseMode jClientPauseMode = (new ClientPauseModeConverter()).convert( + pauseMode); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_PAUSE) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_PAUSE) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout, jClientPauseMode), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientReply(final ClientReply option) { + final CommandArguments args = CommandArguments.create(option); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_REPLY, args); + } + + @Override + public Status clientSetInfo(final ClientAttributeOption clientAttributeOption, final String value) { + final CommandArguments args = CommandArguments.create(clientAttributeOption).add(value); + final redis.clients.jedis.args.ClientAttributeOption jClientAttributeOption = + (new ClientAttributeOptionConverter()).convert(clientAttributeOption); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_SETINFO) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_SETINFO) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETINFO, + (cmd)->cmd.clientSetInfo(jClientAttributeOption, value), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientSetInfo(final ClientAttributeOption clientAttributeOption, final byte[] value) { + final CommandArguments args = CommandArguments.create(clientAttributeOption).add(value); + final redis.clients.jedis.args.ClientAttributeOption jClientAttributeOption = + (new ClientAttributeOptionConverter()).convert(clientAttributeOption); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_SETINFO) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_SETINFO) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETINFO, + (cmd)->cmd.clientSetInfo(jClientAttributeOption, value), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientSetName(final String name) { + final CommandArguments args = CommandArguments.create(name); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_SETNAME) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_SETNAME) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETNAME, (cmd)->cmd.clientSetname(name), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clientSetName(final byte[] name) { + final CommandArguments args = CommandArguments.create(name); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_SETNAME) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_SETNAME) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETNAME, (cmd)->cmd.clientSetname(name), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clientTracking(final ClientTracking clientTracking) { + final CommandArguments args = CommandArguments.create(clientTracking); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_TRACKING, args); + } + + @Override + public ClientTrackingInfo clientTrackingInfo() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_TRACKINGINFO); + } + + @Override + public Status clientUnblock(final int clientId) { + final CommandArguments args = CommandArguments.create(clientId); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK, + (cmd)->cmd.clientUnblock(clientId), oneStatusConverter) + .run(args); + } + } + + @Override + public Status clientUnblock(final int clientId, final ClientUnblockType type) { + final CommandArguments args = CommandArguments.create(clientId).add(type); + final UnblockType unblockType = (new ClientUnblockTypeConverter()).convert(type); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + } + } + + @Override + public Status clientUnPause() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_UNPAUSE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_UNPAUSE) + .run(); + }else{ + return new JedisCommand<>(client, Command.CLIENT, SubCommand.CLIENT_UNPAUSE, (cmd)->cmd.clientUnpause(), + okStatusConverter) + .run(); + } + } + + @Override + public String echo(final String str) { + final CommandArguments args = CommandArguments.create(str); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ECHO) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ECHO) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ECHO, (cmd)->cmd.echo(str), (v)->v) + .run(args); + } + } + + @Override + public byte[] echo(final byte[] str) { + final CommandArguments args = CommandArguments.create(str); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ECHO) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ECHO) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ECHO, (cmd)->cmd.echo(str), (v)->v) + .run(args); + } + } + + @Override + public RedisServer hello(final HelloArgument helloArgument) { + final CommandArguments args = CommandArguments.create(helloArgument); + return notCommand(client, Command.HELLO, args); + } + + @Override + public Status ping() { + final PingResultConverter pingResultConverter = new PingResultConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.PING) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.PING) + .run(); + }else{ + return new JedisCommand<>(client, Command.PING, (cmd)->cmd.ping(), pingResultConverter) + .run(); + } + } + + @Override + public Status quit() { + return notCommand(client, Command.QUIT); + } + + @Override + public Status reset() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.RESET) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.RESET) + .run(); + }else{ + return new JedisCommand<>(client, Command.RESET, (cmd)->cmd.reset(), okStatusConverter) + .run(); + } + } + + @Override + public Status select(final int db) { + final CommandArguments args = CommandArguments.create(db); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SELECT, (cmd)->cmd.select(db), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.SELECT) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SELECT, (cmd)->cmd.select(db), okStatusConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisGeoOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisGeoOperations.java new file mode 100644 index 000000000..7782aa55a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisGeoOperations.java @@ -0,0 +1,872 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.builder.MapBuilder; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Geo; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.GeoAddArgument; +import com.buession.redis.core.command.args.GeoRadiusArgument; +import com.buession.redis.core.command.args.GeoSearchArgument; +import com.buession.redis.core.command.args.GeoSearchStoreArgument; +import com.buession.redis.core.internal.convert.jedis.params.GeoUnitConverter; +import com.buession.redis.core.internal.convert.jedis.response.GeoCoordinateConverter; +import com.buession.redis.core.internal.convert.jedis.response.GeoRadiusResponseConverter; +import com.buession.redis.core.internal.jedis.JedisGeoAddParam; +import com.buession.redis.core.internal.jedis.JedisGeoRadiusParam; +import com.buession.redis.core.internal.jedis.JedisGeoSearchParam; +import com.buession.redis.core.internal.jedis.JedisGeoSearchStoreParam; +import redis.clients.jedis.GeoCoordinate; +import redis.clients.jedis.params.GeoAddParams; +import redis.clients.jedis.params.GeoRadiusParam; +import redis.clients.jedis.params.GeoSearchParam; +import redis.clients.jedis.resps.GeoRadiusResponse; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 单机模式地理位置命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisGeoOperations extends AbstractGeoOperations { + + public JedisGeoOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public Long geoAdd(final String key, final String member, final double longitude, final double latitude) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(member); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, longitude, latitude, member), + (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(member); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, longitude, latitude, member), + (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + final Map geoCoordinates = createGeoCoordinateMapFromGeoMap(memberCoordinates); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + final Map geoCoordinates = createGeoCoordinateMapFromGeoMap(memberCoordinates); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final String key, final String member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(longitude).add(latitude) + .add(member); + final Map memberCoordinates = + MapBuilder.create(1).put(member, new Geo(longitude, latitude)).build(); + + return geoAdd(key, memberCoordinates, geoAddArgument, args); + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(longitude).add(latitude) + .add(member); + final Map memberCoordinates = + MapBuilder.create(1).put(member, new Geo(longitude, latitude)).build(); + + return geoAdd(key, memberCoordinates, geoAddArgument, args); + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + return geoAdd(key, memberCoordinates, geoAddArgument, args); + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(memberCoordinates); + return geoAdd(key, memberCoordinates, geoAddArgument, args); + } + + @Override + public Double geoDist(final String key, final String member1, final String member2) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + } + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + } + } + + @Override + public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2, geoUnit), + (v)->v) + .run(args); + } + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2, geoUnit), + (v)->v) + .run(args); + } + } + + @Override + public List geoHash(final String key, final String... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + } + } + + @Override + public List geoHash(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + } + } + + @Override + public List geoPos(final String key, final String... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } + } + + @Override + public List geoPos(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } + } + + @Override + public List geoRadius(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadius(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = + CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit).add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = + CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit).add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final String key, final String member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoSearch(final String key, final GeoSearchArgument geoSearchArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoSearchArgument); + final GeoSearchParam geoSearchParam = JedisGeoSearchParam.from(geoSearchArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEOSEARCH, (cmd)->cmd.geosearch(key, geoSearchParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEOSEARCH, (cmd)->cmd.geosearch(key, geoSearchParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEOSEARCH, (cmd)->cmd.geosearch(key, geoSearchParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoSearch(final byte[] key, final GeoSearchArgument geoSearchArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoSearchArgument); + final GeoSearchParam geoSearchParam = JedisGeoSearchParam.from(geoSearchArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEOSEARCH, (cmd)->cmd.geosearch(key, geoSearchParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEOSEARCH, (cmd)->cmd.geosearch(key, geoSearchParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEOSEARCH, (cmd)->cmd.geosearch(key, geoSearchParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public Long geoSearchStore(final String destKey, final String key, + final GeoSearchStoreArgument geoSearchStoreArgument) { + final CommandArguments args = CommandArguments.create(destKey).add(key).add(geoSearchStoreArgument); + final GeoSearchParam geoSearchParam = JedisGeoSearchStoreParam.from(geoSearchStoreArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + } + } + + @Override + public Long geoSearchStore(final byte[] destKey, final byte[] key, + final GeoSearchStoreArgument geoSearchStoreArgument) { + final CommandArguments args = CommandArguments.create(destKey).add(key).add(geoSearchStoreArgument); + final GeoSearchParam geoSearchParam = JedisGeoSearchStoreParam.from(geoSearchStoreArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + } + } + + private Long geoAdd(final String key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument, final CommandArguments args) { + final Map geoCoordinates = createGeoCoordinateMapFromGeoMap(memberCoordinates); + final GeoAddParams geoAddParams = JedisGeoAddParam.from(geoAddArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), + (v)->v) + .run(args); + } + } + + private Long geoAdd(final byte[] key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument, final CommandArguments args) { + final Map geoCoordinates = createGeoCoordinateMapFromGeoMap(memberCoordinates); + final GeoAddParams geoAddParams = JedisGeoAddParam.from(geoAddArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), + (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisHashOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisHashOperations.java new file mode 100644 index 000000000..2c2aea65c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisHashOperations.java @@ -0,0 +1,884 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapEntryKeyValueConverter; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.HScanArgument; +import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; +import com.buession.redis.core.internal.jedis.JedisScanParams; +import redis.clients.jedis.params.ScanParams; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Jedis 单机模式模式哈希表命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisHashOperations extends AbstractHashOperations { + + public JedisHashOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public Long hDel(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } + } + + @Override + public Long hDel(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } + } + + @Override + public Boolean hExists(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } + } + + @Override + public Boolean hExists(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } + } + + @Override + public List hExpire(final String key, final int lifetime, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields.length) + .add(fields); + return notCommand(client, Command.HEXPIRE, args); + } + + @Override + public List hExpire(final byte[] key, final int lifetime, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields.length) + .add(fields); + return notCommand(client, Command.HEXPIRE, args); + } + + @Override + public List hExpire(final String key, final int lifetime, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIRE, args); + } + + @Override + public List hExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIRE, args); + } + + @Override + public List hExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireAt(final String key, final long unixTimestamp, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireTime(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIRETIME, args); + } + + @Override + public List hExpireTime(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIRETIME, args); + } + + @Override + public String hGet(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + } + } + + @Override + public byte[] hGet(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + } + } + + @Override + public Map hGetAll(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + } + } + + @Override + public Map hGetAll(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + } + } + + @Override + public Long hIncrBy(final String key, final String field, final long value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Long hIncrBy(final byte[] key, final byte[] field, final long value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Double hIncrByFloat(final String key, final String field, final double value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HINCRBYFLOAT, (cmd)->cmd.hincrByFloat(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HINCRBYFLOAT, (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Double hIncrByFloat(final byte[] key, final byte[] field, final double value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HINCRBYFLOAT, (cmd)->cmd.hincrByFloat(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HINCRBYFLOAT, (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Set hKeys(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + } + } + + @Override + public Set hKeys(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + } + } + + @Override + public Long hLen(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } + } + + @Override + public Long hLen(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } + } + + @Override + public List hMGet(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + } + } + + @Override + public List hMGet(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + } + } + + @Override + public Status hMSet(final String key, final Map data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), okStatusConverter) + .run(args); + } + } + + @Override + public Status hMSet(final byte[] key, final Map data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), okStatusConverter) + .run(args); + } + } + + @Override + public List hPersist(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPERSIST, args); + } + + @Override + public List hPersist(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPERSIST, args); + } + + @Override + public List hpExpire(final String key, final int lifetime, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpire(final byte[] key, final int lifetime, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpire(final String key, final int lifetime, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = + CommandArguments.create(key).add(lifetime).add(expireOption).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = + CommandArguments.create(key).add(lifetime).add(expireOption).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpireAt(final String key, final long unixTimestamp, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireTime(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRETIME, args); + } + + @Override + public List hpExpireTime(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRETIME, args); + } + + @Override + public List hpTtl(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public List hpTtl(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public String hRandField(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] hRandField(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + } + } + + @Override + public List hRandField(final String key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + } + } + + @Override + public List hRandField(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + } + } + + @Override + public List> hRandFieldWithValues(final String key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count).add(Keyword.Hash.WITHVALUES); + final ListConverter, KeyValue> converter = + new ListConverter<>(new MapEntryKeyValueConverter<>((k)->k, (v)->v)); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfieldWithValues(key, count), + converter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfieldWithValues(key, count), + converter) + .run(args); + } + } + + @Override + public List> hRandFieldWithValues(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count).add(Keyword.Hash.WITHVALUES); + final ListConverter, KeyValue> converter = + new ListConverter<>(new MapEntryKeyValueConverter<>((k)->k, (v)->v)); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfieldWithValues(key, count), + converter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfieldWithValues(key, count), + converter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create(key).add(cursor); + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), mapScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create(key).add(cursor); + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), mapScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final String key, final String cursor, + final HScanArgument scanArgument) { + final CommandArguments args = CommandArguments.create(key).add(cursor).add(scanArgument); + final ScanParams scanParams = JedisScanParams.from(scanArgument); + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, + final HScanArgument scanArgument) { + final CommandArguments args = CommandArguments.create(key).add(cursor).add(scanArgument); + final ScanParams scanParams = JedisScanParams.from(scanArgument); + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + } + } + + @Override + public Long hSet(final String key, final KeyValue... data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Long hSet(final byte[] key, final KeyValue... data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Status hSetNx(final String key, final String field, final String value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), oneStatusConverter) + .run(args); + } + } + + @Override + public Status hSetNx(final byte[] key, final byte[] field, final byte[] value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), oneStatusConverter) + .run(args); + } + } + + @Override + public Long hStrLen(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } + } + + @Override + public Long hStrLen(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } + } + + @Override + public List hTtl(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public List hTtl(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public List hVals(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + } + } + + @Override + public List hVals(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisHyperLogLogOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisHyperLogLogOperations.java new file mode 100644 index 000000000..b2f75d098 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisHyperLogLogOperations.java @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; + +/** + * Jedis 单机模式 HyperLogLog 命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisHyperLogLogOperations extends AbstractHyperLogLogOperations { + + public JedisHyperLogLogOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public Status pfAdd(final String key, final String... elements) { + final CommandArguments args = CommandArguments.create(key).add(elements); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), oneStatusConverter) + .run(args); + } + } + + @Override + public Status pfAdd(final byte[] key, final byte[]... elements) { + final CommandArguments args = CommandArguments.create(key).add(elements); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), oneStatusConverter) + .run(args); + } + } + + @Override + public Long pfCount(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } + } + + @Override + public Long pfCount(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } + } + + @Override + public Status pfMerge(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create(destKey).add(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), okStatusConverter) + .run(args); + } + } + + @Override + public Status pfMerge(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(destKey).add(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), okStatusConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisKeyOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisKeyOperations.java new file mode 100644 index 000000000..c745256e7 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisKeyOperations.java @@ -0,0 +1,1685 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.ObjectEncoding; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Type; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.MigrateArgument; +import com.buession.redis.core.command.args.RestoreArgument; +import com.buession.redis.core.command.args.SortArgument; +import com.buession.redis.core.internal.convert.jedis.params.ExpireOptionConverter; +import com.buession.redis.core.internal.convert.response.BinaryObjectEncodingConverter; +import com.buession.redis.core.internal.convert.response.ObjectEncodingConverter; +import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; +import com.buession.redis.core.internal.convert.response.TypeConverter; +import com.buession.redis.core.internal.jedis.JedisMigrateParams; +import com.buession.redis.core.internal.jedis.JedisRestoreParams; +import com.buession.redis.core.internal.jedis.JedisScanParams; +import com.buession.redis.core.internal.jedis.JedisSortingParams; +import com.buession.redis.utils.SafeEncoder; +import redis.clients.jedis.args.ExpiryOption; +import redis.clients.jedis.params.MigrateParams; +import redis.clients.jedis.params.RestoreParams; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.params.SortingParams; + +import java.util.List; +import java.util.Set; + +/** + * Jedis 单机模式 Key 命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisKeyOperations extends AbstractKeyOperations { + + public JedisKeyOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public Status copy(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + return copy(key, destKey, false, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + return copy(key, destKey, false, args); + } + + @Override + public Status copy(final String key, final String destKey, final int db) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + return copy(key, destKey, db, false, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + return copy(key, destKey, db, false, args); + } + + @Override + public Status copy(final String key, final String destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, replace, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, replace, args); + } + + @Override + public Status copy(final String key, final String destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, db, replace, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, db, replace, args); + } + + @Override + public Long del(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } + } + + @Override + public Long del(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } + } + + @Override + public String dump(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), SafeEncoder::encode) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), SafeEncoder::encode) + .run(args); + }else{ + return new JedisCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), SafeEncoder::encode) + .run(args); + } + } + + @Override + public byte[] dump(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + } + } + + @Override + public Boolean exists(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + } + } + + @Override + public Boolean exists(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + } + } + + @Override + public Long exists(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } + } + + @Override + public Long exists(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } + } + + @Override + public Status expire(final String key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), oneStatusConverter) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), oneStatusConverter) + .run(args); + } + } + + @Override + public Status expire(final String key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final String key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final String key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), + oneStatusConverter) + .run(args); + } + } + + @Override + public Long expireTime(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + } + } + + @Override + public Long expireTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + } + } + + @Override + public Set keys(final String pattern) { + final CommandArguments args = CommandArguments.create(pattern); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + } + } + + @Override + public Set keys(final byte[] pattern) { + final CommandArguments args = CommandArguments.create(pattern); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + } + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final String... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(keys); + final MigrateParams migrateParams = new JedisMigrateParams(); + + return migrate(host, port, db, timeout, keys, migrateParams, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(keys); + final MigrateParams migrateParams = new JedisMigrateParams(); + + return migrate(host, port, db, timeout, keys, migrateParams, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgument migrateArgument, final String... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(migrateArgument) + .add(keys); + final MigrateParams migrateParams = JedisMigrateParams.from(migrateArgument); + + return migrate(host, port, db, timeout, keys, migrateParams, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgument migrateArgument, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(migrateArgument) + .add(keys); + final MigrateParams migrateParams = JedisMigrateParams.from(migrateArgument); + + return migrate(host, port, db, timeout, keys, migrateParams, args); + } + + @Override + public Status move(final String key, final int db) { + final CommandArguments args = CommandArguments.create(key).add(db); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.MOVE, (cmd)->cmd.move(key, db), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.MOVE) + .run(args); + }else{ + return new JedisCommand<>(client, Command.MOVE, (cmd)->cmd.move(key, db), oneStatusConverter) + .run(args); + } + } + + @Override + public Status move(final byte[] key, final int db) { + final CommandArguments args = CommandArguments.create(key).add(db); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.MOVE, (cmd)->cmd.move(key, db), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.MOVE) + .run(args); + }else{ + return new JedisCommand<>(client, Command.MOVE, (cmd)->cmd.move(key, db), oneStatusConverter) + .run(args); + } + } + + @Override + public ObjectEncoding objectEncoding(final String key) { + final CommandArguments args = CommandArguments.create(key); + final ObjectEncodingConverter objectEncodingConverter = new ObjectEncodingConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + } + } + + @Override + public ObjectEncoding objectEncoding(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final BinaryObjectEncodingConverter binaryObjectEncodingConverter = new BinaryObjectEncodingConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), binaryObjectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), binaryObjectEncodingConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), binaryObjectEncodingConverter) + .run(args); + } + } + + @Override + public Long objectFreq(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + } + } + + @Override + public Long objectFreq(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + } + } + + @Override + public Long objectIdleTime(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectIdleTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectRefcount(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectRefcount(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + } + } + + @Override + public Status persist(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), oneStatusConverter) + .run(args); + } + } + + @Override + public Status persist(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final String key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final String key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final String key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PEXPIREAT, (cmd)->cmd.pexpireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PEXPIREAT, (cmd)->cmd.pexpireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PEXPIREAT, (cmd)->cmd.pexpireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PEXPIREAT, (cmd)->cmd.pexpireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PEXPIREAT, (cmd)->cmd.pexpireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PEXPIREAT, (cmd)->cmd.pexpireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PEXPIREAT, (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PEXPIREAT, (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), + oneStatusConverter) + .run(args); + } + } + + @Override + public Long pExpireTime(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + } + } + + @Override + public Long pExpireTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + } + } + + @Override + public Long pTtl(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } + } + + @Override + public Long pTtl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } + } + + @Override + public String randomKey() { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RANDOMKEY, (cmd)->cmd.randomKey(), (v)->v) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RANDOMKEY, (cmd)->cmd.randomKey(), (v)->v) + .run(); + }else{ + return new JedisCommand<>(client, Command.RANDOMKEY, (cmd)->cmd.randomKey(), (v)->v) + .run(); + } + } + + @Override + public Status rename(final String key, final String newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), okStatusConverter) + .run(args); + } + } + + @Override + public Status rename(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), okStatusConverter) + .run(args); + } + } + + @Override + public Status renameNx(final String key, final String newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), oneStatusConverter) + .run(args); + } + } + + @Override + public Status renameNx(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), oneStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final String key, final byte[] serializedValue, final int ttl) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RESTORE, (cmd)->cmd.restore(key, ttl, serializedValue), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RESTORE, (cmd)->cmd.restore(key, ttl, serializedValue), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RESTORE, (cmd)->cmd.restore(key, ttl, serializedValue), + okStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RESTORE, (cmd)->cmd.restore(key, ttl, serializedValue), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RESTORE, (cmd)->cmd.restore(key, ttl, serializedValue), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RESTORE, (cmd)->cmd.restore(key, ttl, serializedValue), + okStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final String key, final byte[] serializedValue, final int ttl, + final RestoreArgument restoreArgument) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl).add(restoreArgument); + final RestoreParams restoreParams = JedisRestoreParams.from(restoreArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl, + final RestoreArgument restoreArgument) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl).add(restoreArgument); + final RestoreParams restoreParams = JedisRestoreParams.from(restoreArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final String cursor) { + final CommandArguments args = CommandArguments.create(cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final byte[] cursor) { + final CommandArguments args = CommandArguments.create(cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return scan(cursor, scanParams, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return scan(cursor, scanParams, args); + } + + @Override + public ScanResult> scan(final String cursor, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(count); + final ScanParams scanParams = new JedisScanParams(count); + + return scan(cursor, scanParams, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(count); + final ScanParams scanParams = new JedisScanParams(count); + + return scan(cursor, scanParams, args); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern).add(count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return scan(cursor, scanParams, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern).add(count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return scan(cursor, scanParams, args); + } + + @Override + public List sort(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + } + } + + @Override + public List sort(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + } + } + + @Override + public List sort(final String key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + } + } + + @Override + public List sort(final byte[] key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + } + } + + @Override + public Long sort(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + } + } + + @Override + public Long sort(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + } + } + + @Override + public Long sort(final String key, final String destKey, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), + (v)->v) + .run(args); + } + } + + @Override + public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), + (v)->v) + .run(args); + } + } + + @Override + public List sortRo(final String key) { + final CommandArguments args = CommandArguments.create(key); + final SortingParams sortingParams = new JedisSortingParams(); + + return sortRo(key, sortingParams, args); + } + + @Override + public List sortRo(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final SortingParams sortingParams = new JedisSortingParams(); + + return sortRo(key, sortingParams, args); + } + + @Override + public List sortRo(final String key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + return sortRo(key, sortingParams, args); + } + + @Override + public List sortRo(final byte[] key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + return sortRo(key, sortingParams, args); + } + + @Override + public Long touch(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } + } + + @Override + public Long touch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } + } + + @Override + public Long ttl(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } + } + + @Override + public Long ttl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } + } + + @Override + public Type type(final String key) { + final CommandArguments args = CommandArguments.create(key); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } + } + + @Override + public Type type(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } + } + + @Override + public Long unlink(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } + } + + @Override + public Long unlink(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } + } + + private Status copy(final String key, final String destKey, final boolean replace, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final byte[] key, final byte[] destKey, final boolean replace, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final String key, final String destKey, final int db, final boolean replace, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, db, replace), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, db, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, db, replace), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, db, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, final String[] keys, + final MigrateParams migrateParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, final byte[][] keys, + final MigrateParams migrateParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + } + } + + private List sortRo(final String key, final SortingParams sortingParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadonly(key, sortingParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadonly(key, sortingParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadonly(key, sortingParams), + (v)->v) + .run(args); + } + } + + private List sortRo(final byte[] key, final SortingParams sortingParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadonly(key, sortingParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadonly(key, sortingParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadonly(key, sortingParams), + (v)->v) + .run(args); + } + } + + private ScanResult> scan(final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + + private ScanResult> scan(final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisListOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisListOperations.java new file mode 100644 index 000000000..73b4a9641 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisListOperations.java @@ -0,0 +1,845 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.Direction; +import com.buession.redis.core.ListPosition; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.LPosArgument; +import com.buession.redis.core.internal.convert.jedis.params.DirectionConverter; +import com.buession.redis.core.internal.convert.jedis.params.ListPositionConverter; +import com.buession.redis.core.internal.jedis.JedisLPosParams; +import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.params.LPosParams; + +import java.util.List; + +/** + * Jedis 单机模式列表命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisListOperations extends AbstractListOperations { + + public JedisListOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public String lIndex(final String key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + } + } + + @Override + public byte[] lIndex(final byte[] key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + } + } + + @Override + public Long lInsert(final String key, final ListPosition position, final String pivot, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) + .put("value", value); + final redis.clients.jedis.args.ListPosition listPosition = (new ListPositionConverter()).convert(position); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), + (v)->v) + .run(args); + } + } + + @Override + public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) + .put("value", value); + final redis.clients.jedis.args.ListPosition listPosition = (new ListPositionConverter()).convert(position); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + } + } + + @Override + public Status lSet(final String key, final long index, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status lSet(final byte[] key, final long index, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Long lLen(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } + } + + @Override + public Long lLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } + } + + @Override + public List lRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List lRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final String key, final String element) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final byte[] key, final byte[] element) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final String key, final String element, final LPosArgument lPosArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + } + } + + @Override + public List lPos(final String key, final String element, final LPosArgument lPosArgument, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) + .put("count", count); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element, lPosParams, count), + (v)->v) + .run(args); + } + } + + @Override + public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) + .put("count", count); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element, lPosParams, count), + (v)->v) + .run(args); + } + } + + @Override + public Long lRem(final String key, final String value, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } + } + + @Override + public Long lRem(final byte[] key, final byte[] value, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } + } + + @Override + public Status lTrim(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } + } + + @Override + public Status lTrim(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } + } + + @Override + public String lMove(final String key, final String destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LMOVE, (cmd)->cmd.lmove(key, destKey, fromDirection, + toDirection), (v)->v) + .run(args); + } + } + + @Override + public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LMOVE, (cmd)->cmd.lmove(key, destKey, fromDirection, + toDirection), (v)->v) + .run(args); + } + } + + @Override + public String blMove(final String key, final String destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to).put("timeout", timeout); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + } + } + + @Override + public byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to).put("timeout", timeout); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + } + } + + @Override + public List blPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + } + } + + @Override + public List blPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + } + } + + @Override + public List brPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + } + } + + @Override + public List brPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + } + } + + @Override + public String brPoplPush(final String key, final String destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BRPOPLPUSH, (cmd)->cmd.brpoplpush(key, destKey, timeout), + (v)->v) + .run(args); + } + } + + @Override + public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BRPOPLPUSH, (cmd)->cmd.brpoplpush(key, destKey, timeout), + (v)->v) + .run(args); + } + } + + @Override + public String lPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] lPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + } + } + + @Override + public Long lPush(final String key, final String... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long lPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long lPushX(final String key, final String... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long lPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } + } + + @Override + public String rPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] rPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + } + } + + @Override + public String rPoplPush(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + } + } + + @Override + public byte[] rPoplPush(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + } + } + + @Override + public Long rPush(final String key, final String... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long rPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long rPushX(final String key, final String... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long rPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisPubSubOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisPubSubOperations.java new file mode 100644 index 000000000..0a4def2f9 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisPubSubOperations.java @@ -0,0 +1,451 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.MapConverter; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.PubSubListener; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.pubsub.jedis.DefaultBinaryJedisPubSub; +import com.buession.redis.pubsub.jedis.DefaultJedisPubSub; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 单机模式 Pub/Sub 命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisPubSubOperations extends AbstractPubSubOperations { + + public JedisPubSubOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + + if(isPipeline()){ + new JedisPipelineCommand<>(client, Command.PSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, Command.PSUBSCRIBE) + .run(args); + }else{ + new JedisCommand<>(client, Command.PSUBSCRIBE, (cmd)->{ + cmd.psubscribe(new DefaultJedisPubSub(pubSubListener), patterns); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + + if(isPipeline()){ + new JedisPipelineCommand<>(client, Command.PSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, Command.PSUBSCRIBE) + .run(args); + }else{ + new JedisCommand<>(client, Command.PSUBSCRIBE, (cmd)->{ + cmd.psubscribe(new DefaultBinaryJedisPubSub(pubSubListener), patterns); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public Long publish(final String channel, final String message) { + final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.PUBLISH) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PUBLISH, (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + } + } + + @Override + public Long publish(final byte[] channel, final byte[] message) { + final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.PUBLISH) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PUBLISH, (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + } + } + + @Override + public List pubsubChannels() { + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.PUBSUB_CHANNELS) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.PUBSUB_CHANNELS) + .run(); + }else{ + return new JedisCommand<>(client, Command.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(), (v)->v) + .run(); + } + } + + @Override + public List pubsubChannels(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return pubsubChannels(pattern, (v)->v, args); + } + + @Override + public List pubsubChannels(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final String sPattern = SafeEncoder.encode(pattern); + final com.buession.core.converter.ListConverter stringToBinaryListConverter = + Converters.listStringToBinary(); + + return pubsubChannels(sPattern, stringToBinaryListConverter, args); + } + + @Override + public List pubsubShardChannels() { + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, + Command.PUBSUB_SHARDCHANNELS) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, + Command.PUBSUB_SHARDCHANNELS) + .run(); + }else{ + return new JedisCommand<>(client, Command.PUBSUB_SHARDCHANNELS, (cmd)->cmd.pubsubShardChannels(), + (v)->v) + .run(); + } + } + + @Override + public List pubsubShardChannels(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return pubsubShardChannels(pattern, (v)->v, args); + } + + @Override + public List pubsubShardChannels(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final String sPattern = SafeEncoder.encode(pattern); + final com.buession.core.converter.ListConverter stringToBinaryListConverter = + Converters.listStringToBinary(); + + return pubsubShardChannels(sPattern, stringToBinaryListConverter, args); + } + + @Override + public Long pubsubNumPat() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.PUBSUB_NUMPAT) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.PUBSUB_NUMPAT) + .run(); + }else{ + return new JedisCommand<>(client, Command.PUBSUB_NUMPAT, (cmd)->cmd.pubsubNumPat(), (v)->v) + .run(); + } + } + + @Override + public Map pubsubNumSub() { + if(isPipeline()){ + return new JedisPipelineCommand, Map>(client, + Command.PUBSUB_NUMSUB) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, Map>(client, + Command.PUBSUB_NUMSUB) + .run(); + }else{ + return new JedisCommand<>(client, Command.PUBSUB_NUMSUB, (cmd)->cmd.pubsubNumSub(), (v)->v) + .run(); + } + } + + @Override + public Map pubsubNumSub(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return pubsubNumSub(channels, (v)->v, args); + } + + @Override + public Map pubsubNumSub(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + final String[] sChannels = SafeEncoder.encode(channels); + final MapConverter stringToBinaryKeyPrimitiveValueMapConverter = + new MapConverter<>(SafeEncoder::encode, (v)->v); + + return pubsubNumSub(sChannels, stringToBinaryKeyPrimitiveValueMapConverter, args); + } + + @Override + public Map pubsubShardNumSub() { + if(isPipeline()){ + return new JedisPipelineCommand, Map>(client, + Command.PUBSUB_SHARDNUMSUB) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, Map>(client, + Command.PUBSUB_SHARDNUMSUB) + .run(); + }else{ + return new JedisCommand<>(client, Command.PUBSUB_SHARDNUMSUB, (cmd)->cmd.pubsubShardNumSub(), + (v)->v) + .run(); + } + } + + @Override + public Map pubsubShardNumSub(final String... shardChannels) { + final CommandArguments args = CommandArguments.create("shardChannels", (Object[]) shardChannels); + return pubsubShardNumSub(shardChannels, (v)->v, args); + } + + @Override + public Map pubsubShardNumSub(final byte[]... shardChannels) { + final CommandArguments args = CommandArguments.create("shardChannels", (Object[]) shardChannels); + final String[] sChannels = SafeEncoder.encode(shardChannels); + final MapConverter stringToBinaryKeyPrimitiveValueMapConverter = + new MapConverter<>(SafeEncoder::encode, (v)->v); + + return pubsubShardNumSub(sChannels, stringToBinaryKeyPrimitiveValueMapConverter, args); + } + + @Override + public Object pUnSubscribe() { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PUNSUBSCRIBE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PUNSUBSCRIBE) + .run(); + }else{ + return new JedisCommand<>(client, Command.PUNSUBSCRIBE) + .run(); + } + } + + @Override + public Object pUnSubscribe(final String... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return pUnSubscribe(args); + } + + @Override + public Object pUnSubscribe(final byte[]... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return pUnSubscribe(args); + } + + @Override + public void subscribe(final String[] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + + if(isPipeline()){ + new JedisPipelineCommand<>(client, Command.SUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, Command.SUBSCRIBE) + .run(args); + }else{ + new JedisCommand<>(client, Command.SUBSCRIBE, (cmd)->{ + cmd.subscribe(new DefaultJedisPubSub(pubSubListener), channels); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public void subscribe(final byte[][] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + + if(isPipeline()){ + new JedisPipelineCommand<>(client, Command.SUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, Command.SUBSCRIBE) + .run(args); + }else{ + new JedisCommand<>(client, Command.SUBSCRIBE, (cmd)->{ + cmd.subscribe(new DefaultBinaryJedisPubSub(pubSubListener), channels); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public Object unSubscribe() { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.UNSUBSCRIBE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.UNSUBSCRIBE) + .run(); + }else{ + return new JedisCommand<>(client, Command.UNSUBSCRIBE) + .run(); + } + } + + @Override + public Object unSubscribe(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return unSubscribe(args); + } + + @Override + public Object unSubscribe(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return unSubscribe(args); + } + + private List pubsubChannels(final String pattern, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.PUBSUB_CHANNELS) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.PUBSUB_CHANNELS) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(pattern), + converter) + .run(); + } + } + + private List pubsubShardChannels(final String pattern, + final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.PUBSUB_SHARDCHANNELS) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.PUBSUB_SHARDCHANNELS) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PUBSUB_SHARDCHANNELS, + (cmd)->cmd.pubsubShardChannels(pattern), converter) + .run(); + } + } + + private Map pubsubNumSub(final String[] channels, + final Converter, Map> converter, + final CommandArguments args) { + + if(isPipeline()){ + return new JedisPipelineCommand, Map>(client, Command.PUBSUB_NUMSUB) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, Map>(client, Command.PUBSUB_NUMSUB) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PUBSUB_NUMSUB, (cmd)->cmd.pubsubNumSub(channels), + converter) + .run(args); + } + } + + private Map pubsubShardNumSub(final String[] shardChannels, + final Converter, Map> converter, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand, Map>(client, Command.PUBSUB_NUMSUB) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, Map>(client, Command.PUBSUB_NUMSUB) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PUBSUB_NUMSUB, + (cmd)->cmd.pubsubShardNumSub(shardChannels), converter) + .run(args); + } + } + + private Object pUnSubscribe(final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PUNSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PUNSUBSCRIBE) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PUNSUBSCRIBE) + .run(args); + } + } + + private Object unSubscribe(final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.UNSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.UNSUBSCRIBE) + .run(args); + }else{ + return new JedisCommand<>(client, Command.UNSUBSCRIBE) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisRedisOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisRedisOperations.java new file mode 100644 index 000000000..2c6fe6950 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisRedisOperations.java @@ -0,0 +1,941 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.Converter; +import com.buession.redis.client.connection.jedis.JedisClusterConnection; +import com.buession.redis.client.connection.jedis.JedisConnection; +import com.buession.redis.client.connection.jedis.JedisSentinelConnection; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.client.operations.RedisOperations; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.internal.jedis.JedisResult; +import com.buession.redis.exception.RedisException; +import com.buession.redis.exception.RedisPipelineException; +import com.buession.redis.exception.RedisTransactionException; +import com.buession.redis.pipeline.PipelineProxy; +import com.buession.redis.transaction.TransactionProxy; +import redis.clients.jedis.ClusterPipeline; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.Pipeline; +import redis.clients.jedis.Response; +import redis.clients.jedis.Transaction; + +/** + * Jedis Redis 命令操作接口 + * + * @author Yong.Teng + */ +public interface JedisRedisOperations extends RedisOperations { + + /** + * Jedis 单机模式常规命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class JedisCommand extends + AbstractStandaloneCommand { + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link JedisStandaloneClient} 实例 + * @param command + * Redis 命令 + */ + public JedisCommand(final JedisStandaloneClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link JedisStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisCommand(final JedisStandaloneClient client, final Command command, + final Executor executor, final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link JedisStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public JedisCommand(final JedisStandaloneClient client, final Command command, final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link JedisStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisCommand(final JedisStandaloneClient client, final Command command, final SubCommand subCommand, + final Executor executor, final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @Override + protected R doExecute() throws RedisException { + final SR result = executor.execute(connection.getJedis()); + return result == null ? null : converter.convert(result); + } + + } + + /** + * Jedis 单机模式管道模式命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class JedisPipelineCommand extends + AbstractStandaloneCommand, SR, R> { + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link JedisStandaloneClient} 实例 + * @param command + * Redis 命令 + */ + public JedisPipelineCommand(final JedisStandaloneClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link JedisStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisPipelineCommand(final JedisStandaloneClient client, final Command command, + final Executor> executor, final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link JedisStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public JedisPipelineCommand(final JedisStandaloneClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link JedisStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisPipelineCommand(final JedisStandaloneClient client, final Command command, + final SubCommand subCommand, final Executor> executor, + final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.pipeline.Pipeline pipeline = pipeline(); + + if(pipeline instanceof PipelineProxy){ + final PipelineProxy> pipelineFactory = + (PipelineProxy>) pipeline; + final Runner runner = new PipelineRunner<>(executor, pipelineFactory, converter); + + pipelineFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisPipelineException("ERR EXEC without pipeline. Did you forget to call openPipeline?"); + } + } + + } + + /** + * Jedis 单机模式事务模式命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class JedisTransactionCommand extends + AbstractStandaloneCommand, SR, R> { + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link JedisStandaloneClient} 实例 + * @param command + * Redis 命令 + */ + public JedisTransactionCommand(final JedisStandaloneClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link JedisStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisTransactionCommand(final JedisStandaloneClient client, final Command command, + final Executor> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link JedisStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public JedisTransactionCommand(final JedisStandaloneClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link JedisStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisTransactionCommand(final JedisStandaloneClient client, final Command command, + final SubCommand subCommand, final Executor> executor, + final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.transaction.Transaction transaction = transaction(); + + if(transaction instanceof TransactionProxy){ + final TransactionProxy> transactionFactory = + (TransactionProxy>) transaction; + final Runner runner = new TransactionRunner<>(executor, transactionFactory, converter); + + transactionFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisTransactionException("ERR EXEC without multi. Did you forget to call multi?"); + } + } + + } + + /** + * Jedis 哨兵模式常规命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class JedisSentinelCommand extends + AbstractSentinelCommand { + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link JedisSentinelClient} 实例 + * @param command + * Redis 命令 + */ + public JedisSentinelCommand(final JedisSentinelClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link JedisSentinelClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisSentinelCommand(final JedisSentinelClient client, final Command command, + final Executor executor, final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link JedisSentinelClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public JedisSentinelCommand(final JedisSentinelClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link JedisSentinelClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisSentinelCommand(final JedisSentinelClient client, final Command command, + final SubCommand subCommand, + final Executor executor, final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @Override + protected R doExecute() throws RedisException { + final SR result = executor.execute(connection.getJedis()); + return result == null ? null : converter.convert(result); + } + + } + + /** + * Jedis 哨兵模式管道模式命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class JedisSentinelPipelineCommand extends + AbstractSentinelCommand, SR, R> { + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link JedisSentinelClient} 实例 + * @param command + * Redis 命令 + */ + public JedisSentinelPipelineCommand(final JedisSentinelClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link JedisSentinelClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisSentinelPipelineCommand(final JedisSentinelClient client, final Command command, + final Executor> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link JedisSentinelClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public JedisSentinelPipelineCommand(final JedisSentinelClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link JedisSentinelClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisSentinelPipelineCommand(final JedisSentinelClient client, final Command command, + final SubCommand subCommand, + final Executor> executor, + final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.pipeline.Pipeline pipeline = pipeline(); + + if(pipeline instanceof PipelineProxy){ + final PipelineProxy> pipelineFactory = (PipelineProxy>) pipeline; + final Runner runner = new PipelineRunner<>(executor, pipelineFactory, converter); + + pipelineFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisPipelineException("ERR EXEC without pipeline. Did you forget to call openPipeline?"); + } + } + + } + + /** + * Jedis 哨兵模式事务模式命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class JedisSentinelTransactionCommand extends + AbstractSentinelCommand, SR, R> { + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link JedisSentinelClient} 实例 + * @param command + * Redis 命令 + */ + public JedisSentinelTransactionCommand(final JedisSentinelClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link JedisSentinelClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisSentinelTransactionCommand(final JedisSentinelClient client, final Command command, + final Executor> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link JedisSentinelClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public JedisSentinelTransactionCommand(final JedisSentinelClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link JedisSentinelClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisSentinelTransactionCommand(final JedisSentinelClient client, final Command command, + final SubCommand subCommand, + final Executor> executor, + final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.transaction.Transaction transaction = transaction(); + + if(transaction instanceof TransactionProxy){ + final TransactionProxy> transactionFactory = + (TransactionProxy>) transaction; + final Runner runner = new TransactionRunner<>(executor, transactionFactory, converter); + + transactionFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisTransactionException("ERR EXEC without multi. Did you forget to call multi?"); + } + } + + } + + /** + * Jedis 集群模式常规命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class JedisClusterCommand extends + AbstractClusterCommand { + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link JedisClusterClient} 实例 + * @param command + * Redis 命令 + */ + public JedisClusterCommand(final JedisClusterClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link JedisClusterClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisClusterCommand(final JedisClusterClient client, final Command command, + final Executor executor, final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link JedisClusterClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public JedisClusterCommand(final JedisClusterClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link JedisClusterClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisClusterCommand(final JedisClusterClient client, final Command command, + final SubCommand subCommand, + final Executor executor, final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @Override + protected R doExecute() throws RedisException { + final SR result = executor.execute(connection.getCluster()); + return result == null ? null : converter.convert(result); + } + + } + + /** + * Jedis 集群模式管道模式命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class JedisClusterPipelineCommand extends + AbstractClusterCommand, SR, R> { + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link JedisClusterClient} 实例 + * @param command + * Redis 命令 + */ + public JedisClusterPipelineCommand(final JedisClusterClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link JedisClusterClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisClusterPipelineCommand(final JedisClusterClient client, final Command command, + final Executor> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link JedisClusterClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public JedisClusterPipelineCommand(final JedisClusterClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link JedisClusterClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisClusterPipelineCommand(final JedisClusterClient client, final Command command, + final SubCommand subCommand, + final Executor> executor, + final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.pipeline.Pipeline pipeline = pipeline(); + + if(pipeline instanceof PipelineProxy){ + final PipelineProxy> pipelineFactory = (PipelineProxy>) pipeline; + final Runner runner = new PipelineRunner<>(executor, pipelineFactory, converter); + + pipelineFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisPipelineException("ERR EXEC without pipeline. Did you forget to call openPipeline?"); + } + } + + } + + /** + * Jedis 集群模式集群模式命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class JedisClusterTransactionCommand extends + AbstractClusterCommand, SR, R> { + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link JedisClusterClient} 实例 + * @param command + * Redis 命令 + */ + public JedisClusterTransactionCommand(final JedisClusterClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link JedisClusterClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisClusterTransactionCommand(final JedisClusterClient client, final Command command, + final Executor> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link JedisClusterClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public JedisClusterTransactionCommand(final JedisClusterClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link JedisClusterClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public JedisClusterTransactionCommand(final JedisClusterClient client, final Command command, + final SubCommand subCommand, + final Executor> executor, + final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.transaction.Transaction transaction = transaction(); + + if(transaction instanceof TransactionProxy){ + final TransactionProxy> transactionFactory = + (TransactionProxy>) transaction; + final Runner runner = new TransactionRunner<>(executor, transactionFactory, converter); + + transactionFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisTransactionException("ERR EXEC without multi. Did you forget to call multi?"); + } + } + + } + + abstract class PtRunner implements com.buession.redis.core.Command.Runner { + + protected final com.buession.redis.core.Command.Executor> executor; + + protected final Converter converter; + + public PtRunner(final com.buession.redis.core.Command.Executor> executor, + final Converter converter) { + this.executor = executor; + this.converter = converter; + } + + protected JedisResult newJedisResult(final Response response) { + return JedisResult.Builder.fromResponse(response).build(); + } + + protected JedisResult newJedisResult(final Response response, final Converter converter) { + return JedisResult.Builder.fromResponse(response).mappedWith(converter).build(); + } + + } + + final class PipelineRunner extends PtRunner { + + private final PipelineProxy> pipelineFactory; + + public PipelineRunner(final com.buession.redis.core.Command.Executor> executor, + final PipelineProxy> pipelineFactory, + final Converter converter) { + super(executor, converter); + this.pipelineFactory = pipelineFactory; + } + + @SuppressWarnings({"unchecked"}) + @Override + public JedisResult run() throws RedisException { + final Response response = executor.execute(pipelineFactory.getObject()); + return converter == null ? newJedisResult(response) : newJedisResult(response, converter); + } + + } + + final class TransactionRunner extends PtRunner { + + private final TransactionProxy> transactionFactory; + + public TransactionRunner(final com.buession.redis.core.Command.Executor> executor, + final TransactionProxy> transactionFactory, + final Converter converter) { + super(executor, converter); + this.transactionFactory = transactionFactory; + } + + @SuppressWarnings({"unchecked"}) + @Override + public JedisResult run() throws RedisException { + final Response response = executor.execute(transactionFactory.getObject()); + return converter == null ? newJedisResult(response) : newJedisResult(response, converter); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisScriptingOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisScriptingOperations.java new file mode 100644 index 000000000..ccd9415c4 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisScriptingOperations.java @@ -0,0 +1,404 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.jedis.params.FlushModeConverter; + +import java.util.Arrays; +import java.util.List; + +/** + * Jedis 单机模式 Script 命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisScriptingOperations extends AbstractScriptingOperations { + + public JedisScriptingOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public Object eval(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final byte[] script) { + final CommandArguments args = CommandArguments.create("script", script); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final String script, final String... params) { + final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + final int paramsSize = params == null ? 0 : params.length; + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script, paramsSize, params), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final byte[] script, final byte[]... params) { + final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + final int paramsSize = params == null ? 0 : params.length; + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script, paramsSize, params), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final String script, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script, keysList, argumentsList), + (v)->v) + .run(args); + } + } + + @Override + public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments) { + final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script, keysList, argumentsList), + (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final String digest) { + final CommandArguments args = CommandArguments.create("digest", digest); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final byte[] digest) { + final CommandArguments args = CommandArguments.create("digest", digest); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final String digest, final String... params) { + final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); + final int paramsSize = params == null ? 0 : params.length; + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest, paramsSize, params), + (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final byte[] digest, final byte[]... params) { + final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); + final int paramsSize = params == null ? 0 : params.length; + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest, paramsSize, params), + (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final String digest, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EVALSHA, (cmd)->cmd.eval(digest, keysList, argumentsList), + (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final byte[] digest, final byte[][] keys, final byte[][] arguments) { + final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.EVALSHA, (cmd)->cmd.eval(digest, keysList, argumentsList), + (v)->v) + .run(args); + } + } + + @Override + public List scriptExists(final String... sha1) { + final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(null, + sha1), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(null, + sha1), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), (v)->v) + .run(args); + } + } + + @Override + public List scriptExists(final byte[]... sha1) { + final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(null, + sha1), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(null, + sha1), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), (v)->v) + .run(args); + } + } + + @Override + public Status scriptFlush() { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null), okStatusConverter) + .run(); + }else{ + return new JedisCommand<>(client, Command.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), okStatusConverter) + .run(); + } + } + + @Override + public Status scriptFlush(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + final redis.clients.jedis.args.FlushMode flushMode = (new FlushModeConverter()).convert(mode); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null, flushMode), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null, flushMode), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(flushMode), + okStatusConverter) + .run(args); + } + } + + @Override + public String scriptLoad(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), (v)->v) + .run(args); + } + } + + @Override + public byte[] scriptLoad(final byte[] script) { + final CommandArguments args = CommandArguments.create("script", script); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), (v)->v) + .run(args); + } + } + + @Override + public Status scriptKill() { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SCRIPT_KILL, (cmd)->cmd.scriptKill((String) null), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SCRIPT_KILL, + (cmd)->cmd.scriptKill((String) null), + okStatusConverter) + .run(); + }else{ + return new JedisCommand<>(client, Command.SCRIPT_KILL, (cmd)->cmd.scriptKill(), okStatusConverter) + .run(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelAclOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelAclOperations.java new file mode 100644 index 000000000..2fdcf8fa8 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelAclOperations.java @@ -0,0 +1,396 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.AclCategory; +import com.buession.redis.core.AclLog; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.AclSetUserArgument; +import com.buession.redis.core.internal.convert.jedis.response.AccessControlLogEntryConverter; +import com.buession.redis.core.internal.convert.jedis.response.AccessControlUserConverter; +import com.buession.redis.core.internal.convert.jedis.response.AclCategoryConverter; +import com.buession.redis.core.internal.convert.jedis.response.ProtocolCommandConverter; +import redis.clients.jedis.resps.AccessControlLogEntry; + +import java.util.List; + +/** + * Jedis 哨兵模式权限命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisSentinelAclOperations extends AbstractAclOperations { + + public JedisSentinelAclOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public List aclCat() { + final ListConverter converter = AclCategoryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.ACL, + SubCommand.ACL_CAT) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, Command.ACL, + SubCommand.ACL_CAT) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_CAT, (cmd)->cmd.aclCat(), converter) + .run(); + } + } + + @Override + public List aclCat(final AclCategory aclCategory) { + final CommandArguments args = CommandArguments.create(aclCategory); + final ListConverter converter = ProtocolCommandConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.ACL, + SubCommand.ACL_CAT) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, Command.ACL, + SubCommand.ACL_CAT) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_CAT, + (cmd)->cmd.aclCat(aclCategory.name()), converter) + .run(args); + } + } + + @Override + public Long aclDelUser(final String... usernames) { + final CommandArguments args = CommandArguments.create(usernames); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ACL, SubCommand.ACL_DELUSER) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ACL, SubCommand.ACL_DELUSER) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_DELUSER, + (cmd)->cmd.aclDelUser(usernames), (v)->v) + .run(args); + } + } + + @Override + public Long aclDelUser(final byte[]... usernames) { + final CommandArguments args = CommandArguments.create(usernames); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ACL, SubCommand.ACL_DELUSER) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ACL, SubCommand.ACL_DELUSER) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_DELUSER, + (cmd)->cmd.aclDelUser(usernames), (v)->v) + .run(args); + } + } + + @Override + public Status aclDryRun(final String username, final Command command) { + final CommandArguments args = CommandArguments.create(username).add(command); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ACL, SubCommand.ACL_DRYRUN) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ACL, SubCommand.ACL_DRYRUN) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName()), okStatusConverter) + .run(args); + } + } + + @Override + public Status aclDryRun(final String username, final Command command, final String... arguments) { + final CommandArguments args = CommandArguments.create(username).add(command).add(arguments); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ACL, SubCommand.ACL_DRYRUN) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ACL, SubCommand.ACL_DRYRUN) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName(), arguments), okStatusConverter) + .run(args); + } + } + + @Override + public String aclGenPass() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ACL, SubCommand.ACL_GENPASS) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ACL, SubCommand.ACL_GENPASS) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, (cmd)->cmd.aclGenPass(), + (v)->v) + .run(); + } + } + + @Override + public String aclGenPass(final int bits) { + final CommandArguments args = CommandArguments.create(bits); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ACL, SubCommand.ACL_GENPASS) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ACL, SubCommand.ACL_GENPASS) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, (cmd)->cmd.aclGenPass(bits), + (v)->v) + .run(args); + } + } + + @Override + public AclUser aclGetUser(final String username) { + final CommandArguments args = CommandArguments.create(username); + final AccessControlUserConverter accessControlUserConverter = new AccessControlUserConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ACL, SubCommand.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ACL, SubCommand.ACL_GETUSER) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_GETUSER, + (cmd)->cmd.aclGetUser(username), accessControlUserConverter) + .run(args); + } + } + + @Override + public AclUser aclGetUser(final byte[] username) { + final CommandArguments args = CommandArguments.create(username); + final AccessControlUserConverter accessControlUserConverter = new AccessControlUserConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ACL, SubCommand.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ACL, SubCommand.ACL_GETUSER) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_GETUSER, + (cmd)->cmd.aclGetUser(username), accessControlUserConverter) + .run(args); + } + } + + @Override + public List aclList() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.ACL, SubCommand.LIST) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, Command.ACL, SubCommand.LIST) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.LIST, (cmd)->cmd.aclList(), (v)->v) + .run(); + } + } + + @Override + public Status aclLoad() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ACL, SubCommand.LOAD) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ACL, SubCommand.LOAD) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.LOAD, (cmd)->cmd.aclLoad(), + okStatusConverter) + .run(); + } + } + + @Override + public List aclLog() { + final ListConverter listAccessControlLogEntryConverter = + AccessControlLogEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.ACL, SubCommand.ACL_LOG) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, Command.ACL, + SubCommand.ACL_LOG) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_LOG, (cmd)->cmd.aclLog(), + listAccessControlLogEntryConverter) + .run(); + } + } + + @Override + public List aclLog(final int count) { + final CommandArguments args = CommandArguments.create(count); + final ListConverter listAccessControlLogEntryConverter = + AccessControlLogEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.ACL, SubCommand.ACL_LOG) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, Command.ACL, + SubCommand.ACL_LOG) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_LOG, (cmd)->cmd.aclLog(count), + listAccessControlLogEntryConverter) + .run(args); + } + } + + @Override + public Status aclLogReset() { + final CommandArguments args = CommandArguments.create(SubCommand.RESET); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ACL, SubCommand.ACL_LOG) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ACL, SubCommand.ACL_LOG) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_LOG, (cmd)->cmd.aclLogReset(), + okStatusConverter) + .run(args); + } + } + + @Override + public Status aclSave() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ACL, SubCommand.SAVE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ACL, SubCommand.SAVE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.SAVE, (cmd)->cmd.aclSave(), + okStatusConverter) + .run(); + } + } + + @Override + public Status aclSetUser(final String username, final AclSetUserArgument rules) { + final CommandArguments args = CommandArguments.create(username).add(rules); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ACL, SubCommand.ACL_SETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ACL, SubCommand.ACL_SETUSER) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_SETUSER, + (cmd)->cmd.aclSetUser(username, rules.toArray()), okStatusConverter) + .run(args); + } + } + + @Override + public Status aclSetUser(final byte[] username, final AclSetUserArgument rules) { + final CommandArguments args = CommandArguments.create(username).add(rules); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ACL, SubCommand.ACL_SETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ACL, SubCommand.ACL_SETUSER) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_SETUSER, + (cmd)->cmd.aclSetUser(username, rules.toBinaryArray()), okStatusConverter) + .run(args); + } + } + + @Override + public List aclUsers() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.ACL, + SubCommand.ACL_USERS) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, Command.ACL, + SubCommand.ACL_USERS) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_USERS, (cmd)->cmd.aclUsers(), (v)->v) + .run(); + } + } + + @Override + public String aclWhoAmI() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ACL, SubCommand.ACL_WHOAMI) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ACL, SubCommand.ACL_WHOAMI) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.ACL, SubCommand.ACL_WHOAMI, (cmd)->cmd.aclWhoAmI(), + (v)->v) + .run(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelBitMapOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelBitMapOperations.java new file mode 100644 index 000000000..29eaeeccf --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelBitMapOperations.java @@ -0,0 +1,554 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.BitType; +import com.buession.redis.core.BitOperation; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.BitFieldArgument; +import com.buession.redis.core.command.args.BitFieldRoArgument; +import com.buession.redis.core.internal.convert.jedis.params.BitTypeConverter; +import com.buession.redis.core.internal.convert.jedis.params.BitOperationConverter; +import com.buession.redis.core.internal.jedis.JedisBitPosParams; +import redis.clients.jedis.args.BitOP; +import redis.clients.jedis.params.BitPosParams; + +import java.util.List; + +/** + * Jedis 哨兵模式 BitMap 命令操作抽象类 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelBitMapOperations extends AbstractBitMapOperations { + + public JedisSentinelBitMapOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public Long bitCount(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final String key, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end).add(bitType); + final redis.clients.jedis.args.BitCountOption option = (new BitTypeConverter()).convert( + bitType); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end, option), + (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end).add(bitType); + final redis.clients.jedis.args.BitCountOption option = (new BitTypeConverter()).convert( + bitType); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end, option), + (v)->v) + .run(args); + } + } + + @Override + public List bitField(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + } + } + + @Override + public List bitField(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key), (v)->v) + .run(args); + } + } + + @Override + public List bitField(final String key, final BitFieldArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + final String[] arguments = argument.toArray(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + } + } + + @Override + public List bitField(final byte[] key, final BitFieldArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + final byte[][] arguments = argument.toBinaryArray(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + } + } + + @Override + public List bitFieldRo(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), (v)->v) + .run(args); + } + } + + @Override + public List bitFieldRo(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key), (v)->v) + .run(args); + } + } + + @Override + public List bitFieldRo(final String key, final BitFieldRoArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + final String[] arguments = argument.toArray(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key, arguments), + (v)->v) + .run(args); + } + } + + @Override + public List bitFieldRo(final byte[] key, final BitFieldRoArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + final byte[][] arguments = argument.toBinaryArray(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key, arguments), + (v)->v) + .run(args); + } + } + + @Override + public Long bitOp(final BitOperation operation, final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create(operation).add(destKey).add(keys); + final BitOP bitOP = (new BitOperationConverter()).convert(operation); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(operation).add(destKey).add(keys); + final BitOP bitOP = (new BitOperationConverter()).convert(operation); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final String key, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final String key, final boolean value, final long start) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start); + final BitPosParams bitPosParams = new JedisBitPosParams(start); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start); + final BitPosParams bitPosParams = new JedisBitPosParams(start); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(bitType); + final BitPosParams bitPosParams = new JedisBitPosParams(start, bitType); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(bitType); + final BitPosParams bitPosParams = new JedisBitPosParams(start); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end); + final BitPosParams bitPosParams = new JedisBitPosParams(start, end); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end); + final BitPosParams bitPosParams = new JedisBitPosParams(start, end); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end).add(bitType); + final BitPosParams bitPosParams = new JedisBitPosParams(start, end, bitType); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end).add(bitType); + final BitPosParams bitPosParams = new JedisBitPosParams(start, end, bitType); + + return bitPos(key, value, bitPosParams, args); + } + + @Override + public Boolean getBit(final String key, final long offset) { + final CommandArguments args = CommandArguments.create(key).add(offset); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + } + } + + @Override + public Boolean getBit(final byte[] key, final long offset) { + final CommandArguments args = CommandArguments.create(key).add(offset); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + } + } + + @Override + public Boolean setBit(final String key, final long offset, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(offset).add(value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + } + } + + @Override + public Boolean setBit(final byte[] key, final long offset, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(offset).add(value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + } + } + + private Long bitPos(final String key, final boolean value, final BitPosParams bitPosParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, bitPosParams), + (v)->v) + .run(args); + } + } + + private Long bitPos(final byte[] key, final boolean value, final BitPosParams bitPosParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, bitPosParams), + (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelClusterOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelClusterOperations.java new file mode 100644 index 000000000..b9fd2060c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelClusterOperations.java @@ -0,0 +1,647 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.BumpEpoch; +import com.buession.redis.core.ClusterFailoverOption; +import com.buession.redis.core.ClusterInfo; +import com.buession.redis.core.ClusterLink; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.ClusterResetOption; +import com.buession.redis.core.ClusterSetSlotOption; +import com.buession.redis.core.ClusterRedisShard; +import com.buession.redis.core.ClusterSlot; +import com.buession.redis.core.SlotRange; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.internal.convert.jedis.params.ClusterFailoverOptionConverter; +import com.buession.redis.core.internal.convert.jedis.response.ClusterLinkConverter; +import com.buession.redis.core.internal.convert.response.BumpEpochConverter; +import com.buession.redis.core.internal.convert.response.ClusterInfoConverter; +import com.buession.redis.core.internal.convert.response.ClusterNodesConverter; +import com.buession.redis.core.internal.convert.jedis.response.ClusterReplicasConverter; +import com.buession.redis.core.internal.convert.jedis.response.ClusterResetOptionConverter; +import com.buession.redis.core.internal.convert.response.ClusterNodeConverter; +import com.buession.redis.core.internal.convert.response.ClusterSlotConverter; +import redis.clients.jedis.args.ClusterResetType; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 哨兵模式集群命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelClusterOperations extends AbstractClusterOperations { + + public JedisSentinelClusterOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public Status asking() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ASKING) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ASKING) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.ASKING, (cmd)->cmd.asking(), okStatusConverter) + .run(); + } + } + + @Override + public Status clusterAddSlots(final int... slots) { + final CommandArguments args = CommandArguments.create(slots); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_ADDSLOTS) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_ADDSLOTS) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTS, + (cmd)->cmd.clusterAddSlots(slots), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterAddSlotsRange(final SlotRange... slots) { + final CommandArguments args = CommandArguments.create(slots); + final int[] slotRanges = numberRangeArray(slots); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_ADDSLOTSRANGE) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_ADDSLOTSRANGE) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTSRANGE, + (cmd)->cmd.clusterAddSlotsRange(slotRanges), okStatusConverter) + .run(args); + } + } + + @Override + public KeyValue clusterBumpEpoch() { + final BumpEpochConverter bumpEpochConverter = new BumpEpochConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, KeyValue>(client, + Command.CLUSTER, SubCommand.CLUSTER_BUMPEPOCH) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, KeyValue>( + client, Command.CLUSTER, SubCommand.CLUSTER_BUMPEPOCH) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_BUMPEPOCH, + (cmd)->cmd.clusterBumpEpoch(), bumpEpochConverter) + .run(); + } + } + + @Override + public Long clusterCountFailureReports(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_COUNTFAILUREREPORTS) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_COUNTFAILUREREPORTS) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTFAILUREREPORTS, + (cmd)->cmd.clusterCountFailureReports(nodeId), (v)->v) + .run(args); + } + } + + @Override + public Long clusterCountKeysInSlot(final int slot) { + final CommandArguments args = CommandArguments.create(slot); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_COUNTKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_COUNTKEYSINSLOT) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + } + } + + @Override + public Status clusterDelSlots(final int... slots) { + final CommandArguments args = CommandArguments.create(slots); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_DELSLOTS) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_DELSLOTS) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTS, + (cmd)->cmd.clusterDelSlots(slots), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterDelSlotsRange(final SlotRange... slots) { + final CommandArguments args = CommandArguments.create(slots); + final int[] slotRanges = numberRangeArray(slots); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_DELSLOTSRANGE) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_DELSLOTSRANGE) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTSRANGE, + (cmd)->cmd.clusterDelSlotsRange(slotRanges), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption) { + final CommandArguments args = CommandArguments.create(clusterFailoverOption); + final redis.clients.jedis.args.ClusterFailoverOption failoverOption = + (new ClusterFailoverOptionConverter()).convert(clusterFailoverOption); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_FAILOVER) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_FAILOVER) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FAILOVER, + (cmd)->cmd.clusterFailover(failoverOption), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterFlushSlots() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_FLUSHSLOTS) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_FLUSHSLOTS) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FLUSHSLOTS, + (cmd)->cmd.clusterFlushSlots(), okStatusConverter) + .run(); + } + } + + @Override + public Status clusterForget(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_FORGET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_FORGET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FORGET, + (cmd)->cmd.clusterForget(nodeId), okStatusConverter) + .run(args); + } + } + + @Override + public List clusterGetKeysInSlot(final int slot, final int count) { + final CommandArguments args = CommandArguments.create(slot).add(count); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, + Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, count), (v)->v) + .run(args); + } + } + + @Override + public ClusterInfo clusterInfo() { + final ClusterInfoConverter clusterInfoConverter = new ClusterInfoConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, SubCommand.INFO) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.INFO) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.INFO, (cmd)->cmd.clusterInfo(), + clusterInfoConverter) + .run(); + } + } + + @Override + public Long clusterKeySlot(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterKeySlot(key), (v)->v) + .run(args); + } + } + + @Override + public List clusterLinks() { + final ListConverter, ClusterLink> listConverter = ClusterLinkConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.CLUSTER, + SubCommand.CLUSTER_LINKS) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, Command.CLUSTER, + SubCommand.CLUSTER_LINKS) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_LINKS, + (cmd)->cmd.clusterLinks(), listConverter) + .run(); + } + } + + @Override + public Status clusterMeet(final String ip, final int port) { + final CommandArguments args = CommandArguments.create(ip).add(port); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MEET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MEET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MEET, + (cmd)->cmd.clusterMeet(ip, port), okStatusConverter) + .run(args); + } + } + + @Override + public String clusterMyId() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MYID) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_MYID) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MYID, + (cmd)->cmd.clusterMyId(), (v)->v) + .run(); + } + } + + @Override + public String clusterMyShardId() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_MYSHARDID) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_MYSHARDID) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MYSHARDID, + (cmd)->cmd.clusterMyShardId(), (v)->v) + .run(); + } + } + + @Override + public List clusterNodes() { + final ClusterNodesConverter clusterNodesConverter = new ClusterNodesConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, + Command.CLUSTER, SubCommand.NODES) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + Command.CLUSTER, SubCommand.NODES) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.NODES, (cmd)->cmd.clusterNodes(), + clusterNodesConverter) + .run(); + } + } + + @Override + public List clusterReplicas(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + final ListConverter listClusterReplicasConverter = ClusterReplicasConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, + Command.CLUSTER, SubCommand.CLUSTER_REPLICAS) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + Command.CLUSTER, SubCommand.CLUSTER_REPLICAS) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICAS, + (cmd)->cmd.clusterReplicas(nodeId), listClusterReplicasConverter) + .run(args); + } + } + + @Override + public Status clusterReplicate(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_REPLICATE) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_REPLICATE) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICATE, + (cmd)->cmd.clusterReplicate(nodeId), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterReset() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, SubCommand.RESET) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, SubCommand.RESET) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.RESET, + (cmd)->cmd.clusterReset(), okStatusConverter) + .run(); + } + } + + @Override + public Status clusterReset(final ClusterResetOption clusterResetOption) { + final CommandArguments args = CommandArguments.create(clusterResetOption); + final ClusterResetType clusterResetType = (new ClusterResetOptionConverter()).convert(clusterResetOption); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, SubCommand.RESET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, SubCommand.RESET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.RESET, + (cmd)->cmd.clusterReset(clusterResetType), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterSaveConfig() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_SAVECONFIG) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_SAVECONFIG) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SAVECONFIG, + (cmd)->cmd.clusterSaveConfig(), okStatusConverter) + .run(); + } + } + + @Override + public Status clusterSetConfigEpoch(final long configEpoch) { + final CommandArguments args = CommandArguments.create(configEpoch); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_SETCONFIGEPOCH) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_SETCONFIGEPOCH) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId) { + final CommandArguments args = CommandArguments.create(slot).add(setSlotOption).add(nodeId); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SETSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLUSTER, + SubCommand.CLUSTER_SETSLOT) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + } + } + + @Override + public List clusterShards() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, + Command.CLUSTER, + SubCommand.CLUSTER_SHARDS) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + Command.CLUSTER, + SubCommand.CLUSTER_SHARDS) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SHARDS, + (cmd)->cmd.clusterShards(), + okStatusConverter) + .run(); + } + } + + @Override + public List clusterSlaves(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + final ListConverter listClusterNodeConverter = ClusterNodeConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, + Command.CLUSTER, SubCommand.SLAVES) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + Command.CLUSTER, SubCommand.SLAVES) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.SLAVES, + (cmd)->cmd.clusterSlaves(nodeId), listClusterNodeConverter) + .run(args); + } + } + + @Override + public List clusterSlots() { + final ListConverter listClusterSlotConverter = ClusterSlotConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, + Command.CLUSTER, SubCommand.CLUSTER_SLOTS) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + Command.CLUSTER, SubCommand.CLUSTER_SLOTS) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SLOTS, + (cmd)->cmd.clusterSlots(), + listClusterSlotConverter) + .run(); + } + } + + @Override + public Status readOnly() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.READONLY) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.READONLY) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.READONLY, (cmd)->cmd.readonly(), + okStatusConverter) + .run(); + } + } + + @Override + public Status readWrite() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.READWRITE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.READWRITE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.READWRITE, (cmd)->cmd.readwrite(), + okStatusConverter) + .run(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelConnectionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelConnectionOperations.java new file mode 100644 index 000000000..06f50da95 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelConnectionOperations.java @@ -0,0 +1,567 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.Client; +import com.buession.redis.core.ClientAttributeOption; +import com.buession.redis.core.ClientPauseMode; +import com.buession.redis.core.ClientReply; +import com.buession.redis.core.ClientTrackingInfo; +import com.buession.redis.core.ClientType; +import com.buession.redis.core.ClientUnblockType; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.RedisServer; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.ClientKillArgument; +import com.buession.redis.core.command.args.ClientTracking; +import com.buession.redis.core.command.args.HelloArgument; +import com.buession.redis.core.internal.convert.jedis.params.ClientAttributeOptionConverter; +import com.buession.redis.core.internal.convert.jedis.params.ClientPauseModeConverter; +import com.buession.redis.core.internal.convert.jedis.params.ClientTypeConverter; +import com.buession.redis.core.internal.convert.jedis.params.ClientUnblockTypeConverter; +import com.buession.redis.core.internal.convert.response.ClientConverter; +import com.buession.redis.core.internal.convert.response.PingResultConverter; +import redis.clients.jedis.args.UnblockType; +import redis.clients.jedis.params.ClientKillParams; + +import java.util.List; + +/** + * Jedis 哨兵模式连接命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelConnectionOperations extends AbstractConnectionOperations { + + public JedisSentinelConnectionOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public Status auth(final String user, final String password) { + final CommandArguments args = CommandArguments.create(user).add(password); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.AUTH) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.AUTH) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.AUTH, (cmd)->cmd.auth(user, password), okStatusConverter) + .run(args); + } + } + + @Override + public Status auth(final String password) { + final CommandArguments args = CommandArguments.create(password); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.AUTH) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.AUTH) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.AUTH, (cmd)->cmd.auth(password), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientCaching() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_CACHING); + } + + @Override + public Status clientCaching(final boolean isYes) { + final CommandArguments args = CommandArguments.create(isYes ? Keyword.Common.YES : Keyword.Common.NO); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_CACHING, args); + } + + @Override + public String clientGetName() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_GETNAME) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, + SubCommand.CLIENT_GETNAME) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_GETNAME, + (cmd)->cmd.clientGetname(), (v)->v) + .run(); + } + } + + @Override + public Integer clientGetRedir() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_GETREDIR); + } + + @Override + public Long clientId() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_ID) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_ID) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_ID, (cmd)->cmd.clientId(), + (v)->v) + .run(); + } + } + + @Override + public Client clientInfo() { + final ClientConverter clientConverter = new ClientConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_INFO) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_INFO) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_INFO, (cmd)->cmd.clientInfo(), + clientConverter) + .run(); + } + } + + @Override + public Status clientKill(final String host, final int port) { + final CommandArguments args = CommandArguments.create(host).add(port); + final String addr = host + ':' + port; + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_KILL) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_KILL) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(addr), okStatusConverter) + .run(args); + } + } + + @Override + public Long clientKill(final ClientKillArgument... clientKillArguments) { + final CommandArguments args = CommandArguments.create(clientKillArguments); + final ClientKillParams clientKillParams = createClientKillParamsFromClientKillArgument(clientKillArguments); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_KILL) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_KILL) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(clientKillParams), (v)->v) + .run(args); + } + } + + @Override + public List clientList() { + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.CLIENT, + SubCommand.CLIENT_LIST) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, Command.CLIENT, + SubCommand.CLIENT_LIST) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + } + } + + @Override + public List clientList(final ClientType clientType) { + final CommandArguments args = CommandArguments.create(clientType); + final redis.clients.jedis.args.ClientType jClientType = (new ClientTypeConverter()).convert(clientType); + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.CLIENT, + SubCommand.CLIENT_LIST) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, Command.CLIENT, + SubCommand.CLIENT_LIST) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(jClientType), clientListConverter) + .run(args); + } + } + + @Override + public List clientList(final long... clientIds) { + final CommandArguments args = CommandArguments.create(clientIds); + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.CLIENT, + SubCommand.CLIENT_LIST) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, Command.CLIENT, + SubCommand.CLIENT_LIST) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(clientIds), clientListConverter) + .run(args); + } + } + + @Override + public Status clientNoEvict(final boolean on) { + final CommandArguments args = CommandArguments.create(on ? Keyword.Common.ON : Keyword.Common.OFF); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_NO_EVICT) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, + SubCommand.CLIENT_NO_EVICT) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_NO_EVICT, + (cmd)->(on ? cmd.clientNoEvictOn() : cmd.clientNoEvictOff()), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientNoTouch(final boolean on) { + final CommandArguments args = CommandArguments.create(on ? Keyword.Common.ON : Keyword.Common.OFF); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_NO_TOUCH) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, + SubCommand.CLIENT_NO_TOUCH) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_NO_TOUCH, + (cmd)->(on ? cmd.clientNoTouchOn() : cmd.clientNoTouchOff()), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientPause(final int timeout) { + final CommandArguments args = CommandArguments.create(timeout); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_PAUSE) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_PAUSE) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, (cmd)->cmd.clientInfo(), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clientPause(final int timeout, final ClientPauseMode pauseMode) { + final CommandArguments args = CommandArguments.create(timeout).add(pauseMode); + final redis.clients.jedis.args.ClientPauseMode jClientPauseMode = (new ClientPauseModeConverter()).convert( + pauseMode); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_PAUSE) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, SubCommand.CLIENT_PAUSE) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout, jClientPauseMode), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientReply(final ClientReply option) { + final CommandArguments args = CommandArguments.create(option); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_REPLY, args); + } + + @Override + public Status clientSetInfo(final ClientAttributeOption clientAttributeOption, final String value) { + final CommandArguments args = CommandArguments.create(clientAttributeOption).add(value); + final redis.clients.jedis.args.ClientAttributeOption jClientAttributeOption = + (new ClientAttributeOptionConverter()).convert(clientAttributeOption); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_SETINFO) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, + SubCommand.CLIENT_SETINFO) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETINFO, + (cmd)->cmd.clientSetInfo(jClientAttributeOption, value), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientSetInfo(final ClientAttributeOption clientAttributeOption, final byte[] value) { + final CommandArguments args = CommandArguments.create(clientAttributeOption).add(value); + final redis.clients.jedis.args.ClientAttributeOption jClientAttributeOption = + (new ClientAttributeOptionConverter()).convert(clientAttributeOption); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_SETINFO) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, + SubCommand.CLIENT_SETINFO) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETINFO, + (cmd)->cmd.clientSetInfo(jClientAttributeOption, value), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientSetName(final String name) { + final CommandArguments args = CommandArguments.create(name); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_SETNAME) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, + SubCommand.CLIENT_SETNAME) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientSetName(final byte[] name) { + final CommandArguments args = CommandArguments.create(name); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_SETNAME) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, + SubCommand.CLIENT_SETNAME) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientTracking(final ClientTracking clientTracking) { + final CommandArguments args = CommandArguments.create(clientTracking); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_TRACKING, args); + } + + @Override + public ClientTrackingInfo clientTrackingInfo() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_TRACKINGINFO); + } + + @Override + public Status clientUnblock(final int clientId) { + final CommandArguments args = CommandArguments.create(clientId); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, + SubCommand.CLIENT_UNBLOCK) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK, + (cmd)->cmd.clientUnblock(clientId), oneStatusConverter) + .run(args); + } + } + + @Override + public Status clientUnblock(final int clientId, final ClientUnblockType type) { + final CommandArguments args = CommandArguments.create(clientId).add(type); + final UnblockType unblockType = (new ClientUnblockTypeConverter()).convert(type); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, + SubCommand.CLIENT_UNBLOCK) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + } + } + + @Override + public Status clientUnPause() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CLIENT, SubCommand.CLIENT_UNPAUSE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CLIENT, + SubCommand.CLIENT_UNPAUSE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_UNPAUSE, + (cmd)->cmd.clientUnpause(), okStatusConverter) + .run(); + } + } + + @Override + public String echo(final String str) { + final CommandArguments args = CommandArguments.create(str); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ECHO) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ECHO) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ECHO, (cmd)->cmd.echo(str), (v)->v) + .run(args); + } + } + + @Override + public byte[] echo(final byte[] str) { + final CommandArguments args = CommandArguments.create(str); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ECHO) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ECHO) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ECHO, (cmd)->cmd.echo(str), (v)->v) + .run(args); + } + } + + @Override + public RedisServer hello(final HelloArgument helloArgument) { + final CommandArguments args = CommandArguments.create(helloArgument); + return notCommand(client, Command.HELLO, args); + } + + @Override + public Status ping() { + final PingResultConverter pingResultConverter = new PingResultConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.PING) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.PING) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.PING, (cmd)->cmd.ping(), pingResultConverter) + .run(); + } + } + + @Override + public Status quit() { + return notCommand(client, Command.QUIT); + } + + @Override + public Status reset() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.RESET) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.RESET) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.RESET, (cmd)->cmd.reset(), okStatusConverter) + .run(); + } + } + + @Override + public Status select(final int db) { + final CommandArguments args = CommandArguments.create(db); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SELECT, (cmd)->cmd.select(db), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.SELECT) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SELECT, (cmd)->cmd.select(db), okStatusConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelGeoOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelGeoOperations.java new file mode 100644 index 000000000..6d77c82be --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelGeoOperations.java @@ -0,0 +1,876 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.builder.MapBuilder; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Geo; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.GeoAddArgument; +import com.buession.redis.core.command.args.GeoRadiusArgument; +import com.buession.redis.core.command.args.GeoSearchArgument; +import com.buession.redis.core.command.args.GeoSearchStoreArgument; +import com.buession.redis.core.internal.convert.jedis.params.GeoUnitConverter; +import com.buession.redis.core.internal.convert.jedis.response.GeoCoordinateConverter; +import com.buession.redis.core.internal.convert.jedis.response.GeoRadiusResponseConverter; +import com.buession.redis.core.internal.jedis.JedisGeoAddParam; +import com.buession.redis.core.internal.jedis.JedisGeoRadiusParam; +import com.buession.redis.core.internal.jedis.JedisGeoSearchParam; +import com.buession.redis.core.internal.jedis.JedisGeoSearchStoreParam; +import redis.clients.jedis.GeoCoordinate; +import redis.clients.jedis.params.GeoAddParams; +import redis.clients.jedis.params.GeoRadiusParam; +import redis.clients.jedis.params.GeoSearchParam; +import redis.clients.jedis.resps.GeoRadiusResponse; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 哨兵模式地理位置命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelGeoOperations extends AbstractGeoOperations { + + public JedisSentinelGeoOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public Long geoAdd(final String key, final String member, final double longitude, final double latitude) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(member); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(member); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + final Map geoCoordinates = createGeoCoordinateMapFromGeoMap(memberCoordinates); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + final Map geoCoordinates = createGeoCoordinateMapFromGeoMap(memberCoordinates); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final String key, final String member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(longitude).add(latitude) + .add(member); + final Map memberCoordinates = + MapBuilder.create(1).put(member, new Geo(longitude, latitude)).build(); + + return geoAdd(key, memberCoordinates, geoAddArgument, args); + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(longitude).add(latitude) + .add(member); + final Map memberCoordinates = + MapBuilder.create(1).put(member, new Geo(longitude, latitude)).build(); + + return geoAdd(key, memberCoordinates, geoAddArgument, args); + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + return geoAdd(key, memberCoordinates, geoAddArgument, args); + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(memberCoordinates); + return geoAdd(key, memberCoordinates, geoAddArgument, args); + } + + @Override + public Double geoDist(final String key, final String member1, final String member2) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2), + (v)->v) + .run(args); + } + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2), + (v)->v) + .run(args); + } + } + + @Override + public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + } + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + } + } + + @Override + public List geoHash(final String key, final String... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + } + } + + @Override + public List geoHash(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + } + } + + @Override + public List geoPos(final String key, final String... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEOPOS, + (cmd)->cmd.geopos(key, members), listGeoCoordinateConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } + } + + @Override + public List geoPos(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEOPOS, + (cmd)->cmd.geopos(key, members), listGeoCoordinateConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } + } + + @Override + public List geoRadius(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadius(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = + CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit).add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = + CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit).add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final String key, final String member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoSearch(final String key, final GeoSearchArgument geoSearchArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoSearchArgument); + final GeoSearchParam geoSearchParam = JedisGeoSearchParam.from(geoSearchArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEOSEARCH, + (cmd)->cmd.geosearch(key, geoSearchParam), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEOSEARCH, + (cmd)->cmd.geosearch(key, geoSearchParam), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEOSEARCH, (cmd)->cmd.geosearch(key, geoSearchParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoSearch(final byte[] key, final GeoSearchArgument geoSearchArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoSearchArgument); + final GeoSearchParam geoSearchParam = JedisGeoSearchParam.from(geoSearchArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEOSEARCH, + (cmd)->cmd.geosearch(key, geoSearchParam), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEOSEARCH, + (cmd)->cmd.geosearch(key, geoSearchParam), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEOSEARCH, (cmd)->cmd.geosearch(key, geoSearchParam), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public Long geoSearchStore(final String destKey, final String key, + final GeoSearchStoreArgument geoSearchStoreArgument) { + final CommandArguments args = CommandArguments.create(destKey).add(key).add(geoSearchStoreArgument); + final GeoSearchParam geoSearchParam = JedisGeoSearchStoreParam.from(geoSearchStoreArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + } + } + + @Override + public Long geoSearchStore(final byte[] destKey, final byte[] key, + final GeoSearchStoreArgument geoSearchStoreArgument) { + final CommandArguments args = CommandArguments.create(destKey).add(key).add(geoSearchStoreArgument); + final GeoSearchParam geoSearchParam = JedisGeoSearchStoreParam.from(geoSearchStoreArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchStore(destKey, key, geoSearchParam), (v)->v) + .run(args); + } + } + + private Long geoAdd(final String key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument, final CommandArguments args) { + final Map geoCoordinates = createGeoCoordinateMapFromGeoMap(memberCoordinates); + final GeoAddParams geoAddParams = JedisGeoAddParam.from(geoAddArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + } + } + + private Long geoAdd(final byte[] key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument, final CommandArguments args) { + final Map geoCoordinates = createGeoCoordinateMapFromGeoMap(memberCoordinates); + final GeoAddParams geoAddParams = JedisGeoAddParam.from(geoAddArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddParams, geoCoordinates), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelHashOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelHashOperations.java new file mode 100644 index 000000000..cc37400ac --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelHashOperations.java @@ -0,0 +1,909 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapEntryKeyValueConverter; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.HScanArgument; +import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; +import com.buession.redis.core.internal.jedis.JedisScanParams; +import redis.clients.jedis.params.ScanParams; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Jedis 哨兵模式哈希表命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelHashOperations extends AbstractHashOperations { + + public JedisSentinelHashOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public Long hDel(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } + } + + @Override + public Long hDel(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } + } + + @Override + public Boolean hExists(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } + } + + @Override + public Boolean hExists(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } + } + + @Override + public List hExpire(final String key, final int lifetime, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields.length) + .add(fields); + return notCommand(client, Command.HEXPIRE, args); + } + + @Override + public List hExpire(final byte[] key, final int lifetime, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields.length) + .add(fields); + return notCommand(client, Command.HEXPIRE, args); + } + + @Override + public List hExpire(final String key, final int lifetime, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIRE, args); + } + + @Override + public List hExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIRE, args); + } + + @Override + public List hExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireAt(final String key, final long unixTimestamp, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireTime(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIRETIME, args); + } + + @Override + public List hExpireTime(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIRETIME, args); + } + + @Override + public String hGet(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + } + } + + @Override + public byte[] hGet(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + } + } + + @Override + public Map hGetAll(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + } + } + + @Override + public Map hGetAll(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + } + } + + @Override + public Long hIncrBy(final String key, final String field, final long value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Long hIncrBy(final byte[] key, final byte[] field, final long value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Double hIncrByFloat(final String key, final String field, final double value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HINCRBYFLOAT, (cmd)->cmd.hincrByFloat(key, field, value), + (v)->v) + .run(args); + } + } + + @Override + public Double hIncrByFloat(final byte[] key, final byte[] field, final double value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HINCRBYFLOAT, (cmd)->cmd.hincrByFloat(key, field, value), + (v)->v) + .run(args); + } + } + + @Override + public Set hKeys(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + } + } + + @Override + public Set hKeys(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + } + } + + @Override + public Long hLen(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } + } + + @Override + public Long hLen(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } + } + + @Override + public List hMGet(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + } + } + + @Override + public List hMGet(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + } + } + + @Override + public Status hMSet(final String key, final Map data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), okStatusConverter) + .run(args); + } + } + + @Override + public Status hMSet(final byte[] key, final Map data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), okStatusConverter) + .run(args); + } + } + + @Override + public List hPersist(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPERSIST, args); + } + + @Override + public List hPersist(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPERSIST, args); + } + + @Override + public List hpExpire(final String key, final int lifetime, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpire(final byte[] key, final int lifetime, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpire(final String key, final int lifetime, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = + CommandArguments.create(key).add(lifetime).add(expireOption).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = + CommandArguments.create(key).add(lifetime).add(expireOption).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpireAt(final String key, final long unixTimestamp, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireTime(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRETIME, args); + } + + @Override + public List hpExpireTime(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRETIME, args); + } + + @Override + public List hpTtl(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public List hpTtl(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public String hRandField(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] hRandField(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + } + } + + @Override + public List hRandField(final String key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + } + } + + @Override + public List hRandField(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + } + } + + @Override + public List> hRandFieldWithValues(final String key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count).add(Keyword.Hash.WITHVALUES); + final ListConverter, KeyValue> converter = + new ListConverter<>(new MapEntryKeyValueConverter<>((k)->k, (v)->v)); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfieldWithValues(key, count), + converter) + .run(args); + } + } + + @Override + public List> hRandFieldWithValues(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count).add(Keyword.Hash.WITHVALUES); + final ListConverter, KeyValue> converter = + new ListConverter<>(new MapEntryKeyValueConverter<>((k)->k, (v)->v)); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfieldWithValues(key, count), + converter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create(key).add(cursor); + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create(key).add(cursor); + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final String key, final String cursor, + final HScanArgument scanArgument) { + final CommandArguments args = CommandArguments.create(key).add(cursor).add(scanArgument); + final ScanParams scanParams = JedisScanParams.from(scanArgument); + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanParams), mapScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, + final HScanArgument scanArgument) { + final CommandArguments args = CommandArguments.create(key).add(cursor).add(scanArgument); + final ScanParams scanParams = JedisScanParams.from(scanArgument); + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanParams), mapScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + } + } + + @Override + public Long hSet(final String key, final KeyValue... data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HSET, + (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Long hSet(final byte[] key, final KeyValue... data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HSET, + (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Status hSetNx(final String key, final String field, final String value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status hSetNx(final byte[] key, final byte[] field, final byte[] value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + } + } + + @Override + public Long hStrLen(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } + } + + @Override + public Long hStrLen(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } + } + + @Override + public List hTtl(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public List hTtl(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public List hVals(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + } + } + + @Override + public List hVals(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelHyperLogLogOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelHyperLogLogOperations.java new file mode 100644 index 000000000..69b53beaf --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelHyperLogLogOperations.java @@ -0,0 +1,152 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; + +/** + * Jedis 哨兵模式 HyperLogLog 命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelHyperLogLogOperations extends AbstractHyperLogLogOperations { + + public JedisSentinelHyperLogLogOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public Status pfAdd(final String key, final String... elements) { + final CommandArguments args = CommandArguments.create(key).add(elements); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pfAdd(final byte[] key, final byte[]... elements) { + final CommandArguments args = CommandArguments.create(key).add(elements); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + } + } + + @Override + public Long pfCount(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } + } + + @Override + public Long pfCount(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } + } + + @Override + public Status pfMerge(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create(destKey).add(keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + } + } + + @Override + public Status pfMerge(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(destKey).add(keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelKeyOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelKeyOperations.java new file mode 100644 index 000000000..4a6ea7301 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelKeyOperations.java @@ -0,0 +1,1709 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.ObjectEncoding; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Type; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.MigrateArgument; +import com.buession.redis.core.command.args.RestoreArgument; +import com.buession.redis.core.command.args.SortArgument; +import com.buession.redis.core.internal.convert.jedis.params.ExpireOptionConverter; +import com.buession.redis.core.internal.convert.response.BinaryObjectEncodingConverter; +import com.buession.redis.core.internal.convert.response.ObjectEncodingConverter; +import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; +import com.buession.redis.core.internal.convert.response.TypeConverter; +import com.buession.redis.core.internal.jedis.JedisMigrateParams; +import com.buession.redis.core.internal.jedis.JedisRestoreParams; +import com.buession.redis.core.internal.jedis.JedisScanParams; +import com.buession.redis.core.internal.jedis.JedisSortingParams; +import com.buession.redis.utils.SafeEncoder; +import redis.clients.jedis.args.ExpiryOption; +import redis.clients.jedis.params.MigrateParams; +import redis.clients.jedis.params.RestoreParams; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.params.SortingParams; + +import java.util.List; +import java.util.Set; + +/** + * Jedis 哨兵模式 Key 命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelKeyOperations extends AbstractKeyOperations { + + public JedisSentinelKeyOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public Status copy(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + return copy(key, destKey, false, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + return copy(key, destKey, false, args); + } + + @Override + public Status copy(final String key, final String destKey, final int db) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + return copy(key, destKey, db, false, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + return copy(key, destKey, db, false, args); + } + + @Override + public Status copy(final String key, final String destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, replace, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, replace, args); + } + + @Override + public Status copy(final String key, final String destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, db, replace, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, db, replace, args); + } + + @Override + public Long del(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } + } + + @Override + public Long del(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } + } + + @Override + public String dump(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), SafeEncoder::encode) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), + SafeEncoder::encode) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), SafeEncoder::encode) + .run(args); + } + } + + @Override + public byte[] dump(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + } + } + + @Override + public Boolean exists(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + } + } + + @Override + public Boolean exists(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + } + } + + @Override + public Long exists(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } + } + + @Override + public Long exists(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } + } + + @Override + public Status expire(final String key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expire(final String key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final String key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final String key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + } + } + + @Override + public Long expireTime(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + } + } + + @Override + public Long expireTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + } + } + + @Override + public Set keys(final String pattern) { + final CommandArguments args = CommandArguments.create(pattern); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + } + } + + @Override + public Set keys(final byte[] pattern) { + final CommandArguments args = CommandArguments.create(pattern); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + } + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final String... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(keys); + final MigrateParams migrateParams = new JedisMigrateParams(); + + return migrate(host, port, db, timeout, keys, migrateParams, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(keys); + final MigrateParams migrateParams = new JedisMigrateParams(); + + return migrate(host, port, db, timeout, keys, migrateParams, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgument migrateArgument, final String... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(migrateArgument) + .add(keys); + final MigrateParams migrateParams = JedisMigrateParams.from(migrateArgument); + + return migrate(host, port, db, timeout, keys, migrateParams, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgument migrateArgument, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(migrateArgument) + .add(keys); + final MigrateParams migrateParams = JedisMigrateParams.from(migrateArgument); + + return migrate(host, port, db, timeout, keys, migrateParams, args); + } + + @Override + public Status move(final String key, final int db) { + final CommandArguments args = CommandArguments.create(key).add(db); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.MOVE, (cmd)->cmd.move(key, db), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.MOVE) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.MOVE, (cmd)->cmd.move(key, db), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status move(final byte[] key, final int db) { + final CommandArguments args = CommandArguments.create(key).add(db); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.MOVE, (cmd)->cmd.move(key, db), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.MOVE) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.MOVE, (cmd)->cmd.move(key, db), + oneStatusConverter) + .run(args); + } + } + + @Override + public ObjectEncoding objectEncoding(final String key) { + final CommandArguments args = CommandArguments.create(key); + final ObjectEncodingConverter objectEncodingConverter = new ObjectEncodingConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + } + } + + @Override + public ObjectEncoding objectEncoding(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final BinaryObjectEncodingConverter binaryObjectEncodingConverter = new BinaryObjectEncodingConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), binaryObjectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), binaryObjectEncodingConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), binaryObjectEncodingConverter) + .run(args); + } + } + + @Override + public Long objectFreq(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectFreq(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectIdleTime(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectIdleTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectRefcount(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectRefcount(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + } + } + + @Override + public Status persist(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), oneStatusConverter) + .run(args); + } + } + + @Override + public Status persist(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final String key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final String key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final String key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PEXPIREAT, (cmd)->cmd.pexpireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PEXPIREAT, (cmd)->cmd.pexpireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp, expiryOption), oneStatusConverter) + .run(args); + } + } + + @Override + public Long pExpireTime(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + } + } + + @Override + public Long pExpireTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.expireTime(key), (v)->v) + .run(args); + } + } + + @Override + public Long pTtl(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } + } + + @Override + public Long pTtl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } + } + + @Override + public String randomKey() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RANDOMKEY, (cmd)->cmd.randomKey(), (v)->v) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RANDOMKEY, (cmd)->cmd.randomKey(), + (v)->v) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.RANDOMKEY, (cmd)->cmd.randomKey(), (v)->v) + .run(); + } + } + + @Override + public Status rename(final String key, final String newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + } + } + + @Override + public Status rename(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + } + } + + @Override + public Status renameNx(final String key, final String newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status renameNx(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final String key, final byte[] serializedValue, final int ttl) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RESTORE, (cmd)->cmd.restore(key, ttl, serializedValue), + okStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RESTORE, (cmd)->cmd.restore(key, ttl, serializedValue), + okStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final String key, final byte[] serializedValue, final int ttl, + final RestoreArgument restoreArgument) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl).add(restoreArgument); + final RestoreParams restoreParams = JedisRestoreParams.from(restoreArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl, + final RestoreArgument restoreArgument) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl).add(restoreArgument); + final RestoreParams restoreParams = JedisRestoreParams.from(restoreArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final String cursor) { + final CommandArguments args = CommandArguments.create(cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final byte[] cursor) { + final CommandArguments args = CommandArguments.create(cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return scan(cursor, scanParams, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return scan(cursor, scanParams, args); + } + + @Override + public ScanResult> scan(final String cursor, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(count); + final ScanParams scanParams = new JedisScanParams(count); + + return scan(cursor, scanParams, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(count); + final ScanParams scanParams = new JedisScanParams(count); + + return scan(cursor, scanParams, args); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern).add(count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return scan(cursor, scanParams, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern).add(count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return scan(cursor, scanParams, args); + } + + @Override + public List sort(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + } + } + + @Override + public List sort(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + } + } + + @Override + public List sort(final String key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + } + } + + @Override + public List sort(final byte[] key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + } + } + + @Override + public Long sort(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + } + } + + @Override + public Long sort(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + } + } + + @Override + public Long sort(final String key, final String destKey, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), + (v)->v) + .run(args); + } + } + + @Override + public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), + (v)->v) + .run(args); + } + } + + @Override + public List sortRo(final String key) { + final CommandArguments args = CommandArguments.create(key); + final SortingParams sortingParams = new JedisSortingParams(); + + return sortRo(key, sortingParams, args); + } + + @Override + public List sortRo(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final SortingParams sortingParams = new JedisSortingParams(); + + return sortRo(key, sortingParams, args); + } + + @Override + public List sortRo(final String key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + return sortRo(key, sortingParams, args); + } + + @Override + public List sortRo(final byte[] key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + return sortRo(key, sortingParams, args); + } + + @Override + public Long touch(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } + } + + @Override + public Long touch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } + } + + @Override + public Long ttl(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } + } + + @Override + public Long ttl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } + } + + @Override + public Type type(final String key) { + final CommandArguments args = CommandArguments.create(key); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } + } + + @Override + public Type type(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } + } + + @Override + public Long unlink(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } + } + + @Override + public Long unlink(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } + } + + private Status copy(final String key, final String destKey, final boolean replace, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final byte[] key, final byte[] destKey, final boolean replace, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final String key, final String destKey, final int db, final boolean replace, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, db, replace), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, db, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, db, replace), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, db, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, final String[] keys, + final MigrateParams migrateParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, final byte[][] keys, + final MigrateParams migrateParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + } + } + + private List sortRo(final String key, final SortingParams sortingParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SORT_RO, + (cmd)->cmd.sortReadonly(key, sortingParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SORT_RO, + (cmd)->cmd.sortReadonly(key, sortingParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadonly(key, sortingParams), + (v)->v) + .run(args); + } + } + + private List sortRo(final byte[] key, final SortingParams sortingParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SORT_RO, + (cmd)->cmd.sortReadonly(key, sortingParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SORT_RO, + (cmd)->cmd.sortReadonly(key, sortingParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadonly(key, sortingParams), + (v)->v) + .run(args); + } + } + + private ScanResult> scan(final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + + private ScanResult> scan(final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelListOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelListOperations.java new file mode 100644 index 000000000..b5024bffd --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelListOperations.java @@ -0,0 +1,884 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.Direction; +import com.buession.redis.core.ListPosition; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.LPosArgument; +import com.buession.redis.core.internal.convert.jedis.params.DirectionConverter; +import com.buession.redis.core.internal.convert.jedis.params.ListPositionConverter; +import com.buession.redis.core.internal.jedis.JedisLPosParams; +import redis.clients.jedis.args.ListDirection; +import redis.clients.jedis.params.LPosParams; + +import java.util.List; + +/** + * Jedis 哨兵模式列表命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelListOperations extends AbstractListOperations { + + public JedisSentinelListOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public String lIndex(final String key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + } + } + + @Override + public byte[] lIndex(final byte[] key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + } + } + + @Override + public Long lInsert(final String key, final ListPosition position, final String pivot, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) + .put("value", value); + final redis.clients.jedis.args.ListPosition listPosition = (new ListPositionConverter()).convert(position); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + } + } + + @Override + public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) + .put("value", value); + final redis.clients.jedis.args.ListPosition listPosition = (new ListPositionConverter()).convert(position); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + } + } + + @Override + public Status lSet(final String key, final long index, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status lSet(final byte[] key, final long index, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Long lLen(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } + } + + @Override + public Long lLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } + } + + @Override + public List lRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LRANGE, + (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LRANGE, + (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public List lRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LRANGE, + (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LRANGE, + (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final String key, final String element) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final byte[] key, final byte[] element) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final String key, final String element, final LPosArgument lPosArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), + (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), + (v)->v) + .run(args); + } + } + + @Override + public List lPos(final String key, final String element, final LPosArgument lPosArgument, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) + .put("count", count); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + } + } + + @Override + public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) + .put("count", count); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + } + } + + @Override + public Long lRem(final String key, final String value, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LREM, + (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } + } + + @Override + public Long lRem(final byte[] key, final byte[] value, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LREM, + (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } + } + + @Override + public Status lTrim(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LTRIM, + (cmd)->cmd.ltrim(key, start, end), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } + } + + @Override + public Status lTrim(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LTRIM, + (cmd)->cmd.ltrim(key, start, end), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } + } + + @Override + public String lMove(final String key, final String destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + } + } + + @Override + public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + } + } + + @Override + public String blMove(final String key, final String destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to).put("timeout", timeout); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + } + } + + @Override + public byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to).put("timeout", timeout); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + } + } + + @Override + public List blPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + } + } + + @Override + public List blPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + } + } + + @Override + public List brPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + } + } + + @Override + public List brPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + } + } + + @Override + public String brPoplPush(final String key, final String destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + } + } + + @Override + public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + } + } + + @Override + public String lPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] lPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + } + } + + @Override + public Long lPush(final String key, final String... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long lPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long lPushX(final String key, final String... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long lPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } + } + + @Override + public String rPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] rPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + } + } + + @Override + public String rPoplPush(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + } + } + + @Override + public byte[] rPoplPush(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + } + } + + @Override + public Long rPush(final String key, final String... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long rPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long rPushX(final String key, final String... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long rPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelPubSubOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelPubSubOperations.java new file mode 100644 index 000000000..41f321215 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelPubSubOperations.java @@ -0,0 +1,413 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.MapConverter; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.PubSubListener; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.pubsub.jedis.DefaultBinaryJedisPubSub; +import com.buession.redis.pubsub.jedis.DefaultJedisPubSub; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 哨兵模式 Pub/Sub 命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelPubSubOperations extends AbstractPubSubOperations { + + public JedisSentinelPubSubOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, Command.PSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, Command.PSUBSCRIBE) + .run(args); + }else{ + new JedisSentinelCommand<>(client, Command.PSUBSCRIBE, (cmd)->{ + cmd.psubscribe(new DefaultJedisPubSub(pubSubListener), patterns); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, Command.PSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, Command.PSUBSCRIBE) + .run(args); + }else{ + new JedisSentinelCommand<>(client, Command.PSUBSCRIBE, (cmd)->{ + cmd.psubscribe(new DefaultBinaryJedisPubSub(pubSubListener), patterns); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public Long publish(final String channel, final String message) { + final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PUBLISH, + (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.PUBLISH) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + } + } + + @Override + public Long publish(final byte[] channel, final byte[] message) { + final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PUBLISH, + (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.PUBLISH) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + } + } + + @Override + public List pubsubChannels() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.PUBSUB_CHANNELS) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + Command.PUBSUB_CHANNELS) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(), + (v)->v) + .run(); + } + } + + @Override + public List pubsubChannels(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return pubsubChannels(pattern, (v)->v, args); + } + + @Override + public List pubsubChannels(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final String sPattern = SafeEncoder.encode(pattern); + final com.buession.core.converter.ListConverter stringToBinaryListConverter = + Converters.listStringToBinary(); + + return pubsubChannels(sPattern, stringToBinaryListConverter, args); + } + + @Override + public List pubsubShardChannels() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, + Command.PUBSUB_SHARDCHANNELS) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + Command.PUBSUB_SHARDCHANNELS) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.PUBSUB_SHARDCHANNELS, + (cmd)->cmd.pubsubShardChannels(), (v)->v) + .run(); + } + } + + @Override + public List pubsubShardChannels(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return pubsubShardChannels(pattern, (v)->v, args); + } + + @Override + public List pubsubShardChannels(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final String sPattern = SafeEncoder.encode(pattern); + final com.buession.core.converter.ListConverter stringToBinaryListConverter = + Converters.listStringToBinary(); + + return pubsubShardChannels(sPattern, stringToBinaryListConverter, args); + } + + @Override + public Long pubsubNumPat() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.PUBSUB_NUMPAT) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.PUBSUB_NUMPAT) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.PUBSUB_NUMPAT, (cmd)->cmd.pubsubNumPat(), (v)->v) + .run(); + } + } + + @Override + public Map pubsubNumSub() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, Map>(client, + Command.PUBSUB_NUMSUB) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, Map>(client, + Command.PUBSUB_NUMSUB) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.PUBSUB_NUMSUB, (cmd)->cmd.pubsubNumSub(), + (v)->v) + .run(); + } + } + + @Override + public Map pubsubNumSub(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return pubsubNumSub(channels, (v)->v, args); + } + + @Override + public Map pubsubNumSub(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + final String[] sChannels = SafeEncoder.encode(channels); + final MapConverter stringToBinaryKeyPrimitiveValueMapConverter = + new MapConverter<>(SafeEncoder::encode, (v)->v); + + return pubsubNumSub(sChannels, stringToBinaryKeyPrimitiveValueMapConverter, args); + } + + @Override + public Map pubsubShardNumSub() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, Map>(client, + Command.PUBSUB_SHARDNUMSUB) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, Map>(client, + Command.PUBSUB_SHARDNUMSUB) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.PUBSUB_SHARDNUMSUB, + (cmd)->cmd.pubsubShardNumSub(), (v)->v) + .run(); + } + } + + @Override + public Map pubsubShardNumSub(final String... shardChannels) { + final CommandArguments args = CommandArguments.create("shardChannels", (Object[]) shardChannels); + return pubsubShardNumSub(shardChannels, (v)->v, args); + } + + @Override + public Map pubsubShardNumSub(final byte[]... shardChannels) { + final CommandArguments args = CommandArguments.create("shardChannels", (Object[]) shardChannels); + final String[] sChannels = SafeEncoder.encode(shardChannels); + final MapConverter stringToBinaryKeyPrimitiveValueMapConverter = + new MapConverter<>(SafeEncoder::encode, (v)->v); + + return pubsubShardNumSub(sChannels, stringToBinaryKeyPrimitiveValueMapConverter, args); + } + + @Override + public Object pUnSubscribe() { + return notCommand(client, Command.PUNSUBSCRIBE); + } + + @Override + public Object pUnSubscribe(final String... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return notCommand(client, Command.PUNSUBSCRIBE, args); + } + + @Override + public Object pUnSubscribe(final byte[]... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return notCommand(client, Command.PUNSUBSCRIBE, args); + } + + @Override + public void subscribe(final String[] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, Command.SUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, Command.SUBSCRIBE) + .run(args); + }else{ + new JedisSentinelCommand<>(client, Command.SUBSCRIBE, (cmd)->{ + cmd.subscribe(new DefaultJedisPubSub(pubSubListener), channels); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public void subscribe(final byte[][] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, Command.SUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, Command.SUBSCRIBE) + .run(args); + }else{ + new JedisSentinelCommand<>(client, Command.SUBSCRIBE, (cmd)->{ + cmd.subscribe(new DefaultBinaryJedisPubSub(pubSubListener), channels); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public Object unSubscribe() { + return notCommand(client, Command.UNSUBSCRIBE); + } + + @Override + public Object unSubscribe(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return notCommand(client, Command.UNSUBSCRIBE, args); + } + + @Override + public Object unSubscribe(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return notCommand(client, Command.UNSUBSCRIBE, args); + } + + private List pubsubChannels(final String pattern, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.PUBSUB_CHANNELS) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, Command.PUBSUB_CHANNELS) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(pattern), converter) + .run(); + } + } + + private List pubsubShardChannels(final String pattern, + final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.PUBSUB_SHARDCHANNELS) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, Command.PUBSUB_SHARDCHANNELS) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PUBSUB_SHARDCHANNELS, + (cmd)->cmd.pubsubShardChannels(pattern), converter) + .run(); + } + } + + private Map pubsubNumSub(final String[] channels, + final Converter, Map> converter, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, Map>(client, Command.PUBSUB_NUMSUB) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, Map>(client, + Command.PUBSUB_NUMSUB) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PUBSUB_NUMSUB, (cmd)->cmd.pubsubNumSub(channels), + converter) + .run(args); + } + } + + private Map pubsubShardNumSub(final String[] shardChannels, + final Converter, Map> converter, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, Map>(client, Command.PUBSUB_NUMSUB) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, Map>(client, + Command.PUBSUB_NUMSUB) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PUBSUB_NUMSUB, + (cmd)->cmd.pubsubShardNumSub(shardChannels), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelScriptingOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelScriptingOperations.java new file mode 100644 index 000000000..9e60e1df0 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelScriptingOperations.java @@ -0,0 +1,415 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.jedis.params.FlushModeConverter; + +import java.util.Arrays; +import java.util.List; + +/** + * Jedis 哨兵模式 Script 命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelScriptingOperations extends AbstractScriptingOperations { + + public JedisSentinelScriptingOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public Object eval(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final byte[] script) { + final CommandArguments args = CommandArguments.create("script", script); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final String script, final String... params) { + final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + final int paramsSize = params == null ? 0 : params.length; + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script, paramsSize, params), + (v)->v) + .run(args); + } + } + + @Override + public Object eval(final byte[] script, final byte[]... params) { + final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + final int paramsSize = params == null ? 0 : params.length; + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EVAL, (cmd)->cmd.eval(script, paramsSize, params), + (v)->v) + .run(args); + } + } + + @Override + public Object eval(final String script, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments) { + final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final String digest) { + final CommandArguments args = CommandArguments.create("digest", digest); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final byte[] digest) { + final CommandArguments args = CommandArguments.create("digest", digest); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final String digest, final String... params) { + final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); + final int paramsSize = params == null ? 0 : params.length; + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final byte[] digest, final byte[]... params) { + final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); + final int paramsSize = params == null ? 0 : params.length; + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final String digest, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final byte[] digest, final byte[][] keys, final byte[][] arguments) { + final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + } + } + + @Override + public List scriptExists(final String... sha1) { + final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), + (v)->v) + .run(args); + } + } + + @Override + public List scriptExists(final byte[]... sha1) { + final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), + (v)->v) + .run(args); + } + } + + @Override + public Status scriptFlush() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null), okStatusConverter) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(); + } + } + + @Override + public Status scriptFlush(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + final redis.clients.jedis.args.FlushMode flushMode = (new FlushModeConverter()).convert(mode); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null, flushMode), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null, flushMode), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(flushMode), + okStatusConverter) + .run(args); + } + } + + @Override + public String scriptLoad(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), + (v)->v) + .run(args); + } + } + + @Override + public byte[] scriptLoad(final byte[] script) { + final CommandArguments args = CommandArguments.create("script", script); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), + (v)->v) + .run(args); + } + } + + @Override + public Status scriptKill() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SCRIPT_KILL, + (cmd)->cmd.scriptKill((String) null), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SCRIPT_KILL, + (cmd)->cmd.scriptKill((String) null), okStatusConverter) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelServerOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelServerOperations.java new file mode 100644 index 000000000..6b201385f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelServerOperations.java @@ -0,0 +1,851 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.Info; +import com.buession.redis.core.MemoryStats; +import com.buession.redis.core.Module; +import com.buession.redis.core.RedisMonitor; +import com.buession.redis.core.RedisServerTime; +import com.buession.redis.core.Role; +import com.buession.redis.core.SlowLog; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.jedis.params.FlushModeConverter; +import com.buession.redis.core.internal.convert.jedis.response.MemoryStatsConverter; +import com.buession.redis.core.internal.convert.response.InfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.ModuleConverter; +import com.buession.redis.core.internal.convert.jedis.response.RedisServerTimeConverter; +import com.buession.redis.core.internal.convert.jedis.response.SlowlogConverter; +import com.buession.redis.core.internal.convert.jedis.response.RoleConverter; +import com.buession.redis.core.internal.jedis.JedisFailoverParams; +import redis.clients.jedis.JedisMonitor; +import redis.clients.jedis.args.SaveMode; +import redis.clients.jedis.params.FailoverParams; +import redis.clients.jedis.resps.Slowlog; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 哨兵模式服务端命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelServerOperations extends AbstractServerOperations { + + public JedisSentinelServerOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public String bgRewriteAof() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.BGREWRITEAOF) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.BGREWRITEAOF) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.BGREWRITEAOF, (cmd)->cmd.bgrewriteaof(), (v)->v) + .run(); + } + } + + @Override + public String bgSave() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.BGSAVE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.BGSAVE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.BGSAVE, (cmd)->cmd.bgsave(), (v)->v) + .run(); + } + } + + @Override + public Status configSet(final String parameter, final String value) { + final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CONFIG_SET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CONFIG_SET, + (cmd)->cmd.configSet(parameter, value), okStatusConverter) + .run(args); + } + } + + @Override + public Status configSet(final byte[] parameter, final byte[] value) { + final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CONFIG_SET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CONFIG_SET, + (cmd)->cmd.configSet(parameter, value), okStatusConverter) + .run(args); + } + } + + @Override + public Status configSet(final Map configs) { + final CommandArguments args = CommandArguments.create("configs", configs); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CONFIG_SET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CONFIG_SET, (cmd)->{ + configs.forEach(cmd::configSet); + return Status.SUCCESS; + }, (v)->v) + .run(args); + } + } + + @Override + public Map configGet(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, Map>(client, + Command.CONFIG_GET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, Map>(client, + Command.CONFIG_GET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CONFIG_GET, (cmd)->cmd.configGet(pattern), + (v)->v) + .run(args); + } + } + + @Override + public Map configGet(final byte[] parameter) { + final CommandArguments args = CommandArguments.create("parameter", parameter); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, Map>(client, + Command.CONFIG_GET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, Map>(client, + Command.CONFIG_GET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.CONFIG_GET, (cmd)->cmd.configGet(parameter), + (v)->v) + .run(args); + } + } + + @Override + public Status configResetStat() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CONFIG_RESETSTAT) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CONFIG_RESETSTAT) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CONFIG_RESETSTAT, (cmd)->cmd.configResetStat(), + okStatusConverter) + .run(); + } + } + + @Override + public Status configRewrite() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.CONFIG_REWRITE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.CONFIG_REWRITE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.CONFIG_REWRITE, (cmd)->cmd.configRewrite(), + okStatusConverter) + .run(); + } + } + + @Override + public Long dbSize() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.DBSIZE, (cmd)->cmd.dbSize(), (v)->v) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.DBSIZE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.DBSIZE, (cmd)->cmd.dbSize(), (v)->v) + .run(); + } + } + + @Override + public Status failover() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.FAILOVER) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.FAILOVER) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.FAILOVER, (cmd)->cmd.failover(), + okStatusConverter) + .run(); + } + } + + @Override + public Status failover(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + final FailoverParams failoverParams = new JedisFailoverParams(host, port); + + return failover(failoverParams, args); + } + + @Override + public Status failover(final String host, final int port, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("timeout", timeout); + final FailoverParams failoverParams = new JedisFailoverParams(host, port, timeout); + + return failover(failoverParams, args); + } + + @Override + public Status failover(final String host, final int port, final boolean isForce, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("isForce", isForce) + .put("timeout", timeout); + final FailoverParams failoverParams = new JedisFailoverParams(host, port, timeout, isForce); + + return failover(failoverParams, args); + } + + @Override + public Status failover(final int timeout) { + final CommandArguments args = CommandArguments.create("timeout", timeout); + final FailoverParams failoverParams = new JedisFailoverParams(timeout); + + return failover(failoverParams, args); + } + + @Override + public Status flushAll() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.FLUSHALL) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.FLUSHALL) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.FLUSHALL, (cmd)->cmd.flushAll(), + okStatusConverter) + .run(); + } + } + + @Override + public Status flushAll(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + final redis.clients.jedis.args.FlushMode flushMode = (new FlushModeConverter()).convert(mode); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.FLUSHALL) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.FLUSHALL) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.FLUSHALL, (cmd)->cmd.flushAll(flushMode), + okStatusConverter) + .run(args); + } + } + + @Override + public Status flushDb() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.FLUSHDB) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.FLUSHDB) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.FLUSHDB, (cmd)->cmd.flushDB(), okStatusConverter) + .run(); + } + } + + @Override + public Status flushDb(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + final redis.clients.jedis.args.FlushMode flushMode = (new FlushModeConverter()).convert(mode); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.FLUSHDB) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.FLUSHDB) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.FLUSHDB, (cmd)->cmd.flushDB(flushMode), + okStatusConverter) + .run(args); + } + } + + @Override + public Info info() { + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.INFO) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.INFO) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.INFO, (cmd)->cmd.info(), infoConverter) + .run(); + } + } + + @Override + public Info info(final Info.Section section) { + final CommandArguments args = CommandArguments.create("section", section); + final String sectionName = section.name().toLowerCase(); + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.INFO) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.INFO) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.INFO, (cmd)->cmd.info(sectionName), infoConverter) + .run(args); + } + } + + @Override + public Long lastSave() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.LASTSAVE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.LASTSAVE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.LASTSAVE, (cmd)->cmd.lastsave(), (v)->v) + .run(); + } + } + + @Override + public String memoryDoctor() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.MEMORY_DOCTOR) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.MEMORY_DOCTOR) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.MEMORY_DOCTOR, (cmd)->cmd.memoryDoctor(), (v)->v) + .run(); + } + } + + @Override + public Status memoryPurge() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.MEMORY_PURGE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.MEMORY_PURGE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.MEMORY_PURGE, (cmd)->cmd.memoryPurge(), + okStatusConverter) + .run(); + } + } + + @Override + public MemoryStats memoryStats() { + final MemoryStatsConverter memoryStatsConverter = new MemoryStatsConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.MEMORY_STATS) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.MEMORY_STATS) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.MEMORY_STATS, (cmd)->cmd.memoryStats(), + memoryStatsConverter) + .run(); + } + } + + @Override + public Long memoryUsage(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } + } + + @Override + public Long memoryUsage(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } + } + + @Override + public Long memoryUsage(final String key, final int samples) { + final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + } + } + + @Override + public Long memoryUsage(final byte[] key, final int samples) { + final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + } + } + + @Override + public List moduleList() { + final ListConverter listModuleConverter = ModuleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.MODULE_LIST) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, Command.MODULE_LIST) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.MODULE_LIST, (cmd)->cmd.moduleList(), + listModuleConverter) + .run(); + } + } + + @Override + public Status moduleLoad(final String path) { + final CommandArguments args = CommandArguments.create("path", path); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.MODULE_LOAD) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.MODULE_LOAD) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.MODULE_LOAD, (cmd)->cmd.moduleLoad(path), + okStatusConverter) + .run(args); + } + } + + @Override + public Status moduleLoad(final String path, final String... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.MODULE_LOAD) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.MODULE_LOAD) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.MODULE_LOAD, + (cmd)->cmd.moduleLoad(path, arguments), okStatusConverter) + .run(args); + } + } + + @Override + public Status moduleUnLoad(final String name) { + final CommandArguments args = CommandArguments.create("name", name); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.MODULE_UNLOAD) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.MODULE_UNLOAD) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.MODULE_UNLOAD, (cmd)->cmd.moduleUnload(name), + okStatusConverter) + .run(args); + } + } + + @Override + public void monitor(final RedisMonitor redisMonitor) { + final CommandArguments args = CommandArguments.create("redisMonitor", redisMonitor); + + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, Command.MONITOR) + .run(args); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, Command.MONITOR) + .run(args); + }else{ + new JedisSentinelCommand<>(client, Command.MONITOR, (cmd)->{ + cmd.monitor(new JedisMonitor() { + + @Override + public void onCommand(final String command) { + redisMonitor.onCommand(command); + } + + }); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public Object pSync(final String replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return notCommand(client, Command.PSYNC, args); + } + + @Override + public Object pSync(final byte[] replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return notCommand(client, Command.PSYNC, args); + } + + @Override + public void sync() { + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, Command.SYNC, (cmd)->{ + cmd.sync(); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, Command.SYNC) + .run(); + }else{ + new JedisSentinelCommand<>(client, Command.SYNC) + .run(); + } + } + + @Override + public Status replicaOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.REPLICAOF) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.REPLICAOF) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.REPLICAOF, (cmd)->cmd.replicaof(host, port), + okStatusConverter) + .run(args); + } + } + + @Override + public Status slaveOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.SLAVEOF) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.SLAVEOF) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SLAVEOF, (cmd)->cmd.slaveof(host, port), + okStatusConverter) + .run(args); + } + } + + @Override + public Role role() { + final RoleConverter roleConverter = new RoleConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.ROLE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.ROLE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.ROLE, (cmd)->cmd.role(), roleConverter) + .run(); + } + } + + @Override + public Status save() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.SAVE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.SAVE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.SAVE, (cmd)->cmd.save(), okStatusConverter) + .run(); + } + } + + @Override + public void shutdown() { + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, Command.SHUTDOWN) + .run(); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, Command.SHUTDOWN) + .run(); + }else{ + new JedisSentinelCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(); + return null; + }, (v)->v) + .run(); + } + } + + @Override + public void shutdown(final boolean save) { + final CommandArguments args = CommandArguments.create("save", save); + final SaveMode saveMode = save ? SaveMode.SAVE : SaveMode.NOSAVE; + + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, Command.SHUTDOWN) + .run(); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, Command.SHUTDOWN) + .run(); + }else{ + new JedisSentinelCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(saveMode); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public List slowLogGet() { + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.SLOWLOG_GET) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + Command.SLOWLOG_GET) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + } + } + + @Override + public List slowLogGet(final int count) { + final CommandArguments args = CommandArguments.create("count", count); + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, Command.SLOWLOG_GET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + Command.SLOWLOG_GET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SLOWLOG_GET, (cmd)->cmd.slowlogGet(count), + listSlowlogConverter) + .run(args); + } + } + + @Override + public Long slowLogLen() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.SLOWLOG_LEN) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.SLOWLOG_LEN) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.SLOWLOG_RESET, (cmd)->cmd.slowlogLen(), (v)->v) + .run(); + } + } + + @Override + public Status slowLogReset() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.SLOWLOG_RESET) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.SLOWLOG_RESET) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + } + } + + @Override + public Status swapdb(final int db1, final int db2) { + final CommandArguments args = CommandArguments.create("db1", db1).put("db2", db2); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SWAPDB, (cmd)->cmd.swapDB(db1, db2), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.SWAPDB) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SWAPDB, (cmd)->cmd.swapDB(db1, db2), + okStatusConverter) + .run(args); + } + } + + @Override + public RedisServerTime time() { + final RedisServerTimeConverter redisServerTimeConverter = new RedisServerTimeConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.TIME, (cmd)->cmd.time(), + redisServerTimeConverter) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.TIME) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.TIME, (cmd)->cmd.time(), redisServerTimeConverter) + .run(); + } + } + + private Status failover(final FailoverParams failoverParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.FAILOVER) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, Command.FAILOVER) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.FAILOVER, (cmd)->cmd.failover(failoverParams), + okStatusConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelSetOperations.java new file mode 100644 index 000000000..a295ab60f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelSetOperations.java @@ -0,0 +1,796 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; +import com.buession.redis.core.internal.jedis.JedisScanParams; +import redis.clients.jedis.params.ScanParams; + +import java.util.List; +import java.util.Set; + +/** + * Jedis 哨兵模式集合命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelSetOperations extends AbstractSetOperations { + + public JedisSentinelSetOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public Long sAdd(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long sAdd(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long sCard(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } + } + + @Override + public Long sCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } + } + + @Override + public Set sDiff(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + } + } + + @Override + public Set sDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + } + } + + @Override + public Long sDiffStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long sDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Set sInter(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + } + } + + @Override + public Set sInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + } + } + + @Override + public Long sInterStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long sInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Boolean sIsMember(final String key, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + } + } + + @Override + public Boolean sIsMember(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + } + } + + @Override + public List smIsMember(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SMISMEMBER, (cmd)->cmd.smismember(key, members), + (v)->v) + .run(args); + } + } + + @Override + public List smIsMember(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SMISMEMBER, (cmd)->cmd.smismember(key, members), + (v)->v) + .run(args); + } + } + + @Override + public Set sMembers(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + } + } + + @Override + public Set sMembers(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + } + } + + @Override + public Status sMove(final String key, final String destKey, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status sMove(final byte[] key, final byte[] destKey, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + } + } + + @Override + public String sPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] sPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + } + } + + @Override + public Set sPop(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + } + } + + @Override + public Set sPop(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + } + } + + @Override + public String sRandMember(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] sRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + } + } + + @Override + public List sRandMember(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + } + } + + @Override + public List sRandMember(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + } + } + + @Override + public Long sRem(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long sRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } + } + + @Override + public ScanResult> sScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanParams scanParams = new JedisScanParams(count); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanParams scanParams = new JedisScanParams(count); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public Set sUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + } + } + + @Override + public Set sUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + } + } + + @Override + public Long sUnionStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Long sUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + } + } + + private ScanResult> sScan(final String key, final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelSortedSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelSortedSetOperations.java new file mode 100644 index 000000000..2e40283c1 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelSortedSetOperations.java @@ -0,0 +1,2711 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.NumberUtils; +import com.buession.lang.KeyValue; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.Aggregate; +import com.buession.redis.core.GtLt; +import com.buession.redis.core.NxXx; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; +import com.buession.redis.core.ZRangeBy; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.jedis.response.KeyValueConverter; +import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; +import com.buession.redis.core.internal.convert.jedis.response.TupleConverter; +import com.buession.redis.core.internal.jedis.JedisScanParams; +import com.buession.redis.core.internal.jedis.JedisZAddParams; +import com.buession.redis.core.internal.jedis.JedisZParams; +import com.buession.redis.core.internal.jedis.JedisZRangeParams; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.params.ZAddParams; +import redis.clients.jedis.params.ZParams; +import redis.clients.jedis.params.ZRangeParams; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 哨兵模式模式有序集合命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelSortedSetOperations extends AbstractSortedSetOperations { + + public JedisSentinelSortedSetOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public Tuple zPopMin(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + } + } + + @Override + public Tuple zPopMin(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + } + } + + @Override + public List zPopMin(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + } + } + + @Override + public List zPopMin(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + } + } + + @Override + public Tuple zPopMax(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + } + } + + @Override + public Tuple zPopMax(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + } + } + + @Override + public List zPopMax(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + } + } + + @Override + public List zPopMax(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMin(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMin(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public Long zAdd(final String key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long zAdd(final byte[] key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddParams zAddParams = new JedisZAddParams(nxXx); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddParams zAddParams = new JedisZAddParams(nxXx); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddParams zAddParams = new JedisZAddParams(gtLt); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddParams zAddParams = new JedisZAddParams(gtLt); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(gtLt, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(gtLt, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zCard(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } + } + + @Override + public Long zCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } + } + + @Override + public Long zCount(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZCOUNT, + (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public Long zCount(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZCOUNT, + (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zDiff(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + } + } + + @Override + public List zDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + } + } + + @Override + public List zDiffWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZDIFF, + (cmd)->cmd.zdiffWithScores(keys), listConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + } + } + + @Override + public List zDiffWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZDIFF, + (cmd)->cmd.zdiffWithScores(keys), listConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + } + } + + @Override + public Long zDiffStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Double zIncrBy(final String key, final double increment, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) + .put("member", member); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + } + } + + @Override + public Double zIncrBy(final byte[] key, final double increment, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) + .put("member", member); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + } + } + + @Override + public List zInter(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInter(keys, zParams, args); + } + + @Override + public List zInterWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public Long zInterStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zLexCount(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zLexCount(key, sMin, sMax, args); + } + + @Override + public Long zLexCount(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zLexCount(key, bMin, bMax, args); + } + + @Override + public List zMScore(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZMSCORE, (cmd)->cmd.zmscore(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZMSCORE, + (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + } + } + + @Override + public List zMScore(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZMSCORE, (cmd)->cmd.zmscore(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZMSCORE, + (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + } + } + + @Override + public String zRandMember(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] zRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + } + } + + @Override + public List zRandMember(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), + (v)->v) + .run(args); + } + } + + @Override + public List zRandMember(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), + (v)->v) + .run(args); + } + } + + @Override + public List zRandMemberWithScores(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + } + } + + @Override + public List zRandMemberWithScores(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + } + } + + @Override + public List zRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public List zRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public List zRangeWithScores(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } + } + + @Override + public List zRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } + } + + @Override + public List zRangeByLex(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zRangeByLex(key, sMin, sMax, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, args); + } + + @Override + public List zRangeByLex(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zRangeByLex(key, sMin, sMax, offset, count, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, offset, count, args); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zRangeByScore(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRank(final String key, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public Long zRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public Long zRem(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long zRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByRank(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByRank(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List zRevRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public List zRevRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public List zRevRangeWithScores(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } + } + + @Override + public List zRevRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final String key, final double min, final double max, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } + } + + @Override + public Long zRevRank(final String key, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + } + } + + @Override + public Long zRevRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + } + } + + @Override + public ScanResult> zScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanParams scanParams = new JedisScanParams(count); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanParams scanParams = new JedisScanParams(count); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public Double zScore(final String key, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } + } + + @Override + public Double zScore(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } + } + + @Override + public List zUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public Long zUnionStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionStore(destKey, keys, zParams, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionStore(destKey, keys, zParams, args); + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnionStore(destKey, keys, zParams, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnionStore(destKey, keys, zParams, args); + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionStore(destKey, keys, zParams, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionStore(destKey, keys, zParams, args); + } + + private Long zAdd(final String key, final Map members, final ZAddParams zAddParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), + (v)->v) + .run(args); + } + } + + private Long zAdd(final byte[] key, final Map members, final ZAddParams zAddParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), + (v)->v) + .run(args); + } + } + + private List zInter(final String[] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZINTER, (cmd)->cmd.zinter(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + } + } + + private List zInter(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZINTER, (cmd)->cmd.zinter(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + } + } + + private List zInterWithScores(final String[] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private List zInterWithScores(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private Long zInterStore(final String destKey, final String[] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zInterStore(final byte[] destKey, final byte[][] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zLexCount(final String key, final String min, final String max, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + } + } + + private Long zLexCount(final byte[] key, final byte[] min, final byte[] max, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + } + } + + private List zRangeByLex(final String key, final String min, final String max, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + } + } + + private List zRangeByLex(final String key, final String min, final String max, final long offset, + final int count, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final int count, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + private Long zRangeStore(final String destKey, final String key, final ZRangeParams zRangeParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + } + } + + private Long zRangeStore(final byte[] destKey, final byte[] key, final ZRangeParams zRangeParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + } + } + + private ScanResult> zScan(final String key, final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + } + } + + private List zUnion(final String[] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZUNION, (cmd)->cmd.zunion(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + } + } + + private List zUnion(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZUNION, (cmd)->cmd.zunion(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + } + } + + private List zUnionWithScores(final String[] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + } + } + + private List zUnionWithScores(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + } + } + + private Long zUnionStore(final String destKey, final String[] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zUnionStore(final byte[] destKey, final byte[][] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelStreamOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelStreamOperations.java new file mode 100644 index 000000000..e329a21ce --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelStreamOperations.java @@ -0,0 +1,1137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapEntryMapConverter; +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.Stream; +import com.buession.redis.core.StreamConsumer; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import com.buession.redis.core.StreamGroup; +import com.buession.redis.core.StreamPending; +import com.buession.redis.core.StreamPendingSummary; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.XAddArgument; +import com.buession.redis.core.command.args.XClaimArgument; +import com.buession.redis.core.command.args.XReadArgument; +import com.buession.redis.core.command.args.XReadGroupArgument; +import com.buession.redis.core.command.args.XTrimArgument; +import com.buession.redis.core.internal.convert.jedis.params.StreamEntryIdConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamConsumersInfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamEntryConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamEntryIDConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamFullInfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamGroupInfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamInfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamPendingEntryConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamPendingSummaryConverter; +import com.buession.redis.core.internal.jedis.JedisStreamEntryID; +import com.buession.redis.core.internal.jedis.JedisXAddParams; +import com.buession.redis.core.internal.jedis.JedisXAutoClaimParams; +import com.buession.redis.core.internal.jedis.JedisXClaimParams; +import com.buession.redis.core.internal.jedis.JedisXPendingParams; +import com.buession.redis.core.internal.jedis.JedisXReadGroupParams; +import com.buession.redis.core.internal.jedis.JedisXReadParams; +import com.buession.redis.core.internal.jedis.JedisXTrimParams; +import redis.clients.jedis.StreamEntryID; +import redis.clients.jedis.params.XAddParams; +import redis.clients.jedis.params.XAutoClaimParams; +import redis.clients.jedis.params.XClaimParams; +import redis.clients.jedis.params.XPendingParams; +import redis.clients.jedis.params.XReadGroupParams; +import redis.clients.jedis.params.XReadParams; +import redis.clients.jedis.params.XTrimParams; +import redis.clients.jedis.resps.StreamConsumersInfo; +import redis.clients.jedis.resps.StreamGroupInfo; +import redis.clients.jedis.resps.StreamPendingEntry; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 哨兵模式 Stream 命令操作抽象类 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelStreamOperations extends AbstractStreamOperations { + + public JedisSentinelStreamOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public Long xAck(final String key, final String groupName, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("ids", (Object[]) ids); + final StreamEntryID[] streamEntryIDS = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + } + } + + @Override + public Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("ids", (Object[]) ids); + final byte[][] streamEntryIDS = StreamEntryIdConverter.binaryArrayConverter().convert(ids); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + } + } + + @Override + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XADD, + (cmd)->cmd.xadd(key, streamEntryID, hash), streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XADD, + (cmd)->cmd.xadd(key, streamEntryID, hash), streamEntryIDConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, streamEntryID, hash), + streamEntryIDConverter) + .run(args); + } + } + + @Override + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) + .put("xAddArgument", xAddArgument); + final XAddParams xAddParams = JedisXAddParams.from(xAddArgument).id(id); + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), streamEntryIDConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + streamEntryIDConverter) + .run(args); + } + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) + .put("xAddArgument", xAddArgument); + final XAddParams xAddParams = JedisXAddParams.from(xAddArgument).id(id); + final StreamEntryIDConverter.BinaryStreamEntryIdConverter binaryStreamEntryIdConverter = + new StreamEntryIDConverter.BinaryStreamEntryIdConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), binaryStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), binaryStreamEntryIdConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + binaryStreamEntryIdConverter) + .run(args); + } + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(count); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(count); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count"); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final XClaimParams xClaimParams = new JedisXClaimParams(); + + return xClaim(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); + } + + @Override + public List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final XClaimParams xClaimParams = JedisXClaimParams.from(xClaimArgument); + + return xClaim(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); + } + + @Override + public List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final XClaimParams xClaimParams = new JedisXClaimParams(); + + return xClaimJustId(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); + } + + @Override + public List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final XClaimParams xClaimParams = JedisXClaimParams.from(xClaimArgument); + + return xClaimJustId(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); + } + + @Override + public Long xDel(final String key, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("ids", (Object[]) ids); + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XDEL, + (cmd)->cmd.xdel(key, streamEntryIDs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XDEL, + (cmd)->cmd.xdel(key, streamEntryIDs), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XDEL, (cmd)->cmd.xdel(key, streamEntryIDs), + (v)->v) + .run(args); + } + } + + @Override + public Status xGroupCreate(final String key, final String groupName, final StreamEntryId id, + final boolean makeStream) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("id", id); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + } + } + + @Override + public Long xGroupDelConsumer(final String key, final String groupName, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + } + } + + @Override + public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + } + } + + @Override + public Status xGroupDestroy(final String key, final String groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupDestroy(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupSetId(final String key, final String groupName, final StreamEntryId id) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName).put("id", id); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + } + } + + @Override + public List xInfoConsumers(final String key, final String groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + final ListConverter listStreamConsumersInfoConverter = + StreamConsumersInfoConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + } + } + + @Override + public List xInfoGroups(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final ListConverter listStreamGroupInfoConverter = + StreamGroupInfoConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XINFO_GROUPS, + (cmd)->cmd.xinfoGroups(key), listStreamGroupInfoConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + } + } + + @Override + public Stream xInfoStream(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final StreamInfoConverter streamInfoConverter = new StreamInfoConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStream(key), streamInfoConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamInfoConverter) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final String key, final boolean full) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key), streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key), streamFullInfoConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStreamFull(key), + streamFullInfoConverter) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final String key, final boolean full, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full).put("count", count); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + } + } + + @Override + public Long xLen(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } + } + + @Override + public Long xLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } + } + + @Override + public StreamPendingSummary xPending(final String key, final String groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + final StreamPendingSummaryConverter streamPendingSummaryConverter = new StreamPendingSummaryConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName), streamPendingSummaryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName), streamPendingSummaryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XPENDING, (cmd)->cmd.xpending(key, groupName), + streamPendingSummaryConverter) + .run(args); + } + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final StreamEntryId start, + final StreamEntryId end, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("start", start).put("end", end).put("count", count); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final XPendingParams xPendingParams = new JedisXPendingParams(consumerName); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("start", start).put("end", end).put("count", count); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count, minIdleTime); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime, consumerName); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final StreamEntryId start, + final StreamEntryId end, final int count, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count, consumerName); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count, + final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count, minIdleTime, consumerName); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, startID, endID), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, startID, endID), listStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, startID, endID), listStreamEntryConverter) + .run(args); + } + } + + @Override + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, startID, endID, (int) count), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, startID, endID, (int) count), listStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, startID, endID, (int) count), listStreamEntryConverter) + .run(args); + } + } + + @Override + public List>> xRead(final Map streams) { + final CommandArguments args = CommandArguments.create("streams", streams); + final XReadParams xReadParams = new JedisXReadParams(); + + return xRead(streams, xReadParams, args); + } + + @Override + public List>> xRead(final Map streams, + final XReadArgument xReadArgument) { + final CommandArguments args = CommandArguments.create("streams", streams).put("xReadArgument", xReadArgument); + final XReadParams xReadParams = JedisXReadParams.from(xReadArgument); + + return xRead(streams, xReadParams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadGroupParams xReadGroupParams = JedisXReadGroupParams.from(xReadGroupArgument); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadGroupParams xReadGroupParams = JedisXReadGroupParams.from(xReadGroupArgument); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); + } + + @Override + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), listStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), listStreamEntryConverter) + .run(args); + } + } + + @Override + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start) + .put("count", count); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + } + } + + @Override + public Long xTrim(final String key, final XTrimArgument xTrimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument); + + return xTrim(key, xTrimParams, args); + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument); + + return xTrim(key, xTrimParams, args); + } + + @Override + public Long xTrim(final String key, final XTrimArgument xTrimArgument, final long limit) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) + .put("limit", limit); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument).limit(limit); + + return xTrim(key, xTrimParams, args); + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) + .put("limit", limit); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument).limit(limit); + + return xTrim(key, xTrimParams, args); + } + + private Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, + final XAutoClaimParams xAutoClaimParams, + final CommandArguments args) { + final StreamEntryID startID = JedisStreamEntryID.from(start); + final StreamEntryConverter.MapEntryStreamEntryConverter mapEntryStreamEntryConverter = + new StreamEntryConverter.MapEntryStreamEntryConverter<>(new StreamEntryIDConverter()); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + mapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + mapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + mapEntryStreamEntryConverter) + .run(args); + } + } + + private Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, + final XAutoClaimParams xAutoClaimParams, + final CommandArguments args) { + final byte[] startID = start.getRaw(); + final StreamEntryConverter.MapEntryStreamEntryConverter mapEntryStreamEntryConverter = + new StreamEntryConverter.MapEntryStreamEntryConverter<>(new StreamEntryIDConverter()); + final Converter, Map>> converter = null; + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + converter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + converter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + converter) + .run(args); + } + } + + private Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, + final XAutoClaimParams xAutoClaimParams, + final CommandArguments args) { + final StreamEntryID startID = JedisStreamEntryID.from(start); + final MapEntryMapConverter, StreamEntryId, List> mapEntryStreamEntryIdConverter = StreamEntryIDConverter.mapEntryMapConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams) + , mapEntryStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams) + , mapEntryStreamEntryIdConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams) + , mapEntryStreamEntryIdConverter) + .run(args); + } + } + + private List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, final XClaimParams xClaimParams, + final CommandArguments args) { + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + } + } + + private List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimParams xClaimParams, final CommandArguments args) { + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter listStreamEntryIDConverter = StreamEntryIDConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + } + } + + private List xPending(final String key, final String groupName, + final XPendingParams xPendingParams, final CommandArguments args) { + final ListConverter listStreamPendingEntryConverter = + StreamPendingEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + } + } + + private List>> xRead(final Map streams, + final XReadParams xReadParams, final CommandArguments args) { + final Map stringStreamEntryIDMap = StreamEntryIdConverter.mapConverter().convert( + streams); + final StreamEntryConverter.ListMapEntryStreamEntryConverter listMapEntryStreamEntryConverter = + new StreamEntryConverter.ListMapEntryStreamEntryConverter<>((k)->k); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadGroupParams xReadGroupParams, + final CommandArguments args) { + final Map stringStreamEntryIDMap = StreamEntryIdConverter.mapConverter().convert( + streams); + final StreamEntryConverter.ListMapEntryStreamEntryConverter listMapEntryStreamEntryConverter = + new StreamEntryConverter.ListMapEntryStreamEntryConverter<>((k)->k); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + } + } + + private Long xTrim(final String key, final XTrimParams xTrimParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XTRIM, + (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + } + } + + private Long xTrim(final byte[] key, final XTrimParams xTrimParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.XTRIM, + (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelStringOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelStringOperations.java new file mode 100644 index 000000000..2977c7a74 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelStringOperations.java @@ -0,0 +1,826 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.GetExArgument; +import com.buession.redis.core.command.args.SetArgument; +import com.buession.redis.core.internal.jedis.JedisGetExParams; +import com.buession.redis.core.internal.jedis.JedisSetParams; +import redis.clients.jedis.params.GetExParams; +import redis.clients.jedis.params.SetParams; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Jedis 哨兵模式字符串命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelStringOperations extends AbstractStringOperations { + + public JedisSentinelStringOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public Long append(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long append(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long incr(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } + } + + @Override + public Long incr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } + } + + @Override + public Long incrBy(final String key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long incrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + } + } + + @Override + public Double incrByFloat(final String key, final double value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), + (v)->v) + .run(args); + } + } + + @Override + public Double incrByFloat(final byte[] key, final double value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), + (v)->v) + .run(args); + } + } + + @Override + public Long decr(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } + } + + @Override + public Long decr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } + } + + @Override + public Long decrBy(final String key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long decrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + } + } + + @Override + public String get(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] get(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + } + } + + @Override + public String getEx(final String key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + final GetExParams getExParams = JedisGetExParams.from(getExArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GETEX, (cmd)->cmd.getEx(key, getExParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GETEX, + (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + } + } + + @Override + public byte[] getEx(final byte[] key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + final GetExParams getExParams = JedisGetExParams.from(getExArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GETEX, (cmd)->cmd.getEx(key, getExParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GETEX, + (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + } + } + + @Override + public String getSet(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + } + } + + @Override + public byte[] getSet(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + } + } + + @Override + public String getDel(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] getDel(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + } + } + + @Override + public List mGet(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + } + } + + @Override + public List mGet(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + } + } + + @Override + public Status mSet(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final List temp = new ArrayList<>(values.size() * 2); + + values.forEach((key, value)->{ + temp.add(key); + temp.add(value); + }); + + final String[] keysValues = temp.toArray(new String[0]); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + } + } + + @Override + public Status mSetNx(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final List temp = new ArrayList<>(values.size() * 2); + + values.forEach((key, value)->{ + temp.add(key); + temp.add(value); + }); + + final String[] keysValues = temp.toArray(new String[0]); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pSetEx(final String key, final String value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status pSetEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final String key, final String value, final SetArgument setArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final SetParams setParams = JedisSetParams.from(setArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SET, + (cmd)->cmd.set(key, value, setParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SET, + (cmd)->cmd.set(key, value, setParams), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value, final SetArgument setArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final SetParams setParams = JedisSetParams.from(setArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SET, + (cmd)->cmd.set(key, value, setParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SET, + (cmd)->cmd.set(key, value, setParams), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setEx(final String key, final String value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setNx(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status setNx(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + } + } + + @Override + public Long setRange(final String key, final long offset, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SETRANGE, (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + } + } + + @Override + public Long setRange(final byte[] key, final long offset, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SETRANGE, (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + } + } + + @Override + public String getRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public byte[] getRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public Long strlen(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } + } + + @Override + public Long strlen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } + } + + @Override + public String substr(final String key, final int start, final int end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SUBSTR, + (cmd)->cmd.substr(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SUBSTR, + (cmd)->cmd.substr(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SUBSTR, (cmd)->cmd.substr(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public byte[] substr(final byte[] key, final int start, final int end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.SUBSTR, + (cmd)->cmd.substr(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.SUBSTR, + (cmd)->cmd.substr(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.SUBSTR, (cmd)->cmd.substr(key, start, end), + (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelTransactionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelTransactionOperations.java new file mode 100644 index 000000000..7122053e8 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSentinelTransactionOperations.java @@ -0,0 +1,235 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import redis.clients.jedis.Builder; +import redis.clients.jedis.Response; + +import java.util.List; + +/** + * Jedis 哨兵模式事务命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSentinelTransactionOperations extends AbstractTransactionOperations { + + public JedisSentinelTransactionOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public Status multi() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.MULTI, (cmd)->{ + RedisConnection connection = client.getConnection(); + + return new Response<>(new Builder() { + + @Override + public Status build(Object data) { + try{ + connection.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; + } + } + + }); + }, (v)->v) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.MULTI, (cmd)->{ + RedisConnection connection = client.getConnection(); + + return new Response<>(new Builder() { + + @Override + public Status build(Object data) { + try{ + connection.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; + } + } + + }); + }, (v)->v) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.MULTI, (cmd)->{ + RedisConnection connection = client.getConnection(); + try{ + connection.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; + } + }, (v)->v) + .run(); + } + } + + @Override + public List exec() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, Command.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); + + return new Response<>(new Builder>() { + + @Override + public List build(Object data) { + return connection.exec(); + } + + }); + }, (v)->v).run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); + + return new Response<>(new Builder>() { + + @Override + public List build(Object data) { + return connection.exec(); + } + + }); + }, (v)->v).run(); + }else{ + return new JedisSentinelCommand<>(client, Command.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); + return connection.exec(); + }, (v)->v).run(); + } + } + + @Override + public void discard() { + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, Command.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, Command.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + }else{ + new JedisSentinelCommand<>(client, Command.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + } + } + + @Override + public Status watch(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.WATCH) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.WATCH, + (cmd)->new Response<>(new Builder() { + + @Override + public String build(Object data) { + return cmd.watch(keys); + } + + }), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.WATCH, (cmd)->cmd.watch(keys), okStatusConverter) + .run(args); + } + } + + @Override + public Status watch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.WATCH) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.WATCH, + (cmd)->new Response<>(new Builder() { + + @Override + public String build(Object data) { + return cmd.watch(keys); + } + + }), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, Command.WATCH, (cmd)->cmd.watch(keys), okStatusConverter) + .run(args); + } + } + + @Override + public Status unwatch() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, Command.UNWATCH) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, Command.UNWATCH, + (cmd)->new Response<>(new Builder() { + + @Override + public String build(Object data) { + return cmd.unwatch(); + } + + }), okStatusConverter) + .run(); + }else{ + return new JedisSentinelCommand<>(client, Command.UNWATCH, (cmd)->cmd.unwatch(), okStatusConverter) + .run(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisServerOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisServerOperations.java new file mode 100644 index 000000000..12b3dcd88 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisServerOperations.java @@ -0,0 +1,839 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.Info; +import com.buession.redis.core.MemoryStats; +import com.buession.redis.core.Module; +import com.buession.redis.core.RedisMonitor; +import com.buession.redis.core.RedisServerTime; +import com.buession.redis.core.Role; +import com.buession.redis.core.SlowLog; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.jedis.params.FlushModeConverter; +import com.buession.redis.core.internal.convert.jedis.response.MemoryStatsConverter; +import com.buession.redis.core.internal.convert.response.InfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.ModuleConverter; +import com.buession.redis.core.internal.convert.jedis.response.RedisServerTimeConverter; +import com.buession.redis.core.internal.convert.jedis.response.SlowlogConverter; +import com.buession.redis.core.internal.convert.jedis.response.RoleConverter; +import com.buession.redis.core.internal.jedis.JedisFailoverParams; +import redis.clients.jedis.JedisMonitor; +import redis.clients.jedis.args.SaveMode; +import redis.clients.jedis.params.FailoverParams; +import redis.clients.jedis.resps.Slowlog; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 单机模式服务端命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisServerOperations extends AbstractServerOperations { + + public JedisServerOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public String bgRewriteAof() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.BGREWRITEAOF) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.BGREWRITEAOF) + .run(); + }else{ + return new JedisCommand<>(client, Command.BGREWRITEAOF, (cmd)->cmd.bgrewriteaof(), (v)->v) + .run(); + } + } + + @Override + public String bgSave() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.BGSAVE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.BGSAVE) + .run(); + }else{ + return new JedisCommand<>(client, Command.BGSAVE, (cmd)->cmd.bgsave(), (v)->v) + .run(); + } + } + + @Override + public Status configSet(final String parameter, final String value) { + final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CONFIG_SET) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CONFIG_SET, (cmd)->cmd.configSet(parameter, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status configSet(final byte[] parameter, final byte[] value) { + final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CONFIG_SET) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CONFIG_SET, (cmd)->cmd.configSet(parameter, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status configSet(final Map configs) { + final CommandArguments args = CommandArguments.create("configs", configs); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CONFIG_SET) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CONFIG_SET, (cmd)->cmd.configSet(configs), + okStatusConverter) + .run(args); + } + } + + @Override + public Map configGet(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + + if(isPipeline()){ + return new JedisPipelineCommand, Map>(client, + Command.CONFIG_GET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, Map>(client, + Command.CONFIG_GET) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CONFIG_GET, (cmd)->cmd.configGet(pattern), (v)->v) + .run(args); + } + } + + @Override + public Map configGet(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + + if(isPipeline()){ + return new JedisPipelineCommand, Map>(client, + Command.CONFIG_GET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, Map>(client, + Command.CONFIG_GET) + .run(args); + }else{ + return new JedisCommand<>(client, Command.CONFIG_GET, (cmd)->cmd.configGet(pattern), (v)->v) + .run(args); + } + } + + @Override + public Status configResetStat() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CONFIG_RESETSTAT) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CONFIG_RESETSTAT) + .run(); + }else{ + return new JedisCommand<>(client, Command.CONFIG_RESETSTAT, (cmd)->cmd.configResetStat(), + okStatusConverter) + .run(); + } + } + + @Override + public Status configRewrite() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.CONFIG_REWRITE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.CONFIG_REWRITE) + .run(); + }else{ + return new JedisCommand<>(client, Command.CONFIG_REWRITE, (cmd)->cmd.configRewrite(), + okStatusConverter) + .run(); + } + } + + @Override + public Long dbSize() { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.DBSIZE, (cmd)->cmd.dbSize(), (v)->v) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.DBSIZE) + .run(); + }else{ + return new JedisCommand<>(client, Command.DBSIZE, (cmd)->cmd.dbSize(), (v)->v) + .run(); + } + } + + @Override + public Status failover() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.FAILOVER) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.FAILOVER) + .run(); + }else{ + return new JedisCommand<>(client, Command.FAILOVER, (cmd)->cmd.failover(), okStatusConverter) + .run(); + } + } + + @Override + public Status failover(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + final FailoverParams failoverParams = new JedisFailoverParams(host, port); + + return failover(failoverParams, args); + } + + @Override + public Status failover(final String host, final int port, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("timeout", timeout); + final FailoverParams failoverParams = new JedisFailoverParams(host, port, timeout); + + return failover(failoverParams, args); + } + + @Override + public Status failover(final String host, final int port, final boolean isForce, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("isForce", isForce) + .put("timeout", timeout); + final FailoverParams failoverParams = new JedisFailoverParams(host, port, timeout, isForce); + + return failover(failoverParams, args); + } + + @Override + public Status failover(final int timeout) { + final CommandArguments args = CommandArguments.create("timeout", timeout); + final FailoverParams failoverParams = new JedisFailoverParams(timeout); + + return failover(failoverParams, args); + } + + @Override + public Status flushAll() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.FLUSHALL) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.FLUSHALL) + .run(); + }else{ + return new JedisCommand<>(client, Command.FLUSHALL, (cmd)->cmd.flushAll(), okStatusConverter) + .run(); + } + } + + @Override + public Status flushAll(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + final redis.clients.jedis.args.FlushMode flushMode = (new FlushModeConverter()).convert(mode); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.FLUSHALL) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.FLUSHALL) + .run(args); + }else{ + return new JedisCommand<>(client, Command.FLUSHALL, (cmd)->cmd.flushAll(flushMode), + okStatusConverter) + .run(args); + } + } + + @Override + public Status flushDb() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.FLUSHDB) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.FLUSHDB) + .run(); + }else{ + return new JedisCommand<>(client, Command.FLUSHDB, (cmd)->cmd.flushDB(), okStatusConverter) + .run(); + } + } + + @Override + public Status flushDb(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + final redis.clients.jedis.args.FlushMode flushMode = (new FlushModeConverter()).convert(mode); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.FLUSHDB) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.FLUSHDB) + .run(args); + }else{ + return new JedisCommand<>(client, Command.FLUSHDB, (cmd)->cmd.flushDB(flushMode), okStatusConverter) + .run(args); + } + } + + @Override + public Info info() { + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.INFO) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.INFO) + .run(); + }else{ + return new JedisCommand<>(client, Command.INFO, (cmd)->cmd.info(), infoConverter) + .run(); + } + } + + @Override + public Info info(final Info.Section section) { + final CommandArguments args = CommandArguments.create("section", section); + final String sectionName = section.name().toLowerCase(); + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.INFO) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.INFO) + .run(args); + }else{ + return new JedisCommand<>(client, Command.INFO, (cmd)->cmd.info(sectionName), infoConverter) + .run(args); + } + } + + @Override + public Long lastSave() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.LASTSAVE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.LASTSAVE) + .run(); + }else{ + return new JedisCommand<>(client, Command.LASTSAVE, (cmd)->cmd.lastsave(), (v)->v) + .run(); + } + } + + @Override + public String memoryDoctor() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.MEMORY_DOCTOR) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.MEMORY_DOCTOR) + .run(); + }else{ + return new JedisCommand<>(client, Command.MEMORY_DOCTOR, (cmd)->cmd.memoryDoctor(), (v)->v) + .run(); + } + } + + @Override + public Status memoryPurge() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.MEMORY_PURGE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.MEMORY_PURGE) + .run(); + }else{ + return new JedisCommand<>(client, Command.MEMORY_PURGE, (cmd)->cmd.memoryPurge(), + okStatusConverter) + .run(); + } + } + + @Override + public MemoryStats memoryStats() { + final MemoryStatsConverter memoryStatsConverter = new MemoryStatsConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.MEMORY_STATS) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.MEMORY_STATS) + .run(); + }else{ + return new JedisCommand<>(client, Command.MEMORY_STATS, (cmd)->cmd.memoryStats(), + memoryStatsConverter) + .run(); + } + } + + @Override + public Long memoryUsage(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } + } + + @Override + public Long memoryUsage(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } + } + + @Override + public Long memoryUsage(final String key, final int samples) { + final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key, samples), + (v)->v) + .run(args); + } + } + + @Override + public Long memoryUsage(final byte[] key, final int samples) { + final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key, samples), + (v)->v) + .run(args); + } + } + + @Override + public List moduleList() { + final ListConverter listModuleConverter = ModuleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.MODULE_LIST) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.MODULE_LIST) + .run(); + }else{ + return new JedisCommand<>(client, Command.MODULE_LIST, (cmd)->cmd.moduleList(), + listModuleConverter) + .run(); + } + } + + @Override + public Status moduleLoad(final String path) { + final CommandArguments args = CommandArguments.create("path", path); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.MODULE_LOAD) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.MODULE_LOAD) + .run(args); + }else{ + return new JedisCommand<>(client, Command.MODULE_LOAD, (cmd)->cmd.moduleLoad(path), + okStatusConverter) + .run(args); + } + } + + @Override + public Status moduleLoad(final String path, final String... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.MODULE_LOAD) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.MODULE_LOAD) + .run(args); + }else{ + return new JedisCommand<>(client, Command.MODULE_LOAD, (cmd)->cmd.moduleLoad(path, arguments), + okStatusConverter) + .run(args); + } + } + + @Override + public Status moduleUnLoad(final String name) { + final CommandArguments args = CommandArguments.create("name", name); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.MODULE_UNLOAD) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.MODULE_UNLOAD) + .run(args); + }else{ + return new JedisCommand<>(client, Command.MODULE_UNLOAD, (cmd)->cmd.moduleUnload(name), + okStatusConverter) + .run(args); + } + } + + @Override + public void monitor(final RedisMonitor redisMonitor) { + final CommandArguments args = CommandArguments.create("redisMonitor", redisMonitor); + + if(isPipeline()){ + new JedisPipelineCommand<>(client, Command.MONITOR) + .run(args); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, Command.MONITOR) + .run(args); + }else{ + new JedisCommand<>(client, Command.MONITOR, (cmd)->{ + cmd.monitor(new JedisMonitor() { + + @Override + public void onCommand(final String command) { + redisMonitor.onCommand(command); + } + + }); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public Object pSync(final String replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return notCommand(client, Command.PSYNC, args); + } + + @Override + public Object pSync(final byte[] replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return notCommand(client, Command.PSYNC, args); + } + + @Override + public void sync() { + if(isPipeline()){ + new JedisPipelineCommand<>(client, Command.SYNC, (cmd)->{ + cmd.sync(); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, Command.SYNC) + .run(); + }else{ + new JedisCommand<>(client, Command.SYNC) + .run(); + } + } + + @Override + public Status replicaOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.REPLICAOF) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.REPLICAOF) + .run(args); + }else{ + return new JedisCommand<>(client, Command.REPLICAOF, (cmd)->cmd.replicaof(host, port), + okStatusConverter) + .run(args); + } + } + + @Override + public Status slaveOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.SLAVEOF) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.SLAVEOF) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SLAVEOF, (cmd)->cmd.slaveof(host, port), + okStatusConverter) + .run(args); + } + } + + @Override + public Role role() { + final RoleConverter roleConverter = new RoleConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.ROLE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.ROLE) + .run(); + }else{ + return new JedisCommand<>(client, Command.ROLE, (cmd)->cmd.role(), roleConverter) + .run(); + } + } + + @Override + public Status save() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.SAVE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.SAVE) + .run(); + }else{ + return new JedisCommand<>(client, Command.SAVE, (cmd)->cmd.save(), okStatusConverter) + .run(); + } + } + + @Override + public void shutdown() { + if(isPipeline()){ + new JedisPipelineCommand<>(client, Command.SHUTDOWN) + .run(); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, Command.SHUTDOWN) + .run(); + }else{ + new JedisCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(); + return null; + }, (v)->v) + .run(); + } + } + + @Override + public void shutdown(final boolean save) { + final CommandArguments args = CommandArguments.create("save", save); + final SaveMode saveMode = save ? SaveMode.SAVE : SaveMode.NOSAVE; + + if(isPipeline()){ + new JedisPipelineCommand<>(client, Command.SHUTDOWN) + .run(); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, Command.SHUTDOWN) + .run(); + }else{ + new JedisCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(saveMode); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public List slowLogGet() { + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.SLOWLOG_GET) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.SLOWLOG_GET) + .run(); + }else{ + return new JedisCommand<>(client, Command.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + } + } + + @Override + public List slowLogGet(final int count) { + final CommandArguments args = CommandArguments.create("count", count); + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, Command.SLOWLOG_GET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, Command.SLOWLOG_GET) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SLOWLOG_GET, (cmd)->cmd.slowlogGet(count), + listSlowlogConverter) + .run(args); + } + } + + @Override + public Long slowLogLen() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.SLOWLOG_LEN) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.SLOWLOG_LEN) + .run(); + }else{ + return new JedisCommand<>(client, Command.SLOWLOG_RESET, (cmd)->cmd.slowlogLen(), (v)->v) + .run(); + } + } + + @Override + public Status slowLogReset() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.SLOWLOG_RESET) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.SLOWLOG_RESET) + .run(); + }else{ + return new JedisCommand<>(client, Command.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + } + } + + @Override + public Status swapdb(final int db1, final int db2) { + final CommandArguments args = CommandArguments.create("db1", db1).put("db2", db2); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SWAPDB, (cmd)->cmd.swapDB(db1, db2), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.SWAPDB) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SWAPDB, (cmd)->cmd.swapDB(db1, db2), okStatusConverter) + .run(args); + } + } + + @Override + public RedisServerTime time() { + final RedisServerTimeConverter redisServerTimeConverter = new RedisServerTimeConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.TIME, (cmd)->cmd.time(), + redisServerTimeConverter) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.TIME) + .run(); + }else{ + return new JedisCommand<>(client, Command.TIME, (cmd)->cmd.time(), redisServerTimeConverter) + .run(); + } + } + + private Status failover(final FailoverParams failoverParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.FAILOVER) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, Command.FAILOVER) + .run(args); + }else{ + return new JedisCommand<>(client, Command.FAILOVER, (cmd)->cmd.failover(failoverParams), + okStatusConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSetOperations.java new file mode 100644 index 000000000..a91f3c194 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSetOperations.java @@ -0,0 +1,769 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; +import com.buession.redis.core.internal.jedis.JedisScanParams; +import redis.clients.jedis.params.ScanParams; + +import java.util.List; +import java.util.Set; + +/** + * Jedis 单机模式集合命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSetOperations extends AbstractSetOperations { + + public JedisSetOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public Long sAdd(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long sAdd(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long sCard(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } + } + + @Override + public Long sCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } + } + + @Override + public Set sDiff(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + } + } + + @Override + public Set sDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + } + } + + @Override + public Long sDiffStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Long sDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Set sInter(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + } + } + + @Override + public Set sInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + } + } + + @Override + public Long sInterStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SINTERSTORE, (cmd)->cmd.sinterstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long sInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SINTERSTORE, (cmd)->cmd.sinterstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Boolean sIsMember(final String key, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SISMEMBER, (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + } + } + + @Override + public Boolean sIsMember(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SISMEMBER, (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + } + } + + @Override + public List smIsMember(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SMISMEMBER, (cmd)->cmd.smismember(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SMISMEMBER, (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + } + } + + @Override + public List smIsMember(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SMISMEMBER, (cmd)->cmd.smismember(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SMISMEMBER, (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + } + } + + @Override + public Set sMembers(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + } + } + + @Override + public Set sMembers(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + } + } + + @Override + public Status sMove(final String key, final String destKey, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status sMove(final byte[] key, final byte[] destKey, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + } + } + + @Override + public String sPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] sPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + } + } + + @Override + public Set sPop(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + } + } + + @Override + public Set sPop(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + } + } + + @Override + public String sRandMember(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] sRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + } + } + + @Override + public List sRandMember(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key, (int) count), + (v)->v) + .run(args); + } + } + + @Override + public List sRandMember(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key, (int) count), + (v)->v) + .run(args); + } + } + + @Override + public Long sRem(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long sRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } + } + + @Override + public ScanResult> sScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanParams scanParams = new JedisScanParams(count); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanParams scanParams = new JedisScanParams(count); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return sScan(key, cursor, scanParams, args); + } + + @Override + public Set sUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + } + } + + @Override + public Set sUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + } + } + + @Override + public Long sUnionStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SUNIONSTORE, (cmd)->cmd.sunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long sUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SUNIONSTORE, (cmd)->cmd.sunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + private ScanResult> sScan(final String key, final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSortedSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSortedSetOperations.java new file mode 100644 index 000000000..7468d786d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisSortedSetOperations.java @@ -0,0 +1,2664 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.NumberUtils; +import com.buession.lang.KeyValue; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.Aggregate; +import com.buession.redis.core.GtLt; +import com.buession.redis.core.NxXx; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; +import com.buession.redis.core.ZRangeBy; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.jedis.response.KeyValueConverter; +import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; +import com.buession.redis.core.internal.convert.jedis.response.TupleConverter; +import com.buession.redis.core.internal.jedis.JedisScanParams; +import com.buession.redis.core.internal.jedis.JedisZAddParams; +import com.buession.redis.core.internal.jedis.JedisZParams; +import com.buession.redis.core.internal.jedis.JedisZRangeParams; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.params.ZAddParams; +import redis.clients.jedis.params.ZParams; +import redis.clients.jedis.params.ZRangeParams; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 单机模式模式有序集合命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisSortedSetOperations extends AbstractSortedSetOperations { + + public JedisSortedSetOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public Tuple zPopMin(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + } + } + + @Override + public Tuple zPopMin(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + } + } + + @Override + public List zPopMin(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + } + } + + @Override + public List zPopMin(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + } + } + + @Override + public Tuple zPopMax(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + } + } + + @Override + public Tuple zPopMax(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + } + } + + @Override + public List zPopMax(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + } + } + + @Override + public List zPopMax(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMin(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMin(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public Long zAdd(final String key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long zAdd(final byte[] key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddParams zAddParams = new JedisZAddParams(nxXx); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddParams zAddParams = new JedisZAddParams(nxXx); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddParams zAddParams = new JedisZAddParams(gtLt); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddParams zAddParams = new JedisZAddParams(gtLt); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(gtLt, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(gtLt, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt, ch); + + return zAdd(key, members, zAddParams, args); + } + + @Override + public Long zCard(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } + } + + @Override + public Long zCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } + } + + @Override + public Long zCount(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public Long zCount(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zDiff(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + } + } + + @Override + public List zDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + } + } + + @Override + public List zDiffWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + } + } + + @Override + public List zDiffWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + } + } + + @Override + public Long zDiffStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Long zDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Double zIncrBy(final String key, final double increment, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) + .put("member", member); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZINCRBY, (cmd)->cmd.zincrby(key, increment, member), + (v)->v) + .run(args); + } + } + + @Override + public Double zIncrBy(final byte[] key, final double increment, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) + .put("member", member); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZINCRBY, (cmd)->cmd.zincrby(key, increment, member), + (v)->v) + .run(args); + } + } + + @Override + public List zInter(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInter(keys, zParams, args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInter(keys, zParams, args); + } + + @Override + public List zInterWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterWithScores(keys, zParams, args); + } + + @Override + public Long zInterStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZINTERSTORE, (cmd)->cmd.zinterstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZINTERSTORE, (cmd)->cmd.zinterstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterStore(destKey, keys, zParams, args); + } + + @Override + public Long zLexCount(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zLexCount(key, sMin, sMax, args); + } + + @Override + public Long zLexCount(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zLexCount(key, bMin, bMax, args); + } + + @Override + public List zMScore(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZMSCORE, (cmd)->cmd.zmscore(key, members), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + } + } + + @Override + public List zMScore(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZMSCORE, (cmd)->cmd.zmscore(key, members), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + } + } + + @Override + public String zRandMember(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] zRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + } + } + + @Override + public List zRandMember(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + } + } + + @Override + public List zRandMember(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + } + } + + @Override + public List zRandMemberWithScores(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmemberWithScores(key, count), + listTupleConverter) + .run(args); + } + } + + @Override + public List zRandMemberWithScores(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANDMEMBER, (cmd)->cmd.zrandmemberWithScores(key, count), + listTupleConverter) + .run(args); + } + } + + @Override + public List zRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List zRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List zRangeWithScores(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrangeWithScores(key, start, end), + listTupleConverter) + .run(args); + } + } + + @Override + public List zRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrangeWithScores(key, start, end), + listTupleConverter) + .run(args); + } + } + + @Override + public List zRangeByLex(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zRangeByLex(key, sMin, sMax, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, args); + } + + @Override + public List zRangeByLex(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zRangeByLex(key, sMin, sMax, offset, count, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, offset, count, args); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zRangeByScore(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); + } + + @Override + public Long zRank(final String key, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public Long zRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public Long zRem(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long zRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByRank(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByRank(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List zRevRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List zRevRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List zRevRangeWithScores(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } + } + + @Override + public List zRevRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final String key, final double min, final double max, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } + } + + @Override + public Long zRevRank(final String key, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public Long zRevRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public ScanResult> zScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanParams scanParams = new JedisScanParams(pattern); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanParams scanParams = new JedisScanParams(count); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanParams scanParams = new JedisScanParams(count); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return zScan(key, cursor, scanParams, args); + } + + @Override + public Double zScore(final String key, final String member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } + } + + @Override + public Double zScore(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } + } + + @Override + public List zUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnion(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ZParams zParams = new JedisZParams(); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionWithScores(keys, zParams, args); + } + + @Override + public Long zUnionStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZUNIONSTORE, (cmd)->cmd.zunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZUNIONSTORE, (cmd)->cmd.zunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionStore(destKey, keys, zParams, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionStore(destKey, keys, zParams, args); + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnionStore(destKey, keys, zParams, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZParams zParams = new JedisZParams(weights); + + return zUnionStore(destKey, keys, zParams, args); + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionStore(destKey, keys, zParams, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionStore(destKey, keys, zParams, args); + } + + private Long zAdd(final String key, final Map members, final ZAddParams zAddParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + } + } + + private Long zAdd(final byte[] key, final Map members, final ZAddParams zAddParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + } + } + + private List zInter(final String[] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZINTER, (cmd)->cmd.zinter(zParams, keys), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + } + } + + private List zInter(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZINTER, (cmd)->cmd.zinter(zParams, keys), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + } + } + + private List zInterWithScores(final String[] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZINTER, (cmd)->cmd.zinterWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private List zInterWithScores(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZINTER, (cmd)->cmd.zinterWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private Long zInterStore(final String destKey, final String[] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zInterStore(final byte[] destKey, final byte[][] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zLexCount(final String key, final String min, final String max, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + } + } + + private Long zLexCount(final byte[] key, final byte[] min, final byte[] max, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + } + } + + private List zRangeByLex(final String key, final String min, final String max, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGEBYLEX, (cmd)->cmd.zrangeByLex(key, min, max), + (v)->v) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGEBYLEX, (cmd)->cmd.zrangeByLex(key, min, max), + (v)->v) + .run(args); + } + } + + private List zRangeByLex(final String key, final String min, final String max, final long offset, + final int count, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final int count, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + private Long zRangeStore(final String destKey, final String key, final ZRangeParams zRangeParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + } + } + + private Long zRangeStore(final byte[] destKey, final byte[] key, final ZRangeParams zRangeParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + } + } + + private ScanResult> zScan(final String key, final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + } + } + + private List zUnion(final String[] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZUNION, (cmd)->cmd.zunion(zParams, keys), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + } + } + + private List zUnion(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZUNION, (cmd)->cmd.zunion(zParams, keys), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + } + } + + private List zUnionWithScores(final String[] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZUNION, (cmd)->cmd.zunionWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private List zUnionWithScores(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZUNION, (cmd)->cmd.zunionWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private Long zUnionStore(final String destKey, final String[] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zUnionStore(final byte[] destKey, final byte[][] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisStreamOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisStreamOperations.java new file mode 100644 index 000000000..8048d6f3f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisStreamOperations.java @@ -0,0 +1,1157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapEntryMapConverter; +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.Stream; +import com.buession.redis.core.StreamConsumer; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import com.buession.redis.core.StreamGroup; +import com.buession.redis.core.StreamPending; +import com.buession.redis.core.StreamPendingSummary; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.XAddArgument; +import com.buession.redis.core.command.args.XClaimArgument; +import com.buession.redis.core.command.args.XReadArgument; +import com.buession.redis.core.command.args.XReadGroupArgument; +import com.buession.redis.core.command.args.XTrimArgument; +import com.buession.redis.core.internal.convert.jedis.params.StreamEntryIdConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamConsumersInfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamEntryConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamEntryIDConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamFullInfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamGroupInfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamInfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamPendingEntryConverter; +import com.buession.redis.core.internal.convert.jedis.response.StreamPendingSummaryConverter; +import com.buession.redis.core.internal.jedis.JedisStreamEntryID; +import com.buession.redis.core.internal.jedis.JedisXAddParams; +import com.buession.redis.core.internal.jedis.JedisXAutoClaimParams; +import com.buession.redis.core.internal.jedis.JedisXClaimParams; +import com.buession.redis.core.internal.jedis.JedisXPendingParams; +import com.buession.redis.core.internal.jedis.JedisXReadGroupParams; +import com.buession.redis.core.internal.jedis.JedisXReadParams; +import com.buession.redis.core.internal.jedis.JedisXTrimParams; +import redis.clients.jedis.StreamEntryID; +import redis.clients.jedis.params.XAddParams; +import redis.clients.jedis.params.XAutoClaimParams; +import redis.clients.jedis.params.XClaimParams; +import redis.clients.jedis.params.XPendingParams; +import redis.clients.jedis.params.XReadGroupParams; +import redis.clients.jedis.params.XReadParams; +import redis.clients.jedis.params.XTrimParams; +import redis.clients.jedis.resps.StreamConsumersInfo; +import redis.clients.jedis.resps.StreamGroupInfo; +import redis.clients.jedis.resps.StreamPendingEntry; + +import java.util.List; +import java.util.Map; + +/** + * Jedis 单机模式 Stream 命令操作抽象类 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisStreamOperations extends AbstractStreamOperations { + + public JedisStreamOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public Long xAck(final String key, final String groupName, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("ids", (Object[]) ids); + final StreamEntryID[] streamEntryIDS = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XACK, (cmd)->cmd.xack(key, groupName, streamEntryIDS), + (v)->v) + .run(args); + } + } + + @Override + public Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("ids", (Object[]) ids); + final byte[][] streamEntryIDS = StreamEntryIdConverter.binaryArrayConverter().convert(ids); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XACK, (cmd)->cmd.xack(key, groupName, streamEntryIDS), + (v)->v) + .run(args); + } + } + + @Override + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, streamEntryID, hash), + streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XADD, + (cmd)->cmd.xadd(key, streamEntryID, hash), streamEntryIDConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, streamEntryID, hash), + streamEntryIDConverter) + .run(args); + } + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash); + final XAddParams xAddParams = new JedisXAddParams(id); + final StreamEntryIDConverter.BinaryStreamEntryIdConverter streamEntryIDConverter = + new StreamEntryIDConverter.BinaryStreamEntryIdConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + streamEntryIDConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + streamEntryIDConverter) + .run(args); + } + } + + @Override + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) + .put("xAddArgument", xAddArgument); + final XAddParams xAddParams = JedisXAddParams.from(xAddArgument).id(id); + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + streamEntryIDConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + streamEntryIDConverter) + .run(args); + } + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) + .put("xAddArgument", xAddArgument); + final XAddParams xAddParams = JedisXAddParams.from(xAddArgument).id(id); + final StreamEntryIDConverter.BinaryStreamEntryIdConverter binaryStreamEntryIdConverter = + new StreamEntryIDConverter.BinaryStreamEntryIdConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + binaryStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + binaryStreamEntryIdConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + binaryStreamEntryIdConverter) + .run(args); + } + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(count); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(count); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count"); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); + } + + @Override + public List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final XClaimParams xClaimParams = new JedisXClaimParams(); + + return xClaim(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); + } + + @Override + public List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final XClaimParams xClaimParams = JedisXClaimParams.from(xClaimArgument); + + return xClaim(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); + } + + @Override + public List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final XClaimParams xClaimParams = new JedisXClaimParams(); + + return xClaimJustId(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); + } + + @Override + public List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final XClaimParams xClaimParams = JedisXClaimParams.from(xClaimArgument); + + return xClaimJustId(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); + } + + @Override + public Long xDel(final String key, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("ids", (Object[]) ids); + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XDEL, (cmd)->cmd.xdel(key, streamEntryIDs), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XDEL, (cmd)->cmd.xdel(key, streamEntryIDs), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XDEL, (cmd)->cmd.xdel(key, streamEntryIDs), (v)->v) + .run(args); + } + } + + @Override + public Status xGroupCreate(final String key, final String groupName, final StreamEntryId id, + final boolean makeStream) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("id", id); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + } + } + + @Override + public Long xGroupDelConsumer(final String key, final String groupName, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XGROUP_DELCONSUMER, (cmd)->cmd.xgroupDelConsumer(key, + groupName, consumerName), (v)->v) + .run(args); + } + } + + @Override + public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XGROUP_DELCONSUMER, (cmd)->cmd.xgroupDelConsumer(key, + groupName, consumerName), (v)->v) + .run(args); + } + } + + @Override + public Status xGroupDestroy(final String key, final String groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XGROUP_DESTROY, (cmd)->cmd.xgroupDestroy(key, groupName), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupDestroy(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XGROUP_DESTROY, (cmd)->cmd.xgroupDestroy(key, groupName), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupSetId(final String key, final String groupName, final StreamEntryId id) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName).put("id", id); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + } + } + + @Override + public List xInfoConsumers(final String key, final String groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + final ListConverter listStreamConsumersInfoConverter = + StreamConsumersInfoConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + } + } + + @Override + public List xInfoGroups(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final ListConverter listStreamGroupInfoConverter = + StreamGroupInfoConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + } + } + + @Override + public Stream xInfoStream(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final StreamInfoConverter streamInfoConverter = new StreamInfoConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamInfoConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamInfoConverter) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final String key, final boolean full) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStreamFull(key), + streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStreamFull(key), + streamFullInfoConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStreamFull(key), + streamFullInfoConverter) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final String key, final boolean full, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full).put("count", count); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + } + } + + @Override + public Long xLen(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } + } + + @Override + public Long xLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } + } + + @Override + public StreamPendingSummary xPending(final String key, final String groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + final StreamPendingSummaryConverter streamPendingSummaryConverter = new StreamPendingSummaryConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XPENDING, (cmd)->cmd.xpending(key, groupName), + streamPendingSummaryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XPENDING, (cmd)->cmd.xpending(key, groupName), + streamPendingSummaryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XPENDING, (cmd)->cmd.xpending(key, groupName), + streamPendingSummaryConverter) + .run(args); + } + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final StreamEntryId start, + final StreamEntryId end, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("start", start).put("end", end).put("count", count); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final XPendingParams xPendingParams = new JedisXPendingParams(consumerName); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("start", start).put("end", end).put("count", count); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count, minIdleTime); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime, consumerName); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final StreamEntryId start, + final StreamEntryId end, final int count, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count, consumerName); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count, + final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count, minIdleTime, + consumerName); + + return xPending(key, groupName, xPendingParams, args); + } + + @Override + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XRANGE, (cmd)->cmd.xrange(key, startID, endID), + listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XRANGE, (cmd)->cmd.xrange(key, startID, endID), + listStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XRANGE, (cmd)->cmd.xrange(key, startID, endID), + listStreamEntryConverter) + .run(args); + } + } + + @Override + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, startID, endID, (int) count), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, startID, endID, (int) count), listStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, startID, endID, (int) count), listStreamEntryConverter) + .run(args); + } + } + + @Override + public List>> xRead(final Map streams) { + final CommandArguments args = CommandArguments.create("streams", streams); + final XReadParams xReadParams = new JedisXReadParams(); + + return xRead(streams, xReadParams, args); + } + + @Override + public List>> xRead(final Map streams, + final XReadArgument xReadArgument) { + final CommandArguments args = CommandArguments.create("streams", streams).put("xReadArgument", xReadArgument); + final XReadParams xReadParams = JedisXReadParams.from(xReadArgument); + + return xRead(streams, xReadParams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadGroupParams xReadGroupParams = JedisXReadGroupParams.from(xReadGroupArgument); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadGroupParams xReadGroupParams = JedisXReadGroupParams.from(xReadGroupArgument); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); + } + + @Override + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), listStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XREVRANGE, (cmd)->cmd.xrevrange(key, endID, startID), + listStreamEntryConverter) + .run(args); + } + } + + @Override + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start) + .put("count", count); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + } + } + + @Override + public Long xTrim(final String key, final XTrimArgument xTrimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument); + + return xTrim(key, xTrimParams, args); + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument); + + return xTrim(key, xTrimParams, args); + } + + @Override + public Long xTrim(final String key, final XTrimArgument xTrimArgument, final long limit) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) + .put("limit", limit); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument).limit(limit); + + return xTrim(key, xTrimParams, args); + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) + .put("limit", limit); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument).limit(limit); + + return xTrim(key, xTrimParams, args); + } + + private Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, + final XAutoClaimParams xAutoClaimParams, + final CommandArguments args) { + final StreamEntryID startID = JedisStreamEntryID.from(start); + final StreamEntryConverter.MapEntryStreamEntryConverter mapEntryStreamEntryConverter = + new StreamEntryConverter.MapEntryStreamEntryConverter<>(new StreamEntryIDConverter()); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + mapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + mapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + mapEntryStreamEntryConverter) + .run(args); + } + } + + private Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, + final XAutoClaimParams xAutoClaimParams, + final CommandArguments args) { + final byte[] startID = start.getRaw(); + final StreamEntryConverter.MapEntryStreamEntryConverter mapEntryStreamEntryConverter = + new StreamEntryConverter.MapEntryStreamEntryConverter<>(new StreamEntryIDConverter()); + final Converter, Map>> converter = null; + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + converter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + converter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams), + converter) + .run(args); + } + } + + private Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, + final XAutoClaimParams xAutoClaimParams, + final CommandArguments args) { + final StreamEntryID startID = JedisStreamEntryID.from(start); + final MapEntryMapConverter, StreamEntryId, List> mapEntryStreamEntryIdConverter = StreamEntryIDConverter.mapEntryMapConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams) + , mapEntryStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams) + , mapEntryStreamEntryIdConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startID, xAutoClaimParams) + , mapEntryStreamEntryIdConverter) + .run(args); + } + } + + private List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, final XClaimParams xClaimParams, + final CommandArguments args) { + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + } + } + + private List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimParams xClaimParams, final CommandArguments args) { + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter listStreamEntryIDConverter = StreamEntryIDConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + } + } + + private List xPending(final String key, final String groupName, + final XPendingParams xPendingParams, final CommandArguments args) { + final ListConverter listStreamPendingEntryConverter = + StreamPendingEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + } + } + + private List>> xRead(final Map streams, + final XReadParams xReadParams, final CommandArguments args) { + final Map stringStreamEntryIDMap = StreamEntryIdConverter.mapConverter().convert( + streams); + final StreamEntryConverter.ListMapEntryStreamEntryConverter listMapEntryStreamEntryConverter = + new StreamEntryConverter.ListMapEntryStreamEntryConverter<>((k)->k); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadGroupParams xReadGroupParams, + final CommandArguments args) { + final Map stringStreamEntryIDMap = StreamEntryIdConverter.mapConverter().convert( + streams); + final StreamEntryConverter.ListMapEntryStreamEntryConverter listMapEntryStreamEntryConverter = + new StreamEntryConverter.ListMapEntryStreamEntryConverter<>((k)->k); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + } + } + + private Long xTrim(final String key, final XTrimParams xTrimParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + } + } + + private Long xTrim(final byte[] key, final XTrimParams xTrimParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisStringOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisStringOperations.java new file mode 100644 index 000000000..2415d94fa --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisStringOperations.java @@ -0,0 +1,794 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.GetExArgument; +import com.buession.redis.core.command.args.SetArgument; +import com.buession.redis.core.internal.jedis.JedisGetExParams; +import com.buession.redis.core.internal.jedis.JedisSetParams; +import redis.clients.jedis.params.GetExParams; +import redis.clients.jedis.params.SetParams; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * Jedis 单机模式字符串命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisStringOperations extends AbstractStringOperations { + + public JedisStringOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public Long append(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long append(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long incr(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } + } + + @Override + public Long incr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } + } + + @Override + public Long incrBy(final String key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long incrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + } + } + + @Override + public Double incrByFloat(final String key, final double value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + } + } + + @Override + public Double incrByFloat(final byte[] key, final double value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long decr(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } + } + + @Override + public Long decr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } + } + + @Override + public Long decrBy(final String key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long decrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + } + } + + @Override + public String get(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] get(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + } + } + + @Override + public String getEx(final String key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + final GetExParams getExParams = JedisGetExParams.from(getExArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GETEX, (cmd)->cmd.getEx(key, getExParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + } + } + + @Override + public byte[] getEx(final byte[] key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + final GetExParams getExParams = JedisGetExParams.from(getExArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GETEX, (cmd)->cmd.getEx(key, getExParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + } + } + + @Override + public String getSet(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + } + } + + @Override + public byte[] getSet(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + } + } + + @Override + public String getDel(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] getDel(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + } + } + + @Override + public List mGet(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + } + } + + @Override + public List mGet(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + } + } + + @Override + public Status mSet(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final List temp = new ArrayList<>(values.size() * 2); + + values.forEach((key, value)->{ + temp.add(key); + temp.add(value); + }); + + final String[] keysValues = temp.toArray(new String[0]); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.MSET, (cmd)->cmd.mset(keysValues), okStatusConverter) + .run(args); + } + } + + @Override + public Status mSetNx(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final List temp = new ArrayList<>(values.size() * 2); + + values.forEach((key, value)->{ + temp.add(key); + temp.add(value); + }); + + final String[] keysValues = temp.toArray(new String[0]); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.MSETNX, (cmd)->cmd.msetnx(keysValues), oneStatusConverter) + .run(args); + } + } + + @Override + public Status pSetEx(final String key, final String value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status pSetEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final String key, final String value, final SetArgument setArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final SetParams setParams = JedisSetParams.from(setArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value, final SetArgument setArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final SetParams setParams = JedisSetParams.from(setArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setEx(final String key, final String value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setNx(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), oneStatusConverter) + .run(args); + } + } + + @Override + public Status setNx(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), oneStatusConverter) + .run(args); + } + } + + @Override + public Long setRange(final String key, final long offset, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SETRANGE, (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SETRANGE, (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + } + } + + @Override + public Long setRange(final byte[] key, final long offset, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SETRANGE, (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SETRANGE, (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + } + } + + @Override + public String getRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GETRANGE, (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public byte[] getRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.GETRANGE, (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public Long strlen(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } + } + + @Override + public Long strlen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } + } + + @Override + public String substr(final String key, final int start, final int end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SUBSTR, (cmd)->cmd.substr(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SUBSTR, (cmd)->cmd.substr(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SUBSTR, (cmd)->cmd.substr(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public byte[] substr(final byte[] key, final int start, final int end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.SUBSTR, (cmd)->cmd.substr(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.SUBSTR, (cmd)->cmd.substr(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, Command.SUBSTR, (cmd)->cmd.substr(key, start, end), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisTransactionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisTransactionOperations.java new file mode 100644 index 000000000..c9f9d2097 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/JedisTransactionOperations.java @@ -0,0 +1,215 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import redis.clients.jedis.Builder; +import redis.clients.jedis.Response; + +import java.util.List; + +/** + * Jedis 单机模式事务命令操作 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisTransactionOperations extends AbstractTransactionOperations { + + public JedisTransactionOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public Status multi() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.MULTI) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.MULTI, + (cmd)->new Response<>(new Builder() { + + @Override + public Status build(Object data) { + try{ + cmd.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; + } + } + + }), (v)->v) + .run(); + }else{ + return new JedisCommand<>(client, Command.MULTI, (cmd)->{ + try{ + cmd.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; + } + }, (v)->v) + .run(); + } + } + + @Override + public List exec() { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, Command.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); + + return new Response<>(new Builder>() { + + @Override + public List build(Object data) { + return connection.exec(); + } + + }); + }, (v)->v).run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); + + return new Response<>(new Builder>() { + + @Override + public List build(Object data) { + return connection.exec(); + } + + }); + }, (v)->v).run(); + }else{ + return new JedisCommand<>(client, Command.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); + return connection.exec(); + }, (v)->v).run(); + } + } + + @Override + public void discard() { + if(isPipeline()){ + new JedisPipelineCommand<>(client, Command.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, Command.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + }else{ + new JedisCommand<>(client, Command.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + } + } + + @Override + public Status watch(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.WATCH) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.WATCH, + (cmd)->new Response<>(new Builder() { + + @Override + public String build(Object data) { + return cmd.watch(keys); + } + + }), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.WATCH, (cmd)->cmd.watch(keys), okStatusConverter) + .run(args); + } + } + + @Override + public Status watch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.WATCH) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.WATCH, + (cmd)->new Response<>(new Builder() { + + @Override + public String build(Object data) { + return cmd.watch(keys); + } + + }), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, Command.WATCH, (cmd)->cmd.watch(keys), okStatusConverter) + .run(args); + } + } + + @Override + public Status unwatch() { + if(isPipeline()){ + return new JedisPipelineCommand(client, Command.UNWATCH) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, Command.UNWATCH, + (cmd)->new Response<>(new Builder() { + + @Override + public String build(Object data) { + return cmd.unwatch(); + } + + }), okStatusConverter) + .run(); + }else{ + return new JedisCommand<>(client, Command.UNWATCH, (cmd)->cmd.unwatch(), okStatusConverter) + .run(); + } + } + +} diff --git a/buession-core/src/main/java/com/buession/core/serializer/type/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/package-info.java similarity index 95% rename from buession-core/src/main/java/com/buession/core/serializer/type/package-info.java rename to buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/package-info.java index 3c1bdcaf5..423774240 100644 --- a/buession-core/src/main/java/com/buession/core/serializer/type/package-info.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/jedis/operations/package-info.java @@ -22,7 +22,4 @@ * | Copyright @ 2013-2020 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -/** - * @author Yong.Teng - */ -package com.buession.core.serializer.type; \ No newline at end of file +package com.buession.redis.client.jedis.operations; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/AbstractLettuceRedisClient.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/AbstractLettuceRedisClient.java new file mode 100644 index 000000000..d5b71edf3 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/AbstractLettuceRedisClient.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce; + +import com.buession.redis.client.AbstractRedisClient; +import com.buession.redis.client.connection.lettuce.LettuceRedisConnection; + +/** + * Lettuce Redis 客户端抽象类 + * + * @param + * Lettuce Redis 连接对象类型 {@link LettuceRedisConnection} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractLettuceRedisClient extends AbstractRedisClient + implements LettuceRedisClient { + + /** + * 构造函数 + */ + public AbstractLettuceRedisClient() { + super(); + } + + /** + * 构造函数 + * + * @param connection + * Lettuce Redis 连接对象 {@link LettuceRedisConnection} + */ + public AbstractLettuceRedisClient(final CONN connection) { + super(connection); + } + +} \ No newline at end of file diff --git a/buession-core/src/main/java/com/buession/core/serializer/type/TypeReference.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/LettuceRedisClient.java similarity index 85% rename from buession-core/src/main/java/com/buession/core/serializer/type/TypeReference.java rename to buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/LettuceRedisClient.java index 5f4decbdc..ee0b2631c 100644 --- a/buession-core/src/main/java/com/buession/core/serializer/type/TypeReference.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/LettuceRedisClient.java @@ -19,19 +19,19 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.core.serializer.type; +package com.buession.redis.client.lettuce; + +import com.buession.redis.client.RedisClient; /** + * Lettuce Redis 客户端 + * * @author Yong.Teng + * @since 3.0.0 */ -@Deprecated -public abstract class TypeReference extends com.buession.core.type.TypeReference { - - protected TypeReference() { - super(); - } +public interface LettuceRedisClient extends RedisClient { } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractAclOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractAclOperations.java new file mode 100644 index 000000000..05db236b2 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractAclOperations.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.AclOperations; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.AclSetUserArgument; +import com.buession.redis.utils.SafeEncoder; + +/** + * Lettuce 权限命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractAclOperations extends AbstractLettuceRedisOperations + implements AclOperations { + + public AbstractAclOperations(final C client) { + super(client); + } + + @Override + public Long aclDelUser(final byte[]... usernames) { + return aclDelUser(SafeEncoder.encode(usernames)); + } + + @Override + public Status aclDryRun(final byte[] username, final Command command) { + return aclDryRun(SafeEncoder.encode(username), command); + } + + @Override + public Status aclDryRun(final byte[] username, final Command command, final byte[]... arguments) { + return aclDryRun(SafeEncoder.encode(username), command, SafeEncoder.encode(arguments)); + } + + @Override + public AclUser aclGetUser(final byte[] username) { + return aclGetUser(SafeEncoder.encode(username)); + } + + @Override + public Status aclSetUser(final byte[] username, final AclSetUserArgument rules) { + return aclSetUser(SafeEncoder.encode(username), rules); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractBitMapOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractBitMapOperations.java new file mode 100644 index 000000000..ae6775579 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractBitMapOperations.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.BitMapOperations; +import com.buession.redis.core.BitType; +import com.buession.redis.core.BitOperation; +import com.buession.redis.core.command.args.BitFieldArgument; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce BitMap 命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractBitMapOperations extends AbstractLettuceRedisOperations + implements BitMapOperations { + + public AbstractBitMapOperations(final C client) { + super(client); + } + + @Override + public Long bitCount(final String key) { + return bitCount(SafeEncoder.encode(key)); + } + + @Override + public Long bitCount(final String key, final long start, final long end) { + return bitCount(SafeEncoder.encode(key), start, end); + } + + @Override + public Long bitCount(final String key, final long start, final long end, final BitType bitType) { + return bitCount(SafeEncoder.encode(key), start, end, bitType); + } + + @Override + public List bitField(final String key) { + return bitField(SafeEncoder.encode(key)); + } + + @Override + public List bitField(final String key, final BitFieldArgument argument) { + return bitField(SafeEncoder.encode(key), argument); + } + + @Override + public Long bitOp(final BitOperation operation, final String destKey, final String... keys) { + return bitOp(operation, SafeEncoder.encode(destKey), SafeEncoder.encode(keys)); + } + + @Override + public Long bitPos(final String key, final boolean value) { + return bitPos(SafeEncoder.encode(key), value); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start) { + return bitPos(SafeEncoder.encode(key), value, start); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final BitType bitType) { + return bitPos(SafeEncoder.encode(key), value, start, bitType); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final long end) { + return bitPos(SafeEncoder.encode(key), value, start, end); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final long end, final BitType bitType) { + return bitPos(SafeEncoder.encode(key), value, start, end, bitType); + } + + @Override + public Boolean getBit(final String key, final long offset) { + return getBit(SafeEncoder.encode(key), offset); + } + + @Override + public Boolean setBit(final String key, final long offset, final boolean value) { + return setBit(SafeEncoder.encode(key), offset, value); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractClusterOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractClusterOperations.java new file mode 100644 index 000000000..8580b796a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractClusterOperations.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.ClusterOperations; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.ClusterResetOption; +import com.buession.redis.core.ClusterSetSlotOption; +import com.buession.redis.core.SlotRange; +import com.buession.redis.core.internal.convert.lettuce.params.RangeConverter; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce 集群命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractClusterOperations extends AbstractLettuceRedisOperations + implements ClusterOperations { + + public AbstractClusterOperations(final C client) { + super(client); + } + + @Override + public Long clusterCountFailureReports(final byte[] nodeId) { + return clusterCountFailureReports(SafeEncoder.encode(nodeId)); + } + + @Override + public Status clusterForget(final byte[] nodeId) { + return clusterForget(SafeEncoder.encode(nodeId)); + } + + @Override + public Long clusterKeySlot(final String key) { + return clusterKeySlot(SafeEncoder.encode(key)); + } + + @Override + public List clusterReplicas(final byte[] nodeId) { + return clusterReplicas(SafeEncoder.encode(nodeId)); + } + + @Override + public Status clusterReplicate(final byte[] nodeId) { + return clusterReplicate(SafeEncoder.encode(nodeId)); + } + + @Override + public List clusterSlaves(final byte[] nodeId) { + return clusterSlaves(SafeEncoder.encode(nodeId)); + } + + @Override + public Status clusterReset() { + return clusterReset(ClusterResetOption.SOFT); + } + + @Override + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final byte[] nodeId) { + return clusterSetSlot(slot, setSlotOption, SafeEncoder.encode(nodeId)); + } + + protected static io.lettuce.core.Range[] numberRangeArrayToRange(final SlotRange[] values) { + final RangeConverter rangeConverter = new RangeConverter<>(); + final io.lettuce.core.Range[] result = new io.lettuce.core.Range[values.length]; + + for(int i = 0; i < values.length; i++){ + result[i] = rangeConverter.convert(values[i]); + } + + return result; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractConnectionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractConnectionOperations.java new file mode 100644 index 000000000..4d4984678 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractConnectionOperations.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.ConnectionOperations; +import com.buession.redis.core.ClientAttributeOption; +import com.buession.redis.core.command.args.ClientKillArgument; +import com.buession.redis.core.internal.lettuce.LettuceKillArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KillArgs; + +import java.util.Optional; + +/** + * Jedis 连接命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractConnectionOperations + extends AbstractLettuceRedisOperations implements ConnectionOperations { + + public AbstractConnectionOperations(final C client) { + super(client); + } + + @Override + public Status auth(final byte[] user, final byte[] password) { + return auth(SafeEncoder.encode(user), SafeEncoder.encode(password)); + } + + @Override + public Status auth(final byte[] password) { + return auth(SafeEncoder.encode(password)); + } + + @Override + public Status clientSetInfo(final ClientAttributeOption clientAttributeOption, final byte[] value) { + return clientSetInfo(clientAttributeOption, SafeEncoder.encode(value)); + } + + @Override + public Status clientSetName(final String name) { + return clientSetName(SafeEncoder.encode(name)); + } + + protected static KillArgs createKillArgsFromClientKillArgument(final ClientKillArgument... clientKillArguments) { + if(clientKillArguments != null && clientKillArguments.length > 0){ + final LettuceKillArgs killArgs = LettuceKillArgs.from(clientKillArguments[0]); + ClientKillArgument clientKillArgument; + + for(int i = 1; i < clientKillArguments.length; i++){ + clientKillArgument = clientKillArguments[i]; + + Optional.ofNullable(clientKillArgument.getClientId()).ifPresent(killArgs::id); + Optional.ofNullable(clientKillArgument.getClientType()).ifPresent(killArgs::type); + Optional.ofNullable(clientKillArgument.getUsername()).ifPresent(killArgs::user); + Optional.ofNullable(clientKillArgument.getAddr()).ifPresent(killArgs::addr); + Optional.ofNullable(clientKillArgument.getLaddr()).ifPresent(killArgs::laddr); + Optional.ofNullable(clientKillArgument.getSkipMe()).ifPresent(killArgs::skipme); + } + + return killArgs; + }else{ + return null; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractGeoOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractGeoOperations.java new file mode 100644 index 000000000..20d78308c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractGeoOperations.java @@ -0,0 +1,196 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.lang.Geo; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.GeoOperations; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import com.buession.redis.core.command.args.GeoRadiusArgument; +import com.buession.redis.core.command.args.GeoSearchArgument; +import com.buession.redis.core.command.args.GeoSearchStoreArgument; +import com.buession.redis.core.internal.convert.lettuce.params.GeoUnitConverter; +import com.buession.redis.core.internal.lettuce.LettuceGeoValue; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.GeoSearch; +import io.lettuce.core.GeoValue; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 地理位置命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractGeoOperations extends AbstractLettuceRedisOperations + implements GeoOperations { + + public AbstractGeoOperations(final C client) { + super(client); + } + + @Override + public Long geoAdd(final String key, final String member, final double longitude, final double latitude) { + return geoAdd(SafeEncoder.encode(key), SafeEncoder.encode(member), longitude, latitude); + } + + @Override + public Double geoDist(final String key, final String member1, final String member2) { + return geoDist(SafeEncoder.encode(key), SafeEncoder.encode(member1), SafeEncoder.encode(member2)); + } + + @Override + public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit) { + return geoDist(SafeEncoder.encode(key), SafeEncoder.encode(member1), SafeEncoder.encode(member2), unit); + } + + @Override + public List geoPos(final String key, final String... members) { + return geoPos(SafeEncoder.encode(key), SafeEncoder.encode(members)); + } + + @Override + public List geoRadius(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + return geoRadius(SafeEncoder.encode(key), longitude, latitude, radius, unit); + } + + @Override + public List geoRadius(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + return geoRadius(SafeEncoder.encode(key), longitude, latitude, radius, unit, geoRadiusArgument); + } + + @Override + public List geoRadiusByMember(final String key, final String member, final double radius, + final GeoUnit unit) { + return geoRadiusByMember(SafeEncoder.encode(key), SafeEncoder.encode(member), radius, unit); + } + + @Override + public List geoRadiusByMember(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + return geoRadiusByMember(SafeEncoder.encode(key), SafeEncoder.encode(member), radius, unit, geoRadiusArgument); + } + + @Override + public List geoSearch(final String key, final GeoSearchArgument geoSearchArgument) { + return geoSearch(SafeEncoder.encode(key), geoSearchArgument); + } + + @Override + public Long geoSearchStore(final String destKey, final String key, + final GeoSearchStoreArgument geoSearchStoreArgument) { + return geoSearchStore(SafeEncoder.encode(destKey), SafeEncoder.encode(key), geoSearchStoreArgument); + } + + @SuppressWarnings({"unchecked"}) + protected static GeoValue[] createGeoValueArrayFromGeoMap(final Map memberCoordinates, final + Converter keyConverter) { + if(memberCoordinates == null){ + return null; + }else{ + final GeoValue[] result = new GeoValue[memberCoordinates.size()]; + int i = 0; + + for(Map.Entry e : memberCoordinates.entrySet()){ + result[i++] = LettuceGeoValue.from(keyConverter.convert(e.getKey()), e.getValue()); + } + + return result; + } + } + + protected static GeoSearch.GeoRef createGeoRefFromGeoSearchArgument( + final GeoSearchArgument geoSearchArgument) { + if(geoSearchArgument.getFromMode() instanceof GeoSearchArgument.FromMember){ + return GeoSearch.fromMember(SafeEncoder.encode( + ((GeoSearchArgument.FromMember) geoSearchArgument.getFromMode()).getMember())); + }else if(geoSearchArgument.getFromMode() instanceof GeoSearchArgument.FromLonLat){ + final Geo geo = ((GeoSearchArgument.FromLonLat) geoSearchArgument.getFromMode()).getGeo(); + return GeoSearch.fromCoordinates(geo.getLongitude(), geo.getLatitude()); + }else{ + return null; + } + } + + protected static GeoSearch.GeoPredicate createGeoPredicateFromGeoSearchArgument( + final GeoSearchArgument geoSearchArgument) { + final GeoUnitConverter geoUnitConverter = new GeoUnitConverter(); + + if(geoSearchArgument.getPredicate() instanceof GeoSearchArgument.RadiusPredicate){ + final GeoSearchArgument.RadiusPredicate predicate = (GeoSearchArgument.RadiusPredicate) geoSearchArgument.getPredicate(); + + return GeoSearch.byRadius(predicate.getRadius(), geoUnitConverter.convert(predicate.getUnit())); + }else if(geoSearchArgument.getPredicate() instanceof GeoSearchArgument.BoxPredicate){ + final GeoSearchArgument.BoxPredicate predicate = (GeoSearchArgument.BoxPredicate) geoSearchArgument.getPredicate(); + + return GeoSearch.byBox(predicate.getWidth(), predicate.getHeight(), + geoUnitConverter.convert(predicate.getUnit())); + }else{ + return null; + } + } + + protected static GeoSearch.GeoRef createGeoRefFromGeoSearchStoreArgument( + final GeoSearchStoreArgument geoSearchStoreArgument) { + if(geoSearchStoreArgument.getFromMode() instanceof GeoSearchStoreArgument.FromMember){ + return GeoSearch.fromMember(SafeEncoder.encode( + ((GeoSearchStoreArgument.FromMember) geoSearchStoreArgument.getFromMode()).getMember())); + }else if(geoSearchStoreArgument.getFromMode() instanceof GeoSearchStoreArgument.FromLonLat){ + final Geo geo = ((GeoSearchStoreArgument.FromLonLat) geoSearchStoreArgument.getFromMode()).getGeo(); + return GeoSearch.fromCoordinates(geo.getLongitude(), geo.getLatitude()); + }else{ + return null; + } + } + + protected static GeoSearch.GeoPredicate createGeoPredicateFromGeoSearchStoreArgument( + final GeoSearchStoreArgument geoSearchStoreArgument) { + final GeoUnitConverter geoUnitConverter = new GeoUnitConverter(); + + if(geoSearchStoreArgument.getPredicate() instanceof GeoSearchStoreArgument.RadiusPredicate){ + final GeoSearchStoreArgument.RadiusPredicate predicate = (GeoSearchStoreArgument.RadiusPredicate) geoSearchStoreArgument.getPredicate(); + + return GeoSearch.byRadius(predicate.getRadius(), geoUnitConverter.convert(predicate.getUnit())); + }else if(geoSearchStoreArgument.getPredicate() instanceof GeoSearchStoreArgument.BoxPredicate){ + final GeoSearchStoreArgument.BoxPredicate predicate = (GeoSearchStoreArgument.BoxPredicate) geoSearchStoreArgument.getPredicate(); + + return GeoSearch.byBox(predicate.getWidth(), predicate.getHeight(), + geoUnitConverter.convert(predicate.getUnit())); + }else{ + return null; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractHashOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractHashOperations.java new file mode 100644 index 000000000..7da147747 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractHashOperations.java @@ -0,0 +1,171 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.utils.NumberUtils; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.HashOperations; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.args.HScanArgument; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 哈希表命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractHashOperations extends AbstractLettuceRedisOperations + implements HashOperations { + + public AbstractHashOperations(final C client) { + super(client); + } + + @Override + public Long hDel(final String key, final String... fields) { + return hDel(SafeEncoder.encode(key), SafeEncoder.encode(fields)); + } + + @Override + public Boolean hExists(final String key, final String field) { + return hExists(SafeEncoder.encode(key), SafeEncoder.encode(field)); + } + + @Override + public List hExpire(final String key, final int lifetime, final String... fields) { + return hExpire(SafeEncoder.encode(key), lifetime, SafeEncoder.encode(fields)); + } + + @Override + public List hExpire(final String key, final int lifetime, final ExpireOption expireOption, + final String... fields) { + return hExpire(SafeEncoder.encode(key), lifetime, expireOption, SafeEncoder.encode(fields)); + } + + @Override + public List hExpireAt(final String key, final long unixTimestamp, final String... fields) { + return hExpireAt(SafeEncoder.encode(key), unixTimestamp, SafeEncoder.encode(fields)); + } + + @Override + public List hExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption, + final String... fields) { + return hExpireAt(SafeEncoder.encode(key), unixTimestamp, expireOption, SafeEncoder.encode(fields)); + } + + @Override + public List hExpireTime(final String key, final String... fields) { + return hExpireTime(SafeEncoder.encode(key), SafeEncoder.encode(fields)); + } + + @Override + public Long hIncrBy(final String key, final String field, final long value) { + return hIncrBy(SafeEncoder.encode(key), SafeEncoder.encode(field), value); + } + + @Override + public Double hIncrByFloat(final String key, final String field, final double value) { + return hIncrByFloat(SafeEncoder.encode(key), SafeEncoder.encode(field), value); + } + + @Override + public Long hLen(final String key) { + return hLen(SafeEncoder.encode(key)); + } + + @Override + public Status hMSet(final String key, final Map data) { + return hMSet(SafeEncoder.encode(key), Converters.mapStringToBinary().convert(data)); + } + + public List hPersist(final String key, final String... fields) { + return hPersist(SafeEncoder.encode(key), SafeEncoder.encode(fields)); + } + + @Override + public List hpExpire(final String key, final int lifetime, final String... fields) { + return hpExpire(SafeEncoder.encode(key), lifetime, SafeEncoder.encode(fields)); + } + + @Override + public List hpExpire(final String key, final int lifetime, final ExpireOption expireOption, + final String... fields) { + return hpExpire(SafeEncoder.encode(key), lifetime, expireOption, SafeEncoder.encode(fields)); + } + + @Override + public ScanResult> hScan(final String key, final long cursor) { + return hScan(key, Long.toString(cursor)); + } + + @Override + public ScanResult> hScan(final byte[] key, final long cursor) { + return hScan(key, NumberUtils.long2bytes(cursor)); + } + + @Override + public ScanResult> hScan(final String key, final long cursor, + final HScanArgument scanArgument) { + return hScan(key, Long.toString(cursor), scanArgument); + } + + @Override + public ScanResult> hScan(final byte[] key, final long cursor, + final HScanArgument scanArgument) { + return hScan(key, NumberUtils.long2bytes(cursor), scanArgument); + } + + @Override + public Long hSet(final String key, final KeyValue... data) { + return hSet(SafeEncoder.encode(key), data); + } + + @Override + public Status hSetNx(final String key, final String field, final String value) { + return hSetNx(SafeEncoder.encode(key), SafeEncoder.encode(field), SafeEncoder.encode(value)); + } + + @Override + public List hTtl(final String key, final String... fields) { + return hTtl(SafeEncoder.encode(key), SafeEncoder.encode(fields)); + } + + @Override + public Long hStrLen(final String key, final String field) { + return hStrLen(SafeEncoder.encode(key), SafeEncoder.encode(field)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractHyperLogLogOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractHyperLogLogOperations.java new file mode 100644 index 000000000..e0fec4a01 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractHyperLogLogOperations.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.HyperLogLogOperations; +import com.buession.redis.utils.SafeEncoder; + +/** + * Lettuce HyperLogLog 命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractHyperLogLogOperations + extends AbstractLettuceRedisOperations implements HyperLogLogOperations { + + public AbstractHyperLogLogOperations(final C client) { + super(client); + } + + @Override + public Status pfAdd(final String key, final String... elements) { + return pfAdd(SafeEncoder.encode(key), SafeEncoder.encode(elements)); + } + + @Override + public Long pfCount(final String... keys) { + return pfCount(SafeEncoder.encode(keys)); + } + + @Override + public Status pfMerge(final String destKey, final String... keys) { + return pfMerge(SafeEncoder.encode(destKey), SafeEncoder.encode(keys)); + } + +} \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractKeyOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractKeyOperations.java new file mode 100644 index 000000000..825377389 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractKeyOperations.java @@ -0,0 +1,275 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.utils.NumberUtils; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.KeyOperations; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.ObjectEncoding; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Type; +import com.buession.redis.core.command.args.MigrateArgument; +import com.buession.redis.core.command.args.RestoreArgument; +import com.buession.redis.core.command.args.SortArgument; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce Key 命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractKeyOperations extends AbstractLettuceRedisOperations + implements KeyOperations { + + public AbstractKeyOperations(final C client) { + super(client); + } + + @Override + public Status copy(final String key, final String destKey) { + return copy(SafeEncoder.encode(key), SafeEncoder.encode(destKey)); + } + + @Override + public Status copy(final String key, final String destKey, final int db) { + return copy(SafeEncoder.encode(key), SafeEncoder.encode(destKey), db); + } + + @Override + public Status copy(final String key, final String destKey, final boolean replace) { + return copy(SafeEncoder.encode(key), SafeEncoder.encode(destKey), replace); + } + + @Override + public Status copy(final String key, final String destKey, final int db, final boolean replace) { + return copy(SafeEncoder.encode(key), SafeEncoder.encode(destKey), db, replace); + } + + @Override + public Long del(final String... keys) { + return del(SafeEncoder.encode(keys)); + } + + @Override + public String dump(final String key) { + return SafeEncoder.encode(dump(SafeEncoder.encode(key))); + } + + @Override + public Boolean exists(final String key) { + return exists(SafeEncoder.encode(key)); + } + + @Override + public Long exists(final String... keys) { + return exists(SafeEncoder.encode(keys)); + } + + @Override + public Status expire(final String key, final int lifetime) { + return expire(SafeEncoder.encode(key), lifetime); + } + + @Override + public Status expire(final String key, final int lifetime, final ExpireOption expireOption) { + return expire(SafeEncoder.encode(key), lifetime, expireOption); + } + + @Override + public Status expireAt(final String key, final long unixTimestamp) { + return expireAt(SafeEncoder.encode(key), unixTimestamp); + } + + @Override + public Status expireAt(final String key, final long unixTimestamp, final ExpireOption expireOption) { + return expireAt(SafeEncoder.encode(key), unixTimestamp, expireOption); + } + + @Override + public Long expireTime(String key) { + return expireTime(SafeEncoder.encode(key)); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final String... keys) { + return migrate(host, port, db, timeout, SafeEncoder.encode(keys)); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgument migrateArgument, final String... keys) { + return migrate(host, port, db, timeout, migrateArgument, SafeEncoder.encode(keys)); + } + + @Override + public Status move(final String key, final int db) { + return move(SafeEncoder.encode(key), db); + } + + @Override + public ObjectEncoding objectEncoding(final String key) { + return objectEncoding(SafeEncoder.encode(key)); + } + + @Override + public Long objectFreq(final String key) { + return objectFreq(SafeEncoder.encode(key)); + } + + @Override + public Long objectIdleTime(final String key) { + return objectIdleTime(SafeEncoder.encode(key)); + } + + @Override + public Long objectRefcount(final String key) { + return objectRefcount(SafeEncoder.encode(key)); + } + + @Override + public Status persist(final String key) { + return persist(SafeEncoder.encode(key)); + } + + @Override + public Status pExpire(final String key, final int lifetime) { + return pExpire(SafeEncoder.encode(key), lifetime); + } + + @Override + public Status pExpire(final String key, final int lifetime, final ExpireOption expireOption) { + return pExpire(SafeEncoder.encode(key), lifetime, expireOption); + } + + @Override + public Status pExpireAt(final String key, final long unixTimestamp) { + return pExpireAt(SafeEncoder.encode(key), unixTimestamp); + } + + @Override + public Status pExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption) { + return pExpireAt(SafeEncoder.encode(key), unixTimestamp, expireOption); + } + + @Override + public Long pExpireTime(final String key) { + return pExpireTime(SafeEncoder.encode(key)); + } + + @Override + public Long pTtl(final String key) { + return pTtl(SafeEncoder.encode(key)); + } + + @Override + public Status rename(final String key, final String newKey) { + return rename(SafeEncoder.encode(key), SafeEncoder.encode(newKey)); + } + + @Override + public Status renameNx(final String key, final String newKey) { + return renameNx(SafeEncoder.encode(key), SafeEncoder.encode(newKey)); + } + + @Override + public Status restore(final String key, final byte[] serializedValue, final int ttl) { + return restore(SafeEncoder.encode(key), serializedValue, ttl); + } + + @Override + public Status restore(final String key, final byte[] serializedValue, final int ttl, + final RestoreArgument restoreArgument) { + return restore(SafeEncoder.encode(key), serializedValue, ttl, restoreArgument); + } + + @Override + public ScanResult> scan(final long cursor) { + return scan(Long.toString(cursor)); + } + + @Override + public ScanResult> scan(final long cursor, final String pattern) { + return scan(Long.toString(cursor), pattern); + } + + @Override + public ScanResult> scan(final long cursor, final byte[] pattern) { + return scan(NumberUtils.long2bytes(cursor), pattern); + } + + @Override + public ScanResult> scan(final long cursor, final int count) { + return scan(Long.toString(cursor), count); + } + + @Override + public ScanResult> scan(final long cursor, final String pattern, final int count) { + return scan(Long.toString(cursor), pattern, count); + } + + @Override + public ScanResult> scan(final long cursor, final byte[] pattern, final int count) { + return scan(NumberUtils.long2bytes(cursor), pattern, count); + } + + @Override + public Long sort(final String key, final String destKey) { + return sort(SafeEncoder.encode(key), SafeEncoder.encode(destKey)); + } + + @Override + public Long sort(final String key, final String destKey, final SortArgument sortArgument) { + return sort(SafeEncoder.encode(key), SafeEncoder.encode(destKey), sortArgument); + } + + @Override + public Long touch(final String... keys) { + return touch(SafeEncoder.encode(keys)); + } + + @Override + public Long ttl(final String key) { + return ttl(SafeEncoder.encode(key)); + } + + @Override + public Type type(final String key) { + return type(SafeEncoder.encode(key)); + } + + @Override + public Long unlink(final String... keys) { + return unlink(SafeEncoder.encode(keys)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractLettuceRedisOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractLettuceRedisOperations.java new file mode 100644 index 000000000..0c9f10805 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractLettuceRedisOperations.java @@ -0,0 +1,215 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.client.operations.AbstractRedisOperations; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; + +/** + * Lettuce Redis 命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractLettuceRedisOperations extends AbstractRedisOperations + implements LettuceRedisOperations { + + public AbstractLettuceRedisOperations(final C client) { + super(client); + } + + protected T notCommand(final LettuceStandaloneClient client, final Command command) { + if(isPipeline()){ + return new LettucePipelineCommand(client, command) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, command) + .run(); + }else{ + return new LettuceCommand(client, command) + .run(); + } + } + + protected T notCommand(final LettuceStandaloneClient client, final Command command, + final SubCommand subCommand) { + if(isPipeline()){ + return new LettucePipelineCommand(client, command, subCommand) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, command, subCommand) + .run(); + }else{ + return new LettuceCommand(client, command, subCommand) + .run(); + } + } + + protected T notCommand(final LettuceStandaloneClient client, final Command command, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, command) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, command) + .run(args); + }else{ + return new LettuceCommand(client, command) + .run(args); + } + } + + protected T notCommand(final LettuceStandaloneClient client, final Command command, final SubCommand subCommand, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, command, subCommand) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, command, subCommand) + .run(args); + }else{ + return new LettuceCommand(client, command, subCommand) + .run(args); + } + } + + protected T notCommand(final LettuceSentinelClient client, final Command command) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, command) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, command) + .run(); + }else{ + return new LettuceSentinelCommand(client, command) + .run(); + } + } + + protected T notCommand(final LettuceSentinelClient client, final Command command, final SubCommand subCommand) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, command, subCommand) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, command, subCommand) + .run(); + }else{ + return new LettuceSentinelCommand(client, command, subCommand) + .run(); + } + } + + protected T notCommand(final LettuceSentinelClient client, final Command command, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, command) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, command) + .run(args); + }else{ + return new LettuceSentinelCommand(client, command) + .run(args); + } + } + + protected T notCommand(final LettuceSentinelClient client, final Command command, final SubCommand subCommand, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, command, subCommand) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, command, subCommand) + .run(args); + }else{ + return new LettuceSentinelCommand(client, command, subCommand) + .run(args); + } + } + + protected T notCommand(final LettuceClusterClient client, final Command command) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, command) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, command) + .run(); + }else{ + return new LettuceClusterCommand(client, command) + .run(); + } + } + + protected T notCommand(final LettuceClusterClient client, final Command command, final SubCommand subCommand) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, command, subCommand) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, command, subCommand) + .run(); + }else{ + return new LettuceClusterCommand(client, command, subCommand) + .run(); + } + } + + protected T notCommand(final LettuceClusterClient client, final Command command, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, command) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, command) + .run(args); + }else{ + return new LettuceClusterCommand(client, command) + .run(args); + } + } + + protected T notCommand(final LettuceClusterClient client, final Command command, final SubCommand subCommand, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, command, subCommand) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, command, subCommand) + .run(args); + }else{ + return new LettuceClusterCommand(client, command, subCommand) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractListOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractListOperations.java new file mode 100644 index 000000000..fd86387f8 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractListOperations.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.ListOperations; +import com.buession.redis.core.ListPosition; +import com.buession.redis.core.command.args.LPosArgument; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce 列表命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractListOperations extends AbstractLettuceRedisOperations + implements ListOperations { + + public AbstractListOperations(final C client) { + super(client); + } + + @Override + public Long lInsert(final String key, final ListPosition position, final String pivot, final String value) { + return lInsert(SafeEncoder.encode(key), position, SafeEncoder.encode(pivot), SafeEncoder.encode(value)); + } + + @Override + public Status lSet(final String key, final long index, final String value) { + return lSet(SafeEncoder.encode(key), index, SafeEncoder.encode(value)); + } + + @Override + public Long lLen(final String key) { + return lLen(SafeEncoder.encode(key)); + } + + @Override + public Long lPos(final String key, final String element) { + return lPos(SafeEncoder.encode(key), SafeEncoder.encode(element)); + } + + @Override + public Long lPos(final String key, final String element, final LPosArgument lPosArgument) { + return lPos(SafeEncoder.encode(key), SafeEncoder.encode(element), lPosArgument); + } + + @Override + public List lPos(final String key, final String element, final LPosArgument lPosArgument, final int count) { + return lPos(SafeEncoder.encode(key), SafeEncoder.encode(element), lPosArgument, count); + } + + @Override + public Long lRem(final String key, final String value, final int count) { + return lRem(SafeEncoder.encode(key), SafeEncoder.encode(value), count); + } + + @Override + public Status lTrim(final String key, final long start, final long end) { + return lTrim(SafeEncoder.encode(key), start, end); + } + + @Override + public Long lPush(final String key, final String... values) { + return lPush(SafeEncoder.encode(key), SafeEncoder.encode(values)); + } + + @Override + public Long lPushX(final String key, final String... values) { + return lPushX(SafeEncoder.encode(key), SafeEncoder.encode(values)); + } + + @Override + public Long rPush(final String key, final String... values) { + return rPush(SafeEncoder.encode(key), SafeEncoder.encode(values)); + } + + @Override + public Long rPushX(final String key, final String... values) { + return rPushX(SafeEncoder.encode(key), SafeEncoder.encode(values)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractPubSubOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractPubSubOperations.java new file mode 100644 index 000000000..c5f102a15 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractPubSubOperations.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.PubSubOperations; +import com.buession.redis.utils.SafeEncoder; + +/** + * Lettuce Pub/Sub 命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractPubSubOperations extends AbstractLettuceRedisOperations + implements PubSubOperations { + + public AbstractPubSubOperations(final C client) { + super(client); + } + + @Override + public Long publish(final String channel, final String message) { + return publish(SafeEncoder.encode(channel), SafeEncoder.encode(message)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractScriptingOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractScriptingOperations.java new file mode 100644 index 000000000..13b543ab9 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractScriptingOperations.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.ScriptingOperations; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce Script 命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractScriptingOperations + extends AbstractLettuceRedisOperations implements ScriptingOperations { + + public AbstractScriptingOperations(final C client) { + super(client); + } + + @Override + public Object eval(final byte[] script) { + return eval(SafeEncoder.encode(script)); + } + + @Override + public Object eval(final byte[] script, final byte[]... params) { + return eval(SafeEncoder.encode(script), SafeEncoder.encode(params)); + } + + @Override + public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments) { + return eval(SafeEncoder.encode(script), SafeEncoder.encode(keys), SafeEncoder.encode(arguments)); + } + + @Override + public Object evalSha(final byte[] digest) { + return evalSha(SafeEncoder.encode(digest)); + } + + @Override + public Object evalSha(final byte[] digest, final byte[]... params) { + return evalSha(SafeEncoder.encode(digest), SafeEncoder.encode(params)); + } + + @Override + public Object evalSha(final byte[] digest, final byte[][] keys, final byte[][] arguments) { + return evalSha(SafeEncoder.encode(digest), SafeEncoder.encode(keys), SafeEncoder.encode(arguments)); + } + + @Override + public List scriptExists(final byte[]... sha1) { + return scriptExists(SafeEncoder.encode(sha1)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractServerOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractServerOperations.java new file mode 100644 index 000000000..9a996e107 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractServerOperations.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.ServerOperations; +import com.buession.redis.utils.SafeEncoder; + +/** + * Lettuce 服务端命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractServerOperations extends AbstractLettuceRedisOperations + implements ServerOperations { + + public AbstractServerOperations(final C client) { + super(client); + } + + @Override + public Status configSet(final byte[] parameter, final byte[] value) { + return configSet(SafeEncoder.encode(parameter), SafeEncoder.encode(value)); + } + + @Override + public Long memoryUsage(final String key) { + return memoryUsage(SafeEncoder.encode(key)); + } + + @Override + public Long memoryUsage(final String key, final int samples) { + return memoryUsage(SafeEncoder.encode(key), samples); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractSetOperations.java new file mode 100644 index 000000000..3937547c2 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractSetOperations.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.utils.NumberUtils; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.SetOperations; +import com.buession.redis.core.ScanResult; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce 集合命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractSetOperations extends AbstractLettuceRedisOperations + implements SetOperations { + + public AbstractSetOperations(final C client) { + super(client); + } + + @Override + public Long sAdd(final String key, final String... members) { + return sAdd(SafeEncoder.encode(key), SafeEncoder.encode(members)); + } + + @Override + public Long sCard(final String key) { + return sCard(SafeEncoder.encode(key)); + } + + @Override + public Long sDiffStore(final String destKey, final String... keys) { + return sDiffStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys)); + } + + @Override + public Long sInterStore(final String destKey, final String... keys) { + return sInterStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys)); + } + + @Override + public Boolean sIsMember(final String key, final String member) { + return sIsMember(SafeEncoder.encode(key), SafeEncoder.encode(member)); + } + + @Override + public Status sMove(final String key, final String destKey, final String member) { + return sMove(SafeEncoder.encode(key), SafeEncoder.encode(destKey), SafeEncoder.encode(member)); + } + + @Override + public Long sRem(final String key, final String... members) { + return sRem(SafeEncoder.encode(key), SafeEncoder.encode(members)); + } + + @Override + public ScanResult> sScan(final String key, final long cursor) { + return sScan(key, Long.toString(cursor)); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor) { + return sScan(key, NumberUtils.long2bytes(cursor)); + } + + @Override + public ScanResult> sScan(final String key, final long cursor, final String pattern) { + return sScan(key, Long.toString(cursor), pattern); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor, final byte[] pattern) { + return sScan(key, NumberUtils.long2bytes(cursor), pattern); + } + + @Override + public ScanResult> sScan(final String key, final long cursor, final int count) { + return sScan(key, Long.toString(cursor), count); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor, final int count) { + return sScan(key, NumberUtils.long2bytes(cursor), count); + } + + @Override + public ScanResult> sScan(final String key, final long cursor, final String pattern, final int count) { + return sScan(key, Long.toString(cursor), pattern, count); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor, final byte[] pattern, final int count) { + return sScan(key, NumberUtils.long2bytes(cursor), pattern, count); + } + + @Override + public Long sUnionStore(final String destKey, final String... keys) { + return sUnionStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractSortedSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractSortedSetOperations.java new file mode 100644 index 000000000..084fba2e3 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractSortedSetOperations.java @@ -0,0 +1,254 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.utils.NumberUtils; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.SortedSetOperations; +import com.buession.redis.core.Aggregate; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce 有序集合命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractSortedSetOperations + extends AbstractLettuceRedisOperations implements SortedSetOperations { + + public AbstractSortedSetOperations(final C client) { + super(client); + } + + @Override + public Tuple zPopMin(final String key) { + return zPopMin(SafeEncoder.encode(key)); + } + + @Override + public List zPopMin(final String key, final int count) { + return zPopMin(SafeEncoder.encode(key), count); + } + + @Override + public Tuple zPopMax(final String key) { + return zPopMax(SafeEncoder.encode(key)); + } + + @Override + public List zPopMax(final String key, final int count) { + return zPopMax(SafeEncoder.encode(key), count); + } + + @Override + public Long zCard(final String key) { + return zCard(SafeEncoder.encode(key)); + } + + @Override + public Long zCount(final String key, final double min, final double max) { + return zCount(SafeEncoder.encode(key), min, max); + } + + @Override + public Double zIncrBy(final String key, final double increment, final String member) { + return zIncrBy(SafeEncoder.encode(key), increment, SafeEncoder.encode(member)); + } + + @Override + public Long zInterStore(final String destKey, final String... keys) { + return zInterStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys)); + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate) { + return zInterStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys), aggregate); + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final double... weights) { + return zInterStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys), weights); + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate, + final double... weights) { + return zInterStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys), aggregate, weights); + } + + @Override + public Long zLexCount(final String key, final double min, final double max) { + return 0L;//zLexCount(SafeEncoder.encode(key), NumberUtils.double2bytes(min), NumberUtils.double2bytes(max)); + } + + @Override + public Long zLexCount(final byte[] key, final double min, final double max) { + return 0L;//zLexCount(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max)); + } + + @Override + public List zRangeWithScores(final String key, final long start, final long end) { + return zRangeWithScores(SafeEncoder.encode(key), start, end); + } + + @Override + public List zRangeByScoreWithScores(final String key, final double min, final double max) { + return zRangeByScoreWithScores(SafeEncoder.encode(key), min, max); + } + + @Override + public List zRangeByScoreWithScores(final String key, final double min, final double max, final long offset, + final int count) { + return zRangeByScoreWithScores(SafeEncoder.encode(key), min, max, offset, count); + } + + @Override + public Long zRank(final String key, final String member) { + return zRank(SafeEncoder.encode(key), SafeEncoder.encode(member)); + } + + @Override + public Long zRem(final String key, final String... members) { + return zRem(SafeEncoder.encode(key), SafeEncoder.encode(members)); + } + + @Override + public Long zRemRangeByLex(final String key, final double min, final double max) { + return 0l;//zRemRangeByLex(SafeEncoder.encode(key), NumberUtils.double2bytes(min), + //NumberUtils.double2bytes(max)); + } + + @Override + public Long zRemRangeByLex(final byte[] key, final double min, final double max) { + return 0L;//zRemRangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max)); + } + + @Override + public Long zRemRangeByScore(final String key, final double min, final double max) { + return zRemRangeByScore(SafeEncoder.encode(key), min, max); + } + + @Override + public Long zRemRangeByRank(final String key, final long start, final long end) { + return zRemRangeByRank(SafeEncoder.encode(key), start, end); + } + + @Override + public List zRevRangeWithScores(final String key, final long start, final long end) { + return zRevRangeWithScores(SafeEncoder.encode(key), start, end); + } + + @Override + public List zRevRangeByScoreWithScores(final String key, final double min, final double max) { + return zRevRangeByScoreWithScores(SafeEncoder.encode(key), min, max); + } + + @Override + public List zRevRangeByScoreWithScores(final String key, final double min, final double max, + final long offset, final int count) { + return zRevRangeByScoreWithScores(SafeEncoder.encode(key), min, max, offset, count); + } + + @Override + public Long zRevRank(final String key, final String member) { + return zRevRank(SafeEncoder.encode(key), SafeEncoder.encode(member)); + } + + + @Override + public ScanResult> zScan(final String key, final long cursor) { + return zScan(key, Long.toString(cursor)); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor) { + return zScan(key, NumberUtils.long2bytes(cursor)); + } + + @Override + public ScanResult> zScan(final String key, final long cursor, final String pattern) { + return zScan(key, Long.toString(cursor), pattern); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor, final byte[] pattern) { + return zScan(key, NumberUtils.long2bytes(cursor), pattern); + } + + @Override + public ScanResult> zScan(final String key, final long cursor, final int count) { + return zScan(key, Long.toString(cursor), Long.toString(count)); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor, final int count) { + return zScan(key, NumberUtils.long2bytes(cursor), NumberUtils.long2bytes(count)); + } + + @Override + public ScanResult> zScan(final String key, final long cursor, final String pattern, final int count) { + return zScan(key, Long.toString(cursor), pattern, count); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor, final byte[] pattern, final int count) { + return zScan(key, NumberUtils.long2bytes(cursor), pattern, count); + } + + @Override + public Double zScore(final String key, final String member) { + return zScore(SafeEncoder.encode(key), SafeEncoder.encode(member)); + } + + @Override + public Long zUnionStore(final String destKey, final String... keys) { + return zUnionStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys)); + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate) { + return zUnionStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys), aggregate); + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final double... weights) { + return zUnionStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys), weights); + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate, + final double... weights) { + return zUnionStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys), aggregate, weights); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractStreamOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractStreamOperations.java new file mode 100644 index 000000000..22040a929 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractStreamOperations.java @@ -0,0 +1,248 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.StreamOperations; +import com.buession.redis.core.Stream; +import com.buession.redis.core.StreamConsumer; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import com.buession.redis.core.StreamGroup; +import com.buession.redis.core.StreamPending; +import com.buession.redis.core.StreamPendingSummary; +import com.buession.redis.core.command.args.XAddArgument; +import com.buession.redis.core.command.args.XClaimArgument; +import com.buession.redis.core.command.args.XTrimArgument; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce Stream 命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractStreamOperations extends AbstractLettuceRedisOperations + implements StreamOperations { + + public AbstractStreamOperations(final C client) { + super(client); + } + + @Override + public Long xAck(final String key, final String groupName, final StreamEntryId... ids) { + return xAck(SafeEncoder.encode(key), SafeEncoder.encode(groupName), ids); + } + + @Override + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash) { + return xAdd(SafeEncoder.encode(key), id, Converters.mapStringToBinary().convert(hash)); + } + + @Override + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + return xAdd(SafeEncoder.encode(key), id, Converters.mapStringToBinary().convert(hash), + xAddArgument); + } + + @Override + public List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId... ids) { + return xClaim(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), + minIdleTime, ids); + } + + @Override + public List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + return xClaim(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), + minIdleTime, ids, xClaimArgument); + } + + @Override + public List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId... ids) { + return xClaimJustId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), + minIdleTime, ids); + } + + @Override + public List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + return xClaimJustId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), + minIdleTime, ids, xClaimArgument); + } + + @Override + public Long xDel(final String key, final StreamEntryId... ids) { + return xDel(SafeEncoder.encode(key), ids); + } + + @Override + public Status xGroupCreate(final String key, final String groupName, final StreamEntryId id, + final boolean makeStream) { + return xGroupCreate(SafeEncoder.encode(key), SafeEncoder.encode(groupName), id, makeStream); + } + + @Override + public Long xGroupDelConsumer(final String key, final String groupName, final String consumerName) { + return xGroupDelConsumer(SafeEncoder.encode(key), SafeEncoder.encode(groupName), + SafeEncoder.encode(consumerName)); + } + + @Override + public Status xGroupDestroy(final String key, final String groupName) { + return xGroupDestroy(SafeEncoder.encode(key), SafeEncoder.encode(groupName)); + } + + @Override + public Status xGroupSetId(final String key, final String groupName, final StreamEntryId id) { + return xGroupSetId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), id); + } + + @Override + public List xInfoConsumers(final String key, final String groupName) { + return xInfoConsumers(SafeEncoder.encode(key), SafeEncoder.encode(groupName)); + } + + @Override + public List xInfoGroups(final String key) { + return xInfoGroups(SafeEncoder.encode(key)); + } + + @Override + public Stream xInfoStream(final String key) { + return xInfoStream(SafeEncoder.encode(key)); + } + + @Override + public StreamFull xInfoStream(final String key, final boolean full) { + return xInfoStream(SafeEncoder.encode(key), full); + } + + @Override + public StreamFull xInfoStream(final String key, final boolean full, final int count) { + return xInfoStream(SafeEncoder.encode(key), full, count); + } + + @Override + public Long xLen(final String key) { + return xLen(SafeEncoder.encode(key)); + } + + @Override + public StreamPendingSummary xPending(final String key, final String groupName) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName)); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime); + } + + @Override + public List xPending(final String key, final String groupName, final StreamEntryId start, + final StreamEntryId end, final int count) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), start, end, count); + } + + @Override + public List xPending(final String key, final String groupName, final String consumerName) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName)); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime, start, end, count); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final String consumerName) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime, + SafeEncoder.encode(consumerName)); + } + + @Override + public List xPending(final String key, final String groupName, final StreamEntryId start, + final StreamEntryId end, final int count, final String consumerName) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), start, end, count, + SafeEncoder.encode(consumerName)); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count, + final String consumerName) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime, start, end, count, + SafeEncoder.encode(consumerName)); + } + + @Override + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end) { + return xRange(SafeEncoder.encode(key), start, end); + } + + @Override + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end, + final int count) { + return xRange(SafeEncoder.encode(key), start, end, count); + } + + @Override + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start) { + return xRevRange(SafeEncoder.encode(key), end, start); + } + + @Override + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start, + final int count) { + return xRevRange(SafeEncoder.encode(key), end, start, count); + } + + @Override + public Long xTrim(final String key, final XTrimArgument xTrimArgument) { + return xTrim(SafeEncoder.encode(key), xTrimArgument); + } + + @Override + public Long xTrim(final String key, final XTrimArgument xTrimArgument, final long limit) { + return xTrim(SafeEncoder.encode(key), xTrimArgument, limit); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractStringOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractStringOperations.java new file mode 100644 index 000000000..5119f9dc4 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractStringOperations.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.StringOperations; +import com.buession.redis.core.command.args.SetArgument; +import com.buession.redis.utils.SafeEncoder; + +/** + * Lettuce 字符串命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractStringOperations extends AbstractLettuceRedisOperations + implements StringOperations { + + public AbstractStringOperations(final C client) { + super(client); + } + + @Override + public Long append(final String key, final String value) { + return append(SafeEncoder.encode(key), SafeEncoder.encode(value)); + } + + @Override + public Long incr(final String key) { + return incr(SafeEncoder.encode(key)); + } + + @Override + public Long incrBy(final String key, final long value) { + return incrBy(SafeEncoder.encode(key), value); + } + + @Override + public Double incrByFloat(final String key, final double value) { + return incrByFloat(SafeEncoder.encode(key), value); + } + + @Override + public Long decr(final String key) { + return decr(SafeEncoder.encode(key)); + } + + @Override + public Long decrBy(final String key, final long value) { + return decrBy(SafeEncoder.encode(key), value); + } + + @Override + public Status pSetEx(final String key, final String value, final int lifetime) { + return pSetEx(SafeEncoder.encode(key), SafeEncoder.encode(value), lifetime); + } + + @Override + public Status set(final String key, final String value) { + return set(SafeEncoder.encode(key), SafeEncoder.encode(value)); + } + + @Override + public Status set(final String key, final String value, final SetArgument setArgument) { + return set(SafeEncoder.encode(key), SafeEncoder.encode(value), setArgument); + } + + @Override + public Status setEx(final String key, final String value, final int lifetime) { + return setEx(SafeEncoder.encode(key), SafeEncoder.encode(value), lifetime); + } + + @Override + public Status setNx(final String key, final String value) { + return setNx(SafeEncoder.encode(key), SafeEncoder.encode(value)); + } + + @Override + public Long setRange(final String key, final long offset, final String value) { + return setRange(SafeEncoder.encode(key), offset, SafeEncoder.encode(value)); + } + + @Override + public String getRange(final String key, final long start, final long end) { + return SafeEncoder.encode(getRange(SafeEncoder.encode(key), start, end)); + } + + @Override + public Long strlen(final String key) { + return strlen(SafeEncoder.encode(key)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractTransactionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractTransactionOperations.java new file mode 100644 index 000000000..f5d44804d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/AbstractTransactionOperations.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.TransactionOperations; +import com.buession.redis.utils.SafeEncoder; + +/** + * Lettuce 事务命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractTransactionOperations + extends AbstractLettuceRedisOperations implements TransactionOperations { + + public AbstractTransactionOperations(final C client) { + super(client); + } + + @Override + public Status watch(final String... keys) { + return watch(SafeEncoder.encode(keys)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceAclOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceAclOperations.java new file mode 100644 index 000000000..3d42b94d4 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceAclOperations.java @@ -0,0 +1,366 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.SetListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.AclCategory; +import com.buession.redis.core.AclLog; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.AclSetUserArgument; +import com.buession.redis.core.internal.convert.lettuce.response.AclCategoryConverter; +import com.buession.redis.core.internal.convert.lettuce.response.AclGetUserConverter; +import com.buession.redis.core.internal.convert.lettuce.response.AclLogConverter; +import com.buession.redis.core.internal.convert.lettuce.response.CommandTypeConverter; +import com.buession.redis.core.internal.lettuce.LettuceAclSetuserArgs; +import io.lettuce.core.AclSetuserArgs; +import io.lettuce.core.protocol.CommandType; + +import java.util.List; + +/** + * Lettuce 单机模式权限命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceAclOperations extends AbstractAclOperations { + + public LettuceAclOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public List aclCat() { + final SetListConverter converter = AclCategoryConverter.setListConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ACL, SubCommand.ACL_CAT, (cmd)->cmd.aclCat(), converter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ACL, SubCommand.ACL_CAT, (cmd)->cmd.aclCat(), + converter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.ACL_CAT, (cmd)->cmd.aclCat(), converter) + .run(); + } + } + + @Override + public List aclCat(final AclCategory aclCategory) { + final CommandArguments args = CommandArguments.create(aclCategory); + final io.lettuce.core.AclCategory aclCate = + (new com.buession.redis.core.internal.convert.lettuce.params.AclCategoryConverter()).convert( + aclCategory); + final SetListConverter converter = CommandTypeConverter.setListConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ACL, SubCommand.ACL_CAT, (cmd)->cmd.aclCat(aclCate), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ACL, SubCommand.ACL_CAT, (cmd)->cmd.aclCat(aclCate), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.ACL_CAT, (cmd)->cmd.aclCat(aclCate), converter) + .run(args); + } + } + + @Override + public Long aclDelUser(final String... usernames) { + final CommandArguments args = CommandArguments.create(usernames); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ACL, SubCommand.ACL_DELUSER, + (cmd)->cmd.aclDeluser(usernames), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ACL, SubCommand.ACL_DELUSER, + (cmd)->cmd.aclDeluser(usernames), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.ACL_DELUSER, (cmd)->cmd.aclDeluser(usernames), + (v)->v) + .run(args); + } + } + + @Override + public Status aclDryRun(final String username, final Command command) { + final CommandArguments args = CommandArguments.create(username).add(command); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName()), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName()), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName()), okStatusConverter) + .run(args); + } + } + + @Override + public Status aclDryRun(final String username, final Command command, final String... arguments) { + final CommandArguments args = CommandArguments.create(username).add(command).add(arguments); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName(), arguments), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName(), arguments), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName(), arguments), okStatusConverter) + .run(args); + } + } + + @Override + public String aclGenPass() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, (cmd)->cmd.aclGenpass(), + (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, (cmd)->cmd.aclGenpass(), + (v)->v) + .run(); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, (cmd)->cmd.aclGenpass(), (v)->v) + .run(); + } + } + + @Override + public String aclGenPass(final int bits) { + final CommandArguments args = CommandArguments.create(bits); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, + (cmd)->cmd.aclGenpass(bits), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, + (cmd)->cmd.aclGenpass(bits), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, (cmd)->cmd.aclGenpass(bits), + (v)->v) + .run(args); + } + } + + @Override + public AclUser aclGetUser(final String username) { + final CommandArguments args = CommandArguments.create(username); + final AclGetUserConverter aclGetUserConverter = new AclGetUserConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ACL, SubCommand.ACL_GETUSER, + (cmd)->cmd.aclGetuser(username), aclGetUserConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ACL, SubCommand.ACL_GETUSER, + (cmd)->cmd.aclGetuser(username), aclGetUserConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.ACL_GETUSER, (cmd)->cmd.aclGetuser(username), + aclGetUserConverter) + .run(args); + } + } + + @Override + public List aclList() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ACL, SubCommand.LIST, (cmd)->cmd.aclList(), + (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ACL, SubCommand.LIST, (cmd)->cmd.aclList(), + (v)->v) + .run(); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.LIST, (cmd)->cmd.aclList(), + (v)->v) + .run(); + } + } + + @Override + public Status aclLoad() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ACL, SubCommand.LOAD, (cmd)->cmd.aclLoad(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ACL, SubCommand.LOAD, (cmd)->cmd.aclLoad(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.LOAD, (cmd)->cmd.aclLoad(), + okStatusConverter) + .run(); + } + } + + @Override + public List aclLog() { + final AclLogConverter aclLogConverter = new AclLogConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, Command.ACL, SubCommand.ACL_LOG) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, Command.ACL, SubCommand.ACL_LOG) + .run(); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.ACL_LOG, (cmd)->cmd.aclLog(), aclLogConverter) + .run(); + } + } + + @Override + public List aclLog(final int count) { + final CommandArguments args = CommandArguments.create(count); + final AclLogConverter aclLogConverter = new AclLogConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, Command.ACL, SubCommand.ACL_LOG) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, Command.ACL, SubCommand.ACL_LOG) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.ACL_LOG, (cmd)->cmd.aclLog(count), + aclLogConverter) + .run(args); + } + } + + @Override + public Status aclLogReset() { + final CommandArguments args = CommandArguments.create(SubCommand.RESET); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ACL, SubCommand.ACL_LOG, (cmd)->cmd.aclLogReset(), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ACL, SubCommand.ACL_LOG, (cmd)->cmd.aclLogReset(), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.ACL_LOG, (cmd)->cmd.aclLogReset(), + okStatusConverter) + .run(args); + } + } + + @Override + public Status aclSave() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ACL, SubCommand.SAVE, (cmd)->cmd.aclSave(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ACL, SubCommand.SAVE, (cmd)->cmd.aclSave(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.SAVE, (cmd)->cmd.aclSave(), + okStatusConverter) + .run(); + } + } + + @Override + public Status aclSetUser(final String username, final AclSetUserArgument rules) { + final CommandArguments args = CommandArguments.create(username).add(rules); + final AclSetuserArgs aclSetuserArgs = LettuceAclSetuserArgs.from(rules); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ACL, SubCommand.ACL_SETUSER, + (cmd)->cmd.aclSetuser(username, aclSetuserArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ACL, SubCommand.ACL_SETUSER, + (cmd)->cmd.aclSetuser(username, aclSetuserArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.ACL_SETUSER, + (cmd)->cmd.aclSetuser(username, aclSetuserArgs), okStatusConverter) + .run(args); + } + } + + @Override + public List aclUsers() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ACL, SubCommand.ACL_USERS, (cmd)->cmd.aclUsers(), + (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ACL, SubCommand.ACL_USERS, (cmd)->cmd.aclUsers(), + (v)->v) + .run(); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.ACL_USERS, (cmd)->cmd.aclUsers(), (v)->v) + .run(); + } + } + + @Override + public String aclWhoAmI() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ACL, SubCommand.ACL_WHOAMI, (cmd)->cmd.aclWhoami(), + (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ACL, SubCommand.ACL_WHOAMI, (cmd)->cmd.aclWhoami(), + (v)->v) + .run(); + }else{ + return new LettuceCommand<>(client, Command.ACL, SubCommand.ACL_WHOAMI, (cmd)->cmd.aclWhoami(), (v)->v) + .run(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceBitMapOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceBitMapOperations.java new file mode 100644 index 000000000..dec3e9100 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceBitMapOperations.java @@ -0,0 +1,332 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.BitType; +import com.buession.redis.core.BitOperation; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.BitFieldArgument; +import com.buession.redis.core.command.args.BitFieldRoArgument; +import com.buession.redis.core.internal.lettuce.LettuceBitFieldArgs; +import io.lettuce.core.BitFieldArgs; + +import java.util.List; + +/** + * Lettuce 单机模式 BitMap 命令操作抽象类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceBitMapOperations extends AbstractBitMapOperations { + + public LettuceBitMapOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Long bitCount(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end).add(bitType); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List bitField(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final BitFieldArgs bitFieldArgs = new LettuceBitFieldArgs(); + + return bitField(key, bitFieldArgs, args); + } + + @Override + public List bitField(final byte[] key, final BitFieldArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + final BitFieldArgs bitFieldArgs = LettuceBitFieldArgs.from(argument); + + return bitField(key, bitFieldArgs, args); + } + + @Override + public List bitFieldRo(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.BITFIELD_RO, args); + } + + @Override + public List bitFieldRo(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.BITFIELD_RO, args); + } + + @Override + public List bitFieldRo(final String key, final BitFieldRoArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + return notCommand(client, Command.BITFIELD_RO, args); + } + + @Override + public List bitFieldRo(final byte[] key, final BitFieldRoArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + return notCommand(client, Command.BITFIELD_RO, args); + } + + @Override + public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(operation).add(destKey).add(keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BITOP, (cmd)->{ + if(operation == BitOperation.AND){ + return cmd.bitopAnd(destKey, keys); + }else if(operation == BitOperation.OR){ + return cmd.bitopOr(destKey, keys); + }else if(operation == BitOperation.NOT){ + return cmd.bitopNot(destKey, keys[0]); + }else if(operation == BitOperation.XOR){ + return cmd.bitopXor(destKey, keys); + }else{ + return null; + } + }, (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BITOP, (cmd)->{ + if(operation == BitOperation.AND){ + return cmd.bitopAnd(destKey, keys); + }else if(operation == BitOperation.OR){ + return cmd.bitopOr(destKey, keys); + }else if(operation == BitOperation.NOT){ + return cmd.bitopNot(destKey, keys[0]); + }else if(operation == BitOperation.XOR){ + return cmd.bitopXor(destKey, keys); + }else{ + return null; + } + }, (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BITOP, (cmd)->{ + if(operation == BitOperation.AND){ + return cmd.bitopAnd(destKey, keys); + }else if(operation == BitOperation.OR){ + return cmd.bitopOr(destKey, keys); + }else if(operation == BitOperation.NOT){ + return cmd.bitopNot(destKey, keys[0]); + }else if(operation == BitOperation.XOR){ + return cmd.bitopXor(destKey, keys); + }else{ + return null; + } + }, (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(bitType); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start, end), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start, end), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end).add(bitType); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start, end), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start, end), (v)->v) + .run(args); + } + } + + @Override + public Boolean getBit(final byte[] key, final long offset) { + final CommandArguments args = CommandArguments.create(key).add(offset); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), + oneBooleanConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), + oneBooleanConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), oneBooleanConverter) + .run(args); + } + } + + @Override + public Boolean setBit(final byte[] key, final long offset, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(offset).add(value); + final int iValue = value ? 1 : 0; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, iValue), + oneBooleanConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, iValue), + oneBooleanConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, iValue), + oneBooleanConverter) + .run(args); + } + } + + private List bitField(final byte[] key, final BitFieldArgs bitFieldArgs, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, bitFieldArgs), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, bitFieldArgs), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, bitFieldArgs), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterAclOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterAclOperations.java new file mode 100644 index 000000000..830603e3d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterAclOperations.java @@ -0,0 +1,373 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.SetListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.AclCategory; +import com.buession.redis.core.AclLog; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.AclSetUserArgument; +import com.buession.redis.core.internal.convert.lettuce.response.AclCategoryConverter; +import com.buession.redis.core.internal.convert.lettuce.response.AclGetUserConverter; +import com.buession.redis.core.internal.convert.lettuce.response.AclLogConverter; +import com.buession.redis.core.internal.convert.lettuce.response.CommandTypeConverter; +import com.buession.redis.core.internal.lettuce.LettuceAclSetuserArgs; +import io.lettuce.core.AclSetuserArgs; +import io.lettuce.core.protocol.CommandType; + +import java.util.List; + +/** + * Lettuce 集群模式权限命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterAclOperations extends AbstractAclOperations { + + public LettuceClusterAclOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public List aclCat() { + final SetListConverter converter = AclCategoryConverter.setListConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ACL, SubCommand.ACL_CAT, (cmd)->cmd.aclCat(), + converter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ACL, SubCommand.ACL_CAT, (cmd)->cmd.aclCat(), + converter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.ACL_CAT, (cmd)->cmd.aclCat(), converter) + .run(); + } + } + + @Override + public List aclCat(final AclCategory aclCategory) { + final CommandArguments args = CommandArguments.create(aclCategory); + final io.lettuce.core.AclCategory aclCate = + (new com.buession.redis.core.internal.convert.lettuce.params.AclCategoryConverter()).convert( + aclCategory); + final SetListConverter converter = CommandTypeConverter.setListConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ACL, SubCommand.ACL_CAT, + (cmd)->cmd.aclCat(aclCate), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ACL, SubCommand.ACL_CAT, + (cmd)->cmd.aclCat(aclCate), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.ACL_CAT, (cmd)->cmd.aclCat(aclCate), + converter) + .run(args); + } + } + + @Override + public Long aclDelUser(final String... usernames) { + final CommandArguments args = CommandArguments.create(usernames); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ACL, SubCommand.ACL_DELUSER, + (cmd)->cmd.aclDeluser(usernames), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ACL, SubCommand.ACL_DELUSER, + (cmd)->cmd.aclDeluser(usernames), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.ACL_DELUSER, + (cmd)->cmd.aclDeluser(usernames), (v)->v) + .run(args); + } + } + + @Override + public Status aclDryRun(final String username, final Command command) { + final CommandArguments args = CommandArguments.create(username).add(command); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName()), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName()), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName()), okStatusConverter) + .run(args); + } + } + + @Override + public Status aclDryRun(final String username, final Command command, final String... arguments) { + final CommandArguments args = CommandArguments.create(username).add(command).add(arguments); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName(), arguments), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName(), arguments), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.ACL_DRYRUN, + (cmd)->cmd.aclDryRun(username, command.getName(), arguments), okStatusConverter) + .run(args); + } + } + + @Override + public String aclGenPass() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, + (cmd)->cmd.aclGenpass(), (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, + (cmd)->cmd.aclGenpass(), (v)->v) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, (cmd)->cmd.aclGenpass(), + (v)->v) + .run(); + } + } + + @Override + public String aclGenPass(final int bits) { + final CommandArguments args = CommandArguments.create(bits); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, + (cmd)->cmd.aclGenpass(bits), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, + (cmd)->cmd.aclGenpass(bits), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.ACL_GENPASS, (cmd)->cmd.aclGenpass(bits), + (v)->v) + .run(args); + } + } + + @Override + public AclUser aclGetUser(final String username) { + final CommandArguments args = CommandArguments.create(username); + final AclGetUserConverter aclGetUserConverter = new AclGetUserConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.ACL, SubCommand.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.ACL, SubCommand.ACL_GETUSER) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.ACL_GETUSER, + (cmd)->cmd.aclGetuser(username), aclGetUserConverter) + .run(args); + } + } + + @Override + public List aclList() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ACL, SubCommand.LIST, (cmd)->cmd.aclList(), + (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ACL, SubCommand.LIST, (cmd)->cmd.aclList(), + (v)->v) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.LIST, (cmd)->cmd.aclList(), (v)->v) + .run(); + } + } + + @Override + public Status aclLoad() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ACL, SubCommand.LOAD, (cmd)->cmd.aclLoad(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ACL, SubCommand.LOAD, (cmd)->cmd.aclLoad(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.LOAD, (cmd)->cmd.aclLoad(), + okStatusConverter) + .run(); + } + } + + @Override + public List aclLog() { + final AclLogConverter aclLogConverter = new AclLogConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, Command.ACL, + SubCommand.ACL_LOG) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, Command.ACL, + SubCommand.ACL_LOG) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.ACL_LOG, (cmd)->cmd.aclLog(), + aclLogConverter) + .run(); + } + } + + @Override + public List aclLog(final int count) { + final CommandArguments args = CommandArguments.create(count); + final AclLogConverter aclLogConverter = new AclLogConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, Command.ACL, + SubCommand.ACL_LOG) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, Command.ACL, + SubCommand.ACL_LOG) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.ACL_LOG, (cmd)->cmd.aclLog(count), + aclLogConverter) + .run(args); + } + } + + @Override + public Status aclLogReset() { + final CommandArguments args = CommandArguments.create(SubCommand.RESET); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ACL, SubCommand.ACL_LOG, + (cmd)->cmd.aclLogReset(), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ACL, SubCommand.ACL_LOG, + (cmd)->cmd.aclLogReset(), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.ACL_LOG, (cmd)->cmd.aclLogReset(), + okStatusConverter) + .run(args); + } + } + + @Override + public Status aclSave() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ACL, SubCommand.SAVE, (cmd)->cmd.aclSave(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ACL, SubCommand.SAVE, (cmd)->cmd.aclSave(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.SAVE, (cmd)->cmd.aclSave(), + okStatusConverter) + .run(); + } + } + + @Override + public Status aclSetUser(final String username, final AclSetUserArgument rules) { + final CommandArguments args = CommandArguments.create(username).add(rules); + final AclSetuserArgs aclSetuserArgs = LettuceAclSetuserArgs.from(rules); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ACL, SubCommand.ACL_SETUSER, + (cmd)->cmd.aclSetuser(username, aclSetuserArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ACL, SubCommand.ACL_SETUSER, + (cmd)->cmd.aclSetuser(username, aclSetuserArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.ACL_SETUSER, + (cmd)->cmd.aclSetuser(username, aclSetuserArgs), okStatusConverter) + .run(args); + } + } + + @Override + public List aclUsers() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ACL, SubCommand.ACL_USERS, (cmd)->cmd.aclUsers(), + (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ACL, SubCommand.ACL_USERS, + (cmd)->cmd.aclUsers(), (v)->v) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.ACL_USERS, (cmd)->cmd.aclUsers(), + (v)->v) + .run(); + } + } + + @Override + public String aclWhoAmI() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ACL, SubCommand.ACL_WHOAMI, + (cmd)->cmd.aclWhoami(), (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ACL, SubCommand.ACL_WHOAMI, + (cmd)->cmd.aclWhoami(), (v)->v) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.ACL, SubCommand.ACL_WHOAMI, (cmd)->cmd.aclWhoami(), + (v)->v) + .run(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterBitMapOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterBitMapOperations.java new file mode 100644 index 000000000..bbe1b9609 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterBitMapOperations.java @@ -0,0 +1,343 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.BitType; +import com.buession.redis.core.BitOperation; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.BitFieldArgument; +import com.buession.redis.core.command.args.BitFieldRoArgument; +import com.buession.redis.core.internal.lettuce.LettuceBitFieldArgs; +import io.lettuce.core.BitFieldArgs; + +import java.util.List; + +/** + * Lettuce 集群模式 BitMap 命令操作抽象类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterBitMapOperations extends AbstractBitMapOperations { + + public LettuceClusterBitMapOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Long bitCount(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end).add(bitType); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public List bitField(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final BitFieldArgs bitFieldArgs = new LettuceBitFieldArgs(); + + return bitField(key, bitFieldArgs, args); + } + + @Override + public List bitField(final byte[] key, final BitFieldArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + final BitFieldArgs bitFieldArgs = LettuceBitFieldArgs.from(argument); + + return bitField(key, bitFieldArgs, args); + } + + @Override + public List bitFieldRo(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.BITFIELD_RO, args); + } + + @Override + public List bitFieldRo(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.BITFIELD_RO, args); + } + + @Override + public List bitFieldRo(final String key, final BitFieldRoArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + return notCommand(client, Command.BITCOUNT, args); + } + + @Override + public List bitFieldRo(final byte[] key, final BitFieldRoArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + return notCommand(client, Command.BITCOUNT, args); + } + + @Override + public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(operation).add(destKey).add(keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BITOP, (cmd)->{ + if(operation == BitOperation.AND){ + return cmd.bitopAnd(destKey, keys); + }else if(operation == BitOperation.OR){ + return cmd.bitopOr(destKey, keys); + }else if(operation == BitOperation.NOT){ + return cmd.bitopNot(destKey, keys[0]); + }else if(operation == BitOperation.XOR){ + return cmd.bitopXor(destKey, keys); + }else{ + return null; + } + }, (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BITOP, (cmd)->{ + if(operation == BitOperation.AND){ + return cmd.bitopAnd(destKey, keys); + }else if(operation == BitOperation.OR){ + return cmd.bitopOr(destKey, keys); + }else if(operation == BitOperation.NOT){ + return cmd.bitopNot(destKey, keys[0]); + }else if(operation == BitOperation.XOR){ + return cmd.bitopXor(destKey, keys); + }else{ + return null; + } + }, (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BITOP, (cmd)->{ + if(operation == BitOperation.AND){ + return cmd.bitopAnd(destKey, keys); + }else if(operation == BitOperation.OR){ + return cmd.bitopOr(destKey, keys); + }else if(operation == BitOperation.NOT){ + return cmd.bitopNot(destKey, keys[0]); + }else if(operation == BitOperation.XOR){ + return cmd.bitopXor(destKey, keys); + }else{ + return null; + } + }, (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(bitType); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BITPOS, + (cmd)->cmd.bitpos(key, value, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BITPOS, + (cmd)->cmd.bitpos(key, value, start, end), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start, end), + (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end).add(bitType); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BITPOS, + (cmd)->cmd.bitpos(key, value, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BITPOS, + (cmd)->cmd.bitpos(key, value, start, end), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BITPOS, (cmd)->cmd.bitpos(key, value, start, end), + (v)->v) + .run(args); + } + } + + @Override + public Boolean getBit(final byte[] key, final long offset) { + final CommandArguments args = CommandArguments.create(key).add(offset); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), + oneBooleanConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), + oneBooleanConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GETBIT, (cmd)->cmd.getbit(key, offset), + oneBooleanConverter) + .run(args); + } + } + + @Override + public Boolean setBit(final byte[] key, final long offset, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(offset).add(value); + final int iValue = value ? 1 : 0; + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, iValue), + oneBooleanConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SETBIT, + (cmd)->cmd.setbit(key, offset, iValue), oneBooleanConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SETBIT, (cmd)->cmd.setbit(key, offset, iValue), + oneBooleanConverter) + .run(args); + } + } + + private List bitField(final byte[] key, final BitFieldArgs bitFieldArgs, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, bitFieldArgs), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BITFIELD, + (cmd)->cmd.bitfield(key, bitFieldArgs), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BITFIELD, (cmd)->cmd.bitfield(key, bitFieldArgs), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterClusterOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterClusterOperations.java new file mode 100644 index 000000000..45242216e --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterClusterOperations.java @@ -0,0 +1,639 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.BumpEpoch; +import com.buession.redis.core.ClusterFailoverOption; +import com.buession.redis.core.ClusterInfo; +import com.buession.redis.core.ClusterLink; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.ClusterResetOption; +import com.buession.redis.core.ClusterSetSlotOption; +import com.buession.redis.core.ClusterRedisShard; +import com.buession.redis.core.ClusterSlot; +import com.buession.redis.core.SlotRange; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ClusterReplicasConverter; +import com.buession.redis.core.internal.convert.response.BumpEpochConverter; +import com.buession.redis.core.internal.convert.response.ClusterInfoConverter; +import com.buession.redis.core.internal.convert.response.ClusterNodeConverter; +import com.buession.redis.core.internal.convert.response.ClusterNodesConverter; +import com.buession.redis.core.internal.convert.response.ClusterSlotConverter; +import io.lettuce.core.Range; + +import java.util.List; + +/** + * Lettuce 集群模式集群命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterClusterOperations extends AbstractClusterOperations { + + public LettuceClusterClusterOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Status asking() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ASKING, (cmd)->cmd.asking(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ASKING, (cmd)->cmd.asking(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.ASKING, (cmd)->cmd.asking(), okStatusConverter) + .run(); + } + } + + @Override + public Status clusterAddSlots(final int... slots) { + final CommandArguments args = CommandArguments.create(slots); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTS, + (cmd)->cmd.clusterAddSlots(slots), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTS, + (cmd)->cmd.clusterAddSlots(slots), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTS, + (cmd)->cmd.clusterAddSlots(slots), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterAddSlotsRange(final SlotRange... slots) { + final CommandArguments args = CommandArguments.create(slots); + final Range[] slotsRanges = numberRangeArrayToRange(slots); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTSRANGE, + (cmd)->cmd.clusterAddSlotsRange(slotsRanges), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTSRANGE, + (cmd)->cmd.clusterAddSlotsRange(slotsRanges), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTSRANGE, + (cmd)->cmd.clusterAddSlotsRange(slotsRanges), okStatusConverter) + .run(args); + } + } + + @Override + public KeyValue clusterBumpEpoch() { + final BumpEpochConverter bumpEpochConverter = new BumpEpochConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_BUMPEPOCH, + (cmd)->cmd.clusterBumpepoch(), bumpEpochConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_BUMPEPOCH, + (cmd)->cmd.clusterBumpepoch(), bumpEpochConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_BUMPEPOCH, + (cmd)->cmd.clusterBumpepoch(), bumpEpochConverter) + .run(); + } + } + + @Override + public Long clusterCountFailureReports(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTFAILUREREPORTS, + (cmd)->cmd.clusterCountFailureReports(nodeId), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, + SubCommand.CLUSTER_COUNTFAILUREREPORTS, (cmd)->cmd.clusterCountFailureReports(nodeId), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTFAILUREREPORTS, + (cmd)->cmd.clusterCountFailureReports(nodeId), (v)->v) + .run(args); + } + } + + @Override + public Long clusterCountKeysInSlot(final int slot) { + final CommandArguments args = CommandArguments.create(slot); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + } + } + + @Override + public Status clusterDelSlots(final int... slots) { + final CommandArguments args = CommandArguments.create(slots); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTS, + (cmd)->cmd.clusterDelSlots(slots), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTS, + (cmd)->cmd.clusterDelSlots(slots), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTS, + (cmd)->cmd.clusterDelSlots(slots), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterDelSlotsRange(final SlotRange... slots) { + final CommandArguments args = CommandArguments.create(slots); + final Range[] slotRanges = numberRangeArrayToRange(slots); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTSRANGE, + (cmd)->cmd.clusterDelSlotsRange(slotRanges), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTSRANGE, + (cmd)->cmd.clusterDelSlotsRange(slotRanges), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTSRANGE, + (cmd)->cmd.clusterDelSlotsRange(slotRanges), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption) { + final CommandArguments args = CommandArguments.create(clusterFailoverOption); + final boolean force = ClusterFailoverOption.FORCE == clusterFailoverOption; + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FAILOVER, + (cmd)->cmd.clusterFailover(force), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FAILOVER, + (cmd)->cmd.clusterFailover(force), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FAILOVER, + (cmd)->cmd.clusterFailover(force), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterFlushSlots() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FLUSHSLOTS, + (cmd)->cmd.clusterFlushslots(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FLUSHSLOTS, + (cmd)->cmd.clusterFlushslots(), okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FLUSHSLOTS, + (cmd)->cmd.clusterFlushslots(), okStatusConverter) + .run(); + } + } + + @Override + public Status clusterForget(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FORGET, + (cmd)->cmd.clusterForget(nodeId), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FORGET, + (cmd)->cmd.clusterForget(nodeId), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FORGET, + (cmd)->cmd.clusterForget(nodeId), okStatusConverter) + .run(args); + } + } + + @Override + public List clusterGetKeysInSlot(final int slot, final int count) { + final CommandArguments args = CommandArguments.create(slot).add(count); + final ListConverter listConverter = Converters.listBinaryToString(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, count), listConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, count), listConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, count), listConverter) + .run(args); + } + } + + @Override + public ClusterInfo clusterInfo() { + final ClusterInfoConverter clusterInfoConverter = new ClusterInfoConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.INFO, + (cmd)->cmd.clusterInfo(), clusterInfoConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.INFO, + (cmd)->cmd.clusterInfo(), clusterInfoConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.INFO, (cmd)->cmd.clusterInfo(), + clusterInfoConverter) + .run(); + } + } + + @Override + public Long clusterKeySlot(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterKeyslot(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterKeyslot(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterKeyslot(key), (v)->v) + .run(args); + } + } + + @Override + public List clusterLinks() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_LINKS); + } + + @Override + public Status clusterMeet(final String ip, final int port) { + final CommandArguments args = CommandArguments.create(ip).add(port); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MEET, + (cmd)->cmd.clusterMeet(ip, port), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MEET, + (cmd)->cmd.clusterMeet(ip, port), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MEET, + (cmd)->cmd.clusterMeet(ip, port), okStatusConverter) + .run(args); + } + } + + @Override + public String clusterMyId() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MYID, + (cmd)->cmd.clusterMyId(), (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MYID, + (cmd)->cmd.clusterMyId(), (v)->v) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MYID, + (cmd)->cmd.clusterMyId(), (v)->v) + .run(); + } + } + + @Override + public String clusterMyShardId() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MYSHARDID); + } + + @Override + public List clusterNodes() { + final ClusterNodesConverter clusterNodesConverter = new ClusterNodesConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.NODES, + (cmd)->cmd.clusterNodes(), + clusterNodesConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.NODES, + (cmd)->cmd.clusterNodes(), clusterNodesConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.NODES, (cmd)->cmd.clusterNodes(), + clusterNodesConverter) + .run(); + } + } + + @Override + public List clusterReplicas(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + final ClusterReplicasConverter clusterReplicasConverter = new ClusterReplicasConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICAS, + (cmd)->cmd.clusterReplicate(nodeId), clusterReplicasConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICAS, + (cmd)->cmd.clusterReplicate(nodeId), clusterReplicasConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICAS, + (cmd)->cmd.clusterReplicate(nodeId), clusterReplicasConverter) + .run(args); + } + } + + @Override + public Status clusterReplicate(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICATE, + (cmd)->cmd.clusterReplicate(nodeId), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICATE, + (cmd)->cmd.clusterReplicate(nodeId), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICATE, + (cmd)->cmd.clusterReplicate(nodeId), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterReset(final ClusterResetOption clusterResetOption) { + final CommandArguments args = CommandArguments.create(clusterResetOption); + final boolean hard = ClusterResetOption.HARD == clusterResetOption; + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.RESET, + (cmd)->cmd.clusterReset(hard), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.RESET, + (cmd)->cmd.clusterReset(hard), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.RESET, (cmd)->cmd.clusterReset(hard), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterSaveConfig() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SAVECONFIG, + (cmd)->cmd.clusterSaveconfig(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SAVECONFIG, + (cmd)->cmd.clusterSaveconfig(), okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SAVECONFIG, + (cmd)->cmd.clusterSaveconfig(), okStatusConverter) + .run(); + } + } + + @Override + public Status clusterSetConfigEpoch(final long configEpoch) { + final CommandArguments args = CommandArguments.create(configEpoch); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId) { + final CommandArguments args = CommandArguments.create(slot).add(setSlotOption).add(nodeId); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + } + } + + @Override + public List clusterShards() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SHARDS, + (cmd)->cmd.clusterShards(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SHARDS, + (cmd)->cmd.clusterShards(), okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SHARDS, + (cmd)->cmd.clusterShards(), okStatusConverter) + .run(); + } + } + + @Override + public List clusterSlaves(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + final ListConverter listClusterNodeConverter = ClusterNodeConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.SLAVES, + (cmd)->cmd.clusterSlaves(nodeId), listClusterNodeConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.SLAVES, + (cmd)->cmd.clusterSlaves(nodeId), listClusterNodeConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.SLAVES, + (cmd)->cmd.clusterSlaves(nodeId), listClusterNodeConverter) + .run(args); + } + } + + @Override + public List clusterSlots() { + final ListConverter listClusterSlotConverter = ClusterSlotConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SLOTS, + (cmd)->cmd.clusterSlots(), listClusterSlotConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SLOTS, + (cmd)->cmd.clusterSlots(), listClusterSlotConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SLOTS, + (cmd)->cmd.clusterSlots(), + listClusterSlotConverter) + .run(); + } + } + + @Override + public Status readOnly() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.READONLY, (cmd)->cmd.readOnly(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.READONLY, (cmd)->cmd.readOnly(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.READONLY, (cmd)->cmd.readOnly(), + okStatusConverter) + .run(); + } + } + + @Override + public Status readWrite() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.READWRITE, (cmd)->cmd.readWrite(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.READWRITE, (cmd)->cmd.readWrite(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.READWRITE, (cmd)->cmd.readWrite(), + okStatusConverter) + .run(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterConnectionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterConnectionOperations.java new file mode 100644 index 000000000..cd0ff9988 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterConnectionOperations.java @@ -0,0 +1,534 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.Client; +import com.buession.redis.core.ClientAttributeOption; +import com.buession.redis.core.ClientPauseMode; +import com.buession.redis.core.ClientReply; +import com.buession.redis.core.ClientTrackingInfo; +import com.buession.redis.core.ClientType; +import com.buession.redis.core.ClientUnblockType; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.RedisServer; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.ClientKillArgument; +import com.buession.redis.core.command.args.ClientTracking; +import com.buession.redis.core.command.args.HelloArgument; +import com.buession.redis.core.internal.convert.lettuce.params.ClientTypeConverter; +import com.buession.redis.core.internal.convert.lettuce.params.ClientUnblockTypeConverter; +import com.buession.redis.core.internal.convert.response.ClientConverter; +import com.buession.redis.core.internal.convert.response.PingResultConverter; +import com.buession.redis.core.internal.lettuce.LettuceTrackingArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ClientListArgs; +import io.lettuce.core.KillArgs; +import io.lettuce.core.TrackingArgs; +import io.lettuce.core.UnblockType; + +import java.util.List; + +/** + * Lettuce 集群模式连接命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterConnectionOperations extends AbstractConnectionOperations { + + public LettuceClusterConnectionOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Status auth(final String user, final String password) { + final CommandArguments args = CommandArguments.create(user).add(password); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.AUTH, (cmd)->cmd.auth(user, password), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.AUTH, (cmd)->cmd.auth(user, password), + okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.AUTH, (cmd)->cmd.auth(user, password), + okStatusConverter) + .run(args); + } + } + + @Override + public Status auth(final String password) { + final CommandArguments args = CommandArguments.create(password); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.AUTH, (cmd)->cmd.auth(password), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.AUTH, (cmd)->cmd.auth(password), + okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.AUTH, (cmd)->cmd.auth(password), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientCaching() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_CACHING); + } + + @Override + public Status clientCaching(final boolean isYes) { + final CommandArguments args = CommandArguments.create(isYes ? Keyword.Common.YES : Keyword.Common.NO); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_CACHING, args); + } + + @Override + public String clientGetName() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_GETNAME, + (cmd)->cmd.clientGetname(), SafeEncoder::encode) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_GETNAME, + (cmd)->cmd.clientGetname(), SafeEncoder::encode) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.CLIENT, SubCommand.CLIENT_GETNAME, + (cmd)->cmd.clientGetname(), SafeEncoder::encode) + .run(); + } + } + + @Override + public Integer clientGetRedir() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_GETREDIR); + } + + @Override + public Long clientId() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_ID, + (cmd)->cmd.clientId(), (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_ID, + (cmd)->cmd.clientId(), (v)->v) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.CLIENT, SubCommand.CLIENT_ID, (cmd)->cmd.clientId(), + (v)->v) + .run(); + } + } + + @Override + public Client clientInfo() { + final ClientConverter clientConverter = new ClientConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientInfo(), + clientConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientInfo(), + clientConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, (cmd)->cmd.clientInfo(), + clientConverter) + .run(); + } + } + + @Override + public Status clientKill(final String host, final int port) { + final CommandArguments args = CommandArguments.create(host).add(port); + final String addr = host + ':' + port; + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(addr), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(addr), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(addr), okStatusConverter) + .run(args); + } + } + + @Override + public Long clientKill(final ClientKillArgument... clientKillArguments) { + final CommandArguments args = CommandArguments.create(clientKillArguments); + final KillArgs killArgs = createKillArgsFromClientKillArgument(clientKillArguments); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(killArgs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(killArgs), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(killArgs), (v)->v) + .run(args); + } + } + + @Override + public List clientList() { + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(), clientListConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(), clientListConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + } + } + + @Override + public List clientList(final ClientType clientType) { + final CommandArguments args = CommandArguments.create(clientType); + final ClientListArgs clientListArgs = (new ClientTypeConverter()).convert(clientType); + + return clientList(clientListArgs, args); + } + + @Override + public List clientList(final long... clientIds) { + final CommandArguments args = CommandArguments.create(clientIds); + final ClientListArgs clientListArgs = ClientListArgs.Builder.ids(clientIds); + + return clientList(clientListArgs, args); + } + + @Override + public Status clientNoEvict(final boolean on) { + final CommandArguments args = CommandArguments.create(on ? Keyword.Common.ON : Keyword.Common.OFF); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_NO_EVICT, + (cmd)->cmd.clientNoEvict(on), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_NO_EVICT, + (cmd)->cmd.clientNoEvict(on), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLIENT, SubCommand.CLIENT_NO_EVICT, + (cmd)->cmd.clientNoEvict(on), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientNoTouch(final boolean on) { + final CommandArguments args = CommandArguments.create(on ? Keyword.Common.ON : Keyword.Common.OFF); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_NO_TOUCH, args); + } + + @Override + public Status clientPause(final int timeout) { + final CommandArguments args = CommandArguments.create(timeout); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientPause(final int timeout, final ClientPauseMode pauseMode) { + final CommandArguments args = CommandArguments.create(timeout).add(pauseMode); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientReply(final ClientReply option) { + final CommandArguments args = CommandArguments.create(option); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_REPLY, args); + } + + @Override + public Status clientSetInfo(final ClientAttributeOption clientAttributeOption, final String value) { + final CommandArguments args = CommandArguments.create(clientAttributeOption).add(value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETINFO, + (cmd)->cmd.clientSetinfo(clientAttributeOption.name(), value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETINFO, + (cmd)->cmd.clientSetinfo(clientAttributeOption.name(), value), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETINFO, + (cmd)->cmd.clientSetinfo(clientAttributeOption.name(), value), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientSetName(final byte[] name) { + final CommandArguments args = CommandArguments.create(name); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientTracking(final ClientTracking clientTracking) { + final CommandArguments args = CommandArguments.create(clientTracking); + final TrackingArgs trackingArgs = LettuceTrackingArgs.from(clientTracking); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_TRACKING, + (cmd)->cmd.clientTracking(trackingArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_TRACKING, + (cmd)->cmd.clientTracking(trackingArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLIENT, SubCommand.CLIENT_TRACKING, + (cmd)->cmd.clientTracking(trackingArgs), okStatusConverter) + .run(args); + } + } + + @Override + public ClientTrackingInfo clientTrackingInfo() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_TRACKINGINFO); + } + + @Override + public Status clientUnblock(final int clientId) { + final CommandArguments args = CommandArguments.create(clientId); + return clientUnblock(clientId, UnblockType.TIMEOUT, args); + } + + @Override + public Status clientUnblock(final int clientId, final ClientUnblockType type) { + final CommandArguments args = CommandArguments.create(clientId).add(type); + final UnblockType unblockType = (new ClientUnblockTypeConverter()).convert(type); + + return clientUnblock(clientId, unblockType, args); + } + + @Override + public Status clientUnPause() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_UNPAUSE); + } + + @Override + public String echo(final String str) { + final CommandArguments args = CommandArguments.create(str); + final byte[] msg = SafeEncoder.encode(str); + + return echo(msg, SafeEncoder::encode, args); + } + + @Override + public byte[] echo(final byte[] str) { + final CommandArguments args = CommandArguments.create(str); + return echo(str, (v)->v, args); + } + + @Override + public RedisServer hello(final HelloArgument helloArgument) { + final CommandArguments args = CommandArguments.create(helloArgument); + return notCommand(client, Command.HELLO, args); + } + + @Override + public Status ping() { + final PingResultConverter pingResultConverter = new PingResultConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ECHO, (cmd)->cmd.ping(), + pingResultConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ECHO, (cmd)->cmd.ping(), + pingResultConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.ECHO, (cmd)->cmd.ping(), pingResultConverter) + .run(); + } + } + + @Override + public Status quit() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.QUIT, (cmd)->cmd.quit(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.QUIT, (cmd)->cmd.quit(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.QUIT, (cmd)->cmd.quit(), okStatusConverter) + .run(); + } + } + + @Override + public Status reset() { + if(isPipeline()){ + new LettuceClusterPipelineCommand<>(client, Command.RESET, (cmd)->{ + cmd.reset(); + return Status.SUCCESS; + }, (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.RESET, (cmd)->{ + cmd.reset(); + return Status.SUCCESS; + }, (v)->v) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.RESET, (cmd)->{ + cmd.reset(); + return Status.SUCCESS; + }, (v)->v) + .run(); + } + } + + @Override + public Status select(final int db) { + final CommandArguments args = CommandArguments.create(db); + return notCommand(client, Command.SELECT, args); + } + + private List clientList(final ClientListArgs clientListArgs, final CommandArguments args) { + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(clientListArgs), clientListConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(clientListArgs), clientListConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(clientListArgs), clientListConverter) + .run(args); + } + } + + private Status clientUnblock(final int clientId, final UnblockType unblockType, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + } + } + + private V echo(final byte[] str, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ECHO, (cmd)->cmd.echo(str), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ECHO, (cmd)->cmd.echo(str), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ECHO, (cmd)->cmd.echo(str), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterGeoOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterGeoOperations.java new file mode 100644 index 000000000..044ff2204 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterGeoOperations.java @@ -0,0 +1,487 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.SetListConverter; +import com.buession.lang.Geo; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.GeoAddArgument; +import com.buession.redis.core.command.args.GeoRadiusArgument; +import com.buession.redis.core.command.args.GeoSearchArgument; +import com.buession.redis.core.command.args.GeoSearchStoreArgument; +import com.buession.redis.core.internal.convert.lettuce.params.GeoUnitConverter; +import com.buession.redis.core.internal.convert.lettuce.response.GeoCoordinateConverter; +import com.buession.redis.core.internal.convert.lettuce.response.GeoRadiusGeneralResultConverter; +import com.buession.redis.core.internal.convert.lettuce.response.GeoRadiusResponseConverter; +import com.buession.redis.core.internal.convert.lettuce.response.ValueConverter; +import com.buession.redis.core.internal.lettuce.LettuceGeoAddArgs; +import com.buession.redis.core.internal.lettuce.LettuceGeoArgs; +import com.buession.redis.core.internal.lettuce.LettuceGeoValue; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.GeoAddArgs; +import io.lettuce.core.GeoArgs; +import io.lettuce.core.GeoCoordinates; +import io.lettuce.core.GeoSearch; +import io.lettuce.core.GeoValue; +import io.lettuce.core.GeoWithin; +import io.lettuce.core.Value; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 集群模式地理位置命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterGeoOperations extends AbstractGeoOperations { + + public LettuceClusterGeoOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(member); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + final byte[] bKey = SafeEncoder.encode(key); + final GeoValue[] geoValues = createGeoValueArrayFromGeoMap(memberCoordinates, SafeEncoder::encode); + + return geoAdd(bKey, geoValues, args); + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + final GeoValue[] geoValues = createGeoValueArrayFromGeoMap(memberCoordinates, (v)->v); + + return geoAdd(key, geoValues, args); + } + + @Override + public Long geoAdd(final String key, final String member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(longitude).add(latitude) + .add(member); + final byte[] bKey = SafeEncoder.encode(key); + final GeoValue[] geoValues = new GeoValue[]{LettuceGeoValue.just(longitude, latitude, member)}; + + return geoAdd(bKey, geoValues, geoAddArgument, args); + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(longitude).add(latitude) + .add(member); + final GeoValue[] geoValues = new GeoValue[]{LettuceGeoValue.just(longitude, latitude, member)}; + + return geoAdd(key, geoValues, geoAddArgument, args); + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(memberCoordinates); + final byte[] bKey = SafeEncoder.encode(key); + final GeoValue[] geoValues = createGeoValueArrayFromGeoMap(memberCoordinates, SafeEncoder::encode); + + return geoAdd(bKey, geoValues, geoAddArgument, args); + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(memberCoordinates); + final GeoValue[] geoValues = createGeoValueArrayFromGeoMap(memberCoordinates, (v)->v); + + return geoAdd(key, geoValues, geoAddArgument, args); + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2); + return geoDist(key, member1, member2, GeoArgs.Unit.m, args); + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2).add(unit); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + + return geoDist(key, member1, member2, geoArgsUnit, args); + } + + @Override + public List geoHash(final String key, final String... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + final byte[] bKey = SafeEncoder.encode(key); + final byte[][] bMembers = SafeEncoder.encode(members); + final ListConverter, String> listConverter = ValueConverter.listConverter((v)->v); + + return geoHash(bKey, bMembers, listConverter, args); + } + + @Override + public List geoHash(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + final ListConverter, byte[]> listConverter = ValueConverter.listConverter(SafeEncoder::encode); + + return geoHash(key, members, listConverter, args); + } + + @Override + public List geoPos(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final SetListConverter setListGeoRadiusGeneralResultConverter = + GeoRadiusGeneralResultConverter.setListConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + } + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit) + .add(geoRadiusArgument); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final GeoArgs geoArgs = LettuceGeoArgs.from(geoRadiusArgument); + final ListConverter, GeoRadius> listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + return notCommand(client, Command.GEORADIUS_RO, args); + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + return notCommand(client, Command.GEORADIUS_RO, args); + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = + CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit).add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUS_RO, args); + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = + CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit).add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUS_RO, args); + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final SetListConverter setListGeoRadiusGeneralResultConverter = + GeoRadiusGeneralResultConverter.setListConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final GeoArgs geoArgs = LettuceGeoArgs.from(geoRadiusArgument); + final ListConverter, GeoRadius> listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + return notCommand(client, Command.GEORADIUSBYMEMBER_RO, args); + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + return notCommand(client, Command.GEORADIUSBYMEMBER_RO, args); + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUSBYMEMBER_RO, args); + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUSBYMEMBER_RO, args); + } + + @Override + public List geoSearch(final byte[] key, final GeoSearchArgument geoSearchArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoSearchArgument); + final GeoSearch.GeoRef geoRef = createGeoRefFromGeoSearchArgument(geoSearchArgument); + final GeoSearch.GeoPredicate geoPredicate = createGeoPredicateFromGeoSearchArgument(geoSearchArgument); + final GeoArgs geoArgs = LettuceGeoArgs.from(geoSearchArgument); + final ListConverter, GeoRadius> listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GEOSEARCH, (cmd)->cmd.geosearch(key, geoRef, + geoPredicate, geoArgs), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GEOSEARCH, (cmd)->cmd.geosearch(key, geoRef, + geoPredicate, geoArgs), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GEOSEARCH, (cmd)->cmd.geosearch(key, geoRef, + geoPredicate, geoArgs), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public Long geoSearchStore(final byte[] destKey, final byte[] key, + final GeoSearchStoreArgument geoSearchStoreArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoSearchStoreArgument); + final GeoSearch.GeoRef geoRef = createGeoRefFromGeoSearchStoreArgument(geoSearchStoreArgument); + final GeoSearch.GeoPredicate geoPredicate = createGeoPredicateFromGeoSearchStoreArgument( + geoSearchStoreArgument); + final GeoArgs geoArgs = LettuceGeoArgs.from(geoSearchStoreArgument); + final boolean storeDist = Boolean.TRUE.equals(geoSearchStoreArgument.isStoreDist()); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchstore(destKey, key, geoRef, geoPredicate, geoArgs, storeDist), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchstore(destKey, key, geoRef, geoPredicate, geoArgs, storeDist), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchstore(destKey, key, geoRef, + geoPredicate, geoArgs, storeDist), (v)->v) + .run(args); + } + } + + private Long geoAdd(final byte[] key, final GeoValue[] geoValues, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoValues), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoValues), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoValues), (v)->v) + .run(args); + } + } + + private Long geoAdd(final byte[] key, final GeoValue[] geoValues, + final GeoAddArgument geoAddArgument, final CommandArguments args) { + final GeoAddArgs geoAddArgs = LettuceGeoAddArgs.from(geoAddArgument); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddArgs, geoValues), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddArgs, geoValues), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddArgs, geoValues), (v)->v) + .run(args); + } + } + + private Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoArgs.Unit unit, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, unit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, unit), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2, unit), + (v)->v) + .run(args); + } + } + + private List geoHash(final byte[] key, final byte[][] members, + final ListConverter, V> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterHashOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterHashOperations.java new file mode 100644 index 000000000..9d00276b2 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterHashOperations.java @@ -0,0 +1,815 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.ListSetConverter; +import com.buession.core.converter.MapConverter; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.HScanArgument; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.KeyValueConverter; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.convert.lettuce.response.ValueConverter; +import com.buession.redis.core.internal.lettuce.LettuceExpireArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ExpireArgs; +import io.lettuce.core.MapScanCursor; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; + +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Lettuce 集群模式模式哈希表命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterHashOperations extends AbstractHashOperations { + + public LettuceClusterHashOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Long hDel(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } + } + + @Override + public Boolean hExists(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } + } + + @Override + public List hExpire(final byte[] key, final int lifetime, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields.length) + .add(fields); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HEXPIRE, + (cmd)->cmd.hexpire(key, lifetime, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HEXPIRE, + (cmd)->cmd.hexpire(key, lifetime, fields), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HEXPIRE, (cmd)->cmd.hexpire(key, lifetime, fields), + (v)->v) + .run(args); + } + } + + @Override + public List hExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HEXPIRE, + (cmd)->cmd.hexpire(key, lifetime, expireArgs, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HEXPIRE, + (cmd)->cmd.hexpire(key, lifetime, expireArgs, fields), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HEXPIRE, + (cmd)->cmd.hexpire(key, lifetime, expireArgs, fields), (v)->v) + .run(args); + } + } + + @Override + public List hExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HEXPIREAT, + (cmd)->cmd.hexpireat(key, unixTimestamp, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HEXPIREAT, + (cmd)->cmd.hexpireat(key, unixTimestamp, fields), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HEXPIREAT, + (cmd)->cmd.hexpireat(key, unixTimestamp, fields), (v)->v) + .run(args); + } + } + + @Override + public List hExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HEXPIREAT, + (cmd)->cmd.hexpireat(key, unixTimestamp, expireArgs, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HEXPIREAT, + (cmd)->cmd.hexpireat(key, unixTimestamp, expireArgs, fields), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HEXPIREAT, + (cmd)->cmd.hexpireat(key, unixTimestamp, expireArgs, fields), (v)->v) + .run(args); + } + } + + @Override + public List hExpireTime(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields.length).add(fields); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HEXPIRETIME, (cmd)->cmd.hexpiretime(key, fields), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HEXPIRETIME, + (cmd)->cmd.hexpiretime(key, fields), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HEXPIRETIME, (cmd)->cmd.hexpiretime(key, fields), (v)->v) + .run(args); + } + } + + @Override + public String hGet(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bField = SafeEncoder.encode(field); + + return hGet(bKey, bField, SafeEncoder::encode, args); + } + + @Override + public byte[] hGet(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + return hGet(key, field, (v)->v, args); + } + + @Override + public Map hGetAll(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final MapConverter binaryToStringMapConverter = Converters.mapBinaryToString(); + + return hGetAll(bKey, binaryToStringMapConverter, args); + } + + @Override + public Map hGetAll(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return hGetAll(key, (v)->v, args); + } + + @Override + public Long hIncrBy(final byte[] key, final byte[] field, final long value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrby(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HINCRBY, + (cmd)->cmd.hincrby(key, field, value), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrby(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Double hIncrByFloat(final byte[] key, final byte[] field, final double value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HINCRBYFLOAT, + (cmd)->cmd.hincrbyfloat(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HINCRBYFLOAT, + (cmd)->cmd.hincrbyfloat(key, field, value), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HINCRBYFLOAT, (cmd)->cmd.hincrbyfloat(key, field, value), + (v)->v) + .run(args); + } + } + + @Override + public Set hKeys(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final ListSetConverter binaryToStringListSetConverter = + Converters.listSetBinaryToString(); + + return hKeys(bKey, binaryToStringListSetConverter, args); + } + + @Override + public Set hKeys(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return hKeys(key, HashSet::new, args); + } + + @Override + public Long hLen(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } + } + + @Override + public List hMGet(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + final byte[] bKey = SafeEncoder.encode(key); + final byte[][] bFields = SafeEncoder.encode(fields); + final ListConverter, String> listConverter = + new ListConverter<>((v)->SafeEncoder.encode(v.getValue())); + + return hMGet(bKey, bFields, listConverter, args); + } + + @Override + public List hMGet(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + final ListConverter, byte[]> listConverter = + new ListConverter<>(io.lettuce.core.KeyValue::getValue); + + return hMGet(key, fields, listConverter, args); + } + + @Override + public Status hMSet(final byte[] key, final Map data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), okStatusConverter) + .run(args); + } + } + + @Override + public List hPersist(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HPERSIST, (cmd)->cmd.hpersist(key, fields), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HPERSIST, (cmd)->cmd.hpersist(key, fields), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HPERSIST, (cmd)->cmd.hpersist(key, fields), (v)->v) + .run(args); + } + } + + @Override + public List hpExpire(final byte[] key, final int lifetime, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpire(key, lifetime, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpire(key, lifetime, fields), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HPEXPIRE, (cmd)->cmd.hpexpire(key, lifetime, fields), + (v)->v) + .run(args); + } + } + + @Override + public List hpExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = + CommandArguments.create(key).add(lifetime).add(expireOption).add(Keyword.Hash.FIELDS, fields); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpire(key, lifetime, expireArgs, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpire(key, lifetime, expireArgs, fields), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpire(key, lifetime, expireArgs, fields), (v)->v) + .run(args); + } + } + + @Override + public List hpExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(Keyword.Hash.FIELDS, fields); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpireat(key, unixTimestamp, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpireat(key, unixTimestamp, fields), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpireat(key, unixTimestamp, fields), (v)->v) + .run(args); + } + } + + @Override + public List hpExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = + CommandArguments.create(key).add(unixTimestamp).add(expireOption).add(Keyword.Hash.FIELDS, fields); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpireat(key, unixTimestamp, expireArgs, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpireat(key, unixTimestamp, expireArgs, fields), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpireat(key, unixTimestamp, expireArgs, fields), (v)->v) + .run(args); + } + } + + @Override + public List hpExpireTime(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HPEXPIRETIME, + (cmd)->cmd.hpexpiretime(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HPEXPIRETIME, + (cmd)->cmd.hpexpiretime(key, fields), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HPEXPIRETIME, (cmd)->cmd.hpexpiretime(key, fields), + (v)->v) + .run(args); + } + } + + @Override + public List hpTtl(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HPTTL, (cmd)->cmd.hpttl(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HPTTL, (cmd)->cmd.hpttl(key, fields), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HPTTL, (cmd)->cmd.hpttl(key, fields), (v)->v) + .run(args); + } + } + + @Override + public String hRandField(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + + return hRandField(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] hRandField(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return hRandField(key, (v)->v, args); + } + + @Override + public List hRandField(final String key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return hRandField(bKey, count, listConverter, args); + } + + @Override + public List hRandField(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count); + return hRandField(key, count, (v)->v, args); + } + + @Override + public List> hRandFieldWithValues(final String key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count).add(Keyword.Hash.WITHVALUES); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter, KeyValue> listConverter = + KeyValueConverter.listConverter(SafeEncoder::encode, SafeEncoder::encode); + + return hRandFieldWithValues(bKey, count, listConverter, args); + } + + @Override + public List> hRandFieldWithValues(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count).add(Keyword.Hash.WITHVALUES); + final ListConverter, KeyValue> listConverter = + KeyValueConverter.listConverter((k)->k, (v)->v); + + return hRandFieldWithValues(key, count, listConverter, args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create(key).add(cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create(key).add(cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, mapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor, + final HScanArgument scanArgument) { + final CommandArguments args = CommandArguments.create(key).add(cursor).add(scanArgument); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = LettuceScanArgs.from(scanArgument); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, scanArgs, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, + final HScanArgument scanArgument) { + final CommandArguments args = CommandArguments.create(key).add(cursor).add(scanArgument); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = LettuceScanArgs.from(scanArgument); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, scanArgs, mapScanCursorConverter, args); + } + + @Override + public Long hSet(final byte[] key, final KeyValue... data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HSET, + (cmd)->cmd.hset(key, field, value), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), + converter) + .run(args); + } + } + + @Override + public Status hSetNx(final byte[] key, final byte[] field, final byte[] value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Long hStrLen(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HSETNX, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HSETNX, (cmd)->cmd.hstrlen(key, field), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HSETNX, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } + } + + @Override + public List hTtl(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HPTTL, (cmd)->cmd.httl(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HPTTL, (cmd)->cmd.httl(key, fields), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HSETNX, Command.HPTTL, (cmd)->cmd.httl(key, fields), + (v)->v) + .run(args); + } + } + + @Override + public List hVals(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return hVals(bKey, listConverter, args); + } + + @Override + public List hVals(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return hVals(key, (v)->v, args); + } + + private V hGet(final byte[] key, final byte[] field, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), converter) + .run(args); + } + } + + private Map hGetAll(final byte[] key, final Converter, Map> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetall(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetall(key), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetall(key), converter) + .run(args); + } + } + + private Set hKeys(final byte[] key, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), converter) + .run(args); + } + } + + private List hMGet(final byte[] key, final byte[][] fields, + final ListConverter, V> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), converter) + .run(args); + } + } + + private V hRandField(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), converter) + .run(args); + } + } + + private List hRandField(final byte[] key, final int count, final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), converter) + .run(args); + } + } + + private List> hRandFieldWithValues(final byte[] key, final int count, + final ListConverter, + KeyValue> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HRANDFIELD, + (cmd)->cmd.hrandfieldWithvalues(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HRANDFIELD, + (cmd)->cmd.hrandfieldWithvalues(key, count), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfieldWithvalues(key, count), + converter) + .run(args); + } + } + + private ScanResult> hScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), converter) + .run(args); + } + } + + private ScanResult> hScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanArgs), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanArgs), + converter) + .run(args); + } + } + + private List hVals(final byte[] key, final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterHyperLogLogOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterHyperLogLogOperations.java new file mode 100644 index 000000000..8f0e15b8c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterHyperLogLogOperations.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; + +/** + * Lettuce 集群模式 HyperLogLog 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterHyperLogLogOperations extends AbstractHyperLogLogOperations { + + public LettuceClusterHyperLogLogOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Status pfAdd(final byte[] key, final byte[]... elements) { + final CommandArguments args = CommandArguments.create(key).add(elements); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + } + } + + @Override + public Long pfCount(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } + } + + @Override + public Status pfMerge(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(destKey).add(keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterKeyOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterKeyOperations.java new file mode 100644 index 000000000..5432f41a6 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterKeyOperations.java @@ -0,0 +1,1038 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.ListSetConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.ObjectEncoding; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Type; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.MigrateArgument; +import com.buession.redis.core.command.args.RestoreArgument; +import com.buession.redis.core.command.args.SortArgument; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.convert.response.ObjectEncodingConverter; +import com.buession.redis.core.internal.convert.response.TypeConverter; +import com.buession.redis.core.internal.lettuce.LettuceCopyArgs; +import com.buession.redis.core.internal.lettuce.LettuceExpireArgs; +import com.buession.redis.core.internal.lettuce.LettuceMigrateArgs; +import com.buession.redis.core.internal.lettuce.LettuceRestoreArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.core.internal.lettuce.LettuceSortArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.CopyArgs; +import io.lettuce.core.ExpireArgs; +import io.lettuce.core.KeyScanCursor; +import io.lettuce.core.MigrateArgs; +import io.lettuce.core.RestoreArgs; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.SortArgs; + +import java.util.List; +import java.util.Set; + +/** + * Lettuce 集群模式 Key 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterKeyOperations extends AbstractKeyOperations { + + public LettuceClusterKeyOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + final CopyArgs copyArgs = new LettuceCopyArgs(db); + + return copy(key, destKey, copyArgs, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + final CopyArgs copyArgs = new LettuceCopyArgs(replace); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, copyArgs, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + final CopyArgs copyArgs = new LettuceCopyArgs(db, replace); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, copyArgs, args); + } + + @Override + public Long del(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } + } + + @Override + public byte[] dump(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + } + } + + @Override + public Boolean exists(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), + (v)->v == 1L) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), + (v)->v == 1L) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v == 1L) + .run(args); + } + } + + @Override + public Long exists(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expireArgs), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expireArgs), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime, expireArgs), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireat(key, unixTimestamp), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireat(key, unixTimestamp), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireat(key, unixTimestamp), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireat(key, unixTimestamp, expireArgs), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireat(key, unixTimestamp, expireArgs), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireat(key, unixTimestamp, expireArgs), booleanStatusConverter) + .run(args); + } + } + + @Override + public Long expireTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expiretime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expiretime(key), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expiretime(key), (v)->v) + .run(args); + } + } + + @Override + public Set keys(final String pattern) { + final CommandArguments args = CommandArguments.create(pattern); + final byte[] bPattern = SafeEncoder.encode(pattern); + final ListSetConverter binaryToStringListSetConverter = + Converters.listSetBinaryToString(); + + return keys(bPattern, binaryToStringListSetConverter, args); + } + + @Override + public Set keys(final byte[] pattern) { + final CommandArguments args = CommandArguments.create(pattern); + final ListSetConverter converter = new ListSetConverter<>((v)->v); + + return keys(pattern, converter, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(keys); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgument migrateArgument, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(migrateArgument) + .add(keys); + final MigrateArgs migrateArgs = LettuceMigrateArgs.from(migrateArgument).keys(keys); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status move(final byte[] key, final int db) { + final CommandArguments args = CommandArguments.create(key).add(db); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.MOVE, (cmd)->cmd.move(key, db), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.MOVE, (cmd)->cmd.move(key, db), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.MOVE, (cmd)->cmd.move(key, db), + booleanStatusConverter) + .run(args); + } + } + + @Override + public ObjectEncoding objectEncoding(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final ObjectEncodingConverter objectEncodingConverter = new ObjectEncodingConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + } + } + + @Override + public Long objectFreq(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectIdleTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectRefcount(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + } + } + + @Override + public Status persist(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime, expireArgs), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime, expireArgs), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime, expireArgs), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.pexpireat(key, unixTimestamp), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.pexpireat(key, unixTimestamp), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EXPIREAT, (cmd)->cmd.pexpireat(key, unixTimestamp), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireat(key, unixTimestamp, expireArgs), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireat(key, unixTimestamp, expireArgs), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireat(key, unixTimestamp, expireArgs), booleanStatusConverter) + .run(args); + } + } + + @Override + public Long pExpireTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.pexpiretime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EXPIREAT, (cmd)->cmd.pexpiretime(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EXPIREAT, (cmd)->cmd.pexpiretime(key), (v)->v) + .run(args); + } + } + + @Override + public Long pTtl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } + } + + @Override + public String randomKey() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.RANDOMKEY, (cmd)->cmd.randomkey(), + SafeEncoder::encode) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.RANDOMKEY, (cmd)->cmd.randomkey(), + SafeEncoder::encode) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.RANDOMKEY, (cmd)->cmd.randomkey(), SafeEncoder::encode) + .run(); + } + } + + @Override + public Status rename(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.RENAME, + (cmd)->cmd.rename(key, newKey), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + } + } + + @Override + public Status renameNx(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl, + final RestoreArgument restoreArgument) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl).add(restoreArgument); + final RestoreArgs restoreArgs = LettuceRestoreArgs.from(restoreArgument).ttl(ttl); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, serializedValue, restoreArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, serializedValue, restoreArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, serializedValue, restoreArgs), okStatusConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final String cursor) { + final CommandArguments args = CommandArguments.create(cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor) { + final CommandArguments args = CommandArguments.create(cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, keyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, scanArgs, keyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final String cursor, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, scanArgs, keyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern).add(count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern).add(count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, scanArgs, keyScanCursorConverter, args); + } + + @Override + public List sort(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return sort(bKey, listConverter, args); + } + + @Override + public List sort(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return sort(key, (v)->v, args); + } + + @Override + public List sort(final String key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final byte[] bKey = SafeEncoder.encode(key); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + final ListConverter listConverter = Converters.listBinaryToString(); + + return sort(bKey, sortArgs, listConverter, args); + } + + @Override + public List sort(final byte[] key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + + return sort(key, sortArgs, (v)->v, args); + } + + @Override + public Long sort(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + final SortArgs sortArgs = new LettuceSortArgs(); + + return sortStore(key, destKey, sortArgs, args); + } + + @Override + public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(sortArgument); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + + return sortStore(key, destKey, sortArgs, args); + } + + @Override + public List sortRo(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return sortRo(bKey, listConverter, args); + } + + @Override + public List sortRo(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return sortRo(key, (v)->v, args); + } + + @Override + public List sortRo(final String key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final byte[] bKey = SafeEncoder.encode(key); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + final ListConverter listConverter = Converters.listBinaryToString(); + + return sortRo(bKey, sortArgs, listConverter, args); + } + + @Override + public List sortRo(final byte[] key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + + return sortRo(key, sortArgs, (v)->v, args); + } + + @Override + public Long touch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } + } + + @Override + public Long ttl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } + } + + @Override + public Type type(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } + } + + @Override + public Long unlink(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } + } + + private Status copy(final byte[] key, final byte[] destKey, final CopyArgs copyArgs, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, copyArgs), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, copyArgs), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, copyArgs), + booleanStatusConverter) + .run(args); + } + } + + private Set keys(final byte[] pattern, final ListSetConverter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), converter) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgs migrateArgs, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateArgs), okStatusConverter) + .run(args); + } + } + + private ScanResult> scan(final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), converter) + .run(args); + } + } + + private ScanResult> scan(final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanArgs), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanArgs), + converter) + .run(args); + } + } + + private List sort(final byte[] key, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), converter) + .run(args); + } + } + + private List sort(final byte[] key, final SortArgs sortArgs, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortArgs), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortArgs), + converter) + .run(args); + } + } + + private Long sortStore(final byte[] key, final byte[] destKey, final SortArgs sortArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SORT, + (cmd)->cmd.sortStore(key, sortArgs, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SORT, + (cmd)->cmd.sortStore(key, sortArgs, destKey), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SORT, (cmd)->cmd.sortStore(key, sortArgs, destKey), + (v)->v) + .run(args); + } + } + + private List sortRo(final byte[] key, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadOnly(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadOnly(key), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadOnly(key), converter) + .run(args); + } + } + + private List sortRo(final byte[] key, final SortArgs sortArgs, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadOnly(key, sortArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SORT_RO, + (cmd)->cmd.sortReadOnly(key, sortArgs), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadOnly(key, sortArgs), + converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterListOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterListOperations.java new file mode 100644 index 000000000..add5edb21 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterListOperations.java @@ -0,0 +1,638 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.builder.ListBuilder; +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.Direction; +import com.buession.redis.core.ListPosition; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.LPosArgument; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.lettuce.LettuceLPosArgs; +import com.buession.redis.core.internal.lettuce.utils.LMoveArgsUtils; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyValue; +import io.lettuce.core.LMoveArgs; +import io.lettuce.core.LPosArgs; + +import java.util.List; + +/** + * Lettuce 集群模式列表命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterListOperations extends AbstractListOperations { + + public LettuceClusterListOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public String lIndex(final String key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + final byte[] bKey = SafeEncoder.encode(key); + + return lIndex(bKey, index, SafeEncoder::encode, args); + } + + @Override + public byte[] lIndex(final byte[] key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + return lIndex(key, index, (v)->v, args); + } + + @Override + public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) + .put("value", value); + final boolean before = ListPosition.BEFORE == position; + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, before, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, before, pivot, value), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, before, pivot, value), (v)->v) + .run(args); + } + } + + @Override + public Status lSet(final byte[] key, final long index, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LSET, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LSET, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.LSET, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Long lLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } + } + + @Override + public List lRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return lRange(bKey, start, end, listConverter, args); + } + + @Override + public List lRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return lRange(key, start, end, (v)->v, args); + } + + @Override + public Long lPos(final byte[] key, final byte[] element) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); + final LPosArgs lPosArgs = LettuceLPosArgs.from(lPosArgument); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosArgs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosArgs), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element, lPosArgs), + (v)->v) + .run(args); + } + } + + @Override + public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) + .put("count", count); + final LPosArgs lPosArgs = LettuceLPosArgs.from(lPosArgument); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, (int) count, lPosArgs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, (int) count, lPosArgs), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, (int) count, lPosArgs), (v)->v) + .run(args); + } + } + + @Override + public Long lRem(final byte[] key, final byte[] value, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LREM, + (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } + } + + @Override + public Status lTrim(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LTRIM, + (cmd)->cmd.ltrim(key, start, end), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } + } + + @Override + public String lMove(final String key, final String destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + final LMoveArgs lMoveArgs = LMoveArgsUtils.fromDirection(from, to); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(bKey, bDestKey, lMoveArgs), SafeEncoder::encode) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(bKey, bDestKey, lMoveArgs), SafeEncoder::encode) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(bKey, bDestKey, lMoveArgs), SafeEncoder::encode) + .run(args); + } + } + + @Override + public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + final LMoveArgs lMoveArgs = LMoveArgsUtils.fromDirection(from, to); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, key, lMoveArgs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, key, lMoveArgs), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, key, lMoveArgs), (v)->v) + .run(args); + } + } + + @Override + public String blMove(final String key, final String destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + final LMoveArgs lMoveArgs = LMoveArgsUtils.fromDirection(from, to); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BLMOVE, + (cmd)->cmd.lmove(bKey, bDestKey, lMoveArgs), SafeEncoder::encode) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BLMOVE, + (cmd)->cmd.lmove(bKey, bDestKey, lMoveArgs), SafeEncoder::encode) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BLMOVE, + (cmd)->cmd.lmove(bKey, bDestKey, lMoveArgs), SafeEncoder::encode) + .run(args); + } + } + + @Override + public byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to).put("timeout", timeout); + final LMoveArgs lMoveArgs = LMoveArgsUtils.fromDirection(from, to); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, key, lMoveArgs, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, key, lMoveArgs, timeout), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, key, lMoveArgs, timeout), (v)->v) + .run(args); + } + } + + @Override + public List blPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final Converter, List> converter = + (v)->ListBuilder.of(SafeEncoder.encode(v.getValue())); + + return blPop(bKeys, timeout, converter, args); + } + + @Override + public List blPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final Converter, List> converter = (v)->ListBuilder.of(v.getValue()); + + return blPop(keys, timeout, converter, args); + } + + @Override + public List brPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final Converter, List> converter = + (v)->ListBuilder.of(SafeEncoder.encode(v.getValue())); + + return brPop(bKeys, timeout, converter, args); + } + + @Override + public List brPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final Converter, List> converter = (v)->ListBuilder.of(v.getValue()); + + return brPop(keys, timeout, converter, args); + } + + @Override + public String brPoplPush(final String key, final String destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + + return brPoplPush(bKey, bDestKey, timeout, SafeEncoder::encode, args); + } + + @Override + public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + return brPoplPush(key, destKey, timeout, (v)->v, args); + } + + @Override + public String lPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return lPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] lPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return lPop(key, (v)->v, args); + } + + @Override + public Long lPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long lPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LPUSHX, + (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } + } + + @Override + public String rPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return rPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] rPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return rPop(key, (v)->v, args); + } + + @Override + public String rPoplPush(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + + return rPoplPush(bKey, bDestKey, SafeEncoder::encode, args); + } + + @Override + public byte[] rPoplPush(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + return rPoplPush(key, destKey, (v)->v, args); + } + + @Override + public Long rPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long rPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.RPUSHX, + (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } + } + + private V lIndex(final byte[] key, final long index, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), converter) + .run(args); + } + } + + private List lRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LRANGE, + (cmd)->cmd.lrange(key, start, end), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LRANGE, + (cmd)->cmd.lrange(key, start, end), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), + converter) + .run(args); + } + } + + private V blMove(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.BLMOVE) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.BLMOVE) + .run(args); + }else{ + return new LettuceClusterCommand(client, Command.BLMOVE) + .run(args); + } + } + + private List blPop(final byte[][] keys, final int timeout, final Converter, + List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BLPOP, + (cmd)->cmd.blpop(timeout, keys), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), + converter) + .run(args); + } + } + + private List brPop(final byte[][] keys, final int timeout, final Converter, + List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BRPOP, + (cmd)->cmd.brpop(timeout, keys), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), + converter) + .run(args); + } + } + + private V brPoplPush(final byte[] key, final byte[] destKey, final int timeout, + final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(timeout, key, destKey), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(timeout, key, destKey), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(timeout, key, destKey), converter) + .run(args); + } + } + + private V lPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), converter) + .run(args); + } + } + + private V rPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), converter) + .run(args); + } + } + + private V rPoplPush(final byte[] key, final byte[] destKey, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterOperations.java new file mode 100644 index 000000000..7c2ad2fc6 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterOperations.java @@ -0,0 +1,636 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.BumpEpoch; +import com.buession.redis.core.ClusterFailoverOption; +import com.buession.redis.core.ClusterInfo; +import com.buession.redis.core.ClusterLink; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.ClusterResetOption; +import com.buession.redis.core.ClusterSetSlotOption; +import com.buession.redis.core.ClusterRedisShard; +import com.buession.redis.core.ClusterSlot; +import com.buession.redis.core.SlotRange; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ClusterReplicasConverter; +import com.buession.redis.core.internal.convert.response.BumpEpochConverter; +import com.buession.redis.core.internal.convert.response.ClusterInfoConverter; +import com.buession.redis.core.internal.convert.response.ClusterNodeConverter; +import com.buession.redis.core.internal.convert.response.ClusterNodesConverter; +import com.buession.redis.core.internal.convert.response.ClusterSlotConverter; +import io.lettuce.core.Range; + +import java.util.List; + +/** + * Lettuce 单机模式集群命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterOperations extends AbstractClusterOperations { + + public LettuceClusterOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Status asking() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ASKING, (cmd)->cmd.asking(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ASKING, (cmd)->cmd.asking(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.ASKING, (cmd)->cmd.asking(), okStatusConverter) + .run(); + } + } + + @Override + public Status clusterAddSlots(final int... slots) { + final CommandArguments args = CommandArguments.create(slots); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTS, + (cmd)->cmd.clusterAddSlots(slots), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTS, + (cmd)->cmd.clusterAddSlots(slots), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTS, + (cmd)->cmd.clusterAddSlots(slots), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterAddSlotsRange(final SlotRange... slots) { + final CommandArguments args = CommandArguments.create(slots); + final Range[] slotsRanges = numberRangeArrayToRange(slots); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTSRANGE, + (cmd)->cmd.clusterAddSlotsRange(slotsRanges), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTSRANGE, + (cmd)->cmd.clusterAddSlotsRange(slotsRanges), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTSRANGE, + (cmd)->cmd.clusterAddSlotsRange(slotsRanges), okStatusConverter) + .run(args); + } + } + + @Override + public KeyValue clusterBumpEpoch() { + final BumpEpochConverter bumpEpochConverter = new BumpEpochConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_BUMPEPOCH, + (cmd)->cmd.clusterBumpepoch(), bumpEpochConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_BUMPEPOCH, + (cmd)->cmd.clusterBumpepoch(), bumpEpochConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_BUMPEPOCH, + (cmd)->cmd.clusterBumpepoch(), bumpEpochConverter) + .run(); + } + } + + @Override + public Long clusterCountFailureReports(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTFAILUREREPORTS, + (cmd)->cmd.clusterCountFailureReports(nodeId), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTFAILUREREPORTS, + (cmd)->cmd.clusterCountFailureReports(nodeId), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTFAILUREREPORTS, + (cmd)->cmd.clusterCountFailureReports(nodeId), (v)->v) + .run(args); + } + } + + @Override + public Long clusterCountKeysInSlot(final int slot) { + final CommandArguments args = CommandArguments.create(slot); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + } + } + + @Override + public Status clusterDelSlots(final int... slots) { + final CommandArguments args = CommandArguments.create(slots); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTS, + (cmd)->cmd.clusterDelSlots(slots), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTS, + (cmd)->cmd.clusterDelSlots(slots), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTS, + (cmd)->cmd.clusterDelSlots(slots), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterDelSlotsRange(final SlotRange... slots) { + final CommandArguments args = CommandArguments.create(slots); + final Range[] slotRanges = numberRangeArrayToRange(slots); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTSRANGE, + (cmd)->cmd.clusterDelSlotsRange(slotRanges), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTSRANGE, + (cmd)->cmd.clusterDelSlotsRange(slotRanges), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTSRANGE, + (cmd)->cmd.clusterDelSlotsRange(slotRanges), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption) { + final CommandArguments args = CommandArguments.create(clusterFailoverOption); + final boolean force = ClusterFailoverOption.FORCE == clusterFailoverOption; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FAILOVER, + (cmd)->cmd.clusterFailover(force), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FAILOVER, + (cmd)->cmd.clusterFailover(force), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FAILOVER, + (cmd)->cmd.clusterFailover(force), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterFlushSlots() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FLUSHSLOTS, + (cmd)->cmd.clusterFlushslots(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FLUSHSLOTS, + (cmd)->cmd.clusterFlushslots(), okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FLUSHSLOTS, + (cmd)->cmd.clusterFlushslots(), okStatusConverter) + .run(); + } + } + + @Override + public Status clusterForget(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FORGET, + (cmd)->cmd.clusterForget(nodeId), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FORGET, + (cmd)->cmd.clusterForget(nodeId), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_FORGET, + (cmd)->cmd.clusterForget(nodeId), okStatusConverter) + .run(args); + } + } + + @Override + public List clusterGetKeysInSlot(final int slot, final int count) { + final CommandArguments args = CommandArguments.create(slot).add(count); + final ListConverter listConverter = Converters.listBinaryToString(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, count), listConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, count), listConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, count), listConverter) + .run(args); + } + } + + @Override + public ClusterInfo clusterInfo() { + final ClusterInfoConverter clusterInfoConverter = new ClusterInfoConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.INFO, (cmd)->cmd.clusterInfo(), + clusterInfoConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.INFO, (cmd)->cmd.clusterInfo(), + clusterInfoConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.INFO, (cmd)->cmd.clusterInfo(), + clusterInfoConverter) + .run(); + } + } + + @Override + public Long clusterKeySlot(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterKeyslot(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterKeyslot(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterKeyslot(key), (v)->v) + .run(args); + } + } + + @Override + public List clusterLinks() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_LINKS); + } + + @Override + public Status clusterMeet(final String ip, final int port) { + final CommandArguments args = CommandArguments.create(ip).add(port); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MEET, + (cmd)->cmd.clusterMeet(ip, port), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MEET, + (cmd)->cmd.clusterMeet(ip, port), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MEET, + (cmd)->cmd.clusterMeet(ip, port), + okStatusConverter) + .run(args); + } + } + + @Override + public String clusterMyId() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MYID, + (cmd)->cmd.clusterMyId(), (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MYID, + (cmd)->cmd.clusterMyId(), + (v)->v) + .run(); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_MYID, (cmd)->cmd.clusterMyId(), + (v)->v) + .run(); + } + } + + @Override + public String clusterMyShardId() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MYSHARDID); + } + + @Override + public List clusterNodes() { + final ClusterNodesConverter clusterNodesConverter = new ClusterNodesConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.NODES, (cmd)->cmd.clusterNodes(), + clusterNodesConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.NODES, (cmd)->cmd.clusterNodes(), + clusterNodesConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.NODES, (cmd)->cmd.clusterNodes(), + clusterNodesConverter) + .run(); + } + } + + @Override + public List clusterReplicas(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + final ClusterReplicasConverter clusterReplicasConverter = new ClusterReplicasConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICAS, + (cmd)->cmd.clusterReplicate(nodeId), clusterReplicasConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICAS, + (cmd)->cmd.clusterReplicate(nodeId), clusterReplicasConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICAS, + (cmd)->cmd.clusterReplicate(nodeId), clusterReplicasConverter) + .run(args); + } + } + + @Override + public Status clusterReplicate(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICATE, + (cmd)->cmd.clusterReplicate(nodeId), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICATE, + (cmd)->cmd.clusterReplicate(nodeId), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICATE, + (cmd)->cmd.clusterReplicate(nodeId), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterReset(final ClusterResetOption clusterResetOption) { + final CommandArguments args = CommandArguments.create(clusterResetOption); + final boolean hard = ClusterResetOption.HARD == clusterResetOption; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.RESET, + (cmd)->cmd.clusterReset(hard), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.RESET, + (cmd)->cmd.clusterReset(hard), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.RESET, (cmd)->cmd.clusterReset(hard), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterSaveConfig() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SAVECONFIG, + (cmd)->cmd.clusterSaveconfig(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SAVECONFIG, + (cmd)->cmd.clusterSaveconfig(), okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SAVECONFIG, + (cmd)->cmd.clusterSaveconfig(), okStatusConverter) + .run(); + } + } + + @Override + public Status clusterSetConfigEpoch(final long configEpoch) { + final CommandArguments args = CommandArguments.create(configEpoch); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId) { + final CommandArguments args = CommandArguments.create(slot).add(setSlotOption).add(nodeId); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + } + } + + @Override + public List clusterShards() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SHARDS, + (cmd)->cmd.clusterShards(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SHARDS, + (cmd)->cmd.clusterShards(), okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SHARDS, + (cmd)->cmd.clusterShards(), okStatusConverter) + .run(); + } + } + + @Override + public List clusterSlaves(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + final ListConverter listClusterNodeConverter = ClusterNodeConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.SLAVES, + (cmd)->cmd.clusterSlaves(nodeId), listClusterNodeConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.SLAVES, + (cmd)->cmd.clusterSlaves(nodeId), listClusterNodeConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.SLAVES, (cmd)->cmd.clusterSlaves(nodeId), + listClusterNodeConverter) + .run(args); + } + } + + @Override + public List clusterSlots() { + final ListConverter listClusterSlotConverter = ClusterSlotConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SLOTS, + (cmd)->cmd.clusterSlots(), listClusterSlotConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SLOTS, + (cmd)->cmd.clusterSlots(), listClusterSlotConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.CLUSTER, SubCommand.CLUSTER_SLOTS, (cmd)->cmd.clusterSlots(), + listClusterSlotConverter) + .run(); + } + } + + @Override + public Status readOnly() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.READONLY, (cmd)->cmd.readOnly(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.READONLY, (cmd)->cmd.readOnly(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.READONLY, (cmd)->cmd.readOnly(), okStatusConverter) + .run(); + } + } + + @Override + public Status readWrite() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.READWRITE, (cmd)->cmd.readWrite(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.READWRITE, (cmd)->cmd.readWrite(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.READWRITE, (cmd)->cmd.readWrite(), okStatusConverter) + .run(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterPubSubOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterPubSubOperations.java new file mode 100644 index 000000000..2050c6827 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterPubSubOperations.java @@ -0,0 +1,355 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapConverter; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.PubSubListener; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 集群模式 Pub/Sub 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterPubSubOperations extends AbstractPubSubOperations { + + public LettuceClusterPubSubOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + notCommand(client, Command.PSUBSCRIBE, args); + } + + @Override + public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + notCommand(client, Command.PSUBSCRIBE, args); + } + + @Override + public Long publish(final byte[] channel, final byte[] message) { + final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PUBLISH, + (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PUBLISH, + (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + } + } + + @Override + public List pubsubChannels() { + final ListConverter listConverter = Converters.listBinaryToString(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(), listConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(), listConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(), + listConverter) + .run(); + } + } + + @Override + public List pubsubChannels(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final byte[] bPattern = SafeEncoder.encode(pattern); + final ListConverter listConverter = Converters.listBinaryToString(); + + return pubsubChannels(bPattern, listConverter, args); + } + + @Override + public List pubsubChannels(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return pubsubChannels(pattern, (v)->v, args); + } + + @Override + public List pubsubShardChannels() { + final ListConverter listConverter = Converters.listBinaryToString(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PUBSUB_SHARDCHANNELS, + (cmd)->cmd.pubsubChannels(), listConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PUBSUB_SHARDCHANNELS, + (cmd)->cmd.pubsubChannels(), listConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.PUBSUB_SHARDCHANNELS, + (cmd)->cmd.pubsubChannels(), listConverter) + .run(); + } + } + + @Override + public List pubsubShardChannels(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final byte[] bPattern = SafeEncoder.encode(pattern); + final ListConverter listConverter = Converters.listBinaryToString(); + + return pubsubShardChannels(bPattern, listConverter, args); + } + + @Override + public List pubsubShardChannels(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return pubsubShardChannels(pattern, (v)->v, args); + } + + @Override + public Long pubsubNumPat() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PUBSUB_NUMPAT, (cmd)->cmd.pubsubNumpat(), + (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PUBSUB_NUMPAT, + (cmd)->cmd.pubsubNumpat(), (v)->v) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.PUBSUB_NUMPAT, (cmd)->cmd.pubsubNumpat(), (v)->v) + .run(); + } + } + + @Override + public Map pubsubNumSub() { + final MapConverter converter = new MapConverter<>(SafeEncoder::encode, (v)->v); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PUBSUB_NUMSUB, + (cmd)->cmd.pubsubNumsub(), converter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PUBSUB_NUMSUB, + (cmd)->cmd.pubsubNumsub(), converter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.PUBSUB_NUMSUB, (cmd)->cmd.pubsubNumsub(), + converter) + .run(); + } + } + + @Override + public Map pubsubNumSub(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + final byte[][] bChannels = SafeEncoder.encode(channels); + final MapConverter converter = new MapConverter<>(SafeEncoder::encode, (v)->v); + + return pubsubNumSub(bChannels, converter, args); + } + + @Override + public Map pubsubNumSub(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return pubsubNumSub(channels, (v)->v, args); + } + + @Override + public Map pubsubShardNumSub() { + final MapConverter converter = new MapConverter<>(SafeEncoder::encode, (v)->v); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PUBSUB_SHARDNUMSUB, + (cmd)->cmd.pubsubShardNumsub(), converter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PUBSUB_SHARDNUMSUB, + (cmd)->cmd.pubsubShardNumsub(), converter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.PUBSUB_SHARDNUMSUB, + (cmd)->cmd.pubsubShardNumsub(), converter) + .run(); + } + } + + @Override + public Map pubsubShardNumSub(final String... shardChannels) { + final CommandArguments args = CommandArguments.create("shardChannels", (Object[]) shardChannels); + final byte[][] bShardChannels = SafeEncoder.encode(shardChannels); + final MapConverter converter = new MapConverter<>(SafeEncoder::encode, (v)->v); + + return pubsubShardNumSub(bShardChannels, converter, args); + } + + @Override + public Map pubsubShardNumSub(final byte[]... shardChannels) { + final CommandArguments args = CommandArguments.create("shardChannels", (Object[]) shardChannels); + return pubsubShardNumSub(shardChannels, (v)->v, args); + } + + @Override + public Object pUnSubscribe() { + return notCommand(client, Command.PUNSUBSCRIBE); + } + + @Override + public Object pUnSubscribe(final String... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return notCommand(client, Command.PUNSUBSCRIBE, args); + } + + @Override + public Object pUnSubscribe(final byte[]... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return notCommand(client, Command.PUNSUBSCRIBE, args); + } + + @Override + public void subscribe(final String[] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + notCommand(client, Command.SUBSCRIBE, args); + } + + @Override + public void subscribe(final byte[][] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + notCommand(client, Command.SUBSCRIBE, args); + } + + @Override + public Object unSubscribe() { + return notCommand(client, Command.UNSUBSCRIBE); + } + + @Override + public Object unSubscribe(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return notCommand(client, Command.UNSUBSCRIBE, args); + } + + @Override + public Object unSubscribe(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return notCommand(client, Command.UNSUBSCRIBE, args); + } + + private List pubsubChannels(final byte[] pattern, final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(pattern), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(pattern), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(pattern), converter) + .run(args); + } + } + + private List pubsubShardChannels(final byte[] pattern, final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PUBSUB_SHARDCHANNELS, + (cmd)->cmd.pubsubShardChannels(pattern), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PUBSUB_SHARDCHANNELS, + (cmd)->cmd.pubsubShardChannels(pattern), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.PUBSUB_SHARDCHANNELS, + (cmd)->cmd.pubsubShardChannels(pattern), converter) + .run(args); + } + } + + private Map pubsubNumSub(final byte[][] channels, + final Converter, Map> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PUBSUB_NUMSUB, + (cmd)->cmd.pubsubNumsub(channels), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PUBSUB_NUMSUB, + (cmd)->cmd.pubsubNumsub(channels), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.PUBSUB_NUMSUB, (cmd)->cmd.pubsubNumsub(channels), + converter) + .run(args); + } + } + + private Map pubsubShardNumSub(final byte[][] channels, + final Converter, Map> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PUBSUB_SHARDNUMSUB, + (cmd)->cmd.pubsubShardNumsub(channels), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PUBSUB_SHARDNUMSUB, + (cmd)->cmd.pubsubShardNumsub(channels), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.PUBSUB_SHARDNUMSUB, + (cmd)->cmd.pubsubShardNumsub(channels), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterScriptingOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterScriptingOperations.java new file mode 100644 index 000000000..f29e25271 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterScriptingOperations.java @@ -0,0 +1,322 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.lettuce.params.FlushModeConverter; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ScriptOutputType; + +import java.util.List; + +/** + * Lettuce 集群模式 Script 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterScriptingOperations extends AbstractScriptingOperations { + + public LettuceClusterScriptingOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Object eval(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + final byte[][] bKeys = new byte[][]{}; + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final byte[] script) { + final CommandArguments args = CommandArguments.create("script", script); + final byte[][] keys = new byte[][]{}; + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final String script, final String... params) { + final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + final byte[][] bKeys = new byte[][]{}; + final byte[][] bParams = SafeEncoder.encode(params); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys, bParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys, bParams), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys, bParams), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final byte[] script, final byte[]... params) { + final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + final byte[][] keys = new byte[][]{}; + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys, params), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys, params), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final String script, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final byte[][] bKeys = SafeEncoder.encode(keys); + final byte[][] bArguments = SafeEncoder.encode(arguments); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys, bArguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys, bArguments), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys, bArguments), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments) { + final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys, arguments), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys, arguments), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final String digest) { + final CommandArguments args = CommandArguments.create("digest", digest); + final byte[][] bKeys = new byte[][]{}; + + return evalSha(digest, bKeys, null, args); + } + + @Override + public Object evalSha(final String digest, final String... params) { + final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); + final byte[][] bKeys = new byte[][]{}; + final byte[][] bParams = SafeEncoder.encode(params); + + return evalSha(digest, bKeys, bParams, args); + } + + @Override + public Object evalSha(final String digest, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final byte[][] bKeys = SafeEncoder.encode(keys); + final byte[][] bArguments = SafeEncoder.encode(arguments); + + return evalSha(digest, bKeys, bArguments, args); + } + + @Override + public List scriptExists(final String... sha1) { + final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(sha1), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(sha1), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), + (v)->v) + .run(args); + } + } + + @Override + public Status scriptFlush() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush(), okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(); + } + } + + @Override + public Status scriptFlush(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + final io.lettuce.core.FlushMode flushMode = (new FlushModeConverter()).convert(mode); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush(flushMode), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush(flushMode), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(flushMode), + okStatusConverter) + .run(args); + } + } + + @Override + public String scriptLoad(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + final byte[] bScript = SafeEncoder.encode(script); + + return scriptLoad(bScript, (v)->v, args); + } + + @Override + public byte[] scriptLoad(final byte[] script) { + final CommandArguments args = CommandArguments.create("script", script); + return scriptLoad(script, SafeEncoder::encode, args); + } + + @Override + public Status scriptKill() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + } + } + + private Object evalSha(final String digest, final byte[][] keys, final byte[][] arguments, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, ScriptOutputType.OBJECT, keys, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, ScriptOutputType.OBJECT, keys, arguments), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, ScriptOutputType.OBJECT, keys, arguments), (v)->v) + .run(args); + } + } + + private V scriptLoad(final byte[] script, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), + converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterServerOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterServerOperations.java new file mode 100644 index 000000000..eb445908d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterServerOperations.java @@ -0,0 +1,863 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.Info; +import com.buession.redis.core.MemoryStats; +import com.buession.redis.core.Module; +import com.buession.redis.core.RedisMonitor; +import com.buession.redis.core.RedisServerTime; +import com.buession.redis.core.Role; +import com.buession.redis.core.SlowLog; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.RedisServerTimeConverter; +import com.buession.redis.core.internal.convert.lettuce.response.RoleConverter; +import com.buession.redis.core.internal.convert.lettuce.response.SlowlogConverter; +import com.buession.redis.core.internal.convert.response.InfoConverter; +import com.buession.redis.utils.SafeEncoder; + +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * Lettuce 集群模式服务端命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterServerOperations extends AbstractServerOperations { + + public LettuceClusterServerOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public String bgRewriteAof() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.BGREWRITEAOF) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.BGREWRITEAOF) + .run(); + }else{ + return new LettuceClusterCommand(client, Command.BGREWRITEAOF) + .run(); + } + } + + @Override + public String bgSave() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.BGSAVE) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.BGSAVE) + .run(); + }else{ + return new LettuceClusterCommand(client, Command.BGSAVE) + .run(); + } + } + + @Override + public Status configSet(final String parameter, final String value) { + final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CONFIG_SET, + (cmd)->cmd.configSet(parameter, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CONFIG_SET, + (cmd)->cmd.configSet(parameter, value), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CONFIG_SET, + (cmd)->cmd.configSet(parameter, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status configSet(final Map configs) { + final CommandArguments args = CommandArguments.create("configs", configs); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CONFIG_SET, + (cmd)->cmd.configSet(configs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CONFIG_SET, + (cmd)->cmd.configSet(configs), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CONFIG_SET, (cmd)->cmd.configSet(configs), + okStatusConverter) + .run(args); + } + } + + @Override + public Map configGet(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CONFIG_GET, + (cmd)->cmd.configGet(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CONFIG_GET, + (cmd)->cmd.configGet(pattern), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CONFIG_GET, (cmd)->cmd.configGet(pattern), + (v)->v) + .run(args); + } + } + + @Override + public Map configGet(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final String sPattern = SafeEncoder.encode(pattern); + final Converter, Map> converter = Converters.mapStringToBinary(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CONFIG_GET, + (cmd)->cmd.configGet(sPattern), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CONFIG_GET, + (cmd)->cmd.configGet(sPattern), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.CONFIG_GET, (cmd)->cmd.configGet(sPattern), + converter) + .run(args); + } + } + + @Override + public Status configResetStat() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CONFIG_RESETSTAT, + (cmd)->cmd.configResetstat(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CONFIG_RESETSTAT, + (cmd)->cmd.configResetstat(), okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.CONFIG_RESETSTAT, (cmd)->cmd.configResetstat(), + okStatusConverter) + .run(); + } + } + + @Override + public Status configRewrite() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.CONFIG_REWRITE, + (cmd)->cmd.configRewrite(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.CONFIG_REWRITE, + (cmd)->cmd.configRewrite(), okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.CONFIG_REWRITE, (cmd)->cmd.configRewrite(), + okStatusConverter) + .run(); + } + } + + @Override + public Long dbSize() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.DBSIZE, (cmd)->cmd.dbsize(), (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.DBSIZE, (cmd)->cmd.dbsize(), (v)->v) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.DBSIZE, (cmd)->cmd.dbsize(), (v)->v) + .run(); + } + } + + @Override + public Status failover() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.FAILOVER) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.FAILOVER) + .run(); + }else{ + return new LettuceClusterCommand(client, Command.FAILOVER) + .run(); + } + } + + @Override + public Status failover(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + return failover(args); + } + + @Override + public Status failover(final String host, final int port, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("timeout", timeout); + return failover(args); + } + + @Override + public Status failover(final String host, final int port, final boolean isForce, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("isForce", isForce) + .put("timeout", timeout); + return failover(args); + } + + @Override + public Status failover(final int timeout) { + final CommandArguments args = CommandArguments.create("timeout", timeout); + return failover(args); + } + + @Override + public Status flushAll() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.FLUSHALL, (cmd)->cmd.flushall(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.FLUSHALL, (cmd)->cmd.flushall(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.FLUSHALL, (cmd)->cmd.flushall(), + okStatusConverter) + .run(); + } + } + + @Override + public Status flushAll(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.FLUSHALL, + (cmd)->mode == FlushMode.ASYNC ? cmd.flushallAsync() : cmd.flushall(), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.FLUSHALL, + (cmd)->mode == FlushMode.ASYNC ? cmd.flushallAsync() : cmd.flushall(), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.FLUSHALL, + (cmd)->mode == FlushMode.ASYNC ? cmd.flushallAsync() : cmd.flushall(), okStatusConverter) + .run(args); + } + } + + @Override + public Status flushDb() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.FLUSHDB, (cmd)->cmd.flushdb(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.FLUSHDB, (cmd)->cmd.flushdb(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.FLUSHDB, (cmd)->cmd.flushdb(), okStatusConverter) + .run(); + } + } + + @Override + public Status flushDb(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.FLUSHDB, (cmd)->mode == FlushMode.ASYNC ? + cmd.flushdbAsync() : cmd.flushdb(), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.FLUSHDB, + (cmd)->mode == FlushMode.ASYNC ? + cmd.flushdbAsync() : cmd.flushdb(), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.FLUSHDB, (cmd)->mode == FlushMode.ASYNC ? + cmd.flushdbAsync() : cmd.flushdb(), okStatusConverter) + .run(args); + } + } + + @Override + public Info info() { + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(), + infoConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(), + infoConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(), infoConverter) + .run(); + } + } + + @Override + public Info info(final Info.Section section) { + final CommandArguments args = CommandArguments.create("section", section); + final String sectionName = section.name().toLowerCase(); + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(sectionName), + infoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(sectionName), + infoConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(sectionName), + infoConverter) + .run(args); + } + } + + @Override + public Long lastSave() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.LASTSAVE, (cmd)->cmd.lastsave(), + Date::getTime) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.LASTSAVE, (cmd)->cmd.lastsave(), + Date::getTime) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.LASTSAVE, (cmd)->cmd.lastsave(), Date::getTime) + .run(); + } + } + + @Override + public String memoryDoctor() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.MEMORY_DOCTOR) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.MEMORY_DOCTOR) + .run(); + }else{ + return new LettuceClusterCommand(client, Command.MEMORY_DOCTOR) + .run(); + } + } + + @Override + public Status memoryPurge() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.MEMORY_PURGE) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.MEMORY_PURGE) + .run(); + }else{ + return new LettuceClusterCommand(client, Command.MEMORY_PURGE) + .run(); + } + } + + @Override + public MemoryStats memoryStats() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.MEMORY_STATS) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.MEMORY_STATS) + .run(); + }else{ + return new LettuceClusterCommand(client, Command.MEMORY_STATS) + .run(); + } + } + + @Override + public Long memoryUsage(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + } + } + + @Override + public Long memoryUsage(final byte[] key, final int samples) { + final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + } + } + + @Override + public List moduleList() { + return notCommand(client, Command.MODULE_LIST); + } + + @Override + public Status moduleLoad(final String path) { + final CommandArguments args = CommandArguments.create("path", path); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleLoad(final byte[] path) { + final CommandArguments args = CommandArguments.create("path", path); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleLoad(final String path, final String... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleLoad(final byte[] path, final byte[]... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleUnLoad(final String name) { + final CommandArguments args = CommandArguments.create("name", name); + return notCommand(client, Command.MODULE_UNLOAD, args); + } + + @Override + public Status moduleUnLoad(final byte[] name) { + final CommandArguments args = CommandArguments.create("name", name); + return notCommand(client, Command.MODULE_UNLOAD, args); + } + + @Override + public void monitor(final RedisMonitor redisMonitor) { + final CommandArguments args = CommandArguments.create("redisMonitor", redisMonitor); + + if(isPipeline()){ + new LettuceClusterPipelineCommand<>(client, Command.MONITOR) + .run(args); + }else if(isTransaction()){ + new LettuceClusterTransactionCommand<>(client, Command.MONITOR) + .run(args); + }else{ + new LettuceClusterCommand<>(client, Command.MONITOR) + .run(args); + } + } + + @Override + public Object pSync(final String replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return pSync(args); + } + + @Override + public Object pSync(final byte[] replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return pSync(args); + } + + @Override + public void sync() { + if(isPipeline()){ + new LettuceClusterPipelineCommand<>(client, Command.SYNC) + .run(); + }else if(isTransaction()){ + new LettuceClusterTransactionCommand<>(client, Command.SYNC) + .run(); + }else{ + new LettuceClusterCommand<>(client, Command.SYNC) + .run(); + } + } + + @Override + public Status replicaOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.REPLICAOF) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.REPLICAOF) + .run(args); + }else{ + return new LettuceClusterCommand(client, Command.REPLICAOF) + .run(args); + } + } + + @Override + public Status slaveOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SLAVEOF, (cmd)->cmd.slaveof(host, port), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SLAVEOF, + (cmd)->cmd.slaveof(host, port), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SLAVEOF, (cmd)->cmd.slaveof(host, port), + okStatusConverter) + .run(args); + } + } + + @Override + public Role role() { + final RoleConverter roleConverter = new RoleConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ROLE, (cmd)->cmd.role(), roleConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ROLE, (cmd)->cmd.role(), + roleConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.ROLE, (cmd)->cmd.role(), roleConverter) + .run(); + } + } + + @Override + public Status save() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SAVE, (cmd)->cmd.save(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SAVE, (cmd)->cmd.save(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.SAVE, (cmd)->cmd.save(), okStatusConverter) + .run(); + } + } + + @Override + public void shutdown() { + if(isPipeline()){ + new LettuceClusterPipelineCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(true); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new LettuceClusterTransactionCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(true); + return null; + }, (v)->v) + .run(); + }else{ + new LettuceClusterCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(true); + return null; + }, (v)->v) + .run(); + } + } + + @Override + public void shutdown(final boolean save) { + final CommandArguments args = CommandArguments.create("save", save); + + if(isPipeline()){ + new LettuceClusterPipelineCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(save); + return null; + }, (v)->v) + .run(args); + }else if(isTransaction()){ + new LettuceClusterTransactionCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(save); + return null; + }, (v)->v) + .run(args); + }else{ + new LettuceClusterCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(save); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public List slowLogGet() { + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + } + } + + @Override + public List slowLogGet(final int count) { + final CommandArguments args = CommandArguments.create("count", count); + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SLOWLOG_GET, + (cmd)->cmd.slowlogGet((int) count), listSlowlogConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SLOWLOG_GET, + (cmd)->cmd.slowlogGet((int) count), listSlowlogConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SLOWLOG_GET, (cmd)->cmd.slowlogGet((int) count), + listSlowlogConverter) + .run(args); + } + } + + @Override + public Long slowLogLen() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SLOWLOG_LEN, (cmd)->cmd.slowlogLen(), + (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SLOWLOG_LEN, (cmd)->cmd.slowlogLen(), + (v)->v) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.SLOWLOG_LEN, (cmd)->cmd.slowlogLen(), (v)->v) + .run(); + } + } + + @Override + public Status slowLogReset() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SLOWLOG_RESET, + (cmd)->cmd.slowlogReset(), okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + } + } + + @Override + public Status swapdb(final int db1, final int db2) { + final CommandArguments args = CommandArguments.create("db1", db1).put("db2", db2); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.SWAPDB) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.SWAPDB) + .run(args); + }else{ + return new LettuceClusterCommand(client, Command.SWAPDB) + .run(args); + } + } + + @Override + public RedisServerTime time() { + final RedisServerTimeConverter redisServerTimeConverter = new RedisServerTimeConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.TIME, (cmd)->cmd.time(), + redisServerTimeConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.TIME, (cmd)->cmd.time(), + redisServerTimeConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, Command.TIME, (cmd)->cmd.time(), + redisServerTimeConverter) + .run(); + } + } + + private Status aclSetUser(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.ACL_SETUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.ACL_SETUSER) + .run(args); + }else{ + return new LettuceClusterCommand(client, Command.ACL_SETUSER) + .run(args); + } + } + + private AclUser aclGetUser(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.ACL_GETUSER) + .run(args); + }else{ + return new LettuceClusterCommand(client, Command.ACL_GETUSER) + .run(args); + } + } + + private Long aclDelUser(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.ACL_DELUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.ACL_DELUSER) + .run(args); + }else{ + return new LettuceClusterCommand(client, Command.ACL_DELUSER) + .run(args); + } + } + + private Status failover(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.FAILOVER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.FAILOVER) + .run(args); + }else{ + return new LettuceClusterCommand(client, Command.FAILOVER) + .run(args); + } + } + + private Status moduleLoad(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.MODULE_LOAD) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.MODULE_LOAD) + .run(args); + }else{ + return new LettuceClusterCommand(client, Command.MODULE_LOAD) + .run(args); + } + } + + private Status moduleUnLoad(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.MODULE_UNLOAD) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.MODULE_UNLOAD) + .run(args); + }else{ + return new LettuceClusterCommand(client, Command.MODULE_UNLOAD) + .run(args); + } + } + + private Object pSync(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PSYNC) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PSYNC) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.PSYNC) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterSetOperations.java new file mode 100644 index 000000000..89a654fa5 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterSetOperations.java @@ -0,0 +1,598 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.SetConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.ValueScanCursor; + +import java.util.List; +import java.util.Set; + +/** + * Lettuce 集群模式集合命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterSetOperations extends AbstractSetOperations { + + public LettuceClusterSetOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Long sAdd(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long sCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } + } + + @Override + public Set sDiff(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sDiff(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return sDiff(keys, (v)->v, args); + } + + @Override + public Long sDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Set sInter(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sInter(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return sInter(keys, (v)->v, args); + } + + @Override + public Long sInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Boolean sIsMember(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + } + } + + @Override + public List smIsMember(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return smIsMember(args); + } + + @Override + public List smIsMember(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return smIsMember(args); + } + + @Override + public Set sMembers(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sMembers(bKey, binaryToStringSetConverter, args); + } + + @Override + public Set sMembers(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return sMembers(key, (v)->v, args); + } + + @Override + public Status sMove(final byte[] key, final byte[] destKey, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SMOVE, + (cmd)->cmd.smove(key, destKey, member), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SMOVE, + (cmd)->cmd.smove(key, destKey, member), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SMOVE, (cmd)->cmd.smove(key, destKey, member), + booleanStatusConverter) + .run(args); + } + } + + @Override + public String sPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return sPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] sPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return sPop(key, (v)->v, args); + } + + @Override + public Set sPop(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sPop(bKey, count, binaryToStringSetConverter, args); + } + + @Override + public Set sPop(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return sPop(key, count, (v)->v, args); + } + + @Override + public String sRandMember(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return sRandMember(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] sRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return sRandMember(key, (v)->v, args); + } + + @Override + public List sRandMember(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return sRandMember(bKey, count, listConverter, args); + } + + @Override + public List sRandMember(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return sRandMember(key, count, (v)->v, args); + } + + @Override + public Long sRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } + } + + @Override + public ScanResult> sScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(pattern); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(pattern); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, scanArgs, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, scanArgs, valueScanCursorConverter, args); + } + + @Override + public Set sUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sUnion(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return sUnion(keys, (v)->v, args); + } + + @Override + public Long sUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + } + } + + private Set sDiff(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), converter) + .run(args); + } + } + + private Set sInter(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), converter) + .run(args); + } + } + + private List smIsMember(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, Command.SMISMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, + Command.SMISMEMBER) + .run(args); + }else{ + return new LettuceClusterCommand, List>(client, Command.SMISMEMBER) + .run(args); + } + } + + private Set sMembers(final byte[] key, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), converter) + .run(args); + } + } + + private V sPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), converter) + .run(args); + } + } + + private Set sPop(final byte[] key, final int count, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), converter) + .run(args); + } + } + + private V sRandMember(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SPOP, (cmd)->cmd.srandmember(key), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.srandmember(key), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), + converter) + .run(args); + } + } + + private List sRandMember(final byte[] key, final int count, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, count), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key, count), + converter) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), converter) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanArgs), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanArgs), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor, scanArgs), + converter) + .run(args); + } + } + + private Set sUnion(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterSortedSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterSortedSetOperations.java new file mode 100644 index 000000000..a031ece21 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterSortedSetOperations.java @@ -0,0 +1,1878 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.NumberUtils; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.Aggregate; +import com.buession.redis.core.GtLt; +import com.buession.redis.core.NxXx; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; +import com.buession.redis.core.ZRangeBy; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.KeyValueConverter; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.convert.lettuce.response.ScoredValueTupleConverter; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.core.internal.lettuce.LettuceZAddArgs; +import com.buession.redis.core.internal.lettuce.LettuceZStoreArgs; +import com.buession.redis.core.internal.lettuce.utils.ScoredValueUtils; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.Limit; +import io.lettuce.core.Range; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.ScoredValue; +import io.lettuce.core.ScoredValueScanCursor; +import io.lettuce.core.ZAddArgs; +import io.lettuce.core.ZStoreArgs; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 集群模式模式有序集合命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterSortedSetOperations extends AbstractSortedSetOperations { + + public LettuceClusterSortedSetOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Tuple zPopMin(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final ScoredValueTupleConverter.BinaryScoredValueTupleConverter scoredValueConverter = new ScoredValueTupleConverter.BinaryScoredValueTupleConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + } + } + + @Override + public List zPopMin(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZPOPMIN, + (cmd)->cmd.zpopmin(key, count), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + } + } + + @Override + public Tuple zPopMax(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final ScoredValueTupleConverter.BinaryScoredValueTupleConverter scoredValueConverter = new ScoredValueTupleConverter.BinaryScoredValueTupleConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + } + } + + @Override + public List zPopMax(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZPOPMAX, + (cmd)->cmd.zpopmin(key, count), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + } + } + + @Override + public com.buession.lang.KeyValue bzPopMin(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final KeyValueConverter, String, Tuple> converter = new KeyValueConverter<>( + SafeEncoder::encode, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMin(bKeys, timeout, converter, args); + } + + @Override + public com.buession.lang.KeyValue bzPopMin(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter, byte[], Tuple> converter = new KeyValueConverter<>( + (k)->k, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMin(keys, timeout, converter, args); + } + + @Override + public com.buession.lang.KeyValue bzPopMax(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final KeyValueConverter, String, Tuple> converter = new KeyValueConverter<>( + SafeEncoder::encode, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMax(bKeys, timeout, converter, args); + } + + @Override + public com.buession.lang.KeyValue bzPopMax(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter, byte[], Tuple> converter = new KeyValueConverter<>( + (k)->k, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMax(keys, timeout, converter, args); + } + + @Override + public Long zAdd(final String key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + return zAdd(key, members, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + return zAdd(key, members, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } + } + + @Override + public Long zCount(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, range), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, range), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, range), (v)->v) + .run(args); + } + } + + @Override + public List zDiff(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public List zDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public List zDiffWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public List zDiffWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public Long zDiffStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + return zDiffStore(args); + } + + @Override + public Long zDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + return zDiffStore(args); + } + + @Override + public Double zIncrBy(final byte[] key, final double increment, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) + .put("member", member); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), + (v)->v) + .run(args); + } + } + + @Override + public List zInter(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate); + + return zInterStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(weights); + + return zInterStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate, weights); + + return zInterStore(destKey, keys, zStoreArgs, args); + } + + @Override + public List zMScore(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return zMScore(args); + } + + @Override + public List zMScore(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return zMScore(args); + } + + @Override + public String zRandMember(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + return zRandMember(args); + } + + @Override + public byte[] zRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return zRandMember(args); + } + + @Override + public List zRandMember(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMember(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMemberWithScores(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMemberWithScores(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRange(bKey, start, end, listConverter, args); + } + + @Override + public List zRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return zRange(key, start, end, (v)->v, args); + } + + @Override + public List zRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRangeByLex(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRangeByLex(bKey, bMin, bMax, listConverter, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, (v)->v, args); + } + + @Override + public List zRangeByLex(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRangeByLex(bKey, bMin, bMax, offset, count, listConverter, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, offset, count, (v)->v, args); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRangeByScore(bKey, min, max, listConverter, args); + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRangeByScore(key, min, max, (v)->v, args); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRangeByScore(bKey, min, max, offset, count, listConverter, args); + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRangeByScore(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final Range range = Range.create(min, max); + final Limit limit = Limit.create(offset, count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + } + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public Long zRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangebyscore(key, range), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangebyscore(key, range), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangebyscore(key, range), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByRank(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangebyrank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangebyrank(key, start, end), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangebyrank(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List zRevRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRevRange(bKey, start, end, listConverter, args); + } + + @Override + public List zRevRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return zRevRange(key, start, end, (v)->v, args); + } + + @Override + public List zRevRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRevRangeByLex(bKey, bMin, bMax, listConverter, args); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(key, bMin, bMax, (v)->v, args); + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRevRangeByLex(bKey, bMin, bMax, offset, count, listConverter, args); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(key, bMin, bMax, offset, count, (v)->v, args); + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRevRangeByScore(bKey, min, max, listConverter, args); + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRevRangeByScore(key, min, max, (v)->v, args); + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRevRangeByScore(bKey, min, max, offset, count, listConverter, args); + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRevRangeByScore(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final Range range = Range.create(min, max); + final Limit limit = Limit.create(offset, count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + } + } + + @Override + public Long zRevRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + } + } + + @Override + public ScanResult> zScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public Double zScore(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZSCORE, + (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } + } + + @Override + public List zUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate); + + return zUnionStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(weights); + + return zUnionStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate, weights); + + return zUnionStore(destKey, keys, zStoreArgs, args); + } + + private com.buession.lang.KeyValue bzPopMin(final byte[][] keys, final int timeout, + final KeyValueConverter, K, + Tuple> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + converter) + .run(args); + } + } + + private com.buession.lang.KeyValue bzPopMax(final byte[][] keys, final int timeout, + final KeyValueConverter, + K, Tuple> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + converter) + .run(args); + } + } + + private Long zAdd(final String key, final Map members, final CommandArguments args) { + final byte[] bKey = SafeEncoder.encode(key); + return zAdd(bKey, ScoredValueUtils.fromStringMap(members), args); + } + + private Long zAdd(final String key, final Map members, final ZAddArgs zAddArgs, + final CommandArguments args) { + final byte[] bKey = SafeEncoder.encode(key); + return zAdd(bKey, ScoredValueUtils.fromStringMap(members), zAddArgs, args); + } + + private Long zAdd(final byte[] key, final Map members, final CommandArguments args) { + return zAdd(key, ScoredValueUtils.fromBinaryMap(members), args); + } + + private Long zAdd(final byte[] key, final Map members, final ZAddArgs zAddArgs, + final CommandArguments args) { + return zAdd(key, ScoredValueUtils.fromBinaryMap(members), zAddArgs, args); + } + + private Long zAdd(final byte[] key, final ScoredValue[] scoredValues, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, scoredValues), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, scoredValues), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, scoredValues), (v)->v) + .run(args); + } + } + + private Long zAdd(final byte[] key, final ScoredValue[] scoredValues, final ZAddArgs zAddArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, zAddArgs, scoredValues), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, zAddArgs, scoredValues), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, zAddArgs, scoredValues), (v)->v) + .run(args); + } + } + + private List zDiff(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, Command.ZDIFF) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, Command.ZDIFF) + .run(args); + }else{ + return new LettuceClusterCommand, List>(client, Command.ZDIFF) + .run(args); + } + } + + private Long zDiffStore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.ZDIFFSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.ZDIFFSTORE) + .run(args); + }else{ + return new LettuceClusterCommand(client, Command.ZDIFFSTORE) + .run(args); + } + } + + private List zInter(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, Command.ZINTER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, Command.ZINTER) + .run(args); + }else{ + return new LettuceClusterCommand, List>(client, Command.ZINTER) + .run(args); + } + } + + private Long zInterStore(final byte[] destKey, final byte[][] keys, final ZStoreArgs zStoreArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + } + } + + private List zMScore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, Command.ZMSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, Command.ZMSCORE) + .run(args); + }else{ + return new LettuceClusterCommand, List>(client, Command.ZMSCORE) + .run(args); + } + } + + private V zRandMember(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.ZRANDMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.ZRANDMEMBER) + .run(args); + }else{ + return new LettuceClusterCommand(client, Command.ZRANDMEMBER) + .run(args); + } + } + + private List zRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrange(key, start, end), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrange(key, start, end), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), + converter) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final Converter, List> converter, final CommandArguments args) { + return zRangeByLex(key, Range.create(min, max), converter, args); + } + + private List zRangeByLex(final byte[] key, final Range range, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZRANGEBYLEX, (cmd)->cmd.zrangebylex(key, range), + converter) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final int count, final Converter, List> converter, + final CommandArguments args) { + return zRangeByLex(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRangeByLex(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range, limit), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range, limit), converter) + .run(args); + } + } + + private List zRangeByScore(final byte[] key, final double min, final double max, + final Converter, List> converter, final CommandArguments args) { + return zRangeByScore(key, Range.create(min, max), converter, args); + } + + private List zRangeByScore(final byte[] key, final Range range, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range), converter) + .run(args); + } + } + + private List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count, final Converter, List> converter, + final CommandArguments args) { + return zRangeByScore(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRangeByScore(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range, limit), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range, limit), converter) + .run(args); + } + } + + private Long zRangeStore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.ZRANGESTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.ZRANGESTORE) + .run(args); + }else{ + return new LettuceClusterCommand(client, Command.ZRANGESTORE) + .run(args); + } + } + + private List zRevRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), + converter) + .run(args); + } + } + + private List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final Converter, List> converter, final CommandArguments args) { + return zRevRangeByLex(key, Range.create(min, max), converter, args); + } + + private List zRevRangeByLex(final byte[] key, final Range range, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range), converter) + .run(args); + } + } + + private List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final int count, final Converter, List> converter, + final CommandArguments args) { + return zRevRangeByLex(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRevRangeByLex(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range, limit), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range, limit), converter) + .run(args); + } + } + + private List zRevRangeByScore(final byte[] key, final double min, final double max, + final Converter, List> converter, + final CommandArguments args) { + return zRevRangeByScore(key, Range.create(min, max), converter, args); + } + + private List zRevRangeByScore(final byte[] key, final Range range, + final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range), converter) + .run(args); + } + } + + private List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count, final Converter, List> converter, + final CommandArguments args) { + return zRevRangeByScore(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRevRangeByScore(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range, limit), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range, limit), converter) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zscan(key, cursor), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZREVRANK, + (cmd)->cmd.zscan(key, cursor), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zscan(key, cursor), + converter) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanArgs), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanArgs), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanArgs), + converter) + .run(args); + } + } + + private List zUnion(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, Command.ZUNION) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, Command.ZUNION) + .run(args); + }else{ + return new LettuceClusterCommand, List>(client, Command.ZUNION) + .run(args); + } + } + + private Long zUnionStore(final byte[] destKey, final byte[][] keys, final ZStoreArgs zStoreArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterStreamOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterStreamOperations.java new file mode 100644 index 000000000..45629e660 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterStreamOperations.java @@ -0,0 +1,1098 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.Stream; +import com.buession.redis.core.StreamConsumer; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import com.buession.redis.core.StreamGroup; +import com.buession.redis.core.StreamPending; +import com.buession.redis.core.StreamPendingSummary; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.ApproximateExactTrimming; +import com.buession.redis.core.command.args.XAddArgument; +import com.buession.redis.core.command.args.XClaimArgument; +import com.buession.redis.core.command.args.XReadArgument; +import com.buession.redis.core.command.args.XReadGroupArgument; +import com.buession.redis.core.command.args.XTrimArgument; +import com.buession.redis.core.internal.convert.lettuce.params.StreamEntryIdConverter; +import com.buession.redis.core.internal.convert.lettuce.response.PendingMessageConverter; +import com.buession.redis.core.internal.convert.lettuce.response.PendingMessagesConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamConsumersInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamEntryIDConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamFullInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamGroupInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamMessageConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamMessageMapConverter; +import com.buession.redis.core.internal.lettuce.LettuceXAddArgs; +import com.buession.redis.core.internal.lettuce.LettuceXClaimArgs; +import com.buession.redis.core.internal.lettuce.LettuceXGroupCreateArgs; +import com.buession.redis.core.internal.lettuce.LettuceXPendingArgs; +import com.buession.redis.core.internal.lettuce.LettuceXReadArgs; +import com.buession.redis.core.internal.lettuce.LettuceXReadGroupArgs; +import com.buession.redis.core.internal.lettuce.utils.StreamOffsetUtils; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.Consumer; +import io.lettuce.core.Limit; +import io.lettuce.core.Range; +import io.lettuce.core.StreamMessage; +import io.lettuce.core.XAddArgs; +import io.lettuce.core.XClaimArgs; +import io.lettuce.core.XGroupCreateArgs; +import io.lettuce.core.XReadArgs; +import io.lettuce.core.models.stream.PendingMessage; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 集群模式 Stream 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterStreamOperations extends AbstractStreamOperations { + + public LettuceClusterStreamOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("ids", (Object[]) ids); + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, messageIds), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, messageIds), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, messageIds), (v)->v) + .run(args); + } + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash); + final XAddArgs xAddArgs = new LettuceXAddArgs(id); + + return xAdd(key, hash, xAddArgs, args); + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) + .put("xAddArgument", xAddArgument); + final XAddArgs xAddArgs = LettuceXAddArgs.from(xAddArgument).id(id); + + return xAdd(key, hash, xAddArgs, args); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count"); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count"); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaimJustId(args); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = new LettuceXClaimArgs(minIdleTime); + + return xClaim(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = LettuceXClaimArgs.from(xClaimArgument).minIdleTime(minIdleTime); + + return xClaim(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = null;//new LettuceXClaimArgs(minIdleTime, true); + + return xClaimJustId(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = LettuceXClaimArgs.from(xClaimArgument).minIdleTime(minIdleTime).justid(); + + return xClaimJustId(key, ids, consumer, xClaimArgs, args); + } + + @Override + public Long xDel(final byte[] key, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("ids", (Object[]) ids); + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XDEL, (cmd)->cmd.xdel(key, messageIds), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XDEL, + (cmd)->cmd.xdel(key, messageIds), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XDEL, (cmd)->cmd.xdel(key, messageIds), (v)->v) + .run(args); + } + } + + @Override + public Status xGroupCreate(final byte[] key, final byte[] groupName, final StreamEntryId id, + final boolean makeStream) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("id", id); + final XReadArgs.StreamOffset streamOffset = XReadArgs.StreamOffset.latest(key); + final XGroupCreateArgs xGroupCreateArgs = new LettuceXGroupCreateArgs(makeStream); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(streamOffset, groupName, xGroupCreateArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(streamOffset, groupName, xGroupCreateArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(streamOffset, groupName, xGroupCreateArgs), okStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + return xGroupCreateConsumer(args); + } + + @Override + public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + return xGroupCreateConsumer(args); + } + + @Override + public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelconsumer(key, consumer), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelconsumer(key, consumer), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelconsumer(key, consumer), (v)->v) + .run(args); + } + } + + @Override + public Status xGroupDestroy(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), booleanStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupSetId(final byte[] key, final byte[] groupName, final StreamEntryId id) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName).put("id", id); + final XReadArgs.StreamOffset streamOffset = XReadArgs.StreamOffset.from(key, id.toString()); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XGROUP_SETID, + (cmd)->cmd.xgroupSetid(streamOffset, groupName), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XGROUP_SETID, + (cmd)->cmd.xgroupSetid(streamOffset, groupName), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XGROUP_SETID, + (cmd)->cmd.xgroupSetid(streamOffset, groupName), okStatusConverter) + .run(args); + } + } + + @Override + public List xInfoConsumers(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + final ListConverter listStreamConsumersInfoConverter = StreamConsumersInfoConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + } + } + + @Override + public List xInfoGroups(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final ListConverter listStreamGroupInfoConverter = StreamGroupInfoConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XINFO_GROUPS, + (cmd)->cmd.xinfoGroups(key), listStreamGroupInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XINFO_GROUPS, + (cmd)->cmd.xinfoGroups(key), listStreamGroupInfoConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + } + } + + @Override + public Stream xInfoStream(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final StreamInfoConverter streamInfoConverter = new StreamInfoConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream( + key), streamInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream( + key), streamInfoConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream( + key), streamInfoConverter) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStream(key), streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStream(key), streamFullInfoConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full).put("count", count); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStream(key), streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XINFO_STREAM, + (cmd)->cmd.xinfoStream(key), streamFullInfoConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + } + } + + @Override + public Long xLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } + } + + @Override + public StreamPendingSummary xPending(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + final PendingMessagesConverter pendingMessagesConverter = new PendingMessagesConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName), pendingMessagesConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName), pendingMessagesConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XPENDING, (cmd)->cmd.xpending(key, groupName), + pendingMessagesConverter) + .run(args); + } + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime); + final LettuceXPendingArgs xPendingArgs = new LettuceXPendingArgs<>(minIdleTime, groupName, null); + final ListConverter listStreamPendingConverter = PendingMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, xPendingArgs), listStreamPendingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, xPendingArgs), listStreamPendingConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XPENDING, (cmd)->cmd.xpending(key, xPendingArgs), + listStreamPendingConverter) + .run(args); + } + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("start", start).put("end", end).put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, groupName, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.unbounded(); + final Limit limit = Limit.unlimited(); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("start", start).put("end", end).put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, groupName, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.unbounded(); + final Limit limit = Limit.unlimited(); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final int count, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count, + final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final Range range = Range.create(start.toString(), end.toString()); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XRANGE, (cmd)->cmd.xrange(key, range), + listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XRANGE, (cmd)->cmd.xrange(key, range), + listStreamMessageConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XRANGE, (cmd)->cmd.xrange(key, range), + listStreamMessageConverter) + .run(args); + } + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, range, limit), listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XRANGE, + (cmd)->cmd.xrange(key, range, limit), listStreamMessageConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XRANGE, (cmd)->cmd.xrange(key, range, limit), + listStreamMessageConverter) + .run(args); + } + } + + @Override + public List>> xRead(final Map streams) { + final CommandArguments args = CommandArguments.create("streams", streams); + return xRead(streams, args); + } + + @Override + public List>> xRead(final Map streams, + final XReadArgument xReadArgument) { + final CommandArguments args = CommandArguments.create("streams", streams).put("xReadArgument", xReadArgument); + final XReadArgs xReadArgs = LettuceXReadArgs.from(xReadArgument); + + return xRead(xReadArgs, streams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams); + return xReadGroup(groupName, consumerName, streams, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams); + return xReadGroup(groupName, consumerName, streams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadArgs xReadArgs = LettuceXReadGroupArgs.from(xReadGroupArgument); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadArgs xReadArgs = LettuceXReadGroupArgs.from(xReadGroupArgument); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadGroupArgs(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadGroupArgs(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadArgs xReadArgs = LettuceXReadGroupArgs.from(xReadGroupArgument).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final boolean isNoAck, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadArgs xReadArgs = LettuceXReadGroupArgs.from(xReadGroupArgument).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start); + final Range range = Range.create(start.toString(), end.toString()); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, range), listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, range), listStreamMessageConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XREVRANGE, (cmd)->cmd.xrevrange(key, range), + listStreamMessageConverter) + .run(args); + } + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start) + .put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, range, limit), listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, range, limit), listStreamMessageConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, range, limit), listStreamMessageConverter) + .run(args); + } + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); + return xTrim(key, xTrimArgument.getApproximateExactTrimming(), Long.MAX_VALUE, args); + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) + .put("limit", limit); + return xTrim(key, xTrimArgument.getApproximateExactTrimming(), limit, args); + } + + private StreamEntryId xAdd(final byte[] key, final Map hash, final XAddArgs xAddArgs, + final CommandArguments args) { + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XADD, + (cmd)->cmd.xadd(key, xAddArgs, hash), streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XADD, + (cmd)->cmd.xadd(key, xAddArgs, hash), streamEntryIDConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, xAddArgs, hash), + streamEntryIDConverter) + .run(args); + } + } + + private Map> xAutoClaim(final CommandArguments args) { + + if(isPipeline()){ + return new LettuceClusterPipelineCommand>, Map>>( + client, Command.XAUTOCLAIM) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand>, Map>>( + client, Command.XAUTOCLAIM) + .run(args); + }else{ + return new LettuceClusterCommand>, Map>>( + client, Command.XAUTOCLAIM) + .run(args); + } + } + + private Map> xAutoClaimJustId(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand>, Map>>( + client, Command.XAUTOCLAIM) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand>, Map>>( + client, Command.XAUTOCLAIM) + .run(args); + }else{ + return new LettuceClusterCommand>, Map>>( + client, Command.XAUTOCLAIM) + .run(args); + } + } + + private List xClaim(final byte[] key, final StreamEntryId[] ids, final Consumer consumer, + final XClaimArgs xClaimArgs, final CommandArguments args) { + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageConverter) + .run(args); + } + } + + private List xClaimJustId(final byte[] key, final StreamEntryId[] ids, + final Consumer consumer, final XClaimArgs xClaimArgs, + final CommandArguments args) { + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter, StreamEntryId> listStreamMessageStreamEntryIdConverter + = StreamMessageConverter.StreamMessageStreamEntryIdConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageStreamEntryIdConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageStreamEntryIdConverter) + .run(args); + } + } + + private Status xGroupCreateConsumer(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, Command.XGROUP_CREATECONSUMER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, Command.XGROUP_CREATECONSUMER) + .run(args); + }else{ + return new LettuceClusterCommand(client, Command.XGROUP_CREATECONSUMER) + .run(args); + } + } + + private List xPending(final byte[] key, final byte[] groupName, Range range, + final Limit limit, final CommandArguments args) { + final ListConverter listStreamPendingConverter = PendingMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName, range, limit), listStreamPendingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName, range, limit), listStreamPendingConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName, range, limit), listStreamPendingConverter) + .run(args); + } + } + + private List xPending(final byte[] key, final Consumer consumer, Range range, + final Limit limit, final CommandArguments args) { + final ListConverter listStreamPendingConverter = PendingMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, consumer, range, limit), listStreamPendingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, consumer, range, limit), listStreamPendingConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, consumer, range, limit), listStreamPendingConverter) + .run(args); + } + } + + private List>> xRead(final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromStringMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XREAD, (cmd)->cmd.xread(streamOffsets), + listStreamMessageMapConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XREAD, + (cmd)->cmd.xread(streamOffsets), listStreamMessageMapConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XREAD, (cmd)->cmd.xread(streamOffsets), + listStreamMessageMapConverter) + .run(args); + } + } + + private List>> xRead(final XReadArgs xReadArgs, final Map streams, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromStringMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XREAD, + (cmd)->cmd.xread(xReadArgs, streamOffsets), listStreamMessageMapConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XREAD, + (cmd)->cmd.xread(xReadArgs, streamOffsets), listStreamMessageMapConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XREAD, + (cmd)->cmd.xread(xReadArgs, streamOffsets), listStreamMessageMapConverter) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromStringMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), streamOffsets, + listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromBinaryMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(groupName, consumerName, streamOffsets, listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final XReadArgs.StreamOffset[] streamOffsets, + final Converter>, + List>>> converter, + final CommandArguments args) { + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, streamOffsets), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, streamOffsets), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, streamOffsets), converter) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadArgs xReadArgs, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromStringMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), streamOffsets, xReadArgs, + listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final XReadArgs xReadArgs, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromBinaryMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(groupName, consumerName, streamOffsets, xReadArgs, listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final XReadArgs.StreamOffset[] streamOffsets, + final XReadArgs xReadArgs, + final Converter>, + List>>> converter, + final CommandArguments args) { + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, xReadArgs, streamOffsets), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, xReadArgs, streamOffsets), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, xReadArgs, streamOffsets), converter) + .run(args); + } + } + + private Long xTrim(final byte[] key, final ApproximateExactTrimming approximateExactTrimming, final long limit, + final CommandArguments args) { + final boolean approximateTrimming = ApproximateExactTrimming.APPROXIMATE == approximateExactTrimming; + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.XTRIM, + (cmd)->cmd.xtrim(key, approximateTrimming, limit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.XTRIM, + (cmd)->cmd.xtrim(key, approximateTrimming, limit), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.XTRIM, + (cmd)->cmd.xtrim(key, approximateTrimming, limit), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterStringOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterStringOperations.java new file mode 100644 index 000000000..61753db0f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterStringOperations.java @@ -0,0 +1,544 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.StringUtils; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.GetExArgument; +import com.buession.redis.core.command.args.SetArgument; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.lettuce.LettuceGetExArgs; +import com.buession.redis.core.internal.lettuce.LettuceSetArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.GetExArgs; +import io.lettuce.core.KeyValue; +import io.lettuce.core.SetArgs; +import io.lettuce.core.Value; + +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; + +/** + * Lettuce 集群模式字符串命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterStringOperations extends AbstractStringOperations { + + public LettuceClusterStringOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Long append(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long incr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } + } + + @Override + public Long incrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.INCRBY, (cmd)->cmd.incrby(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.INCRBY, (cmd)->cmd.incrby(key, value), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.INCRBY, (cmd)->cmd.incrby(key, value), (v)->v) + .run(args); + } + } + + @Override + public Double incrByFloat(final byte[] key, final double value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.INCRBYFLOAT, + (cmd)->cmd.incrbyfloat(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.INCRBYFLOAT, + (cmd)->cmd.incrbyfloat(key, value), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.INCRBYFLOAT, (cmd)->cmd.incrbyfloat(key, value), + (v)->v) + .run(args); + } + } + + @Override + public Long decr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } + } + + @Override + public Long decrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.DECRBY, (cmd)->cmd.decrby(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.DECRBY, (cmd)->cmd.decrby(key, value), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.DECRBY, (cmd)->cmd.decrby(key, value), (v)->v) + .run(args); + } + } + + @Override + public String get(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return get(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] get(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return get(key, (v)->v, args); + } + + @Override + public String getEx(final String key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + final byte[] bKey = SafeEncoder.encode(key); + final GetExArgs getExArgs = LettuceGetExArgs.from(getExArgument); + + return getEx(bKey, getExArgs, SafeEncoder::encode, args); + } + + @Override + public byte[] getEx(final byte[] key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + final GetExArgs getExArgs = LettuceGetExArgs.from(getExArgument); + + return getEx(key, getExArgs, (v)->v, args); + } + + @Override + public String getSet(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bValue = SafeEncoder.encode(value); + + return getSet(bKey, bValue, SafeEncoder::encode, args); + } + + @Override + public byte[] getSet(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return getSet(key, value, (v)->v, args); + } + + @Override + public String getDel(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return getDel(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] getDel(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return getDel(key, (v)->v, args); + } + + @Override + public List mGet(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final ListConverter, String> listConverter = + new ListConverter<>((v)->SafeEncoder.encode(v.getValue())); + + return mGet(bKeys, listConverter, args); + } + + @Override + public List mGet(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ListConverter, byte[]> listConverter = new ListConverter<>(Value::getValue); + + return mGet(keys, listConverter, args); + } + + @Override + public Status mSet(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final Map bValues = Converters.mapStringToBinary().convert(values); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.MSET, (cmd)->cmd.mset(bValues), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.MSET, (cmd)->cmd.mset(bValues), + okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.MSET, (cmd)->cmd.mset(bValues), + okStatusConverter) + .run(args); + } + } + + @Override + public Status mSetNx(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final Map bValues = Converters.mapStringToBinary().convert(values); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.MSETNX, (cmd)->cmd.msetnx(bValues), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.MSETNX, (cmd)->cmd.msetnx(bValues), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.MSETNX, (cmd)->cmd.msetnx(bValues), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pSetEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value, final SetArgument setArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final SetArgs setArgs = LettuceSetArgs.from(setArgument); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setArgs), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SET, + (cmd)->cmd.set(key, value, setArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setArgs), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setNx(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Long setRange(final byte[] key, final long offset, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + } + } + + @Override + public byte[] getRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public Long strlen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } + } + + @Override + public String substr(final String key, final int start, final int end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + final Converter converter = (v)->StringUtils.substring(SafeEncoder.encode(v), start, end); + + return substr(bKey, converter, args); + } + + @Override + public byte[] substr(final byte[] key, final int start, final int end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final Converter converter = (v)->StringUtils.substring(SafeEncoder.encode(v), start, end) + .getBytes(StandardCharsets.UTF_8); + + return substr(key, converter, args); + } + + private V get(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GET, (cmd)->cmd.get(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GET, (cmd)->cmd.get(key), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GET, (cmd)->cmd.get(key), converter) + .run(args); + } + } + + private V getEx(final byte[] key, final GetExArgs getExArgs, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GETEX, (cmd)->cmd.getex(key, getExArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GETEX, + (cmd)->cmd.getex(key, getExArgs), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GETEX, (cmd)->cmd.getex(key, getExArgs), + converter) + .run(args); + } + } + + private V getSet(final byte[] key, final byte[] value, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GETSET, (cmd)->cmd.getset(key, value), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GETSET, (cmd)->cmd.getset(key, value), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GETSET, (cmd)->cmd.getset(key, value), converter) + .run(args); + } + } + + private V getDel(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.GETDEL, (cmd)->cmd.getdel(key), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.GETDEL, (cmd)->cmd.getdel(key), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.GETDEL, (cmd)->cmd.getdel(key), converter) + .run(args); + } + } + + private List mGet(final byte[][] keys, final Converter>, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), converter) + .run(args); + } + } + + private V substr(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, Command.SUBSTR, (cmd)->cmd.get(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, Command.SUBSTR, (cmd)->cmd.get(key), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, Command.SUBSTR, (cmd)->cmd.get(key), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterTransactionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterTransactionOperations.java new file mode 100644 index 000000000..fde0806a8 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceClusterTransactionOperations.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; + +import java.util.List; + +/** + * Lettuce 集群模式事务命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterTransactionOperations extends AbstractTransactionOperations { + + public LettuceClusterTransactionOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Status multi() { + return notCommand(client, Command.MULTI); + } + + @Override + public List exec() { + return notCommand(client, Command.EXEC); + } + + @Override + public void discard() { + notCommand(client, Command.DISCARD); + } + + @Override + public Status watch(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return notCommand(client, Command.WATCH, args); + } + + @Override + public Status watch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return notCommand(client, Command.WATCH, args); + } + + @Override + public Status unwatch() { + return notCommand(client, Command.UNWATCH); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceConnectionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceConnectionOperations.java new file mode 100644 index 000000000..c9e745c63 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceConnectionOperations.java @@ -0,0 +1,537 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.Client; +import com.buession.redis.core.ClientAttributeOption; +import com.buession.redis.core.ClientPauseMode; +import com.buession.redis.core.ClientReply; +import com.buession.redis.core.ClientTrackingInfo; +import com.buession.redis.core.ClientType; +import com.buession.redis.core.ClientUnblockType; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.RedisServer; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.ClientKillArgument; +import com.buession.redis.core.command.args.ClientTracking; +import com.buession.redis.core.command.args.HelloArgument; +import com.buession.redis.core.internal.convert.lettuce.params.ClientTypeConverter; +import com.buession.redis.core.internal.convert.lettuce.params.ClientUnblockTypeConverter; +import com.buession.redis.core.internal.convert.response.ClientConverter; +import com.buession.redis.core.internal.convert.response.PingResultConverter; +import com.buession.redis.core.internal.lettuce.LettuceTrackingArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ClientListArgs; +import io.lettuce.core.KillArgs; +import io.lettuce.core.TrackingArgs; +import io.lettuce.core.UnblockType; + +import java.util.List; + +/** + * Lettuce 单机模式连接命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceConnectionOperations extends AbstractConnectionOperations { + + public LettuceConnectionOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Status auth(final String user, final String password) { + final CommandArguments args = CommandArguments.create(user).add(password); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.AUTH, (cmd)->cmd.auth(user, password), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.AUTH, (cmd)->cmd.auth(user, password), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.AUTH, (cmd)->cmd.auth(user, password), + okStatusConverter) + .run(args); + } + } + + @Override + public Status auth(final String password) { + final CommandArguments args = CommandArguments.create(password); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.AUTH, (cmd)->cmd.auth(password), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.AUTH, (cmd)->cmd.auth(password), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.AUTH, (cmd)->cmd.auth(password), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientCaching() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_CACHING); + } + + @Override + public Status clientCaching(final boolean isYes) { + final CommandArguments args = CommandArguments.create(isYes ? Keyword.Common.YES : Keyword.Common.NO); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_CACHING, args); + } + + @Override + public String clientGetName() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_GETNAME, + (cmd)->cmd.clientGetname(), SafeEncoder::encode) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_GETNAME, + (cmd)->cmd.clientGetname(), SafeEncoder::encode) + .run(); + }else{ + return new LettuceCommand<>(client, Command.CLIENT, SubCommand.CLIENT_GETNAME, (cmd)->cmd.clientGetname(), + SafeEncoder::encode) + .run(); + } + } + + @Override + public Integer clientGetRedir() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_GETREDIR); + } + + @Override + public Long clientId() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_ID, (cmd)->cmd.clientId(), + (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_ID, (cmd)->cmd.clientId(), + (v)->v) + .run(); + }else{ + return new LettuceCommand<>(client, Command.CLIENT, SubCommand.CLIENT_ID, (cmd)->cmd.clientId(), (v)->v) + .run(); + } + } + + @Override + public Client clientInfo() { + final ClientConverter clientConverter = new ClientConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_INFO, (cmd)->cmd.clientInfo(), + clientConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_INFO, + (cmd)->cmd.clientInfo(), clientConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.CLIENT, SubCommand.CLIENT_INFO, (cmd)->cmd.clientInfo(), + clientConverter) + .run(); + } + } + + @Override + public Status clientKill(final String host, final int port) { + final CommandArguments args = CommandArguments.create(host).add(port); + final String addr = host + ':' + port; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(addr), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(addr), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, (cmd)->cmd.clientKill(addr), + okStatusConverter) + .run(args); + } + } + + @Override + public Long clientKill(final ClientKillArgument... clientKillArguments) { + final CommandArguments args = CommandArguments.create(clientKillArguments); + final KillArgs killArgs = createKillArgsFromClientKillArgument(clientKillArguments); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(killArgs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(killArgs), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, (cmd)->cmd.clientKill(killArgs), + (v)->v) + .run(args); + } + } + + @Override + public List clientList() { + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(), clientListConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + } + } + + @Override + public List clientList(final ClientType clientType) { + final CommandArguments args = CommandArguments.create(clientType); + final ClientListArgs clientListArgs = (new ClientTypeConverter()).convert(clientType); + + return clientList(clientListArgs, args); + } + + @Override + public List clientList(final long... clientIds) { + final CommandArguments args = CommandArguments.create(clientIds); + final ClientListArgs clientListArgs = ClientListArgs.Builder.ids(clientIds); + + return clientList(clientListArgs, args); + } + + @Override + public Status clientNoEvict(final boolean on) { + final CommandArguments args = CommandArguments.create(on ? Keyword.Common.ON : Keyword.Common.OFF); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_NO_EVICT, + (cmd)->cmd.clientNoEvict(on), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_NO_EVICT, + (cmd)->cmd.clientNoEvict(on), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLIENT, SubCommand.CLIENT_NO_EVICT, + (cmd)->cmd.clientNoEvict(on), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientNoTouch(final boolean on) { + final CommandArguments args = CommandArguments.create(on ? Keyword.Common.ON : Keyword.Common.OFF); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_NO_TOUCH, args); + } + + @Override + public Status clientPause(final int timeout) { + final CommandArguments args = CommandArguments.create(timeout); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientPause(final int timeout, final ClientPauseMode pauseMode) { + final CommandArguments args = CommandArguments.create(timeout).add(pauseMode); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientReply(final ClientReply option) { + final CommandArguments args = CommandArguments.create(option); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_REPLY, args); + } + + @Override + public Status clientSetInfo(final ClientAttributeOption clientAttributeOption, final String value) { + final CommandArguments args = CommandArguments.create(clientAttributeOption).add(value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETINFO, + (cmd)->cmd.clientSetinfo(clientAttributeOption.name(), value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETINFO, + (cmd)->cmd.clientSetinfo(clientAttributeOption.name(), value), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETINFO, + (cmd)->cmd.clientSetinfo(clientAttributeOption.name(), value), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientSetName(final byte[] name) { + final CommandArguments args = CommandArguments.create(name); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientTracking(final ClientTracking clientTracking) { + final CommandArguments args = CommandArguments.create(clientTracking); + final TrackingArgs trackingArgs = LettuceTrackingArgs.from(clientTracking); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_TRACKING, + (cmd)->cmd.clientTracking(trackingArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_TRACKING, + (cmd)->cmd.clientTracking(trackingArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLIENT, SubCommand.CLIENT_TRACKING, + (cmd)->cmd.clientTracking(trackingArgs), okStatusConverter) + .run(args); + } + } + + @Override + public ClientTrackingInfo clientTrackingInfo() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_TRACKINGINFO); + } + + @Override + public Status clientUnblock(final int clientId) { + final CommandArguments args = CommandArguments.create(clientId); + return clientUnblock(clientId, UnblockType.TIMEOUT, args); + } + + @Override + public Status clientUnblock(final int clientId, final ClientUnblockType type) { + final CommandArguments args = CommandArguments.create(clientId).add(type); + final UnblockType unblockType = (new ClientUnblockTypeConverter()).convert(type); + + return clientUnblock(clientId, unblockType, args); + } + + @Override + public Status clientUnPause() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_UNPAUSE); + } + + @Override + public String echo(final String str) { + final CommandArguments args = CommandArguments.create("str", str); + final byte[] msg = SafeEncoder.encode(str); + + return echo(msg, SafeEncoder::encode, args); + } + + @Override + public byte[] echo(final byte[] str) { + final CommandArguments args = CommandArguments.create("str", str); + return echo(str, (v)->v, args); + } + + @Override + public RedisServer hello(final HelloArgument helloArgument) { + final CommandArguments args = CommandArguments.create(helloArgument); + return notCommand(client, Command.HELLO, args); + } + + @Override + public Status ping() { + final PingResultConverter pingResultConverter = new PingResultConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ECHO, (cmd)->cmd.ping(), pingResultConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ECHO, (cmd)->cmd.ping(), pingResultConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.ECHO, (cmd)->cmd.ping(), pingResultConverter) + .run(); + } + } + + @Override + public Status quit() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.QUIT, (cmd)->cmd.quit(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.QUIT, (cmd)->cmd.quit(), okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.QUIT, (cmd)->cmd.quit(), okStatusConverter) + .run(); + } + } + + @Override + public Status reset() { + if(isPipeline()){ + new LettucePipelineCommand<>(client, Command.RESET, (cmd)->{ + cmd.reset(); + return Status.SUCCESS; + }, (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.RESET, (cmd)->{ + cmd.reset(); + return Status.SUCCESS; + }, (v)->v) + .run(); + }else{ + return new LettuceCommand<>(client, Command.RESET, (cmd)->{ + cmd.reset(); + return Status.SUCCESS; + }, (v)->v) + .run(); + } + } + + @Override + public Status select(final int db) { + final CommandArguments args = CommandArguments.create(db); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SELECT, (cmd)->cmd.select(db), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SELECT, (cmd)->cmd.select(db), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SELECT, (cmd)->cmd.select(db), okStatusConverter) + .run(args); + } + } + + private List clientList(final ClientListArgs clientListArgs, final CommandArguments args) { + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(clientListArgs), clientListConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(clientListArgs), clientListConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(clientListArgs), clientListConverter) + .run(args); + } + } + + private Status clientUnblock(final int clientId, final UnblockType unblockType, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + } + } + + private V echo(final byte[] str, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ECHO, (cmd)->cmd.echo(str), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ECHO, (cmd)->cmd.echo(str), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ECHO, (cmd)->cmd.echo(str), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceGeoOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceGeoOperations.java new file mode 100644 index 000000000..194668a43 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceGeoOperations.java @@ -0,0 +1,486 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.SetListConverter; +import com.buession.lang.Geo; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.GeoAddArgument; +import com.buession.redis.core.command.args.GeoRadiusArgument; +import com.buession.redis.core.command.args.GeoSearchArgument; +import com.buession.redis.core.command.args.GeoSearchStoreArgument; +import com.buession.redis.core.internal.convert.lettuce.params.GeoUnitConverter; +import com.buession.redis.core.internal.convert.lettuce.response.GeoCoordinateConverter; +import com.buession.redis.core.internal.convert.lettuce.response.GeoRadiusGeneralResultConverter; +import com.buession.redis.core.internal.convert.lettuce.response.GeoRadiusResponseConverter; +import com.buession.redis.core.internal.convert.lettuce.response.ValueConverter; +import com.buession.redis.core.internal.lettuce.LettuceGeoAddArgs; +import com.buession.redis.core.internal.lettuce.LettuceGeoArgs; +import com.buession.redis.core.internal.lettuce.LettuceGeoValue; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.GeoAddArgs; +import io.lettuce.core.GeoArgs; +import io.lettuce.core.GeoCoordinates; +import io.lettuce.core.GeoSearch; +import io.lettuce.core.GeoValue; +import io.lettuce.core.GeoWithin; +import io.lettuce.core.Value; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 单机模式地理位置命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceGeoOperations extends AbstractGeoOperations { + + public LettuceGeoOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(member); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + final byte[] bKey = SafeEncoder.encode(key); + final GeoValue[] geoValues = createGeoValueArrayFromGeoMap(memberCoordinates, SafeEncoder::encode); + + return geoAdd(bKey, geoValues, args); + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + final GeoValue[] geoValues = createGeoValueArrayFromGeoMap(memberCoordinates, (v)->v); + + return geoAdd(key, geoValues, args); + } + + @Override + public Long geoAdd(final String key, final String member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(longitude).add(latitude) + .add(member); + final byte[] bKey = SafeEncoder.encode(key); + final GeoValue[] geoValues = new GeoValue[]{LettuceGeoValue.just(longitude, latitude, member)}; + + return geoAdd(bKey, geoValues, geoAddArgument, args); + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(longitude).add(latitude) + .add(member); + final GeoValue[] geoValues = new GeoValue[]{LettuceGeoValue.just(longitude, latitude, member)}; + + return geoAdd(key, geoValues, geoAddArgument, args); + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(memberCoordinates); + final byte[] bKey = SafeEncoder.encode(key); + final GeoValue[] geoValues = createGeoValueArrayFromGeoMap(memberCoordinates, SafeEncoder::encode); + + return geoAdd(bKey, geoValues, geoAddArgument, args); + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(memberCoordinates); + final GeoValue[] geoValues = createGeoValueArrayFromGeoMap(memberCoordinates, (v)->v); + + return geoAdd(key, geoValues, geoAddArgument, args); + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2); + return geoDist(key, member1, member2, GeoArgs.Unit.m, args); + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2).add(unit); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + + return geoDist(key, member1, member2, geoArgsUnit, args); + } + + @Override + public List geoHash(final String key, final String... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + final byte[] bKey = SafeEncoder.encode(key); + final byte[][] bMembers = SafeEncoder.encode(members); + final ListConverter, String> listConverter = ValueConverter.listConverter((v)->v); + + return geoHash(bKey, bMembers, listConverter, args); + } + + @Override + public List geoHash(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + final ListConverter, byte[]> listConverter = ValueConverter.listConverter(SafeEncoder::encode); + + return geoHash(key, members, listConverter, args); + } + + @Override + public List geoPos(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final SetListConverter setListGeoRadiusGeneralResultConverter = + GeoRadiusGeneralResultConverter.setListConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + } + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = + CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit).add(geoRadiusArgument); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final GeoArgs geoArgs = LettuceGeoArgs.from(geoRadiusArgument); + final ListConverter, GeoRadius> listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + return notCommand(client, Command.GEORADIUS_RO, args); + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + return notCommand(client, Command.GEORADIUS_RO, args); + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = + CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit).add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUS_RO, args); + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = + CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit).add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUS_RO, args); + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final SetListConverter setListGeoRadiusGeneralResultConverter = + GeoRadiusGeneralResultConverter.setListConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final GeoArgs geoArgs = LettuceGeoArgs.from(geoRadiusArgument); + final ListConverter, GeoRadius> listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + return notCommand(client, Command.GEORADIUSBYMEMBER_RO, args); + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + return notCommand(client, Command.GEORADIUSBYMEMBER_RO, args); + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUSBYMEMBER_RO, args); + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUSBYMEMBER_RO, args); + } + + @Override + public List geoSearch(final byte[] key, final GeoSearchArgument geoSearchArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoSearchArgument); + final GeoSearch.GeoRef geoRef = createGeoRefFromGeoSearchArgument(geoSearchArgument); + final GeoSearch.GeoPredicate geoPredicate = createGeoPredicateFromGeoSearchArgument(geoSearchArgument); + final GeoArgs geoArgs = LettuceGeoArgs.from(geoSearchArgument); + final ListConverter, GeoRadius> listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GEOSEARCH, (cmd)->cmd.geosearch(key, geoRef, + geoPredicate, geoArgs), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GEOSEARCH, (cmd)->cmd.geosearch(key, geoRef, + geoPredicate, geoArgs), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GEOSEARCH, (cmd)->cmd.geosearch(key, geoRef, + geoPredicate, geoArgs), listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public Long geoSearchStore(final byte[] destKey, final byte[] key, + final GeoSearchStoreArgument geoSearchStoreArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoSearchStoreArgument); + final GeoSearch.GeoRef geoRef = createGeoRefFromGeoSearchStoreArgument(geoSearchStoreArgument); + final GeoSearch.GeoPredicate geoPredicate = createGeoPredicateFromGeoSearchStoreArgument( + geoSearchStoreArgument); + final GeoArgs geoArgs = LettuceGeoArgs.from(geoSearchStoreArgument); + final boolean storeDist = Boolean.TRUE.equals(geoSearchStoreArgument.isStoreDist()); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchstore(destKey, key, geoRef, geoPredicate, geoArgs, storeDist), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GEOSEARCHSTORE, + (cmd)->cmd.geosearchstore(destKey, key, geoRef, geoPredicate, geoArgs, storeDist), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GEOSEARCHSTORE, (cmd)->cmd.geosearchstore(destKey, key, geoRef, + geoPredicate, geoArgs, storeDist), (v)->v) + .run(args); + } + } + + private Long geoAdd(final byte[] key, final GeoValue[] geoValues, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoValues), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoValues), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoValues), (v)->v) + .run(args); + } + } + + private Long geoAdd(final byte[] key, final GeoValue[] geoValues, final GeoAddArgument geoAddArgument, + final CommandArguments args) { + final GeoAddArgs geoAddArgs = LettuceGeoAddArgs.from(geoAddArgument); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoAddArgs, geoValues), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GEOADD, + (cmd)->cmd.geoadd(key, geoAddArgs, geoValues), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GEOADD, (cmd)->cmd.geoadd(key, geoAddArgs, geoValues), (v)->v) + .run(args); + } + } + + private Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoArgs.Unit unit, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, unit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, unit), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GEODIST, (cmd)->cmd.geodist(key, member1, member2, unit), + (v)->v) + .run(args); + } + } + + private List geoHash(final byte[] key, final byte[][] members, + final ListConverter, V> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GEOHASH, (cmd)->cmd.geohash(key, members), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceHashOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceHashOperations.java new file mode 100644 index 000000000..e0cf382a4 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceHashOperations.java @@ -0,0 +1,797 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.ListSetConverter; +import com.buession.core.converter.MapConverter; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.HScanArgument; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.KeyValueConverter; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.lettuce.LettuceExpireArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ExpireArgs; +import io.lettuce.core.MapScanCursor; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; + +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Lettuce 单机模式模式哈希表命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceHashOperations extends AbstractHashOperations { + + public LettuceHashOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Long hDel(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } + } + + @Override + public Boolean hExists(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } + } + + @Override + public List hExpire(final byte[] key, final int lifetime, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields.length) + .add(fields); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HEXPIRE, (cmd)->cmd.hexpire(key, lifetime, fields), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HEXPIRE, (cmd)->cmd.hexpire(key, lifetime, fields), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HEXPIRE, (cmd)->cmd.hexpire(key, lifetime, fields), (v)->v) + .run(args); + } + } + + @Override + public List hExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HEXPIRE, + (cmd)->cmd.hexpire(key, lifetime, expireArgs, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HEXPIRE, + (cmd)->cmd.hexpire(key, lifetime, expireArgs, fields), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HEXPIRE, + (cmd)->cmd.hexpire(key, lifetime, expireArgs, fields), (v)->v) + .run(args); + } + } + + @Override + public List hExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HEXPIREAT, + (cmd)->cmd.hexpireat(key, unixTimestamp, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HEXPIREAT, + (cmd)->cmd.hexpireat(key, unixTimestamp, fields), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HEXPIREAT, (cmd)->cmd.hexpireat(key, unixTimestamp, fields), + (v)->v) + .run(args); + } + } + + @Override + public List hExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HEXPIREAT, (cmd)->cmd.hexpireat(key, unixTimestamp, + expireArgs, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HEXPIREAT, + (cmd)->cmd.hexpireat(key, unixTimestamp, expireArgs, fields), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HEXPIREAT, + (cmd)->cmd.hexpireat(key, unixTimestamp, expireArgs, fields), (v)->v) + .run(args); + } + } + + @Override + public List hExpireTime(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields.length).add(fields); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HEXPIRETIME, (cmd)->cmd.hexpiretime(key, fields), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HEXPIRETIME, (cmd)->cmd.hexpiretime(key, fields), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HEXPIRETIME, (cmd)->cmd.hexpiretime(key, fields), (v)->v) + .run(args); + } + } + + @Override + public String hGet(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bField = SafeEncoder.encode(field); + + return hGet(bKey, bField, SafeEncoder::encode, args); + } + + @Override + public byte[] hGet(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + return hGet(key, field, (v)->v, args); + } + + @Override + public Map hGetAll(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final MapConverter binaryToStringMapConverter = Converters.mapBinaryToString(); + + return hGetAll(bKey, binaryToStringMapConverter, args); + } + + @Override + public Map hGetAll(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return hGetAll(key, (v)->v, args); + } + + @Override + public Long hIncrBy(final byte[] key, final byte[] field, final long value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrby(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrby(key, field, value), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HINCRBY, (cmd)->cmd.hincrby(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Double hIncrByFloat(final byte[] key, final byte[] field, final double value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HINCRBYFLOAT, + (cmd)->cmd.hincrbyfloat(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HINCRBYFLOAT, + (cmd)->cmd.hincrbyfloat(key, field, value), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HINCRBYFLOAT, (cmd)->cmd.hincrbyfloat(key, field, value), + (v)->v) + .run(args); + } + } + + @Override + public Set hKeys(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final ListSetConverter binaryToStringListSetConverter = + Converters.listSetBinaryToString(); + + return hKeys(bKey, binaryToStringListSetConverter, args); + } + + @Override + public Set hKeys(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return hKeys(key, HashSet::new, args); + } + + @Override + public Long hLen(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } + } + + @Override + public List hMGet(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + final byte[] bKey = SafeEncoder.encode(key); + final byte[][] bFields = SafeEncoder.encode(fields); + final ListConverter, String> listConverter = + new ListConverter<>((v)->SafeEncoder.encode(v.getValue())); + + return hMGet(bKey, bFields, listConverter, args); + } + + @Override + public List hMGet(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + final ListConverter, byte[]> listConverter = + new ListConverter<>(io.lettuce.core.KeyValue::getValue); + + return hMGet(key, fields, listConverter, args); + } + + @Override + public Status hMSet(final byte[] key, final Map data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HMSET, (cmd)->cmd.hmset(key, data), okStatusConverter) + .run(args); + } + } + + @Override + public List hPersist(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HPERSIST, (cmd)->cmd.hpersist(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HPERSIST, (cmd)->cmd.hpersist(key, fields), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HPERSIST, (cmd)->cmd.hpersist(key, fields), (v)->v) + .run(args); + } + } + + @Override + public List hpExpire(final byte[] key, final int lifetime, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HPEXPIRE, (cmd)->cmd.hpexpire(key, lifetime, fields), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HPEXPIRE, (cmd)->cmd.hpexpire(key, lifetime, fields), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HPEXPIRE, (cmd)->cmd.hpexpire(key, lifetime, fields), (v)->v) + .run(args); + } + } + + @Override + public List hpExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = + CommandArguments.create(key).add(lifetime).add(expireOption).add(Keyword.Hash.FIELDS, fields); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpire(key, lifetime, expireArgs, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpire(key, lifetime, expireArgs, fields), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpire(key, lifetime, expireArgs, fields), (v)->v) + .run(args); + } + } + + @Override + public List hpExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(Keyword.Hash.FIELDS, fields); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpireat(key, unixTimestamp, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpireat(key, unixTimestamp, fields), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HPEXPIRE, (cmd)->cmd.hpexpireat(key, unixTimestamp, fields), + (v)->v) + .run(args); + } + } + + @Override + public List hpExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = + CommandArguments.create(key).add(unixTimestamp).add(expireOption).add(Keyword.Hash.FIELDS, fields); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpireat(key, unixTimestamp, expireArgs, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpireat(key, unixTimestamp, expireArgs, fields), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HPEXPIRE, + (cmd)->cmd.hpexpireat(key, unixTimestamp, expireArgs, fields), (v)->v) + .run(args); + } + } + + @Override + public List hpExpireTime(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HPEXPIRETIME, (cmd)->cmd.hpexpiretime(key, fields), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HPEXPIRETIME, (cmd)->cmd.hpexpiretime(key, fields), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HPEXPIRETIME, (cmd)->cmd.hpexpiretime(key, fields), (v)->v) + .run(args); + } + } + + @Override + public List hpTtl(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HPTTL, (cmd)->cmd.hpttl(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HPTTL, (cmd)->cmd.hpttl(key, fields), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HPTTL, (cmd)->cmd.hpttl(key, fields), (v)->v) + .run(args); + } + } + + @Override + public String hRandField(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + + return hRandField(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] hRandField(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return hRandField(key, (v)->v, args); + } + + @Override + public List hRandField(final String key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return hRandField(bKey, count, listConverter, args); + } + + @Override + public List hRandField(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count); + return hRandField(key, count, (v)->v, args); + } + + @Override + public List> hRandFieldWithValues(final String key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count).add(Keyword.Hash.WITHVALUES); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter, KeyValue> listConverter = + KeyValueConverter.listConverter(SafeEncoder::encode, SafeEncoder::encode); + + return hRandFieldWithValues(bKey, count, listConverter, args); + } + + @Override + public List> hRandFieldWithValues(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count).add(Keyword.Hash.WITHVALUES); + final ListConverter, KeyValue> listConverter = + KeyValueConverter.listConverter((k)->k, (v)->v); + + return hRandFieldWithValues(key, count, listConverter, args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create(key).add(cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create(key).add(cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, mapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor, + final HScanArgument scanArgument) { + final CommandArguments args = CommandArguments.create(key).add(cursor).add(scanArgument); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = LettuceScanArgs.from(scanArgument); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, scanArgs, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, + final HScanArgument scanArgument) { + final CommandArguments args = CommandArguments.create(key).add(cursor).add(scanArgument); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = LettuceScanArgs.from(scanArgument); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, scanArgs, mapScanCursorConverter, args); + } + + @Override + public Long hSet(final byte[] key, final KeyValue... data) { + final CommandArguments args = CommandArguments.create(key).add(data); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HSET, (cmd)->cmd.hset(key, field, value), converter) + .run(args); + } + } + + @Override + public Status hSetNx(final byte[] key, final byte[] field, final byte[] value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Long hStrLen(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HSETNX, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HSETNX, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HSETNX, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } + } + + @Override + public List hTtl(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HPTTL, (cmd)->cmd.httl(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HPTTL, (cmd)->cmd.httl(key, fields), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HSETNX, Command.HPTTL, (cmd)->cmd.httl(key, fields), (v)->v) + .run(args); + } + } + + @Override + public List hVals(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return hVals(bKey, listConverter, args); + } + + @Override + public List hVals(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return hVals(key, (v)->v, args); + } + + private V hGet(final byte[] key, final byte[] field, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HGET, (cmd)->cmd.hget(key, field), converter) + .run(args); + } + } + + private Map hGetAll(final byte[] key, final Converter, Map> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetall(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetall(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HGETALL, (cmd)->cmd.hgetall(key), converter) + .run(args); + } + } + + private Set hKeys(final byte[] key, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HKEYS, (cmd)->cmd.hkeys(key), converter) + .run(args); + } + } + + private List hMGet(final byte[] key, final byte[][] fields, + final Converter>, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HMGET, (cmd)->cmd.hmget(key, fields), converter) + .run(args); + } + } + + private V hRandField(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key), converter) + .run(args); + } + } + + private List hRandField(final byte[] key, final int count, final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), converter) + .run(args); + } + } + + private List> hRandFieldWithValues(final byte[] key, final int count, + final ListConverter, + KeyValue> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HRANDFIELD, + (cmd)->cmd.hrandfieldWithvalues(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HRANDFIELD, + (cmd)->cmd.hrandfieldWithvalues(key, count), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HRANDFIELD, + (cmd)->cmd.hrandfieldWithvalues(key, count), converter) + .run(args); + } + } + + private ScanResult> hScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor), converter) + .run(args); + } + } + + private ScanResult> hScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanArgs), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HSCAN, (cmd)->cmd.hscan(key, cursor, scanArgs), converter) + .run(args); + } + } + + private List hVals(final byte[] key, final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.HVALS, (cmd)->cmd.hvals(key), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceHyperLogLogOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceHyperLogLogOperations.java new file mode 100644 index 000000000..6613f61ae --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceHyperLogLogOperations.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; + +/** + * Lettuce 单机模式 HyperLogLog 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceHyperLogLogOperations extends AbstractHyperLogLogOperations { + + public LettuceHyperLogLogOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Status pfAdd(final byte[] key, final byte[]... elements) { + final CommandArguments args = CommandArguments.create(key).add(elements); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.PFADD, (cmd)->cmd.pfadd(key, elements), oneStatusConverter) + .run(args); + } + } + + @Override + public Long pfCount(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } + } + + @Override + public Status pfMerge(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(destKey).add(keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), okStatusConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceKeyOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceKeyOperations.java new file mode 100644 index 000000000..852d73e25 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceKeyOperations.java @@ -0,0 +1,1028 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.ListSetConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.ObjectEncoding; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Type; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.MigrateArgument; +import com.buession.redis.core.command.args.RestoreArgument; +import com.buession.redis.core.command.args.SortArgument; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.convert.response.ObjectEncodingConverter; +import com.buession.redis.core.internal.convert.response.TypeConverter; +import com.buession.redis.core.internal.lettuce.LettuceCopyArgs; +import com.buession.redis.core.internal.lettuce.LettuceExpireArgs; +import com.buession.redis.core.internal.lettuce.LettuceMigrateArgs; +import com.buession.redis.core.internal.lettuce.LettuceRestoreArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.core.internal.lettuce.LettuceSortArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.CopyArgs; +import io.lettuce.core.ExpireArgs; +import io.lettuce.core.KeyScanCursor; +import io.lettuce.core.MigrateArgs; +import io.lettuce.core.RestoreArgs; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.SortArgs; + +import java.util.List; +import java.util.Set; + +/** + * Lettuce 单机模式 Key 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceKeyOperations extends AbstractKeyOperations { + + public LettuceKeyOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey), booleanStatusConverter) + .run(args); + } + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + final CopyArgs copyArgs = new LettuceCopyArgs(db); + + return copy(key, destKey, copyArgs, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + final CopyArgs copyArgs = new LettuceCopyArgs(replace); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, copyArgs, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + final CopyArgs copyArgs = new LettuceCopyArgs(db, replace); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return copy(key, destKey, copyArgs, args); + } + + @Override + public Long del(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } + } + + @Override + public byte[] dump(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + } + } + + @Override + public Boolean exists(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v == 1L) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v == 1L) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(key), (v)->v == 1L) + .run(args); + } + } + + @Override + public Long exists(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime, expireArgs), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime, expireArgs), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EXPIRE, (cmd)->cmd.expire(key, lifetime, expireArgs), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireat(key, unixTimestamp), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireat(key, unixTimestamp), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireat(key, unixTimestamp), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireat(key, unixTimestamp, expireArgs), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EXPIREAT, + (cmd)->cmd.expireat(key, unixTimestamp, expireArgs), booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EXPIREAT, (cmd)->cmd.expireat(key, unixTimestamp, expireArgs), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Long expireTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expiretime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expiretime(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EXPIRETIME, (cmd)->cmd.expiretime(key), (v)->v) + .run(args); + } + } + + @Override + public Set keys(final String pattern) { + final CommandArguments args = CommandArguments.create(pattern); + final byte[] bPattern = SafeEncoder.encode(pattern); + final ListSetConverter binaryToStringListSetConverter = + Converters.listSetBinaryToString(); + + return keys(bPattern, binaryToStringListSetConverter, args); + } + + @Override + public Set keys(final byte[] pattern) { + final CommandArguments args = CommandArguments.create(pattern); + final ListSetConverter converter = new ListSetConverter<>((v)->v); + + return keys(pattern, converter, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... + keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(keys); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgument migrateArgument, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(migrateArgument) + .add(keys); + final MigrateArgs migrateArgs = LettuceMigrateArgs.from(migrateArgument).keys(keys); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status move(final byte[] key, final int db) { + final CommandArguments args = CommandArguments.create(key).add(db); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.MOVE, (cmd)->cmd.move(key, db), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.MOVE, (cmd)->cmd.move(key, db), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.MOVE, (cmd)->cmd.move(key, db), + booleanStatusConverter) + .run(args); + } + } + + @Override + public ObjectEncoding objectEncoding(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final ObjectEncodingConverter objectEncodingConverter = new ObjectEncodingConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + } + } + + @Override + public Long objectFreq(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + } + } + + @Override + public Long objectIdleTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectRefcount(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + } + } + + @Override + public Status persist(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.PERSIST, (cmd)->cmd.persist(key), booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime, expireArgs), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime, expireArgs), booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime, expireArgs), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.EXPIREAT, (cmd)->cmd.pexpireat(key, unixTimestamp), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EXPIREAT, (cmd)->cmd.pexpireat(key, unixTimestamp), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EXPIREAT, (cmd)->cmd.pexpireat(key, unixTimestamp), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + final ExpireArgs expireArgs = new LettuceExpireArgs(expireOption); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireat(key, unixTimestamp, expireArgs), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PEXPIREAT, + (cmd)->cmd.pexpireat(key, unixTimestamp, expireArgs), booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.PEXPIREAT, (cmd)->cmd.pexpireat(key, unixTimestamp, expireArgs), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Long pExpireTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PEXPIRETIME, (cmd)->cmd.pexpiretime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EXPIREAT, (cmd)->cmd.pexpiretime(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EXPIREAT, (cmd)->cmd.pexpiretime(key), (v)->v) + .run(args); + } + } + + @Override + public Long pTtl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } + } + + @Override + public String randomKey() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.RANDOMKEY, (cmd)->cmd.randomkey(), + SafeEncoder::encode) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.RANDOMKEY, (cmd)->cmd.randomkey(), + SafeEncoder::encode) + .run(); + }else{ + return new LettuceCommand<>(client, Command.RANDOMKEY, (cmd)->cmd.randomkey(), SafeEncoder::encode) + .run(); + } + } + + @Override + public Status rename(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.RENAME, (cmd)->cmd.rename(key, newKey), okStatusConverter) + .run(args); + } + } + + @Override + public Status renameNx(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.RESTORE, (cmd)->cmd.restore(key, ttl, serializedValue), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.RESTORE, (cmd)->cmd.restore(key, ttl, serializedValue), + okStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl, + final RestoreArgument restoreArgument) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl).add(restoreArgument); + final RestoreArgs restoreArgs = LettuceRestoreArgs.from(restoreArgument).ttl(ttl); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, serializedValue, restoreArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.RESTORE, + (cmd)->cmd.restore(key, serializedValue, restoreArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.RESTORE, (cmd)->cmd.restore(key, serializedValue, restoreArgs), + okStatusConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final String cursor) { + final CommandArguments args = CommandArguments.create(cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor) { + final CommandArguments args = CommandArguments.create(cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, keyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, scanArgs, keyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final String cursor, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, scanArgs, keyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern).add(count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern).add(count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, scanArgs, keyScanCursorConverter, args); + } + + @Override + public List sort(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return sort(bKey, listConverter, args); + } + + @Override + public List sort(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return sort(key, (v)->v, args); + } + + @Override + public List sort(final String key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final byte[] bKey = SafeEncoder.encode(key); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + final ListConverter listConverter = Converters.listBinaryToString(); + + return sort(bKey, sortArgs, listConverter, args); + } + + @Override + public List sort(final byte[] key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + + return sort(key, sortArgs, (v)->v, args); + } + + @Override + public Long sort(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + final SortArgs sortArgs = new LettuceSortArgs(); + + return sortStore(key, destKey, sortArgs, args); + } + + @Override + public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(sortArgument); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + + return sortStore(key, destKey, sortArgs, args); + } + + @Override + public List sortRo(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return sortRo(bKey, listConverter, args); + } + + @Override + public List sortRo(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return sortRo(key, (v)->v, args); + } + + @Override + public List sortRo(final String key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final byte[] bKey = SafeEncoder.encode(key); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + final ListConverter listConverter = Converters.listBinaryToString(); + + return sortRo(bKey, sortArgs, listConverter, args); + } + + @Override + public List sortRo(final byte[] key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + + return sortRo(key, sortArgs, (v)->v, args); + } + + @Override + public Long touch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } + } + + @Override + public Long ttl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } + } + + @Override + public Type type(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } + } + + @Override + public Long unlink(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } + } + + private Status copy(final byte[] key, final byte[] destKey, final CopyArgs copyArgs, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, copyArgs), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.COPY, + (cmd)->cmd.copy(key, destKey, copyArgs), booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.COPY, (cmd)->cmd.copy(key, destKey, copyArgs), + booleanStatusConverter) + .run(args); + } + } + + private Set keys(final byte[] pattern, final ListSetConverter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.KEYS, (cmd)->cmd.keys(pattern), converter) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgs migrateArgs, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateArgs), okStatusConverter) + .run(args); + } + } + + private ScanResult> scan(final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor), converter) + .run(args); + } + } + + private ScanResult> scan(final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanArgs), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SCAN, (cmd)->cmd.scan(cursor, scanArgs), + converter) + .run(args); + } + } + + private List sort(final byte[] key, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SORT, (cmd)->cmd.sort(key), converter) + .run(args); + } + } + + private List sort(final byte[] key, final SortArgs sortArgs, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortArgs), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SORT, (cmd)->cmd.sort(key, sortArgs), + converter) + .run(args); + } + } + + private Long sortStore(final byte[] key, final byte[] destKey, final SortArgs sortArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SORT, (cmd)->cmd.sortStore(key, sortArgs, destKey), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SORT, (cmd)->cmd.sortStore(key, sortArgs, destKey), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SORT, (cmd)->cmd.sortStore(key, sortArgs, destKey), + (v)->v) + .run(args); + } + } + + private List sortRo(final byte[] key, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadOnly(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadOnly(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadOnly(key), converter) + .run(args); + } + } + + private List sortRo(final byte[] key, final SortArgs sortArgs, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadOnly(key, sortArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadOnly(key, sortArgs), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SORT_RO, (cmd)->cmd.sortReadOnly(key, sortArgs), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceListOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceListOperations.java new file mode 100644 index 000000000..0d6340362 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceListOperations.java @@ -0,0 +1,614 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.builder.ListBuilder; +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.Direction; +import com.buession.redis.core.ListPosition; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.LPosArgument; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.lettuce.LettuceLPosArgs; +import com.buession.redis.core.internal.lettuce.utils.LMoveArgsUtils; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyValue; +import io.lettuce.core.LMoveArgs; +import io.lettuce.core.LPosArgs; + +import java.util.List; + +/** + * Lettuce 单机模式列表命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceListOperations extends AbstractListOperations { + + public LettuceListOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public String lIndex(final String key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + final byte[] bKey = SafeEncoder.encode(key); + + return lIndex(bKey, index, SafeEncoder::encode, args); + } + + @Override + public byte[] lIndex(final byte[] key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + return lIndex(key, index, (v)->v, args); + } + + @Override + public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) + .put("value", value); + final boolean before = ListPosition.BEFORE == position; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, before, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LINSERT, + (cmd)->cmd.linsert(key, before, pivot, value), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.LINSERT, (cmd)->cmd.linsert(key, before, pivot, value), + (v)->v) + .run(args); + } + } + + @Override + public Status lSet(final byte[] key, final long index, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LSET, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LSET, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.LSET, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Long lLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } + } + + @Override + public List lRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return lRange(bKey, start, end, listConverter, args); + } + + @Override + public List lRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return lRange(key, start, end, (v)->v, args); + } + + @Override + public Long lPos(final byte[] key, final byte[] element) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); + final LPosArgs lPosArgs = LettuceLPosArgs.from(lPosArgument); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosArgs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, lPosArgs), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.LPOS, (cmd)->cmd.lpos(key, element, lPosArgs), (v)->v) + .run(args); + } + } + + @Override + public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) + .put("count", count); + final LPosArgs lPosArgs = LettuceLPosArgs.from(lPosArgument); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, (int) count, lPosArgs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, (int) count, lPosArgs), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.LPOS, + (cmd)->cmd.lpos(key, element, (int) count, lPosArgs), (v)->v) + .run(args); + } + } + + @Override + public Long lRem(final byte[] key, final byte[] value, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } + } + + @Override + public Status lTrim(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } + } + + @Override + public String lMove(final String key, final String destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + final LMoveArgs lMoveArgs = LMoveArgsUtils.fromDirection(from, to); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(bKey, bDestKey, lMoveArgs), SafeEncoder::encode) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(bKey, bDestKey, lMoveArgs), SafeEncoder::encode) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.LMOVE, (cmd)->cmd.lmove(bKey, bDestKey, lMoveArgs), + SafeEncoder::encode) + .run(args); + } + } + + @Override + public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + final LMoveArgs lMoveArgs = LMoveArgsUtils.fromDirection(from, to); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, lMoveArgs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LMOVE, + (cmd)->cmd.lmove(key, destKey, lMoveArgs), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.LMOVE, (cmd)->cmd.lmove(key, destKey, lMoveArgs), + (v)->v) + .run(args); + } + } + + @Override + public String blMove(final String key, final String destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + final LMoveArgs lMoveArgs = LMoveArgsUtils.fromDirection(from, to); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(bKey, bDestKey, lMoveArgs, timeout), SafeEncoder::encode) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(bKey, bDestKey, lMoveArgs, timeout), SafeEncoder::encode) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(bKey, bDestKey, lMoveArgs, timeout), SafeEncoder::encode) + .run(args); + } + } + + @Override + public byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to).put("timeout", timeout); + final LMoveArgs lMoveArgs = LMoveArgsUtils.fromDirection(from, to); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, key, lMoveArgs, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, key, lMoveArgs, timeout), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BLMOVE, + (cmd)->cmd.blmove(key, key, lMoveArgs, timeout), (v)->v) + .run(args); + } + } + + @Override + public List blPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final Converter, List> converter = + (v)->ListBuilder.of(SafeEncoder.encode(v.getValue())); + + return blPop(bKeys, timeout, converter, args); + } + + @Override + public List blPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final Converter, List> converter = (v)->ListBuilder.of(v.getValue()); + + return blPop(keys, timeout, converter, args); + } + + @Override + public List brPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final Converter, List> converter = + (v)->ListBuilder.of(SafeEncoder.encode(v.getValue())); + + return brPop(bKeys, timeout, converter, args); + } + + @Override + public List brPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final Converter, List> converter = (v)->ListBuilder.of(v.getValue()); + + return brPop(keys, timeout, converter, args); + } + + @Override + public String brPoplPush(final String key, final String destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + + return brPoplPush(bKey, bDestKey, timeout, SafeEncoder::encode, args); + } + + @Override + public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + return brPoplPush(key, destKey, timeout, (v)->v, args); + } + + @Override + public String lPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return lPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] lPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return lPop(key, (v)->v, args); + } + + @Override + public Long lPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long lPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } + } + + @Override + public String rPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return rPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] rPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return rPop(key, (v)->v, args); + } + + @Override + public String rPoplPush(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + + return rPoplPush(bKey, bDestKey, SafeEncoder::encode, args); + } + + @Override + public byte[] rPoplPush(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + return rPoplPush(key, destKey, (v)->v, args); + } + + @Override + public Long rPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long rPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } + } + + private V lIndex(final byte[] key, final long index, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.LINDEX, (cmd)->cmd.lindex(key, index), converter) + .run(args); + } + } + + private List lRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.LRANGE, (cmd)->cmd.lrange(key, start, end), + converter) + .run(args); + } + } + + private List blPop(final byte[][] keys, final int timeout, final Converter, + List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BLPOP, (cmd)->cmd.blpop(timeout, keys), converter) + .run(args); + } + } + + private List brPop(final byte[][] keys, final int timeout, final Converter, + List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BRPOP, (cmd)->cmd.brpop(timeout, keys), converter) + .run(args); + } + } + + private V brPoplPush(final byte[] key, final byte[] destKey, final int timeout, + final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(timeout, key, destKey), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(timeout, key, destKey), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(timeout, key, destKey), converter) + .run(args); + } + } + + private V lPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.LPOP, (cmd)->cmd.lpop(key), converter) + .run(args); + } + } + + private V rPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.RPOP, (cmd)->cmd.rpop(key), converter) + .run(args); + } + } + + private V rPoplPush(final byte[] key, final byte[] destKey, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettucePubSubOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettucePubSubOperations.java new file mode 100644 index 000000000..16a4eb5e3 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettucePubSubOperations.java @@ -0,0 +1,354 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapConverter; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.PubSubListener; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 单机模式 Pub/Sub 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettucePubSubOperations extends AbstractPubSubOperations { + + public LettucePubSubOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + notCommand(client, Command.PSUBSCRIBE, args); + } + + @Override + public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + notCommand(client, Command.PSUBSCRIBE, args); + } + + @Override + public Long publish(final byte[] channel, final byte[] message) { + final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PUBLISH, + (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.PUBLISH, (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + } + } + + @Override + public List pubsubChannels() { + final ListConverter listConverter = Converters.listBinaryToString(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(), + listConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(), + listConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(), + listConverter) + .run(); + } + } + + @Override + public List pubsubChannels(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final byte[] bPattern = SafeEncoder.encode(pattern); + final ListConverter listConverter = Converters.listBinaryToString(); + + return pubsubChannels(bPattern, listConverter, args); + } + + @Override + public List pubsubChannels(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return pubsubChannels(pattern, (v)->v, args); + } + + @Override + public List pubsubShardChannels() { + final ListConverter listConverter = Converters.listBinaryToString(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PUBSUB_SHARDCHANNELS, + (cmd)->cmd.pubsubChannels(), listConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PUBSUB_SHARDCHANNELS, + (cmd)->cmd.pubsubChannels(), listConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.PUBSUB_SHARDCHANNELS, (cmd)->cmd.pubsubChannels(), + listConverter) + .run(); + } + } + + @Override + public List pubsubShardChannels(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final byte[] bPattern = SafeEncoder.encode(pattern); + final ListConverter listConverter = Converters.listBinaryToString(); + + return pubsubShardChannels(bPattern, listConverter, args); + } + + @Override + public List pubsubShardChannels(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return pubsubShardChannels(pattern, (v)->v, args); + } + + @Override + public Long pubsubNumPat() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PUBSUB_NUMPAT, (cmd)->cmd.pubsubNumpat(), + (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PUBSUB_NUMPAT, (cmd)->cmd.pubsubNumpat(), + (v)->v) + .run(); + }else{ + return new LettuceCommand<>(client, Command.PUBSUB_NUMPAT, (cmd)->cmd.pubsubNumpat(), (v)->v) + .run(); + } + } + + @Override + public Map pubsubNumSub() { + final MapConverter converter = new MapConverter<>(SafeEncoder::encode, (v)->v); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PUBSUB_NUMSUB, + (cmd)->cmd.pubsubNumsub(), converter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PUBSUB_NUMSUB, + (cmd)->cmd.pubsubNumsub(), converter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.PUBSUB_NUMSUB, (cmd)->cmd.pubsubNumsub(), + converter) + .run(); + } + } + + @Override + public Map pubsubNumSub(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + final byte[][] bChannels = SafeEncoder.encode(channels); + final MapConverter converter = new MapConverter<>(SafeEncoder::encode, (v)->v); + + return pubsubNumSub(bChannels, converter, args); + } + + @Override + public Map pubsubNumSub(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return pubsubNumSub(channels, (v)->v, args); + } + + @Override + public Map pubsubShardNumSub() { + final MapConverter converter = new MapConverter<>(SafeEncoder::encode, (v)->v); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PUBSUB_SHARDNUMSUB, + (cmd)->cmd.pubsubShardNumsub(), converter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PUBSUB_SHARDNUMSUB, + (cmd)->cmd.pubsubShardNumsub(), converter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.PUBSUB_SHARDNUMSUB, + (cmd)->cmd.pubsubShardNumsub(), converter) + .run(); + } + } + + @Override + public Map pubsubShardNumSub(final String... shardChannels) { + final CommandArguments args = CommandArguments.create("shardChannels", (Object[]) shardChannels); + final byte[][] bShardChannels = SafeEncoder.encode(shardChannels); + final MapConverter converter = new MapConverter<>(SafeEncoder::encode, (v)->v); + + return pubsubShardNumSub(bShardChannels, converter, args); + } + + @Override + public Map pubsubShardNumSub(final byte[]... shardChannels) { + final CommandArguments args = CommandArguments.create("shardChannels", (Object[]) shardChannels); + return pubsubShardNumSub(shardChannels, (v)->v, args); + } + + @Override + public Object pUnSubscribe() { + return notCommand(client, Command.PUNSUBSCRIBE); + } + + @Override + public Object pUnSubscribe(final String... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return notCommand(client, Command.PUNSUBSCRIBE, args); + } + + @Override + public Object pUnSubscribe(final byte[]... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return notCommand(client, Command.PUNSUBSCRIBE, args); + } + + @Override + public void subscribe(final String[] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + notCommand(client, Command.SUBSCRIBE, args); + } + + @Override + public void subscribe(final byte[][] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + notCommand(client, Command.SUBSCRIBE, args); + } + + @Override + public Object unSubscribe() { + return notCommand(client, Command.UNSUBSCRIBE); + } + + @Override + public Object unSubscribe(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return notCommand(client, Command.UNSUBSCRIBE, args); + } + + @Override + public Object unSubscribe(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return notCommand(client, Command.UNSUBSCRIBE, args); + } + + private List pubsubChannels(final byte[] pattern, final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(pattern), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(pattern), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(pattern), + converter) + .run(args); + } + } + + private List pubsubShardChannels(final byte[] pattern, final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PUBSUB_SHARDCHANNELS, + (cmd)->cmd.pubsubShardChannels(pattern), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PUBSUB_SHARDCHANNELS, + (cmd)->cmd.pubsubShardChannels(pattern), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.PUBSUB_SHARDCHANNELS, + (cmd)->cmd.pubsubShardChannels(pattern), converter) + .run(args); + } + } + + private Map pubsubNumSub(final byte[][] channels, + final Converter, Map> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PUBSUB_NUMSUB, + (cmd)->cmd.pubsubNumsub(channels), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PUBSUB_NUMSUB, + (cmd)->cmd.pubsubNumsub(channels), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.PUBSUB_NUMSUB, (cmd)->cmd.pubsubNumsub(channels), + converter) + .run(args); + } + } + + private Map pubsubShardNumSub(final byte[][] channels, + final Converter, Map> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PUBSUB_SHARDNUMSUB, + (cmd)->cmd.pubsubShardNumsub(channels), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PUBSUB_SHARDNUMSUB, + (cmd)->cmd.pubsubShardNumsub(channels), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.PUBSUB_SHARDNUMSUB, + (cmd)->cmd.pubsubShardNumsub(channels), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceRedisOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceRedisOperations.java new file mode 100644 index 000000000..58d414953 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceRedisOperations.java @@ -0,0 +1,983 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.redis.client.connection.lettuce.LettuceClusterConnection; +import com.buession.redis.client.connection.lettuce.LettuceConnection; +import com.buession.redis.client.connection.lettuce.LettuceSentinelConnection; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.client.operations.RedisOperations; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.internal.lettuce.LettuceResult; +import com.buession.redis.exception.RedisException; +import com.buession.redis.exception.RedisPipelineException; +import com.buession.redis.exception.RedisTransactionException; +import com.buession.redis.pipeline.PipelineProxy; +import com.buession.redis.transaction.TransactionProxy; +import io.lettuce.core.FlushEachCommand; +import io.lettuce.core.RedisFuture; +import io.lettuce.core.api.async.RedisAsyncCommands; +import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands; +import io.lettuce.core.cluster.api.sync.RedisClusterCommands; +import io.lettuce.core.sentinel.api.async.RedisSentinelAsyncCommands; +import io.lettuce.core.sentinel.api.sync.RedisSentinelCommands; + +/** + * Lettuce Redis 命令操作接口 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface LettuceRedisOperations extends RedisOperations { + + /** + * Lettuce 单机模式常规命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class LettuceCommand extends + AbstractStandaloneCommand, SR, SR, R> { + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link LettuceStandaloneClient} 实例 + * @param command + * Redis 命令 + */ + public LettuceCommand(final LettuceStandaloneClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link LettuceStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceCommand(final LettuceStandaloneClient client, final Command command, + final Executor, SR> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link LettuceStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public LettuceCommand(final LettuceStandaloneClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link LettuceStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceCommand(final LettuceStandaloneClient client, final Command command, final SubCommand subCommand, + final Executor, SR> executor, + final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @Override + protected R doExecute() throws RedisException { + final SR result = executor.execute(connection.getStatefulConnection().sync()); + return result == null ? null : converter.convert(result); + } + + } + + /** + * Lettuce 单机模式管道模式命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class LettucePipelineCommand extends + AbstractStandaloneCommand, RedisFuture, SR, R> { + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link LettuceStandaloneClient} 实例 + * @param command + * Redis 命令 + */ + public LettucePipelineCommand(final LettuceStandaloneClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link LettuceStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettucePipelineCommand(final LettuceStandaloneClient client, final Command command, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link LettuceStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public LettucePipelineCommand(final LettuceStandaloneClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link LettuceStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettucePipelineCommand(final LettuceStandaloneClient client, final Command command, + final SubCommand subCommand, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.pipeline.Pipeline pipeline = pipeline(); + + if(pipeline instanceof PipelineProxy){ + final PipelineProxy> pipelineFactory = + (PipelineProxy>) pipeline; + + final Runner runner = new PipelineRunner<>((context)->{ + context.onCommand(connection.getStatefulConnection()); + return executor.execute(connection.getStatefulConnection().async()); + }, pipelineFactory, converter); + + pipelineFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisPipelineException("ERR EXEC without pipeline. Did you forget to call openPipeline?"); + } + } + + } + + /** + * Lettuce 单机模式事务模式命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class LettuceTransactionCommand extends + AbstractStandaloneCommand, + RedisFuture, SR, R> { + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link LettuceStandaloneClient} 实例 + * @param command + * Redis 命令 + */ + public LettuceTransactionCommand(final LettuceStandaloneClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link LettuceStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceTransactionCommand(final LettuceStandaloneClient client, final Command command, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link LettuceStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public LettuceTransactionCommand(final LettuceStandaloneClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link LettuceStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceTransactionCommand(final LettuceStandaloneClient client, final Command command, + final SubCommand subCommand, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.transaction.Transaction transaction = transaction(); + + if(transaction instanceof TransactionProxy){ + final TransactionProxy, LettuceResult> transactionFactory = + (TransactionProxy, LettuceResult>) transaction; + + final Runner runner = new TransactionRunner<>( + (context)->executor.execute(connection.getStatefulConnection().async()), transactionFactory, + converter); + + transactionFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisTransactionException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + } + + /** + * Lettuce 哨兵模式常规命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class LettuceSentinelCommand extends + AbstractSentinelCommand, SR, SR, R> { + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link LettuceSentinelClient} 实例 + * @param command + * Redis 命令 + */ + public LettuceSentinelCommand(final LettuceSentinelClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link LettuceSentinelClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceSentinelCommand(final LettuceSentinelClient client, final Command command, + final Executor, SR> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link LettuceSentinelClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public LettuceSentinelCommand(final LettuceSentinelClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link LettuceSentinelClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceSentinelCommand(final LettuceSentinelClient client, final Command command, + final SubCommand subCommand, + final Executor, SR> executor, + final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @Override + protected R doExecute() throws RedisException { + final SR result = executor.execute(connection.getStatefulRedisSentinelConnection().sync()); + return result == null ? null : converter.convert(result); + } + + } + + /** + * Lettuce 哨兵模式管道模式命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class LettuceSentinelPipelineCommand extends + AbstractSentinelCommand, RedisFuture, SR, R> { + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link LettuceSentinelClient} 实例 + * @param command + * Redis 命令 + */ + public LettuceSentinelPipelineCommand(final LettuceSentinelClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link LettuceSentinelClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceSentinelPipelineCommand(final LettuceSentinelClient client, final Command command, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link LettuceSentinelClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public LettuceSentinelPipelineCommand(final LettuceSentinelClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link LettuceSentinelClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceSentinelPipelineCommand(final LettuceSentinelClient client, final Command command, + final SubCommand subCommand, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.pipeline.Pipeline pipeline = pipeline(); + + if(pipeline instanceof PipelineProxy){ + final PipelineProxy> pipelineFactory = + (PipelineProxy>) pipeline; + + final Runner runner = new PipelineRunner<>((context)->{ + context.onCommand(connection.getStatefulRedisSentinelConnection()); + return executor.execute(connection.getStatefulRedisSentinelConnection().async()); + }, pipelineFactory, converter); + + pipelineFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisPipelineException("ERR EXEC without pipeline. Did you forget to call openPipeline?"); + } + } + + } + + /** + * Lettuce 哨兵模式事务模式命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class LettuceSentinelTransactionCommand extends + AbstractSentinelCommand, + RedisFuture, SR, R> { + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link LettuceSentinelClient} 实例 + * @param command + * Redis 命令 + */ + public LettuceSentinelTransactionCommand(final LettuceSentinelClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link LettuceSentinelClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceSentinelTransactionCommand(final LettuceSentinelClient client, final Command command, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link LettuceSentinelClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public LettuceSentinelTransactionCommand(final LettuceSentinelClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link LettuceSentinelClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceSentinelTransactionCommand(final LettuceSentinelClient client, final Command command, + final SubCommand subCommand, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.transaction.Transaction transaction = transaction(); + + if(transaction instanceof TransactionProxy){ + final TransactionProxy, LettuceResult> transactionFactory = + (TransactionProxy, LettuceResult>) transaction; + + final Runner runner = new TransactionRunner<>( + (context)->executor.execute(connection.getStatefulRedisSentinelConnection().async()), + transactionFactory, converter); + + transactionFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisTransactionException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + } + + /** + * Lettuce 集群模式常规命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class LettuceClusterCommand extends + AbstractClusterCommand, SR, SR, R> { + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link LettuceClusterClient} 实例 + * @param command + * Redis 命令 + */ + public LettuceClusterCommand(final LettuceClusterClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link LettuceClusterClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceClusterCommand(final LettuceClusterClient client, final Command command, + final Executor, SR> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link LettuceClusterClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public LettuceClusterCommand(final LettuceClusterClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link LettuceClusterClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceClusterCommand(final LettuceClusterClient client, final Command command, + final SubCommand subCommand, + final Executor, SR> executor, + final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @Override + protected R doExecute() throws RedisException { + final SR result = executor.execute(connection.getStatefulRedisClusterConnection().sync()); + return result == null ? null : converter.convert(result); + } + + } + + /** + * Lettuce 集群模式管道模式命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class LettuceClusterPipelineCommand extends + AbstractClusterCommand, RedisFuture, SR, R> { + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link LettuceClusterClient} 实例 + * @param command + * Redis 命令 + */ + public LettuceClusterPipelineCommand(final LettuceClusterClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link LettuceClusterClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceClusterPipelineCommand(final LettuceClusterClient client, final Command command, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link LettuceClusterClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public LettuceClusterPipelineCommand(final LettuceClusterClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link LettuceClusterClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceClusterPipelineCommand(final LettuceClusterClient client, final Command command, + final SubCommand subCommand, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.pipeline.Pipeline pipeline = pipeline(); + + if(pipeline instanceof PipelineProxy){ + final PipelineProxy> pipelineFactory = + (PipelineProxy>) pipeline; + + final Runner runner = new PipelineRunner<>((context)->{ + context.onCommand(connection.getStatefulRedisClusterConnection()); + return executor.execute(connection.getStatefulRedisClusterConnection().async()); + }, pipelineFactory, converter); + + pipelineFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisPipelineException("ERR EXEC without pipeline. Did you forget to call openPipeline?"); + } + } + + } + + /** + * Lettuce 集群模式集群模式命令 + * + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + class LettuceClusterTransactionCommand extends + AbstractClusterCommand, + RedisFuture, SR, R> { + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link LettuceClusterClient} 实例 + * @param command + * Redis 命令 + */ + public LettuceClusterTransactionCommand(final LettuceClusterClient client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link LettuceClusterClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceClusterTransactionCommand(final LettuceClusterClient client, final Command command, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link LettuceClusterClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public LettuceClusterTransactionCommand(final LettuceClusterClient client, final Command command, + final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link LettuceClusterClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public LettuceClusterTransactionCommand(final LettuceClusterClient client, final Command command, + final SubCommand subCommand, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.transaction.Transaction transaction = transaction(); + + if(transaction instanceof TransactionProxy){ + final TransactionProxy, LettuceResult> transactionFactory = + (TransactionProxy, LettuceResult>) transaction; + + final Runner runner = new TransactionRunner<>( + (context)->executor.execute(connection.getStatefulRedisClusterConnection().async()), + transactionFactory, converter); + + transactionFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisTransactionException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + } + + abstract class PtRunner implements com.buession.redis.core.Command.Runner { + + protected final com.buession.redis.core.Command.Executor> executor; + + protected final Converter converter; + + public PtRunner(final com.buession.redis.core.Command.Executor> executor, + final Converter converter) { + this.executor = executor; + this.converter = converter; + } + + protected LettuceResult newLettuceResult(final RedisFuture future) { + return LettuceResult.Builder.fromRedisFuture(future).build(); + } + + protected LettuceResult newLettuceResult(final RedisFuture future, + final Converter converter) { + return LettuceResult.Builder.fromRedisFuture(future).mappedWith(converter).build(); + } + + } + + final class PipelineRunner extends PtRunner { + + private final PipelineProxy> pipelineFactory; + + public PipelineRunner(final com.buession.redis.core.Command.Executor> executor, + final PipelineProxy> pipelineFactory, + final Converter converter) { + super(executor, converter); + this.pipelineFactory = pipelineFactory; + } + + @SuppressWarnings({"unchecked"}) + @Override + public LettuceResult run() throws RedisException { + final RedisFuture future = executor.execute(pipelineFactory.getObject()); + return converter == null ? newLettuceResult(future) : newLettuceResult(future, converter); + } + + } + + final class TransactionRunner extends PtRunner { + + private final TransactionProxy> transactionProxy; + + public TransactionRunner(final com.buession.redis.core.Command.Executor> executor, + final TransactionProxy> transactionProxy, + final Converter converter) { + super(executor, converter); + this.transactionProxy = transactionProxy; + } + + @SuppressWarnings({"unchecked"}) + @Override + public LettuceResult run() throws RedisException { + final RedisFuture future = executor.execute(transactionProxy.getObject()); + return converter == null ? newLettuceResult(future) : newLettuceResult(future, converter); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceScriptingOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceScriptingOperations.java new file mode 100644 index 000000000..a5a11506e --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceScriptingOperations.java @@ -0,0 +1,320 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.lettuce.params.FlushModeConverter; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ScriptOutputType; + +import java.util.List; + +/** + * Lettuce 单机模式 Script 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceScriptingOperations extends AbstractScriptingOperations { + + public LettuceScriptingOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Object eval(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + final byte[][] bKeys = new byte[][]{}; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final byte[] script) { + final CommandArguments args = CommandArguments.create("script", script); + final byte[][] keys = new byte[][]{}; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final String script, final String... params) { + final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + final byte[][] bKeys = new byte[][]{}; + final byte[][] bParams = SafeEncoder.encode(params); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys, bParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys, bParams), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys, bParams), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final byte[] script, final byte[]... params) { + final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + final byte[][] keys = new byte[][]{}; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys, params), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys, params), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final String script, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final byte[][] bKeys = SafeEncoder.encode(keys); + final byte[][] bArguments = SafeEncoder.encode(arguments); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys, bArguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys, bArguments), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, bKeys, bArguments), (v)->v) + .run(args); + } + } + + @Override + public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments) { + final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys, arguments), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EVAL, + (cmd)->cmd.eval(script, ScriptOutputType.OBJECT, keys, arguments), (v)->v) + .run(args); + } + } + + @Override + public Object evalSha(final String digest) { + final CommandArguments args = CommandArguments.create("digest", digest); + final byte[][] bKeys = new byte[][]{}; + + return evalSha(digest, bKeys, null, args); + } + + @Override + public Object evalSha(final String digest, final String... params) { + final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); + final byte[][] bKeys = new byte[][]{}; + final byte[][] bParams = SafeEncoder.encode(params); + + return evalSha(digest, bKeys, bParams, args); + } + + @Override + public Object evalSha(final String digest, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final byte[][] bKeys = SafeEncoder.encode(keys); + final byte[][] bArguments = SafeEncoder.encode(arguments); + + return evalSha(digest, bKeys, bArguments, args); + } + + @Override + public List scriptExists(final String... sha1) { + final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), (v)->v) + .run(args); + } + } + + @Override + public Status scriptFlush() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(); + } + } + + @Override + public Status scriptFlush(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + final io.lettuce.core.FlushMode flushMode = (new FlushModeConverter()).convert(mode); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(flushMode), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush(flushMode), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(flushMode), + okStatusConverter) + .run(args); + } + } + + @Override + public String scriptLoad(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + final byte[] bScript = SafeEncoder.encode(script); + + return scriptLoad(bScript, (v)->v, args); + } + + @Override + public byte[] scriptLoad(final byte[] script) { + final CommandArguments args = CommandArguments.create("script", script); + return scriptLoad(script, SafeEncoder::encode, args); + } + + @Override + public Status scriptKill() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + } + } + + private Object evalSha(final String digest, final byte[][] keys, final byte[][] arguments, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, ScriptOutputType.OBJECT, keys, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, ScriptOutputType.OBJECT, keys, arguments), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.EVALSHA, + (cmd)->cmd.evalsha(digest, ScriptOutputType.OBJECT, keys, arguments), (v)->v) + .run(args); + } + } + + private V scriptLoad(final byte[] script, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelAclOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelAclOperations.java new file mode 100644 index 000000000..5c17b8f32 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelAclOperations.java @@ -0,0 +1,175 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.AclCategory; +import com.buession.redis.core.AclLog; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.AclSetUserArgument; + +import java.util.List; + +/** + * Lettuce 哨兵模式权限命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelAclOperations extends AbstractAclOperations { + + public LettuceSentinelAclOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public List aclCat() { + return notCommand(client, Command.ACL, SubCommand.ACL_CAT); + } + + @Override + public List aclCat(final AclCategory aclCategory) { + final CommandArguments args = CommandArguments.create(aclCategory); + return notCommand(client, Command.ACL, SubCommand.ACL_CAT, args); + } + + @Override + public Long aclDelUser(final String... usernames) { + final CommandArguments args = CommandArguments.create(usernames); + return notCommand(client, Command.ACL, SubCommand.ACL_DELUSER, args); + } + + @Override + public Long aclDelUser(final byte[]... usernames) { + final CommandArguments args = CommandArguments.create(usernames); + return notCommand(client, Command.ACL, SubCommand.ACL_DELUSER, args); + } + + @Override + public Status aclDryRun(final String username, final Command command) { + final CommandArguments args = CommandArguments.create(username).add(command); + return notCommand(client, Command.ACL, SubCommand.ACL_DRYRUN, args); + } + + @Override + public Status aclDryRun(final byte[] username, final Command command) { + final CommandArguments args = CommandArguments.create(username).add(command); + return notCommand(client, Command.ACL, SubCommand.ACL_DRYRUN, args); + } + + @Override + public Status aclDryRun(final String username, final Command command, final String... arguments) { + final CommandArguments args = CommandArguments.create(username).add(command).add(arguments); + return notCommand(client, Command.ACL, SubCommand.ACL_DRYRUN, args); + } + + @Override + public Status aclDryRun(final byte[] username, final Command command, final byte[]... arguments) { + final CommandArguments args = CommandArguments.create(username).add(command).add(arguments); + return notCommand(client, Command.ACL, SubCommand.ACL_DRYRUN, args); + } + + @Override + public String aclGenPass() { + return notCommand(client, Command.ACL, SubCommand.ACL_GENPASS); + } + + @Override + public String aclGenPass(final int bits) { + final CommandArguments args = CommandArguments.create(bits); + return notCommand(client, Command.ACL, SubCommand.ACL_GENPASS, args); + } + + @Override + public AclUser aclGetUser(final String username) { + final CommandArguments args = CommandArguments.create(username); + return notCommand(client, Command.ACL, SubCommand.ACL_GETUSER, args); + } + + @Override + public AclUser aclGetUser(final byte[] username) { + final CommandArguments args = CommandArguments.create(username); + return notCommand(client, Command.ACL, SubCommand.ACL_GETUSER, args); + } + + @Override + public List aclList() { + return notCommand(client, Command.ACL, SubCommand.LIST); + } + + @Override + public Status aclLoad() { + return notCommand(client, Command.ACL, SubCommand.LOAD); + } + + @Override + public List aclLog() { + return notCommand(client, Command.ACL, SubCommand.ACL_LOG); + } + + @Override + public List aclLog(final int count) { + final CommandArguments args = CommandArguments.create(count); + return notCommand(client, Command.ACL, SubCommand.ACL_LOG, args); + } + + @Override + public Status aclLogReset() { + final CommandArguments args = CommandArguments.create(SubCommand.RESET); + return notCommand(client, Command.ACL, SubCommand.ACL_LOG, args); + } + + @Override + public Status aclSave() { + return notCommand(client, Command.ACL, SubCommand.SAVE); + } + + @Override + public Status aclSetUser(final String username, final AclSetUserArgument rules) { + final CommandArguments args = CommandArguments.create(username).add(rules); + return notCommand(client, Command.ACL, SubCommand.ACL_SETUSER, args); + } + + @Override + public Status aclSetUser(final byte[] username, final AclSetUserArgument rules) { + final CommandArguments args = CommandArguments.create(username).add(rules); + return notCommand(client, Command.ACL, SubCommand.ACL_SETUSER, args); + } + + @Override + public List aclUsers() { + return notCommand(client, Command.ACL, SubCommand.ACL_USERS); + } + + @Override + public String aclWhoAmI() { + return notCommand(client, Command.ACL, SubCommand.ACL_WHOAMI); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelBitMapOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelBitMapOperations.java new file mode 100644 index 000000000..3b8629b30 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelBitMapOperations.java @@ -0,0 +1,231 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.BitType; +import com.buession.redis.core.BitOperation; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.BitFieldArgument; +import com.buession.redis.core.command.args.BitFieldRoArgument; + +import java.util.List; + +/** + * Lettuce 哨兵模式 BitMap 命令操作抽象类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelBitMapOperations extends AbstractBitMapOperations { + + public LettuceSentinelBitMapOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Long bitCount(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.BITCOUNT, args); + } + + @Override + public Long bitCount(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.BITCOUNT, args); + } + + @Override + public Long bitCount(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end); + return notCommand(client, Command.BITCOUNT, args); + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end); + return notCommand(client, Command.BITCOUNT, args); + } + + @Override + public Long bitCount(final String key, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end).add(bitType); + return notCommand(client, Command.BITCOUNT, args); + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(start).add(end).add(bitType); + return notCommand(client, Command.BITCOUNT, args); + } + + @Override + public List bitField(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.BITFIELD, args); + } + + @Override + public List bitField(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.BITFIELD, args); + } + + @Override + public List bitField(final String key, final BitFieldArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + return notCommand(client, Command.BITFIELD, args); + } + + @Override + public List bitField(final byte[] key, final BitFieldArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + return notCommand(client, Command.BITFIELD, args); + } + + @Override + public List bitFieldRo(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.BITFIELD_RO, args); + } + + @Override + public List bitFieldRo(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.BITFIELD_RO, args); + } + + @Override + public List bitFieldRo(final String key, final BitFieldRoArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + return notCommand(client, Command.BITFIELD_RO, args); + } + + @Override + public List bitFieldRo(final byte[] key, final BitFieldRoArgument argument) { + final CommandArguments args = CommandArguments.create(key).add(argument); + return notCommand(client, Command.BITFIELD_RO, args); + } + + @Override + public Long bitOp(final BitOperation operation, final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create(operation).add(destKey).add(keys); + return notCommand(client, Command.BITOP, args); + } + + @Override + public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(operation).add(destKey).add(keys); + return notCommand(client, Command.BITOP, args); + } + + @Override + public Long bitPos(final String key, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(value); + return notCommand(client, Command.BITPOS, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(value); + return notCommand(client, Command.BITPOS, args); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start); + return notCommand(client, Command.BITPOS, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start); + return notCommand(client, Command.BITPOS, args); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(bitType); + return notCommand(client, Command.BITPOS, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(bitType); + return notCommand(client, Command.BITPOS, args); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end); + return notCommand(client, Command.BITPOS, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end); + return notCommand(client, Command.BITPOS, args); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final long end, + final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end).add(bitType); + return notCommand(client, Command.BITPOS, args); + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end, + final BitType bitType) { + final CommandArguments args = CommandArguments.create(key).add(value).add(start).add(end).add(bitType); + return notCommand(client, Command.BITPOS, args); + } + + @Override + public Boolean getBit(final String key, final long offset) { + final CommandArguments args = CommandArguments.create(key).add(offset); + return notCommand(client, Command.GETBIT, args); + } + + @Override + public Boolean getBit(final byte[] key, final long offset) { + final CommandArguments args = CommandArguments.create(key).add(offset); + return notCommand(client, Command.GETBIT, args); + } + + @Override + public Boolean setBit(final String key, final long offset, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(offset).add(value); + return notCommand(client, Command.SETBIT, args); + } + + @Override + public Boolean setBit(final byte[] key, final long offset, final boolean value) { + final CommandArguments args = CommandArguments.create(key).add(offset).add(value); + return notCommand(client, Command.SETBIT, args); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelClusterOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelClusterOperations.java new file mode 100644 index 000000000..4c9c58453 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelClusterOperations.java @@ -0,0 +1,267 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.BumpEpoch; +import com.buession.redis.core.ClusterFailoverOption; +import com.buession.redis.core.ClusterInfo; +import com.buession.redis.core.ClusterLink; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.ClusterResetOption; +import com.buession.redis.core.ClusterSetSlotOption; +import com.buession.redis.core.ClusterRedisShard; +import com.buession.redis.core.ClusterSlot; +import com.buession.redis.core.SlotRange; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; + +import java.util.List; + +/** + * Lettuce 哨兵模式集群命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelClusterOperations extends AbstractClusterOperations { + + public LettuceSentinelClusterOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Status asking() { + return notCommand(client, Command.ASKING); + } + + @Override + public Status clusterAddSlots(final int... slots) { + final CommandArguments args = CommandArguments.create(slots); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTS, args); + } + + @Override + public Status clusterAddSlotsRange(final SlotRange... slots) { + final CommandArguments args = CommandArguments.create(slots); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_ADDSLOTSRANGE, args); + } + + @Override + public KeyValue clusterBumpEpoch() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_BUMPEPOCH); + } + + @Override + public Long clusterCountFailureReports(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTFAILUREREPORTS, args); + } + + @Override + public Long clusterCountFailureReports(final byte[] nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTFAILUREREPORTS, args); + } + + @Override + public Long clusterCountKeysInSlot(final int slot) { + final CommandArguments args = CommandArguments.create(slot); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_COUNTKEYSINSLOT, args); + } + + @Override + public Status clusterDelSlots(final int... slots) { + final CommandArguments args = CommandArguments.create(slots); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTS, args); + } + + @Override + public Status clusterDelSlotsRange(final SlotRange... slots) { + final CommandArguments args = CommandArguments.create(slots); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_DELSLOTSRANGE, args); + } + + @Override + public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption) { + final CommandArguments args = CommandArguments.create(clusterFailoverOption); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_FAILOVER, args); + } + + @Override + public Status clusterForget(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_FORGET, args); + } + + @Override + public Status clusterForget(final byte[] nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_FORGET, args); + } + + @Override + public Status clusterFlushSlots() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_FLUSHSLOTS); + } + + @Override + public List clusterGetKeysInSlot(final int slot, final int count) { + final CommandArguments args = CommandArguments.create(slot).add(count); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_GETKEYSINSLOT, args); + } + + @Override + public ClusterInfo clusterInfo() { + return notCommand(client, Command.CLUSTER, SubCommand.INFO); + } + + @Override + public Long clusterKeySlot(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_KEYSLOT, args); + } + + @Override + public Long clusterKeySlot(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_KEYSLOT, args); + } + + @Override + public List clusterLinks() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_LINKS); + } + + @Override + public Status clusterMeet(final String ip, final int port) { + final CommandArguments args = CommandArguments.create(ip).add(port); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MEET, args); + } + + @Override + public String clusterMyId() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MYID); + } + + @Override + public String clusterMyShardId() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_MYSHARDID); + } + + @Override + public List clusterNodes() { + return notCommand(client, Command.CLUSTER, SubCommand.NODES); + } + + @Override + public List clusterReplicas(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICAS, args); + } + + @Override + public List clusterReplicas(final byte[] nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICAS, args); + } + + @Override + public Status clusterReplicate(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICATE, args); + } + + @Override + public Status clusterReplicate(final byte[] nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_REPLICATE, args); + } + + @Override + public Status clusterReset(final ClusterResetOption clusterResetOption) { + final CommandArguments args = CommandArguments.create(clusterResetOption); + return notCommand(client, Command.CLUSTER, SubCommand.RESET, args); + } + + @Override + public Status clusterSaveConfig() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SAVECONFIG); + } + + @Override + public Status clusterSetConfigEpoch(final long configEpoch) { + final CommandArguments args = CommandArguments.create(configEpoch); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SETCONFIGEPOCH, args); + } + + @Override + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId) { + final CommandArguments args = CommandArguments.create(slot).add(setSlotOption).add(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SETSLOT, args); + } + + @Override + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final byte[] nodeId) { + final CommandArguments args = CommandArguments.create(slot).add(setSlotOption).add(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SETSLOT, args); + } + + @Override + public List clusterShards() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SHARDS); + } + + @Override + public List clusterSlaves(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.SLAVES, args); + } + + @Override + public List clusterSlaves(final byte[] nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + return notCommand(client, Command.CLUSTER, SubCommand.SLAVES, args); + } + + @Override + public List clusterSlots() { + return notCommand(client, Command.CLUSTER, SubCommand.CLUSTER_SLOTS); + } + + @Override + public Status readOnly() { + return notCommand(client, Command.READONLY); + } + + @Override + public Status readWrite() { + return notCommand(client, Command.READWRITE); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelConnectionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelConnectionOperations.java new file mode 100644 index 000000000..c1dedc9e7 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelConnectionOperations.java @@ -0,0 +1,415 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.Client; +import com.buession.redis.core.ClientAttributeOption; +import com.buession.redis.core.ClientPauseMode; +import com.buession.redis.core.ClientReply; +import com.buession.redis.core.ClientTrackingInfo; +import com.buession.redis.core.ClientType; +import com.buession.redis.core.ClientUnblockType; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.RedisServer; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.ClientKillArgument; +import com.buession.redis.core.command.args.ClientTracking; +import com.buession.redis.core.command.args.HelloArgument; +import com.buession.redis.core.internal.convert.lettuce.params.ClientTypeConverter; +import com.buession.redis.core.internal.convert.response.ClientConverter; +import com.buession.redis.core.internal.convert.response.PingResultConverter; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ClientListArgs; +import io.lettuce.core.KillArgs; + +import java.util.List; + +/** + * Lettuce 哨兵模式连接命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelConnectionOperations extends AbstractConnectionOperations { + + public LettuceSentinelConnectionOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Status auth(final String user, final String password) { + final CommandArguments args = CommandArguments.create(user).add(password); + return notCommand(client, Command.AUTH, args); + } + + @Override + public Status auth(final byte[] user, final byte[] password) { + final CommandArguments args = CommandArguments.create(user).add(password); + return notCommand(client, Command.AUTH, args); + } + + @Override + public Status auth(final String password) { + final CommandArguments args = CommandArguments.create(password); + return notCommand(client, Command.AUTH, args); + } + + @Override + public Status auth(final byte[] password) { + final CommandArguments args = CommandArguments.create(password); + return notCommand(client, Command.AUTH, args); + } + + @Override + public Status clientCaching() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_CACHING); + } + + @Override + public Status clientCaching(final boolean isYes) { + final CommandArguments args = CommandArguments.create(isYes ? Keyword.Common.YES : Keyword.Common.NO); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_CACHING, args); + } + + @Override + public String clientGetName() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_GETNAME, + (cmd)->cmd.clientGetname(), SafeEncoder::encode) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_GETNAME, + (cmd)->cmd.clientGetname(), SafeEncoder::encode) + .run(); + }else{ + return new LettuceSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_GETNAME, + (cmd)->cmd.clientGetname(), SafeEncoder::encode) + .run(); + } + } + + @Override + public Integer clientGetRedir() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_GETREDIR); + } + + @Override + public Long clientId() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_ID); + } + + @Override + public Client clientInfo() { + final ClientConverter clientConverter = new ClientConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_INFO, + (cmd)->cmd.clientInfo(), + clientConverter) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_INFO, + (cmd)->cmd.clientInfo(), + clientConverter) + .run(); + }else{ + return new LettuceSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_INFO, (cmd)->cmd.clientInfo(), + clientConverter) + .run(); + } + } + + @Override + public Status clientKill(final String host, final int port) { + final CommandArguments args = CommandArguments.create(host).add(port); + final String addr = host + ':' + port; + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(addr), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(addr), okStatusConverter) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(addr), okStatusConverter) + .run(args); + } + } + + @Override + public Long clientKill(final ClientKillArgument... clientKillArguments) { + final CommandArguments args = CommandArguments.create(clientKillArguments); + final KillArgs killArgs = createKillArgsFromClientKillArgument(clientKillArguments); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(killArgs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(killArgs), (v)->v) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(killArgs), (v)->v) + .run(args); + } + } + + @Override + public List clientList() { + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(), clientListConverter) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(), clientListConverter) + .run(); + }else{ + return new LettuceSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + } + } + + @Override + public List clientList(final ClientType clientType) { + final CommandArguments args = CommandArguments.create(clientType); + final ClientListArgs clientListArgs = (new ClientTypeConverter()).convert(clientType); + + return clientList(clientListArgs, args); + } + + @Override + public List clientList(final long... clientIds) { + final CommandArguments args = CommandArguments.create(clientIds); + final ClientListArgs clientListArgs = ClientListArgs.Builder.ids(clientIds); + + return clientList(clientListArgs, args); + } + + @Override + public Status clientNoEvict(final boolean on) { + final CommandArguments args = CommandArguments.create(on ? Keyword.Common.ON : Keyword.Common.OFF); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_NO_EVICT, args); + } + + @Override + public Status clientNoTouch(final boolean on) { + final CommandArguments args = CommandArguments.create(on ? Keyword.Common.ON : Keyword.Common.OFF); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_NO_TOUCH, args); + } + + @Override + public Status clientPause(final int timeout) { + final CommandArguments args = CommandArguments.create(timeout); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientPause(final int timeout, final ClientPauseMode pauseMode) { + final CommandArguments args = CommandArguments.create(timeout).add(pauseMode); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientReply(final ClientReply option) { + final CommandArguments args = CommandArguments.create(option); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_REPLY, args); + } + + @Override + public Status clientSetInfo(final ClientAttributeOption clientAttributeOption, final String value) { + final CommandArguments args = CommandArguments.create(clientAttributeOption).add(value); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETINFO, + (cmd)->cmd.clientSetinfo(clientAttributeOption.name(), value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETINFO, + (cmd)->cmd.clientSetinfo(clientAttributeOption.name(), value), okStatusConverter) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETINFO, + (cmd)->cmd.clientSetinfo(clientAttributeOption.name(), value), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientSetName(final byte[] name) { + final CommandArguments args = CommandArguments.create(name); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientTracking(final ClientTracking clientTracking) { + final CommandArguments args = CommandArguments.create(clientTracking); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_TRACKING, args); + } + + @Override + public ClientTrackingInfo clientTrackingInfo() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_TRACKINGINFO); + } + + @Override + public Status clientUnblock(final int clientId) { + final CommandArguments args = CommandArguments.create(clientId); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK, args); + } + + @Override + public Status clientUnblock(final int clientId, final ClientUnblockType type) { + final CommandArguments args = CommandArguments.create(clientId).add(type); + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_UNBLOCK, args); + } + + @Override + public Status clientUnPause() { + return notCommand(client, Command.CLIENT, SubCommand.CLIENT_UNPAUSE); + } + + @Override + public String echo(final String str) { + final CommandArguments args = CommandArguments.create("str", str); + return notCommand(client, Command.ECHO, args); + } + + @Override + public byte[] echo(final byte[] str) { + final CommandArguments args = CommandArguments.create("str", str); + return notCommand(client, Command.ECHO, args); + } + + @Override + public RedisServer hello(final HelloArgument helloArgument) { + final CommandArguments args = CommandArguments.create(helloArgument); + return notCommand(client, Command.HELLO, args); + } + + @Override + public Status ping() { + final PingResultConverter pingResultConverter = new PingResultConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, Command.ECHO, (cmd)->cmd.ping(), + pingResultConverter) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, Command.ECHO, (cmd)->cmd.ping(), + pingResultConverter) + .run(); + }else{ + return new LettuceSentinelCommand<>(client, Command.ECHO, (cmd)->cmd.ping(), pingResultConverter) + .run(); + } + } + + @Override + public Status quit() { + return notCommand(client, Command.QUIT); + } + + @Override + public Status reset() { + return notCommand(client, Command.RESET); + } + + @Override + public Status select(final int db) { + final CommandArguments args = CommandArguments.create(db); + return notCommand(client, Command.SELECT, args); + } + + private List clientList(final ClientListArgs clientListArgs, final CommandArguments args) { + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(clientListArgs), clientListConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(clientListArgs), clientListConverter) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, Command.CLIENT, SubCommand.CLIENT_LIST, + (cmd)->cmd.clientList(clientListArgs), clientListConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelGeoOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelGeoOperations.java new file mode 100644 index 000000000..2e1530834 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelGeoOperations.java @@ -0,0 +1,305 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Geo; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.GeoAddArgument; +import com.buession.redis.core.command.args.GeoRadiusArgument; +import com.buession.redis.core.command.args.GeoSearchArgument; +import com.buession.redis.core.command.args.GeoSearchStoreArgument; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 哨兵模式地理位置命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelGeoOperations extends AbstractGeoOperations { + + public LettuceSentinelGeoOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Long geoAdd(final String key, final String member, final double longitude, final double latitude) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(member); + return notCommand(client, Command.GEOADD, args); + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(member); + return notCommand(client, Command.GEOADD, args); + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + return notCommand(client, Command.GEOADD, args); + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + return notCommand(client, Command.GEOADD, args); + } + + @Override + public Long geoAdd(final String key, final String member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(longitude).add(latitude) + .add(member); + return notCommand(client, Command.GEOADD, args); + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoAddArgument).add(longitude).add(latitude) + .add(member); + return notCommand(client, Command.GEOADD, args); + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + return notCommand(client, Command.GEOADD, args); + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates, + final GeoAddArgument geoAddArgument) { + final CommandArguments args = CommandArguments.create(key).add(memberCoordinates); + return notCommand(client, Command.GEOADD, args); + } + + @Override + public Double geoDist(final String key, final String member1, final String member2) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2); + return notCommand(client, Command.GEODIST, args); + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2); + return notCommand(client, Command.GEODIST, args); + } + + @Override + public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2).add(unit); + return notCommand(client, Command.GEODIST, args); + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member1).add(member2).add(unit); + return notCommand(client, Command.GEODIST, args); + } + + @Override + public List geoHash(final String key, final String... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + return notCommand(client, Command.GEOHASH, args); + } + + @Override + public List geoHash(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + return notCommand(client, Command.GEOHASH, args); + } + + @Override + public List geoPos(final String key, final String... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + return notCommand(client, Command.GEOPOS, args); + } + + @Override + public List geoPos(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create(key).add(members); + return notCommand(client, Command.GEOPOS, args); + } + + @Override + public List geoRadius(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + return notCommand(client, Command.GEORADIUS, args); + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + return notCommand(client, Command.GEORADIUS, args); + } + + @Override + public List geoRadius(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = + CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit).add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUS, args); + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = + CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit).add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUS, args); + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + return notCommand(client, Command.GEORADIUS_RO, args); + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit); + return notCommand(client, Command.GEORADIUS_RO, args); + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = + CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit).add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUS_RO, args); + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = + CommandArguments.create(key).add(longitude).add(latitude).add(radius).add(unit).add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUS_RO, args); + } + + @Override + public List geoRadiusByMember(final String key, final String member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + return notCommand(client, Command.GEORADIUSBYMEMBER, args); + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + return notCommand(client, Command.GEORADIUSBYMEMBER, args); + } + + @Override + public List geoRadiusByMember(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUSBYMEMBER, args); + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUSBYMEMBER, args); + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + return notCommand(client, Command.GEORADIUSBYMEMBER_RO, args); + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit); + return notCommand(client, Command.GEORADIUSBYMEMBER_RO, args); + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUSBYMEMBER_RO, args); + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create(key).add(member).add(radius).add(unit) + .add(geoRadiusArgument); + return notCommand(client, Command.GEORADIUSBYMEMBER_RO, args); + } + + @Override + public List geoSearch(final String key, final GeoSearchArgument geoSearchArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoSearchArgument); + return notCommand(client, Command.GEOSEARCH, args); + } + + @Override + public List geoSearch(final byte[] key, final GeoSearchArgument geoSearchArgument) { + final CommandArguments args = CommandArguments.create(key).add(geoSearchArgument); + return notCommand(client, Command.GEOSEARCH, args); + } + + @Override + public Long geoSearchStore(final String destKey, final String key, + final GeoSearchStoreArgument geoSearchStoreArgument) { + final CommandArguments args = CommandArguments.create(destKey).add(key).add(geoSearchStoreArgument); + return notCommand(client, Command.GEOSEARCHSTORE, args); + } + + @Override + public Long geoSearchStore(final byte[] destKey, final byte[] key, + final GeoSearchStoreArgument geoSearchStoreArgument) { + final CommandArguments args = CommandArguments.create(destKey).add(key).add(geoSearchStoreArgument); + return notCommand(client, Command.GEOSEARCHSTORE, args); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelHashOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelHashOperations.java new file mode 100644 index 000000000..8a7dfc329 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelHashOperations.java @@ -0,0 +1,459 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.HScanArgument; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Lettuce 哨兵模式模式哈希表命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelHashOperations extends AbstractHashOperations { + + public LettuceSentinelHashOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Long hDel(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + return notCommand(client, Command.HDEL, args); + } + + @Override + public Long hDel(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + return notCommand(client, Command.HDEL, args); + } + + @Override + public Boolean hExists(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); + return notCommand(client, Command.HEXISTS, args); + } + + @Override + public Boolean hExists(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + return notCommand(client, Command.HEXISTS, args); + } + + @Override + public List hExpire(final String key, final int lifetime, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields.length) + .add(fields); + return notCommand(client, Command.HEXPIRE, args); + } + + @Override + public List hExpire(final byte[] key, final int lifetime, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields.length) + .add(fields); + return notCommand(client, Command.HEXPIRE, args); + } + + @Override + public List hExpire(final String key, final int lifetime, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIRE, args); + } + + @Override + public List hExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIRE, args); + } + + @Override + public List hExpireAt(final String key, final long unixTimestamp, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireTime(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public List hExpireTime(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields.length).add(fields); + return notCommand(client, Command.HEXPIREAT, args); + } + + @Override + public String hGet(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); + return notCommand(client, Command.HGET, args); + } + + @Override + public byte[] hGet(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + return notCommand(client, Command.HGET, args); + } + + @Override + public Map hGetAll(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.HGETALL, args); + } + + @Override + public Map hGetAll(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.HGETALL, args); + } + + @Override + public Long hIncrBy(final String key, final String field, final long value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + return notCommand(client, Command.HINCRBY, args); + } + + @Override + public Long hIncrBy(final byte[] key, final byte[] field, final long value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + return notCommand(client, Command.HINCRBY, args); + } + + @Override + public Double hIncrByFloat(final String key, final String field, final double value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + return notCommand(client, Command.HINCRBYFLOAT, args); + } + + @Override + public Double hIncrByFloat(final byte[] key, final byte[] field, final double value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + return notCommand(client, Command.HINCRBYFLOAT, args); + } + + @Override + public Set hKeys(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.HKEYS, args); + } + + @Override + public Set hKeys(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.HKEYS, args); + } + + @Override + public Long hLen(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.HLEN, args); + } + + @Override + public Long hLen(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.HLEN, args); + } + + @Override + public List hMGet(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + return notCommand(client, Command.HMGET, args); + } + + @Override + public List hMGet(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); + return notCommand(client, Command.HMGET, args); + } + + @Override + public Status hMSet(final String key, final Map data) { + final CommandArguments args = CommandArguments.create(key).add(data); + return notCommand(client, Command.HMSET, args); + } + + @Override + public Status hMSet(final byte[] key, final Map data) { + final CommandArguments args = CommandArguments.create(key).add(data); + return notCommand(client, Command.HMSET, args); + } + + @Override + public List hPersist(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPERSIST, args); + } + + @Override + public List hPersist(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPERSIST, args); + } + + @Override + public List hpExpire(final String key, final int lifetime, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpire(final byte[] key, final int lifetime, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpire(final String key, final int lifetime, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = + CommandArguments.create(key).add(lifetime).add(expireOption).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = + CommandArguments.create(key).add(lifetime).add(expireOption).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRE, args); + } + + @Override + public List hpExpireAt(final String key, final long unixTimestamp, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption, + final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption) + .add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIREAT, args); + } + + @Override + public List hpExpireTime(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRETIME, args); + } + + @Override + public List hpExpireTime(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPEXPIRETIME, args); + } + + @Override + public List hpTtl(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public List hpTtl(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public String hRandField(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.HRANDFIELD, args); + } + + @Override + public byte[] hRandField(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.HRANDFIELD, args); + } + + @Override + public List hRandField(final String key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count); + return notCommand(client, Command.HRANDFIELD, args); + } + + @Override + public List hRandField(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count); + return notCommand(client, Command.HRANDFIELD, args); + } + + @Override + public List> hRandFieldWithValues(final String key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count).add(Keyword.Hash.WITHVALUES); + return notCommand(client, Command.HRANDFIELD, args); + } + + @Override + public List> hRandFieldWithValues(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create(key).add(count).add(Keyword.Hash.WITHVALUES); + return notCommand(client, Command.HRANDFIELD, args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create(key).add(cursor); + return notCommand(client, Command.HSCAN, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create(key).add(cursor); + return notCommand(client, Command.HSCAN, args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor, + final HScanArgument scanArgument) { + final CommandArguments args = CommandArguments.create(key).add(cursor).add(scanArgument); + return notCommand(client, Command.HSCAN, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, + final HScanArgument scanArgument) { + final CommandArguments args = CommandArguments.create(key).add(cursor).add(scanArgument); + return notCommand(client, Command.HSCAN, args); + } + + @Override + public Long hSet(final String key, final KeyValue... data) { + final CommandArguments args = CommandArguments.create(key).add(data); + return notCommand(client, Command.HSET, args); + } + + @Override + public Long hSet(final byte[] key, final KeyValue... data) { + final CommandArguments args = CommandArguments.create(key).add(data); + return notCommand(client, Command.HSET, args); + } + + @Override + public Status hSetNx(final String key, final String field, final String value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + return notCommand(client, Command.HSETNX, args); + } + + @Override + public Status hSetNx(final byte[] key, final byte[] field, final byte[] value) { + final CommandArguments args = CommandArguments.create(key).add(field).add(value); + return notCommand(client, Command.HSETNX, args); + } + + @Override + public Long hStrLen(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); + return notCommand(client, Command.HSTRLEN, args); + } + + @Override + public Long hStrLen(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); + return notCommand(client, Command.HSTRLEN, args); + } + + @Override + public List hTtl(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public List hTtl(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(Keyword.Hash.FIELDS, fields); + return notCommand(client, Command.HPTTL, args); + } + + @Override + public List hVals(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.HVALS, args); + } + + @Override + public List hVals(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.HVALS, args); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelHyperLogLogOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelHyperLogLogOperations.java new file mode 100644 index 000000000..78c445c60 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelHyperLogLogOperations.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; + +/** + * Lettuce 哨兵模式 HyperLogLog 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelHyperLogLogOperations extends AbstractHyperLogLogOperations { + + public LettuceSentinelHyperLogLogOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Status pfAdd(final String key, final String... elements) { + final CommandArguments args = CommandArguments.create(key).add(elements); + return notCommand(client, Command.PFADD, args); + } + + @Override + public Status pfAdd(final byte[] key, final byte[]... elements) { + final CommandArguments args = CommandArguments.create(key).add(elements); + return notCommand(client, Command.PFADD, args); + } + + @Override + public Long pfCount(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + return notCommand(client, Command.PFCOUNT, args); + } + + @Override + public Long pfCount(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return notCommand(client, Command.PFCOUNT, args); + } + + @Override + public Status pfMerge(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create(destKey).add(keys); + return notCommand(client, Command.PFMERGE, args); + } + + @Override + public Status pfMerge(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(destKey).add(keys); + return notCommand(client, Command.PFMERGE, args); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelKeyOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelKeyOperations.java new file mode 100644 index 000000000..7359e6c17 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelKeyOperations.java @@ -0,0 +1,627 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.Keyword; +import com.buession.redis.core.ObjectEncoding; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Type; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.core.command.args.MigrateArgument; +import com.buession.redis.core.command.args.RestoreArgument; +import com.buession.redis.core.command.args.SortArgument; + +import java.util.List; +import java.util.Set; + +/** + * Lettuce 哨兵模式 Key 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelKeyOperations extends AbstractKeyOperations { + + public LettuceSentinelKeyOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Status copy(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + return notCommand(client, Command.COPY, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + return notCommand(client, Command.COPY, args); + } + + @Override + public Status copy(final String key, final String destKey, final int db) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + return notCommand(client, Command.COPY, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + return notCommand(client, Command.COPY, args); + } + + @Override + public Status copy(final String key, final String destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return notCommand(client, Command.COPY, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return notCommand(client, Command.COPY, args); + } + + @Override + public Status copy(final String key, final String destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return notCommand(client, Command.COPY, args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(db); + + if(replace){ + args.add(Keyword.Common.REPLACE); + } + + return notCommand(client, Command.COPY, args); + } + + @Override + public Long del(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + return notCommand(client, Command.DEL, args); + } + + @Override + public Long del(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return notCommand(client, Command.DEL, args); + } + + @Override + public String dump(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.DUMP, args); + } + + @Override + public byte[] dump(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.DUMP, args); + } + + @Override + public Boolean exists(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.EXISTS, args); + } + + @Override + public Boolean exists(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.EXISTS, args); + } + + @Override + public Long exists(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + return notCommand(client, Command.EXISTS, args); + } + + @Override + public Long exists(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return notCommand(client, Command.EXISTS, args); + } + + @Override + public Status expire(final String key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + return notCommand(client, Command.EXPIRE, args); + } + + @Override + public Status expire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + return notCommand(client, Command.EXPIRE, args); + } + + @Override + public Status expire(final String key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + return notCommand(client, Command.EXPIRE, args); + } + + @Override + public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + return notCommand(client, Command.EXPIRE, args); + } + + @Override + public Status expireAt(final String key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + return notCommand(client, Command.EXPIREAT, args); + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + return notCommand(client, Command.EXPIREAT, args); + } + + @Override + public Status expireAt(final String key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + return notCommand(client, Command.EXPIREAT, args); + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + return notCommand(client, Command.EXPIREAT, args); + } + + @Override + public Long expireTime(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.EXPIRETIME, args); + } + + @Override + public Long expireTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.EXPIRETIME, args); + } + + @Override + public Set keys(final String pattern) { + final CommandArguments args = CommandArguments.create(pattern); + return notCommand(client, Command.KEYS, args); + } + + @Override + public Set keys(final byte[] pattern) { + final CommandArguments args = CommandArguments.create(pattern); + return notCommand(client, Command.KEYS, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(keys); + return notCommand(client, Command.MIGRATE, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgument migrateArgument, final String... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(migrateArgument) + .add(keys); + return notCommand(client, Command.MIGRATE, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgument migrateArgument, final byte[]... keys) { + final CommandArguments args = CommandArguments.create(host).add(port).add(db).add(timeout).add(migrateArgument) + .add(keys); + return notCommand(client, Command.MIGRATE, args); + } + + @Override + public Status move(final byte[] key, final int db) { + final CommandArguments args = CommandArguments.create(key).add(db); + return notCommand(client, Command.MOVE, args); + } + + @Override + public ObjectEncoding objectEncoding(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, args); + } + + @Override + public ObjectEncoding objectEncoding(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.OBJECT, SubCommand.OBJECT_ENCODING, args); + } + + @Override + public Long objectFreq(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.OBJECT, SubCommand.OBJECT_REFQ, args); + } + + @Override + public Long objectFreq(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.OBJECT, SubCommand.OBJECT_REFQ, args); + } + + @Override + public Long objectIdleTime(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, args); + } + + @Override + public Long objectIdleTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.OBJECT, SubCommand.OBJECT_IDLETIME, args); + } + + @Override + public Long objectRefcount(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, args); + } + + @Override + public Long objectRefcount(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.OBJECT, SubCommand.OBJECT_REFCOUNT, args); + } + + @Override + public Status persist(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.PERSIST, args); + } + + @Override + public Status persist(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.PERSIST, args); + } + + @Override + public Status pExpire(final String key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + return notCommand(client, Command.PEXPIRE, args); + } + + @Override + public Status pExpire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + return notCommand(client, Command.PEXPIRE, args); + } + + @Override + public Status pExpire(final String key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(lifetime).add(expireOption); + return notCommand(client, Command.PEXPIRE, args); + } + + @Override + public Status pExpire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create(key).add(lifetime); + return notCommand(client, Command.PEXPIRE, args); + } + + @Override + public Status pExpireAt(final String key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + return notCommand(client, Command.PEXPIREAT, args); + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp); + return notCommand(client, Command.PEXPIREAT, args); + } + + @Override + public Status pExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + return notCommand(client, Command.PEXPIREAT, args); + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create(key).add(unixTimestamp).add(expireOption); + return notCommand(client, Command.PEXPIREAT, args); + } + + @Override + public Long pExpireTime(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.PEXPIRETIME, args); + } + + @Override + public Long pExpireTime(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.PEXPIRETIME, args); + } + + @Override + public Long pTtl(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.PTTL, args); + } + + @Override + public Long pTtl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.PTTL, args); + } + + @Override + public String randomKey() { + return notCommand(client, Command.RANDOMKEY); + } + + @Override + public Status rename(final String key, final String newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + return notCommand(client, Command.RENAME, args); + } + + @Override + public Status rename(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + return notCommand(client, Command.RENAME, args); + } + + @Override + public Status renameNx(final String key, final String newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + return notCommand(client, Command.RENAMENX, args); + } + + @Override + public Status renameNx(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create(key).add(newKey); + return notCommand(client, Command.RENAMENX, args); + } + + @Override + public Status restore(final String key, final byte[] serializedValue, final int ttl) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl); + return notCommand(client, Command.RESTORE, args); + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl); + return notCommand(client, Command.RESTORE, args); + } + + @Override + public Status restore(final String key, final byte[] serializedValue, final int ttl, + final RestoreArgument restoreArgument) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl).add(restoreArgument); + return notCommand(client, Command.RESTORE, args); + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl, + final RestoreArgument restoreArgument) { + final CommandArguments args = CommandArguments.create(key).add(serializedValue).add(ttl).add(restoreArgument); + return notCommand(client, Command.RESTORE, args); + } + + @Override + public ScanResult> scan(final String cursor) { + final CommandArguments args = CommandArguments.create(cursor); + return notCommand(client, Command.SCAN, args); + } + + @Override + public ScanResult> scan(final byte[] cursor) { + final CommandArguments args = CommandArguments.create(cursor); + return notCommand(client, Command.SCAN, args); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern); + return notCommand(client, Command.SCAN, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern); + return notCommand(client, Command.SCAN, args); + } + + @Override + public ScanResult> scan(final String cursor, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(count); + return notCommand(client, Command.SCAN, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(count); + return notCommand(client, Command.SCAN, args); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern).add(count); + return notCommand(client, Command.SCAN, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern, final int count) { + final CommandArguments args = CommandArguments.create(cursor).add(pattern).add(count); + return notCommand(client, Command.SCAN, args); + } + + @Override + public List sort(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.SORT, args); + } + + @Override + public List sort(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.SORT, args); + } + + @Override + public List sort(final String key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + return notCommand(client, Command.SORT, args); + } + + @Override + public List sort(final byte[] key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + return notCommand(client, Command.SORT, args); + } + + @Override + public Long sort(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + return notCommand(client, Command.SORT, args); + } + + @Override + public Long sort(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create(key).add(destKey); + return notCommand(client, Command.SORT, args); + } + + @Override + public Long sort(final String key, final String destKey, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(sortArgument); + return notCommand(client, Command.SORT, args); + } + + @Override + public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(destKey).add(sortArgument); + return notCommand(client, Command.SORT, args); + } + + @Override + public List sortRo(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.SORT_RO, args); + } + + @Override + public List sortRo(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.SORT_RO, args); + } + + @Override + public List sortRo(final String key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + return notCommand(client, Command.SORT_RO, args); + } + + @Override + public List sortRo(final byte[] key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create(key).add(sortArgument); + return notCommand(client, Command.SORT_RO, args); + } + + @Override + public Long touch(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + return notCommand(client, Command.TOUCH, args); + } + + @Override + public Long touch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return notCommand(client, Command.TOUCH, args); + } + + @Override + public Long ttl(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.TTL, args); + } + + @Override + public Long ttl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.TTL, args); + } + + @Override + public Type type(final String key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.TYPE, args); + } + + @Override + public Type type(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return notCommand(client, Command.TYPE, args); + } + + @Override + public Long unlink(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + return notCommand(client, Command.UNLINK, args); + } + + @Override + public Long unlink(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return notCommand(client, Command.UNLINK, args); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelListOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelListOperations.java new file mode 100644 index 000000000..74a7f6122 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelListOperations.java @@ -0,0 +1,464 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.builder.ListBuilder; +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.Direction; +import com.buession.redis.core.ListPosition; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.LPosArgument; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyValue; + +import java.util.List; + +/** + * Lettuce 哨兵模式列表命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelListOperations extends AbstractListOperations { + + public LettuceSentinelListOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public String lIndex(final String key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + return notCommand(client, Command.LINDEX, args); + } + + @Override + public byte[] lIndex(final byte[] key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + return notCommand(client, Command.LINDEX, args); + } + + @Override + public Long lInsert(final String key, final ListPosition position, final String pivot, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) + .put("value", value); + return notCommand(client, Command.LINSERT, args); + } + + @Override + public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) + .put("value", value); + return notCommand(client, Command.LINSERT, args); + } + + @Override + public Status lSet(final String key, final long index, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); + return notCommand(client, Command.LSET, args); + } + + @Override + public Status lSet(final byte[] key, final long index, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); + return notCommand(client, Command.LSET, args); + } + + @Override + public Long lLen(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + return notCommand(client, Command.LLEN, args); + } + + @Override + public Long lLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return notCommand(client, Command.LLEN, args); + } + + @Override + public List lRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return notCommand(client, Command.LRANGE, args); + } + + @Override + public List lRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return notCommand(client, Command.LRANGE, args); + } + + @Override + public Long lPos(final String key, final String element) { + final CommandArguments args = CommandArguments.create("key", key); + return notCommand(client, Command.LPOS, args); + } + + @Override + public Long lPos(final byte[] key, final byte[] element) { + final CommandArguments args = CommandArguments.create("key", key); + return notCommand(client, Command.LPOS, args); + } + + @Override + public Long lPos(final String key, final String element, final LPosArgument lPosArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); + return notCommand(client, Command.LPOS, args); + } + + @Override + public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); + return notCommand(client, Command.LPOS, args); + } + + @Override + public List lPos(final String key, final String element, final LPosArgument lPosArgument, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) + .put("count", count); + return notCommand(client, Command.LPOS, args); + } + + @Override + public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) + .put("count", count); + return notCommand(client, Command.LPOS, args); + } + + @Override + public Long lRem(final byte[] key, final byte[] value, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); + return notCommand(client, Command.LREM, args); + } + + @Override + public Status lTrim(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return notCommand(client, Command.LTRIM, args); + } + + @Override + public String lMove(final String key, final String destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + return notCommand(client, Command.LMOVE, args); + } + + @Override + public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + return notCommand(client, Command.LMOVE, args); + } + + @Override + public String blMove(final String key, final String destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + return notCommand(client, Command.BLMOVE, args); + } + + @Override + public byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to).put("timeout", timeout); + return notCommand(client, Command.BLMOVE, args); + } + + @Override + public List blPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final Converter, List> converter = + (v)->ListBuilder.of(SafeEncoder.encode(v.getValue())); + + return blPop(bKeys, timeout, converter, args); + } + + @Override + public List blPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final Converter, List> converter = (v)->ListBuilder.of(v.getValue()); + + return blPop(keys, timeout, converter, args); + } + + @Override + public List brPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final Converter, List> converter = + (v)->ListBuilder.of(SafeEncoder.encode(v.getValue())); + + return brPop(bKeys, timeout, converter, args); + } + + @Override + public List brPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final Converter, List> converter = (v)->ListBuilder.of(v.getValue()); + + return brPop(keys, timeout, converter, args); + } + + @Override + public String brPoplPush(final String key, final String destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + + return brPoplPush(bKey, bDestKey, timeout, SafeEncoder::encode, args); + } + + @Override + public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + return brPoplPush(key, destKey, timeout, (v)->v, args); + } + + @Override + public String lPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return lPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] lPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return lPop(key, (v)->v, args); + } + + @Override + public Long lPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.LPUSH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.LPUSH) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.LPUSH) + .run(args); + } + } + + @Override + public Long lPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.LPUSHX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.LPUSHX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.LPUSHX) + .run(args); + } + } + + @Override + public String rPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return rPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] rPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return rPop(key, (v)->v, args); + } + + @Override + public String rPoplPush(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + + return rPoplPush(bKey, bDestKey, SafeEncoder::encode, args); + } + + @Override + public byte[] rPoplPush(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + return rPoplPush(key, destKey, (v)->v, args); + } + + @Override + public Long rPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.RPUSH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.RPUSH) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.RPUSH) + .run(args); + } + } + + @Override + public Long rPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.RPUSHX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.RPUSHX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.RPUSHX) + .run(args); + } + } + + private List lRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.LRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.LRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.LRANGE) + .run(args); + } + } + + private V blMove(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.BLMOVE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.BLMOVE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.BLMOVE) + .run(args); + } + } + + private List blPop(final byte[][] keys, final int timeout, final Converter, + List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.BLPOP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.BLPOP) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.BLPOP) + .run(args); + } + } + + private List brPop(final byte[][] keys, final int timeout, final Converter, + List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.BRPOP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.BRPOP) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.BRPOP) + .run(args); + } + } + + private V brPoplPush(final byte[] key, final byte[] destKey, final int timeout, + final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.BRPOPLPUSH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.BRPOPLPUSH) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.BRPOPLPUSH) + .run(args); + } + } + + private V lPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.LPOP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.LPOP) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.LPOP) + .run(args); + } + } + + private V rPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.RPOP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.RPOP) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.RPOP) + .run(args); + } + } + + private V rPoplPush(final byte[] key, final byte[] destKey, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.RPOPLPUSH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.RPOPLPUSH) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.RPOPLPUSH) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelPubSubOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelPubSubOperations.java new file mode 100644 index 000000000..a05ea073a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelPubSubOperations.java @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.PubSubListener; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 哨兵模式 Pub/Sub 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelPubSubOperations extends AbstractPubSubOperations { + + public LettuceSentinelPubSubOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + notCommand(client, Command.PSUBSCRIBE, args); + } + + @Override + public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + notCommand(client, Command.PSUBSCRIBE, args); + } + + @Override + public Long publish(final String channel, final String message) { + final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); + return notCommand(client, Command.PUBLISH, args); + } + + @Override + public Long publish(final byte[] channel, final byte[] message) { + final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); + return notCommand(client, Command.PUBLISH, args); + } + + @Override + public List pubsubChannels() { + return notCommand(client, Command.PUBSUB_CHANNELS); + } + + @Override + public List pubsubChannels(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return notCommand(client, Command.PUBSUB_CHANNELS, args); + } + + @Override + public List pubsubChannels(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return notCommand(client, Command.PUBSUB_CHANNELS, args); + } + + @Override + public List pubsubShardChannels() { + return notCommand(client, Command.PUBSUB_SHARDCHANNELS); + } + + @Override + public List pubsubShardChannels(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return notCommand(client, Command.PUBSUB_SHARDCHANNELS, args); + } + + @Override + public List pubsubShardChannels(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return notCommand(client, Command.PUBSUB_SHARDCHANNELS, args); + } + + @Override + public Long pubsubNumPat() { + return notCommand(client, Command.PUBSUB_NUMPAT); + } + + @Override + public Map pubsubNumSub() { + return notCommand(client, Command.PUBSUB_NUMSUB); + } + + @Override + public Map pubsubNumSub(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return notCommand(client, Command.PUBSUB_NUMSUB, args); + } + + @Override + public Map pubsubNumSub(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return notCommand(client, Command.PUBSUB_NUMSUB, args); + } + + @Override + public Map pubsubShardNumSub() { + return notCommand(client, Command.PUBSUB_SHARDNUMSUB); + } + + @Override + public Map pubsubShardNumSub(final String... shardChannels) { + final CommandArguments args = CommandArguments.create("shardChannels", (Object[]) shardChannels); + return notCommand(client, Command.PUBSUB_SHARDNUMSUB, args); + } + + @Override + public Map pubsubShardNumSub(final byte[]... shardChannels) { + final CommandArguments args = CommandArguments.create("shardChannels", (Object[]) shardChannels); + return notCommand(client, Command.PUBSUB_SHARDNUMSUB, args); + } + + @Override + public Object pUnSubscribe() { + return notCommand(client, Command.PUNSUBSCRIBE); + } + + @Override + public Object pUnSubscribe(final String... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return notCommand(client, Command.PUNSUBSCRIBE, args); + } + + @Override + public Object pUnSubscribe(final byte[]... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return notCommand(client, Command.PUNSUBSCRIBE, args); + } + + @Override + public void subscribe(final String[] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + notCommand(client, Command.SUBSCRIBE, args); + } + + @Override + public void subscribe(final byte[][] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + notCommand(client, Command.SUBSCRIBE, args); + } + + @Override + public Object unSubscribe() { + return notCommand(client, Command.UNSUBSCRIBE); + } + + @Override + public Object unSubscribe(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return notCommand(client, Command.UNSUBSCRIBE, args); + } + + @Override + public Object unSubscribe(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return notCommand(client, Command.UNSUBSCRIBE, args); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelScriptingOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelScriptingOperations.java new file mode 100644 index 000000000..8eb1b6d6f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelScriptingOperations.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; + +import java.util.List; + +/** + * Lettuce 哨兵模式 Script 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelScriptingOperations extends AbstractScriptingOperations { + + public LettuceSentinelScriptingOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Object eval(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + return notCommand(client, Command.EVAL, args); + } + + @Override + public Object eval(final byte[] script) { + final CommandArguments args = CommandArguments.create("script", script); + return notCommand(client, Command.EVAL, args); + } + + @Override + public Object eval(final String script, final String... params) { + final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + return notCommand(client, Command.EVAL, args); + } + + @Override + public Object eval(final byte[] script, final byte[]... params) { + final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + return notCommand(client, Command.EVAL, args); + } + + @Override + public Object eval(final String script, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + return notCommand(client, Command.EVAL, args); + } + + @Override + public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments) { + final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + return notCommand(client, Command.EVAL, args); + } + + @Override + public Object evalSha(final String digest) { + final CommandArguments args = CommandArguments.create("digest", digest); + return notCommand(client, Command.EVALSHA, args); + } + + @Override + public Object evalSha(final String digest, final String... params) { + final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); + return notCommand(client, Command.EVALSHA, args); + } + + @Override + public Object evalSha(final String digest, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + return notCommand(client, Command.EVALSHA, args); + } + + @Override + public List scriptExists(final String... sha1) { + final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); + return notCommand(client, Command.SCRIPT_EXISTS, args); + } + + @Override + public List scriptExists(final byte[]... sha1) { + final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); + return notCommand(client, Command.SCRIPT_EXISTS, args); + } + + @Override + public Status scriptFlush() { + return notCommand(client, Command.SCRIPT_FLUSH); + } + + @Override + public Status scriptFlush(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + return notCommand(client, Command.SCRIPT_FLUSH, args); + } + + @Override + public String scriptLoad(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + return notCommand(client, Command.SCRIPT_LOAD, args); + } + + @Override + public byte[] scriptLoad(final byte[] script) { + final CommandArguments args = CommandArguments.create("script", script); + return notCommand(client, Command.SCRIPT_LOAD, args); + } + + @Override + public Status scriptKill() { + return notCommand(client, Command.SCRIPT_KILL); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelServerOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelServerOperations.java new file mode 100644 index 000000000..dde778a31 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelServerOperations.java @@ -0,0 +1,765 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.Info; +import com.buession.redis.core.MemoryStats; +import com.buession.redis.core.Module; +import com.buession.redis.core.RedisMonitor; +import com.buession.redis.core.RedisServerTime; +import com.buession.redis.core.Role; +import com.buession.redis.core.SlowLog; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.lettuce.response.RedisServerTimeConverter; +import com.buession.redis.core.internal.convert.lettuce.response.RoleConverter; +import com.buession.redis.core.internal.convert.lettuce.response.SlowlogConverter; +import com.buession.redis.core.internal.convert.response.InfoConverter; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 哨兵模式服务端命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelServerOperations extends AbstractServerOperations { + + public LettuceSentinelServerOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public String bgRewriteAof() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.BGREWRITEAOF) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.BGREWRITEAOF) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.BGREWRITEAOF) + .run(); + } + } + + @Override + public String bgSave() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.BGSAVE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.BGSAVE) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.BGSAVE) + .run(); + } + } + + @Override + public Status configSet(final String parameter, final String value) { + final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.CONFIG_SET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.CONFIG_SET) + .run(args); + } + } + + @Override + public Status configSet(final Map configs) { + final CommandArguments args = CommandArguments.create("configs", configs); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.CONFIG_SET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.CONFIG_SET) + .run(args); + } + } + + @Override + public Map configGet(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return configGet(pattern, args); + } + + @Override + public Map configGet(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final String sPattern = SafeEncoder.encode(pattern); + + return configGet(sPattern, args); + } + + @Override + public Status configResetStat() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.CONFIG_RESETSTAT) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.CONFIG_RESETSTAT) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.CONFIG_RESETSTAT) + .run(); + } + } + + @Override + public Status configRewrite() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.CONFIG_REWRITE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.CONFIG_REWRITE) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.CONFIG_REWRITE) + .run(); + } + } + + @Override + public Long dbSize() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.DBSIZE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.DBSIZE) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.DBSIZE) + .run(); + } + } + + @Override + public Status failover() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.FAILOVER) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.FAILOVER) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.FAILOVER) + .run(); + } + } + + @Override + public Status failover(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + return failover(args); + } + + @Override + public Status failover(final String host, final int port, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("timeout", timeout); + return failover(args); + } + + @Override + public Status failover(final String host, final int port, final boolean isForce, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("isForce", isForce) + .put("timeout", timeout); + return failover(args); + } + + @Override + public Status failover(final int timeout) { + final CommandArguments args = CommandArguments.create("timeout", timeout); + return failover(args); + } + + @Override + public Status flushAll() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.FLUSHALL) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.FLUSHALL) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.FLUSHALL) + .run(); + } + } + + @Override + public Status flushAll(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.FLUSHALL) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.FLUSHALL) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.FLUSHALL) + .run(args); + } + } + + @Override + public Status flushDb() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.FLUSHDB) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.FLUSHDB) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.FLUSHDB) + .run(); + } + } + + @Override + public Status flushDb(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.FLUSHDB) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.FLUSHDB) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.FLUSHDB) + .run(args); + } + } + + @Override + public Info info() { + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(), + infoConverter) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(), + infoConverter) + .run(); + }else{ + return new LettuceSentinelCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(), infoConverter) + .run(); + } + } + + @Override + public Info info(final Info.Section section) { + final CommandArguments args = CommandArguments.create("section", section); + final String sectionName = section.name().toLowerCase(); + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(sectionName), + infoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, Command.FLUSHDB, + (cmd)->cmd.info(sectionName), infoConverter) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(sectionName), + infoConverter) + .run(args); + } + } + + @Override + public Long lastSave() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.LASTSAVE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.LASTSAVE) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.LASTSAVE) + .run(); + } + } + + @Override + public String memoryDoctor() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.MEMORY_DOCTOR) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.MEMORY_DOCTOR) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.MEMORY_DOCTOR) + .run(); + } + } + + @Override + public Status memoryPurge() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.MEMORY_PURGE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.MEMORY_PURGE) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.MEMORY_PURGE) + .run(); + } + } + + @Override + public MemoryStats memoryStats() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.MEMORY_STATS) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.MEMORY_STATS) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.MEMORY_STATS) + .run(); + } + } + + @Override + public Long memoryUsage(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.MEMORY_USAGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.MEMORY_USAGE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.MEMORY_USAGE) + .run(args); + } + } + + @Override + public Long memoryUsage(final byte[] key, final int samples) { + final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.MEMORY_USAGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.MEMORY_USAGE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.MEMORY_USAGE) + .run(args); + } + } + + @Override + public List moduleList() { + return notCommand(client, Command.MODULE_LIST); + } + + @Override + public Status moduleLoad(final String path) { + final CommandArguments args = CommandArguments.create("path", path); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleLoad(final byte[] path) { + final CommandArguments args = CommandArguments.create("path", path); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleLoad(final String path, final String... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleLoad(final byte[] path, final byte[]... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleUnLoad(final String name) { + final CommandArguments args = CommandArguments.create("name", name); + return notCommand(client, Command.MODULE_UNLOAD, args); + } + + @Override + public Status moduleUnLoad(final byte[] name) { + final CommandArguments args = CommandArguments.create("name", name); + return notCommand(client, Command.MODULE_UNLOAD, args); + } + + @Override + public void monitor(final RedisMonitor redisMonitor) { + final CommandArguments args = CommandArguments.create("redisMonitor", redisMonitor); + + if(isPipeline()){ + new LettuceSentinelPipelineCommand<>(client, Command.MONITOR) + .run(args); + }else if(isTransaction()){ + new LettuceSentinelTransactionCommand<>(client, Command.MONITOR) + .run(args); + }else{ + new LettuceSentinelCommand<>(client, Command.MONITOR) + .run(args); + } + } + + @Override + public Object pSync(final String replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return pSync(args); + } + + @Override + public Object pSync(final byte[] replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return pSync(args); + } + + @Override + public void sync() { + if(isPipeline()){ + new LettuceSentinelPipelineCommand<>(client, Command.SYNC) + .run(); + }else if(isTransaction()){ + new LettuceSentinelTransactionCommand<>(client, Command.SYNC) + .run(); + }else{ + new LettuceSentinelCommand<>(client, Command.SYNC) + .run(); + } + } + + @Override + public Status replicaOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.REPLICAOF) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.REPLICAOF) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.REPLICAOF) + .run(args); + } + } + + @Override + public Status slaveOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.SLAVEOF) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.SLAVEOF) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.SLAVEOF) + .run(args); + } + } + + @Override + public Role role() { + final RoleConverter roleConverter = new RoleConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ROLE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ROLE) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.ROLE) + .run(); + } + } + + @Override + public Status save() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.SAVE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.SAVE) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.SAVE) + .run(); + } + } + + @Override + public void shutdown() { + if(isPipeline()){ + new LettuceSentinelPipelineCommand<>(client, Command.SHUTDOWN) + .run(); + }else if(isTransaction()){ + new LettuceSentinelTransactionCommand<>(client, Command.SHUTDOWN) + .run(); + }else{ + new LettuceSentinelCommand<>(client, Command.SHUTDOWN) + .run(); + } + } + + @Override + public void shutdown(final boolean save) { + final CommandArguments args = CommandArguments.create("save", save); + + if(isPipeline()){ + new LettuceSentinelPipelineCommand<>(client, Command.SHUTDOWN) + .run(args); + }else if(isTransaction()){ + new LettuceSentinelTransactionCommand<>(client, Command.SHUTDOWN) + .run(args); + }else{ + new LettuceSentinelCommand<>(client, Command.SHUTDOWN) + .run(args); + } + } + + @Override + public List slowLogGet() { + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.SLOWLOG_GET) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.SLOWLOG_GET) + .run(); + }else{ + return new LettuceSentinelCommand, List>(client, Command.SLOWLOG_GET) + .run(); + } + } + + @Override + public List slowLogGet(final int count) { + final CommandArguments args = CommandArguments.create("count", count); + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.SLOWLOG_GET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.SLOWLOG_GET) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.SLOWLOG_GET) + .run(args); + } + } + + @Override + public Long slowLogLen() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.SLOWLOG_LEN) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.SLOWLOG_LEN) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.SLOWLOG_LEN) + .run(); + } + } + + @Override + public Status slowLogReset() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.SLOWLOG_RESET) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.SLOWLOG_RESET) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.SLOWLOG_RESET) + .run(); + } + } + + @Override + public Status swapdb(final int db1, final int db2) { + final CommandArguments args = CommandArguments.create("db1", db1).put("db2", db2); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.SWAPDB) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.SWAPDB) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.SWAPDB) + .run(args); + } + } + + @Override + public RedisServerTime time() { + final RedisServerTimeConverter redisServerTimeConverter = new RedisServerTimeConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.TIME) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.TIME) + .run(); + }else{ + return new LettuceSentinelCommand(client, Command.TIME) + .run(); + } + } + + private AclUser aclGetUser(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ACL_GETUSER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ACL_GETUSER) + .run(args); + } + } + + private Long aclDelUser(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ACL_DELUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ACL_DELUSER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ACL_DELUSER) + .run(args); + } + } + + private Map configGet(final String pattern, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Map>(client, Command.CONFIG_GET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Map>(client, Command.CONFIG_GET) + .run(args); + }else{ + return new LettuceSentinelCommand, Map>(client, Command.CONFIG_GET) + .run(args); + } + } + + private Status failover(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.FAILOVER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.FAILOVER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.FAILOVER) + .run(args); + } + } + + private Status moduleLoad(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.MODULE_LOAD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.MODULE_LOAD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.MODULE_LOAD) + .run(args); + } + } + + private Status moduleUnLoad(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.MODULE_UNLOAD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.MODULE_UNLOAD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.MODULE_UNLOAD) + .run(args); + } + } + + private Object pSync(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, Command.PSYNC) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, Command.PSYNC) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, Command.PSYNC) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelSetOperations.java new file mode 100644 index 000000000..20e0f61d3 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelSetOperations.java @@ -0,0 +1,564 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.SetConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.ValueScanCursor; + +import java.util.List; +import java.util.Set; + +/** + * Lettuce 哨兵模式集合命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelSetOperations extends AbstractSetOperations { + + public LettuceSentinelSetOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Long sAdd(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.SADD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.SADD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.SADD) + .run(args); + } + } + + @Override + public Long sCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.SCARD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.SCARD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.SCARD) + .run(args); + } + } + + @Override + public Set sDiff(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sDiff(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return sDiff(keys, (v)->v, args); + } + + @Override + public Long sDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.SDIFFSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.SDIFFSTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.SDIFFSTORE) + .run(args); + } + } + + @Override + public Set sInter(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sInter(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return sInter(keys, (v)->v, args); + } + + @Override + public Long sInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.SINTERSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.SINTERSTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.SINTERSTORE) + .run(args); + } + } + + @Override + public Boolean sIsMember(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.SISMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.SISMEMBER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.SISMEMBER) + .run(args); + } + } + + @Override + public List smIsMember(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return smIsMember(args); + } + + @Override + public List smIsMember(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return smIsMember(args); + } + + @Override + public Set sMembers(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sMembers(bKey, binaryToStringSetConverter, args); + } + + @Override + public Set sMembers(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return sMembers(key, (v)->v, args); + } + + @Override + public Status sMove(final byte[] key, final byte[] destKey, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.SMOVE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.SMOVE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.SMOVE) + .run(args); + } + } + + @Override + public String sPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return sPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] sPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return sPop(key, (v)->v, args); + } + + @Override + public Set sPop(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sPop(bKey, count, binaryToStringSetConverter, args); + } + + @Override + public Set sPop(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return sPop(key, count, (v)->v, args); + } + + @Override + public String sRandMember(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return sRandMember(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] sRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return sRandMember(key, (v)->v, args); + } + + @Override + public List sRandMember(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return sRandMember(bKey, count, listConverter, args); + } + + @Override + public List sRandMember(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return sRandMember(key, count, (v)->v, args); + } + + @Override + public Long sRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.SREM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.SREM) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.SREM) + .run(args); + } + } + + @Override + public ScanResult> sScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(pattern); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(pattern); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, scanArgs, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, scanArgs, valueScanCursorConverter, args); + } + + @Override + public Set sUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sUnion(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return sUnion(keys, (v)->v, args); + } + + @Override + public Long sUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.SUNIONSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.SUNIONSTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.SUNIONSTORE) + .run(args); + } + } + + private Set sDiff(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Set>(client, Command.SDIFF) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Set>(client, Command.SDIFF) + .run(args); + }else{ + return new LettuceSentinelCommand, Set>(client, Command.SDIFF) + .run(args); + } + } + + private Set sInter(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Set>(client, Command.SINTER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Set>(client, Command.SINTER) + .run(args); + }else{ + return new LettuceSentinelCommand, Set>(client, Command.SINTER) + .run(args); + } + } + + private List smIsMember(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.SMISMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.SMISMEMBER) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.SMISMEMBER) + .run(args); + } + } + + private Set sMembers(final byte[] key, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Set>(client, Command.SMEMBERS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Set>(client, Command.SMEMBERS) + .run(args); + }else{ + return new LettuceSentinelCommand, Set>(client, Command.SMEMBERS) + .run(args); + } + } + + private V sPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.SPOP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.SPOP) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.SPOP) + .run(args); + } + } + + private Set sPop(final byte[] key, final int count, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Set>(client, Command.SPOP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Set>(client, Command.SPOP) + .run(args); + }else{ + return new LettuceSentinelCommand, Set>(client, Command.SPOP) + .run(args); + } + } + + private V sRandMember(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.SPOP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.SPOP) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.SPOP) + .run(args); + } + } + + private List sRandMember(final byte[] key, final int count, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.SRANDMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.SRANDMEMBER) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.SRANDMEMBER) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>, ScanResult>>(client, + Command.SSCAN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>, ScanResult>>(client, + Command.SSCAN) + .run(args); + }else{ + return new LettuceSentinelCommand>, ScanResult>>(client, Command.SSCAN) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>, ScanResult>>(client, + Command.SSCAN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>, ScanResult>>(client, + Command.SSCAN) + .run(args); + }else{ + return new LettuceSentinelCommand>, ScanResult>>(client, + Command.SSCAN) + .run(args); + } + } + + private Set sUnion(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Set>(client, Command.SUNION) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Set>(client, Command.SUNION) + .run(args); + }else{ + return new LettuceSentinelCommand, Set>(client, Command.SUNION) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelSortedSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelSortedSetOperations.java new file mode 100644 index 000000000..9790c3447 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelSortedSetOperations.java @@ -0,0 +1,1469 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.NumberUtils; +import com.buession.lang.KeyValue; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.Aggregate; +import com.buession.redis.core.GtLt; +import com.buession.redis.core.NxXx; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; +import com.buession.redis.core.ZRangeBy; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.Range; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 哨兵模式模式有序集合命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelSortedSetOperations extends AbstractSortedSetOperations { + + public LettuceSentinelSortedSetOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Tuple zPopMin(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZPOPMIN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZPOPMIN) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZPOPMIN) + .run(args); + } + } + + @Override + public List zPopMin(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZPOPMIN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.ZPOPMIN) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZPOPMIN) + .run(args); + } + } + + @Override + public Tuple zPopMax(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZPOPMAX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZPOPMAX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZPOPMAX) + .run(args); + } + } + + @Override + public List zPopMax(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZPOPMAX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.ZPOPMAX) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZPOPMAX) + .run(args); + } + } + + @Override + public KeyValue bzPopMin(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, KeyValue>( + client, Command.BZPOPMIN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, KeyValue>( + client, Command.BZPOPMIN) + .run(args); + }else{ + return new LettuceSentinelCommand, KeyValue>( + client, Command.BZPOPMIN) + .run(args); + } + } + + @Override + public KeyValue bzPopMin(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, KeyValue>( + client, Command.BZPOPMIN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, KeyValue>( + client, Command.BZPOPMIN) + .run(args); + }else{ + return new LettuceSentinelCommand, KeyValue>( + client, Command.BZPOPMIN) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, KeyValue>( + client, Command.BZPOPMAX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, KeyValue>( + client, Command.BZPOPMAX) + .run(args); + }else{ + return new LettuceSentinelCommand, KeyValue>( + client, Command.BZPOPMAX) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, KeyValue>( + client, Command.BZPOPMAX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, KeyValue>( + client, Command.BZPOPMAX) + .run(args); + }else{ + return new LettuceSentinelCommand, KeyValue>( + client, Command.BZPOPMAX) + .run(args); + } + } + + @Override + public Long zAdd(final String key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + return zAdd(args); + } + + @Override + public Long zAdd(final byte[] key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + return zAdd(args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + return zAdd(args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + return zAdd(args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + return zAdd(args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + return zAdd(args); + } + + @Override + public Long zAdd(final String key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + return zAdd(args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + return zAdd(args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + return zAdd(args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + return zAdd(args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + return zAdd(args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + return zAdd(args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + return zAdd(args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + return zAdd(args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + return zAdd(args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + return zAdd(args); + } + + @Override + public Long zCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZCARD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZCARD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZCARD) + .run(args); + } + } + + @Override + public Long zCount(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZCOUNT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZCOUNT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZCOUNT) + .run(args); + } + } + + @Override + public List zDiff(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public List zDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public List zDiffWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public List zDiffWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public Long zDiffStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + return zDiffStore(args); + } + + @Override + public Long zDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + return zDiffStore(args); + } + + @Override + public Double zIncrBy(final byte[] key, final double increment, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) + .put("member", member); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZINCRBY) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZINCRBY) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZINCRBY) + .run(args); + } + } + + @Override + public List zInter(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZINTERSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZINTERSTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZINTERSTORE) + .run(args); + } + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + return zInterStore(args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + return zInterStore(args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + return zInterStore(args); + } + + @Override + public List zMScore(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return zMScore(args); + } + + @Override + public List zMScore(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return zMScore(args); + } + + @Override + public String zRandMember(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + return zRandMember(args); + } + + @Override + public byte[] zRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return zRandMember(args); + } + + @Override + public List zRandMember(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMember(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMemberWithScores(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMemberWithScores(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return zRange(args); + } + + @Override + public List zRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return zRange(args); + } + + @Override + public List zRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.ZRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZRANGE) + .run(args); + } + } + + @Override + public List zRangeByLex(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRangeByLex(args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRangeByLex(args); + } + + @Override + public List zRangeByLex(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRangeByLex(args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRangeByLex(args); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRangeByScore(args); + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRangeByScore(args); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRangeByScore(args); + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRangeByScore(args); + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.ZRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZRANGEBYSCORE) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.ZRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZRANGEBYSCORE) + .run(args); + } + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZRANK) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZRANK) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZRANK) + .run(args); + } + } + + @Override + public Long zRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZREM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZREM) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZREM) + .run(args); + } + } + + @Override + public Long zRemRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZREMRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZREMRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZREMRANGEBYSCORE) + .run(args); + } + } + + @Override + public Long zRemRangeByRank(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZREMRANGEBYRANK) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZREMRANGEBYRANK) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZREMRANGEBYRANK) + .run(args); + } + } + + @Override + public List zRevRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return null;//zRevRange(bKey, start, end, listConverter, args); + } + + @Override + public List zRevRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return null;//zRevRange(key, start, end, (v)->v, args); + } + + @Override + public List zRevRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZREVRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.ZREVRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZREVRANGE) + .run(args); + } + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + final ListConverter listConverter = Converters.listBinaryToString(); + + return null;//zRevRangeByLex(bKey, bMin, bMax, listConverter, args); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return null;//zRevRangeByLex(key, bMin, bMax, (v)->v, args); + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + final ListConverter listConverter = Converters.listBinaryToString(); + + return null;//zRevRangeByLex(bKey, bMin, bMax, offset, count, listConverter, args); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return null;//zRevRangeByLex(key, bMin, bMax, offset, count, (v)->v, args); + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return null;//zRevRangeByScore(bKey, min, max, listConverter, args); + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return null;//zRevRangeByScore(key, min, max, (v)->v, args); + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return null;//zRevRangeByScore(bKey, min, max, offset, count, listConverter, args); + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return null;//zRevRangeByScore(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + Command.ZREVRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.ZREVRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZREVRANGEBYSCORE) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + Command.ZREVRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.ZREVRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZREVRANGEBYSCORE) + .run(args); + } + } + + @Override + public Long zRevRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZREVRANK) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZREVRANK) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZREVRANK) + .run(args); + } + } + + @Override + public ScanResult> zScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + return zScan(args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + return zScan(args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + return zScan(args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + return zScan(args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + return zScan(args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + return zScan(args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + return zScan(args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + return zScan(args); + } + + @Override + public Double zScore(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZSCORE) + .run(args); + } + } + + @Override + public List zUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + return zUnionStore(args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + return zUnionStore(args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + return zUnionStore(args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + return zUnionStore(args); + } + + private Long zAdd(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZADD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZADD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZADD) + .run(args); + } + } + + private List zDiff(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZDIFF) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.ZDIFF) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZDIFF) + .run(args); + } + } + + private Long zDiffStore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZDIFFSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZDIFFSTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZDIFFSTORE) + .run(args); + } + } + + private List zInter(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZINTER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.ZINTER) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZINTER) + .run(args); + } + } + + private Long zInterStore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZINTERSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZINTERSTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZINTERSTORE) + .run(args); + } + } + + private List zMScore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZMSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.ZMSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZMSCORE) + .run(args); + } + } + + private V zRandMember(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZRANDMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZRANDMEMBER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZRANDMEMBER) + .run(args); + } + } + + private List zRange(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.ZRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZRANGE) + .run(args); + } + } + + private List zRangeByLex(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZRANGEBYLEX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.ZRANGEBYLEX) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZRANGEBYLEX) + .run(args); + } + } + + private List zRangeByScore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.ZRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZRANGEBYSCORE) + .run(args); + } + } + + private Long zRangeStore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZRANGESTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZRANGESTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZRANGESTORE) + .run(args); + } + } + + private List zRevRange(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZREVRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.ZREVRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZREVRANGE) + .run(args); + } + } + + private List zRevRangeByLex(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZREVRANGEBYLEX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.ZREVRANGEBYLEX) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZREVRANGEBYLEX) + .run(args); + } + } + + private List zRevRangeByScore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZREVRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.ZREVRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZREVRANGEBYSCORE) + .run(args); + } + } + + private ScanResult> zScan(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>, ScanResult>>(client, + Command.ZREVRANK) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>, ScanResult>>(client, + Command.ZREVRANK) + .run(args); + }else{ + return new LettuceSentinelCommand>, ScanResult>>(client, + Command.ZREVRANK) + .run(args); + } + } + + private List zUnion(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, Command.ZUNION) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, Command.ZUNION) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.ZUNION) + .run(args); + } + } + + private Long zUnionStore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.ZUNIONSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.ZUNIONSTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.ZUNIONSTORE) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelStreamOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelStreamOperations.java new file mode 100644 index 000000000..f01bfa172 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelStreamOperations.java @@ -0,0 +1,1017 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.Stream; +import com.buession.redis.core.StreamConsumer; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import com.buession.redis.core.StreamGroup; +import com.buession.redis.core.StreamPending; +import com.buession.redis.core.StreamPendingSummary; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.ApproximateExactTrimming; +import com.buession.redis.core.command.args.XAddArgument; +import com.buession.redis.core.command.args.XClaimArgument; +import com.buession.redis.core.command.args.XReadArgument; +import com.buession.redis.core.command.args.XReadGroupArgument; +import com.buession.redis.core.command.args.XTrimArgument; +import com.buession.redis.core.internal.convert.lettuce.params.StreamEntryIdConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamMessageConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamMessageMapConverter; +import com.buession.redis.core.internal.lettuce.LettuceXClaimArgs; +import com.buession.redis.core.internal.lettuce.LettuceXReadArgs; +import com.buession.redis.core.internal.lettuce.LettuceXReadGroupArgs; +import com.buession.redis.core.internal.lettuce.utils.StreamOffsetUtils; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.Consumer; +import io.lettuce.core.Limit; +import io.lettuce.core.Range; +import io.lettuce.core.StreamMessage; +import io.lettuce.core.XClaimArgs; +import io.lettuce.core.XReadArgs; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 哨兵模式 Stream 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelStreamOperations extends AbstractStreamOperations { + + public LettuceSentinelStreamOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Long xAck(final String key, final String groupName, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("ids", (Object[]) ids); + return notCommand(client, Command.XACK, args); + } + + @Override + public Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("ids", (Object[]) ids); + return notCommand(client, Command.XACK, args); + } + + @Override + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash); + return notCommand(client, Command.XADD, args); + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash); + return notCommand(client, Command.XADD, args); + } + + @Override + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) + .put("xAddArgument", xAddArgument); + return notCommand(client, Command.XADD, args); + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) + .put("xAddArgument", xAddArgument); + return notCommand(client, Command.XADD, args); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count"); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count"); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaimJustId(args); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = new LettuceXClaimArgs(minIdleTime); + + return xClaim(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = LettuceXClaimArgs.from(xClaimArgument).minIdleTime(minIdleTime); + + return xClaim(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = null;//new LettuceXClaimArgs(minIdleTime, true); + + return xClaimJustId(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = LettuceXClaimArgs.from(xClaimArgument).minIdleTime(minIdleTime).justid(); + + return xClaimJustId(key, ids, consumer, xClaimArgs, args); + } + + @Override + public Long xDel(final byte[] key, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("ids", (Object[]) ids); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.XDEL) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.XDEL) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.XDEL) + .run(args); + } + } + + @Override + public Status xGroupCreate(final byte[] key, final byte[] groupName, final StreamEntryId id, + final boolean makeStream) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("id", id); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.XGROUP_CREATE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.XGROUP_CREATE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.XGROUP_CREATE) + .run(args); + } + } + + @Override + public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + return xGroupCreateConsumer(args); + } + + @Override + public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + return xGroupCreateConsumer(args); + } + + @Override + public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Converter converter = (v)->v ? 1L : 0L; + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.XGROUP_DELCONSUMER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.XGROUP_DELCONSUMER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.XGROUP_DELCONSUMER) + .run(args); + } + } + + @Override + public Status xGroupDestroy(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.XGROUP_DESTROY) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.XGROUP_DESTROY) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.XGROUP_DESTROY) + .run(args); + } + } + + @Override + public Status xGroupSetId(final byte[] key, final byte[] groupName, final StreamEntryId id) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName).put("id", id); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.XGROUP_SETID) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.XGROUP_SETID) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.XGROUP_SETID) + .run(args); + } + } + + @Override + public List xInfoConsumers(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + Command.XINFO_CONSUMERS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.XINFO_CONSUMERS) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + Command.XINFO_CONSUMERS) + .run(args); + } + } + + @Override + public List xInfoGroups(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + Command.XINFO_GROUPS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.XINFO_GROUPS) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + Command.XINFO_GROUPS) + .run(args); + } + } + + @Override + public Stream xInfoStream(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.XINFO_STREAM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.XINFO_STREAM) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.XINFO_STREAM) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.XINFO_STREAM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.XINFO_STREAM) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.XINFO_STREAM) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full).put("count", count); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.XINFO_STREAM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.XINFO_STREAM) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.XINFO_STREAM) + .run(args); + } + } + + @Override + public Long xLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.XLEN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.XLEN) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.XLEN) + .run(args); + } + } + + @Override + public StreamPendingSummary xPending(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, + Command.XPENDING) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, + Command.XPENDING) + .run(args); + }else{ + return new LettuceSentinelCommand(client, + Command.XPENDING) + .run(args); + } + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + Command.XPENDING) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.XPENDING) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + Command.XPENDING) + .run(args); + } + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("start", start).put("end", end).put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, groupName, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.unbounded(); + final Limit limit = Limit.unlimited(); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("start", start).put("end", end).put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, groupName, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.unbounded(); + final Limit limit = Limit.unlimited(); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final int count, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count, + final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + Command.XRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.XRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.XRANGE) + .run(args); + } + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + Command.XRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.XRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.XRANGE) + .run(args); + } + } + + @Override + public List>> xRead(final Map streams) { + final CommandArguments args = CommandArguments.create("streams", streams); + return xRead(streams, args); + } + + @Override + public List>> xRead(final Map streams, + final XReadArgument xReadArgument) { + final CommandArguments args = CommandArguments.create("streams", streams).put("xReadArgument", xReadArgument); + final XReadArgs xReadArgs = LettuceXReadArgs.from(xReadArgument); + + return xRead(xReadArgs, streams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams); + return xReadGroup(groupName, consumerName, streams, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams); + return xReadGroup(groupName, consumerName, streams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadArgs xReadArgs = LettuceXReadGroupArgs.from(xReadGroupArgument); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadArgs xReadArgs = LettuceXReadGroupArgs.from(xReadGroupArgument); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = (new LettuceXReadArgs()).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = (new LettuceXReadArgs()).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadArgs xReadArgs = LettuceXReadGroupArgs.from(xReadGroupArgument).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final boolean isNoAck, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadArgs xReadArgs = LettuceXReadGroupArgs.from(xReadGroupArgument).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start); + final Range range = Range.create(start.toString(), end.toString()); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + Command.XREVRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.XREVRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.XREVRANGE) + .run(args); + } + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start) + .put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + Command.XREVRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.XREVRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.XREVRANGE) + .run(args); + } + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); + return xTrim(key, xTrimArgument.getApproximateExactTrimming(), Long.MAX_VALUE, args); + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) + .put("limit", limit); + return xTrim(key, xTrimArgument.getApproximateExactTrimming(), limit, args); + } + + private Map> xAutoClaim(final CommandArguments args) { + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>, Map>>( + client, Command.XAUTOCLAIM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>, Map>>( + client, Command.XAUTOCLAIM) + .run(args); + }else{ + return new LettuceSentinelCommand>, Map>>( + client, Command.XAUTOCLAIM) + .run(args); + } + } + + private Map> xAutoClaimJustId(final CommandArguments args) { + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>, Map>>( + client, Command.XAUTOCLAIM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>, Map>>( + client, Command.XAUTOCLAIM) + .run(args); + }else{ + return new LettuceSentinelCommand>, Map>>( + client, Command.XAUTOCLAIM) + .run(args); + } + } + + private List xClaim(final byte[] key, final StreamEntryId[] ids, final Consumer consumer, + final XClaimArgs xClaimArgs, final CommandArguments args) { + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + Command.XCLAIM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.XCLAIM) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, Command.XCLAIM) + .run(args); + } + } + + private List xClaimJustId(final byte[] key, final StreamEntryId[] ids, + final Consumer consumer, final XClaimArgs xClaimArgs, + final CommandArguments args) { + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter, StreamEntryId> listStreamMessageStreamEntryIdConverter + = StreamMessageConverter.StreamMessageStreamEntryIdConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + Command.XCLAIM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.XCLAIM) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + Command.XCLAIM) + .run(args); + } + } + + private Status xGroupCreateConsumer(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.XGROUP_CREATECONSUMER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.XGROUP_CREATECONSUMER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.XGROUP_CREATECONSUMER) + .run(args); + } + } + + private List xPending(final byte[] key, final byte[] groupName, Range range, + final Limit limit, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + Command.XPENDING) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.XPENDING) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + Command.XPENDING) + .run(args); + } + } + + private List xPending(final byte[] key, final Consumer consumer, Range range, + final Limit limit, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + Command.XPENDING) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + Command.XPENDING) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + Command.XPENDING) + .run(args); + } + } + + private List>> xRead(final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromStringMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>>, List>>>( + client, Command.XREAD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>>, List>>>( + client, Command.XREAD) + .run(args); + }else{ + return new LettuceSentinelCommand>>, List>>>( + client, Command.XREAD) + .run(args); + } + } + + private List>> xRead(final XReadArgs xReadArgs, final Map streams, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromStringMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>>, List>>>( + client, Command.XREAD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>>, List>>>( + client, Command.XREAD) + .run(args); + }else{ + return new LettuceSentinelCommand>>, List>>>( + client, Command.XREAD) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromStringMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), streamOffsets, + listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromBinaryMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(groupName, consumerName, streamOffsets, listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final XReadArgs.StreamOffset[] streamOffsets, + final Converter>, + List>>> converter, + final CommandArguments args) { + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>>, List>>>( + client, Command.XREADGROUP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>>, List>>>( + client, Command.XREADGROUP) + .run(args); + }else{ + return new LettuceSentinelCommand>>, List>>>( + client, Command.XREADGROUP) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadArgs xReadArgs, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromStringMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), streamOffsets, xReadArgs, + listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final XReadArgs xReadArgs, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromBinaryMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(groupName, consumerName, streamOffsets, xReadArgs, listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final XReadArgs.StreamOffset[] streamOffsets, + final XReadArgs xReadArgs, + final Converter>, + List>>> converter, + final CommandArguments args) { + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>>, List>>>( + client, Command.XREADGROUP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>>, List>>>( + client, Command.XREADGROUP) + .run(args); + }else{ + return new LettuceSentinelCommand>>, List>>>( + client, Command.XREADGROUP) + .run(args); + } + } + + private Long xTrim(final byte[] key, final ApproximateExactTrimming approximateExactTrimming, final long limit, + final CommandArguments args) { + final boolean approximateTrimming = ApproximateExactTrimming.APPROXIMATE == approximateExactTrimming; + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, Command.XTRIM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, Command.XTRIM) + .run(args); + }else{ + return new LettuceSentinelCommand(client, Command.XTRIM) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelStringOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelStringOperations.java new file mode 100644 index 000000000..991a5312b --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelStringOperations.java @@ -0,0 +1,295 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.GetExArgument; +import com.buession.redis.core.command.args.SetArgument; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 哨兵模式字符串命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelStringOperations extends AbstractStringOperations { + + public LettuceSentinelStringOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Long append(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return notCommand(client, Command.APPEND, args); + } + + @Override + public Long append(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return notCommand(client, Command.APPEND, args); + } + + @Override + public Long incr(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + return notCommand(client, Command.INCR, args); + } + + @Override + public Long incr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return notCommand(client, Command.INCR, args); + } + + @Override + public Long incrBy(final String key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return notCommand(client, Command.INCRBY, args); + } + + @Override + public Long incrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return notCommand(client, Command.INCRBY, args); + } + + @Override + public Double incrByFloat(final byte[] key, final double value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return notCommand(client, Command.INCRBYFLOAT, args); + } + + @Override + public Long decr(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + return notCommand(client, Command.DECR, args); + } + + @Override + public Long decr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return notCommand(client, Command.DECR, args); + } + + @Override + public Long decrBy(final String key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return notCommand(client, Command.DECRBY, args); + } + + @Override + public Long decrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return notCommand(client, Command.DECRBY, args); + } + + @Override + public String get(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + return notCommand(client, Command.GET, args); + } + + @Override + public byte[] get(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return notCommand(client, Command.GET, args); + } + + @Override + public String getEx(final String key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + return notCommand(client, Command.GETEX, args); + } + + @Override + public byte[] getEx(final byte[] key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + return notCommand(client, Command.GETEX, args); + } + + @Override + public String getSet(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return notCommand(client, Command.GETSET, args); + } + + @Override + public byte[] getSet(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return notCommand(client, Command.GETSET, args); + } + + @Override + public String getDel(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + return notCommand(client, Command.GETDEL, args); + } + + @Override + public byte[] getDel(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return notCommand(client, Command.GETDEL, args); + } + + @Override + public List mGet(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return notCommand(client, Command.MGET, args); + } + + @Override + public List mGet(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return notCommand(client, Command.MGET, args); + } + + @Override + public Status mSet(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + return notCommand(client, Command.MSET, args); + } + + @Override + public Status mSetNx(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + return notCommand(client, Command.MSET, args); + } + + @Override + public Status pSetEx(final String key, final String value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + return notCommand(client, Command.PSETEX, args); + } + + @Override + public Status pSetEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + return notCommand(client, Command.PSETEX, args); + } + + @Override + public Status set(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return notCommand(client, Command.SET, args); + } + + @Override + public Status set(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return notCommand(client, Command.SET, args); + } + + @Override + public Status set(final String key, final String value, final SetArgument setArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return notCommand(client, Command.SET, args); + } + + @Override + public Status set(final byte[] key, final byte[] value, final SetArgument setArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return notCommand(client, Command.SET, args); + } + + @Override + public Status setEx(final String key, final String value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + return notCommand(client, Command.SETEX, args); + } + + @Override + public Status setEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + return notCommand(client, Command.SETEX, args); + } + + @Override + public Status setNx(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return notCommand(client, Command.SETNX, args); + } + + @Override + public Status setNx(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return notCommand(client, Command.SETNX, args); + } + + @Override + public Long setRange(final String key, final long offset, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + return notCommand(client, Command.SETRANGE, args); + } + + @Override + public Long setRange(final byte[] key, final long offset, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + return notCommand(client, Command.SETRANGE, args); + } + + @Override + public String getRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return notCommand(client, Command.GETRANGE, args); + } + + @Override + public byte[] getRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return notCommand(client, Command.GETRANGE, args); + } + + @Override + public Long strlen(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + return notCommand(client, Command.STRLEN, args); + } + + @Override + public Long strlen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return notCommand(client, Command.STRLEN, args); + } + + @Override + public String substr(final String key, final int start, final int end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return notCommand(client, Command.SUBSTR, args); + } + + @Override + public byte[] substr(final byte[] key, final int start, final int end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return notCommand(client, Command.SUBSTR, args); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelTransactionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelTransactionOperations.java new file mode 100644 index 000000000..f90f7b4ba --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSentinelTransactionOperations.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; + +import java.util.List; + +/** + * Lettuce 哨兵模式事务命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelTransactionOperations extends AbstractTransactionOperations { + + public LettuceSentinelTransactionOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Status multi() { + return notCommand(client, Command.MULTI); + } + + @Override + public List exec() { + return notCommand(client, Command.EXEC); + } + + @Override + public void discard() { + notCommand(client, Command.DISCARD); + } + + @Override + public Status watch(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return notCommand(client, Command.WATCH, args); + } + + @Override + public Status watch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return notCommand(client, Command.WATCH, args); + } + + @Override + public Status unwatch() { + return notCommand(client, Command.UNWATCH); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceServerOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceServerOperations.java new file mode 100644 index 000000000..006a9fc68 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceServerOperations.java @@ -0,0 +1,811 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.Info; +import com.buession.redis.core.MemoryStats; +import com.buession.redis.core.Module; +import com.buession.redis.core.RedisMonitor; +import com.buession.redis.core.RedisServerTime; +import com.buession.redis.core.Role; +import com.buession.redis.core.SlowLog; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.RedisServerTimeConverter; +import com.buession.redis.core.internal.convert.lettuce.response.RoleConverter; +import com.buession.redis.core.internal.convert.lettuce.response.SlowlogConverter; +import com.buession.redis.core.internal.convert.response.InfoConverter; +import com.buession.redis.utils.SafeEncoder; + +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * Lettuce 单机模式服务端命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceServerOperations extends AbstractServerOperations { + + public LettuceServerOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public String bgRewriteAof() { + if(isPipeline()){ + return new LettucePipelineCommand(client, Command.BGREWRITEAOF) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, Command.BGREWRITEAOF) + .run(); + }else{ + return new LettuceCommand(client, Command.BGREWRITEAOF) + .run(); + } + } + + @Override + public String bgSave() { + if(isPipeline()){ + return new LettucePipelineCommand(client, Command.BGSAVE) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, Command.BGSAVE) + .run(); + }else{ + return new LettuceCommand(client, Command.BGSAVE) + .run(); + } + } + + @Override + public Status configSet(final String parameter, final String value) { + final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CONFIG_SET, + (cmd)->cmd.configSet(parameter, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CONFIG_SET, + (cmd)->cmd.configSet(parameter, value), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CONFIG_SET, (cmd)->cmd.configSet(parameter, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status configSet(final Map configs) { + final CommandArguments args = CommandArguments.create("configs", configs); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CONFIG_SET, + (cmd)->cmd.configSet(configs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CONFIG_SET, + (cmd)->cmd.configSet(configs), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CONFIG_SET, (cmd)->cmd.configSet(configs), + okStatusConverter) + .run(args); + } + } + + @Override + public Map configGet(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CONFIG_GET, + (cmd)->cmd.configGet(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CONFIG_GET, + (cmd)->cmd.configGet(pattern), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CONFIG_GET, (cmd)->cmd.configGet(pattern), (v)->v) + .run(args); + } + } + + @Override + public Map configGet(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final String sPattern = SafeEncoder.encode(pattern); + final MapConverter converter = Converters.mapStringToBinary(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CONFIG_GET, (cmd)->cmd.configGet(sPattern), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CONFIG_GET, (cmd)->cmd.configGet(sPattern), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.CONFIG_GET, (cmd)->cmd.configGet(sPattern), + converter) + .run(args); + } + } + + @Override + public Status configResetStat() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CONFIG_RESETSTAT, (cmd)->cmd.configResetstat(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CONFIG_RESETSTAT, + (cmd)->cmd.configResetstat(), okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.CONFIG_RESETSTAT, (cmd)->cmd.configResetstat(), + okStatusConverter) + .run(); + } + } + + @Override + public Status configRewrite() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.CONFIG_REWRITE, (cmd)->cmd.configRewrite(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.CONFIG_REWRITE, (cmd)->cmd.configRewrite(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.CONFIG_REWRITE, (cmd)->cmd.configRewrite(), + okStatusConverter) + .run(); + } + } + + @Override + public Long dbSize() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.DBSIZE, (cmd)->cmd.dbsize(), (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.DBSIZE, (cmd)->cmd.dbsize(), (v)->v) + .run(); + }else{ + return new LettuceCommand<>(client, Command.DBSIZE, (cmd)->cmd.dbsize(), (v)->v) + .run(); + } + } + + @Override + public Status failover() { + if(isPipeline()){ + return new LettucePipelineCommand(client, Command.FAILOVER) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, Command.FAILOVER) + .run(); + }else{ + return new LettuceCommand(client, Command.FAILOVER) + .run(); + } + } + + @Override + public Status failover(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + return failover(args); + } + + @Override + public Status failover(final String host, final int port, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("timeout", timeout); + return failover(args); + } + + @Override + public Status failover(final String host, final int port, final boolean isForce, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("isForce", isForce) + .put("timeout", timeout); + return failover(args); + } + + @Override + public Status failover(final int timeout) { + final CommandArguments args = CommandArguments.create("timeout", timeout); + return failover(args); + } + + @Override + public Status flushAll() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.FLUSHALL, (cmd)->cmd.flushall(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.FLUSHALL, (cmd)->cmd.flushall(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.FLUSHALL, (cmd)->cmd.flushall(), okStatusConverter) + .run(); + } + } + + @Override + public Status flushAll(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.FLUSHALL, + (cmd)->mode == FlushMode.ASYNC ? cmd.flushallAsync() : cmd.flushall(), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.FLUSHALL, + (cmd)->mode == FlushMode.ASYNC ? cmd.flushallAsync() : cmd.flushall(), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.FLUSHALL, + (cmd)->mode == FlushMode.ASYNC ? cmd.flushallAsync() : cmd.flushall(), okStatusConverter) + .run(args); + } + } + + @Override + public Status flushDb() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.FLUSHDB, (cmd)->cmd.flushdb(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.FLUSHDB, (cmd)->cmd.flushdb(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.FLUSHDB, (cmd)->cmd.flushdb(), okStatusConverter) + .run(); + } + } + + @Override + public Status flushDb(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.FLUSHDB, (cmd)->mode == FlushMode.ASYNC ? + cmd.flushdbAsync() : cmd.flushdb(), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.FLUSHDB, (cmd)->mode == FlushMode.ASYNC ? + cmd.flushdbAsync() : cmd.flushdb(), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.FLUSHDB, (cmd)->mode == FlushMode.ASYNC ? + cmd.flushdbAsync() : cmd.flushdb(), okStatusConverter) + .run(args); + } + } + + @Override + public Info info() { + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(), infoConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(), infoConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(), infoConverter) + .run(); + } + } + + @Override + public Info info(final Info.Section section) { + final CommandArguments args = CommandArguments.create("section", section); + final String sectionName = section.name().toLowerCase(); + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(sectionName), + infoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(sectionName), + infoConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.FLUSHDB, (cmd)->cmd.info(sectionName), infoConverter) + .run(args); + } + } + + @Override + public Long lastSave() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.LASTSAVE, (cmd)->cmd.lastsave(), Date::getTime) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.LASTSAVE, (cmd)->cmd.lastsave(), + Date::getTime) + .run(); + }else{ + return new LettuceCommand<>(client, Command.LASTSAVE, (cmd)->cmd.lastsave(), Date::getTime) + .run(); + } + } + + @Override + public String memoryDoctor() { + if(isPipeline()){ + return new LettucePipelineCommand(client, Command.MEMORY_DOCTOR) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, Command.MEMORY_DOCTOR) + .run(); + }else{ + return new LettuceCommand(client, Command.MEMORY_DOCTOR) + .run(); + } + } + + @Override + public Status memoryPurge() { + if(isPipeline()){ + return new LettucePipelineCommand(client, Command.MEMORY_PURGE) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, Command.MEMORY_PURGE) + .run(); + }else{ + return new LettuceCommand(client, Command.MEMORY_PURGE) + .run(); + } + } + + @Override + public MemoryStats memoryStats() { + if(isPipeline()){ + return new LettucePipelineCommand(client, Command.MEMORY_STATS) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, Command.MEMORY_STATS) + .run(); + }else{ + return new LettuceCommand(client, Command.MEMORY_STATS) + .run(); + } + } + + @Override + public Long memoryUsage(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } + } + + @Override + public Long memoryUsage(final byte[] key, final int samples) { + final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } + } + + @Override + public List moduleList() { + return notCommand(client, Command.MODULE_LIST); + } + + @Override + public Status moduleLoad(final String path) { + final CommandArguments args = CommandArguments.create("path", path); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleLoad(final byte[] path) { + final CommandArguments args = CommandArguments.create("path", path); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleLoad(final String path, final String... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleLoad(final byte[] path, final byte[]... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + return notCommand(client, Command.MODULE_LOAD, args); + } + + @Override + public Status moduleUnLoad(final String name) { + final CommandArguments args = CommandArguments.create("name", name); + return notCommand(client, Command.MODULE_UNLOAD, args); + } + + @Override + public Status moduleUnLoad(final byte[] name) { + final CommandArguments args = CommandArguments.create("name", name); + return notCommand(client, Command.MODULE_UNLOAD, args); + } + + @Override + public void monitor(final RedisMonitor redisMonitor) { + final CommandArguments args = CommandArguments.create("redisMonitor", redisMonitor); + + if(isPipeline()){ + new LettucePipelineCommand<>(client, Command.MONITOR) + .run(args); + }else if(isTransaction()){ + new LettuceTransactionCommand<>(client, Command.MONITOR) + .run(args); + }else{ + new LettuceCommand<>(client, Command.MONITOR) + .run(args); + } + } + + @Override + public Object pSync(final String replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return pSync(args); + } + + @Override + public Object pSync(final byte[] replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return pSync(args); + } + + @Override + public void sync() { + if(isPipeline()){ + new LettucePipelineCommand<>(client, Command.SYNC) + .run(); + }else if(isTransaction()){ + new LettuceTransactionCommand<>(client, Command.SYNC) + .run(); + }else{ + new LettuceCommand<>(client, Command.SYNC) + .run(); + } + } + + @Override + public Status replicaOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new LettucePipelineCommand(client, Command.REPLICAOF) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, Command.REPLICAOF) + .run(args); + }else{ + return new LettuceCommand(client, Command.REPLICAOF) + .run(args); + } + } + + @Override + public Status slaveOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SLAVEOF, (cmd)->cmd.slaveof(host, port), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SLAVEOF, (cmd)->cmd.slaveof(host, port), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SLAVEOF, (cmd)->cmd.slaveof(host, port), + okStatusConverter) + .run(args); + } + } + + @Override + public Role role() { + final RoleConverter roleConverter = new RoleConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ROLE, (cmd)->cmd.role(), roleConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ROLE, (cmd)->cmd.role(), roleConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.ROLE, (cmd)->cmd.role(), roleConverter) + .run(); + } + } + + @Override + public Status save() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SAVE, (cmd)->cmd.save(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SAVE, (cmd)->cmd.save(), okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.SAVE, (cmd)->cmd.save(), okStatusConverter) + .run(); + } + } + + @Override + public void shutdown() { + if(isPipeline()){ + new LettucePipelineCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(true); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new LettuceTransactionCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(true); + return null; + }, (v)->v) + .run(); + }else{ + new LettuceCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(true); + return null; + }, (v)->v) + .run(); + } + } + + @Override + public void shutdown(final boolean save) { + final CommandArguments args = CommandArguments.create("save", save); + + if(isPipeline()){ + new LettucePipelineCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(save); + return null; + }, (v)->v) + .run(args); + }else if(isTransaction()){ + new LettuceTransactionCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(save); + return null; + }, (v)->v) + .run(args); + }else{ + new LettuceCommand<>(client, Command.SHUTDOWN, (cmd)->{ + cmd.shutdown(save); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public List slowLogGet() { + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + } + } + + @Override + public List slowLogGet(final int count) { + final CommandArguments args = CommandArguments.create("count", count); + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SLOWLOG_GET, (cmd)->cmd.slowlogGet((int) count), + listSlowlogConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SLOWLOG_GET, + (cmd)->cmd.slowlogGet((int) count), + listSlowlogConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SLOWLOG_GET, (cmd)->cmd.slowlogGet((int) count), + listSlowlogConverter) + .run(args); + } + } + + @Override + public Long slowLogLen() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SLOWLOG_LEN, (cmd)->cmd.slowlogLen(), (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SLOWLOG_LEN, (cmd)->cmd.slowlogLen(), (v)->v) + .run(); + }else{ + return new LettuceCommand<>(client, Command.SLOWLOG_LEN, (cmd)->cmd.slowlogLen(), (v)->v) + .run(); + } + } + + @Override + public Status slowLogReset() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + } + } + + @Override + public Status swapdb(final int db1, final int db2) { + final CommandArguments args = CommandArguments.create("db1", db1).put("db2", db2); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SWAPDB, (cmd)->cmd.swapdb(db1, db2), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SWAPDB, (cmd)->cmd.swapdb(db1, db2), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SWAPDB, (cmd)->cmd.swapdb(db1, db2), okStatusConverter) + .run(args); + } + } + + @Override + public RedisServerTime time() { + final RedisServerTimeConverter redisServerTimeConverter = new RedisServerTimeConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.TIME, (cmd)->cmd.time(), + redisServerTimeConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.TIME, (cmd)->cmd.time(), + redisServerTimeConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.TIME, (cmd)->cmd.time(), redisServerTimeConverter) + .run(); + } + } + + private AclUser aclGetUser(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, Command.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, Command.ACL_GETUSER) + .run(args); + }else{ + return new LettuceCommand(client, Command.ACL_GETUSER) + .run(args); + } + } + + private Long aclDelUser(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, Command.ACL_DELUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, Command.ACL_DELUSER) + .run(args); + }else{ + return new LettuceCommand(client, Command.ACL_DELUSER) + .run(args); + } + } + + private Status failover(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, Command.FAILOVER) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, Command.FAILOVER) + .run(args); + }else{ + return new LettuceCommand(client, Command.FAILOVER) + .run(args); + } + } + + private Object pSync(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PSYNC) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PSYNC) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.PSYNC) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSetOperations.java new file mode 100644 index 000000000..9e9d21676 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSetOperations.java @@ -0,0 +1,580 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.SetConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.ValueScanCursor; + +import java.util.List; +import java.util.Set; + +/** + * Lettuce 单机模式集合命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSetOperations extends AbstractSetOperations { + + public LettuceSetOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Long sAdd(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long sCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } + } + + @Override + public Set sDiff(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sDiff(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return sDiff(keys, (v)->v, args); + } + + @Override + public Long sDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Set sInter(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sInter(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return sInter(keys, (v)->v, args); + } + + @Override + public Long sInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SINTERSTORE, (cmd)->cmd.sinterstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Boolean sIsMember(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SISMEMBER, (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + } + } + + @Override + public List smIsMember(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return smIsMember(args); + } + + @Override + public List smIsMember(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return smIsMember(args); + } + + @Override + public Set sMembers(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sMembers(bKey, binaryToStringSetConverter, args); + } + + @Override + public Set sMembers(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return sMembers(key, (v)->v, args); + } + + @Override + public Status sMove(final byte[] key, final byte[] destKey, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SMOVE, (cmd)->cmd.smove(key, destKey, member), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SMOVE, + (cmd)->cmd.smove(key, destKey, member), booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SMOVE, (cmd)->cmd.smove(key, destKey, member), + booleanStatusConverter) + .run(args); + } + } + + @Override + public String sPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return sPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] sPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return sPop(key, (v)->v, args); + } + + @Override + public Set sPop(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sPop(bKey, count, binaryToStringSetConverter, args); + } + + @Override + public Set sPop(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return sPop(key, count, (v)->v, args); + } + + @Override + public String sRandMember(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return sRandMember(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] sRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return sRandMember(key, (v)->v, args); + } + + @Override + public List sRandMember(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return sRandMember(bKey, count, listConverter, args); + } + + @Override + public List sRandMember(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return sRandMember(key, count, (v)->v, args); + } + + @Override + public Long sRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } + } + + @Override + public ScanResult> sScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(pattern); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(pattern); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, scanArgs, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, scanArgs, valueScanCursorConverter, args); + } + + @Override + public Set sUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sUnion(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return sUnion(keys, (v)->v, args); + } + + @Override + public Long sUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SUNIONSTORE, (cmd)->cmd.sunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + private Set sDiff(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SDIFF, (cmd)->cmd.sdiff(keys), converter) + .run(args); + } + } + + private Set sInter(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SINTER, (cmd)->cmd.sinter(keys), converter) + .run(args); + } + } + + private List smIsMember(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, Command.SMISMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, Command.SMISMEMBER) + .run(args); + }else{ + return new LettuceCommand, List>(client, Command.SMISMEMBER) + .run(args); + } + } + + private Set sMembers(final byte[] key, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SMEMBERS, (cmd)->cmd.smembers(key), converter) + .run(args); + } + } + + private V sPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key), converter) + .run(args); + } + } + + private Set sPop(final byte[] key, final int count, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SPOP, (cmd)->cmd.spop(key, count), converter) + .run(args); + } + } + + private V sRandMember(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SPOP, (cmd)->cmd.srandmember(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SPOP, (cmd)->cmd.srandmember(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key), converter) + .run(args); + } + } + + private List sRandMember(final byte[] key, final int count, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key, count), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SRANDMEMBER, + (cmd)->cmd.srandmember(key, count), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SRANDMEMBER, (cmd)->cmd.srandmember(key, count), + converter) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor), converter) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor, scanArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanArgs), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SSCAN, (cmd)->cmd.sscan(key, cursor, scanArgs), + converter) + .run(args); + } + } + + private Set sUnion(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SUNION, (cmd)->cmd.sunion(keys), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSortedSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSortedSetOperations.java new file mode 100644 index 000000000..40f9295cb --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceSortedSetOperations.java @@ -0,0 +1,1861 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.NumberUtils; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.Aggregate; +import com.buession.redis.core.GtLt; +import com.buession.redis.core.NxXx; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; +import com.buession.redis.core.ZRangeBy; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.KeyValueConverter; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.convert.lettuce.response.ScoredValueTupleConverter; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.core.internal.lettuce.LettuceZAddArgs; +import com.buession.redis.core.internal.lettuce.LettuceZStoreArgs; +import com.buession.redis.core.internal.lettuce.utils.ScoredValueUtils; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.Limit; +import io.lettuce.core.Range; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.ScoredValue; +import io.lettuce.core.ScoredValueScanCursor; +import io.lettuce.core.ZAddArgs; +import io.lettuce.core.ZStoreArgs; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 单机模式模式有序集合命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSortedSetOperations extends AbstractSortedSetOperations { + + public LettuceSortedSetOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Tuple zPopMin(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final ScoredValueTupleConverter.BinaryScoredValueTupleConverter scoredValueConverter = new ScoredValueTupleConverter.BinaryScoredValueTupleConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key), scoredValueConverter) + .run(args); + } + } + + @Override + public List zPopMin(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZPOPMIN, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + } + } + + @Override + public Tuple zPopMax(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final ScoredValueTupleConverter.BinaryScoredValueTupleConverter scoredValueConverter = new ScoredValueTupleConverter.BinaryScoredValueTupleConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmin(key), scoredValueConverter) + .run(args); + } + } + + @Override + public List zPopMax(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZPOPMAX, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + } + } + + @Override + public com.buession.lang.KeyValue bzPopMin(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final KeyValueConverter, String, Tuple> converter = new KeyValueConverter<>( + SafeEncoder::encode, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMin(bKeys, timeout, converter, args); + } + + @Override + public com.buession.lang.KeyValue bzPopMin(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter, byte[], Tuple> converter = new KeyValueConverter<>( + (k)->k, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMin(keys, timeout, converter, args); + } + + @Override + public com.buession.lang.KeyValue bzPopMax(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final KeyValueConverter, String, Tuple> converter = new KeyValueConverter<>( + SafeEncoder::encode, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMax(bKeys, timeout, converter, args); + } + + @Override + public com.buession.lang.KeyValue bzPopMax(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter, byte[], Tuple> converter = new KeyValueConverter<>( + (k)->k, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMax(keys, timeout, converter, args); + } + + @Override + public Long zAdd(final String key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + return zAdd(key, members, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + return zAdd(key, members, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } + } + + @Override + public Long zCount(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, range), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, range), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZCOUNT, (cmd)->cmd.zcount(key, range), (v)->v) + .run(args); + } + } + + @Override + public List zDiff(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public List zDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public List zDiffWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public List zDiffWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public Long zDiffStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + return zDiffStore(args); + } + + @Override + public Long zDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + return zDiffStore(args); + } + + @Override + public Double zIncrBy(final byte[] key, final double increment, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) + .put("member", member); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZINCRBY, (cmd)->cmd.zincrby(key, increment, member), + (v)->v) + .run(args); + } + } + + @Override + public List zInter(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZINTERSTORE, (cmd)->cmd.zinterstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate); + + return zInterStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(weights); + + return zInterStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate, weights); + + return zInterStore(destKey, keys, zStoreArgs, args); + } + + @Override + public List zMScore(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return zMScore(args); + } + + @Override + public List zMScore(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return zMScore(args); + } + + @Override + public String zRandMember(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + return zRandMember(args); + } + + @Override + public byte[] zRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return zRandMember(args); + } + + @Override + public List zRandMember(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMember(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMemberWithScores(final String key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMemberWithScores(final byte[] key, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRange(bKey, start, end, listConverter, args); + } + + @Override + public List zRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return zRange(key, start, end, (v)->v, args); + } + + @Override + public List zRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrangeWithScores(key, start, end), + listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRangeByLex(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRangeByLex(bKey, bMin, bMax, listConverter, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, (v)->v, args); + } + + @Override + public List zRangeByLex(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRangeByLex(bKey, bMin, bMax, offset, count, listConverter, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, offset, count, (v)->v, args); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRangeByScore(bKey, min, max, listConverter, args); + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRangeByScore(key, min, max, (v)->v, args); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRangeByScore(bKey, min, max, offset, count, listConverter, args); + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRangeByScore(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final Range range = Range.create(min, max); + final Limit limit = Limit.create(offset, count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + } + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public Long zRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangebyscore(key, range), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangebyscore(key, range), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangebyscore(key, range), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByRank(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangebyrank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangebyrank(key, start, end), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangebyrank(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List zRevRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRevRange(bKey, start, end, listConverter, args); + } + + @Override + public List zRevRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return zRevRange(key, start, end, (v)->v, args); + } + + @Override + public List zRevRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRevRangeByLex(bKey, bMin, bMax, listConverter, args); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(key, bMin, bMax, (v)->v, args); + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRevRangeByLex(bKey, bMin, bMax, offset, count, listConverter, args); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(key, bMin, bMax, offset, count, (v)->v, args); + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRevRangeByScore(bKey, min, max, listConverter, args); + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRevRangeByScore(key, min, max, (v)->v, args); + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ListConverter listConverter = Converters.listBinaryToString(); + + return zRevRangeByScore(bKey, min, max, offset, count, listConverter, args); + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRevRangeByScore(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max, + final long offset, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final Range range = Range.create(min, max); + final Limit limit = Limit.create(offset, count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + } + } + + @Override + public Long zRevRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public ScanResult> zScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public Double zScore(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } + } + + @Override + public List zUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZUNIONSTORE, (cmd)->cmd.zunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate); + + return zUnionStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(weights); + + return zUnionStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate, weights); + + return zUnionStore(destKey, keys, zStoreArgs, args); + } + + private com.buession.lang.KeyValue bzPopMin(final byte[][] keys, final int timeout, + final KeyValueConverter, K, + Tuple> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + converter) + .run(args); + } + } + + private com.buession.lang.KeyValue bzPopMax(final byte[][] keys, final int timeout, + final KeyValueConverter, + K, Tuple> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + converter) + .run(args); + } + } + + private Long zAdd(final String key, final Map members, final CommandArguments args) { + return zAdd(SafeEncoder.encode(key), ScoredValueUtils.fromStringMap(members), args); + } + + private Long zAdd(final String key, final Map members, final ZAddArgs zAddArgs, + final CommandArguments args) { + return zAdd(SafeEncoder.encode(key), ScoredValueUtils.fromStringMap(members), zAddArgs, args); + } + + private Long zAdd(final byte[] key, final Map members, final CommandArguments args) { + return zAdd(key, ScoredValueUtils.fromBinaryMap(members), args); + } + + private Long zAdd(final byte[] key, final Map members, final ZAddArgs zAddArgs, + final CommandArguments args) { + return zAdd(key, ScoredValueUtils.fromBinaryMap(members), zAddArgs, args); + } + + private Long zAdd(final byte[] key, final ScoredValue[] scoredValues, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, scoredValues), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, scoredValues), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, scoredValues), (v)->v) + .run(args); + } + } + + private Long zAdd(final byte[] key, final ScoredValue[] scoredValues, final ZAddArgs zAddArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, zAddArgs, scoredValues), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZADD, + (cmd)->cmd.zadd(key, zAddArgs, scoredValues), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZADD, (cmd)->cmd.zadd(key, zAddArgs, scoredValues), + (v)->v) + .run(args); + } + } + + private List zDiff(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, Command.ZDIFF) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, Command.ZDIFF) + .run(args); + }else{ + return new LettuceCommand, List>(client, Command.ZDIFF) + .run(args); + } + } + + private Long zDiffStore(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, Command.ZDIFFSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, Command.ZDIFFSTORE) + .run(args); + }else{ + return new LettuceCommand(client, Command.ZDIFFSTORE) + .run(args); + } + } + + private List zInter(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, Command.ZINTER) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, Command.ZINTER) + .run(args); + }else{ + return new LettuceCommand, List>(client, Command.ZINTER) + .run(args); + } + } + + private Long zInterStore(final byte[] destKey, final byte[][] keys, final ZStoreArgs zStoreArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + } + } + + private List zMScore(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, Command.ZMSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, Command.ZMSCORE) + .run(args); + }else{ + return new LettuceCommand, List>(client, Command.ZMSCORE) + .run(args); + } + } + + private V zRandMember(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, Command.ZRANDMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, Command.ZRANDMEMBER) + .run(args); + }else{ + return new LettuceCommand(client, Command.ZRANDMEMBER) + .run(args); + } + } + + private List zRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZRANGE, (cmd)->cmd.zrange(key, start, end), converter) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final Converter, List> converter, final CommandArguments args) { + return zRangeByLex(key, Range.create(min, max), converter, args); + } + + private List zRangeByLex(final byte[] key, final Range range, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZRANGEBYLEX, (cmd)->cmd.zrangebylex(key, range), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZRANGEBYLEX, (cmd)->cmd.zrangebylex(key, range), + converter) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final int count, final Converter, List> converter, + final CommandArguments args) { + return zRangeByLex(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRangeByLex(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range, limit), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZRANGEBYLEX, (cmd)->cmd.zrangebylex(key, range, limit), + converter) + .run(args); + } + } + + private List zRangeByScore(final byte[] key, final double min, final double max, + final Converter, List> converter, final CommandArguments args) { + return zRangeByScore(key, Range.create(min, max), converter, args); + } + + private List zRangeByScore(final byte[] key, final Range range, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZRANGEBYSCORE, (cmd)->cmd.zrangebyscore(key, range), + converter) + .run(args); + } + } + + private List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count, final Converter, List> converter, + final CommandArguments args) { + return zRangeByScore(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRangeByScore(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range, limit), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range, limit), converter) + .run(args); + } + } + + private Long zRangeStore(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, Command.ZRANGESTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, Command.ZRANGESTORE) + .run(args); + }else{ + return new LettuceCommand(client, Command.ZRANGESTORE) + .run(args); + } + } + + private List zRevRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), + converter) + .run(args); + } + } + + private List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final Converter, List> converter, final CommandArguments args) { + return zRevRangeByLex(key, Range.create(min, max), converter, args); + } + + private List zRevRangeByLex(final byte[] key, final Range range, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZREVRANGEBYLEX, (cmd)->cmd.zrevrangebylex(key, range), + converter) + .run(args); + } + } + + private List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final int count, final Converter, List> converter, + final CommandArguments args) { + return zRevRangeByLex(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRevRangeByLex(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range, limit), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range, limit), converter) + .run(args); + } + } + + private List zRevRangeByScore(final byte[] key, final double min, final double max, + final Converter, List> converter, + final CommandArguments args) { + return zRevRangeByScore(key, Range.create(min, max), converter, args); + } + + private List zRevRangeByScore(final byte[] key, final Range range, + final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range), converter) + .run(args); + } + } + + private List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count, final Converter, List> converter, + final CommandArguments args) { + return zRevRangeByScore(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRevRangeByScore(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range, limit), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range, limit), converter) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zscan(key, cursor), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zscan(key, cursor), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZREVRANK, (cmd)->cmd.zscan(key, cursor), converter) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanArgs), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanArgs), + converter) + .run(args); + } + } + + private List zUnion(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, Command.ZUNION) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, Command.ZUNION) + .run(args); + }else{ + return new LettuceCommand, List>(client, Command.ZUNION) + .run(args); + } + } + + private Long zUnionStore(final byte[] destKey, final byte[][] keys, final ZStoreArgs zStoreArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceStreamOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceStreamOperations.java new file mode 100644 index 000000000..fb0cd609c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceStreamOperations.java @@ -0,0 +1,1104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.Stream; +import com.buession.redis.core.StreamConsumer; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import com.buession.redis.core.StreamGroup; +import com.buession.redis.core.StreamPending; +import com.buession.redis.core.StreamPendingSummary; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.ApproximateExactTrimming; +import com.buession.redis.core.command.args.XAddArgument; +import com.buession.redis.core.command.args.XClaimArgument; +import com.buession.redis.core.command.args.XReadArgument; +import com.buession.redis.core.command.args.XReadGroupArgument; +import com.buession.redis.core.command.args.XTrimArgument; +import com.buession.redis.core.internal.convert.lettuce.params.StreamEntryIdConverter; +import com.buession.redis.core.internal.convert.lettuce.response.PendingMessageConverter; +import com.buession.redis.core.internal.convert.lettuce.response.PendingMessagesConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamConsumersInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamEntryIDConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamFullInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamGroupInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamMessageConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamMessageMapConverter; +import com.buession.redis.core.internal.lettuce.LettuceXAddArgs; +import com.buession.redis.core.internal.lettuce.LettuceXClaimArgs; +import com.buession.redis.core.internal.lettuce.LettuceXGroupCreateArgs; +import com.buession.redis.core.internal.lettuce.LettuceXPendingArgs; +import com.buession.redis.core.internal.lettuce.LettuceXReadArgs; +import com.buession.redis.core.internal.lettuce.LettuceXReadGroupArgs; +import com.buession.redis.core.internal.lettuce.utils.StreamOffsetUtils; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.Consumer; +import io.lettuce.core.Limit; +import io.lettuce.core.Range; +import io.lettuce.core.StreamMessage; +import io.lettuce.core.XAddArgs; +import io.lettuce.core.XAutoClaimArgs; +import io.lettuce.core.XClaimArgs; +import io.lettuce.core.XGroupCreateArgs; +import io.lettuce.core.XReadArgs; +import io.lettuce.core.models.stream.ClaimedMessages; +import io.lettuce.core.models.stream.PendingMessage; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 单机模式 Stream 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceStreamOperations extends AbstractStreamOperations { + + public LettuceStreamOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("ids", (Object[]) ids); + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, messageIds), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XACK, + (cmd)->cmd.xack(key, groupName, messageIds), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XACK, (cmd)->cmd.xack(key, groupName, messageIds), + (v)->v) + .run(args); + } + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash); + final XAddArgs xAddArgs = new LettuceXAddArgs(id); + + return xAdd(key, hash, xAddArgs, args); + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) + .put("xAddArgument", xAddArgument); + final XAddArgs xAddArgs = LettuceXAddArgs.from(xAddArgument).id(id); + + return xAdd(key, hash, xAddArgs, args); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + return null;//xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + return null;//xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return null;//xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return null;//xAutoClaim(args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count"); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count"); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaimJustId(args); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = new LettuceXClaimArgs(minIdleTime); + + return xClaim(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = LettuceXClaimArgs.from(xClaimArgument).minIdleTime(minIdleTime); + + return xClaim(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = null;//new LettuceXClaimArgs(minIdleTime, true); + + return xClaimJustId(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = LettuceXClaimArgs.from(xClaimArgument).minIdleTime(minIdleTime).justid(); + + return xClaimJustId(key, ids, consumer, xClaimArgs, args); + } + + @Override + public Long xDel(final byte[] key, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("ids", (Object[]) ids); + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XDEL, (cmd)->cmd.xdel(key, messageIds), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XDEL, (cmd)->cmd.xdel(key, messageIds), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XDEL, (cmd)->cmd.xdel(key, messageIds), (v)->v) + .run(args); + } + } + + @Override + public Status xGroupCreate(final byte[] key, final byte[] groupName, final StreamEntryId id, + final boolean makeStream) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("id", id); + final XReadArgs.StreamOffset streamOffset = XReadArgs.StreamOffset.latest(key); + final XGroupCreateArgs xGroupCreateArgs = new LettuceXGroupCreateArgs(makeStream); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(streamOffset, groupName, xGroupCreateArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(streamOffset, groupName, xGroupCreateArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(streamOffset, groupName, xGroupCreateArgs), okStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + return xGroupCreateConsumer(args); + } + + @Override + public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + return xGroupCreateConsumer(args); + } + + @Override + public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelconsumer(key, consumer), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelconsumer(key, consumer), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelconsumer(key, consumer), (v)->v) + .run(args); + } + } + + @Override + public Status xGroupDestroy(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), booleanStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupSetId(final byte[] key, final byte[] groupName, final StreamEntryId id) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName).put("id", id); + final XReadArgs.StreamOffset streamOffset = XReadArgs.StreamOffset.from(key, id.toString()); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XGROUP_SETID, + (cmd)->cmd.xgroupSetid(streamOffset, groupName), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XGROUP_SETID, + (cmd)->cmd.xgroupSetid(streamOffset, groupName), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XGROUP_SETID, + (cmd)->cmd.xgroupSetid(streamOffset, groupName), okStatusConverter) + .run(args); + } + } + + @Override + public List xInfoConsumers(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + final ListConverter listStreamConsumersInfoConverter = StreamConsumersInfoConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + } + } + + @Override + public List xInfoGroups(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final ListConverter listStreamGroupInfoConverter = StreamGroupInfoConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + } + } + + @Override + public Stream xInfoStream(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final StreamInfoConverter streamInfoConverter = new StreamInfoConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream( + key), streamInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream( + key), streamInfoConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream( + key), streamInfoConverter) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full).put("count", count); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + } + } + + @Override + public Long xLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } + } + + @Override + public StreamPendingSummary xPending(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + final PendingMessagesConverter pendingMessagesConverter = new PendingMessagesConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XPENDING, (cmd)->cmd.xpending(key, groupName), + pendingMessagesConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName), pendingMessagesConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XPENDING, (cmd)->cmd.xpending(key, groupName), + pendingMessagesConverter) + .run(args); + } + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime); + final LettuceXPendingArgs xPendingArgs = new LettuceXPendingArgs<>(minIdleTime, groupName, null); + final ListConverter listStreamPendingConverter = PendingMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, xPendingArgs), + listStreamPendingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, xPendingArgs), listStreamPendingConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XPENDING, (cmd)->cmd.xpending(key, xPendingArgs), + listStreamPendingConverter) + .run(args); + } + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("start", start).put("end", end).put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, groupName, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.unbounded(); + final Limit limit = Limit.unlimited(); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("start", start).put("end", end).put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, groupName, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.unbounded(); + final Limit limit = Limit.unlimited(); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final int count, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count, + final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final Range range = Range.create(start.toString(), end.toString()); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XRANGE, (cmd)->cmd.xrange(key, range), + listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XRANGE, (cmd)->cmd.xrange(key, range), + listStreamMessageConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XRANGE, (cmd)->cmd.xrange(key, range), + listStreamMessageConverter) + .run(args); + } + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XRANGE, (cmd)->cmd.xrange(key, range, limit), + listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XRANGE, (cmd)->cmd.xrange(key, range, limit), + listStreamMessageConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XRANGE, (cmd)->cmd.xrange(key, range, limit), + listStreamMessageConverter) + .run(args); + } + } + + @Override + public List>> xRead(final Map streams) { + final CommandArguments args = CommandArguments.create("streams", streams); + return xRead(streams, args); + } + + @Override + public List>> xRead(final Map streams, + final XReadArgument xReadArgument) { + final CommandArguments args = CommandArguments.create("streams", streams).put("xReadArgument", xReadArgument); + final XReadArgs xReadArgs = LettuceXReadArgs.from(xReadArgument); + + return xRead(xReadArgs, streams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams); + return xReadGroup(groupName, consumerName, streams, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams); + return xReadGroup(groupName, consumerName, streams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadArgs xReadArgs = LettuceXReadGroupArgs.from(xReadGroupArgument); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadArgs xReadArgs = LettuceXReadGroupArgs.from(xReadGroupArgument); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadGroupArgs(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadGroupArgs(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadArgs xReadArgs = LettuceXReadGroupArgs.from(xReadGroupArgument).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final boolean isNoAck, + final Map streams, + final XReadGroupArgument xReadGroupArgument) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams).put("xReadGroupArgument", xReadGroupArgument); + final XReadArgs xReadArgs = LettuceXReadGroupArgs.from(xReadGroupArgument).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start); + final Range range = Range.create(start.toString(), end.toString()); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XREVRANGE, (cmd)->cmd.xrevrange(key, range), + listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XREVRANGE, (cmd)->cmd.xrevrange(key, range), + listStreamMessageConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XREVRANGE, (cmd)->cmd.xrevrange(key, range), + listStreamMessageConverter) + .run(args); + } + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start, + final int count) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start) + .put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, range, limit), listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XREVRANGE, + (cmd)->cmd.xrevrange(key, range, limit), listStreamMessageConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XREVRANGE, (cmd)->cmd.xrevrange(key, range, limit), + listStreamMessageConverter) + .run(args); + } + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); + return xTrim(key, xTrimArgument.getApproximateExactTrimming(), Long.MAX_VALUE, args); + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) + .put("limit", limit); + return xTrim(key, xTrimArgument.getApproximateExactTrimming(), limit, args); + } + + private StreamEntryId xAdd(final byte[] key, final Map hash, final XAddArgs xAddArgs, + final CommandArguments args) { + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, xAddArgs, hash), + streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, xAddArgs, hash), + streamEntryIDConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XADD, (cmd)->cmd.xadd(key, xAddArgs, hash), + streamEntryIDConverter) + .run(args); + } + } + + private Map> xAutoClaim(final byte[] key, + final XAutoClaimArgs xAutoClaimArgs, + final CommandArguments args) { + final Converter, Map>> converter = null; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XAUTOCLAIM, + (c)->c.xautoclaim(key, xAutoClaimArgs), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XAUTOCLAIM, + (c)->c.xautoclaim(key, xAutoClaimArgs), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XAUTOCLAIM, (c)->c.xautoclaim(key, xAutoClaimArgs), + converter) + .run(args); + } + } + + private Map> xAutoClaimJustId(final CommandArguments args) { + + if(isPipeline()){ + return new LettucePipelineCommand>, Map>>( + client, Command.XAUTOCLAIM) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand>, Map>>( + client, Command.XAUTOCLAIM) + .run(args); + }else{ + return new LettuceCommand>, Map>>( + client, Command.XAUTOCLAIM) + .run(args); + } + } + + private List xClaim(final byte[] key, final StreamEntryId[] ids, final Consumer consumer, + final XClaimArgs xClaimArgs, final CommandArguments args) { + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XCLAIM, (cmd)->cmd.xclaim(key, consumer, xClaimArgs, + messageIds), listStreamMessageConverter) + .run(args); + } + } + + private List xClaimJustId(final byte[] key, final StreamEntryId[] ids, + final Consumer consumer, final XClaimArgs xClaimArgs, + final CommandArguments args) { + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter, StreamEntryId> listStreamMessageStreamEntryIdConverter + = StreamMessageConverter.StreamMessageStreamEntryIdConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageStreamEntryIdConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageStreamEntryIdConverter) + .run(args); + } + } + + private Status xGroupCreateConsumer(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, Command.XGROUP_CREATECONSUMER) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, Command.XGROUP_CREATECONSUMER) + .run(args); + }else{ + return new LettuceCommand(client, Command.XGROUP_CREATECONSUMER) + .run(args); + } + } + + private List xPending(final byte[] key, final byte[] groupName, Range range, + final Limit limit, final CommandArguments args) { + final ListConverter listStreamPendingConverter = PendingMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName, range, limit), listStreamPendingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName, range, limit), listStreamPendingConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, groupName, range, limit), listStreamPendingConverter) + .run(args); + } + } + + private List xPending(final byte[] key, final Consumer consumer, Range range, + final Limit limit, final CommandArguments args) { + final ListConverter listStreamPendingConverter = PendingMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, consumer, range, limit), listStreamPendingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, consumer, range, limit), listStreamPendingConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XPENDING, + (cmd)->cmd.xpending(key, consumer, range, limit), listStreamPendingConverter) + .run(args); + } + } + + private List>> xRead(final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromStringMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XREAD, (cmd)->cmd.xread(streamOffsets), + listStreamMessageMapConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XREAD, (cmd)->cmd.xread(streamOffsets), + listStreamMessageMapConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XREAD, (cmd)->cmd.xread(streamOffsets), + listStreamMessageMapConverter) + .run(args); + } + } + + private List>> xRead(final XReadArgs xReadArgs, final Map streams, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromStringMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XREAD, + (cmd)->cmd.xread(xReadArgs, streamOffsets), listStreamMessageMapConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XREAD, + (cmd)->cmd.xread(xReadArgs, streamOffsets), listStreamMessageMapConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XREAD, (cmd)->cmd.xread(xReadArgs, streamOffsets), + listStreamMessageMapConverter) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromStringMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), streamOffsets, + listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromBinaryMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(groupName, consumerName, streamOffsets, listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final XReadArgs.StreamOffset[] streamOffsets, + final Converter>, + List>>> converter, + final CommandArguments args) { + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, streamOffsets), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, streamOffsets), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, streamOffsets), converter) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadArgs xReadArgs, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromStringMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), streamOffsets, xReadArgs, + listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final XReadArgs xReadArgs, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = StreamOffsetUtils.fromBinaryMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(groupName, consumerName, streamOffsets, xReadArgs, listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final XReadArgs.StreamOffset[] streamOffsets, + final XReadArgs xReadArgs, + final Converter>, + List>>> converter, + final CommandArguments args) { + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, xReadArgs, streamOffsets), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, xReadArgs, streamOffsets), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, xReadArgs, streamOffsets), converter) + .run(args); + } + } + + private Long xTrim(final byte[] key, final ApproximateExactTrimming approximateExactTrimming, final long limit, + final CommandArguments args) { + final boolean approximateTrimming = ApproximateExactTrimming.APPROXIMATE == approximateExactTrimming; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.XTRIM, + (cmd)->cmd.xtrim(key, approximateTrimming, limit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.XTRIM, + (cmd)->cmd.xtrim(key, approximateTrimming, limit), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.XTRIM, + (cmd)->cmd.xtrim(key, approximateTrimming, limit), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceStringOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceStringOperations.java new file mode 100644 index 000000000..495b1b4ef --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceStringOperations.java @@ -0,0 +1,532 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.StringUtils; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.args.GetExArgument; +import com.buession.redis.core.command.args.SetArgument; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.lettuce.LettuceGetExArgs; +import com.buession.redis.core.internal.lettuce.LettuceSetArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.GetExArgs; +import io.lettuce.core.KeyValue; +import io.lettuce.core.SetArgs; +import io.lettuce.core.Value; + +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; + +/** + * Lettuce 单机模式字符串命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceStringOperations extends AbstractStringOperations { + + public LettuceStringOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Long append(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long incr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } + } + + @Override + public Long incrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.INCRBY, (cmd)->cmd.incrby(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.INCRBY, (cmd)->cmd.incrby(key, value), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.INCRBY, (cmd)->cmd.incrby(key, value), (v)->v) + .run(args); + } + } + + @Override + public Double incrByFloat(final byte[] key, final double value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.INCRBYFLOAT, (cmd)->cmd.incrbyfloat(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.INCRBYFLOAT, + (cmd)->cmd.incrbyfloat(key, value), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.INCRBYFLOAT, (cmd)->cmd.incrbyfloat(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long decr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } + } + + @Override + public Long decrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.DECRBY, (cmd)->cmd.decrby(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.DECRBY, (cmd)->cmd.decrby(key, value), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.DECRBY, (cmd)->cmd.decrby(key, value), (v)->v) + .run(args); + } + } + + @Override + public String get(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return get(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] get(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return get(key, (v)->v, args); + } + + @Override + public String getEx(final String key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + final byte[] bKey = SafeEncoder.encode(key); + final GetExArgs getExArgs = LettuceGetExArgs.from(getExArgument); + + return getEx(bKey, getExArgs, SafeEncoder::encode, args); + } + + @Override + public byte[] getEx(final byte[] key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + final GetExArgs getExArgs = LettuceGetExArgs.from(getExArgument); + + return getEx(key, getExArgs, (v)->v, args); + } + + @Override + public String getSet(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bValue = SafeEncoder.encode(value); + + return getSet(bKey, bValue, SafeEncoder::encode, args); + } + + @Override + public byte[] getSet(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return getSet(key, value, (v)->v, args); + } + + @Override + public String getDel(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return getDel(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] getDel(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return getDel(key, (v)->v, args); + } + + @Override + public List mGet(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final com.buession.core.converter.ListConverter, String> listConverter = + new com.buession.core.converter.ListConverter<>((v)->SafeEncoder.encode(v.getValue())); + + return mGet(bKeys, listConverter, args); + } + + @Override + public List mGet(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ListConverter, byte[]> listConverter = new ListConverter<>(Value::getValue); + + return mGet(keys, listConverter, args); + } + + @Override + public Status mSet(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final Map bValues = Converters.mapStringToBinary().convert(values); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.MSET, (cmd)->cmd.mset(bValues), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.MSET, (cmd)->cmd.mset(bValues), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.MSET, (cmd)->cmd.mset(bValues), okStatusConverter) + .run(args); + } + } + + @Override + public Status mSetNx(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final Map bValues = Converters.mapStringToBinary().convert(values); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.MSETNX, (cmd)->cmd.msetnx(bValues), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.MSETNX, (cmd)->cmd.msetnx(bValues), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.MSETNX, (cmd)->cmd.msetnx(bValues), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pSetEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SET, (cmd)->cmd.set(key, value), okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value, final SetArgument setArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final SetArgs setArgs = LettuceSetArgs.from(setArgument); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setArgs), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setArgs), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SET, (cmd)->cmd.set(key, value, setArgs), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setNx(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SETNX, (cmd)->cmd.setnx(key, value), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Long setRange(final byte[] key, final long offset, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SETRANGE, (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + } + } + + @Override + public byte[] getRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GETRANGE, (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public Long strlen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } + } + + @Override + public String substr(final String key, final int start, final int end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + final Converter converter = (v)->StringUtils.substring(SafeEncoder.encode(v), start, end); + + return substr(bKey, converter, args); + } + + @Override + public byte[] substr(final byte[] key, final int start, final int end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final Converter converter = (v)->StringUtils.substring(SafeEncoder.encode(v), start, end) + .getBytes(StandardCharsets.UTF_8); + + return substr(key, converter, args); + } + + private V get(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GET, (cmd)->cmd.get(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GET, (cmd)->cmd.get(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GET, (cmd)->cmd.get(key), converter) + .run(args); + } + } + + private V getEx(final byte[] key, final GetExArgs getExArgs, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GETEX, (cmd)->cmd.getex(key, getExArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GETEX, (cmd)->cmd.getex(key, getExArgs), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GETEX, (cmd)->cmd.getex(key, getExArgs), + converter) + .run(args); + } + } + + private V getSet(final byte[] key, final byte[] value, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GETSET, (cmd)->cmd.getset(key, value), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GETSET, (cmd)->cmd.getset(key, value), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GETSET, (cmd)->cmd.getset(key, value), converter) + .run(args); + } + } + + private V getDel(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.GETDEL, (cmd)->cmd.getdel(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.GETDEL, (cmd)->cmd.getdel(key), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.GETDEL, (cmd)->cmd.getdel(key), converter) + .run(args); + } + } + + private List mGet(final byte[][] keys, final Converter>, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.MGET, (cmd)->cmd.mget(keys), converter) + .run(args); + } + } + + private V substr(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.SUBSTR, (cmd)->cmd.get(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.SUBSTR, (cmd)->cmd.get(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.SUBSTR, (cmd)->cmd.get(key), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceTransactionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceTransactionOperations.java new file mode 100644 index 000000000..168ec3475 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/LettuceTransactionOperations.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.internal.convert.lettuce.response.TransactionResultConverter; + +import java.util.List; + +/** + * Lettuce 单机模式事务命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceTransactionOperations extends AbstractTransactionOperations { + + public LettuceTransactionOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Status multi() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.MULTI, (cmd)->cmd.multi(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.MULTI, (cmd)->cmd.multi(), okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.MULTI, (cmd)->cmd.multi(), okStatusConverter) + .run(); + } + } + + @Override + public List exec() { + final TransactionResultConverter transactionResultConverter = new TransactionResultConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.MULTI, (cmd)->cmd.exec(), + transactionResultConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.MULTI, (cmd)->cmd.exec(), + transactionResultConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.MULTI, (cmd)->cmd.exec(), transactionResultConverter) + .run(); + } + } + + @Override + public void discard() { + if(isPipeline()){ + new LettucePipelineCommand<>(client, Command.DISCARD, (cmd)->cmd.discard(), (v)->v) + .run(); + }else if(isTransaction()){ + new LettuceTransactionCommand<>(client, Command.DISCARD, (cmd)->cmd.discard(), (v)->v) + .run(); + }else{ + new LettuceCommand<>(client, Command.DISCARD, (cmd)->cmd.discard(), (v)->v) + .run(); + } + } + + @Override + public Status watch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.WATCH, (cmd)->cmd.watch(keys), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.WATCH, (cmd)->cmd.watch(keys), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, Command.WATCH, (cmd)->cmd.watch(keys), okStatusConverter) + .run(args); + } + } + + @Override + public Status unwatch() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, Command.UNWATCH, (cmd)->cmd.unwatch(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, Command.UNWATCH, (cmd)->cmd.unwatch(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, Command.UNWATCH, (cmd)->cmd.unwatch(), okStatusConverter) + .run(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/package-info.java new file mode 100644 index 000000000..d6466871b --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/lettuce/operations/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.client.lettuce.operations; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/operations/AclOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/operations/AclOperations.java new file mode 100644 index 000000000..fa0a390bd --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/operations/AclOperations.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.operations; + +import com.buession.redis.core.command.AclCommands; + +/** + * 权限操作命令接口 + * + * @author Yong.Teng + */ +public interface AclOperations extends AclCommands, RedisOperations { + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/client/operations/RedisOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/client/operations/RedisOperations.java new file mode 100644 index 000000000..5125dc76e --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/client/operations/RedisOperations.java @@ -0,0 +1,498 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.operations; + +import com.buession.core.converter.Converter; +import com.buession.redis.client.RedisClient; +import com.buession.redis.client.RedisClusterClient; +import com.buession.redis.client.RedisSentinelClient; +import com.buession.redis.client.RedisStandaloneClient; +import com.buession.redis.client.connection.RedisClusterConnection; +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.client.connection.RedisConnectionUtils; +import com.buession.redis.client.connection.RedisSentinelConnection; +import com.buession.redis.client.connection.RedisStandaloneConnection; +import com.buession.redis.core.AbstractRedisCommand; +import com.buession.redis.core.RedisMode; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.exception.NotSupportedCommandException; +import com.buession.redis.exception.NotSupportedPipelineCommandException; +import com.buession.redis.exception.NotSupportedTransactionCommandException; +import com.buession.redis.exception.RedisException; + +/** + * Redis 命令操作接口 + * + * @author Yong.Teng + */ +public interface RedisOperations { + + /** + * Redis 运算命令 + * + * @param + * Redis 客户端 {@link RedisClient} + * @param + * Redis 连接对象 {@link RedisConnection} + * + * @since 3.0.0 + */ + interface RedisOperationsCommand { + + } + + /** + * Redis 单机模式运算命令 + * + * @param + * Redis 单机客户端 {@link RedisStandaloneClient} + * @param + * Redis 单机连接对象 {@link RedisStandaloneConnection} + * + * @since 3.0.0 + */ + interface RedisStandaloneOperationsCommand extends RedisOperationsCommand { + + } + + /** + * Redis 哨兵模式运算命令 + * + * @param + * Redis 哨兵客户端 {@link RedisSentinelClient} + * @param + * Redis 哨兵连接对象 {@link RedisSentinelConnection} + * + * @since 3.0.0 + */ + interface RedisSentinelOperationsCommand extends RedisOperationsCommand { + + } + + /** + * Redis 集群模式运算命令 + * + * @param + * Redis 集群客户端 {@link RedisClusterClient} + * @param + * Redis 集群连接对象 {@link RedisClusterConnection} + * + * @since 3.0.0 + */ + interface RedisClusterOperationsCommand extends RedisOperationsCommand { + + } + + /** + * Redis 运算命令抽象类 + * + * @param + * Redis 客户端 {@link RedisClient} + * @param + * Redis 连接对象 {@link RedisConnection} + * @param + * Redis 提供者原生类型 + * @param + * - + * @param + * 原生结果类型 + * @param + * 结果类型 + * + * @since 3.0.0 + */ + abstract class AbstractRedisOperationsCommand extends AbstractRedisCommand implements RedisOperationsCommand { + + /** + * Redis 连接对象 {@link RedisConnection} 实例 + */ + protected final CONN connection; + + /** + * Redis 命令执行器 + */ + protected final Executor executor; + + /** + * 结果转换器 + */ + protected final Converter converter; + + /** + * 构造函数 + * + * @param client + * Redis 客户端 {@link RedisClient} 实例 + * @param command + * Redis 命令 + */ + @SuppressWarnings({"unchecked"}) + public AbstractRedisOperationsCommand(final CLIENT client, final Command command) { + this(client, command, null, (value)->(R) value); + } + + /** + * 构造函数 + * + * @param client + * Redis 客户端 {@link RedisClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + @SuppressWarnings({"unchecked"}) + public AbstractRedisOperationsCommand(final CLIENT client, final Command command, + final Executor executor, final Converter converter) { + super(client, command); + connection = (CONN) client.getConnection(); + this.executor = executor; + this.converter = converter; + } + + /** + * 构造函数 + * + * @param client + * Redis 客户端 {@link RedisClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + @SuppressWarnings({"unchecked"}) + public AbstractRedisOperationsCommand(final CLIENT client, final Command command, final SubCommand subCommand) { + this(client, command, subCommand, null, (value)->(R) value); + } + + /** + * 构造函数 + * + * @param client + * Redis 客户端 {@link RedisClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + @SuppressWarnings({"unchecked"}) + public AbstractRedisOperationsCommand(final CLIENT client, final Command command, final SubCommand subCommand, + final Executor executor, final Converter converter) { + super(client, command, subCommand); + connection = (CONN) client.getConnection(); + this.executor = executor; + this.converter = converter; + } + + @Override + public R execute() throws RedisException { + final RedisMode mode = RedisConnectionUtils.getRedisMode(connection); + + if(executor == null){ + if(connection.isPipeline()){ + throw new NotSupportedPipelineCommandException(mode, getCommand()); + }else if(connection.isTransaction()){ + throw new NotSupportedTransactionCommandException(mode, getCommand()); + }else{ + throw new NotSupportedCommandException(RedisConnectionUtils.getRedisMode(connection), + NotSupportedCommandException.Type.NORMAL, getCommand()); + } + }else{ + try{ + return doExecute(); + }catch(Exception e){ + throw new RedisException(e.getMessage(), e); + } + } + } + + protected abstract R doExecute() throws RedisException; + + } + + /** + * Redis 单机模式命令 + * + * @param + * Redis 单机客户端 {@link RedisStandaloneClient} + * @param + * Redis 单机连接对象 {@link RedisStandaloneConnection} + * @param + * Redis 提供者原生类型 + * @param + * - + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + abstract class AbstractStandaloneCommand + extends AbstractRedisOperationsCommand + implements RedisStandaloneOperationsCommand { + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link RedisStandaloneClient} 实例 + * @param command + * Redis 命令 + */ + public AbstractStandaloneCommand(final CLIENT client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link RedisStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public AbstractStandaloneCommand(final CLIENT client, final Command command, + final Executor executor, final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link RedisStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public AbstractStandaloneCommand(final CLIENT client, final Command command, final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 单机客户端 {@link RedisStandaloneClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public AbstractStandaloneCommand(final CLIENT client, final Command command, final SubCommand subCommand, + final Executor executor, final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + } + + /** + * Redis 哨兵模式命令 + * + * @param + * Redis 哨兵客户端 {@link RedisSentinelClient} + * @param + * Redis 哨兵连接对象 {@link RedisSentinelConnection} + * @param + * Redis 提供者原生类型 + * @param + * - + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + abstract class AbstractSentinelCommand + extends AbstractRedisOperationsCommand + implements RedisSentinelOperationsCommand { + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link RedisSentinelClient} 实例 + * @param command + * Redis 命令 + */ + public AbstractSentinelCommand(final CLIENT client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link RedisSentinelClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public AbstractSentinelCommand(final CLIENT client, final Command command, + final Executor executor, final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link RedisSentinelClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public AbstractSentinelCommand(final CLIENT client, final Command command, final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 哨兵客户端 {@link RedisSentinelClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public AbstractSentinelCommand(final CLIENT client, final Command command, final SubCommand subCommand, + final Executor executor, final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + } + + /** + * Redis 集群模式命令 + * + * @param + * Redis 集群客户端 {@link RedisClusterClient} + * @param + * Redis 集群连接对象 {@link RedisClusterConnection} + * @param + * Redis 提供者原生类型 + * @param + * - + * @param + * 原生结果类型 + * @param + * 结果类型 + */ + abstract class AbstractClusterCommand + extends AbstractRedisOperationsCommand + implements RedisClusterOperationsCommand { + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link RedisClusterClient} 实例 + * @param command + * Redis 命令 + */ + public AbstractClusterCommand(final CLIENT client, final Command command) { + super(client, command); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link RedisClusterClient} 实例 + * @param command + * Redis 命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public AbstractClusterCommand(final CLIENT client, final Command command, + final Executor executor, final Converter converter) { + super(client, command, executor, converter); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link RedisClusterClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + public AbstractClusterCommand(final CLIENT client, final Command command, final SubCommand subCommand) { + super(client, command, subCommand); + } + + /** + * 构造函数 + * + * @param client + * Redis 集群客户端 {@link RedisClusterClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + * @param executor + * Redis 命令执行器 + * @param converter + * 结果转换器 + */ + public AbstractClusterCommand(final CLIENT client, final Command command, final SubCommand subCommand, + final Executor executor, final Converter converter) { + super(client, command, subCommand, executor, converter); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/AbstractRedisCommand.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/AbstractRedisCommand.java new file mode 100644 index 000000000..05d88d73c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/AbstractRedisCommand.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.client.RedisClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.exception.RedisException; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.transaction.Transaction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Redis 命令抽象类 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public abstract class AbstractRedisCommand implements com.buession.redis.core.Command { + + /** + * Redis 客户端 {@link RedisClient} 实例 + */ + protected final C client; + + /** + * Redis 命令 + */ + private final Command command; + + /** + * Redis 子命令 + */ + private final SubCommand subCommand; + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + /** + * 构造函数 + * + * @param client + * Redis 客户端 {@link RedisClient} 实例 + * @param command + * Redis 命令 + */ + protected AbstractRedisCommand(final C client, final Command command) { + this(client, command, null); + } + + /** + * 构造函数 + * + * @param client + * Redis 客户端 {@link RedisClient} 实例 + * @param command + * Redis 命令 + * @param subCommand + * Redis 子命令 + */ + protected AbstractRedisCommand(final C client, final Command command, final SubCommand subCommand) { + this.client = client; + this.command = command; + this.subCommand = subCommand; + } + + @Override + public Command getCommand() { + return command; + } + + public SubCommand getSubCommand() { + return subCommand; + } + + @Override + public R run(final CommandArguments arguments) throws RedisException { + return client.execute(this, arguments); + } + + protected Pipeline pipeline() { + return client.getConnection().openPipeline(); + } + + protected Transaction transaction() { + return client.getConnection().multi(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/AclCategory.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/AclCategory.java new file mode 100644 index 000000000..c6703fa56 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/AclCategory.java @@ -0,0 +1,188 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.core.validator.Validate; +import com.buession.redis.utils.SafeEncoder; + +import java.nio.charset.StandardCharsets; +import java.util.Objects; + +/** + * Redis ACL categories. + * + * @author Yong.Teng + * @since 3.0.0 + */ +public enum AclCategory implements Keyword { + + /** + * command affects keyspace + */ + KEYSPACE, + + /** + * read command + */ + READ, + + /** + * write command + */ + WRITE, + + /** + * command for sets + */ + SET, + + /** + * command for sorted sets + */ + SORTEDSET, + + /** + * command for lists + */ + LIST, + + /** + * command for hash ops + */ + HASH, + + /** + * command for strings + */ + STRING, + + /** + * command for bitmaps + */ + BITMAP, + + /** + * command for hyperloglog + */ + HYPERLOGLOG, + + /** + * geo command + */ + GEO, + + /** + * streaming command + */ + STREAM, + + /** + * pubsub command + */ + PUBSUB, + + /** + * admin command + */ + ADMIN, + + /** + * fast command + */ + FAST, + + /** + * slow command + */ + SLOW, + + /** + * blocking command + */ + BLOCKING, + + /** + * dangerous command + */ + DANGEROUS, + + /** + * connection-establishing command + */ + CONNECTION, + + /** + * transactional command + */ + TRANSACTION, + + /** + * scripting command + */ + SCRIPTING; + + private final byte[] raw; + + AclCategory() { + this.raw = name().getBytes(StandardCharsets.US_ASCII); + } + + @Override + public String getValue() { + return name(); + } + + @Override + public byte[] getRaw() { + return raw; + } + + public static AclCategory from(final String str) { + if(Validate.hasText(str)){ + String upperStr = str.toUpperCase(); + + for(AclCategory category : values()){ + if(category.getValue().equals(upperStr)){ + return category; + } + } + } + + return null; + } + + public static AclCategory from(final byte[] raw) { + if(raw != null){ + for(AclCategory category : values()){ + if(Objects.equals(category.getRaw(), raw)){ + return category; + } + } + } + + return null; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/AclUser.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/AclUser.java new file mode 100644 index 000000000..8a9f31da0 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/AclUser.java @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.core.validator.Validate; +import com.buession.redis.utils.ObjectStringBuilder; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Yong.Teng + * @since 2.0.0 + */ +public class AclUser implements Serializable { + + private final static long serialVersionUID = -2237993389031684508L; + + private final State state; + + private final String commands; + + private final Map userInfo = new HashMap<>(); + + private final List passwords = new ArrayList<>(); + + private final List flags = new ArrayList<>(); + + private final List keys = new ArrayList<>(); + + private final List channels = new ArrayList<>(); + + private final List selectors = new ArrayList<>(); + + public AclUser(final String commands, final Map userInfo, final List passwords, + final List flags, final List keys, final List channels, + final List selectors) { + this.commands = commands; + + if(Validate.isNotEmpty(userInfo)){ + this.userInfo.putAll(userInfo); + } + + if(passwords != null){ + this.passwords.addAll(passwords); + } + + if(flags != null){ + State state; + try{ + state = Enum.valueOf(State.class, flags.get(0).toUpperCase()); + }catch(Exception e){ + state = State.OFF; + } + this.flags.addAll(flags); + this.state = state; + }else{ + this.state = State.OFF; + } + + if(keys != null){ + this.keys.addAll(keys); + } + + if(channels != null){ + this.channels.addAll(channels); + } + + if(selectors != null){ + this.selectors.addAll(selectors); + } + } + + public String getCommands() { + return commands; + } + + public Map getUserInfo() { + return userInfo; + } + + public List getPasswords() { + return passwords; + } + + public List getFlags() { + return flags; + } + + public List getKeys() { + return keys; + } + + public List getChannels() { + return channels; + } + + public List getSelectors() { + return selectors; + } + + @Override + public String toString() { + return ObjectStringBuilder.create() + .add("state", state) + .add("commands", commands) + .add("userInfo", userInfo) + .add("passwords", passwords) + .add("flags", flags) + .add("keys", keys) + .add("channels", channels) + .add("selectors", selectors) + .build(); + } + + public enum State { + ON, + + OFF + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/AtomicvarApi.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/AtomicvarApi.java new file mode 100644 index 000000000..fde0caf4b --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/AtomicvarApi.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +/** + * @author Yong.Teng + */ +public enum AtomicvarApi { + + ATOMIC_BUILTIN("atomic-builtin"), + + SYNC_BUILTIN("sync-builtin"), + + PTHREAD_MUTEX("pthread-mutex"); + + private final String value; + + AtomicvarApi(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + @Override + public String toString(){ + return getValue(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/BitOperation.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/BitOperation.java new file mode 100644 index 000000000..84209ba5d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/BitOperation.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import java.nio.charset.StandardCharsets; + +/** + * @author Yong.Teng + */ +public enum BitOperation implements Keyword { + + AND, + + OR, + + NOT, + + XOR; + + private final byte[] raw; + + BitOperation() { + this.raw = name().getBytes(StandardCharsets.US_ASCII); + } + + @Override + public String getValue() { + return name(); + } + + @Override + public byte[] getRaw() { + return raw; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/Client.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/Client.java new file mode 100644 index 000000000..eb4a4f3f4 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/Client.java @@ -0,0 +1,613 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.core.command.Command; +import com.buession.redis.utils.ObjectStringBuilder; + +import java.io.Serializable; +import java.util.Set; + +/** + * @author Yong.Teng + */ +public class Client implements Serializable { + + private final static long serialVersionUID = -8794975805619333960L; + + /** + * 客户端 ID + */ + private int id; + + /** + * 客户端名称 + */ + private String name; + + /** + * 客户端的地址和端口 + */ + private String addr; + + /** + * 客户端的地址 + */ + private String host; + + /** + * 客户端端口 + */ + private int port; + + /** + * 套接字所使用的文件描述符 + */ + private int fd; + + /** + * 已连接时长(单位:秒) + */ + private int age; + + /** + * 空闲时长(单位:秒) + */ + private int idle; + + /** + * 客户端 flag + */ + private Set flags; + + /** + * 该客户端正在使用的数据库 ID + */ + private int db; + + /** + * 已订阅频道的数量 + */ + private int sub; + + /** + * 已订阅模式的数量 + */ + private int psub; + + /** + * 在事务中被执行的命令数量 + */ + private int multi; + + /** + * 查询缓冲区的长度(字节为单位, 0 表示没有分配查询缓冲区) + */ + private int qBuf; + + /** + * 查询缓冲区剩余空间的长度(字节为单位, 0 表示没有剩余空间) + */ + private int qBufFree; + + /** + * 输出缓冲区的长度(字节为单位, 0 表示没有分配输出缓冲区) + */ + private int obl; + + /** + * 输出列表包含的对象数量(当输出缓冲区没有剩余空间时,命令回复会以字符串对象的形式被入队到这个队列里) + */ + private int oll; + + /** + * 输出缓冲区和输出列表占用的内存总量 + */ + private int omem; + + /** + * 文件描述符事件(见下文) + */ + private Event events; + + /** + * 最近一次执行的命令 + */ + private Command cmd; + + /** + * 获取客户端 ID + * + * @return 客户端 ID + */ + public int getId(){ + return id; + } + + /** + * 设置客户端 ID + * + * @param id + * 客户端 ID + */ + public void setId(final int id){ + this.id = id; + } + + /** + * 获取客户端名称 + * + * @return 客户端名称 + */ + public String getName(){ + return name; + } + + /** + * 设置客户端名称 + * + * @param name + * 客户端名称 + */ + public void setName(final String name){ + this.name = name; + } + + /** + * 获取客户端的地址和端口 + * + * @return 客户端的地址和端口 + */ + public String getAddr(){ + return addr; + } + + /** + * 设置客户端的地址和端口 + * + * @param addr + * 客户端的地址和端口 + */ + public void setAddr(String addr){ + this.addr = addr; + } + + /** + * 获取客户端的地址 + * + * @return 客户端的地址 + */ + public String getHost(){ + return host; + } + + /** + * 设置客户端的地址 + * + * @param host + * 客户端的地址 + */ + public void setHost(String host){ + this.host = host; + } + + /** + * 获取客户端的端口 + * + * @return 客户端的端口 + */ + public int getPort(){ + return port; + } + + /** + * 设置客户端的端口 + * + * @param port + * 客户端的端口 + */ + public void setPort(int port){ + this.port = port; + } + + /** + * 获取套接字所使用的文件描述符 + * + * @return 套接字所使用的文件描述符 + */ + public int getFd(){ + return fd; + } + + /** + * 设置套接字所使用的文件描述符 + * + * @param fd + * 套接字所使用的文件描述符 + */ + public void setFd(int fd){ + this.fd = fd; + } + + /** + * 获取已连接时长(单位:秒) + * + * @return 已连接时长(单位:秒) + */ + public int getAge(){ + return age; + } + + /** + * 设置已连接时长(单位:秒) + * + * @param age + * 已连接时长(单位:秒) + */ + public void setAge(int age){ + this.age = age; + } + + /** + * 获取空闲时长(单位:秒) + * + * @return 空闲时长(单位:秒) + */ + public int getIdle(){ + return idle; + } + + /** + * 设置空闲时长(单位:秒) + * + * @param idle + * 空闲时长(单位:秒) + */ + public void setIdle(int idle){ + this.idle = idle; + } + + /** + * 获取客户端 flag + * + * @return 客户端 flag + */ + public Set getFlags(){ + return flags; + } + + /** + * 设置客户端 flag + * + * @param flags + * 客户端 flag + */ + public void setFlags(Set flags){ + this.flags = flags; + } + + /** + * 获取该客户端正在使用的数据库 ID + * + * @return 该客户端正在使用的数据库 ID + */ + public int getDb(){ + return db; + } + + /** + * 设置该客户端正在使用的数据库 ID + * + * @param db + * 该客户端正在使用的数据库 ID + */ + public void setDb(int db){ + this.db = db; + } + + /** + * 获取已订阅频道的数量 + * + * @return 已订阅频道的数量 + */ + public int getSub(){ + return sub; + } + + /** + * 设置已订阅频道的数量 + * + * @param sub + * 已订阅频道的数量 + */ + public void setSub(int sub){ + this.sub = sub; + } + + /** + * 获取已订阅模式的数量 + * + * @return 已订阅模式的数量 + */ + public int getPsub(){ + return psub; + } + + /** + * 设置已订阅模式的数量 + * + * @param psub + * 已订阅模式的数量 + */ + public void setPsub(int psub){ + this.psub = psub; + } + + /** + * 获取 在事务中被执行的命令数量 + * + * @return 在事务中被执行的命令数量 + */ + public int getMulti(){ + return multi; + } + + /** + * 设置 在事务中被执行的命令数量 + * + * @param multi + * 在事务中被执行的命令数量 + */ + public void setMulti(int multi){ + this.multi = multi; + } + + /** + * 获取 查询缓冲区的长度(字节为单位, 0 表示没有分配查询缓冲区) + * + * @return 查询缓冲区的长度(字节为单位, 0 表示没有分配查询缓冲区) + */ + public int getQBuf(){ + return qBuf; + } + + /** + * 设置 查询缓冲区的长度(字节为单位, 0 表示没有分配查询缓冲区) + * + * @param qBuf + * 查询缓冲区的长度(字节为单位, 0 表示没有分配查询缓冲区) + */ + public void setQBuf(int qBuf){ + this.qBuf = qBuf; + } + + /** + * 获取查询缓冲区剩余空间的长度(字节为单位, 0 表示没有剩余空间) + * + * @return 查询缓冲区剩余空间的长度(字节为单位, 0 表示没有剩余空间) + */ + public int getQBufFree(){ + return qBufFree; + } + + /** + * 设置查询缓冲区剩余空间的长度(字节为单位, 0 表示没有剩余空间) + * + * @param qBufFree + * 查询缓冲区剩余空间的长度(字节为单位, 0 表示没有剩余空间) + */ + public void setQBufFree(int qBufFree){ + this.qBufFree = qBufFree; + } + + /** + * 获取输出缓冲区的长度(字节为单位, 0 表示没有分配输出缓冲区) + * + * @return 输出缓冲区的长度(字节为单位, 0 表示没有分配输出缓冲区) + */ + public int getObl(){ + return obl; + } + + /** + * 设置输出缓冲区的长度(字节为单位, 0 表示没有分配输出缓冲区) + * + * @param obl + * 输出缓冲区的长度(字节为单位, 0 表示没有分配输出缓冲区) + */ + public void setObl(int obl){ + this.obl = obl; + } + + /** + * 获取输出列表包含的对象数量(当输出缓冲区没有剩余空间时,命令回复会以字符串对象的形式被入队到这个队列里) + * + * @return 输出列表包含的对象数量(当输出缓冲区没有剩余空间时,命令回复会以字符串对象的形式被入队到这个队列里) + */ + public int getOll(){ + return oll; + } + + /** + * 设置输出列表包含的对象数量(当输出缓冲区没有剩余空间时,命令回复会以字符串对象的形式被入队到这个队列里) + * + * @param oll + * 输出列表包含的对象数量(当输出缓冲区没有剩余空间时,命令回复会以字符串对象的形式被入队到这个队列里) + */ + public void setOll(int oll){ + this.oll = oll; + } + + /** + * 获取输出缓冲区和输出列表占用的内存总量 + * + * @return 输出缓冲区和输出列表占用的内存总量 + */ + public int getOmem(){ + return omem; + } + + /** + * 设置输出缓冲区和输出列表占用的内存总量 + * + * @param omem + * 输出缓冲区和输出列表占用的内存总量 + */ + public void setOmem(int omem){ + this.omem = omem; + } + + /** + * 获取文件描述符事件 + * + * @return 文件描述符事件 + */ + public Event getEvents(){ + return events; + } + + /** + * 设置文件描述符事件 + * + * @param events + * 文件描述符事件 + */ + public void setEvents(Event events){ + this.events = events; + } + + /** + * 获取最近一次执行的命令 + * + * @return 最近一次执行的命令 + */ + public Command getCmd(){ + return cmd; + } + + /** + * 设置最近一次执行的命令 + * + * @param cmd + * 最近一次执行的命令 + */ + public void setCmd(Command cmd){ + this.cmd = cmd; + } + + @Override + public String toString(){ + return ObjectStringBuilder.create() + .add("id", id) + .add("name", name) + .add("addr", addr) + .add("host", host) + .add("port", port) + .add("fd", fd) + .add("age", age) + .add("idle", idle) + .add("flags", flags) + .add("db", db) + .add("su", sub) + .add("psub", psub) + .add("mult", multi) + .add("qBuf", qBuf) + .add("qBufFree", qBufFree) + .add("obl", obl) + .add("oll", oll) + .add("omem", omem) + .add("events", events) + .add("cmd", cmd) + .build(); + } + + public enum Flag { + + /** + * 客户端是 MONITOR 模式下的附属节点(slave) + */ + O, + + /** + * 客户端是一般模式下(normal)的附属节点 + */ + S, + + /** + * 客户端是主节点(master) + */ + M, + + /** + * 客户端正在执行事务 + */ + x, + + /** + * 客户端正在等待阻塞事件 + */ + b, + + /** + * 客户端正在等待 VM I/O 操作(已废弃) + */ + @Deprecated + i, + + /** + * 一个受监视(watched)的键已被修改, EXEC 命令将失败 + */ + d, + + /** + * 在将回复完整地写出之后,关闭链接 + */ + c, + + /** + * 客户端未被阻塞(unblocked) + */ + u, + + /** + * 尽可能快地关闭连接 + */ + A, + + /** + * 未设置任何 flag + */ + N + } + + public enum Event { + + R, + + W + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/ClientAttributeOption.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClientAttributeOption.java new file mode 100644 index 000000000..a39e15252 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClientAttributeOption.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +/** + * 客户端属性选项 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public enum ClientAttributeOption { + LIB_NAME, + + LIB_VER +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/ClientPauseMode.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClientPauseMode.java new file mode 100644 index 000000000..53b47807e --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClientPauseMode.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +/** + * 客户端暂停模式 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public enum ClientPauseMode { + ALL, + + WRITE; +} diff --git a/buession-redis/src/test/java/com/buession/redis/AbstractRedisTest.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClientReply.java similarity index 95% rename from buession-redis/src/test/java/com/buession/redis/AbstractRedisTest.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/ClientReply.java index 8f9d6db79..3cf0459ba 100644 --- a/buession-redis/src/test/java/com/buession/redis/AbstractRedisTest.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClientReply.java @@ -22,11 +22,17 @@ * | Copyright @ 2013-2020 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.redis; +package com.buession.redis.core; /** * @author Yong.Teng */ -public abstract class AbstractRedisTest { +public enum ClientReply { + + ON, + + OFF, + + SKIP } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/ClientTrackingInfo.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClientTrackingInfo.java new file mode 100644 index 000000000..2b15d8061 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClientTrackingInfo.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +/** + * {@code CLIENT TRACKINGINFO} 结果 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class ClientTrackingInfo { + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/ClientUnblockType.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClientUnblockType.java new file mode 100644 index 000000000..0e98a57d3 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClientUnblockType.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2020 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +/** + * @author Yong.Teng + */ +public enum ClientUnblockType { + + TIMEOUT, + + ERROR + +} diff --git a/buession-redis/src/main/java/com/buession/redis/utils/ResponseUtils.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterFailoverOption.java similarity index 85% rename from buession-redis/src/main/java/com/buession/redis/utils/ResponseUtils.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterFailoverOption.java index 0101a4399..e6d56d715 100644 --- a/buession-redis/src/main/java/com/buession/redis/utils/ResponseUtils.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterFailoverOption.java @@ -22,21 +22,18 @@ * | Copyright @ 2013-2022 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.redis.utils; - -import com.buession.core.utils.StringUtils; +package com.buession.redis.core; /** + * http://www.redis.cn/commands/cluster-failover.html + * * @author Yong.Teng * @since 2.0.0 */ -@Deprecated -public class ResponseUtils { +public enum ClusterFailoverOption { - public final static String ROW_SEPARATOR = "\r\n"; + FORCE, - public static String[] parseRows(final String str) { - return StringUtils.split(str, "\r\n"); - } + TAKEOVER } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterInfo.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterInfo.java new file mode 100644 index 000000000..b0177771e --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterInfo.java @@ -0,0 +1,423 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.utils.ObjectStringBuilder; + +import java.io.Serializable; +import java.util.Properties; + +/** + * 集群信息,更多信息 http://www.redis.cn/commands/cluster-info.html + * + * @author Yong.Teng + * @since 2.0.0 + */ +public class ClusterInfo implements Serializable { + + private final static long serialVersionUID = 5975395725518673096L; + + /** + * 集群状态,Status.SUCCESS 表示集群可以正常接受查询请求;Status.FAILURE 表示,至少有一个哈希槽没有被绑定(说明有哈希槽没有被绑定到任意一个节点),或者在错误的状态(节点可以提供服务但是带有FAIL 标记),或者该节点无法联系到多数master节点 + */ + private final State state; + + /** + * 已分配到集群节点的哈希槽数量 + */ + private final int slotsAssigned; + + /** + * 哈希槽状态不是 FAIL 和 PFAIL 的数量 + */ + private final int slotsOk; + + /** + * 哈希槽状态是 PFAIL 的数量; + * 只要哈希槽状态没有被升级到 FAIL 状态,这些哈希槽仍然可以被正常处理; + * PFAIL 状态表示我们当前不能和节点进行交互,但这种状态只是临时的错误状态 + */ + private final int slotsPfail; + + /** + * 哈希槽状态是 FAIL 的数量,如果值不是 0,那么集群节点将无法提供查询服务,除非 cluster-require-full-coverage 被设置为 no + */ + private final int slotsFail; + + /** + * 集群中节点数量,包括处于握手状态还没有成为集群正式成员的节点 + */ + private final int knownNodes; + + /** + * 至少包含一个哈希槽且能够提供服务的 master 节点数量 + */ + private final int size; + + /** + * 集群本地 Current Epoch 变量的值;这个值在节点故障转移过程时有用,它总是递增和唯一的 + */ + private final int currentEpoch; + + /** + * 当前正在使用的节点的 Config Epoch 值,这个是关联在本节点的版本值 + */ + private final int myEpoch; + + /** + * - + */ + private final long messagesPingSent; + + /** + * - + */ + private final long messagesPongSent; + + /** + * 通过 node-to-node 二进制总线发送的消息数量 + */ + private final long messagesSent; + + /** + * - + */ + private final long messagesPingReceived; + + /** + * - + */ + private final long messagesPongReceived; + + /** + * - + */ + private final long messagesMeetReceived; + + /** + * 通过 node-to-node 二进制总线接收的消息数量 + */ + private final long messagesReceived; + + /** + * 构造函数 + * + * @param state + * 集群状态 + * @param slotsAssigned + * 已分配到集群节点的哈希槽数量 + * @param slotsOk + * 哈希槽状态不是 FAIL 和 PFAIL 的数量 + * @param slotsPfail + * 哈希槽状态是 PFAIL 的数量 + * @param slotsFail + * 哈希槽状态是 FAIL 的数量 + * @param knownNodes + * 集群中节点数量 + * @param size + * 至少包含一个哈希槽且能够提供服务的 master 节点数量 + * @param currentEpoch + * 集群本地 Current Epoch 变量的值 + * @param myEpoch + * 当前正在使用的节点的 Config Epoch 值 + * @param messagesPingSent + * - + * @param messagesPongSent + * - + * @param messagesSent + * 通过 node-to-node 二进制总线发送的消息数量 + * @param messagesPingReceived + * - + * @param messagesPongReceived + * - + * @param messagesMeetReceived + * - + * @param messagesReceived + * 通过 node-to-node 二进制总线接收的消息数量 + */ + public ClusterInfo(final State state, final int slotsAssigned, final int slotsOk, final int slotsPfail, + final int slotsFail, final int knownNodes, final int size, final int currentEpoch, + final int myEpoch, final long messagesPingSent, final long messagesPongSent, + final long messagesSent, final long messagesPingReceived, final long messagesPongReceived, + final long messagesMeetReceived, final long messagesReceived) { + this.state = state; + this.slotsAssigned = slotsAssigned; + this.slotsOk = slotsOk; + this.slotsPfail = slotsPfail; + this.slotsFail = slotsFail; + this.knownNodes = knownNodes; + this.size = size; + this.currentEpoch = currentEpoch; + this.myEpoch = myEpoch; + this.messagesPingSent = messagesPingSent; + this.messagesPongSent = messagesPongSent; + this.messagesSent = messagesSent; + this.messagesPingReceived = messagesPingReceived; + this.messagesPongReceived = messagesPongReceived; + this.messagesMeetReceived = messagesMeetReceived; + this.messagesReceived = messagesReceived; + } + + /** + * 返回集群状态 + * + * @return 集群状态 + */ + public State getState() { + return state; + } + + /** + * 返回已分配到集群节点的哈希槽数量 + * + * @return 已分配到集群节点的哈希槽数量 + */ + public int getSlotsAssigned() { + return slotsAssigned; + } + + /** + * 返回哈希槽状态不是 FAIL 和 PFAIL 的数量 + * + * @return 哈希槽状态不是 FAIL 和 PFAIL 的数量 + */ + public int getSlotsOk() { + return slotsOk; + } + + /** + * 返回哈希槽状态是 PFAIL 的数量 + * + * @return 哈希槽状态是 PFAIL 的数量 + */ + public int getSlotsPfail() { + return slotsPfail; + } + + /** + * 返回哈希槽状态是 FAIL 的数量 + * + * @return 哈希槽状态是 FAIL 的数量 + */ + public int getSlotsFail() { + return slotsFail; + } + + /** + * 返回集群中节点数量,包括处于握手状态还没有成为集群正式成员的节点 + * + * @return 集群中节点数量,包括处于握手状态还没有成为集群正式成员的节点 + */ + public int getKnownNodes() { + return knownNodes; + } + + /** + * 返回至少包含一个哈希槽且能够提供服务的 master 节点数量 + * + * @return 至少包含一个哈希槽且能够提供服务的 master 节点数量 + */ + public int getSize() { + return size; + } + + /** + * 返回集群本地 Current Epoch 变量的值;这个值在节点故障转移过程时有用,它总是递增和唯一的 + * + * @return 集群本地 Current Epoch 变量的值 + */ + public int getCurrentEpoch() { + return currentEpoch; + } + + /** + * 返回当前正在使用的节点的 Config Epoch 值,这个是关联在本节点的版本值 + * + * @return 当前正在使用的节点的 Config Epoch 值 + */ + public int getMyEpoch() { + return myEpoch; + } + + /** + * - + * + * @return - + */ + public long getMessagesPingSent() { + return messagesPingSent; + } + + /** + * - + * + * @return - + */ + public long getMessagesPongSent() { + return messagesPongSent; + } + + /** + * 返回通过 node-to-node 二进制总线发送的消息数量 + * + * @return 通过 node-to-node 二进制总线发送的消息数量 + */ + public long getMessagesSent() { + return messagesSent; + } + + /** + * - + * + * @return - + */ + public long getMessagesPingReceived() { + return messagesPingReceived; + } + + /** + * - + * + * @return - + */ + public long getMessagesPongReceived() { + return messagesPongReceived; + } + + /** + * - + * + * @return - + */ + public long getMessagesMeetReceived() { + return messagesMeetReceived; + } + + /** + * 返回通过 node-to-node 二进制总线接收的消息数量 + * + * @return 通过 node-to-node 二进制总线接收的消息数量 + */ + public long getMessagesReceived() { + return messagesReceived; + } + + @SuppressWarnings("unchecked") + protected static E getObject(final Properties properties, final String key) { + return (E) properties.get(key); + } + + @Override + public String toString() { + return ObjectStringBuilder.create() + .add(Key.STATE.value, state) + .add(Key.SLOTS_ASSIGNED.value, slotsAssigned) + .add(Key.SLOTS_OK.value, slotsOk) + .add(Key.SLOTS_PFAIL.value, slotsPfail) + .add(Key.SLOTS_FAIL.value, slotsFail) + .add(Key.KNOWN_NODES.value, knownNodes) + .add(Key.SIZE.value, size) + .add(Key.CURRENT_EPOCH.value, currentEpoch) + .add(Key.MY_EPOCH.value, myEpoch) + .add(Key.MESSAGES_PING_SENT.value, messagesPingSent) + .add(Key.MESSAGES_PONG_SENT.value, messagesPongSent) + .add(Key.MESSAGES_SENT.value, messagesSent) + .add(Key.MESSAGES_PING_RECEIVED.value, messagesPingReceived) + .add(Key.MESSAGES_PONG_RECEIVED.value, messagesPongReceived) + .add(Key.MESSAGES_MEET_RECEIVED.value, messagesMeetReceived) + .add(Key.MESSAGES_RECEIVED.value, messagesReceived) + .build(); + } + + public enum State { + + OK("ok"), + + FAIL("fail"); + + private String value; + + State(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + return getValue(); + } + + } + + public enum Key { + + STATE("cluster_state"), + + SLOTS_ASSIGNED("cluster_slots_assigned"), + + SLOTS_OK("cluster_slots_ok"), + + SLOTS_PFAIL("cluster_slots_pfail"), + + SLOTS_FAIL("cluster_slots_fail"), + + KNOWN_NODES("cluster_known_nodes"), + + SIZE("cluster_size"), + + CURRENT_EPOCH("cluster_current_epoch"), + + MY_EPOCH("cluster_my_epoch"), + + MESSAGES_PING_SENT("cluster_stats_messages_ping_sent"), + + MESSAGES_PONG_SENT("cluster_stats_messages_pong_sent"), + + MESSAGES_SENT("cluster_stats_messages_sent"), + + MESSAGES_PING_RECEIVED("cluster_stats_messages_ping_received"), + + MESSAGES_PONG_RECEIVED("cluster_stats_messages_pong_received"), + + MESSAGES_MEET_RECEIVED("cluster_stats_messages_meet_received"), + + MESSAGES_RECEIVED("cluster_stats_messages_received"); + + private final String value; + + Key(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterLink.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterLink.java new file mode 100644 index 000000000..811181697 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterLink.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class ClusterLink { + + private String node; + + private Direction direction; + + private Long createTime; + + private Event[] events; + + private Integer sendBufferAllocated; + + private Integer sendBufferUsed; + + public String getNode() { + return node; + } + + public void setNode(String node) { + this.node = node; + } + + public Direction getDirection() { + return direction; + } + + public void setDirection(Direction direction) { + this.direction = direction; + } + + public Long getCreateTime() { + return createTime; + } + + public void setCreateTime(Long createTime) { + this.createTime = createTime; + } + + public Event[] getEvents() { + return events; + } + + public void setEvents(Event[] events) { + this.events = events; + } + + public Integer getSendBufferAllocated() { + return sendBufferAllocated; + } + + public void setSendBufferAllocated(Integer sendBufferAllocated) { + this.sendBufferAllocated = sendBufferAllocated; + } + + public Integer getSendBufferUsed() { + return sendBufferUsed; + } + + public void setSendBufferUsed(Integer sendBufferUsed) { + this.sendBufferUsed = sendBufferUsed; + } + + public enum Direction { + FROM, + + TO + } + + public enum Event { + R, + + W + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterRedisNode.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterRedisNode.java new file mode 100644 index 000000000..8b3cc6aef --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterRedisNode.java @@ -0,0 +1,353 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.utils.ObjectStringBuilder; + +import java.util.Set; + +/** + * 集群节点 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public class ClusterRedisNode extends RedisNode { + + private final static long serialVersionUID = -6841072654023820951L; + + /** + * Redis 服务器主机 IP 地址 + */ + private final String ip; + + /** + * 标记位 + */ + private final Set flags; + + /** + * 是否是自身 + */ + private final boolean isMySelf; + + /** + * 主机角色 + */ + private Role role; + + /** + * Master 主机 ID + */ + private String masterId; + + /** + * 最近一次发送 ping 的时间(unix 毫秒时间戳),0 代表没有发送过 + */ + private final long pingSent; + + /** + * 最近一次收到 pong 的时间(unix 毫秒时间戳),0 代表没有接收过 + */ + private final long pongSent; + + /** + * 节点的 epoch 值 + */ + private final long configEpoch; + + /** + * node-to-node 集群总线使用的链接的状态 + */ + private final LinkState linkState; + + /** + * 哈希槽值或者一个哈希槽范围 + */ + private final SlotRange slot; + + /** + * 构造函数 + * + * @param id + * 节点ID + * @param ip + * 客户端与节点通信使用的地址 + * @param port + * 客户端与节点通信使用的端口 + * @param flags + * 标记位 + * @param role + * 主机角色 + * @param masterId + * Master 节点 Id + * @param pingSent + * 最近一次发送 ping 的时间(unix 毫秒时间戳) + * @param pongSent + * 最近一次收到 pong 的时间(unix 毫秒时间戳) + * @param configEpoch + * 节点的 epoch 值 + * @param linkState + * node-to-node 集群总线使用的链接的状态 + * @param slot + * 哈希槽值或者一个哈希槽范围 + * + * @ + */ + public ClusterRedisNode(final String id, final String ip, final int port, final Set flags, + final Role role, final String masterId, final long pingSent, final long pongSent, + final long configEpoch, + final LinkState linkState, final SlotRange slot) { + super(ip, port); + setId(id); + this.ip = ip; + this.flags = flags; + if(flags == null){ + this.isMySelf = false; + }else{ + this.isMySelf = flags.contains(Flag.MYSELF); + } + this.role = role; + this.masterId = masterId; + this.pingSent = pingSent; + this.pongSent = pongSent; + this.configEpoch = configEpoch; + this.linkState = linkState; + this.slot = slot; + } + + /** + * 返回客户端与节点通信使用的地址 + * + * @return 客户端与节点通信使用的地址 + */ + public String getIp() { + return ip; + } + + /** + * 返回标记位 + * + * @return 标记位 + */ + public Set getFlags() { + return flags; + } + + /** + * 是否是自身 + * + * @return true / false + */ + public boolean isMySelf() { + return isMySelf; + } + + /** + * 返回主机角色 + * + * @return 主机角色 + */ + public Role getRole() { + return role; + } + + /** + * 设置主机角色 + * + * @param role + * 主机角色 + */ + public void setRole(Role role) { + this.role = role; + } + + /** + * 返回 Master 主机 ID + * + * @return Master 主机 ID + */ + public String getMasterId() { + return masterId; + } + + /** + * 设置 Master 主机 ID + * + * @param masterId + * Master 主机 ID + */ + public void setMasterId(String masterId) { + this.masterId = masterId; + } + + /** + * 返回最近一次发送 ping 的时间(unix 毫秒时间戳),0 代表没有发送过 + * + * @return 最近一次发送 ping 的时间(unix 毫秒时间戳),0 代表没有发送过 + */ + public long getPingSent() { + return pingSent; + } + + /** + * 返回最近一次收到 pong 的时间(unix 毫秒时间戳),0 代表没有接收过 + * + * @return 最近一次收到 pong 的时间(unix 毫秒时间戳),0 代表没有接收过 + */ + public long getPongSent() { + return pongSent; + } + + /** + * 返回节点的 epoch 值 + * + * @return 节点的 epoch 值 + */ + public long getConfigEpoch() { + return configEpoch; + } + + /** + * 返回 node-to-node 集群总线使用的链接的状态 + * + * @return node-to-node 集群总线使用的链接的状态 + */ + public LinkState getLinkState() { + return linkState; + } + + /** + * 返回哈希槽值或者一个哈希槽范围 + * + * @return 哈希槽值或者一个哈希槽范围 + */ + public SlotRange getSlot() { + return slot; + } + + @Override + public String toString() { + return ObjectStringBuilder.create() + .add("id", getId()) + .add("host", getHost() + ":" + getPort()) + .add("masterId", getMasterId()) + .add("ping-sent", pingSent) + .add("pong-recv", pongSent) + .add("config-epoch", configEpoch) + .add("link-state", linkState) + .add("slot", slot) + .build(); + } + + /** + * 标记位 + */ + public enum Flag { + + /** + * 当前连接的节点 + */ + MYSELF("myself"), + + /** + * master 节点 + */ + MASTER("master"), + + /** + * slave 节点 + */ + SLAVE("slave"), + + /** + * 节点处于 PFAIL 状态 + */ + PFAIL("fail?"), + + /** + * 节点处于FAIL 状态 + */ + FAIL(""), + + /** + * 还未取得信任的节点,当前正在与其进行握手 + */ + HANDSHAKE("handshake"), + + /** + * 没有地址的节点 + */ + NOADDR("noaddr"), + + /** + * 没有标记 + */ + NOFLAGS("noflags"); + + private final String value; + + Flag(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + return getValue(); + } + + } + + /** + * node-to-node 集群总线使用的链接的状态 + */ + public enum LinkState { + + CONNECTED("connected"), + + DISCONNECTED("disconnected"); + + private final String value; + + LinkState(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + return getValue(); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterRedisShard.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterRedisShard.java new file mode 100644 index 000000000..9b7bf5d1d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterRedisShard.java @@ -0,0 +1,195 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +/** + * The details about which cluster slots map to which Redis instances. + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class ClusterRedisShard extends RedisNode { + + private final static long serialVersionUID = 6399444050542251476L; + + /** + * 主机名称 + */ + private String hostname; + + /** + * 插槽范围 + */ + private SlotRange slots; + + /** + * 构造函数 + * + * @param host + * 主机地址 + */ + public ClusterRedisShard(String host) { + super(host); + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + */ + public ClusterRedisShard(String host, int port) { + super(host, port); + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param hostname + * 主机名称 + */ + public ClusterRedisShard(String host, String hostname) { + super(host); + this.hostname = hostname; + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param slots + * 插槽范围 + */ + public ClusterRedisShard(String host, SlotRange slots) { + super(host); + this.slots = slots; + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param hostname + * 主机名称 + * @param slots + * 插槽范围 + */ + public ClusterRedisShard(String host, String hostname, SlotRange slots) { + this(host, hostname); + this.slots = slots; + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + * @param hostname + * 主机名称 + */ + public ClusterRedisShard(String host, int port, String hostname) { + super(host, port); + this.hostname = hostname; + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + * @param slots + * 插槽范围 + */ + public ClusterRedisShard(String host, int port, SlotRange slots) { + super(host, port); + this.slots = slots; + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + * @param hostname + * 主机名称 + * @param slots + * 插槽范围 + */ + public ClusterRedisShard(String host, int port, String hostname, SlotRange slots) { + this(host, port, hostname); + this.slots = slots; + } + + /** + * 返回主机名称 + * + * @return 主机名称 + */ + public String getHostname() { + return hostname; + } + + /** + * 设置主机名称 + * + * @param hostname + * 主机名称 + */ + public void setHostname(String hostname) { + this.hostname = hostname; + } + + /** + * 返回插槽范围 + * + * @return 插槽范围 + */ + public SlotRange getSlots() { + return slots; + } + + /** + * 设置插槽范围 + * + * @param slots + * 插槽范围 + */ + public void setSlots(SlotRange slots) { + this.slots = slots; + } + +} diff --git a/buession-aop/src/main/java/com/buession/aop/aspectj/AbstractAspectAnnotationsMethodInterceptor.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterResetOption.java similarity index 84% rename from buession-aop/src/main/java/com/buession/aop/aspectj/AbstractAspectAnnotationsMethodInterceptor.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterResetOption.java index 2d945de20..65391025f 100644 --- a/buession-aop/src/main/java/com/buession/aop/aspectj/AbstractAspectAnnotationsMethodInterceptor.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterResetOption.java @@ -22,19 +22,18 @@ * | Copyright @ 2013-2022 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.aop.aspectj; +package com.buession.redis.core; /** - * Aspectj 方法注解拦截器抽象类 + * Redis Reset 类型,详情 http://www.redis.cn/commands/cluster-reset.html * * @author Yong.Teng - * @since 2.1.0 + * @since 2.0.0 */ -@Deprecated -public abstract class AbstractAspectAnnotationsMethodInterceptor extends AbstractAspectjAnnotationsMethodInterceptor { +public enum ClusterResetOption { - public AbstractAspectAnnotationsMethodInterceptor(){ - super(); - } + HARD, + + SOFT } diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/OkHttpClient.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterSetSlotOption.java similarity index 75% rename from buession-httpclient/src/main/java/com/buession/httpclient/OkHttpClient.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterSetSlotOption.java index b88acec7f..a564b8ccd 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/OkHttpClient.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterSetSlotOption.java @@ -22,41 +22,34 @@ * | Copyright @ 2013-2022 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.httpclient; - -import com.buession.httpclient.conn.OkHttpClientConnectionManager; +package com.buession.redis.core; /** + * 详情 http://www.redis.cn/commands/cluster-setslot.html + * * @author Yong.Teng + * @since 2.0.0 */ -@Deprecated -public class OkHttpClient extends OkHttpHttpClient { +public enum ClusterSetSlotOption { + + /** + * 将一个哈希槽设置为 importing 状态 + */ + IMPORTING, /** - * 构造函数 + * 将一个哈希槽设置为 migrating 状态 */ - public OkHttpClient(){ - super(); - } + MIGRATING, /** - * 构造函数 - * - * @param connectionManager - * 连接管理器 + * 从哈希槽中清除导入和迁移状态 */ - public OkHttpClient(OkHttpClientConnectionManager connectionManager){ - super(connectionManager); - } + STABLE, /** - * 构造函数 - * - * @param httpClient - * OkHttp Client + * 将一个哈希槽绑定到另一个不同的节点 */ - public OkHttpClient(okhttp3.OkHttpClient httpClient){ - super(httpClient); - } + NODE } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterSlot.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterSlot.java new file mode 100644 index 000000000..5e726a04c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ClusterSlot.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.utils.ObjectStringBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * 哈希槽和 Redis 实例映射关系,详细信息请看 http://www.redis.cn/commands/cluster-slots.html + * + * @author Yong.Teng + * @since 2.0.0 + */ +public class ClusterSlot implements Serializable { + + private final static long serialVersionUID = -809787517243228575L; + + /** + * 哈希槽起始编号 + */ + private final long start; + + /** + * 哈希槽结束编号 + */ + private final long end; + + /** + * master 节点副本列表 + */ + private final List masterNodes; + + /** + * 构造函数 + * + * @param start + * 哈希槽起始编号 + * @param end + * 哈希槽结束编号 + * @param masterNodes + * master 节点副本列表 + */ + public ClusterSlot(final long start, final long end, final List masterNodes){ + this.start = start; + this.end = end; + this.masterNodes = masterNodes; + } + + /** + * 返回哈希槽起始编号 + * + * @return 哈希槽起始编号 + */ + public long getStart(){ + return start; + } + + /** + * 返回哈希槽结束编号 + * + * @return 哈希槽结束编号 + */ + public long getEnd(){ + return end; + } + + /** + * 返回 master 节点副本列表 + * + * @return master 节点副本列表 + */ + public List getMasterNodes(){ + return masterNodes; + } + + @Override + public String toString(){ + return ObjectStringBuilder.create() + .add("start", start) + .add("end", end) + .add("masterNodes", masterNodes) + .build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/Command.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/Command.java new file mode 100644 index 000000000..aad95d63b --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/Command.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.exception.RedisException; + +/** + * Redis 命令接口 + * + * @param + * 命令执行结果类型 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public interface Command { + + /** + * 返回 Redis 命令 + * + * @return Redis 命令 + */ + com.buession.redis.core.command.Command getCommand(); + + /** + * 返回 Redis 子命令 + * + * @return Redis 子命令 + * + * @since 3.0.0 + */ + com.buession.redis.core.command.SubCommand getSubCommand(); + + /** + * 执行 Redis 命令 + * + * @return Redis 命令执行结果 + * + * @throws RedisException + * Redis 命令执行异常 + */ + R execute() throws RedisException; + + /** + * 运行 Redis 命令 + * + * @return Redis 命令运行结果 + * + * @throws RedisException + * Redis 命令运行异常 + */ + default R run() throws RedisException { + return run(null); + } + + /** + * 运行 Redis 命令 + * + * @param arguments + * Redis 命令参数 + * + * @return Redis 命令运行结果 + * + * @throws RedisException + * Redis 命令运行异常 + */ + R run(final CommandArguments arguments) throws RedisException; + + /** + * Redis 命令执行器 + * + * @param + * Redis 对象上下文 + * @param + * 命令执行返回值类型 + * + * @since 3.0.0 + */ + @FunctionalInterface + interface Executor extends com.buession.core.Executor { + + @Override + R execute(C context) throws RedisException; + + } + + /** + * Redis 命令运行器 + * + * @author Yong.Teng + */ + @FunctionalInterface + interface Runner { + + /** + * 运行 Redis 命令 + * + * @param + * 命令运行结果类型 + * + * @return Redis 命令运行结果 + * + * @throws RedisException + * Redis 命令运行异常 + */ + R run() throws RedisException; + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/ExpireOption.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ExpireOption.java new file mode 100644 index 000000000..d7367fb84 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ExpireOption.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +/** + * @author Yong.Teng + * @since 2.0.0 + */ +public enum ExpireOption { + + /** + * Set expiry only when the key has no expiry + */ + NX, + + /** + * Set expiry only when the key has an existing expiry + */ + XX, + + /** + * Set expiry only when the new expiry is greater than current one + */ + GT, + + /** + * Set expiry only when the new expiry is less than current one + */ + LT + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/FutureResult.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/FutureResult.java new file mode 100644 index 000000000..a8b72345a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/FutureResult.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.internal.convert.Converters; +import org.springframework.lang.Nullable; + +/** + * 事务、管道异步结果 + * + * @param + * Response + * + * @author Yong.Teng + */ +public abstract class FutureResult { + + private final T holder; + + @SuppressWarnings({"rawtypes"}) + private final Converter converter; + + public FutureResult(final T holder) { + this(holder, Converters.always()); + } + + @SuppressWarnings({"rawtypes"}) + public FutureResult(final T holder, final Converter converter) { + this.holder = holder; + this.converter = converter; + } + + public final T getHolder() { + return holder; + } + + @Nullable + public abstract Object get(); + + /** + * 将 事务、管道 + * + * @param result + * 事务、管道原始返回结果 + * + * @return 转换结果 + */ + @SuppressWarnings({"unchecked"}) + @Nullable + public Object convert(@Nullable Object result) { + return result == null ? null : converter.convert(result); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/Info.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/Info.java new file mode 100644 index 000000000..531b27c9c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/Info.java @@ -0,0 +1,2812 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.core.utils.PropertiesUtils; +import com.buession.core.utils.StringUtils; +import com.buession.core.validator.Validate; +import com.buession.lang.Constants; +import com.buession.net.Multiplexing; +import com.buession.lang.Status; +import com.buession.lang.Uptime; +import com.buession.net.HostAndPort; +import org.apache.commons.lang3.arch.Processor; + +import java.io.Serializable; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.StringJoiner; + +/** + * Redis 服务器的各种信息和统计数值 + * + * @author Yong.Teng + */ +public class Info implements Serializable { + + private final static long serialVersionUID = -2772690110674245981L; + + /** + * Redis 服务器的信息 + */ + private final Server server; + + /** + * 已连接客户端的信息 + */ + private final Clients clients; + + /** + * Redis 服务器的内存信息 + */ + private final Memory memory; + + /** + * RDB 持久化和 AOF 持久化有关的信息 + */ + private final Persistence persistence; + + /** + * 一般统计信息 + */ + private final Stats stats; + + /** + * 主从复制信息 + */ + private final Replication replication; + + /** + * Sentinel 信息 + */ + private final Sentinel sentinel; + + /** + * CPU 的计算量统计信息 + */ + private final Cpu cpu; + + /** + * 集群有关的信息 + */ + private final Cluster cluster; + + /** + * 数据库相关的统计信息 + */ + private final List keyspace; + + public Info(final Server server, final Clients clients, final Memory memory, final Persistence persistence, + final Stats stats, final Replication replication, final Sentinel sentinel, final Cpu cpu, + final Cluster cluster, final List keyspaces){ + this.server = server; + this.clients = clients; + this.memory = memory; + this.persistence = persistence; + this.stats = stats; + this.replication = replication; + this.sentinel = sentinel; + this.cpu = cpu; + this.cluster = cluster; + this.keyspace = keyspaces; + } + + /** + * 获取 Redis 服务器的信息 + * + * @return Redis 服务器的信息 + */ + public Server getServer(){ + return server; + } + + /** + * 获取已连接客户端的信息 + * + * @return 已连接客户端的信息 + */ + public Clients getClients(){ + return clients; + } + + /** + * 获取 Redis 服务器的内存信息 + * + * @return Redis 服务器的内存信息 + */ + public Memory getMemory(){ + return memory; + } + + /** + * 获取 RDB 持久化和 AOF 持久化有关的信息 + * + * @return RDB 持久化和 AOF 持久化有关的信息 + */ + public Persistence getPersistence(){ + return persistence; + } + + /** + * 获取集群有关的信息 + * + * @return 集群有关的信息 + */ + public Cluster getCluster(){ + return cluster; + } + + /** + * 获取一般统计信息 + * + * @return 一般统计信息 + */ + public Stats getStats(){ + return stats; + } + + /** + * 获取主从复制信息 + * + * @return 主从复制信息 + */ + public Replication getReplication(){ + return replication; + } + + /** + * 获取 Sentinel 信息 + * + * @return Sentinel 信息 + */ + public Sentinel getSentinel(){ + return sentinel; + } + + /** + * 获取 CPU 的计算量统计信息 + * + * @return CPU 的计算量统计信息 + */ + public Cpu getCpu(){ + return cpu; + } + + /** + * 获取数据库相关的统计信息 + * + * @return 数据库相关的统计信息 + */ + public List getKeyspace(){ + return keyspace; + } + + public String toPrettyString(){ + final StringBuilder sb = new StringBuilder(); + String lineSeparator = System.lineSeparator(); + boolean init = false; + + if(server != null){ + init = true; + sb.append("server:").append(lineSeparator).append(server.toPrettyString()); + } + + if(clients != null){ + if(init){ + sb.append(lineSeparator).append(lineSeparator); + } + init = true; + sb.append("clients:").append(lineSeparator).append(clients.toPrettyString()); + } + + if(memory != null){ + if(init){ + sb.append(lineSeparator).append(lineSeparator); + } + init = true; + sb.append("memory:").append(lineSeparator).append(memory.toPrettyString()); + } + + if(persistence != null){ + if(init){ + sb.append(lineSeparator).append(lineSeparator); + } + init = true; + sb.append("persistence:").append(lineSeparator).append(persistence.toPrettyString()); + } + + if(stats != null){ + if(init){ + sb.append(lineSeparator).append(lineSeparator); + } + init = true; + sb.append("stats:").append(lineSeparator).append(stats.toPrettyString()); + } + + if(replication != null){ + if(init){ + sb.append(lineSeparator).append(lineSeparator); + } + init = true; + sb.append("replication:").append(lineSeparator).append(replication.toPrettyString()); + } + + if(sentinel != null){ + if(init){ + sb.append(lineSeparator).append(lineSeparator); + } + init = true; + sb.append("sentinel:").append(lineSeparator).append(sentinel.toPrettyString()); + } + + if(cpu != null){ + if(init){ + sb.append(lineSeparator).append(lineSeparator); + } + init = true; + sb.append("cpu:").append(lineSeparator).append(cpu.toPrettyString()); + } + + if(cluster != null){ + if(init){ + sb.append(lineSeparator).append(lineSeparator); + } + init = true; + sb.append("cluster:").append(lineSeparator).append(cluster.toPrettyString()); + } + + if(keyspace != null){ + if(init){ + sb.append(lineSeparator).append(lineSeparator); + } + sb.append("keyspace:").append(lineSeparator).append(StringUtils.join(keyspace, lineSeparator)); + } + + return sb.toString(); + } + + @Override + public String toString(){ + final StringBuilder sb = new StringBuilder(); + boolean init = false; + + if(server != null){ + init = true; + sb.append("server=").append('[').append(server).append(']'); + } + + if(clients != null){ + if(init){ + sb.append(", "); + } + init = true; + sb.append("clients=").append('[').append(clients).append(']').append(", "); + } + + if(memory != null){ + if(init){ + sb.append(", "); + } + init = true; + sb.append("memory=").append('[').append(memory).append(']'); + } + + if(persistence != null){ + if(init){ + sb.append(", "); + } + init = true; + sb.append("persistence=").append('[').append(persistence).append(']'); + } + + if(stats != null){ + if(init){ + sb.append(", "); + } + init = true; + sb.append("stats=").append('[').append(stats).append(']'); + } + + if(replication != null){ + if(init){ + sb.append(", "); + } + init = true; + sb.append("replication=").append('[').append(replication).append(']'); + } + + if(sentinel != null){ + if(init){ + sb.append(", "); + } + init = true; + sb.append("sentinel=").append('[').append(sentinel).append(']'); + } + + if(cpu != null){ + if(init){ + sb.append(", "); + } + init = true; + sb.append("cpu=").append('[').append(cpu).append(']'); + } + + if(cluster != null){ + if(init){ + sb.append(", "); + } + init = true; + sb.append("cluster=").append('[').append(cluster).append(']'); + } + + if(keyspace != null){ + if(init){ + sb.append(", "); + } + sb.append("keyspace=").append('[').append(keyspace).append(']'); + } + + return sb.toString(); + } + + protected static Double getPercent(final Properties properties, final String key){ + String str = properties.getProperty(key); + return Validate.hasText(str) ? Double.parseDouble(str.substring(0, str.length() - 1)) : null; + } + + protected static Boolean getBoolean(final Properties properties, final String key){ + String str = properties.getProperty(key); + + if(Validate.hasText(str) == false){ + return null; + } + + if(Boolean.parseBoolean(str)){ + return true; + } + + try{ + return Integer.parseInt(str) != 0; + }catch(Exception e){ + return false; + } + } + + protected static Date getDate(final Properties properties, final String key, final boolean isUnixTimestamp){ + String str = properties.getProperty(key); + + if(Validate.hasText(str) == false){ + return null; + } + + long timestamp = Long.parseLong(str); + + if(isUnixTimestamp){ + timestamp = timestamp * 1000; + } + + return new Date(timestamp); + } + + @SuppressWarnings("unchecked") + protected static E getObject(final Properties properties, final String key){ + return (E) properties.get(key); + } + + protected static String toPrettyString(final Properties properties){ + int max = properties.size() - 1; + if(max == -1){ + return Constants.EMPTY_STRING; + } + + final StringBuilder sb = new StringBuilder(); + + Iterator> iterator = properties.entrySet().iterator(); + for(int i = 0; ; i++){ + Map.Entry element = iterator.next(); + Object key = element.getKey(); + Object value = element.getValue(); + + if(value != null){ + sb.append(key).append('=').append(value); + } + + if(i == max){ + return sb.toString(); + } + + sb.append(System.lineSeparator()); + } + } + + protected static String toString(final Properties properties){ + int max = properties.size() - 1; + if(max == -1){ + return Constants.EMPTY_STRING; + } + + final StringBuilder sb = new StringBuilder(); + + Iterator> iterator = properties.entrySet().iterator(); + for(int i = 0; ; i++){ + Map.Entry element = iterator.next(); + Object key = element.getKey(); + Object value = element.getValue(); + + if(value != null){ + sb.append(key).append('=').append(value); + } + + if(i == max){ + return sb.toString(); + } + + sb.append(", "); + } + } + + public enum Section { + + SERVER, + + CLIENTS, + + MEMORY, + + PERSISTENCE, + + STATS, + + CPU, + + REPLICATION, + + CLUSTER, + + COMMAND_STATS, + + KEYSPACE + + } + + /** + * Redis 服务器的信息 + * + * @author Yong.Teng + */ + public final static class Server implements Serializable { + + private final static long serialVersionUID = 2729543496870054983L; + + private final Properties properties; + + public Server(final Properties properties){ + this.properties = properties; + } + + /** + * 获取 Redis 架构 + * + * @return Redis 架构 + */ + public Processor.Arch getArch(){ + return getObject(properties, Key.ARCH.value); + } + + /** + * 获取 Redis atomicvar API + * + * @return Redis atomicvar API + */ + public AtomicvarApi getAtomicvarApi(){ + return getObject(properties, Key.ATOMICVAR_API.value); + } + + /** + * 获取 Redis build id + * + * @return Redis build id + */ + public String getBuildId(){ + return PropertiesUtils.get(properties, Key.BUILD_ID.value); + } + + public Integer getConfiguredHz(){ + return PropertiesUtils.getInt(properties, Key.CONFIGURED_HZ.value); + } + + /** + * 获取 Redis 可执行文件路径 + * + * @return Redis 可执行文件路径 + */ + public String getExecutable(){ + return PropertiesUtils.get(properties, Key.EXECUTABLE.value); + } + + /** + * 获取 Redis 配置文件路径 + * + * @return Redis 配置文件路径 + */ + public String getConfigFile(){ + return PropertiesUtils.get(properties, Key.CONFIG_FILE.value); + } + + /** + * 获取编译 Redis 时所使用的 GCC 版本 + * + * @return 编译 Redis 时所使用的 GCC 版本 + */ + public String getGccVersion(){ + return PropertiesUtils.get(properties, Key.GCC_VESION.value); + } + + /** + * 获取 Redis Git dirty flag + * + * @return Redis Git dirty flag + */ + public String getGitDirty(){ + return PropertiesUtils.get(properties, Key.GIT_DIRTY.value); + } + + /** + * 获取 Redis Git SHA1 + * + * @return Redis Git SHA1 + */ + public String getGitSha1(){ + return PropertiesUtils.get(properties, Key.GIT_SHA1.value); + } + + /** + * 获取 Redis 内部调度(进行关闭 timeout 的客户端,删除过期key等等)频率 + * + * @return Redis 内部调度(进行关闭 timeout 的客户端,删除过期key等等)频率 + */ + public Integer getHz(){ + return PropertiesUtils.getInt(properties, Key.HZ.value); + } + + /** + * 获取以分钟为单位进行自增的时钟,用于 LRU 管理 + * + * @return 以分钟为单位进行自增的时钟,用于 LRU 管理 + */ + public Integer getLruClock(){ + return PropertiesUtils.getInt(properties, Key.LRU_CLOCK.value); + } + + /** + * 获取 Redis 运行模式 + * + * @return Redis 运行模式 + */ + public RedisMode getMode(){ + return getObject(properties, Key.MODE.value); + } + + /** + * 获取 Redis 所使用的事件处理机制 + * + * @return Redis 所使用的事件处理机制 + */ + public Multiplexing getMultiplexingApi(){ + return getObject(properties, Key.MULTIPLEXING_API.value); + } + + /** + * 获取 Redis 服务器的宿主操作系统 + * + * @return Redis 服务器的宿主操作系统 + */ + public String getOs(){ + return PropertiesUtils.get(properties, Key.OS.value); + } + + /** + * 获取 Redis 服务器主机端口 + * + * @return Redis 服务器主机端口 + */ + public Integer getPort(){ + return PropertiesUtils.getInt(properties, Key.PORT.value); + } + + /** + * 获取服务器进程的 PID + * + * @return 服务器进程的 PID + */ + public Integer getProcessId(){ + return PropertiesUtils.getInt(properties, Key.PROCESS_ID.value); + } + + /** + * 获取 Redis 服务器的随机标识符(用于 Sentinel 和集群) + * + * @return Redis 服务器的随机标识符(用于 Sentinel 和集群) + */ + public String getRunId(){ + return PropertiesUtils.get(properties, Key.RUN_ID.value); + } + + /** + * 获取自 Redis 服务器启动以来的运行时间 + * + * @return 自 Redis 服务器启动以来的运行时间 + */ + public Uptime getUptime(){ + return getObject(properties, Key.UPTIME.value); + } + + /** + * 获取 Redis 服务器版本 + * + * @return Redis 服务器版本 + */ + public String getVersion(){ + return PropertiesUtils.get(properties, Key.VERSION.value); + } + + public String toPrettyString(){ + return Info.toPrettyString(properties); + } + + @Override + public String toString(){ + return Info.toString(properties); + } + + public enum Key { + + ARCH("arch_bits"), + + ATOMICVAR_API("atomicvar_api"), + + BUILD_ID("redis_build_id"), + + CONFIGURED_HZ("configured_hz"), + + CONFIG_FILE("config_file"), + + EXECUTABLE("executable"), + + GCC_VESION("gcc_version"), + + GIT_DIRTY("redis_git_dirty"), + + GIT_SHA1("redis_git_sha1"), + + HZ("hz"), + + LRU_CLOCK("lru_clock"), + + MODE("redis_mode"), + + MULTIPLEXING_API("multiplexing_api"), + + OS("os"), + + PORT("tcp_port"), + + PROCESS_ID("process_id"), + + RUN_ID("run_id"), + + UPTIME("uptime"), + + VERSION("redis_version"); + + private final String value; + + Key(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + } + + /** + * 已连接客户端的信息 + * + * @author Yong.Teng + */ + public final static class Clients implements Serializable { + + private final static long serialVersionUID = 7746131798680346372L; + + private final Properties properties; + + public Clients(final Properties properties){ + this.properties = properties; + } + + /** + * 获取当前连接的客户端当中,最大输入缓存 + * + * @return 当前连接的客户端当中,最大输入缓存 + */ + public Integer getBiggestInputBuffer(){ + return PropertiesUtils.getInt(properties, Key.BIGGES_TINPUT_BUFFER.value); + } + + /** + * 获取正在等待阻塞命令的客户端的数量 + * + * @return 正在等待阻塞命令的客户端的数量 + */ + public Integer getBlockeds(){ + return PropertiesUtils.getInt(properties, Key.BLOCKEDS.value); + } + + /** + * 获取已连接客户端的数量 + * + * @return 已连接客户端的数量 + */ + public Integer getConnecteds(){ + return PropertiesUtils.getInt(properties, Key.CONNECTEDS.value); + } + + /** + * 获取当前连接的客户端中最大输入 + * + * @return 当前连接的客户端中最大输入 + */ + public Integer getClientRecentMaxInputBuffer(){ + return PropertiesUtils.getInt(properties, Key.CLIENT_RECENT_MAX_INPUT_BUFFER.value); + } + + /** + * 获取当前连接的客户端中最大输出 + * + * @return 当前连接的客户端中最大输出 + */ + public Integer getClientRecentMaxOutputBuffer(){ + return PropertiesUtils.getInt(properties, Key.CLIENT_RECENT_MAX_OUTPUT_BUFFER.value); + } + + /** + * 获取当前连接的客户端当中,最长的输出列表 + * + * @return 当前连接的客户端当中,最长的输出列表 + */ + public Integer getLongestOutputList(){ + return PropertiesUtils.getInt(properties, Key.LONGEST_OUTPUT_LIST.value); + } + + public String toPrettyString(){ + return Info.toPrettyString(properties); + } + + @Override + public String toString(){ + return Info.toString(properties); + } + + public enum Key { + + BIGGES_TINPUT_BUFFER("client_biggest_input_buf"), + + BLOCKEDS("blocked_clients"), + + CONNECTEDS("connected_clients"), + + CLIENT_RECENT_MAX_INPUT_BUFFER("client_recent_max_input_buffer"), + + CLIENT_RECENT_MAX_OUTPUT_BUFFER("client_recent_max_output_buffer"), + + LONGEST_OUTPUT_LIST("client_longest_output_list"); + + private final String value; + + Key(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + } + + /** + * Redis 服务器的内存信息 + * + * @author Yong.Teng + */ + public final static class Memory implements Serializable { + + private final static long serialVersionUID = 1058962019266560745L; + + private final Properties properties; + + public Memory(final Properties properties){ + this.properties = properties; + } + + /** + * 检测内存整理是否处于活动状态 + * + * @return 内存整理是否处于活动状态 + */ + public Boolean isActiveDefragRunning(){ + return getActiveDefragRunning(); + } + + /** + * 检测内存整理是否处于活动状态 + * + * @return 内存整理是否处于活动状态 + */ + public Boolean getActiveDefragRunning(){ + return getBoolean(properties, Key.ACTIVE_DEFRAG_RUNNING.value); + } + + /** + * 返回 Redis 中分配器活跃内存数(单位:byte) + * + * @return Redis 中分配器活跃内存数 + */ + public Long getAllocatorActive(){ + return PropertiesUtils.getLong(properties, Key.ALLOCATOR_ACTIVE.value); + } + + /** + * 返回 Redis 中分配器分配内存数(单位:byte) + * + * @return Redis 中分配器分配内存数 + */ + public Long getAllocatorAllocated(){ + return PropertiesUtils.getLong(properties, Key.ALLOCATOR_ALLOCATED.value); + } + + /** + * 返回分配器内存碎片大小(单位:byte) + * + * @return 分配器内存碎片大小 + */ + public Long getAllocatorFragBytes(){ + return PropertiesUtils.getLong(properties, Key.ALLOCATOR_FRAG_BYTES.value); + } + + /** + * 返回分配器碎片率 + * + * @return 分配器碎片率 + */ + public Double getAllocatorFragRatio(){ + return PropertiesUtils.getDouble(properties, Key.ALLOCATOR_FRAG_RATIO.value); + } + + /** + * 返回 Redis 中分配器常驻内存数(单位:byte) + * + * @return Redis 中分配器常驻内存数 + */ + public Long getAllocatorResident(){ + return PropertiesUtils.getLong(properties, Key.ALLOCATOR_RESIDENT.value); + } + + /** + * 返回分配器常驻内存大小(单位:byte) + * + * @return 分配器常驻内存大小 + */ + public Long getAllocatorRssBytes(){ + return PropertiesUtils.getLong(properties, Key.ALLOCATOR_RSS_BYTES.value); + } + + /** + * 返回分配器常驻内存比例 + * + * @return 分配器常驻内存比例 + */ + public Double getAllocatorRssRatio(){ + return PropertiesUtils.getDouble(properties, Key.ALLOCATOR_RSS_RATIO.value); + } + + /** + * 返回等待释放对象数,此值只会在使用 ASYNC 选项并调用 UNLINK 或 FLUSHDB 和 FLUSHALL 时存在 + * + * @return 等待释放对象数 + */ + public Integer getLazyfreePendingObjects(){ + return PropertiesUtils.getInt(properties, Key.LAZYFREE_PENDING_OBJECTS.value); + } + + /** + * 返回 Redis 中可分配的最大内存数,默认为0不限制 + * + * @return Redis 中可分配的最大内存数 + */ + public Long getMaxMemory(){ + return PropertiesUtils.getLong(properties, Key.MAX_MEMORY.value); + } + + /** + * 返回 Redis 中可分配的最大内存数的可读信息 + * + * @return Redis 中可分配的最大内存数的可读信息 + */ + public String getMaxMemoryHuman(){ + return PropertiesUtils.get(properties, Key.MAX_MEMORY_HUMAN.value); + } + + /** + * 返回达到 Redis 最大内存数 maxmemory 后的处理策略 + * + * @return 达到 Redis 最大内存数 maxmemory 后的处理策略 + */ + public MaxMemoryPolicy getMaxMemoryPolicy(){ + return getObject(properties, Key.MAX_MEMORY_POLICY.value); + } + + /** + * 返回 Redis 在编译时指定的,Redis 所使用的内存分配器及其版本 + * + * @return Redis 在编译时指定的,Redis 所使用的内存分配器及其版本 + */ + public String getMemAllocator(){ + return PropertiesUtils.get(properties, Key.MEM_ALLOCATOR.value); + } + + /** + * 返回 Redis 使用 aof 持久化方式中 aof_buffer 缓冲区大小(单位:byte) + * + * @return Redis 使用 ao f持久化方式中 aof_buffer 缓冲区大小 + */ + public Long getMemAofBuffer(){ + return PropertiesUtils.getLong(properties, Key.MEM_AOF_BUFFER.value); + } + + public Integer getMemClientsNormal(){ + return PropertiesUtils.getInt(properties, Key.MEM_CLIENTS_NORMAL.value); + } + + public Integer getMemClientsSlaves(){ + return PropertiesUtils.getInt(properties, Key.MEM_CLIENTS_SLAVES.value); + } + + /** + * Redis 中内存碎片大小(单位:byte) + * + * @return Redis 中内存碎片大小 + */ + public Long getMemFragmentationBytes(){ + return PropertiesUtils.getLong(properties, Key.MEM_FRAGMENTATION_BYTES.value); + } + + /** + * 返回 Redis 中内存碎片率,此值为 (used_memory_rss/used_memory)*100% + * + * @return Redis 中内存碎片率 + */ + public Double getMemFragmentationRatio(){ + return PropertiesUtils.getDouble(properties, Key.MEM_FRAGMENTATION_RATIO.value); + } + + /** + * 返回被驱逐的内存大小 + * + * @return 被驱逐的内存大小 + */ + public Long getMemNotCountedForEvict(){ + return PropertiesUtils.getLong(properties, Key.MEM_NOT_COUNTED_FOR_EVICT.value); + } + + /** + * 返回从服务其中 backlog 内存大小 + * + * @return 从服务其中 backlog 内存大小 + */ + public Long getMemReplicationBacklog(){ + return PropertiesUtils.getLong(properties, Key.MEM_REPLICATION_BACKLOG.value); + } + + public Integer getNumberOfCachedScripts(){ + return PropertiesUtils.getInt(properties, Key.NUMBER_OF_CACHED_SCRIPTS.value); + } + + /** + * 返回常驻内存开销比例 + * + * @return 常驻内存开销比例 + */ + public Double getRssOverheadRatio(){ + return PropertiesUtils.getDouble(properties, Key.RSS_OVERHEAD_RATIO.value); + } + + /** + * 返回常驻内存开销大小(单位:byte) + * + * @return 常驻内存开销大小 + */ + public Long getRssOverheadBytes(){ + return PropertiesUtils.getLong(properties, Key.RSS_OVERHEAD_BYTES.value); + } + + /** + * 返回系统内存总数 + * + * @return 系统内存总数 + */ + public Long getTotalSystemMemory(){ + return PropertiesUtils.getLong(properties, Key.TOTAL_SYSTEM_MEMORY.value); + } + + /** + * 返回系统内存总数的可读信息(单位:byte) + * + * @return 系统内存总数的可读信息 + */ + public String getTotalSystemMemoryHuman(){ + return PropertiesUtils.get(properties, Key.TOTAL_SYSTEM_MEMORY_HUMAN.value); + } + + /** + * 返回由 Redis 分配器分配的内存总量,包括使用的虚拟内存(单位:byte) + * + * @return 由 Redis 分配器分配的内存总量,包括使用的虚拟内存 + */ + public Long getUsedMemory(){ + return PropertiesUtils.getLong(properties, Key.USED_MEMORY.value); + } + + /** + * 返回 Redis 中数据集所占内存数据大小,即:used_memory - used_memory_overhead(单位:byte) + * + * @return Redis 中数据集所占内存数据大小 + */ + public Long getUsedMemoryDataset(){ + return PropertiesUtils.getLong(properties, Key.USED_MEMORY_DATASET.value); + } + + /** + * used_memory_dataset 在净内存(used_memory - used_memory_startup)使用量中所占的百分比,即: + * (used_memory_dataset/(used_memory—used_memory_startup)) * 100% + * + * @return used_memory_dataset 在净内存(used_memory - used_memory_startup)使用量中所占的百分比 + */ + public Double getUsedMemoryDatasetPerc(){ + return getPercent(properties, Key.USED_MEMORY_DATASET_PERC.value); + } + + /** + * 由 Redis 分配器分配的内存总量,包括使用的虚拟内存的可读信息 + * + * @return 由 Redis 分配器分配的内存总量,包括使用的虚拟内存的可读信息 + */ + public String getUsedMemoryHuman(){ + return PropertiesUtils.get(properties, Key.USED_MEMORY_HUMAN.value); + } + + /** + * 返回 lua 引擎使用内存量(单位:byte) + * + * @return lua 引擎使用内存量 + */ + public Long getUsedMemoryLua(){ + return PropertiesUtils.getLong(properties, Key.USED_MEMORY_LUA.value); + } + + /** + * 返回 lua 引擎使用内存量的可读信息 + * + * @return lua 引擎使用内存量的可读信息 + */ + public String getUsedMemoryLuaHuman(){ + return PropertiesUtils.get(properties, Key.USED_MEMORY_LUA_HUMAN.value); + } + + /** + * 返回 Redis 维护整个内存数据集可用内部机制所需要的内存开销。 + * 包括维护内部数据结构,所有客户端输出缓冲区,AOF 重写缓冲区,查询缓冲区,AOF 写入缓冲区和主从复制的 backlog(单位:byte) + * + * @return Redis 维护整个内存数据集可用内部机制所需要的内存开销 + */ + public Long getUsedMemoryOverhead(){ + return PropertiesUtils.getLong(properties, Key.USED_MEMORY_OVERHEAD.value); + } + + /** + * 返回 Redis 的内存消耗峰值,即:Redis 内存使用的最大值(单位:byte) + * + * @return Redis 的内存消耗峰值,即:Redis 内存使用的最大值 + */ + public Long getUsedMemoryPeak(){ + return PropertiesUtils.getLong(properties, Key.USED_MEMORY_PEAK.value); + } + + /** + * 返回 Redis 的内存消耗峰值,即:Redis 内存使用的最大值的可读信息 + * + * @return Redis 的内存消耗峰值,即:Redis 内存使用的最大值的可读信息 + */ + public String getUsedMemoryPeakHuman(){ + return PropertiesUtils.get(properties, Key.USED_MEMORY_PEAK_HUMAN.value); + } + + /** + * 返回 used_memory_peak 在 used_memory 中所占的百分比 + * + * @return used_memory_peak 在 used_memory 中所占的百分比 + */ + public Double getUsedMemoryPeakPerc(){ + return getPercent(properties, Key.USED_MEMORY_PEAK_PERC.value); + } + + /** + * 获取从操作系统角度返回 Redis 使用内存数,与 Linux 中 top,ps 命令返回数据一致 + * 除了分配器分配的内存之外,used_memory_rss 还包括进程运行本身需要的内存、内存碎片等,但是不包括虚拟内存(单位:byte) + * + * @return Redis 使用内存数 + */ + public Long getUsedMemoryRss(){ + return PropertiesUtils.getLong(properties, Key.USED_MEMORY_RSS.value); + } + + /** + * 返回 Redis 使用内存数的可读信息 + * + * @return Redis 使用内存数的可读信息 + */ + public String getUsedMemoryRssHuman(){ + return PropertiesUtils.get(properties, Key.USED_MEMORY_RSS_HUMAN.value); + } + + public Long getUsedMemoryScripts(){ + return PropertiesUtils.getLong(properties, Key.USED_MEMORY_SCRIPTS.value); + } + + public String getUsedMemoryScriptsHuman(){ + return PropertiesUtils.get(properties, Key.USED_MEMORY_SCRIPTS_HUMAN.value); + } + + /** + * 返回 Redis 消耗的初始内存值 + * + * @return Redis 消耗的初始内存值 + */ + public Long getUsedMemoryStartup(){ + return PropertiesUtils.getLong(properties, Key.USED_MEMORY_STARTUP.value); + } + + public String toPrettyString(){ + return Info.toPrettyString(properties); + } + + @Override + public String toString(){ + return Info.toString(properties); + } + + public enum Key { + + ACTIVE_DEFRAG_RUNNING("active_defrag_running"), + + ALLOCATOR_ACTIVE("allocator_active"), + + ALLOCATOR_ALLOCATED("allocator_allocated"), + + ALLOCATOR_FRAG_BYTES("allocator_frag_bytes"), + + ALLOCATOR_FRAG_RATIO("allocator_frag_ratio"), + + ALLOCATOR_RESIDENT("allocator_resident"), + + ALLOCATOR_RSS_BYTES("allocator_rss_bytes"), + + ALLOCATOR_RSS_RATIO("allocator_rss_ratio"), + + LAZYFREE_PENDING_OBJECTS("lazyfree_pending_objects"), + + MAX_MEMORY("maxmemory"), + + MAX_MEMORY_HUMAN("maxmemory_human"), + + MAX_MEMORY_POLICY("maxmemory_policy"), + + MEM_ALLOCATOR("mem_allocator"), + + MEM_AOF_BUFFER("mem_aof_buffer"), + + MEM_CLIENTS_NORMAL("mem_clients_normal"), + + MEM_CLIENTS_SLAVES("mem_clients_slaves"), + + MEM_FRAGMENTATION_BYTES("mem_fragmentation_bytes"), + + MEM_FRAGMENTATION_RATIO("mem_fragmentation_ratio"), + + MEM_NOT_COUNTED_FOR_EVICT("mem_not_counted_for_evict"), + + MEM_REPLICATION_BACKLOG("mem_replication_backlog"), + + NUMBER_OF_CACHED_SCRIPTS("number_of_cached_scripts"), + + RSS_OVERHEAD_BYTES("rss_overhead_bytes"), + + RSS_OVERHEAD_RATIO("rss_overhead_ratio"), + + TOTAL_SYSTEM_MEMORY("total_system_memory"), + + TOTAL_SYSTEM_MEMORY_HUMAN("total_system_memory_human"), + + USED_MEMORY("used_memory"), + + USED_MEMORY_DATASET("used_memory_dataset"), + + USED_MEMORY_DATASET_PERC("used_memory_dataset_perc"), + + USED_MEMORY_HUMAN("used_memory_human"), + + USED_MEMORY_LUA("used_memory_lua"), + + USED_MEMORY_LUA_HUMAN("used_memory_lua_human"), + + USED_MEMORY_OVERHEAD("used_memory_overhead"), + + USED_MEMORY_PEAK("used_memory_peak"), + + USED_MEMORY_PEAK_HUMAN("used_memory_peak_human"), + + USED_MEMORY_PEAK_PERC("used_memory_peak_perc"), + + USED_MEMORY_RSS("used_memory_rss"), + + USED_MEMORY_RSS_HUMAN("used_memory_rss_human"), + + USED_MEMORY_SCRIPTS("used_memory_scripts"), + + USED_MEMORY_SCRIPTS_HUMAN("used_memory_scripts_human"), + + USED_MEMORY_STARTUP("used_memory_startup"); + + private final String value; + + Key(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + } + + /** + * RDB 持久化和 AOF 持久化有关的信息 + * + * @author Yong.Teng + */ + public final static class Persistence implements Serializable { + + private final static long serialVersionUID = 643244503594125194L; + + private final Properties properties; + + public Persistence(final Properties properties){ + this.properties = properties; + } + + /** + * 获取服务器启动时或者 AOF 重写最近一次执行之后,AOF 文件的大小 + * + * @return 服务器启动时或者 AOF 重写最近一次执行之后,AOF 文件的大小 + */ + public Long getAofBaseSize(){ + return PropertiesUtils.getLong(properties, Key.AOF_BASE_SIZE.value); + } + + /** + * 获取AOF 缓冲区的大小 + * + * @return AOF 缓冲区的大小 + */ + public Integer getAofBufferLength(){ + return PropertiesUtils.getInt(properties, Key.AOF_BUFFER_LENGTH.value); + } + + /** + * 获取如果服务器正在创建 AOF 文件,那么这个域记录的就是当前的创建操作已经耗费的秒数 + * + * @return 如果服务器正在创建 AOF 文件,那么这个域记录的就是当前的创建操作已经耗费的秒数 + */ + public Integer getAofCurrentRewriteTimeSec(){ + return PropertiesUtils.getInt(properties, Key.AOF_CURRENT_REWRITE_TIME_SEC.value); + } + + /** + * 获取AOF 文件目前的大小 + * + * @return AOF 文件目前的大小 + */ + public Long getAofCurrentSize(){ + return PropertiesUtils.getLong(properties, Key.AOF_CURRENT_SIZE.value); + } + + /** + * 获取被延迟的 fsync 调用数量 + * + * @return 被延迟的 fsync 调用数量 + */ + public Integer getAofDelayedFsync(){ + return PropertiesUtils.getInt(properties, Key.AOF_DELAYED_FSYNC.value); + } + + /** + * 获取AOF 是否处于打开状态 + * + * @return AOF 是否处于打开状态 + */ + public Boolean isAofEnabled(){ + return getAofEnabled(); + } + + /** + * 获取AOF 是否处于打开状态 + * + * @return AOF 是否处于打开状态 + */ + public Boolean getAofEnabled(){ + return getBoolean(properties, Key.AOF_ENABLED.value); + } + + /** + * 获取后台 I/O 队列里面,等待执行的 fsync 调用数量 + * + * @return 后台 I/O 队列里面,等待执行的 fsync 调用数量 + */ + public Integer getAofPendingBioFsync(){ + return PropertiesUtils.getInt(properties, Key.AOF_PENDING_BIO_FSYNC.value); + } + + /** + * 获取是否有 AOF 重写操作在等待 RDB 文件创建完毕之后执行 + * + * @return 是否有 AOF 重写操作在等待 RDB 文件创建完毕之后执行 + */ + public Boolean isAofPendingRewrite(){ + return getAofPendingRewrite(); + } + + /** + * 获取是否有 AOF 重写操作在等待 RDB 文件创建完毕之后执行 + * + * @return 是否有 AOF 重写操作在等待 RDB 文件创建完毕之后执行 + */ + public Boolean getAofPendingRewrite(){ + return getBoolean(properties, Key.AOF_PENDING_REWRITE.value); + } + + /** + * 获取AOF 重写缓冲区的大小 + * + * @return AOF 重写缓冲区的大小 + */ + public Integer getAofRewriteBufferLength(){ + return PropertiesUtils.getInt(properties, Key.AOF_REWRITE_BUFFER_LENGTH.value); + } + + /** + * 返回最后一次 bgrewriteaof 重写是否成功 + * + * @return 最后一次 bgrewriteaof 重写是否成功 + */ + public Status getAofLastBgRewriteStatus(){ + return getObject(properties, Key.AOF_LAST_BGREWRITE_STATUS.value); + } + + /** + * 返回最后一次执行 AOF 重写操作期间 copy-on-write 分配的字节大小 + * + * @return 最后一次执行 AOF 重写操作期间 copy-on-write 分配的字节大小 + */ + public Long getAofLastCowSize(){ + return PropertiesUtils.getLong(properties, Key.AOF_LAST_COW_SIZE.value); + } + + /** + * 获取最近一次创建 AOF 文件耗费的时长 + * + * @return 最近一次创建 AOF 文件耗费的时长 + */ + public Integer getAofLastRewriteTimeSec(){ + return PropertiesUtils.getInt(properties, Key.AOF_LAST_REWRITE_TIME_SEC.value); + } + + /** + * 返回最后一次 AOF 重写是否成功 + * + * @return 最后一次 AOF 重写是否成功 + */ + public Status getAofLastWriteStatus(){ + return getObject(properties, Key.AOF_LAST_WRITE_STATUS.value); + } + + /** + * 获取服务器是否正在创建 AOF 文件 + * + * @return 服务器是否正在创建 AOF 文件 + */ + public Boolean isAofRewriteInProgress(){ + return getAofRewriteInProgress(); + } + + /** + * 获取服务器是否正在创建 AOF 文件 + * + * @return 服务器是否正在创建 AOF 文件 + */ + public Boolean getAofRewriteInProgress(){ + return getBoolean(properties, Key.AOF_REWRITE_IN_PROGRESS.value); + } + + /** + * 获取在 RDB 文件创建完毕之后,是否需要执行预约的 AOF 重写操作 + * + * @return 在 RDB 文件创建完毕之后,是否需要执行预约的 AOF 重写操作 + */ + public Boolean isAofRewriteScheduled(){ + return getAofRewriteScheduled(); + } + + /** + * 获取在 RDB 文件创建完毕之后,是否需要执行预约的 AOF 重写操作 + * + * @return 在 RDB 文件创建完毕之后,是否需要执行预约的 AOF 重写操作 + */ + public Boolean getAofRewriteScheduled(){ + return getBoolean(properties, Key.AOF_REWRITE_SCHEDULED.value); + } + + /** + * 获取服务器是否正在载入持久化文件 + * + * @return 服务器是否正在载入持久化文件 + */ + public Boolean isLoading(){ + return getLoading(); + } + + /** + * 获取服务器是否正在载入持久化文件 + * + * @return 服务器是否正在载入持久化文件 + */ + public Boolean getLoading(){ + return getBoolean(properties, Key.LOADING.value); + } + + /** + * 获取服务器是否正在创建 RDB 文件 + * + * @return 服务器是否正在创建 RDB 文件 + */ + public Boolean isRdbBgSaveInProgress(){ + return getRdbBgSaveInProgress(); + } + + /** + * 获取服务器是否正在创建 RDB 文件 + * + * @return 服务器是否正在创建 RDB 文件 + */ + public Boolean getRdbBgSaveInProgress(){ + return getBoolean(properties, Key.RDB_BGSAVE_IN_PROGRESS.value); + } + + /** + * 获取距离最近一次成功创建持久化文件之后,经过了多少秒 + * + * @return 距离最近一次成功创建持久化文件之后,经过了多少秒 + */ + public Integer getRdbChangesSinceLastSave(){ + return PropertiesUtils.getInt(properties, Key.RDB_CHANGES_SINCE_LAST_SAVE.value); + } + + /** + * 获取如果服务器正在创建 RDB 文件,那么这个域记录的就是当前的创建操作已经耗费的秒数 + * + * @return 如果服务器正在创建 RDB 文件,那么这个域记录的就是当前的创建操作已经耗费的秒数 + */ + public Integer getRdbCurrentBgSaveTimeSec(){ + return PropertiesUtils.getInt(properties, Key.RDB_CURRENT_BGSAVE_TIME_SEC.value); + } + + /** + * 获取最近一次创建 RDB 文件的结果是成功还是失败 + * + * @return 最近一次创建 RDB 文件的结果是成功还是失败 + */ + public Status getRdbLastBgSaveStatus(){ + return getObject(properties, Key.RDB_LAST_BGSAVE_STATUS.value); + } + + /** + * 获取最近一次创建 RDB 文件耗费的秒数 + * + * @return 最近一次创建 RDB 文件耗费的秒数 + */ + public Integer getRdbLastBgSaveTimeSec(){ + return PropertiesUtils.getInt(properties, Key.RDB_LAST_BGSAVE_TIME_SEC.value); + } + + /** + * 最后一次执行 rdb 操作期间 copy-on-write 分配的字节大小(单位:byte) + * + * @return 最后一次执行 rdb 操作期间 copy-on-write 分配的字节大小 + */ + public Long getRdbLastCowSize(){ + return PropertiesUtils.getLong(properties, Key.RDB_LAST_COW_SIZE.value); + } + + /** + * 获取最近一次成功创建 RDB 文件的时间 + * + * @return 最近一次成功创建 RDB 文件的时间 + */ + public Date getRdbLastSaveTime(){ + return getDate(properties, Key.RDB_LAST_SAVE_TIME.getValue(), true); + } + + public String toPrettyString(){ + return Info.toPrettyString(properties); + } + + @Override + public String toString(){ + return Info.toString(properties); + } + + public enum Key { + + AOF_BASE_SIZE("aof_base_size"), + + AOF_BUFFER_LENGTH("aof_buffer_length"), + + AOF_CURRENT_REWRITE_TIME_SEC("aof_current_rewrite_time_sec"), + + AOF_CURRENT_SIZE("aof_current_size"), + + AOF_DELAYED_FSYNC("aof_delayed_fsync"), + + AOF_ENABLED("aof_enabled"), + + AOF_LAST_BGREWRITE_STATUS("aof_last_bgrewrite_status"), + + AOF_LAST_COW_SIZE("aof_last_cow_size"), + + AOF_LAST_REWRITE_TIME_SEC("aof_last_rewrite_time_sec"), + + AOF_LAST_WRITE_STATUS("aof_last_write_status"), + + AOF_PENDING_BIO_FSYNC("aof_pending_bio_fsync"), + + AOF_PENDING_REWRITE("aof_pending_rewrite"), + + AOF_REWRITE_BUFFER_LENGTH("aof_rewrite_buffer_length"), + + AOF_REWRITE_IN_PROGRESS("aof_rewrite_in_progress"), + + AOF_REWRITE_SCHEDULED("aof_rewrite_scheduled"), + + LOADING("loading"), + + RDB_BGSAVE_IN_PROGRESS("rdb_bgsave_in_progress"), + + RDB_CHANGES_SINCE_LAST_SAVE("rdb_changes_since_last_save"), + + RDB_CURRENT_BGSAVE_TIME_SEC("rdb_current_bgsave_time_sec"), + + RDB_LAST_BGSAVE_STATUS("rdb_last_bgsave_status"), + + RDB_LAST_BGSAVE_TIME_SEC("rdb_last_bgsave_time_sec"), + + RDB_LAST_COW_SIZE("rdb_last_cow_size"), + + RDB_LAST_SAVE_TIME("rdb_last_save_time"); + + private final String value; + + Key(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + } + + /** + * 一般统计信息 + * + * @author Yong.Teng + */ + public final static class Stats implements Serializable { + + private final static long serialVersionUID = 668423701291623945L; + + private final Properties properties; + + public Stats(final Properties properties){ + this.properties = properties; + } + + /** + * 返回主动垃圾碎片整理命中次数 + * + * @return 主动垃圾碎片整理命中次数 + */ + public Integer getActiveDefragHits(){ + return PropertiesUtils.getInt(properties, Key.ACTIVE_DEFRAG_HITS.value); + } + + /** + * 返回主动垃圾碎片整理 key 命中次数 + * + * @return 主动垃圾碎片整理 key 命中次数 + */ + public Integer getActiveDefragKeyHits(){ + return PropertiesUtils.getInt(properties, Key.ACTIVE_DEFRAG_KEY_HITS.value); + } + + /** + * 返回主动垃圾碎片整理 key 未命中次数 + * + * @return 主动垃圾碎片整理 key 未命中次数 + */ + public Integer getActiveDefragKeyMisses(){ + return PropertiesUtils.getInt(properties, Key.ACTIVE_DEFRAG_KEY_MISSES.value); + } + + /** + * 返回主动垃圾碎片整理未命中 + * + * @return 主动垃圾碎片整理未命中 + */ + public Integer getActiveDefragMisses(){ + return PropertiesUtils.getInt(properties, Key.ACTIVE_DEFRAG_MISSES.value); + } + + /** + * 获取因为过期而被自动删除的数据库键数量 + * + * @return 因为过期而被自动删除的数据库键数量 + */ + public Integer getExpiredKeys(){ + return PropertiesUtils.getInt(properties, Key.EXPIRED_KEYS.value); + } + + /** + * 获取过期 key 占总 key 比率 + * + * @return 过期 key 占总 key 比率 + */ + public Double getExpiredStalePerc(){ + return getPercent(properties, Key.EXPIRED_STALE_PERC.value); + } + + /** + * 返回过期计数 + * + * @return 过期计数 + */ + public Integer getExpiredTimeCapReachedCount(){ + return PropertiesUtils.getInt(properties, Key.EXPIRED_TIME_CAP_REACHED_COUNT.value); + } + + /** + * 获取因为最大内存容量限制而被驱逐(evict)的键数量 + * + * @return 因为最大内存容量限制而被驱逐(evict)的键数量 + */ + public Integer getEvictedKeys(){ + return PropertiesUtils.getInt(properties, Key.EVICTED_KEYS.value); + } + + /** + * 返回输入带宽,Redis 服务每秒读字节数(kbps) + * + * @return 输入带宽,Redis 服务每秒读字节数 + */ + public Integer getInstantaneousInputKbps(){ + return PropertiesUtils.getInt(properties, Key.INSTANTANEOUS_INPUT.value); + } + + /** + * 获取服务器每秒钟执行的命令数量 + * + * @return 服务器每秒钟执行的命令数量 + */ + public Integer getInstantaneousOpsPerSec(){ + return PropertiesUtils.getInt(properties, Key.INSTANTANEOUS_INPUT.value); + } + + /** + * 返回输出带宽,Redis 服务每秒写字节数(kbps) + * + * @return 输出带宽,Redis 服务每秒写字节数 + */ + public Integer getInstantaneousOutput(){ + return PropertiesUtils.getInt(properties, Key.INSTANTANEOUS_OUTPUT.value); + } + + /** + * 获取查找数据库键成功的次数 + * + * @return 查找数据库键成功的次数 + */ + public Integer getKeyspaceHits(){ + return PropertiesUtils.getInt(properties, Key.KEYSPACE_HITS.value); + } + + /** + * 获取查找数据库键失败的次数 + * + * @return 查找数据库键失败的次数 + */ + public Integer getKeyspaceMisses(){ + return PropertiesUtils.getInt(properties, Key.KEYSPACE_MISSES.value); + } + + /** + * 获取 最近一次 fork() 操作耗费的毫秒数 + * + * @return 最近一次 fork() 操作耗费的毫秒数 + */ + public Integer getLatestForkUsec(){ + return PropertiesUtils.getInt(properties, Key.LATEST_FORK_USEC.value); + } + + public Integer getMigrateCachedSockets(){ + return PropertiesUtils.getInt(properties, Key.MIGRATE_CACHED_SOCKETS.value); + } + + /** + * 获取目前被订阅的频道数量 + * + * @return 目前被订阅的频道数量 + */ + public Integer getPubsubChannels(){ + return PropertiesUtils.getInt(properties, Key.PUBSUB_CHANNELS.value); + } + + /** + * 获取目前被订阅的模式数量 + * + * @return 目前被订阅的模式数量 + */ + public Integer getPubsubPatterns(){ + return PropertiesUtils.getInt(properties, Key.PUBSUB_PATTERNS.value); + } + + /** + * 获取因为最大客户端数量限制而被拒绝的连接请求数量 + * + * @return 因为最大客户端数量限制而被拒绝的连接请求数量 + */ + public Integer getRejectedConnections(){ + return PropertiesUtils.getInt(properties, Key.REJECTED_CONNECTIONS.value); + } + + /** + * 返回从服务器中到期 key 数量 + * + * @return 从服务器中到期 key 数量 + */ + public Integer getSlaveExpiresTrackedKeys(){ + return PropertiesUtils.getInt(properties, Key.SLAVE_EXPIRES_TRACKED_KEYS.value); + } + + /** + * 返回主从之间数据同步完全成功次数 + * + * @return 主从之间数据同步完全成功次数 + */ + public Integer getSyncFull(){ + return PropertiesUtils.getInt(properties, Key.SYNC_FULL.value); + } + + /** + * 返回主从之间数据同步部分失败次数 + * + * @return 主从之间数据同步部分失败次数 + */ + public Integer getSyncPartialErr(){ + return PropertiesUtils.getInt(properties, Key.SYNC_PARTIAL_ERR.value); + } + + /** + * 返回主从之间数据同步部分成功次数 + * + * @return 主从之间数据同步部分成功次数 + */ + public Integer getSyncPartialOk(){ + return PropertiesUtils.getInt(properties, Key.SYNC_PARTIAL_OK.value); + } + + /** + * 获取服务器已执行的命令数量 + * + * @return 服务器已执行的命令数量 + */ + public Integer getTotalCommandsProcessed(){ + return PropertiesUtils.getInt(properties, Key.TOTAL_COMMANDS_PROCESSED.value); + } + + /** + * 获取服务器已接受的连接请求数量 + * + * @return 服务器已接受的连接请求数量 + */ + public Integer getTotalConnectionsReceived(){ + return PropertiesUtils.getInt(properties, Key.TOTAL_CONNECTIONS_RECEIVED.value); + } + + /** + * 返回 Redis 服务接受输入总数据量(单位: byte) + * + * @return Redis 服务接受输入总数据量 + */ + public Integer getTotalNetInput(){ + return PropertiesUtils.getInt(properties, Key.TOTAL_NET_INPUT.value); + } + + /** + * 返回 Redis 服务输出总数据量(单位: byte) + * + * @return Redis 服务输出总数据量 + */ + public Integer getTotalNetOutput(){ + return PropertiesUtils.getInt(properties, Key.TOTAL_NET_OUTPUT.value); + } + + public String toPrettyString(){ + return Info.toPrettyString(properties); + } + + @Override + public String toString(){ + return Info.toString(properties); + } + + public enum Key { + + ACTIVE_DEFRAG_HITS("active_defrag_hits"), + + ACTIVE_DEFRAG_KEY_HITS("active_defrag_key_hits"), + + ACTIVE_DEFRAG_KEY_MISSES("active_defrag_key_misses"), + + ACTIVE_DEFRAG_MISSES("active_defrag_misses"), + + EXPIRED_KEYS("expired_keys"), + + EXPIRED_STALE_PERC("expired_stale_perc"), + + EXPIRED_TIME_CAP_REACHED_COUNT("expired_time_cap_reached_count"), + + EVICTED_KEYS("evicted_keys"), + + INSTANTANEOUS_INPUT("instantaneous_input_kbps"), + + INSTANTANEOUS_OPS_PER_SEC("instantaneous_ops_per_sec"), + + INSTANTANEOUS_OUTPUT("instantaneous_output_kbps"), + + KEYSPACE_HITS("keyspace_hits"), + + KEYSPACE_MISSES("keyspace_misses"), + + LATEST_FORK_USEC("latest_fork_usec"), + + MIGRATE_CACHED_SOCKETS("migrate_cached_sockets"), + + PUBSUB_CHANNELS("pubsub_channels"), + + PUBSUB_PATTERNS("pubsub_patterns"), + + REJECTED_CONNECTIONS("rejected_connections"), + + SLAVE_EXPIRES_TRACKED_KEYS("slave_expires_tracked_keys"), + + SYNC_FULL("sync_full"), + + SYNC_PARTIAL_ERR("sync_partial_err"), + + SYNC_PARTIAL_OK("sync_partial_ok"), + + TOTAL_COMMANDS_PROCESSED("total_commands_processed"), + + TOTAL_CONNECTIONS_RECEIVED("total_connections_received"), + + TOTAL_NET_INPUT("total_net_input_bytes"), + + TOTAL_NET_OUTPUT("total_net_output_bytes"); + + private final String value; + + Key(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + } + + /** + * 主从复制信息 + * + * @author Yong.Teng + */ + public final static class Replication implements Serializable { + + private final static long serialVersionUID = 5728324218040813770L; + + private final Properties properties; + + public Replication(final Properties properties){ + this.properties = properties; + } + + /** + * 获取已连接的从服务器数量 + * + * @return 已连接的从服务器数量 + */ + public Integer getConnectedSlaves(){ + return PropertiesUtils.getInt(properties, Key.CONNECTED_SLAVES.value); + } + + /** + * 获取 Master 节点 + * + * @return Master 节点 + */ + public RedisNode getMaster(){ + return getObject(properties, Key.MASTER.value); + } + + /** + * 获取 Slave 节点 + * + * @return Slave 节点 + */ + public List getSlave(){ + return getObject(properties, Key.SLAVE.value); + } + + /** + * 获取距离最近一次与主服务器进行通信已经过去了多少秒钟 + * + * @return 距离最近一次与主服务器进行通信已经过去了多少秒钟 + */ + public Integer getMasterLastIoSecondsAgo(){ + return PropertiesUtils.getInt(properties, Key.MASTER_LAST_IO_SECONDS_AGO.value); + } + + /** + * 获取复制连接当前的状态,up 表示连接正常,down 表示连接断开 + * + * @return 复制连接当前的状态,up 表示连接正常,down 表示连接断开 + */ + public MasterLinkStatus getMasterLinkStatus(){ + return getObject(properties, Key.MASTER_LINK_STATUS.value); + } + + /** + * 获取主服务器是否正在与这个从服务器进行同步 + * + * @return 主服务器是否正在与这个从服务器进行同步 + */ + public Boolean isMasterSyncInProgress(){ + return getMasterSyncInProgress(); + } + + /** + * 获取主服务器是否正在与这个从服务器进行同步 + * + * @return 主服务器是否正在与这个从服务器进行同步 + */ + public Boolean getMasterSyncInProgress(){ + return getBoolean(properties, Key.MASTER_SYNC_IN_PROGRESS.value); + } + + /** + * 获取当前 master 记录的复制偏移量 + * + * @return 当前 master 记录的复制偏移量 + */ + public Integer getMasterReplOffset(){ + return PropertiesUtils.getInt(properties, Key.MASTER_REPL_OFFSET.value); + } + + /** + * 获取服务器的复制 ID + * + * @return 服务器的复制 ID + */ + public String getMasterReplId(){ + return PropertiesUtils.get(properties, Key.MASTER_REPL_ID.value); + } + + /** + * 获取第二服务器复制 ID + * + * @return 第二服务器复制 ID + */ + public String getMasterReplId2(){ + return PropertiesUtils.get(properties, Key.MASTER_REPL_ID2.value); + } + + public ReplBacklog getReplBackLog(){ + return getObject(properties, Key.REPL_BACK_LOG.value); + } + + /** + * 获取 Redis 服务器角色 + * + * @return Redis 服务器角色 + */ + public Role getRole(){ + return getObject(properties, Key.ROLE.value); + } + + /** + * 获取第二服务器复制偏移量 + * + * @return 第二服务器复制偏移量 + */ + public Integer getSecondReplOffset(){ + return PropertiesUtils.getInt(properties, Key.SECOND_REPL_OFFSET.value); + } + + public Integer getSlaveReplOffset(){ + return PropertiesUtils.getInt(properties, Key.SLAVE_REPL_OFFSET.value); + } + + public Integer getSlavePriority(){ + return PropertiesUtils.getInt(properties, Key.SLAVE_PRIORITY.value); + } + + /** + * 获取从节点是否为只读 + * + * @return 从节点是否为只读 + */ + public Boolean getSlaveReadOnly(){ + return getBoolean(properties, Key.SLAVE_READ_ONLY.value); + } + + public Integer getReplBackLogActive(){ + return PropertiesUtils.getInt(properties, Key.REPL_BACKLOG_ACTIVE.value); + } + + public Integer getReplBackLogSize(){ + return PropertiesUtils.getInt(properties, Key.REPL_BACKLOG_ACTIVE.value); + } + + public Integer getReplBackLogByteOffset(){ + return PropertiesUtils.getInt(properties, Key.REPL_BACKLOG_FIRST_BYTE_OFFSET.value); + } + + public Integer getReplBackLogHistLen(){ + return PropertiesUtils.getInt(properties, Key.REPL_BACKLOG_FIRST_BYTE_OFFSET.value); + } + + public String toPrettyString(){ + return Info.toPrettyString(properties); + } + + @Override + public String toString(){ + return Info.toString(properties); + } + + public enum Key { + + CONNECTED_SLAVES("connected_slaves"), + + MASTER("master"), + + SLAVE("slave"), + + MASTER_LAST_IO_SECONDS_AGO("master_last_io_seconds_ago"), + + MASTER_LINK_STATUS("master_link_status"), + + MASTER_SYNC_IN_PROGRESS("master_sync_in_progress"), + + MASTER_REPL_OFFSET("master_repl_offset"), + + MASTER_REPL_ID("master_replid"), + + MASTER_REPL_ID2("master_replid2"), + + REPL_BACK_LOG("repl_back_log"), + + ROLE("role"), + + SECOND_REPL_OFFSET("second_repl_offset"), + + SLAVE_REPL_OFFSET("slave_repl_offset"), + + SLAVE_PRIORITY("slave_priority"), + + SLAVE_READ_ONLY("slave_read_only"), + + REPL_BACKLOG_ACTIVE("repl_backlog_active"), + + REPL_BACKLOG_SIZE("repl_backlog_size"), + + REPL_BACKLOG_FIRST_BYTE_OFFSET("repl_backlog_first_byte_offset"), + + REPL_BACKLOG_HISTLEN("repl_backlog_histlen"); + + private final String value; + + Key(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + public enum MasterLinkStatus { + + UP("up"), + + DOWN("down"); + + private final String value; + + MasterLinkStatus(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + public final static class Slave extends RedisServer implements Serializable { + + private final static long serialVersionUID = 2989042827385297339L; + + private final Properties properties; + + public Slave(final Properties properties){ + super(PropertiesUtils.get(properties, Key.IP.value), + PropertiesUtils.getInt(properties, Key.PORT.value)); + this.properties = properties; + } + + /** + * 获取从服务器状态 + * + * @return 从服务器状态 + */ + public SlaveState getState(){ + return getObject(properties, Key.STATE.value); + } + + /** + * 获取复制偏移量 + * + * @return 复制偏移量 + */ + public Integer getOffset(){ + return PropertiesUtils.getInt(properties, Key.OFFSET.value); + } + + /** + * 获取复制延迟 + * + * @return 复制延迟 + */ + public Integer getLag(){ + return PropertiesUtils.getInt(properties, Key.LAG.value); + } + + @Override + public String toString(){ + return "ip=" + getIp() + ", port=" + getPort() + ", state=" + getState() + ", offset=" + getOffset() + + ", " + "lag=" + getLag(); + } + + public enum Key { + + IP("ip"), + + PORT("port"), + + STATE("state"), + + OFFSET("offset"), + + LAG("lag"); + + private final String value; + + Key(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + public enum SlaveState { + + ONLINE("online"); + + private final String value; + + SlaveState(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + } + + public final static class ReplBacklog implements Serializable { + + private final static long serialVersionUID = 1468810894033878876L; + + private final Properties properties; + + public ReplBacklog(final Properties properties){ + this.properties = properties; + } + + public Integer getActive(){ + return PropertiesUtils.getInt(properties, Key.ACTIVE.value); + } + + public Integer getSize(){ + return PropertiesUtils.getInt(properties, Key.SIZE.value); + } + + public Integer getFirstByteOffset(){ + return PropertiesUtils.getInt(properties, Key.FIRST_BYTE_OFFSET.value); + } + + public Integer getHistlen(){ + return PropertiesUtils.getInt(properties, Key.HISTLEN.value); + } + + public String toPrettyString(){ + return Info.toPrettyString(properties); + } + + @Override + public String toString(){ + return Info.toString(properties); + } + + public enum Key { + + ACTIVE("repl_backlog_active"), + + SIZE("repl_backlog_size"), + + FIRST_BYTE_OFFSET("repl_backlog_first_byte_offset"), + + HISTLEN("repl_backlog_histlen"); + + private final String value; + + Key(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + } + + } + + /** + * 哨兵信息 + * + * @author Yong.Teng + */ + public final static class Sentinel implements Serializable { + + private final static long serialVersionUID = 1740259200282640149L; + + private final Properties properties; + + public Sentinel(Properties properties){ + this.properties = properties; + } + + /** + * 获取 Master 节点列表 + * + * @return Master 节点列表 + */ + public List getMasters(){ + return getObject(properties, Key.MASTERS.value); + } + + /** + * 获取 sentinel 正在运行的脚本数量 + * + * @return sentinel 正在运行的脚本数量 + */ + public Integer getRunningScripts(){ + return PropertiesUtils.getInt(properties, Key.RUNNING_SCRIPTS.value); + } + + /** + * 获取 Master 数量 + * + * @return Master 数量 + */ + public Integer getSentinelMasters(){ + return PropertiesUtils.getInt(properties, Key.SENTINEL_MASTERS.value); + } + + /** + * 获取是否进入了 tilt 模式 + * + * @return 是否进入了 tilt 模式 + */ + public Boolean isTilt(){ + return getTilt(); + } + + /** + * 获取是否进入了 tilt 模式 + * + * @return 是否进入了 tilt 模式 + */ + public Boolean getTilt(){ + return getBoolean(properties, Key.TILT.value); + } + + /** + * 获取 sentinel 在队列中正在排队的脚本的个数 + * + * @return sentinel 在队列中正在排队的脚本的个数 + */ + public Integer getScriptsQueueLength(){ + return PropertiesUtils.getInt(properties, Key.SCRIPTS_QUEUE_LENGTH.value); + } + + public Integer getSentinelSimulateFailureFlags(){ + return PropertiesUtils.getInt(properties, Key.SIMULATE_FAILURE_FLAGS.value); + } + + public String toPrettyString(){ + return Info.toPrettyString(properties); + } + + @Override + public String toString(){ + return Info.toString(properties); + } + + public enum Key { + + MASTERS("masters"), + + RUNNING_SCRIPTS("sentinel_running_scripts"), + + SENTINEL_MASTERS("sentinel_masters"), + + TILT("sentinel_tilt"), + + SCRIPTS_QUEUE_LENGTH("sentinel_scripts_queue_length"), + + SIMULATE_FAILURE_FLAGS("sentinel_simulate_failure_flags"); + + private final String value; + + Key(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + public final static class Master extends RedisNode implements Serializable { + + private final static long serialVersionUID = 5058163948650311361L; + + private final Properties properties; + + public Master(Properties properties){ + super(PropertiesUtils.get(properties, Key.HOST.value), + PropertiesUtils.getInt(properties, Key.PORT.value)); + setName(PropertiesUtils.get(properties, Key.NAME.value)); + this.properties = properties; + } + + /** + * 获取状态 + * + * @return 状态 + */ + public HostAndPort getAddress(){ + return getObject(properties, Key.ADDRESS.value); + } + + /** + * 获取状态 + * + * @return 状态 + */ + public Status getStatus(){ + return getObject(properties, Key.STATUS.value); + } + + /** + * 获取从节点数量 + * + * @return 从节点数量 + */ + public Integer getSlaves(){ + return PropertiesUtils.getInt(properties, Key.SENTINELS.value); + } + + /** + * 获取哨兵节点数量 + * + * @return 哨兵节点数量 + */ + public Integer getSentinels(){ + return PropertiesUtils.getInt(properties, Key.SLAVES.value); + } + + @Override + public String toString(){ + return "name=" + getName() + ", status=" + getStatus() + ", address=" + getAddress() + ", slaves=" + + getSlaves() + ", sentinels=" + getSentinels(); + } + + public enum Key { + + ADDRESS("address"), + + HOST("host"), + + NAME("name"), + + PORT("port"), + + STATUS("status"), + + SLAVES("slaves"), + + SENTINELS("sentinels"); + + private final String value; + + Key(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + } + + public enum Status { + + OK("ok"), + + SDOWN("sdown"), + + ODOWN("odown"); + + private final String value; + + Status(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + } + + /** + * CPU 的计算量统计信息 + * + * @author Yong.Teng + */ + public final static class Cpu implements Serializable { + + private final static long serialVersionUID = 7374909500664048450L; + + private final Properties properties; + + public Cpu(Properties properties){ + this.properties = properties; + } + + /** + * 获取 Redis 服务器耗费的系统 CPU + * + * @return Redis 服务器耗费的系统 CPU + */ + public Double getUsedSys(){ + return PropertiesUtils.getDouble(properties, Key.USED_SYS.value); + } + + /** + * 获取 Redis 后台进程耗费的系统 CPU + * + * @return Redis 后台进程耗费的系统 CPU + */ + public Double getUsedSysChildren(){ + return PropertiesUtils.getDouble(properties, Key.USED_SYS_CHILDREN.value); + } + + /** + * 获取 Redis 服务器耗费的用户 CPU + * + * @return Redis 服务器耗费的用户 CPU + */ + public Double getUsedCpuUser(){ + return PropertiesUtils.getDouble(properties, Key.USED_USER.value); + } + + /** + * 获取 Redis 后台进程耗费的用户 CPU + * + * @return Redis 后台进程耗费的用户 CPU + */ + public Double getUsedUserChildren(){ + return PropertiesUtils.getDouble(properties, Key.USED_USER_CHILDREN.value); + } + + public String toPrettyString(){ + return Info.toPrettyString(properties); + } + + @Override + public String toString(){ + return Info.toString(properties); + } + + public enum Key { + + USED_SYS("used_cpu_sys"), + + USED_SYS_CHILDREN("used_cpu_sys_children"), + + USED_USER("used_cpu_user"), + + USED_USER_CHILDREN("used_cpu_user_children"); + + private final String value; + + Key(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + } + + /** + * 集群有关的信息 + * + * @author Yong.Teng + */ + public final static class Cluster implements Serializable { + + private final static long serialVersionUID = 1616257693468570678L; + + private final Properties properties; + + public Cluster(final Properties properties){ + this.properties = properties; + } + + /** + * 获取集群功能是否已经开启 + * + * @return 获取集群功能是否已经开启 + */ + public Boolean isEnabled(){ + return getEnabled(); + } + + /** + * 获取集群功能是否已经开启 + * + * @return 获取集群功能是否已经开启 + */ + public Boolean getEnabled(){ + return getBoolean(properties, Key.ENABLED.value); + } + + public String toPrettyString(){ + return Info.toPrettyString(properties); + } + + @Override + public String toString(){ + return Info.toString(properties); + } + + public enum Key { + + ENABLED("cluster_enabled"); + + private final String value; + + Key(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + } + + /** + * 数据库相关的统计信息 + * + * @author Yong.Teng + */ + public final static class Keyspace implements Serializable { + + private final static long serialVersionUID = -5023410132423250601L; + + private final Properties properties; + + public Keyspace(final Properties properties){ + this.properties = properties; + } + + public Long getAvgTtl(){ + return PropertiesUtils.getLong(properties, Key.AVG_TTL.value); + } + + /** + * 获取数据库 + * + * @return 数据库 + */ + public Integer getDb(){ + return PropertiesUtils.getInt(properties, Key.DB.value); + } + + /** + * 获取带有生存期的 Key 的数量 + * + * @return 带有生存期的 Key 的数量 + */ + public Integer getExpires(){ + return PropertiesUtils.getInt(properties, Key.EXPIRES.value); + } + + /** + * 获取 Key 数量 + * + * @return Key 数量 + */ + public Integer getKeys(){ + return PropertiesUtils.getInt(properties, Key.KEYS.value); + } + + public String toPrettyString(){ + return toString(); + } + + @Override + public String toString(){ + final StringJoiner stringJoiner = new StringJoiner(", "); + + stringJoiner.add("db=" + getDb()).add("keys=" + getKeys()).add("expires=" + getExpires()) + .add("avg_ttl=" + getAvgTtl()); + + return stringJoiner.toString(); + } + + public enum Key { + + AVG_TTL("avg_ttl"), + + DB("db"), + + EXPIRES("expires"), + + KEYS("keys"); + + private final String value; + + Key(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/Keyword.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/Keyword.java new file mode 100644 index 000000000..4eae2fa2b --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/Keyword.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.core.Rawable; +import com.buession.core.Value; + +/** + * 关键字 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface Keyword extends Value, Rawable { + + enum Common { + ABSTTL, + + BCAST, + + CH, + + ID, + + COUNT, + + ANY, + + IDLETIME, + + FREQ, + + USER, + + TYPE, + + ADDR, + + LADDR, + + SKIPME, + + MAXAGE, + + REPLACE, + + REDIRECT, + + PREFIX, + + OPTIN, + + OPTOUT, + + NOLOOP, + + AUTH, + + AUTH2, + + SETNAME, + + KEYS, + + KEEPTTL, + + YES, + + NO, + + ON, + + OFF + } + + enum Key { + MATCH, + + NOVALUES + } + + enum Geo { + FROMMEMBER, + + FROMLONLAT, + + BYRADIUS, + + BYBOX, + + WITHCOORD, + + WITHDIST, + + WITHHASH, + + STOREDIST + } + + enum Hash { + FIELDS, + + WITHVALUES + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/MaxMemoryPolicy.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/MaxMemoryPolicy.java new file mode 100644 index 000000000..4a025ef2b --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/MaxMemoryPolicy.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +/** + * @author Yong.Teng + */ +public enum MaxMemoryPolicy { + + /** + * 最近最少使用算法,从设置了过期时间的键中选择空转时间最长的键值对清除掉 + */ + VOLATILE_LRU("volatile-lru"), + + /** + * 最近最不经常使用算法,从设置了过期时间的键中选择某段时间之内使用频次最小的键值对清除掉 + */ + VOLATILE_LFU("volatile-lfu"), + + /** + * 从设置了过期时间的键中选择过期时间最早的键值对清除 + */ + VOLATILE_TTL("volatile-ttl"), + + /** + * 从设置了过期时间的键中,随机选择键进行清除 + */ + VOLATILE_RANDOM("volatile-random"), + + /** + * 最近最少使用算法,从所有的键中选择空转时间最长的键值对清除 + */ + ALLKEYS_LRU("allkeys-lru"), + + /** + * 最近最不经常使用算法,从所有的键中选择某段时间之内使用频次最少的键值对清除 + */ + ALLKEYS_LFU("allkeys-lfu"), + + /** + * 所有的键中,随机选择键进行删除 + */ + ALLKEYS_RANDOM("allkeys-random"), + + /** + * 不做任何的清理工作,在redis的内存超过限制之后,所有的写入操作都会返回错误;但是读操作都能正常的进行 + */ + NOEVICTION("noeviction"); + + private final String value; + + MaxMemoryPolicy(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + @Override + public String toString(){ + return getValue(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/MemoryStats.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/MemoryStats.java new file mode 100644 index 000000000..a7c68eef8 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/MemoryStats.java @@ -0,0 +1,689 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +/** + * @author Yong.Teng + * @since 2.0.0 + */ +public class MemoryStats implements Serializable { + + private final static long serialVersionUID = -5308964580953471955L; + + /** + * 全部数据所使用的内存{for dataset.bytes} + */ + private Long dataset; + + /** + * redis 数据占用内存占总内存分配的百分比{for dataset.percentage} + */ + private Double datasetPercentage; + + /** + * 常驻内存开销大小{for rss-overhead.bytes} + */ + private Long rssOverhead; + + /** + * 常驻内存开销比例{for rss-overhead.ratio} + */ + private Double rssOverheadRatio; + + /** + * 当前内存使用量与峰值时的占比{for peak.percentage} + */ + private Double peakPercentage; + + /** + * Aof 持久化使用的缓存和 Aof Rewrite 时产生的缓存之和,若关闭了 appendonly 则为 0{for aof.buffer} + */ + private Long aofBuffer; + + /** + * 平均每一个 key 的内存大小{for keys.bytes-per-key} + */ + private Long keysBytesPerKey; + + /** + * 分配器分配的内存{for allocator.allocated} + */ + private Long allocatorAllocated; + + /** + * used_memory_rss 和 used_memory 的差值 {for allocator-fragmentation.bytes} + */ + private Long allocatorFragmentation; + + /** + * used_memory_rss Redis从系统申请的内存和 used_memory Redis 给数据分配的内存的比率;不仅包括碎片,还包括其他进程及代码、共享库、堆栈的内存开销等等{for allocator + * -fragmentation.ratio} + */ + private Double allocatorFragmentationRatio; + + /** + * 分配器活动页中的字节量,包含外部碎片{for allocator.active} + */ + private Long allocatorActive; + + /** + * 分配器的常驻内存大小{for allocator-rss.bytes} + */ + private Long allocatorRss; + + /** + * 分配器常驻内存比例{for allocator-rss.ratio} + */ + private Double allocatorRssRatio; + + /** + * 分配器包含的总字节量{for allocator.resident} + */ + private Long allocatorResident; + + /** + * 所有常规客户端消耗内存节字数{for clients.normal} + */ + private Long clientsNormal; + + /** + * 所有 slave clients 消耗的内存字节数{for clients.slaves} + */ + private Long clientsSlaves; + + /** + * 内存碎片{for fragmentation.bytes} + */ + private Long fragmentation; + + /** + * 内存碎片率{for fragmentation} + */ + private Double fragmentationRatio; + + /** + * Lua 脚本缓存开销内存节字数{for lua.caches} + */ + private Long luaCaches; + + /** + * redis 启动至今,最多使用过多少内存{for peak.allocated} + */ + private Long peakAllocated; + + /** + * 当前使用的内存总量{for total.allocated} + */ + private Long totalAllocated; + + /** + * 主从复制 backlog 使用的内存{for replication.backlog} + */ + private Long replicationBacklog; + + /** + * redis 启动完成使用的内存字节数{for startup.allocated} + */ + private Long startupAllocated; + + /** + * redis 额外的总开销内存字节数;即分配器分配的总内存 total.allocated,减去数据实际存储使用内存{for overhead.total} + */ + private Long overheadTotal; + + /** + * key 总量{for keys.count} + */ + private Long keysCount; + + /** + * 每个 DB 统计{for db.x} + */ + private Map dbs; + + /** + * 返回全部数据所使用的内存 + * + * @return 全部数据所使用的内存{for dataset.bytes} + */ + public Long getDataset() { + return dataset; + } + + /** + * 设置全部数据所使用的内存{for dataset.bytes} + * + * @param dataset + * 全部数据所使用的内存 + */ + public void setDataset(Long dataset) { + this.dataset = dataset; + } + + /** + * 返回 redis 数据占用内存占总内存分配的百分比 + * + * @return redis 数据占用内存占总内存分配的百分比{for dataset.percentage} + */ + public Double getDatasetPercentage() { + return datasetPercentage; + } + + /** + * 设置 redis 数据占用内存占总内存分配的百分比{for dataset.percentage} + * + * @param datasetPercentage + * redis 数据占用内存占总内存分配的百分比 + */ + public void setDatasetPercentage(Double datasetPercentage) { + this.datasetPercentage = datasetPercentage; + } + + /** + * 返回常驻内存开销大小{for rss-overhead.bytes} + * + * @return 常驻内存开销大小 + */ + public Long getRssOverhead() { + return rssOverhead; + } + + /** + * 设置常驻内存开销大小{for rss-overhead.bytes} + * + * @param rssOverhead + * 常驻内存开销大小 + */ + public void setRssOverhead(Long rssOverhead) { + this.rssOverhead = rssOverhead; + } + + /** + * 返回常驻内存开销比例{for rss-overhead.ratio} + * + * @return 常驻内存开销比例{for rss-overhead.ratio} + */ + public Double getRssOverheadRatio() { + return rssOverheadRatio; + } + + /** + * 设置常驻内存开销比例{for rss-overhead.ratio} + * + * @param rssOverheadRatio + * 常驻内存开销比例 + */ + public void setRssOverheadRatio(Double rssOverheadRatio) { + this.rssOverheadRatio = rssOverheadRatio; + } + + /** + * 返回当前内存使用量与峰值时的占比{for peak.percentage} + * + * @return 当前内存使用量与峰值时的占比 + */ + public Double getPeakPercentage() { + return peakPercentage; + } + + /** + * 设置当前内存使用量与峰值时的占比{for peak.percentage} + * + * @param peakPercentage + * 当前内存使用量与峰值时的占比 + */ + public void setPeakPercentage(Double peakPercentage) { + this.peakPercentage = peakPercentage; + } + + /** + * 返回 Aof 持久化使用的缓存和 Aof Rewrite 时产生的缓存之和{for aof.buffer} + * + * @return Aof 持久化使用的缓存和 Aof Rewrite 时产生的缓存之和,若关闭了 appendonly 则为 0 + */ + public Long getAofBuffer() { + return aofBuffer; + } + + /** + * 设置 Aof 持久化使用的缓存和 Aof Rewrite 时产生的缓存之和{for aof.buffer} + * + * @param aofBuffer + * Aof 持久化使用的缓存和 Aof Rewrite 时产生的缓存之和 + */ + public void setAofBuffer(Long aofBuffer) { + this.aofBuffer = aofBuffer; + } + + /** + * 返回平均每一个 key 的内存大小{for keys.bytes-per-key} + * + * @return 平均每一个 key 的内存大小 + */ + public Long getKeysBytesPerKey() { + return keysBytesPerKey; + } + + /** + * 设置平均每一个 key 的内存大小{for keys.bytes-per-key} + * + * @param keysBytesPerKey + * 平均每一个 key 的内存大小 + */ + public void setKeysBytesPerKey(Long keysBytesPerKey) { + this.keysBytesPerKey = keysBytesPerKey; + } + + /** + * 返回分配器分配的内存{for allocator.allocated} + * + * @return 分配器分配的内存 + */ + public Long getAllocatorAllocated() { + return allocatorAllocated; + } + + /** + * 设置分配器分配的内存{for allocator.allocated} + * + * @param allocatorAllocated + * 分配器分配的内存 + */ + public void setAllocatorAllocated(Long allocatorAllocated) { + this.allocatorAllocated = allocatorAllocated; + } + + /** + * 返回 used_memory_rss 和 used_memory 的差值 {for allocator-fragmentation.bytes} + * + * @return used_memory_rss 和 used_memory 的差值 + */ + public Long getAllocatorFragmentation() { + return allocatorFragmentation; + } + + /** + * 设置 used_memory_rss 和 used_memory 的差值 {for allocator-fragmentation.bytes} + * + * @param allocatorFragmentation + * used_memory_rss 和 used_memory 的差值 + */ + public void setAllocatorFragmentation(Long allocatorFragmentation) { + this.allocatorFragmentation = allocatorFragmentation; + } + + /** + * 返回 used_memory_rss Redis从系统申请的内存和 used_memory Redis 给数据分配的内存的比率;不仅包括碎片,还包括其他进程及代码、共享库、堆栈的内存开销等等{for allocator + * -fragmentation.ratio} + * + * @return used_memory_rss Redis从系统申请的内存和 used_memory Redis 给数据分配的内存的比率 + */ + public Double getAllocatorFragmentationRatio() { + return allocatorFragmentationRatio; + } + + /** + * 设置 used_memory_rss Redis从系统申请的内存和 used_memory Redis 给数据分配的内存的比率;不仅包括碎片,还包括其他进程及代码、共享库、堆栈的内存开销等等{for allocator-fragmentation.ratio} + * + * @param allocatorFragmentationRatio + * used_memory_rss Redis从系统申请的内存和 used_memory Redis 给数据分配的内存的比率 + */ + public void setAllocatorFragmentationRatio(Double allocatorFragmentationRatio) { + this.allocatorFragmentationRatio = allocatorFragmentationRatio; + } + + /** + * 返回分配器活动页中的字节量,包含外部碎片{for allocator.active} + * + * @return 分配器活动页中的字节量,包含外部碎片 + */ + public Long getAllocatorActive() { + return allocatorActive; + } + + /** + * 设置分配器活动页中的字节量,包含外部碎片{for allocator.active} + * + * @param allocatorActive + * 分配器活动页中的字节量 + */ + public void setAllocatorActive(Long allocatorActive) { + this.allocatorActive = allocatorActive; + } + + /** + * 返回分配器的常驻内存大小{for allocator-rss.bytes} + * + * @return 分配器的常驻内存大小 + */ + public Long getAllocatorRss() { + return allocatorRss; + } + + /** + * 设置分配器的常驻内存大小{for allocator-rss.bytes} + * + * @param allocatorRss + * 分配器的常驻内存大小 + */ + public void setAllocatorRss(Long allocatorRss) { + this.allocatorRss = allocatorRss; + } + + /** + * 返回分配器常驻内存比例{for allocator-rss.ratio} + * + * @return 分配器常驻内存比例 + */ + public Double getAllocatorRssRatio() { + return allocatorRssRatio; + } + + /** + * 设置分配器常驻内存比例{for allocator-rss.ratio} + * + * @param allocatorRssRatio + * 分配器常驻内存比例 + */ + public void setAllocatorRssRatio(Double allocatorRssRatio) { + this.allocatorRssRatio = allocatorRssRatio; + } + + /** + * 返回分配器包含的总字节量{for allocator.resident} + * + * @return 分配器包含的总字节量 + */ + public Long getAllocatorResident() { + return allocatorResident; + } + + /** + * 设置分配器包含的总字节量{for allocator.resident} + * + * @param allocatorResident + * 分配器包含的总字节量 + */ + public void setAllocatorResident(Long allocatorResident) { + this.allocatorResident = allocatorResident; + } + + /** + * 返回所有常规客户端消耗内存节字数{for clients.normal} + * + * @return 所有常规客户端消耗内存节字数 + */ + public Long getClientsNormal() { + return clientsNormal; + } + + /** + * 设置所有常规客户端消耗内存节字数{for clients.normal} + * + * @param clientsNormal + * 所有常规客户端消耗内存节字数 + */ + public void setClientsNormal(Long clientsNormal) { + this.clientsNormal = clientsNormal; + } + + /** + * 返回所有 slave clients 消耗的内存字节数{for clients.slaves} + * + * @return 所有 slave clients 消耗的内存字节数 + */ + public Long getClientsSlaves() { + return clientsSlaves; + } + + /** + * 设置所有 slave clients 消耗的内存字节数{for clients.slaves} + * + * @param clientsSlaves + * 所有 slave clients 消耗的内存字节数 + */ + public void setClientsSlaves(Long clientsSlaves) { + this.clientsSlaves = clientsSlaves; + } + + /** + * 返回内存碎片{for fragmentation.bytes} + * + * @return 内存碎片 + */ + public Long getFragmentation() { + return fragmentation; + } + + /** + * 设置内存碎片{for fragmentation.bytes} + * + * @param fragmentation + * 内存碎片 + */ + public void setFragmentation(Long fragmentation) { + this.fragmentation = fragmentation; + } + + /** + * 返回内存碎片率{for fragmentation} + * + * @return 内存碎片率 + */ + public Double getFragmentationRatio() { + return fragmentationRatio; + } + + /** + * 设置内存碎片率{for fragmentation} + * + * @param fragmentationRatio + * 内存碎片率 + */ + public void setFragmentationRatio(Double fragmentationRatio) { + this.fragmentationRatio = fragmentationRatio; + } + + /** + * 返回 Lua 脚本缓存开销内存节字数{for lua.caches} + * + * @return Lua 脚本缓存开销内存节字数 + */ + public Long getLuaCaches() { + return luaCaches; + } + + /** + * 设置 Lua 脚本缓存开销内存节字数{for lua.caches} + * + * @param luaCaches + * Lua 脚本缓存开销内存节字数 + */ + public void setLuaCaches(Long luaCaches) { + this.luaCaches = luaCaches; + } + + /** + * 返回 redis 启动至今,最多使用过多少内存{for peak.allocated} + * + * @return redis 启动至今,最多使用过多少内存 + */ + public Long getPeakAllocated() { + return peakAllocated; + } + + /** + * 设置 redis 启动至今,最多使用过多少内存{for peak.allocated} + * + * @param peakAllocated + * redis 启动至今,最多使用过多少内存 + */ + public void setPeakAllocated(Long peakAllocated) { + this.peakAllocated = peakAllocated; + } + + /** + * 返回当前使用的内存总量{for total.allocated} + * + * @return 当前使用的内存总量 + */ + public Long getTotalAllocated() { + return totalAllocated; + } + + /** + * 设置当前使用的内存总量{for total.allocated} + * + * @param totalAllocated + * 当前使用的内存总量 + */ + public void setTotalAllocated(Long totalAllocated) { + this.totalAllocated = totalAllocated; + } + + /** + * 返回主从复制 backlog 使用的内存{for replication.backlog} + * + * @return 主从复制 backlog 使用的内存 + */ + public Long getReplicationBacklog() { + return replicationBacklog; + } + + /** + * 设置主从复制 backlog 使用的内存{for replication.backlog} + * + * @param replicationBacklog + * 主从复制 backlog 使用的内存 + */ + public void setReplicationBacklog(Long replicationBacklog) { + this.replicationBacklog = replicationBacklog; + } + + /** + * 返回 redis 启动完成使用的内存字节数{for startup.allocated} + * + * @return redis 启动完成使用的内存字节数 + */ + public Long getStartupAllocated() { + return startupAllocated; + } + + /** + * 设置 redis 启动完成使用的内存字节数{for startup.allocated} + * + * @param startupAllocated + * redis 启动完成使用的内存字节数 + */ + public void setStartupAllocated(Long startupAllocated) { + this.startupAllocated = startupAllocated; + } + + /** + * 返回 redis 额外的总开销内存字节数;即分配器分配的总内存 total.allocated,减去数据实际存储使用内存{for overhead.total} + * + * @return redis 额外的总开销内存字节数 + */ + public Long getOverheadTotal() { + return overheadTotal; + } + + /** + * 设置 redis 额外的总开销内存字节数;即分配器分配的总内存 total.allocated,减去数据实际存储使用内存{for overhead.total} + * + * @param overheadTotal + * redis 额外的总开销内存字节数;即分配器分配的总内存 total.allocated,减去数据实际存储使用内存 + */ + public void setOverheadTotal(Long overheadTotal) { + this.overheadTotal = overheadTotal; + } + + /** + * 返回 key 总量{for keys.count} + * + * @return key 总量 + */ + public Long getKeysCount() { + return keysCount; + } + + /** + * 设置 key 总量{for keys.count} + * + * @param keysCount + * key 总量 + */ + public void setKeysCount(Long keysCount) { + this.keysCount = keysCount; + } + + /** + * 返回每个 DB 统计{for db.x} + * + * @return 每个 DB 统计 + */ + public Map getDbs() { + return dbs; + } + + /** + * 设置每个 DB 统计{for db.x} + * + * @param dbs + * 每个 DB 统计 + */ + public void setDbs(Map dbs) { + this.dbs = dbs; + } + + public final static class Db { + + private long overheadHashTableMain; + + private long overheadHashTableExpires; + + public long getOverheadHashTableMain() { + return overheadHashTableMain; + } + + public void setOverheadHashTableMain(long overheadHashTableMain) { + this.overheadHashTableMain = overheadHashTableMain; + } + + public long getOverheadHashTableExpires() { + return overheadHashTableExpires; + } + + public void setOverheadHashTableExpires(long overheadHashTableExpires) { + this.overheadHashTableExpires = overheadHashTableExpires; + } + + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/KeyedZSetElement.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/Module.java similarity index 67% rename from buession-redis/src/main/java/com/buession/redis/core/KeyedZSetElement.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/Module.java index 064b622ea..c36b5c28f 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/KeyedZSetElement.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/Module.java @@ -25,54 +25,49 @@ package com.buession.redis.core; import com.buession.redis.utils.ObjectStringBuilder; -import com.buession.redis.utils.SafeEncoder; -import java.util.Arrays; +import java.io.Serializable; +import java.util.Objects; /** * @author Yong.Teng * @since 2.0.0 */ -public class KeyedZSetElement extends Tuple { +public final class Module implements Serializable { - private final static long serialVersionUID = -8468320641916277445L; + private final static long serialVersionUID = 8584149197825340590L; - private final byte[] key; + private final String name; - public KeyedZSetElement(final String key, final String element, final Double score){ - super(element, score); - this.key = SafeEncoder.encode(key); - } + private final int version; - public KeyedZSetElement(final byte[] key, final byte[] element, final Double score){ - super(element, score); - this.key = key; + public Module(final String name, final int version){ + this.name = name; + this.version = version; } - public String getKey(){ - return key == null ? null : SafeEncoder.encode(key); + public String getName(){ + return name; } - public byte[] getBinaryKey(){ - return key; + public int getVersion(){ + return version; } @Override public int hashCode(){ - int result = super.hashCode(); - result = 31 * result + Arrays.hashCode(key); - return result; + return Objects.hash(name, version); } @Override public boolean equals(Object obj){ - if(this == obj){ + if(obj == this){ return true; } - if(obj instanceof KeyedZSetElement){ - KeyedZSetElement that = (KeyedZSetElement) obj; - return Arrays.equals(key, that.key) && super.equals(obj); + if(obj instanceof Module){ + Module that = (Module) obj; + return Objects.equals(name, that.name) && version == that.version; } return false; @@ -81,8 +76,8 @@ public boolean equals(Object obj){ @Override public String toString(){ return ObjectStringBuilder.create() - .add("key", key) - .append(super.toString()) + .add("name", name) + .add("version", version) .build(); } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/ObjectEncoding.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ObjectEncoding.java new file mode 100644 index 000000000..1995969cd --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ObjectEncoding.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +/** + * 详细信息请看,https://redis.io/commands/object-encoding/ + * + * @author Yong.Teng + * @since 2.0.0 + */ +public enum ObjectEncoding { + + RAW("raw"), + + INT("int"), + + ZIPLIST("ziplist"), + + LINKEDLIST("linkedlist"), + + SKIPLIST("skiplist"), + + INTSET("intset"), + + HASHTABLE("hashtable"); + + private final String raw; + + ObjectEncoding(final String raw){ + this.raw = raw; + } + + public String getRaw(){ + return raw; + } + + @Override + public String toString(){ + return getRaw(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/PoolConfig.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/PoolConfig.java new file mode 100644 index 000000000..ba9122f9d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/PoolConfig.java @@ -0,0 +1,608 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.core.converter.mapper.PropertyMapper; +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; + +import java.time.Duration; + +/** + * 连接池配置 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public class PoolConfig { + + /** + * 池模式,为 true 时,后进先出;为 false 时,先进先出 + */ + private boolean lifo = GenericObjectPoolConfig.DEFAULT_LIFO; + + /** + * 当从池中获取资源或者将资源还回池中时,是否使用 {@link java.util.concurrent.locks.ReentrantLock} 的公平锁机制 + */ + private boolean fairness = GenericObjectPoolConfig.DEFAULT_FAIRNESS; + + /** + * 当连接池资源用尽后,调用者获取连接时的最大等待时间 + */ + private Duration maxWait = GenericObjectPoolConfig.DEFAULT_MAX_WAIT; + + /** + * 连接的最小空闲时间,达到此值后且已达最大空闲连接数该空闲连接可能会被移除 + */ + private Duration minEvictableIdleTime = Duration.ofMillis(60000); + + /** + * 连接空闲的最小时间,达到此值后空闲链接将会被移除,且保留 minIdle 个空闲连接数 + */ + private Duration softMinEvictableIdleTime = GenericObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION; + + /** + * 驱逐策略的类名 + */ + private String evictionPolicyClassName = GenericObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME; + + /** + * 关闭驱逐线程的超时时间 + */ + private Duration evictorShutdownTimeout = GenericObjectPoolConfig.DEFAULT_EVICTOR_SHUTDOWN_TIMEOUT; + + /** + * 检测空闲对象线程每次运行时检测的空闲对象的数量; + * 如果 numTestsPerEvictionRun >= 0, 则取 numTestsPerEvictionRun 和池内的连接数的较小值作为每次检测的连接数; + * 如果 numTestsPerEvictionRun < 0,则每次检查的连接数是检查时池内连接的总数除以这个值的绝对值再向上取整的结果 + */ + private int numTestsPerEvictionRun = -1; + + /** + * 在创建对象时检测对象是否有效,配置 true 会降低性能 + */ + private boolean testOnCreate = GenericObjectPoolConfig.DEFAULT_TEST_ON_CREATE; + + /** + * 在从对象池获取对象时是否检测对象有效,配置 true 会降低性能 + */ + private boolean testOnBorrow = GenericObjectPoolConfig.DEFAULT_TEST_ON_BORROW; + + /** + * 在向对象池中归还对象时是否检测对象有效,配置 true 会降低性能 + */ + private boolean testOnReturn = GenericObjectPoolConfig.DEFAULT_TEST_ON_RETURN; + + /** + * 在检测空闲对象线程检测到对象不需要移除时,是否检测对象的有效性;建议配置为 true,不影响性能,并且保证安全性 + */ + private boolean testWhileIdle = true; + + /** + * 空闲连接检测的周期,如果为负值,表示不运行检测线程 + */ + private Duration timeBetweenEvictionRuns = Duration.ofMillis(30000); + + /** + * 当对象池没有空闲对象时,新的获取对象的请求是否阻塞(true 阻塞,maxWaitMillis 才生效;false 连接池没有资源立马抛异常) + */ + private boolean blockWhenExhausted = GenericObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED; + + /** + * 是否注册 JMX + */ + private boolean jmxEnabled = GenericObjectPoolConfig.DEFAULT_JMX_ENABLE; + + /** + * JMX 前缀 + */ + private String jmxNamePrefix = GenericObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX; + + /** + * 使用 base + jmxNamePrefix + i 来生成 ObjectName + */ + private String jmxNameBase = GenericObjectPoolConfig.DEFAULT_JMX_NAME_BASE; + + /** + * 最大连接数 + */ + private int maxTotal = GenericObjectPoolConfig.DEFAULT_MAX_TOTAL; + + /** + * 最小空闲连接数 + */ + private int minIdle = GenericObjectPoolConfig.DEFAULT_MIN_IDLE; + + /** + * 最大空闲连接数 + */ + private int maxIdle = GenericObjectPoolConfig.DEFAULT_MAX_IDLE; + + /** + * 返回池模式 + * + * @return 池模式,为 true 时,后进先出;为 false 时,先进先出 + */ + public boolean getLifo() { + return lifo; + } + + /** + * 设置池模式 + * + * @param lifo + * 池模式,为 true 时,后进先出;为 false 时,先进先出 + */ + public void setLifo(boolean lifo) { + this.lifo = lifo; + } + + /** + * 返回当从池中获取资源或者将资源还回池中时,是否使用 {@link java.util.concurrent.locks.ReentrantLock} 的公平锁机制 + * + * @return 当从池中获取资源或者将资源还回池中时,是否使用 {@link java.util.concurrent.locks.ReentrantLock} 的公平锁机制 + */ + public boolean getFairness() { + return fairness; + } + + /** + * 设置当从池中获取资源或者将资源还回池中时,是否使用 {@link java.util.concurrent.locks.ReentrantLock} 的公平锁机制 + * + * @param fairness + * 当从池中获取资源或者将资源还回池中时,是否使用 {@link java.util.concurrent.locks.ReentrantLock} 的公平锁机制 + */ + public void setFairness(boolean fairness) { + this.fairness = fairness; + } + + /** + * 返回当连接池资源用尽后,调用者获取连接时的最大等待时间 + * + * @return 当连接池资源用尽后,调用者获取连接时的最大等待时间 + */ + public Duration getMaxWait() { + return maxWait; + } + + /** + * 设置当连接池资源用尽后,调用者获取连接时的最大等待时间 + * + * @param maxWait + * 当连接池资源用尽后,调用者获取连接时的最大等待时间 + */ + public void setMaxWait(Duration maxWait) { + this.maxWait = maxWait; + } + + /** + * 返回连接的最小空闲时间,达到此值后且已达最大空闲连接数该空闲连接可能会被移除 + * + * @return 连接的最小空闲时间,达到此值后且已达最大空闲连接数该空闲连接可能会被移除 + */ + public Duration getMinEvictableIdleTime() { + return minEvictableIdleTime; + } + + /** + * 设置连接的最小空闲时间,达到此值后且已达最大空闲连接数该空闲连接可能会被移除 + * + * @param minEvictableIdleTime + * 连接的最小空闲时间,达到此值后且已达最大空闲连接数该空闲连接可能会被移除 + */ + public void setMinEvictableIdleTime(Duration minEvictableIdleTime) { + this.minEvictableIdleTime = minEvictableIdleTime; + } + + /** + * 返回连接空闲的最小时间,达到此值后空闲链接将会被移除,且保留 minIdle 个空闲连接数 + * + * @return 连接空闲的最小时间,达到此值后空闲链接将会被移除,且保留 minIdle 个空闲连接数 + */ + public Duration getSoftMinEvictableIdleTime() { + return softMinEvictableIdleTime; + } + + /** + * 设置连接空闲的最小时间,达到此值后空闲链接将会被移除,且保留 minIdle 个空闲连接数 + * + * @param softMinEvictableIdleTime + * 连接空闲的最小时间,达到此值后空闲链接将会被移除,且保留 minIdle 个空闲连接数 + */ + public void setSoftMinEvictableIdleTime(Duration softMinEvictableIdleTime) { + this.softMinEvictableIdleTime = softMinEvictableIdleTime; + } + + /** + * 返回驱逐策略的类名 + * + * @return 驱逐策略的类名 + */ + public String getEvictionPolicyClassName() { + return evictionPolicyClassName; + } + + /** + * 设置驱逐策略的类名 + * + * @param evictionPolicyClassName + * 驱逐策略的类名 + */ + public void setEvictionPolicyClassName(String evictionPolicyClassName) { + this.evictionPolicyClassName = evictionPolicyClassName; + } + + /** + * 返回关闭驱逐线程的超时时间 + * + * @return 关闭驱逐线程的超时时间 + */ + public Duration getEvictorShutdownTimeout() { + return evictorShutdownTimeout; + } + + /** + * 设置关闭驱逐线程的超时时间 + * + * @param evictorShutdownTimeout + * 关闭驱逐线程的超时时间 + */ + public void setEvictorShutdownTimeout(Duration evictorShutdownTimeout) { + this.evictorShutdownTimeout = evictorShutdownTimeout; + } + + /** + * 返回检测空闲对象线程每次运行时检测的空闲对象的数量 + * + * @return 检测空闲对象线程每次运行时检测的空闲对象的数量; + * 如果 numTestsPerEvictionRun >= 0, 则取 numTestsPerEvictionRun 和池内的连接数的较小值作为每次检测的连接数; + * 如果 numTestsPerEvictionRun < 0,则每次检查的连接数是检查时池内连接的总数除以这个值的绝对值再向上取整的结果 + */ + public int getNumTestsPerEvictionRun() { + return numTestsPerEvictionRun; + } + + /** + * 设置检测空闲对象线程每次运行时检测的空闲对象的数量 + * + * @param numTestsPerEvictionRun + * 检测空闲对象线程每次运行时检测的空闲对象的数量 + */ + public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) { + this.numTestsPerEvictionRun = numTestsPerEvictionRun; + } + + /** + * 返回在创建对象时检测对象是否有效 + * + * @return 在创建对象时检测对象是否有效 + */ + public boolean isTestOnCreate() { + return getTestOnCreate(); + } + + /** + * 返回在创建对象时检测对象是否有效 + * + * @return 在创建对象时检测对象是否有效 + */ + public boolean getTestOnCreate() { + return testOnCreate; + } + + /** + * 设置在创建对象时检测对象是否有效 + * + * @param testOnCreate + * 在创建对象时检测对象是否有效,配置 true 会降低性能 + */ + public void setTestOnCreate(boolean testOnCreate) { + this.testOnCreate = testOnCreate; + } + + /** + * 返回在从对象池获取对象时是否检测对象有效 + * + * @return 在从对象池获取对象时是否检测对象有效 + */ + public boolean isTestOnBorrow() { + return getTestOnBorrow(); + } + + /** + * 返回在从对象池获取对象时是否检测对象有效 + * + * @return 在从对象池获取对象时是否检测对象有效 + */ + public boolean getTestOnBorrow() { + return testOnBorrow; + } + + /** + * 设置在从对象池获取对象时是否检测对象有效 + * + * @param testOnBorrow + * 在从对象池获取对象时是否检测对象有效,配置 true 会降低性能 + */ + public void setTestOnBorrow(boolean testOnBorrow) { + this.testOnBorrow = testOnBorrow; + } + + /** + * 返回在向对象池中归还对象时是否检测对象有效 + * + * @return 在向对象池中归还对象时是否检测对象有效 + */ + public boolean isTestOnReturn() { + return getTestOnReturn(); + } + + /** + * 返回在向对象池中归还对象时是否检测对象有效 + * + * @return 在向对象池中归还对象时是否检测对象有效 + */ + public boolean getTestOnReturn() { + return testOnReturn; + } + + /** + * 设置在向对象池中归还对象时是否检测对象有效 + * + * @param testOnReturn + * 在向对象池中归还对象时是否检测对象有效,配置 true 会降低性能 + */ + public void setTestOnReturn(boolean testOnReturn) { + this.testOnReturn = testOnReturn; + } + + /** + * 返回在检测空闲对象线程检测到对象不需要移除时,是否检测对象的有效性 + * + * @return 在检测空闲对象线程检测到对象不需要移除时,是否检测对象的有效性 + */ + public boolean isTestWhileIdle() { + return getTestWhileIdle(); + } + + /** + * 返回在检测空闲对象线程检测到对象不需要移除时,是否检测对象的有效性 + * + * @return 在检测空闲对象线程检测到对象不需要移除时,是否检测对象的有效性 + */ + public boolean getTestWhileIdle() { + return testWhileIdle; + } + + /** + * 设置在检测空闲对象线程检测到对象不需要移除时,是否检测对象的有效性;建议配置为 true,不影响性能,并且保证安全性 + * + * @param testWhileIdle + * 在检测空闲对象线程检测到对象不需要移除时,是否检测对象的有效性 + */ + public void setTestWhileIdle(boolean testWhileIdle) { + this.testWhileIdle = testWhileIdle; + } + + /** + * 返回空闲连接检测的周期,如果为负值,表示不运行检测线程 + * + * @return 空闲连接检测的周期,如果为负值,表示不运行检测线程 + */ + public Duration getTimeBetweenEvictionRuns() { + return timeBetweenEvictionRuns; + } + + /** + * 设置空闲连接检测的周期,如果为负值,表示不运行检测线程 + * + * @param timeBetweenEvictionRuns + * 空闲连接检测的周期 + */ + public void setTimeBetweenEvictionRuns(Duration timeBetweenEvictionRuns) { + this.timeBetweenEvictionRuns = timeBetweenEvictionRuns; + } + + /** + * 返回当对象池没有空闲对象时,新的获取对象的请求是否阻塞 + * + * @return 当对象池没有空闲对象时,新的获取对象的请求是否阻塞(true 阻塞,maxWaitMillis 才生效; false 连接池没有资源立马抛异常) + */ + public boolean isBlockWhenExhausted() { + return getBlockWhenExhausted(); + } + + /** + * 返回当对象池没有空闲对象时,新的获取对象的请求是否阻塞 + * + * @return 当对象池没有空闲对象时,新的获取对象的请求是否阻塞(true 阻塞,maxWaitMillis 才生效; false 连接池没有资源立马抛异常) + */ + public boolean getBlockWhenExhausted() { + return blockWhenExhausted; + } + + /** + * 设置当对象池没有空闲对象时,新的获取对象的请求是否阻塞(true 阻塞,maxWaitMillis 才生效; false 连接池没有资源立马抛异常) + * + * @param blockWhenExhausted + * 当对象池没有空闲对象时,新的获取对象的请求是否阻塞 + */ + public void setBlockWhenExhausted(boolean blockWhenExhausted) { + this.blockWhenExhausted = blockWhenExhausted; + } + + /** + * 返回是否注册 JMX + * + * @return 是否注册 JMX + */ + public boolean isJmxEnabled() { + return getJmxEnabled(); + } + + /** + * 返回是否注册 JMX + * + * @return 是否注册 JMX + */ + public boolean getJmxEnabled() { + return jmxEnabled; + } + + /** + * 设置是否注册 JMX + * + * @param jmxEnabled + * 是否注册 JMX + */ + public void setJmxEnabled(boolean jmxEnabled) { + this.jmxEnabled = jmxEnabled; + } + + /** + * 返回 JMX 前缀 + * + * @return JMX 前缀 + */ + public String getJmxNamePrefix() { + return jmxNamePrefix; + } + + /** + * 设置 JMX 前缀 + * + * @param jmxNamePrefix + * JMX 前缀 + */ + public void setJmxNamePrefix(String jmxNamePrefix) { + this.jmxNamePrefix = jmxNamePrefix; + } + + public String getJmxNameBase() { + return jmxNameBase; + } + + public void setJmxNameBase(String jmxNameBase) { + this.jmxNameBase = jmxNameBase; + } + + /** + * 返回最大连接数 + * + * @return 最大连接数 + */ + public int getMaxTotal() { + return maxTotal; + } + + /** + * 设置最大连接数 + * + * @param maxTotal + * 最大连接数 + */ + public void setMaxTotal(int maxTotal) { + this.maxTotal = maxTotal; + } + + /** + * 返回最小空闲连接数 + * + * @return 最小空闲连接数 + */ + public int getMinIdle() { + return minIdle; + } + + /** + * 设置最小空闲连接数 + * + * @param minIdle + * 最小空闲连接数 + */ + public void setMinIdle(int minIdle) { + this.minIdle = minIdle; + } + + /** + * 返回最大空闲连接数 + * + * @return 最大空闲连接数 + */ + public int getMaxIdle() { + return maxIdle; + } + + /** + * 设置最大空闲连接数 + * + * @param maxIdle + * 最大空闲连接数 + */ + public void setMaxIdle(int maxIdle) { + this.maxIdle = maxIdle; + } + + /** + * 转换为 jedis {@link GenericObjectPoolConfig} + * + * @param poolConfig + * {@link GenericObjectPoolConfig} 实例 + * @param + * {@link GenericObjectPoolConfig} 类型 + * + * @return {@link GenericObjectPoolConfig} 实例 + * + * @since 2.3.2 + */ + public GenericObjectPoolConfig toGenericObjectPoolConfig(final GenericObjectPoolConfig poolConfig) { + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); + + poolConfig.setLifo(getLifo()); + poolConfig.setFairness(getFairness()); + poolConfig.setMaxWait(getMaxWait()); + poolConfig.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun()); + poolConfig.setTestOnCreate(getTestOnCreate()); + poolConfig.setTestOnBorrow(getTestOnBorrow()); + poolConfig.setTestOnReturn(getTestOnReturn()); + poolConfig.setTestWhileIdle(getTestWhileIdle()); + poolConfig.setBlockWhenExhausted(getBlockWhenExhausted()); + poolConfig.setJmxEnabled(getJmxEnabled()); + poolConfig.setMaxTotal(getMaxTotal()); + poolConfig.setMinIdle(getMinIdle()); + poolConfig.setMaxIdle(getMaxIdle()); + + propertyMapper.from(getMinEvictableIdleTime()).to(poolConfig::setMinEvictableIdleTime); + propertyMapper.from(getSoftMinEvictableIdleTime()).to(poolConfig::setSoftMinEvictableIdleTime); + propertyMapper.from(getEvictorShutdownTimeout()).to(poolConfig::setEvictorShutdownTimeout); + propertyMapper.from(getTimeBetweenEvictionRuns()).to(poolConfig::setTimeBetweenEvictionRuns); + propertyMapper.alwaysApplyingWhenHasText().from(getEvictionPolicyClassName()) + .to(poolConfig::setEvictionPolicyClassName); + propertyMapper.alwaysApplyingWhenHasText().from(getJmxNamePrefix()).to(poolConfig::setJmxNamePrefix); + propertyMapper.alwaysApplyingWhenHasText().from(getJmxNameBase()).to(poolConfig::setJmxNameBase); + + return poolConfig; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/PubSubListener.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/PubSubListener.java new file mode 100644 index 000000000..78bae681f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/PubSubListener.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2019 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +/** + * @author Yong.Teng + */ +public interface PubSubListener { + + void onMessage(final V channel, final V message); + + void onPMessage(final V pattern, final V channel, final V message); + + void onSubscribe(final V channel, final int subscribedChannels); + + void onUnsubscribe(final V channel, final int subscribedChannels); + + void onPUnsubscribe(final V pattern, final int subscribedChannels); + + void onPSubscribe(final V pattern, final int subscribedChannels); + + void onPong(final V pattern); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisClusterServer.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisClusterServer.java new file mode 100644 index 000000000..411e8bf35 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisClusterServer.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +/** + * @author Yong.Teng + * @since 2.0.0 + */ +public class RedisClusterServer extends RedisServer { + + private final static long serialVersionUID = 4843502163987630437L; + + /** + * 构造函数 + * + * @param host + * Redis 节点地址 + */ + public RedisClusterServer(final String host){ + super(host); + } + + /** + * 构造函数 + * + * @param host + * Redis 节点地址 + * @param port + * Redis 端口 + */ + public RedisClusterServer(final String host, final int port){ + super(host, port); + } + + /** + * 构造函数 + * + * @param host + * Redis 节点地址 + * @param role + * 节点角色 + */ + public RedisClusterServer(final String host, final Role role){ + super(host, role); + } + + /** + * 构造函数 + * + * @param host + * Redis 节点地址 + * @param port + * Redis 端口 + * @param role + * 节点角色 + */ + public RedisClusterServer(final String host, final int port, final Role role){ + super(host, port, role); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisMode.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisMode.java new file mode 100644 index 000000000..a98f75feb --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisMode.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +/** + * @author Yong.Teng + */ +public enum RedisMode { + + STANDALONE("Standalone"), + + SHARDED("Sharded"), + + MASTER_SLAVE("Master-Slave"), + + SENTINEL("Sentinel"), + + CLUSTER("Cluster"); + + private final String value; + + RedisMode(final String value){ + this.value = value; + } + + public String getValue(){ + return value; + } + + @Override + public String toString(){ + return value; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisMonitor.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisMonitor.java new file mode 100644 index 000000000..f5a6159c1 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisMonitor.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +/** + * @author Yong.Teng + */ +@FunctionalInterface +public interface RedisMonitor { + + void onCommand(final String command); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisNamedNode.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisNamedNode.java new file mode 100644 index 000000000..b36379e44 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisNamedNode.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.core.NamedNode; + +/** + * 带有名称的 Redis 节点 + * + * @author Yong.Teng + */ +public class RedisNamedNode extends RedisNode implements NamedNode { + + private final static long serialVersionUID = -9142375093229773814L; + + /** + * 名称 + */ + private String name; + + /** + * 构造函数 + * + * @param host + * 主机地址 + */ + public RedisNamedNode(final String host) { + super(host); + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + */ + public RedisNamedNode(final String host, final int port) { + super(host, port); + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param name + * 名称 + */ + public RedisNamedNode(final String host, final String name) { + super(host); + this.name = name; + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + */ + public RedisNamedNode(final String host, final int port, final String name) { + super(host, port); + this.name = name; + } + + /** + * 返回名称 + * + * @return 名称 + */ + @Override + public String getName() { + return name; + } + + /** + * 设置名称 + * + * @param name + * 名称 + */ + public void setName(String name) { + this.name = name; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisNode.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisNode.java new file mode 100644 index 000000000..fc6dd9726 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisNode.java @@ -0,0 +1,313 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import java.io.Serializable; +import java.util.Objects; + +/** + * Redis 节点 + * + * @author Yong.Teng + */ +public class RedisNode implements Serializable { + + private final static long serialVersionUID = -2212702986712034274L; + + public final static String DEFAULT_HOST = "localhost"; + + public final static int DEFAULT_PORT = 6379; + + public final static int DEFAULT_SENTINEL_PORT = 26379; + + public final static int DEFAULT_DATABASE = 0; + + /** + * 主机 ID + */ + private String id; + + /** + * 主机地址 + */ + private String host; + + /** + * 主机端口 + */ + private int port; + + /** + * 主机角色 + */ + //private Role role; + + /** + * Master 主机 ID + */ + //private String masterId; + + /** + * 构造函数 + * + * @param host + * 主机地址 + */ + public RedisNode(final String host) { + this.host = host; + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + */ + public RedisNode(final String host, final int port) { + this.host = host; + this.port = port; + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param role + * 主机角色 + */ + /* + public RedisNode( final String host, final Role role){ + this(host); + this.role = role; + } + + */ + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + * @param role + * 主机角色 + */ + /* + public RedisNode(final String host, final int port, final Role role){ + this(host, port); + this.role = role; + } + + */ + + /** + * 返回主机 ID + * + * @return 主机 ID + */ + public String getId() { + return id; + } + + /** + * 设置主机 ID + * + * @param id + * 主机 ID + */ + public void setId(String id) { + this.id = id; + } + + /** + * 返回主机地址 + * + * @return 主机地址 + */ + public String getHost() { + return host; + } + + /** + * 设置主机地址 + * + * @param host + * 主机地址 + */ + public void setHost(String host) { + this.host = host; + } + + /** + * 返回主机端口 + * + * @return 主机地址 + */ + public int getPort() { + return port; + } + + /** + * 设置主机端口 + * + * @param port + * 主机端口 + */ + public void setPort(int port) { + this.port = port; + } + + /** + * 返回主机角色 + * + * @return 主机角色 + */ + /* + public Role getRole(){ + return role; + } + + */ + + /** + * 设置主机角色 + * + * @param role + * 主机角色 + */ + /* + public void setRole( Role role){ + this.role = role; + } + + */ + + /** + * 返回主机 Master Id + * + * @return 主机 Master Id + */ + /* + public String getMasterId(){ + return masterId; + } + + */ + + /** + * 设置主机 Master Id + * + * @param masterId + * 主机 Master Id + */ + /* + public void setMasterId(@String masterId){ + this.masterId = masterId; + } + + */ + + /** + * 返回是否为 Master 节点 + * + * @return 是否为 Master 节点 + */ + /* + public boolean isMaster(){ + return Role.MASTER.equals(getRole()); + } + + */ + + /** + * 返回是否为 Slave 节点 + * + * @return 是否为 Slave 节点 + */ + /* + public boolean isSlave(){ + return Role.SLAVE.equals(getRole()); + } + + */ + + /** + * 返回是否为 Slave 节点 + * + * @return 是否为 Slave 节点 + */ + /* + public boolean isReplica(){ + return isSlave(); + } + + */ + public String asString() { + final StringBuilder sb = new StringBuilder(host); + + sb.append(':').append(port); + if(id != null){ + sb.append("[id: ").append(id).append(']'); + } + + return sb.toString(); + } + + @Override + public String toString() { + return asString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + + result = prime * result + Objects.hashCode(host); + result = prime * result + Objects.hashCode(port); + + return result; + } + + @Override + public boolean equals(Object obj) { + if(this == obj){ + return true; + } + + if(obj instanceof RedisNode){ + RedisNode that = (RedisNode) obj; + return port == that.port && Objects.equals(host, that.host); + } + + return false; + } + + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisSentinelNode.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisSentinelNode.java new file mode 100644 index 000000000..416084f0d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisSentinelNode.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import org.springframework.lang.Nullable; + +/** + * Redis 哨兵节点 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public class RedisSentinelNode extends RedisNode { + + private final static long serialVersionUID = 7609068824843419481L; + + private int quorum; + + /** + * 构造函数 + * + * @param host + * 主机地址 + */ + public RedisSentinelNode(@Nullable String host){ + super(host); + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + */ + public RedisSentinelNode(@Nullable String host, int port){ + super(host, port); + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param role + * 主机角色 + */ + public RedisSentinelNode(@Nullable String host, @Nullable Role role){ + super(host, role); + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + * @param role + * 主机角色 + */ + public RedisSentinelNode(@Nullable String host, int port, @Nullable Role role){ + super(host, port, role); + } + + public int getQuorum(){ + return quorum; + } + + public void setQuorum(int quorum){ + this.quorum = quorum; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisServer.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisServer.java new file mode 100644 index 000000000..b8e9f9acb --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisServer.java @@ -0,0 +1,361 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.core.utils.Assert; +import com.buession.core.utils.EnumUtils; +import com.buession.core.utils.StringUtils; +import com.buession.core.validator.Validate; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + +/** + * @author Yong.Teng + */ +public class RedisServer extends RedisNode { + + private final static long serialVersionUID = 4843502163987630437L; + + /** + * Redis 服务器主机 IP 地址 + */ + private final String ip; + + /** + * Redis 服务器信息 + */ + private Properties properties; + + /** + * 构造函数 + * + * @param host + * Redis 节点地址 + */ + public RedisServer(final String host){ + super(host); + this.ip = host; + } + + /** + * 构造函数 + * + * @param host + * Redis 节点地址 + * @param port + * Redis 端口 + */ + public RedisServer(final String host, final int port){ + super(host, port); + this.ip = host; + } + + /** + * 构造函数 + * + * @param host + * Redis 节点地址 + * @param role + * 节点角色 + */ + public RedisServer(final String host, final Role role){ + super(host, role); + this.ip = host; + } + + /** + * 构造函数 + * + * @param host + * Redis 节点地址 + * @param port + * Redis 端口 + * @param role + * 节点角色 + */ + public RedisServer(final String host, final int port, final Role role){ + super(host, port, role); + this.ip = host; + } + + /** + * 构造函数 + * + * @param host + * Redis 节点地址 + * @param properties + * Redis 服务器信息 + */ + public RedisServer(final String host, final Properties properties){ + this(host); + this.properties = properties; + } + + /** + * 构造函数 + * + * @param host + * Redis 节点地址 + * @param port + * Redis 端口 + * @param properties + * Redis 服务器信息 + */ + public RedisServer(final String host, final int port, final Properties properties){ + this(host, port); + this.properties = properties; + } + + /** + * 构造函数 + * + * @param host + * Redis 节点地址 + * @param role + * 节点角色 + * @param properties + * Redis 服务器信息 + */ + public RedisServer(final String host, final Role role, final Properties properties){ + this(host, role); + this.properties = properties; + } + + /** + * 构造函数 + * + * @param host + * Redis 节点地址 + * @param port + * Redis 端口 + * @param role + * 节点角色 + * @param properties + * Redis 服务器信息 + */ + public RedisServer(final String host, final int port, final Role role, final Properties properties){ + this(host, port, role); + this.properties = properties; + } + + /** + * 获取 Redis 服务器主机 IP 地址 + * + * @return Redis 服务器主机 IP 地址 + */ + public String getIp(){ + return ip; + } + + /** + * 返回 Redis 服务器信息 + * + * @return Redis 服务器信息 + */ + public Properties getProperties(){ + return properties; + } + + public Long getQuorum(){ + return getLongValueOf(Key.QUORUM); + } + + public String getRunId(){ + return get(Key.RUNID); + } + + public Long getNumSlaves(){ + return getLongValueOf(Key.NUMBER_SLAVES); + } + + public Long getNumOtherSentinels(){ + return getLongValueOf(Key.NUMBER_OTHER_SENTINELS); + } + + public Long getParallelSyncs(){ + return getLongValueOf(Key.PARALLEL_SYNCS); + } + + public Long getConfigEpoch(){ + return getLongValueOf(Key.CONFIG_EPOCH); + } + + public Long getInfoRefresh(){ + return getLongValueOf(Key.INFO_REFRESH); + } + + public Role getRoleReported(){ + String roleName = get(Key.ROLE_REPORTED); + return Validate.hasText(roleName) ? EnumUtils.getEnum(Role.class, roleName) : null; + } + + public Long getRoleReportedTime(){ + return getLongValueOf(Key.ROLE_REPORTED_TIME); + } + + public Long getLastPingSent(){ + return getLongValueOf(Key.LAST_PING_SENT); + } + + public Long getLastPingReply(){ + return getLongValueOf(Key.LAST_PING_REPLY); + } + + public Long getLastOkPingReply(){ + return getLongValueOf(Key.LAST_OK_PING_REPLY); + } + + public Long getLinkPendingCommands(){ + return getLongValueOf(Key.LINK_PENDING_COMMANDS); + } + + public Long getFailoverTimeout(){ + return getLongValueOf(Key.FAILOVER_TIMEOUT); + } + + public Long getLinkRefcount(){ + return getLongValueOf(Key.LINK_REFCOUNT); + } + + public Long getODownTime(){ + return getLongValueOf(Key.O_DOWN_TIME); + } + + public Long getSDownTime(){ + return getLongValueOf(Key.S_DOWN_TIME); + } + + public Long getDownAfterMilliseconds(){ + return getLongValueOf(Key.DOWN_AFTER_MILLISECONDS); + } + + public Set getFlags(){ + String value = get(Key.FLAGS); + + if(value == null){ + return null; + }else if(value.length() == 0){ + return Collections.emptySet(); + }else{ + return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(StringUtils.split(value, ',')))); + } + } + + @Override + public String asString(){ + final StringBuilder sb = new StringBuilder(); + + if(getId() != null){ + sb.append(getId()).append(" "); + } + + sb.append(getHost()).append(':').append(getPort()); + + return sb.toString(); + } + + public String get(final Key key){ + Assert.isNull(key, "Cannot retrieve client information for 'null'."); + return properties.getProperty(key.getKey()); + } + + private Long getLongValueOf(final Key key){ + String value = get(key); + return value == null ? null : Long.valueOf(value); + } + + public enum Key { + + NAME("name"), + + HOST("ip"), + + PORT("port"), + + RUNID("runid"), + + FLAGS("flags"), + + PENDING_COMMANDS("pending-commands"), + + LINK_PENDING_COMMANDS("link-pending-commands"), + + LAST_PING_SENT("last-ping-sent"), + + LAST_PING_REPLY("last-ping-reply"), + + LAST_OK_PING_REPLY("last-ok-ping-reply"), + + DOWN_AFTER_MILLISECONDS("down-after-milliseconds"), + + INFO_REFRESH("info-refresh"), + + ROLE_REPORTED("role-reported"), + + ROLE_REPORTED_TIME("role-reported-time"), + + CONFIG_EPOCH("config-epoch"), + + NUMBER_SLAVES("num-slaves"), + + NUMBER_OTHER_SENTINELS("num-other-sentinels"), + + BUFFER_LENGTH("qbuf"), + + BUFFER_FREE_SPACE("qbuf-free"), + + OUTPUT_BUFFER_LENGTH("obl"), + + OUTPUT_LIST_LENGTH("number-other-sentinels"), + + QUORUM("quorum"), + + FAILOVER_TIMEOUT("failover-timeout"), + + PARALLEL_SYNCS("parallel-syncs"), + + LINK_REFCOUNT("link-refcount"), + + O_DOWN_TIME("o-down-time"), + + S_DOWN_TIME("s-down-time"); + + private final String key; + + Key(final String key){ + this.key = key; + } + + public String getKey(){ + return key; + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisServerTime.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisServerTime.java new file mode 100644 index 000000000..596c4ea21 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisServerTime.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.utils.ObjectStringBuilder; + +import java.io.Serializable; +import java.util.Date; +import java.util.Objects; + +/** + * @author Yong.Teng + */ +public final class RedisServerTime implements Serializable { + + private final static long serialVersionUID = 7818271427941747714L; + + private final Date date; + + private final long usec; + + public RedisServerTime(final Date date, final long usec) { + this.date = date; + this.usec = usec; + } + + public Date getDate() { + return date; + } + + public long getUsec() { + return usec; + } + + @Override + public int hashCode() { + return Objects.hash(date, usec); + } + + @Override + public boolean equals(Object obj) { + if(this == obj){ + return true; + } + + if(obj instanceof RedisServerTime){ + RedisServerTime that = (RedisServerTime) obj; + return usec == that.usec && Objects.equals(date, that.date); + } + + return false; + } + + @Override + public String toString() { + return ObjectStringBuilder.create() + .add("date", date) + .add("usec", usec) + .build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisURI.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisURI.java new file mode 100644 index 000000000..3af7e8e74 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/RedisURI.java @@ -0,0 +1,308 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.core.builder.SetBuilder; +import com.buession.core.utils.Assert; +import com.buession.core.validator.Validate; +import com.buession.net.AbstractUserInfoURI; +import com.buession.net.AbstractUserInfoURIBuilder; + +import java.net.URI; +import java.util.Map; +import java.util.Set; + +/** + * @author Yong.Teng + */ +public class RedisURI extends AbstractUserInfoURI { + + private final static long serialVersionUID = 7893709100532398408L; + + public final static String REDIS = "redis"; + + public final static String REDISS = "rediss"; + + public final static String PARAMETER_NAME_DATABASE = "database"; + + public final static String PARAMETER_NAME_DATABASE_ALT = "db"; + + public final static String PARAMETER_NAME_CLIENT_NAME = "clientName"; + + public final static String PARAMETER_NAME_WEIGHT = "weight"; + + public final static String PARAMETER_NAME_TIMEOUT = "timeout"; + + public final static Set ALLOWED_SCHEMES = SetBuilder.create().add(REDIS).add(REDISS).build(); + + public final static int DEFAULT_TIMEOUT = 60; + + private URI uri; + + private int database; + + private String clientName; + + private int weight; + + private int timeout = DEFAULT_TIMEOUT; + + public int getDatabase() { + return database; + } + + public void setDatabase(int database) { + this.database = database; + } + + public String getClientName() { + return clientName; + } + + public void setClientName(String clientName) { + this.clientName = clientName; + } + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + this.weight = weight; + } + + public int getTimeout() { + return timeout; + } + + public void setTimeout(int timeout) { + this.timeout = timeout; + } + + @Override + public boolean isSsl() { + return REDISS.equals(getScheme()); + } + + public boolean isUseSsl() { + return isSsl(); + } + + public void setUseSsl(boolean useSsl) { + setUseSsl(useSsl); + } + + public static RedisURI create(String uri) { + Assert.isBlank(uri, "URI must not be null or empty."); + return create(URI.create(uri)); + } + + public static RedisURI create(URI uri) { + RedisURI redisURI = buildRedisUriFromUri(uri); + + redisURI.uri = uri; + + return redisURI; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + + sb.append(getClass().getSimpleName()); + + sb.append(" ["); + + sb.append("host='").append(host).append('\''); + sb.append(", port=").append(port); + + if(password != null){ + sb.append(", password='").append(password).append('\''); + } + + sb.append(", database=").append(database); + + if(clientName != null){ + sb.append(", clientName='").append(clientName).append('\''); + } + + sb.append(", weight=").append(weight); + sb.append(", timeout=").append(timeout); + sb.append(", useSsl=").append(isUseSsl()); + + sb.append(']'); + + return sb.toString(); + } + + @Override + public URI toURI() { + return this.uri; + } + + private static RedisURI buildRedisUriFromUri(URI uri) { + Assert.isNull(uri, "URI must not be null"); + + Assert.isTrue(Validate.hasText(uri.getScheme()) && + ALLOWED_SCHEMES.contains(uri.getScheme()), "Scheme " + uri.getScheme() + " not supported."); + + Builder builder = Builder.getInstance(); + + String userInfo = uri.getUserInfo(); + + if(Validate.hasText(userInfo) == false && Validate.hasText(uri.getAuthority()) && + uri.getAuthority().indexOf('@') > 0){ + userInfo = uri.getAuthority().substring(0, uri.getAuthority().indexOf('@')); + } + + if(Validate.hasText(userInfo)){ + String password = userInfo; + int semiIndex = password.indexOf(':'); + + if(semiIndex == 0){ + password = password.substring(1); + }else{ + if(semiIndex > 0){ + password = password.substring(semiIndex + 1); + } + } + + if(Validate.hasText(password)){ + builder.password(password); + } + } + + if(Validate.hasText(uri.getPath())){ + String database = uri.getPath().substring(1); + + if(Validate.hasText(database)){ + builder.database(Integer.parseInt(database)); + } + } + + if(Validate.hasText(uri.getQuery())){ + builder.queryString(uri.getQuery()); + } + + return builder.build(); + } + + public final static class Builder extends AbstractUserInfoURIBuilder { + + private int database = RedisNode.DEFAULT_DATABASE; + + private String queryString; + + private Builder() { + super(); + host(RedisNode.DEFAULT_HOST); + port(RedisNode.DEFAULT_PORT); + } + + public static Builder getInstance() { + return new Builder(); + } + + public Builder database(final int database) { + Assert.isNegative(database, "Invalid database number: " + database); + this.database = database; + return this; + } + + public Builder queryString(final String queryString) { + this.queryString = queryString; + return this; + } + + @Override + public RedisURI build() { + RedisURI redisURI = new RedisURI(); + + redisURI.setHost(host); + redisURI.setPort(port); + + if(password != null){ + redisURI.setPassword(password); + } + + redisURI.setDatabase(database); + + Map parameters = parseParameters(queryString); + + if(Validate.isNotEmpty(parameters)){ + parseDatabase(redisURI, parameters.get(PARAMETER_NAME_DATABASE)); + parseDatabase(redisURI, parameters.get(PARAMETER_NAME_DATABASE_ALT)); + parseClientName(redisURI, parameters.get(PARAMETER_NAME_CLIENT_NAME)); + parseWeight(redisURI, parameters.get(PARAMETER_NAME_WEIGHT)); + parseTimeout(redisURI, parameters.get(PARAMETER_NAME_TIMEOUT)); + } + + redisURI.setUseSsl(REDISS.equalsIgnoreCase(scheme)); + + return redisURI; + } + + private static void parseDatabase(final RedisURI redisURI, final String paramValue) { + if(Validate.hasText(paramValue)){ + int db = Integer.parseInt(paramValue); + + if(db >= 0){ + redisURI.setDatabase(db); + } + } + } + + private static void parseClientName(final RedisURI redisURI, final String paramValue) { + if(Validate.hasText(paramValue)){ + redisURI.setClientName(paramValue); + } + } + + private static void parseWeight(final RedisURI redisURI, final String paramValue) { + if(Validate.hasText(paramValue)){ + int weight = Integer.parseInt(paramValue); + + if(weight >= 0){ + redisURI.setWeight(weight); + } + } + } + + private static void parseTimeout(final RedisURI redisURI, final String paramValue) { + if(Validate.hasText(paramValue)){ + int timeout = Integer.parseInt(paramValue); + + if(timeout >= 0){ + redisURI.setTimeout(timeout); + return; + } + } + + redisURI.setTimeout(DEFAULT_TIMEOUT); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/ScanResult.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/ScanResult.java new file mode 100644 index 000000000..7b8ae712f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/ScanResult.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.utils.SafeEncoder; + +import java.util.Arrays; + +/** + * 迭代结果 + * + * @param + * 结果数据类型 + * + * @author Yong.Teng + */ +public class ScanResult { + + /** + * 游标 + */ + private final byte[] cursor; + + /** + * 游标的字符串形式 + */ + private String cursorAsString; + + /** + * 结果集 + */ + private final V results; + + /** + * 构造函数 + * + * @param cursor + * 游标 + * @param results + * 结果集 + */ + public ScanResult(final byte[] cursor, final V results){ + this.cursor = cursor; + this.results = results; + } + + /** + * 构造函数 + * + * @param cursor + * 游标 + * @param results + * 结果集 + */ + public ScanResult(final String cursor, final V results){ + this(SafeEncoder.encode(cursor), results); + this.cursorAsString = cursor; + } + + /** + * 返回游标 + * + * @return 游标 + */ + public byte[] getCursor(){ + return cursor; + } + + /** + * 返回游标的字符串形式 + * + * @return 游标字符串形式 + */ + public String getCursorAsString(){ + if(cursorAsString == null){ + cursorAsString = SafeEncoder.encode(cursor); + } + + return cursorAsString; + } + + /** + * 返回结果集 + * + * @return 结果集 + */ + public V getResults(){ + return results; + } + + /** + * 是否完成迭代 + * + * @return 完成迭代返回 true;否则,返回 false + */ + public boolean isCompleteIteration(){ + return Arrays.equals(Constants.SCAN_POINTER_START_BINARY, getCursor()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/SessionCallback.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/SessionCallback.java new file mode 100644 index 000000000..3887ec8ce --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/SessionCallback.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.client.RedisClient; +import com.buession.redis.exception.RedisException; + +/** + * @author Yong.Teng + */ +@FunctionalInterface +public interface SessionCallback extends com.buession.core.Executor { + + @Override + R execute(RedisClient context) throws RedisException; + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/SlotRange.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/SlotRange.java new file mode 100644 index 000000000..b98bd3d52 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/SlotRange.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.core.NumberRange; + +import java.io.Serializable; + +/** + * 哈希槽范围 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public class SlotRange extends NumberRange implements Serializable { + + private final static long serialVersionUID = -185528503728995147L; + + public SlotRange() { + super(); + } + + public SlotRange(final Integer start, final Integer end) { + super(start, end); + } + + @Override + public String toString() { + return super.toString(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/SlowLog.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/SlowLog.java new file mode 100644 index 000000000..10d32cc70 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/SlowLog.java @@ -0,0 +1,164 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.utils.ObjectStringBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * 慢日志信息,更多信息 http://www.redis.cn/commands/slowlog.html + * + * @author Yong.Teng + * @since 2.0.0 + */ +public class SlowLog implements Serializable { + + private final static long serialVersionUID = 4948377124212583969L; + + /** + * 每个慢查询条目的唯一的递增标识符 + */ + private final long id; + + /** + * 处理记录命令的unix时间戳 + */ + private final long timestamp; + + /** + * 命令执行所需的总时间(单位:毫秒) + */ + private final long executionTime; + + /** + * 组成该命令的参数的数组 + */ + private final List args; + + /** + * 客户端信息 + */ + private final Client client; + + /** + * 客户端名称 + */ + private final String clientName; + + /** + * 构造函数 + * + * @param id + * 每个慢查询条目的唯一的递增标识符 + * @param timestamp + * 处理记录命令的unix时间戳 + * @param executionTime + * 命令执行所需的总时间(单位:毫秒) + * @param args + * 组成该命令的参数的数组 + * @param client + * 客户端信息 + * @param clientName + * 客户端名称 + */ + public SlowLog(final long id, final long timestamp, final long executionTime, final List args, + final Client client, final String clientName){ + this.id = id; + this.timestamp = timestamp; + this.executionTime = executionTime; + this.args = args; + this.client = client; + this.clientName = clientName; + } + + /** + * 返回每个慢查询条目的唯一的递增标识符 + * + * @return 每个慢查询条目的唯一的递增标识符 + */ + public long getId(){ + return id; + } + + /** + * 返回处理记录命令的unix时间戳 + * + * @return 处理记录命令的unix时间戳 + */ + public long getTimestamp(){ + return timestamp; + } + + /** + * 返回命令执行所需的总时间(单位:毫秒) + * + * @return 命令执行所需的总时间 + */ + public long getExecutionTime(){ + return executionTime; + } + + /** + * 返回组成该命令的参数的数组 + * + * @return 组成该命令的参数的数组 + */ + public List getArgs(){ + return args; + } + + /** + * 返回客户端信息 + * + * @return 客户端信息 + */ + public Client getClient(){ + return client; + } + + /** + * 返回客户端名称 + * + * @return 客户端名称 + */ + public String getClientName(){ + return clientName; + } + + @Override + public String toString(){ + return ObjectStringBuilder.create() + .add("id", id) + .add("timestamp", timestamp) + .add("executionTime", executionTime) + .add("args", args) + .add("client", client) + .add("clientName", clientName) + .build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/Stream.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/Stream.java new file mode 100644 index 000000000..21d8536a7 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/Stream.java @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.utils.ObjectStringBuilder; + +import java.io.Serializable; +import java.util.Map; + +/** + * @author Yong.Teng + * @since 2.0.0 + */ +public class Stream implements Serializable { + + private final static long serialVersionUID = -4336316668706617743L; + + private final long length; + + private final long radixTreeKeys; + + private final long radixTreeNodes; + + private final long groups; + + private final StreamEntryId lastGeneratedId; + + private final StreamEntry firstEntry; + + private final StreamEntry lastEntry; + + private final Map infos; + + public Stream(final long length, final long radixTreeKeys, final long radixTreeNodes, final long groups, + final StreamEntryId lastGeneratedId, final StreamEntry firstEntry, final StreamEntry lastEntry, + final Map infos){ + this.length = length; + this.radixTreeKeys = radixTreeKeys; + this.radixTreeNodes = radixTreeNodes; + this.groups = groups; + this.lastGeneratedId = lastGeneratedId; + this.firstEntry = firstEntry; + this.lastEntry = lastEntry; + this.infos = infos; + } + + public long getLength(){ + return length; + } + + public long getRadixTreeKeys(){ + return radixTreeKeys; + } + + public long getRadixTreeNodes(){ + return radixTreeNodes; + } + + public long getGroups(){ + return groups; + } + + public StreamEntryId getLastGeneratedId(){ + return lastGeneratedId; + } + + public StreamEntry getFirstEntry(){ + return firstEntry; + } + + public StreamEntry getLastEntry(){ + return lastEntry; + } + + public Map getInfos(){ + return infos; + } + + @Override + public String toString(){ + return ObjectStringBuilder.create() + .add("length", length) + .add("radixTreeKeys", radixTreeKeys) + .add("radixTreeNodes", radixTreeNodes) + .add("groups", groups) + .add("lastGeneratedId", lastGeneratedId) + .add("firstEntry", firstEntry) + .add("lastEntry", lastEntry) + .add("infos", infos) + .build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamConsumer.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamConsumer.java new file mode 100644 index 000000000..2423780ec --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamConsumer.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.utils.ObjectStringBuilder; + +import java.io.Serializable; +import java.util.Map; + +/** + * Stream Consumer + * + * @author Yong.Teng + * @since 2.0.0 + */ +public class StreamConsumer implements Serializable { + + private final static long serialVersionUID = 1432302411997199283L; + + private final String name; + + private final long idle; + + private final long pending; + + private final Map infos; + + public StreamConsumer(final String name, final long idle, final long pending, final Map infos){ + this.name = name; + this.idle = idle; + this.pending = pending; + this.infos = infos; + } + + public String getName(){ + return name; + } + + public long getIdle(){ + return idle; + } + + public long getPending(){ + return pending; + } + + public Map getInfos(){ + return infos; + } + + @Override + public String toString(){ + return ObjectStringBuilder.create() + .add("name", name) + .add("idle", idle) + .add("pending", pending) + .add("infos", infos) + .build(); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GeoRadiusArgumentConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamConsumerFull.java similarity index 57% rename from buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GeoRadiusArgumentConverter.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/StreamConsumerFull.java index d9c5c3d3f..e34fa780e 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GeoRadiusArgumentConverter.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamConsumerFull.java @@ -22,50 +22,70 @@ * | Copyright @ 2013-2022 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.redis.core.internal.convert.jedis.params; +package com.buession.redis.core; -import com.buession.core.converter.Converter; -import com.buession.lang.Order; -import com.buession.redis.core.command.GeoCommands; -import redis.clients.jedis.params.GeoRadiusParam; +import com.buession.redis.utils.ObjectStringBuilder; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; /** - * {@link GeoCommands.GeoRadiusArgument} 转换为 jedis {@link GeoRadiusParam} - * * @author Yong.Teng * @since 2.0.0 */ -public final class GeoRadiusArgumentConverter implements Converter { +public class StreamConsumerFull implements Serializable { - public final static GeoRadiusArgumentConverter INSTANCE = new GeoRadiusArgumentConverter(); + private final static long serialVersionUID = -4058066725300830836L; - @Override - public GeoRadiusParam convert(final GeoCommands.GeoRadiusArgument source){ - final GeoRadiusParam geoRadiusParam = new GeoRadiusParam(); + private final String name; + + private final Long seenTime; - if(Boolean.TRUE.equals(source.isWithCoord())){ - geoRadiusParam.withCoord(); - } + private final Long pelCount; - if(Boolean.TRUE.equals(source.isWithDist())){ - geoRadiusParam.withDist(); - } + private final List pending; - if(Boolean.TRUE.equals(source.isWithHash())){ - geoRadiusParam.withHash(); - } + private final Map infos; - if(source.getOrder() == Order.ASC){ - geoRadiusParam.sortAscending(); - }else if(source.getOrder() == Order.DESC){ - geoRadiusParam.sortDescending(); - } + public StreamConsumerFull(final String name, final Long seenTime, final Long pelCount, final List pending, + final Map infos){ + this.name = name; + this.seenTime = seenTime; + this.pelCount = pelCount; + this.pending = pending; + this.infos = infos; + } + + public String getName(){ + return name; + } - if(source.getCount() != null){ - geoRadiusParam.count(source.getCount()); - } + public Long getSeenTime(){ + return seenTime; + } - return geoRadiusParam; + public Long getPelCount(){ + return pelCount; + } + + public List getPending(){ + return pending; + } + + public Map getInfos(){ + return infos; + } + + @Override + public String toString(){ + return ObjectStringBuilder.create() + .add("name", name) + .add("seenTime", seenTime) + .add("pelCount", pelCount) + .add("pending", pending) + .add("infos", infos) + .build(); } } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamEntry.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamEntry.java new file mode 100644 index 000000000..45ef18d82 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamEntry.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import java.io.Serializable; +import java.util.Map; + +/** + * @author Yong.Teng + * @since 2.0.0 + */ +public class StreamEntry implements Serializable { + + private final static long serialVersionUID = 6763043914884686198L; + + private final StreamEntryId id; + + private final Map fields; + + public StreamEntry(final StreamEntryId id, final Map fields){ + this.id = id; + this.fields = fields; + } + + public StreamEntryId getId(){ + return id; + } + + public Map getFields(){ + return fields; + } + + @Override + public String toString(){ + return id + " " + fields; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamEntryId.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamEntryId.java new file mode 100644 index 000000000..fdcbfeca3 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamEntryId.java @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.core.Rawable; +import com.buession.core.utils.StringUtils; +import com.buession.redis.utils.SafeEncoder; + +import java.io.Serializable; +import java.nio.charset.StandardCharsets; +import java.util.Objects; + +/** + * @author Yong.Teng + * @since 2.0.0 + */ +public class StreamEntryId implements Rawable, Comparable, Serializable { + + private final static long serialVersionUID = -4487927281373256508L; + + /** + * Should be used only with XADD + * + * + * XADD mystream * field1 value1 + * + */ + public final static StreamEntryId NEW_ENTRY = new StreamEntryId() { + + @Override + public String toString() { + return "*"; + } + + }; + + /** + * Can be used in XRANGE, XREVRANGE and XPENDING commands. + */ + public final static StreamEntryId MINIMUM_ID = new StreamEntryId() { + + @Override + public String toString() { + return "-"; + } + + }; + + /** + * Can be used in XRANGE, XREVRANGE and XPENDING commands. + */ + public final static StreamEntryId MAXIMUM_ID = new StreamEntryId() { + + @Override + public String toString() { + return "+"; + } + + }; + + /** + * Should be used only with XGROUP CREATE + * + * + * XGROUP CREATE mystream consumer-group-name $ + * + */ + public final static StreamEntryId LAST_ENTRY = new StreamEntryId() { + + @Override + public String toString() { + return "$"; + } + + }; + + /** + * Should be used only with XREADGROUP + *

+ * {@code XREADGROUP $GroupName $ConsumerName BLOCK 2000 COUNT 10 STREAMS mystream >} + *

+ */ + public final static StreamEntryId UNRECEIVED_ENTRY = new StreamEntryId() { + + @Override + public String toString() { + return ">"; + } + + }; + + private final long time; + + private final long sequence; + + public StreamEntryId() { + this(0L, 0L); + } + + public StreamEntryId(final String id) { + String[] split = StringUtils.split(id, '-'); + this.time = Long.parseLong(split[0]); + this.sequence = Long.parseLong(split[1]); + } + + public StreamEntryId(final byte[] id) { + this(SafeEncoder.encode(id)); + } + + public StreamEntryId(final long time) { + this(time, 0L); + } + + public StreamEntryId(final long time, final long sequence) { + this.time = time; + this.sequence = sequence; + } + + public long getTime() { + return time; + } + + public long getSequence() { + return sequence; + } + + @Override + public byte[] getRaw() { + return toString().getBytes(StandardCharsets.UTF_8); + } + + @Override + public int compareTo(StreamEntryId other) { + int timeCompare = Long.compare(this.time, other.time); + return timeCompare != 0 ? timeCompare : Long.compare(this.sequence, other.sequence); + } + + @Override + public int hashCode() { + return Objects.hash(time, sequence); + } + + @Override + public boolean equals(Object obj) { + if(obj == this){ + return true; + } + + if(obj instanceof StreamEntryId){ + StreamEntryId that = (StreamEntryId) obj; + return that.time == time && that.sequence == sequence; + } + + return false; + } + + @Override + public String toString() { + return time + "-" + sequence; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamFull.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamFull.java new file mode 100644 index 000000000..b0eb314fc --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamFull.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.utils.ObjectStringBuilder; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +/** + * @author Yong.Teng + * @since 2.0.0 + */ +public class StreamFull implements Serializable { + + private final static long serialVersionUID = -4336316668706617743L; + + private final long length; + + private final long radixTreeKeys; + + private final long radixTreeNodes; + + private final List groups; + + private final StreamEntryId lastGeneratedId; + + private final List entries; + + private final Map infos; + + public StreamFull(final long length, final long radixTreeKeys, final long radixTreeNodes, + final List groups, final StreamEntryId lastGeneratedId, + final List entries, final Map infos){ + this.length = length; + this.radixTreeKeys = radixTreeKeys; + this.radixTreeNodes = radixTreeNodes; + this.groups = groups; + this.lastGeneratedId = lastGeneratedId; + this.entries = entries; + this.infos = infos; + } + + public long getLength(){ + return length; + } + + public long getRadixTreeKeys(){ + return radixTreeKeys; + } + + public long getRadixTreeNodes(){ + return radixTreeNodes; + } + + public List getGroups(){ + return groups; + } + + public StreamEntryId getLastGeneratedId(){ + return lastGeneratedId; + } + + public List getEntries(){ + return entries; + } + + public Map getInfos(){ + return infos; + } + + @Override + public String toString(){ + return ObjectStringBuilder.create() + .add("length", length) + .add("radixTreeKeys", radixTreeKeys) + .add("radixTreeNodes", radixTreeNodes) + .add("groups", groups) + .add("lastGeneratedId", lastGeneratedId) + .add("entries", entries) + .add("infos", infos) + .build(); + } + + /** + * @since 2.0.1 + */ + public final static class Group implements Serializable { + + private static final long serialVersionUID = 560117056010590768L; + + private final String name; + + private final List consumers; + + private final List> pending; + + private final Long pelCount; + + private final StreamEntryId lastDeliveredId; + + private final Map infos; + + public Group(final String name, final List consumers, final List> pending, + final Long pelCount, final StreamEntryId lastDeliveredId, + final Map infos){ + this.name = name; + this.consumers = consumers; + this.pending = pending; + this.pelCount = pelCount; + this.lastDeliveredId = lastDeliveredId; + this.infos = infos; + } + + public String getName(){ + return name; + } + + public List getConsumers(){ + return consumers; + } + + public List> getPending(){ + return pending; + } + + public Long getPelCount(){ + return pelCount; + } + + public StreamEntryId getLastDeliveredId(){ + return lastDeliveredId; + } + + public Map getInfos(){ + return infos; + } + + @Override + public String toString(){ + return ObjectStringBuilder.create() + .add("name", name) + .add("consumers", consumers) + .add("pending", pending) + .add("pelCount", pelCount) + .add("lastDeliveredId", lastDeliveredId) + .add("infos", infos) + .build(); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamGroup.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamGroup.java new file mode 100644 index 000000000..10d21072c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamGroup.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.utils.ObjectStringBuilder; + +import java.io.Serializable; +import java.util.Map; + +/** + * Stream Group + * + * @author Yong.Teng + * @since 2.0.0 + */ +public class StreamGroup implements Serializable { + + private final static long serialVersionUID = -3992031318445262909L; + + private final String name; + + private final long consumers; + + private final long pending; + + private final StreamEntryId lastDeliveredId; + + private final Map infos; + + public StreamGroup(final String name, final long consumers, final long pending, final StreamEntryId lastDeliveredId, + final Map infos){ + this.name = name; + this.consumers = consumers; + this.pending = pending; + this.lastDeliveredId = lastDeliveredId; + this.infos = infos; + } + + public String getName(){ + return name; + } + + public long getConsumers(){ + return consumers; + } + + public long getPending(){ + return pending; + } + + public StreamEntryId getLastDeliveredId(){ + return lastDeliveredId; + } + + public Map getInfos(){ + return infos; + } + + @Override + public String toString(){ + return ObjectStringBuilder.create() + .add("name", name) + .add("consumers", consumers) + .add("pending", pending) + .add("lastDeliveredId", lastDeliveredId) + .add("infos", infos) + .build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamPending.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamPending.java new file mode 100644 index 000000000..8d704afcc --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamPending.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.utils.ObjectStringBuilder; + +import java.io.Serializable; + +/** + * @author Yong.Teng + * @since 2.0.0 + */ +public class StreamPending implements Serializable { + + private static final long serialVersionUID = -9058837565507153831L; + + private final StreamEntryId id; + + private final String consumerName; + + private final long idleTime; + + private final long deliveredTimes; + + public StreamPending(final StreamEntryId id, final String consumerName, final long idleTime, + final long deliveredTimes){ + this.id = id; + this.consumerName = consumerName; + this.idleTime = idleTime; + this.deliveredTimes = deliveredTimes; + } + + public StreamEntryId getId(){ + return id; + } + + public String getConsumerName(){ + return consumerName; + } + + public long getIdleTime(){ + return idleTime; + } + + public long getDeliveredTimes(){ + return deliveredTimes; + } + + @Override + public String toString(){ + return ObjectStringBuilder.create() + .add("id", id) + .add("consumerName", consumerName) + .add("idleTime", idleTime) + .add("deliveredTimes", deliveredTimes) + .build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamPendingSummary.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamPendingSummary.java new file mode 100644 index 000000000..25b54a4c5 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/StreamPendingSummary.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.redis.utils.ObjectStringBuilder; + +import java.io.Serializable; +import java.util.Map; + +/** + * @author Yong.Teng + * @since 2.0.0 + */ +public class StreamPendingSummary implements Serializable { + + private final static long serialVersionUID = 4352578196582945851L; + + private final long total; + + private final StreamEntryId minId; + + private final StreamEntryId maxId; + + private final Map consumerMessageCount; + + public StreamPendingSummary(final long total, final StreamEntryId minId, final StreamEntryId maxId, + final Map consumerMessageCount){ + this.total = total; + this.minId = minId; + this.maxId = maxId; + this.consumerMessageCount = consumerMessageCount; + } + + public long getTotal(){ + return total; + } + + public StreamEntryId getMinId(){ + return minId; + } + + public StreamEntryId getMaxId(){ + return maxId; + } + + public Map getConsumerMessageCount(){ + return consumerMessageCount; + } + + @Override + public String toString(){ + return ObjectStringBuilder.create() + .add("total", total) + .add("minId", minId) + .add("maxId", maxId) + .add("consumerMessageCount", consumerMessageCount) + .build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/Tuple.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/Tuple.java new file mode 100644 index 000000000..ae30c972a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/Tuple.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +import com.buession.core.utils.comparator.ByteArrayComparable; +import com.buession.redis.utils.SafeEncoder; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.Objects; +import java.util.StringJoiner; + +/** + * @author Yong.Teng + */ +public class Tuple implements Comparable, Serializable { + + private final static long serialVersionUID = -6469375940111456577L; + + private final byte[] element; + + private final Double score; + + public Tuple(final String element, final Double score){ + this(SafeEncoder.encode(element), score); + } + + public Tuple(final byte[] element, final Double score){ + super(); + this.element = element; + this.score = score; + } + + public String getElement(){ + return element == null ? null : SafeEncoder.encode(element); + } + + public byte[] getBinaryElement(){ + return element; + } + + public double getScore(){ + return score; + } + + @Override + public int hashCode(){ + final int prime = 31; + int result = 1; + + result = prime * result; + + if(element != null){ + for(byte b : element){ + result = prime * result + b; + } + } + + long temp = Double.doubleToLongBits(score); + return prime * result + (int) (temp ^ (temp >>> 32)); + } + + @Override + public boolean equals(Object obj){ + if(this == obj){ + return true; + } + + if(obj instanceof Tuple){ + Tuple that = (Tuple) obj; + return Arrays.equals(element, that.element) && Objects.equals(score, that.score); + } + + return false; + } + + @Override + public int compareTo(Tuple that){ + int compScore = Double.compare(this.score, that.score); + + if(compScore != 0){ + return compScore; + }else{ + ByteArrayComparable comparable = new ByteArrayComparable(this.element); + return comparable.compareTo(that.element); + } + } + + @Override + public String toString(){ + return new StringJoiner(", ", "{", "}") + .add("element=" + SafeEncoder.encode(element)) + .add("score=" + score) + .toString(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/AclCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/AclCommands.java new file mode 100644 index 000000000..03535cb06 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/AclCommands.java @@ -0,0 +1,307 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.Status; +import com.buession.redis.core.AclCategory; +import com.buession.redis.core.AclLog; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.command.args.AclSetUserArgument; + +import java.util.List; + +/** + * 权限命令 + * + *

详情说明 https://redis.io/docs/latest/commands/acl/

+ * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface AclCommands extends RedisCommands { + + /** + * The command shows the available ACL categories + * + *

详情说明 https://redis.io/commands/acl-cat/

+ * + * @return A list of ACL categories or a list of commands inside a given category + */ + List aclCat(); + + /** + * The command shows all the Redis commands in the specified category + * + *

详情说明 https://redis.io/commands/acl-cat/

+ * + * @param aclCategory + * Acl Category Name + * + * @return A list of ACL categories or a list of commands inside a given category + */ + List aclCat(final AclCategory aclCategory); + + /** + * Delete all the specified ACL users and terminate all the connections that are authenticated with such users + * + *

详情说明 https://redis.io/commands/acl-deluser/

+ * + * @param usernames + * 用户名 + * + * @return 删除用户数量 + */ + Long aclDelUser(final String... usernames); + + /** + * Delete all the specified ACL users and terminate all the connections that are authenticated with such users + * + *

详情说明 https://redis.io/commands/acl-deluser/

+ * + * @param usernames + * 用户名 + * + * @return 删除用户数量 + */ + Long aclDelUser(final byte[]... usernames); + + /** + * Simulate the execution of a given command by a given user. + * This command can be used to test the permissions of a given user without having to enable the user or cause the side effects of running the command. + * + *

详情说明 https://redis.io/docs/latest/commands/acl-dryrun/

+ * + * @param username + * 用户名 + * @param command + * 命令 + * + * @return 操作结果 + */ + Status aclDryRun(final String username, final Command command); + + /** + * Simulate the execution of a given command by a given user. + * This command can be used to test the permissions of a given user without having to enable the user or cause the side effects of running the command. + * + *

详情说明 https://redis.io/docs/latest/commands/acl-dryrun/

+ * + * @param username + * 用户名 + * @param command + * 命令 + * + * @return 操作结果 + */ + Status aclDryRun(final byte[] username, final Command command); + + /** + * Simulate the execution of a given command by a given user. + * This command can be used to test the permissions of a given user without having to enable the user or cause the side effects of running the command. + * + *

详情说明 https://redis.io/docs/latest/commands/acl-dryrun/

+ * + * @param username + * 用户名 + * @param command + * 命令 + * @param arguments + * 命令参数 + * + * @return 操作结果 + */ + Status aclDryRun(final String username, final Command command, final String... arguments); + + /** + * Simulate the execution of a given command by a given user. + * This command can be used to test the permissions of a given user without having to enable the user or cause the side effects of running the command. + * + *

详情说明 https://redis.io/docs/latest/commands/acl-dryrun/

+ * + * @param username + * 用户名 + * @param command + * 命令 + * @param arguments + * 命令参数 + * + * @return 操作结果 + */ + Status aclDryRun(final byte[] username, final Command command, final byte[]... arguments); + + /** + * ACL users need a solid password in order to authenticate to the server without security risks + * + *

详情说明 https://redis.io/commands/acl-genpass/

+ * + * @return By default 64 bytes string representing 256 bits of pseudorandom data + */ + String aclGenPass(); + + /** + * ACL users need a solid password in order to authenticate to the server without security risks + * + *

详情说明 https://redis.io/commands/acl-genpass/

+ * + * @param bits + * 位 + * + * @return By default 64 bytes string representing 256 bits of pseudorandom data + */ + String aclGenPass(final int bits); + + /** + * The command returns all the rules defined for an existing ACL user + * + *

详情说明 https://redis.io/commands/acl-getuser/

+ * + * @param username + * 用户名 + * + * @return A list of ACL rule definitions for the user + */ + AclUser aclGetUser(final String username); + + /** + * The command returns all the rules defined for an existing ACL user + * + *

详情说明 https://redis.io/commands/acl-getuser/

+ * + * @param username + * 用户名 + * + * @return A list of ACL rule definitions for the user + */ + AclUser aclGetUser(final byte[] username); + + /** + * The command shows the currently active ACL rules in the Redis server. + * Each line in the returned array defines a different user, and the format is the same used in the redis.conf + * file or the external ACL file, so you can cut and paste what is returned by the ACL LIST command directly + * inside a configuration file if you wish (but make sure to check ACL SAVE). + * + *

详情说明 https://redis.io/commands/acl-list/

+ * + * @return Acl List + */ + List aclList(); + + /** + * When Redis is configured to use an ACL file (with the aclfile configuration option), + * this command will reload the ACLs from the file, replacing all the current ACL rules with the ones defined in the file + * + *

详情说明 https://redis.io/commands/acl-load/

+ * + * @return Status.SUCCESS + */ + Status aclLoad(); + + /** + * The optional argument specifies how many entries to show. By default up to ten failures are returned + * + *

详情说明 https://redis.io/commands/acl-log/

+ * + * @return A list of ACL security events + */ + List aclLog(); + + /** + * The optional argument specifies how many entries to show. By default up to ten failures are returned + * + *

详情说明 https://redis.io/commands/acl-log/

+ * + * @param count + * 返回数量 + * + * @return A list of ACL security events + */ + List aclLog(final int count); + + /** + * The optional argument specifies how many entries to show. By default up to ten failures are returned + * + *

详情说明 https://redis.io/commands/acl-log/

+ * + * @return 日志重置成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status aclLogReset(); + + /** + * When Redis is configured to use an ACL file (with the aclfile configuration option), + * this command will save the currently defined ACLs from the server memory to the ACL file + * + *

详情说明 https://redis.io/commands/acl-save/

+ * + * @return 保存成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status aclSave(); + + /** + * Create an ACL user with the specified rules or modify the rules of an existing user + * + *

详情说明 https://redis.io/commands/acl-setuser/

+ * + * @param username + * 用户名 + * @param rules + * the specified rules + * + * @return 操作成功,返回 Status.Success;否则,返回 Status.Failure + */ + Status aclSetUser(final String username, final AclSetUserArgument rules); + + /** + * Create an ACL user with the specified rules or modify the rules of an existing user + * + *

详情说明 https://redis.io/commands/acl-setuser/

+ * + * @param username + * 用户名 + * @param rules + * the specified rules + * + * @return 操作成功,返回 Status.Success;否则,返回 Status.Failure + */ + Status aclSetUser(final byte[] username, final AclSetUserArgument rules); + + /** + * The command shows a list of all the usernames of the currently configured users in the Redis ACL system + * + *

详情说明 https://redis.io/commands/acl-users/

+ * + * @return A list of all the usernames of the currently configured users in the Redis ACL system + */ + List aclUsers(); + + /** + * Return the username the current connection is authenticated with + * + *

详情说明 https://redis.io/commands/acl-whoami/

+ * + * @return The username of the current connection + */ + String aclWhoAmI(); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/BitMapCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/BitMapCommands.java new file mode 100644 index 000000000..fc5a79b05 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/BitMapCommands.java @@ -0,0 +1,542 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.redis.core.BitType; +import com.buession.redis.core.BitOperation; +import com.buession.redis.core.command.args.BitFieldArgument; +import com.buession.redis.core.command.args.BitFieldRoArgument; + +import java.util.List; + +/** + * BitMap 命令 + * + *

详情说明 https://redis.io/commands/?group=bitmap

+ * + * @author Yong.Teng + * @since 2.0.0 + */ +public interface BitMapCommands extends RedisCommands { + + /** + * 计算给定字符串中,被设置为 1 的比特位的数量 + * + *

详情说明 http://redisdoc.com/bitmap/bitcount.html

+ * + * @param key + * Key + * + * @return 被设置为 1 的位的数量 + */ + Long bitCount(final String key); + + /** + * 计算给定字符串中,被设置为 1 的比特位的数量 + * + *

详情说明 http://redisdoc.com/bitmap/bitcount.html

+ * + * @param key + * Key + * + * @return 被设置为 1 的位的数量 + */ + Long bitCount(final byte[] key); + + /** + * 计算给定字符串中,被设置为 1 的比特位的数量 + * + *

详情说明 http://redisdoc.com/bitmap/bitcount.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 被设置为 1 的位的数量 + */ + Long bitCount(final String key, final long start, final long end); + + /** + * 计算给定字符串中,被设置为 1 的比特位的数量 + * + *

详情说明 http://redisdoc.com/bitmap/bitcount.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 被设置为 1 的位的数量 + */ + Long bitCount(final byte[] key, final long start, final long end); + + /** + * 计算给定字符串中,被设置为 1 的比特位的数量 + * + *

详情说明 http://redisdoc.com/bitmap/bitcount.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param bitType + * {@link BitType} + * + * @return 被设置为 1 的位的数量 + */ + Long bitCount(final String key, final long start, final long end, final BitType bitType); + + /** + * 计算给定字符串中,被设置为 1 的比特位的数量 + * + *

详情说明 http://redisdoc.com/bitmap/bitcount.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param bitType + * {@link BitType} + * + * @return 被设置为 1 的位的数量 + */ + Long bitCount(final byte[] key, final long start, final long end, final BitType bitType); + + /** + * 可以将一个 Redis 字符串看作是一个由二进制位组成的数组,并对这个数组中储存的长度不同的整数进行访问; + * 可以在一次调用中同时对多个位范围进行操作, + * 它接受一系列待执行的操作作为参数,并返回一个数组作为回复,数组中的每个元素就是对应操作的执行结果 + * + *

详情说明 http://redisdoc.com/bitmap/bitfield.html

+ * + * @param key + * Key + * + * @return 返回值是一个数组,数组中的每个元素对应一个被执行的子命令 + * + * @since 3.0.0 + */ + List bitField(final String key); + + /** + * 可以将一个 Redis 字符串看作是一个由二进制位组成的数组,并对这个数组中储存的长度不同的整数进行访问; + * 可以在一次调用中同时对多个位范围进行操作, + * 它接受一系列待执行的操作作为参数,并返回一个数组作为回复,数组中的每个元素就是对应操作的执行结果 + * + *

详情说明 http://redisdoc.com/bitmap/bitfield.html

+ * + * @param key + * Key + * + * @return 返回值是一个数组,数组中的每个元素对应一个被执行的子命令 + * + * @since 3.0.0 + */ + List bitField(final byte[] key); + + /** + * 可以将一个 Redis 字符串看作是一个由二进制位组成的数组,并对这个数组中储存的长度不同的整数进行访问; + * 可以在一次调用中同时对多个位范围进行操作, + * 它接受一系列待执行的操作作为参数,并返回一个数组作为回复,数组中的每个元素就是对应操作的执行结果 + * + *

详情说明 http://redisdoc.com/bitmap/bitfield.html

+ * + * @param key + * Key + * @param argument + * 命令参数 + * + * @return 返回值是一个数组,数组中的每个元素对应一个被执行的子命令 + * + * @since 2.3.0 + */ + List bitField(final String key, final BitFieldArgument argument); + + /** + * 可以将一个 Redis 字符串看作是一个由二进制位组成的数组,并对这个数组中储存的长度不同的整数进行访问; + * 可以在一次调用中同时对多个位范围进行操作, + * 它接受一系列待执行的操作作为参数,并返回一个数组作为回复,数组中的每个元素就是对应操作的执行结果 + * + *

详情说明 http://redisdoc.com/bitmap/bitfield.html

+ * + * @param key + * Key + * @param argument + * 命令参数 + * + * @return 返回值是一个数组,数组中的每个元素对应一个被执行的子命令 + * + * @since 2.3.0 + */ + List bitField(final byte[] key, final BitFieldArgument argument); + + /** + * 可以将一个 Redis 字符串看作是一个由二进制位组成的数组,并对这个数组中储存的长度不同的整数进行访问; + * 可以在一次调用中同时对多个位范围进行操作, + * 它接受一系列待执行的操作作为参数,并返回一个数组作为回复,数组中的每个元素就是对应操作的执行结果 + * + *

详情说明 http://redisdoc.com/bitmap/bitfield.html

+ * + * @param key + * Key + * + * @return 返回值是一个数组,数组中的每个元素对应一个被执行的子命令 + */ + List bitFieldRo(final String key); + + /** + * 可以将一个 Redis 字符串看作是一个由二进制位组成的数组,并对这个数组中储存的长度不同的整数进行访问; + * 可以在一次调用中同时对多个位范围进行操作, + * 它接受一系列待执行的操作作为参数,并返回一个数组作为回复,数组中的每个元素就是对应操作的执行结果 + * + *

详情说明 http://redisdoc.com/bitmap/bitfield.html

+ * + * @param key + * Key + * + * @return 返回值是一个数组,数组中的每个元素对应一个被执行的子命令 + */ + List bitFieldRo(final byte[] key); + + /** + * 可以将一个 Redis 字符串看作是一个由二进制位组成的数组,并对这个数组中储存的长度不同的整数进行访问; + * 可以在一次调用中同时对多个位范围进行操作, + * 它接受一系列待执行的操作作为参数,并返回一个数组作为回复,数组中的每个元素就是对应操作的执行结果 + * + *

详情说明 http://redisdoc.com/bitmap/bitfield.html

+ * + * @param key + * Key + * @param argument + * 命令参数 + * + * @return 返回值是一个数组,数组中的每个元素对应一个被执行的子命令 + */ + List bitFieldRo(final String key, final BitFieldRoArgument argument); + + /** + * 可以将一个 Redis 字符串看作是一个由二进制位组成的数组,并对这个数组中储存的长度不同的整数进行访问; + * 可以在一次调用中同时对多个位范围进行操作, + * 它接受一系列待执行的操作作为参数,并返回一个数组作为回复,数组中的每个元素就是对应操作的执行结果 + * + *

详情说明 http://redisdoc.com/bitmap/bitfield.html

+ * + * @param key + * Key + * @param argument + * 命令参数 + * + * @return 返回值是一个数组,数组中的每个元素对应一个被执行的子命令 + */ + List bitFieldRo(final byte[] key, final BitFieldRoArgument argument); + + /** + * 对一个或多个保存二进制位的字符串 key 进行位元操作,并将结果保存到 destKey 上, + * 除了 Operation.NOT 操作之外,其他操作都可以接受一个或多个 key 作为输入 + * + *

详情说明 http://redisdoc.com/bitmap/bitop.html

+ * + * @param operation + * 运算操作 + * @param destKey + * 目标 Key + * @param keys + * Keys + * + * @return 保存到 destKey 的字符串的长度 + */ + Long bitOp(final BitOperation operation, final String destKey, final String... keys); + + /** + * 对一个或多个保存二进制位的字符串 key 进行位元操作,并将结果保存到 destKey 上, + * 除了 Operation.NOT 操作之外,其他操作都可以接受一个或多个 key 作为输入 + * + *

详情说明 http://redisdoc.com/bitmap/bitop.html

+ * + * @param operation + * 运算操作 + * @param destKey + * 目标 Key + * @param keys + * Keys + * + * @return 保存到 destKey 的字符串的长度 + */ + Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys); + + /** + * 获取位图中第一个值为 bit 的二进制位的位置 + * + *

详情说明 http://redisdoc.com/bitmap/bitpos.html

+ * + * @param key + * Key + * @param value + * 位 + * + * @return 位图中第一个值为 bit 的二进制位的位置 + */ + Long bitPos(final String key, final boolean value); + + /** + * 获取位图中第一个值为 bit 的二进制位的位置 + * + *

详情说明 http://redisdoc.com/bitmap/bitpos.html

+ * + * @param key + * Key + * @param value + * 位 + * + * @return 位图中第一个值为 bit 的二进制位的位置 + */ + Long bitPos(final byte[] key, final boolean value); + + /** + * 获取位图中第一个值为 bit 的二进制位的位置 + * + *

详情说明 http://redisdoc.com/bitmap/bitpos.html

+ * + * @param key + * Key + * @param value + * 位 + * @param start + * 开始位置 + * + * @return 位图中第一个值为 bit 的二进制位的位置 + * + * @since 3.0.0 + */ + Long bitPos(final String key, final boolean value, final long start); + + /** + * 获取位图中第一个值为 bit 的二进制位的位置 + * + *

详情说明 http://redisdoc.com/bitmap/bitpos.html

+ * + * @param key + * Key + * @param value + * 位 + * @param start + * 开始位置 + * + * @return 位图中第一个值为 bit 的二进制位的位置 + * + * @since 3.0.0 + */ + Long bitPos(final byte[] key, final boolean value, final long start); + + /** + * 获取位图中第一个值为 bit 的二进制位的位置 + * + *

详情说明 http://redisdoc.com/bitmap/bitpos.html

+ * + * @param key + * Key + * @param value + * 位 + * @param start + * 开始位置 + * @param bitType + * {@link BitType} + * + * @return 位图中第一个值为 bit 的二进制位的位置 + * + * @since 3.0.0 + */ + Long bitPos(final String key, final boolean value, final long start, final BitType bitType); + + /** + * 获取位图中第一个值为 bit 的二进制位的位置 + * + *

详情说明 http://redisdoc.com/bitmap/bitpos.html

+ * + * @param key + * Key + * @param value + * 位 + * @param start + * 开始位置 + * @param bitType + * {@link BitType} + * + * @return 位图中第一个值为 bit 的二进制位的位置 + * + * @since 3.0.0 + */ + Long bitPos(final byte[] key, final boolean value, final long start, final BitType bitType); + + /** + * 获取位图中第一个值为 bit 的二进制位的位置 + * + *

详情说明 http://redisdoc.com/bitmap/bitpos.html

+ * + * @param key + * Key + * @param value + * 位 + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 位图中第一个值为 bit 的二进制位的位置 + */ + Long bitPos(final String key, final boolean value, final long start, final long end); + + /** + * 获取位图中第一个值为 bit 的二进制位的位置 + * + *

详情说明 http://redisdoc.com/bitmap/bitpos.html

+ * + * @param key + * Key + * @param value + * 位 + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 位图中第一个值为 bit 的二进制位的位置 + */ + Long bitPos(final byte[] key, final boolean value, final long start, final long end); + + /** + * 获取位图中第一个值为 bit 的二进制位的位置 + * + *

详情说明 http://redisdoc.com/bitmap/bitpos.html

+ * + * @param key + * Key + * @param value + * 位 + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param bitType + * {@link BitType} + * + * @return 位图中第一个值为 bit 的二进制位的位置 + * + * @since 3.0.0 + */ + Long bitPos(final String key, final boolean value, final long start, final long end, final BitType bitType); + + /** + * 获取位图中第一个值为 bit 的二进制位的位置 + * + *

详情说明 http://redisdoc.com/bitmap/bitpos.html

+ * + * @param key + * Key + * @param value + * 位 + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param bitType + * {@link BitType} + * + * @return 位图中第一个值为 bit 的二进制位的位置 + * + * @since 3.0.0 + */ + Long bitPos(final byte[] key, final boolean value, final long start, final long end, final BitType bitType); + + /** + * 获取 key 指定偏移量上的位 + * + *

详情说明 http://redisdoc.com/bitmap/getbit.html

+ * + * @param key + * Key + * @param offset + * 偏移量 + * + * @return Key 指定偏移量上的位 + */ + Boolean getBit(final String key, final long offset); + + /** + * 获取 key 指定偏移量上的位 + * + *

详情说明 http://redisdoc.com/bitmap/getbit.html

+ * + * @param key + * Key + * @param offset + * 偏移量 + * + * @return Key 指定偏移量上的位 + */ + Boolean getBit(final byte[] key, final long offset); + + /** + * 对 key 所储存的字符串值,设置或清除指定偏移量上的位;位的设置或清除取决于 value 参数 + * + *

详情说明 http://redisdoc.com/bitmap/setbit.html

+ * + * @param key + * Key + * @param offset + * 偏移量 + * @param value + * true 设置位,false 清除位 + * + * @return 偏移量原来储存的位 + */ + Boolean setBit(final String key, final long offset, final boolean value); + + /** + * 对 key 所储存的字符串值,设置或清除指定偏移量上的位;位的设置或清除取决于 value 参数 + * + *

详情说明 http://redisdoc.com/bitmap/setbit.html

+ * + * @param key + * Key + * @param offset + * 偏移量 + * @param value + * true 设置位,false 清除位 + * + * @return 偏移量原来储存的位 + */ + Boolean setBit(final byte[] key, final long offset, final boolean value); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ClusterCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ClusterCommands.java new file mode 100644 index 000000000..66e20ece5 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ClusterCommands.java @@ -0,0 +1,501 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.core.BumpEpoch; +import com.buession.redis.core.ClusterFailoverOption; +import com.buession.redis.core.ClusterInfo; +import com.buession.redis.core.ClusterLink; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.ClusterResetOption; +import com.buession.redis.core.ClusterSetSlotOption; +import com.buession.redis.core.ClusterRedisShard; +import com.buession.redis.core.ClusterSlot; +import com.buession.redis.core.SlotRange; + +import java.util.List; + +/** + * 集群命令 + * + *

详情说明 https://redis.io/docs/latest/commands/?group=cluster

+ * + * @author Yong.Teng + * @since 2.0.0 + */ +public interface ClusterCommands extends RedisCommands { + + /** + * When a cluster client receives an -ASK redirect, + * the ASKING command is sent to the target node followed by the command which was redirected. + * This is normally done automatically by cluster clients. + * + *

详情说明 https://redis.io/commands/asking/

+ * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status asking(); + + /** + * 把一组 hash slots 分配给接收命令的节点 + * + *

详情说明 http://www.redis.cn/commands/cluster-addslots.html

+ * + * @param slots + * hash slots + * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status clusterAddSlots(final int... slots); + + /** + * The {@code CLUSTER ADDSLOTSRANGE} is similar to the {@code CLUSTER ADDSLOTS} command in that they both assign + * hash slots to nodes. + * + *

详情说明 https://redis.io/docs/latest/commands/cluster-addslotsrange/

+ * + * @param slots + * hash slots + * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + * + * @since 3.0.0 + */ + Status clusterAddSlotsRange(final SlotRange... slots); + + /** + * The CLUSTER BUMPEPOCH command triggers an increment to the cluster’s config epoch from the connected node. + * The epoch will be incremented if the node’s config epoch is zero, or if it is less than the cluster’s greatest epoch. + * + *

详情说明 https://redis.io/commands/cluster-bumpepoch/

+ * + * @return {@link BumpEpoch} + */ + KeyValue clusterBumpEpoch(); + + /** + * The command returns the number of failure reports for the specified node + * + *

详情说明 https://redis.io/commands/cluster-count-failure-reports/

+ * + * @param nodeId + * 节点 Id + * + * @return The number of active failure reports for the node + */ + Long clusterCountFailureReports(final String nodeId); + + /** + * The command returns the number of failure reports for the specified node + * + *

详情说明 https://redis.io/commands/cluster-count-failure-reports/

+ * + * @param nodeId + * 节点 Id + * + * @return The number of active failure reports for the node + */ + Long clusterCountFailureReports(final byte[] nodeId); + + /** + * 返回连接节点负责的指定 hash slot 的 key 的数量; + * 只查询连接节点的数据集,所以如果连接节点指派到该 hash slot 会返回 0 + * + *

详情说明 http://www.redis.cn/commands/cluster-countkeysinslot.html

+ * + * @param slot + * hash slot + * + * @return 连接节点负责的指定 hash slot 的 key 的数量 + */ + Long clusterCountKeysInSlot(final int slot); + + /** + * 使一个特定的 Redis Cluster 节点去忘记一个主节点正在负责的哈希槽 + * + *

详情说明 http://www.redis.cn/commands/cluster-delslots.html

+ * + * @param slots + * hash slots + * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status clusterDelSlots(final int... slots); + + /** + * The {@cpde CLUSTER DELSLOTSRANGE} command is similar to the {@cpde CLUSTER DELSLOTS} command in that they both + * remove hash slots from the node. + * + *

详情说明 http://www.redis.cn/commands/cluster-delslots.html

+ * + * @param slots + * hash slots + * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + * + * @since 3.0.0 + */ + Status clusterDelSlotsRange(final SlotRange... slots); + + /** + * 让 slave 节点进行一次人工故障切换 + * + *

详情说明 http://www.redis.cn/commands/cluster-failover.html

+ * + * @param clusterFailoverOption + * 切换选项 + * + * @return 该命令已被接受并进行人工故障转移,返回 Status.SUCCESS;切换操作无法执行,返回 Status.FAILURE + */ + Status clusterFailover(final ClusterFailoverOption clusterFailoverOption); + + /** + * Deletes all slots from a node + * + *

详情说明 https://redis.io/commands/cluster-flushslots/

+ * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status clusterFlushSlots(); + + /** + * 从收到命令的 Redis 群集节点的节点信息列表中移除指定ID的节点 + * + *

详情说明 http://www.redis.cn/commands/cluster-forget.html

+ * + * @param nodeId + * 节点 Id + * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status clusterForget(final String nodeId); + + /** + * 从收到命令的 Redis 群集节点的节点信息列表中移除指定ID的节点 + * + *

详情说明 http://www.redis.cn/commands/cluster-forget.html

+ * + * @param nodeId + * 节点 Id + * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status clusterForget(final byte[] nodeId); + + /** + * 返回存储在连接节点的指定 hash slot 里面的 key 的列表 + * + *

详情说明 http://www.redis.cn/commands/cluster-getkeysinslot.html

+ * + * @param slot + * hash slot + * @param count + * 返回数量 + * + * @return count 个储在连接节点的指定 hash slot 里面的 key 的列表 + */ + List clusterGetKeysInSlot(final int slot, final int count); + + /** + * 返回 Redis 集群信息 + * + *

详情说明 http://www.redis.cn/commands/cluster-info.html

+ * + * @return Redis 集群信息 + */ + ClusterInfo clusterInfo(); + + /** + * 返回一个整数,用于标识指定键所散列到的哈希槽 + * + *

详情说明 http://www.redis.cn/commands/cluster-keyslot.html

+ * + * @param key + * Key + * + * @return 哈希槽的值 + */ + Long clusterKeySlot(final String key); + + /** + * 返回一个整数,用于标识指定键所散列到的哈希槽 + * + *

详情说明 http://www.redis.cn/commands/cluster-keyslot.html

+ * + * @param key + * Key + * + * @return 哈希槽的值 + */ + Long clusterKeySlot(final byte[] key); + + /** + * Each node in a Redis Cluster maintains a pair of long-lived TCP link with each peer in the cluster: + * One for sending outbound messages towards the peer and one for receiving inbound messages from the peer. + * + *

详情说明 https://redis.io/docs/latest/commands/cluster-links/

+ * + * @return 返回当前节点 Id + * + * @since 3.0.0 + */ + List clusterLinks(); + + /** + * 用来连接不同的开启集群支持的 Redis 节点,以进入工作集群 + * + *

详情说明 http://www.redis.cn/commands/cluster-meet.html

+ * + * @param ip + * Redis 集群节点 IP + * @param port + * Redis 集群节点端口 + * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status clusterMeet(final String ip, final int port); + + /** + * 返回当前节点 Id + * + *

详情说明 https://redis.io/commands/cluster-myid/

+ * + * @return 返回当前节点 Id + */ + String clusterMyId(); + + /** + * The {@code CLUSTER MYSHARDID} command returns the unique, + * auto-generated identifier that is associated with the shard to which the connected cluster node belongs. + * + *

详情说明 https://redis.io/docs/latest/commands/cluster-myshardid/

+ * + * @return 返回当前节点 Id + * + * @since 3.0.0 + */ + String clusterMyShardId(); + + /** + * 当前连接节点所属集群的配置信息 + * + *

详情说明 http://www.redis.cn/commands/cluster-nodes.html

+ * + * @return 集群配置信息 + */ + List clusterNodes(); + + /** + * 列出指定主节点的辅助副本节点 + * + *

详情说明 http://www.redis.cn/commands/cluster-replicas.html

+ * + * @param nodeId + * 节点 Id + * + * @return 主节点的辅助副本节点 + */ + List clusterReplicas(final String nodeId); + + /** + * 列出指定主节点的辅助副本节点 + * + *

详情说明 http://www.redis.cn/commands/cluster-replicas.html

+ * + * @param nodeId + * 节点 Id + * + * @return 主节点的辅助副本节点 + */ + List clusterReplicas(final byte[] nodeId); + + /** + * 重新配置一个节点成为指定master的salve节点 + * + *

详情说明 http://www.redis.cn/commands/cluster-replicate.html

+ * + * @param nodeId + * 节点 Id + * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status clusterReplicate(final String nodeId); + + /** + * 重新配置一个节点成为指定master的salve节点 + * + *

详情说明 http://www.redis.cn/commands/cluster-replicate.html

+ * + * @param nodeId + * 节点 Id + * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status clusterReplicate(final byte[] nodeId); + + /** + * Reset 集群 + * + *

详情说明 http://www.redis.cn/commands/cluster-reset.html

+ * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status clusterReset(); + + /** + * Reset 集群 + * + *

详情说明 http://www.redis.cn/commands/cluster-reset.html

+ * + * @param clusterResetOption + * Reset 类型 + * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status clusterReset(final ClusterResetOption clusterResetOption); + + /** + * 强制保存配置 nodes.conf 至磁盘 + * + *

详情说明 http://www.redis.cn/commands/cluster-saveconfig.html

+ * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status clusterSaveConfig(); + + /** + * 为一个全新的节点设置指定的 config epoch,仅在如下情况下有效: + * 1)节点的节点信息表为空 + * 2)节点的当前 config epoch 为 0 + * + *

详情说明 http://www.redis.cn/commands/cluster-set-config-epoch.html

+ * + * @param configEpoch + * Config Epoch + * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status clusterSetConfigEpoch(final long configEpoch); + + /** + * 根据如下子命令选项,修改接受节点中哈希槽的状态 + * + *

详情说明 http://www.redis.cn/commands/cluster-setslot.html

+ * + * @param slot + * hash slot + * @param setSlotOption + * 命令选项 {@link ClusterSetSlotOption} + * @param nodeId + * 节点 Id + * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId); + + /** + * 根据如下子命令选项,修改接受节点中哈希槽的状态 + * + *

详情说明 http://www.redis.cn/commands/cluster-setslot.html

+ * + * @param slot + * hash slot + * @param setSlotOption + * 命令选项 {@link ClusterSetSlotOption} + * @param nodeId + * 节点 Id + * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final byte[] nodeId); + + /** + * {@code CLUSTER SHARDS} returns details about the shards of the cluster. A shard is defined as a collection of + * nodes that serve the same set of slots and that replicate from each other. A shard may only have a single + * master at a given time, but may have multiple or no replicas. It is possible for a shard to not be serving any + * slots while still having replicas. + * + *

详情说明 https://redis.io/docs/latest/commands/cluster-shards/

+ * + * @return The details about the shards of the cluster. + * + * @since 3.0.0 + */ + List clusterShards(); + + /** + * 列出指定 master 节点所有 slave 节点 + * + *

详情说明 http://www.redis.cn/commands/cluster-slaves.html

+ * + * @param nodeId + * Master 节点 Id + * + * @return 指定 master 节点所有 slave 节点 + */ + List clusterSlaves(final String nodeId); + + /** + * 列出指定 master 节点所有 slave 节点 + * + *

详情说明 http://www.redis.cn/commands/cluster-slaves.html

+ * + * @param nodeId + * Master 节点 Id + * + * @return 指定 master 节点所有 slave 节点 + */ + List clusterSlaves(final byte[] nodeId); + + /** + * 返回哈希槽和 Redis 实例映射关系 + * + *

详情说明 http://www.redis.cn/commands/cluster-slots.html

+ * + * @return 哈希槽和 Redis 实例映射关系 + */ + List clusterSlots(); + + /** + * 开启与 Redis Cluster 从节点连接的读请求,通过该命令将从节点设置为只读模式 + * + *

详情说明 http://www.redis.cn/commands/readonly.html

+ * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status readOnly(); + + /** + * 将连接的只读模式重置为读写模式 + * + *

详情说明 http://www.redis.cn/commands/readwrite.html

+ * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status readWrite(); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/Command.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/Command.java new file mode 100644 index 000000000..e5dead0b5 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/Command.java @@ -0,0 +1,735 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.core.validator.Validate; +import com.buession.redis.utils.SafeEncoder; + +/** + * Redis 协议命令 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public enum Command implements ProtocolCommand { + + /** + * BitMap command start + **/ + BITCOUNT("r", CommandGroup.BITMAP), + + BITFIELD("r", CommandGroup.BITMAP), + + BITFIELD_RO("r", CommandGroup.BITMAP), + + BITOP("r", CommandGroup.BITMAP), + + BITPOS("r", CommandGroup.BITMAP), + + GETBIT("r", CommandGroup.BITMAP), + + SETBIT("w", CommandGroup.BITMAP), + /** + * BitMap command end + **/ + + /** + * Cluster command start + **/ + ASKING("r", CommandGroup.CLUSTER), + + CLUSTER("rw", CommandGroup.CLUSTER, SubCommand.CLUSTER_ADDSLOTS, SubCommand.CLUSTER_ADDSLOTSRANGE, + SubCommand.CLUSTER_BUMPEPOCH, SubCommand.CLUSTER_COUNTFAILUREREPORTS, SubCommand.CLUSTER_COUNTKEYSINSLOT, + SubCommand.CLUSTER_DELSLOTS, SubCommand.CLUSTER_DELSLOTSRANGE, SubCommand.CLUSTER_FAILOVER, + SubCommand.CLUSTER_FLUSHSLOTS, SubCommand.CLUSTER_FORGET, SubCommand.CLUSTER_GETKEYSINSLOT, + SubCommand.INFO, SubCommand.CLUSTER_KEYSLOT, SubCommand.CLUSTER_LINKS, SubCommand.CLUSTER_MEET, + SubCommand.CLUSTER_MYID, SubCommand.CLUSTER_MYSHARDID, SubCommand.NODES, SubCommand.CLUSTER_REPLICAS, + SubCommand.CLUSTER_REPLICATE, SubCommand.RESET, SubCommand.CLUSTER_SAVECONFIG, + SubCommand.CLUSTER_SETCONFIGEPOCH, SubCommand.CLUSTER_SETSLOT, SubCommand.CLUSTER_SHARDS, + SubCommand.SLAVES, SubCommand.CLUSTER_SLOTS), + + READONLY("r", CommandGroup.CLUSTER), + + READWRITE("r", CommandGroup.CLUSTER), + /** + * Cluster command end + **/ + + /** + * Connection command start + */ + AUTH("rw", CommandGroup.CONNECTION), + + CLIENT("rw", CommandGroup.CONNECTION, SubCommand.CLIENT_CACHING, SubCommand.CLIENT_GETNAME, + SubCommand.CLIENT_GETREDIR, SubCommand.CLIENT_ID, SubCommand.CLIENT_INFO, SubCommand.CLIENT_KILL, + SubCommand.CLIENT_LIST, SubCommand.CLIENT_NO_EVICT, SubCommand.CLIENT_NO_TOUCH, SubCommand.CLIENT_PAUSE, + SubCommand.CLIENT_REPLY, SubCommand.CLIENT_SETINFO, SubCommand.CLIENT_SETNAME, SubCommand.CLIENT_TRACKING, + SubCommand.CLIENT_TRACKINGINFO, SubCommand.CLIENT_UNBLOCK, SubCommand.CLIENT_UNPAUSE), + + ECHO("w", CommandGroup.CONNECTION), + + HELLO("w", CommandGroup.CONNECTION), + + PING("r", CommandGroup.CONNECTION), + + QUIT("rw", CommandGroup.CONNECTION), + + RESET("w", CommandGroup.CONNECTION), + + SELECT("w", CommandGroup.CONNECTION), + /** + * Connection command end + */ + + /** + * Key command start + **/ + COPY("rw", CommandGroup.KEY), + + DEL("rw", CommandGroup.KEY), + + DUMP("r", CommandGroup.KEY), + + EXISTS("r", CommandGroup.KEY), + + EXPIRE("w", CommandGroup.KEY), + + EXPIREAT("w", CommandGroup.KEY), + + EXPIRETIME("r", CommandGroup.KEY), + + KEYS("r", CommandGroup.KEY), + + MIGRATE("w", CommandGroup.KEY), + + MOVE("w", CommandGroup.KEY), + + OBJECT("rw", CommandGroup.KEY, SubCommand.OBJECT_ENCODING, SubCommand.OBJECT_REFQ, SubCommand.OBJECT_IDLETIME, + SubCommand.OBJECT_REFCOUNT), + + PERSIST("w", CommandGroup.KEY), + + PEXPIRE("w", CommandGroup.KEY), + + PEXPIREAT("w", CommandGroup.KEY), + + PEXPIRETIME("r", CommandGroup.KEY), + + PTTL("r", CommandGroup.KEY), + + RANDOMKEY("r", CommandGroup.KEY), + + RENAME("w", CommandGroup.KEY), + + RENAMENX("w", CommandGroup.KEY), + + RESTORE("w", CommandGroup.KEY), + + SCAN("r", CommandGroup.KEY), + + SORT("rw", CommandGroup.KEY), + + SORT_RO("r", CommandGroup.KEY), + + TOUCH("w", CommandGroup.KEY), + + TTL("r", CommandGroup.KEY), + + TYPE("r", CommandGroup.KEY), + + UNLINK("w", CommandGroup.KEY), + /** + * Key command end + **/ + + /** + * Generic command start + **/ + WAIT("w", CommandGroup.KEY), + + WAITOF("w", CommandGroup.KEY), + /** + * Generic command end + **/ + + /** + * Geo command start + **/ + GEOADD("w", CommandGroup.GEO), + + GEODIST("r", CommandGroup.GEO), + + GEOHASH("r", CommandGroup.GEO), + + GEOPOS("r", CommandGroup.GEO), + + GEORADIUS("r", CommandGroup.GEO), + + GEORADIUS_RO("r", CommandGroup.GEO), + + GEORADIUSBYMEMBER("r", CommandGroup.GEO), + + GEORADIUSBYMEMBER_RO("r", CommandGroup.GEO), + + GEOSEARCH("r", CommandGroup.GEO), + + GEOSEARCHSTORE("rw", CommandGroup.GEO), + /** + * Geo command end + **/ + + /** + * Hash command start + **/ + HDEL("w", CommandGroup.HASH), + + HEXISTS("r", CommandGroup.HASH), + + HEXPIRE("w", CommandGroup.HASH), + + HEXPIREAT("w", CommandGroup.HASH), + + HEXPIRETIME("r", CommandGroup.HASH), + + HGET("r", CommandGroup.HASH), + + HGETALL("r", CommandGroup.HASH), + + HINCRBY("rw", CommandGroup.HASH), + + HINCRBYFLOAT("rw", CommandGroup.HASH), + + HKEYS("r", CommandGroup.HASH), + + HLEN("r", CommandGroup.HASH), + + HMGET("r", CommandGroup.HASH), + + HMSET("w", CommandGroup.HASH), + + HPERSIST("w", CommandGroup.HASH), + + HPEXPIRE("w", CommandGroup.HASH), + + HPEXPIREAT("w", CommandGroup.HASH), + + HPEXPIRETIME("r", CommandGroup.HASH), + + HPTTL("r", CommandGroup.HASH), + + HRANDFIELD("r", CommandGroup.HASH), + + HSCAN("r", CommandGroup.HASH), + + HSET("w", CommandGroup.HASH), + + HSETNX("w", CommandGroup.HASH), + + HSTRLEN("r", CommandGroup.HASH), + + HTTL("r", CommandGroup.HASH), + + HVALS("r", CommandGroup.HASH), + /** + * Hash command start + **/ + + /** + * Hyperloglog command start + **/ + PFADD("w", CommandGroup.HYPERLOGLOG), + + PFCOUNT("r", CommandGroup.HYPERLOGLOG), + + PFMERGE("w", CommandGroup.HYPERLOGLOG), + /** + * Hyperloglog command end + **/ + + /** + * ACL command start + **/ + ACL("rw", CommandGroup.ACL, SubCommand.ACL_CAT, SubCommand.ACL_DELUSER, SubCommand.ACL_DRYRUN, + SubCommand.ACL_GENPASS, SubCommand.ACL_GETUSER, SubCommand.LIST, SubCommand.LOAD, SubCommand.ACL_LOG, + SubCommand.SAVE, SubCommand.ACL_SETUSER, SubCommand.ACL_USERS, SubCommand.ACL_WHOAMI), + /** + * ACL command end + **/ + + /** + * list command start + **/ + BLPOP(CommandGroup.LIST), + + BRPOP(CommandGroup.LIST), + + BRPOPLPUSH(CommandGroup.LIST), + + LINDEX(CommandGroup.LIST), + + LINSERT(CommandGroup.LIST), + + LLEN(CommandGroup.LIST), + + LPOP(CommandGroup.LIST), + + LPOS(CommandGroup.LIST), + + LPUSH(CommandGroup.LIST), + + LPUSHX(CommandGroup.LIST), + + LRANGE(CommandGroup.LIST), + + LREM(CommandGroup.LIST), + + LSET(CommandGroup.LIST), + + LTRIM(CommandGroup.LIST), + + RPOP(CommandGroup.LIST), + + RPOPLPUSH(CommandGroup.LIST), + + RPUSH(CommandGroup.LIST), + + RPUSHX(CommandGroup.LIST), + + LMOVE(CommandGroup.LIST), + + BLMOVE(CommandGroup.LIST), + /** + * list command end + **/ + + /** + * pubsub command start + **/ + PSUBSCRIBE(CommandGroup.PUBSUB), + + PUBSUB_CHANNELS(CommandGroup.PUBSUB), + + PUBSUB_SHARDCHANNELS(CommandGroup.PUBSUB), + + PUBSUB_NUMPAT(CommandGroup.PUBSUB), + + PUBSUB_NUMSUB(CommandGroup.PUBSUB), + + PUBSUB_SHARDNUMSUB(CommandGroup.PUBSUB), + + PUBLISH(CommandGroup.PUBSUB), + + PUNSUBSCRIBE(CommandGroup.PUBSUB), + + SUBSCRIBE(CommandGroup.PUBSUB), + + UNSUBSCRIBE(CommandGroup.PUBSUB), + /** + * pubsub command end + **/ + + /** + * scripting command start + **/ + EVAL(CommandGroup.SCRIPTING), + + EVALSHA(CommandGroup.SCRIPTING), + + SCRIPT_EXISTS(CommandGroup.SCRIPTING), + + SCRIPT_FLUSH(CommandGroup.SCRIPTING), + + SCRIPT_KILL(CommandGroup.SCRIPTING), + + SCRIPT_LOAD(CommandGroup.SCRIPTING), + /** + * scripting command end + **/ + + /** + * server command start + **/ + + + BGREWRITEAOF(CommandGroup.SERVER), + + BGSAVE(CommandGroup.SERVER), + + CONFIG_GET(CommandGroup.SERVER), + + CONFIG_RESETSTAT(CommandGroup.SERVER), + + CONFIG_REWRITE(CommandGroup.SERVER), + + CONFIG_SET(CommandGroup.SERVER), + + DBSIZE(CommandGroup.SERVER), + + DEBUG(CommandGroup.SERVER), + + FLUSHALL(CommandGroup.SERVER), + + FLUSHDB(CommandGroup.SERVER), + + INFO(CommandGroup.SERVER), + + LASTSAVE(CommandGroup.SERVER), + + MEMORY_DOCTOR(CommandGroup.SERVER), + + MEMORY_MALLOCSTATS(CommandGroup.SERVER), + + MEMORY_PURGE(CommandGroup.SERVER), + + MEMORY_STATS(CommandGroup.SERVER), + + MEMORY_USAGE(CommandGroup.SERVER), + + MONITOR(CommandGroup.SERVER), + + REPLICAOF(CommandGroup.SERVER), + + ROLE(CommandGroup.SERVER), + + SAVE(CommandGroup.SERVER), + + SHUTDOWN(CommandGroup.SERVER), + + SLAVEOF(CommandGroup.SERVER), + + SLOWLOG_GET(CommandGroup.SERVER), + + SLOWLOG_LEN(CommandGroup.SERVER), + + SLOWLOG_RESET(CommandGroup.SERVER), + + SYNC(CommandGroup.SERVER), + + PSYNC(CommandGroup.SERVER), + + TIME(CommandGroup.SERVER), + + FAILOVER(CommandGroup.SERVER), + + MODULE_LIST(CommandGroup.SERVER), + + MODULE_LOAD(CommandGroup.SERVER), + + MODULE_UNLOAD(CommandGroup.SERVER), + + SWAPDB(CommandGroup.SERVER), + /** + * server command end + **/ + + /** + * set command start + **/ + SADD(CommandGroup.SET), + + SCARD(CommandGroup.SET), + + SDIFF(CommandGroup.SET), + + SDIFFSTORE(CommandGroup.SET), + + SINTER(CommandGroup.SET), + + SINTERSTORE(CommandGroup.SET), + + SISMEMBER(CommandGroup.SET), + + SMISMEMBER(CommandGroup.SET), + + SMEMBERS(CommandGroup.SET), + + SMOVE(CommandGroup.SET), + + SPOP(CommandGroup.SET), + + SRANDMEMBER(CommandGroup.SET), + + SREM(CommandGroup.SET), + + SSCAN(CommandGroup.SET), + + SUNION(CommandGroup.SET), + + SUNIONSTORE(CommandGroup.SET), + /** + * set command end + **/ + + /** + * sorted set command start + **/ + ZADD(CommandGroup.SORTEDSET), + + ZCARD(CommandGroup.SORTEDSET), + + ZCOUNT(CommandGroup.SORTEDSET), + + ZINCRBY(CommandGroup.SORTEDSET), + + ZINTERSTORE(CommandGroup.SORTEDSET), + + ZLEXCOUNT(CommandGroup.SORTEDSET), + + ZMSCORE(CommandGroup.SORTEDSET), + + ZRANGE(CommandGroup.SORTEDSET), + + ZRANGEBYLEX(CommandGroup.SORTEDSET), + + ZRANGEBYSCORE(CommandGroup.SORTEDSET), + + ZRANGESTORE(CommandGroup.SORTEDSET), + + ZRANK(CommandGroup.SORTEDSET), + + ZPOPMAX(CommandGroup.SORTEDSET), + + ZPOPMIN(CommandGroup.SORTEDSET), + + ZREM(CommandGroup.SORTEDSET), + + ZREMRANGEBYLEX(CommandGroup.SORTEDSET), + + ZREMRANGEBYSCORE(CommandGroup.SORTEDSET), + + ZREMRANGEBYRANK(CommandGroup.SORTEDSET), + + ZREVRANGE(CommandGroup.SORTEDSET), + + ZREVRANGEBYLEX(CommandGroup.SORTEDSET), + + ZREVRANGEBYSCORE(CommandGroup.SORTEDSET), + + ZREVRANK(CommandGroup.SORTEDSET), + + ZSCAN(CommandGroup.SORTEDSET), + + ZSCORE(CommandGroup.SORTEDSET), + + ZUNIONSTORE(CommandGroup.SORTEDSET), + + BZPOPMIN(CommandGroup.SORTEDSET), + + BZPOPMAX(CommandGroup.SORTEDSET), + + ZDIFF(CommandGroup.SORTEDSET), + + ZDIFFSTORE(CommandGroup.SORTEDSET), + + ZINTER(CommandGroup.SORTEDSET), + + ZRANDMEMBER(CommandGroup.SORTEDSET), + + ZUNION(CommandGroup.SORTEDSET), + /** + * sorted set command end + **/ + + /** + * stream command start + **/ + XACK(CommandGroup.STREAM), + + XADD(CommandGroup.STREAM), + + XAUTOCLAIM(CommandGroup.STREAM), + + XCLAIM(CommandGroup.STREAM), + + XDEL(CommandGroup.STREAM), + + XGROUP_CREATE(CommandGroup.STREAM), + + XGROUP_CREATECONSUMER(CommandGroup.STREAM), + + XGROUP_DELCONSUMER(CommandGroup.STREAM), + + XGROUP_DESTROY(CommandGroup.STREAM), + + XGROUP_SETID(CommandGroup.STREAM), + + XINFO_CONSUMERS(CommandGroup.STREAM), + + XINFO_GROUPS(CommandGroup.STREAM), + + XINFO_STREAM(CommandGroup.STREAM), + + XLEN(CommandGroup.STREAM), + + XPENDING(CommandGroup.STREAM), + + XRANGE(CommandGroup.STREAM), + + XREAD(CommandGroup.STREAM), + + XREADGROUP(CommandGroup.STREAM), + + XREVRANGE(CommandGroup.STREAM), + + XSETID(CommandGroup.STREAM), + + XTRIM(CommandGroup.STREAM), + /** + * stream command end + **/ + + /** + * string command start + **/ + APPEND(CommandGroup.STRING), + + DECR(CommandGroup.STRING), + + DECRBY(CommandGroup.STRING), + + GET(CommandGroup.STRING), + + GETRANGE(CommandGroup.STRING), + + GETSET(CommandGroup.STRING), + + GETEX(CommandGroup.STRING), + + GETDEL(CommandGroup.STRING), + + INCR(CommandGroup.STRING), + + INCRBY(CommandGroup.STRING), + + INCRBYFLOAT(CommandGroup.STRING), + + MGET(CommandGroup.STRING), + + MSET(CommandGroup.STRING), + + MSETNX(CommandGroup.STRING), + + PSETEX(CommandGroup.STRING), + + SET(CommandGroup.STRING), + + SETEX(CommandGroup.STRING), + + SETNX(CommandGroup.STRING), + + SETRANGE(CommandGroup.STRING), + + STRLEN(CommandGroup.STRING), + + SUBSTR(CommandGroup.STRING), + /** string command end **/ + + /** + * transaction command start + **/ + DISCARD(CommandGroup.TRANSACTION), + + EXEC(CommandGroup.TRANSACTION), + + MULTI(CommandGroup.TRANSACTION), + + UNWATCH(CommandGroup.TRANSACTION), + + WATCH(CommandGroup.TRANSACTION); + + /** + * transaction command end + **/ + + private final byte[] raw; + + /** + * 命令分组 + */ + private final CommandGroup group; + + /** + * 子命令 + */ + private final SubCommand[] subCommands; + + /** + * 是否为读操作命令 + */ + private final boolean read; + + /** + * 是否为写操作命令 + */ + private final boolean write; + + Command(final String mode, final CommandGroup group) { + this(mode, group, new SubCommand[]{}); + } + + Command(final String mode, final CommandGroup group, final SubCommand... subCommands) { + raw = SafeEncoder.encode(name()); + this.group = group; + this.subCommands = subCommands; + if(Validate.hasText(mode)){ + String modeLower = mode.toLowerCase(); + this.read = modeLower.indexOf('r') > -1; + this.write = modeLower.indexOf('w') > -1; + }else{ + this.read = true; + this.write = false; + } + } + + @Override + public String getName() { + return name(); + } + + public CommandGroup getGroup() { + return group; + } + + @Override + public byte[] getRaw() { + return raw; + } + + @Override + public boolean isRead() { + return read; + } + + @Override + public boolean isWrite() { + return write; + } + + @Override + public String toString() { + return getName(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/CommandArguments.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/CommandArguments.java new file mode 100644 index 000000000..fb81520da --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/CommandArguments.java @@ -0,0 +1,149 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.core.Range; +import com.buession.core.utils.StringUtils; +import com.buession.core.validator.Validate; +import com.buession.lang.Constants; +import com.buession.redis.core.Keyword; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +/** + * @author Yong.Teng + */ +public final class CommandArguments { + + private CommandArguments() { + } + + private CommandArguments(final Keyword value) { + add(value); + } + + private CommandArguments(final ProtocolCommand value) { + add(value); + } + + private CommandArguments(final Range value) { + add(value); + } + + private CommandArguments(final Keyword... values) { + add(values); + } + + private CommandArguments(final ProtocolCommand... values) { + add(values); + } + + private CommandArguments(final Range... values) { + add(values); + } + + public static CommandArguments create(final Keyword value) { + return new CommandArguments(value); + } + + public static CommandArguments create(final ProtocolCommand value) { + return new CommandArguments(value); + } + + public static CommandArguments create(final Range value) { + return new CommandArguments(value); + } + + public static CommandArguments create(final Keyword... values) { + return new CommandArguments(values); + } + + public static CommandArguments create(final ProtocolCommand... values) { + return new CommandArguments(values); + } + + public static CommandArguments create(final Range... values) { + return new CommandArguments(values); + } + + public CommandArguments add(final Keyword value) { + if(value != null){ + parameters.add(value.getValue()); + } + + return this; + } + + public CommandArguments add(final ProtocolCommand value) { + if(value != null){ + parameters.add(value.getName()); + } + + return this; + } + + public CommandArguments add(final Range value) { + if(value != null){ + parameters.add(value.getStart()); + parameters.add(value.getEnd()); + } + + return this; + } + + public CommandArguments add(final Keyword... values) { + if(Validate.isNotEmpty(values)){ + for(Object value : values){ + add(value); + } + } + + return this; + } + + public CommandArguments add(final ProtocolCommand... values) { + if(Validate.isNotEmpty(values)){ + for(Object value : values){ + add(value); + } + } + + return this; + } + + public CommandArguments add(final Range... values) { + if(Validate.isNotEmpty(values)){ + for(Object value : values){ + add(value); + } + } + + return this; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/CommandGroup.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/CommandGroup.java new file mode 100644 index 000000000..ac61b94aa --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/CommandGroup.java @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +/** + * Redis 协议命令分组 + * + * @author Yong.Teng + */ +public enum CommandGroup { + + /** + * 权限命令 + */ + ACL("Acl"), + + /** + * 位图命令 + */ + BITMAP("BitMap"), + + /** + * 集群命令 + */ + CLUSTER("Cluster"), + + /** + * 连接命令 + */ + CONNECTION("Connection"), + + /** + * 地理位置命令 + */ + GEO("Geo"), + + /** + * 哈希命令 + */ + HASH("Hash"), + + /** + * HyperLogLog 命令 + */ + HYPERLOGLOG("HyperLogLog"), + + /** + * 键命令 + */ + KEY("Key"), + + /** + * 列表命令 + */ + LIST("List"), + + /** + * 发布订阅命令 + */ + PUBSUB("PubSub"), + + /** + * 脚本命令 + */ + SCRIPTING("Scripting"), + + /** + * 服务器命令 + */ + SERVER("Server"), + + /** + * 集合命令 + */ + SET("Set"), + + /** + * 有序集合命令 + */ + SORTEDSET("Sorted Set"), + + /** + * 流命令 + */ + STREAM("Stream"), + + /** + * 字符串命令 + */ + STRING("String"), + + /** + * 事务命令 + */ + TRANSACTION("Transaction"); + + private final String name; + + CommandGroup(final String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Deprecated + public String getValue() { + return getName(); + } + + @Override + public String toString() { + return getName(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ConnectionCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ConnectionCommands.java new file mode 100644 index 000000000..b5c449b6a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ConnectionCommands.java @@ -0,0 +1,487 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.Status; +import com.buession.redis.core.Client; +import com.buession.redis.core.ClientAttributeOption; +import com.buession.redis.core.ClientPauseMode; +import com.buession.redis.core.ClientReply; +import com.buession.redis.core.ClientTrackingInfo; +import com.buession.redis.core.ClientType; +import com.buession.redis.core.ClientUnblockType; +import com.buession.redis.core.RedisServer; +import com.buession.redis.core.command.args.ClientKillArgument; +import com.buession.redis.core.command.args.ClientTracking; +import com.buession.redis.core.command.args.HelloArgument; + +import java.util.List; + +/** + * 连接相关命令 + * + *

详情说明 http://www.redis.cn/commands.html#connection

+ * + * @author Yong.Teng + */ +public interface ConnectionCommands extends RedisCommands { + + /** + * 通过密码进行认证 + * + *

详情说明 http://redisdoc.com/client_and_server/auth.html

+ * + * @param user + * 用户账号 + * @param password + * 密码 + * + * @return 密码匹配时返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status auth(final String user, final String password); + + /** + * 通过密码进行认证 + * + *

详情说明 http://redisdoc.com/client_and_server/auth.html

+ * + * @param user + * 用户账号 + * @param password + * 密码 + * + * @return 密码匹配时返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status auth(final byte[] user, final byte[] password); + + /** + * 通过密码进行认证 + * + *

详情说明 + * http://redisdoc.com/client_and_server/auth.html

+ * + * @param password + * 密码 + * + * @return 密码匹配时返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status auth(final String password); + + /** + * 通过密码进行认证 + * + *

详情说明 + * http://redisdoc.com/client_and_server/auth.html

+ * + * @param password + * 密码 + * + * @return 密码匹配时返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status auth(final byte[] password); + + /** + * This command controls the tracking of the keys in the next command executed by the connection, + * when tracking is enabled in OPTIN or OPTOUT mode + * + *

详情说明 https://redis.io/commands/client-caching/

+ * + * @return Status.SUCCESS or Status.FAILURE if the argument is not yes or no + * + * @since 3.0.0 + */ + Status clientCaching(); + + /** + * This command controls the tracking of the keys in the next command executed by the connection, + * when tracking is enabled in OPTIN or OPTOUT mode + * + *

详情说明 https://redis.io/commands/client-caching/

+ * + * @param isYes + * Yes / No + * + * @return Status.SUCCESS or Status.FAILURE if the argument is not yes or no + */ + Status clientCaching(final boolean isYes); + + /** + * 获取连接时设置的名字 + * + *

详情说明 http://redisdoc.com/client_and_server/client_getname.html

+ * + * @return 连接时设置的名字 + */ + String clientGetName(); + + /** + * This command returns the client ID we are redirecting our tracking notifications to + * + *

详情说明 https://redis.io/commands/client-getredir/

+ * + * @return the ID of the client we are redirecting the notifications to; + * The command returns -1 if client tracking is not enabled, + * or 0 if client tracking is enabled but we are not redirecting the notifications to any client + */ + Integer clientGetRedir(); + + /** + * 返回当前连接的 ID + * + *

详情说明 http://www.redis.cn/commands/client-id.html

+ * + * @return 当前连接的 ID + */ + Long clientId(); + + /** + * The command returns information and statistics about the current client connection in a mostly human readable format + * + *

详情说明 https://redis.io/commands/client-info/

+ * + * @return 连接到服务器的客户端信息 + */ + Client clientInfo(); + + /** + * 关闭地址为 host:port 的客户端 + * + *

详情说明 http://redisdoc.com/client_and_server/client_kill.html

+ * + * @param host + * 客户端地址 + * @param port + * 客户端端口 + * + * @return 当指定的客户端存在,且被成功关闭时,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status clientKill(final String host, final int port); + + /** + * 关闭地址为 host:port 的客户端 + * + *

详情说明 http://redisdoc.com/client_and_server/client_kill.html

+ * + * @param clientKillArguments + * 客户端关闭参数 + * + * @return 关闭客户端数量 + * + * @since 3.0.0 + */ + Long clientKill(final ClientKillArgument... clientKillArguments); + + /** + * 获取所有连接到服务器的客户端信息和统计数据 + * + *

详情说明 http://redisdoc.com/client_and_server/client_list.html

+ * + * @return 所有连接到服务器的客户端信息和统计数据 + */ + List clientList(); + + /** + * 获取连接到服务器的指定类型客户端信息和统计数据 + * + *

详情说明 http://redisdoc.com/client_and_server/client_list.html

+ * + * @param clientType + * 客户端类型 + * + * @return 连接到服务器的指定类型客户端信息和统计数据 + */ + List clientList(final ClientType clientType); + + /** + * 根据客户端 ID 获取客户端信息和统计数据 + * + *

详情说明 http://redisdoc.com/client_and_server/client_list.html

+ * + * @param clientIds + * 客户端 ID + * + * @return 客户端信息和统计数据 + * + * @since 3.0.0 + */ + List clientList(final long... clientIds); + + /** + * Sets the client eviction mode for the current connection. + * + * @param on + * {@code true} will turn eviction mode on, and {@code false} will turn it off. + * + * @return 操作结果 + * + * @since 3.0.0 + */ + Status clientNoEvict(final boolean on); + + /** + * Sets the client touch mode for the current connection. + * + * @param on + * {@code true} will turn touch mode on, and {@code false} will turn it off. + * + * @return 操作结果 + * + * @since 3.0.0 + */ + Status clientNoTouch(final boolean on); + + /** + * 将所有客户端的访问暂停给定的毫秒数 + * + *

详情说明 http://www.redis.cn/commands/client-pause.html

+ * + * @param timeout + * 暂停时间(单位:毫秒) + * + * @return 操作结果 + */ + Status clientPause(final int timeout); + + /** + * 将所有客户端的访问暂停给定的毫秒数 + * + *

详情说明 http://www.redis.cn/commands/client-pause.html

+ * + * @param timeout + * 暂停时间(单位:毫秒) + * @param pauseMode + * 客户端暂停模式 + * + * @return 操作结果 + */ + Status clientPause(final int timeout, final ClientPauseMode pauseMode); + + /** + * 当需要完全禁用redis服务器对当前客户端的回复时可使用该命令 + * + *

详情说明 http://www.redis.cn/commands/client-reply.html

+ * + * @param option + * 选项 + * + * @return 当执行命令设置为 OFF 或 SKIP,设置命令收不到任何回复,当设置为 ON 时,返回OK + */ + Status clientReply(final ClientReply option); + + /** + * The CLIENT SETINFO command assigns various info attributes to the current connection which are displayed in the output of CLIENT LIST and CLIENT INFO. + * + *

详情说明 https://redis.io/commands/client-info/

+ * + * @param clientAttributeOption + * 客户端属性选项 + * @param value + * 值 + * + * @return 操作结果 + * + * @since 3.0.0 + */ + Status clientSetInfo(final ClientAttributeOption clientAttributeOption, final String value); + + /** + * The CLIENT SETINFO command assigns various info attributes to the current connection which are displayed in the output of CLIENT LIST and CLIENT INFO. + * + *

详情说明 https://redis.io/commands/client-info/

+ * + * @param clientAttributeOption + * 客户端属性选项 + * @param value + * 值 + * + * @return 操作结果 + * + * @since 3.0.0 + */ + Status clientSetInfo(final ClientAttributeOption clientAttributeOption, final byte[] value); + + /** + * 为当前连接分配一个名字 + * + *

详情说明 http://redisdoc.com/client_and_server/client_setname.html

+ * + * @param name + * 名字 + * + * @return 设置成功时返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status clientSetName(final String name); + + /** + * 为当前连接分配一个名字 + * + *

详情说明 http://redisdoc.com/client_and_server/client_setname.html

+ * + * @param name + * 名字 + * + * @return 设置成功时返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status clientSetName(final byte[] name); + + /** + * This command enables the tracking feature of the Redis server, that is used for server assisted client side + * caching. + * + *

详情说明 https://redis.io/docs/latest/commands/client-tracking/

+ * + * @param clientTracking + * 跟踪参数 + * + * @return 设置成功时返回 Status.SUCCESS;否则,返回 Status.FAILURE + * + * @since 3.0.0 + */ + Status clientTracking(final ClientTracking clientTracking); + + /** + * The command returns information about the current client connection's use of the server assisted client side caching feature. + * + *

详情说明 https://redis.io/docs/latest/commands/client-trackinginfo/

+ * + * @return The information about the current client connection's use of the server assisted client side caching feature. + * + * @since 3.0.0 + */ + ClientTrackingInfo clientTrackingInfo(); + + /** + * 该命令可以通过其他连接解除客户端的阻塞 + * + *

详情说明 http://www.redis.cn/commands/client-unblock.html

+ * + * @param clientId + * 客户端 ID + * + * @return 当执行命令设置为 OFF 或 SKIP,设置命令收不到任何回复,当设置为 ON 时,返回OK + */ + Status clientUnblock(final int clientId); + + /** + * 该命令可以通过其他连接解除客户端的阻塞 + * + *

详情说明 http://www.redis.cn/commands/client-unblock.html

+ * + * @param clientId + * 客户端 ID + * @param type + * type + * + * @return 当执行命令设置为 OFF 或 SKIP,设置命令收不到任何回复,当设置为 ON 时,返回OK + */ + Status clientUnblock(final int clientId, final ClientUnblockType type); + + /** + * 取消客户端暂停 + * + * @return 操作结果 + * + * @since 3.0.0 + */ + Status clientUnPause(); + + /** + * 打印一个特定的字符串 + * + *

详情说明 http://www.redis.cn/commands/echo.html

+ * + * @param str + * 待打印的字符串 + * + * @return 字符串本身 + */ + String echo(final String str); + + /** + * 打印一个特定的字符串 + * + *

详情说明 http://www.redis.cn/commands/echo.html

+ * + * @param str + * 待打印的字符串 + * + * @return 字符串本身 + */ + byte[] echo(final byte[] str); + + /** + * Switch to a different protocol, optionally authenticating and setting the connection's name, or provide a contextual client report. + * + *

详情说明 https://redis.io/docs/latest/commands/hello/

+ * + * @param helloArgument + * {@link HelloArgument} + * + * @return A list of server properties. + */ + RedisServer hello(final HelloArgument helloArgument); + + /** + * 使用客户端向 Redis 服务器发送一个 PING ,如果服务器运作正常的话,会返回一个 PONG; + * 通常用于测试与服务器的连接是否仍然生效,或者用于测量延迟值 + * + *

详情说明 http://www.redis.cn/commands/ping.html

+ * + * @return PING 结果 + */ + Status ping(); + + /** + * 请求服务器关闭与当前客户端的连接 + * + *

详情说明 http://www.redis.cn/commands/quit.html

+ * + * @return 总是返回 Status.SUCCESS + */ + Status quit(); + + /** + * This command performs a full reset of the connection’s server-side context, + * mimicking the effect of disconnecting and reconnecting again. + * + *

详情说明 https://redis.io/commands/reset/

+ * + * @return 总是返回 Status.SUCCESS + */ + Status reset(); + + /** + * 切换到指定的数据库 + * + *

详情说明 http://redisdoc.com/database/select.html

+ * + * @param db + * 数据库索引号 + * + * @return 切换成功返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status select(final int db); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/GeoCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/GeoCommands.java new file mode 100644 index 000000000..f332331c1 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/GeoCommands.java @@ -0,0 +1,723 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.Geo; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import com.buession.redis.core.command.args.GeoAddArgument; +import com.buession.redis.core.command.args.GeoRadiusArgument; +import com.buession.redis.core.command.args.GeoSearchArgument; +import com.buession.redis.core.command.args.GeoSearchStoreArgument; + +import java.util.List; +import java.util.Map; + +/** + * 地理位置命令 + * + *

详情说明 https://redis.io/docs/latest/commands/?group=geo

+ * + * @author Yong.Teng + */ +public interface GeoCommands extends RedisCommands { + + /** + * 将给定的空间元素(经度、纬度、名字)添加到指定的键里面 + * + *

详情说明 http://redisdoc.com/geo/geoadd.html

+ * + * @param key + * Key + * @param member + * 名字 + * @param longitude + * 经度 + * @param latitude + * 纬度 + * + * @return 新添加到键里面的空间元素数量,不包括那些已经存在但是被更新的元素 + */ + Long geoAdd(final String key, final String member, final double longitude, final double latitude); + + /** + * 将给定的空间元素(经度、纬度、名字)添加到指定的键里面 + * + *

详情说明 http://redisdoc.com/geo/geoadd.html

+ * + * @param key + * Key + * @param member + * 名字 + * @param longitude + * 经度 + * @param latitude + * 纬度 + * + * @return 新添加到键里面的空间元素数量,不包括那些已经存在但是被更新的元素 + */ + Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude); + + /** + * 批量将给定的空间元素(经度、纬度、名字)添加到指定的键里面 + * + *

详情说明 http://redisdoc.com/geo/geoadd.html

+ * + * @param key + * Key + * @param memberCoordinates + * 空间元素(纬度、经度、名字)集合 + * + * @return 新添加到键里面的空间元素数量,不包括那些已经存在但是被更新的元素 + */ + Long geoAdd(final String key, final Map memberCoordinates); + + /** + * 批量将给定的空间元素(经度、纬度、名字)添加到指定的键里面 + * + *

详情说明 http://redisdoc.com/geo/geoadd.html

+ * + * @param key + * Key + * @param memberCoordinates + * 空间元素(纬度、经度、名字)集合 + * + * @return 新添加到键里面的空间元素数量,不包括那些已经存在但是被更新的元素 + */ + Long geoAdd(final byte[] key, final Map memberCoordinates); + + /** + * 将给定的空间元素(经度、纬度、名字)添加到指定的键里面 + * + *

详情说明 http://redisdoc.com/geo/geoadd.html

+ * + * @param key + * Key + * @param member + * 名字 + * @param longitude + * 经度 + * @param latitude + * 纬度 + * @param geoAddArgument + * 添加参数 + * + * @return 新添加到键里面的空间元素数量,不包括那些已经存在但是被更新的元素 + */ + Long geoAdd(final String key, final String member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument); + + /** + * 将给定的空间元素(经度、纬度、名字)添加到指定的键里面 + * + *

详情说明 http://redisdoc.com/geo/geoadd.html

+ * + * @param key + * Key + * @param member + * 名字 + * @param longitude + * 经度 + * @param latitude + * 纬度 + * @param geoAddArgument + * 添加参数 + * + * @return 新添加到键里面的空间元素数量,不包括那些已经存在但是被更新的元素 + * + * @since 3.0.0 + */ + Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude, + final GeoAddArgument geoAddArgument); + + /** + * 批量将给定的空间元素(经度、纬度、名字)添加到指定的键里面 + * + *

详情说明 http://redisdoc.com/geo/geoadd.html

+ * + * @param key + * Key + * @param memberCoordinates + * 空间元素(纬度、经度、名字)集合 + * @param geoAddArgument + * 添加参数 + * + * @return 新添加到键里面的空间元素数量,不包括那些已经存在但是被更新的元素 + * + * @since 3.0.0 + */ + Long geoAdd(final String key, final Map memberCoordinates, final GeoAddArgument geoAddArgument); + + /** + * 批量将给定的空间元素(经度、纬度、名字)添加到指定的键里面 + * + *

详情说明 http://redisdoc.com/geo/geoadd.html

+ * + * @param key + * Key + * @param memberCoordinates + * 空间元素(纬度、经度、名字)集合 + * @param geoAddArgument + * 添加参数 + * + * @return 新添加到键里面的空间元素数量,不包括那些已经存在但是被更新的元素 + * + * @since 3.0.0 + */ + Long geoAdd(final byte[] key, final Map memberCoordinates, final GeoAddArgument geoAddArgument); + + /** + * 计算两个给定位置之间的距离 + * + *

详情说明 http://redisdoc.com/geo/geodist.html

+ * + * @param key + * Key + * @param member1 + * 位置一 + * @param member2 + * 位置一 + * + * @return 计算出的距离会以双精度浮点数的形式被返回(单位:米),如果给定的位置元素不存在,那么返回空值 + */ + Double geoDist(final String key, final String member1, final String member2); + + /** + * 计算两个给定位置之间的距离 + * + *

详情说明 http://redisdoc.com/geo/geodist.html

+ * + * @param key + * Key + * @param member1 + * 位置一 + * @param member2 + * 位置一 + * + * @return 计算出的距离会以双精度浮点数的形式被返回(单位:米),如果给定的位置元素不存在,那么返回空值 + */ + Double geoDist(final byte[] key, final byte[] member1, final byte[] member2); + + /** + * 计算两个给定位置之间的距离 + * + *

详情说明 http://redisdoc.com/geo/geodist.html

+ * + * @param key + * Key + * @param member1 + * 位置一 + * @param member2 + * 位置一 + * @param unit + * 距离单位 + * + * @return 计算出的距离会以双精度浮点数的形式被返回,如果给定的位置元素不存在,那么返回空值 + */ + Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit); + + /** + * 计算两个给定位置之间的距离 + * + *

详情说明 http://redisdoc.com/geo/geodist.html

+ * + * @param key + * Key + * @param member1 + * 位置一 + * @param member2 + * 位置一 + * @param unit + * 距离单位 + * + * @return 计算出的距离会以双精度浮点数的形式被返回,如果给定的位置元素不存在,那么返回空值 + */ + Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit); + + /** + * 获取一个或多个位置元素的 Geohash 表示 + * + *

详情说明 http://redisdoc.com/geo/geohash.html

+ * + * @param key + * Key + * @param members + * 一个或多个位置元素 + * + * @return Geohash 数组 + */ + List geoHash(final String key, final String... members); + + /** + * 获取一个或多个位置元素的 Geohash 表示 + * + *

详情说明 http://redisdoc.com/geo/geohash.html

+ * + * @param key + * Key + * @param members + * 一个或多个位置元素 + * + * @return Geohash 数组 + */ + List geoHash(final byte[] key, final byte[]... members); + + /** + * 批量从键里面返回所有给定位置元素的位置(经度和纬度) + * + *

详情说明 http://redisdoc.com/geo/geopos.html

+ * + * @param key + * Key + * @param members + * 名字 + * + * @return 经纬度列表 + */ + List geoPos(final String key, final String... members); + + /** + * 批量从键里面返回所有给定位置元素的位置(经度和纬度) + * + *

详情说明 http://redisdoc.com/geo/geopos.html

+ * + * @param key + * Key + * @param members + * 名字 + * + * @return 经纬度列表 + */ + List geoPos(final byte[] key, final byte[]... members); + + /** + * 以给定的经纬度为中心,返回键包含的位置元素当中,与中心的距离不超过给定最大距离的所有位置元素 + * + *

详情说明 http://redisdoc.com/geo/georadius.html

+ * + * @param key + * Key + * @param longitude + * 经度 + * @param latitude + * 纬度 + * @param radius + * 范围 + * @param unit + * 距离单位 + * + * @return 位置元素 + */ + List geoRadius(final String key, final double longitude, final double latitude, final double radius, + final GeoUnit unit); + + /** + * 以给定的经纬度为中心,返回键包含的位置元素当中,与中心的距离不超过给定最大距离的所有位置元素 + * + *

详情说明 http://redisdoc.com/geo/georadius.html

+ * + * @param key + * Key + * @param longitude + * 经度 + * @param latitude + * 纬度 + * @param radius + * 范围 + * @param unit + * 距离单位 + * + * @return 位置元素 + */ + List geoRadius(final byte[] key, final double longitude, final double latitude, final double radius, + final GeoUnit unit); + + /** + * 以给定的经纬度为中心,返回键包含的位置元素当中,与中心的距离不超过给定最大距离的所有位置元素 + * + *

详情说明 http://redisdoc.com/geo/georadius.html

+ * + * @param key + * Key + * @param longitude + * 经度 + * @param latitude + * 纬度 + * @param radius + * 范围 + * @param unit + * 距离单位 + * @param geoRadiusArgument + * GEO 参数 + * + * @return 位置元素 + */ + List geoRadius(final String key, final double longitude, final double latitude, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument); + + /** + * 以给定的经纬度为中心,返回键包含的位置元素当中,与中心的距离不超过给定最大距离的所有位置元素 + * + *

详情说明 http://redisdoc.com/geo/georadius.html

+ * + * @param key + * Key + * @param longitude + * 经度 + * @param latitude + * 纬度 + * @param radius + * 范围 + * @param unit + * 距离单位 + * @param geoRadiusArgument + * GEO 参数 + * + * @return 位置元素 + */ + List geoRadius(final byte[] key, final double longitude, final double latitude, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument); + + /** + * Read-only variant of the GEORADIUS command + * + *

详情说明 https://redis.io/commands/georadius_ro/

+ * + * @param key + * Key + * @param longitude + * 经度 + * @param latitude + * 纬度 + * @param radius + * 范围 + * @param unit + * 距离单位 + * + * @return 位置元素 + */ + List geoRadiusRo(final String key, final double longitude, final double latitude, final double radius, + final GeoUnit unit); + + /** + * Read-only variant of the GEORADIUS command + * + *

详情说明 https://redis.io/commands/georadius_ro/

+ * + * @param key + * Key + * @param longitude + * 经度 + * @param latitude + * 纬度 + * @param radius + * 范围 + * @param unit + * 距离单位 + * + * @return 位置元素 + */ + List geoRadiusRo(final byte[] key, final double longitude, final double latitude, final double radius, + final GeoUnit unit); + + /** + * Read-only variant of the GEORADIUS command + * + *

详情说明 https://redis.io/commands/georadius_ro/

+ * + * @param key + * Key + * @param longitude + * 经度 + * @param latitude + * 纬度 + * @param radius + * 范围 + * @param unit + * 距离单位 + * @param geoRadiusArgument + * GEO 参数 + * + * @return 位置元素 + */ + List geoRadiusRo(final String key, final double longitude, final double latitude, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument); + + /** + * Read-only variant of the GEORADIUS command + * + *

详情说明 https://redis.io/commands/georadius_ro/

+ * + * @param key + * Key + * @param longitude + * 经度 + * @param latitude + * 纬度 + * @param radius + * 范围 + * @param unit + * 距离单位 + * @param geoRadiusArgument + * GEO 参数 + * + * @return 位置元素 + */ + List geoRadiusRo(final byte[] key, final double longitude, final double latitude, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument); + + /** + * 找出位于指定范围内的元素, + * 但是 GEORADIUSBYMEMBER 的中心点是由给定的位置元素决定的,而不是像 GEORADIUS 那样,使用输入的经度和纬度来决定中心点 + * + *

详情说明 http://redisdoc.com/geo/georadiusbymember.html

+ * + * @param key + * Key + * @param member + * 位置元素 + * @param radius + * 范围 + * @param unit + * 距离单位 + * + * @return 位置元素 + */ + List geoRadiusByMember(final String key, final String member, final double radius, final GeoUnit unit); + + /** + * 找出位于指定范围内的元素, + * 但是 GEORADIUSBYMEMBER 的中心点是由给定的位置元素决定的,而不是像 GEORADIUS 那样,使用输入的经度和纬度来决定中心点 + * + *

详情说明 http://redisdoc.com/geo/georadiusbymember.html

+ * + * @param key + * Key + * @param member + * 位置元素 + * @param radius + * 范围 + * @param unit + * 距离单位 + * + * @return 位置元素 + */ + List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, final GeoUnit unit); + + /** + * 找出位于指定范围内的元素, + * 但是 GEORADIUSBYMEMBER 的中心点是由给定的位置元素决定的,而不是像 GEORADIUS 那样,使用输入的经度和纬度来决定中心点 + * + *

详情说明 http://redisdoc.com/geo/georadiusbymember.html

+ * + * @param key + * Key + * @param member + * 位置元素 + * @param radius + * 范围 + * @param unit + * 距离单位 + * @param geoRadiusArgument + * GEO 参数 + * + * @return 位置元素 + */ + List geoRadiusByMember(final String key, final String member, final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument); + + /** + * 找出位于指定范围内的元素, + * 但是 GEORADIUSBYMEMBER 的中心点是由给定的位置元素决定的,而不是像 GEORADIUS 那样,使用输入的经度和纬度来决定中心点 + * + *

详情说明 http://redisdoc.com/geo/georadiusbymember.html

+ * + * @param key + * Key + * @param member + * 位置元素 + * @param radius + * 范围 + * @param unit + * 距离单位 + * @param geoRadiusArgument + * GEO 参数 + * + * @return 位置元素 + */ + List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument); + + /** + * Read-only variant of the GEORADIUSBYMEMBER command + * + *

详情说明 https://redis.io/commands/georadiusbymember_ro/

+ * + * @param key + * Key + * @param member + * 位置元素 + * @param radius + * 范围 + * @param unit + * 距离单位 + * + * @return 位置元素 + */ + List geoRadiusByMemberRo(final String key, final String member, final double radius, final GeoUnit unit); + + /** + * Read-only variant of the GEORADIUSBYMEMBER command + * + *

详情说明 https://redis.io/commands/georadiusbymember_ro/

+ * + * @param key + * Key + * @param member + * 位置元素 + * @param radius + * 范围 + * @param unit + * 距离单位 + * + * @return 位置元素 + */ + List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, final GeoUnit unit); + + /** + * Read-only variant of the GEORADIUSBYMEMBER command + * + *

详情说明 https://redis.io/commands/georadiusbymember_ro/

+ * + * @param key + * Key + * @param member + * 位置元素 + * @param radius + * 范围 + * @param unit + * 距离单位 + * @param geoRadiusArgument + * GEO 参数 + * + * @return 位置元素 + */ + List geoRadiusByMemberRo(final String key, final String member, final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument); + + /** + * Read-only variant of the GEORADIUSBYMEMBER command + * + *

详情说明 https://redis.io/commands/georadiusbymember_ro/

+ * + * @param key + * Key + * @param member + * 位置元素 + * @param radius + * 范围 + * @param unit + * 距离单位 + * @param geoRadiusArgument + * GEO 参数 + * + * @return 位置元素 + */ + List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument); + + /** + * Return the members of a sorted set populated with geospatial information using {@code GEOADD}, which are within + * the borders of the area specified by a given shape. This command extends the {@code GEORADIUS} command, so in + * addition to searching within circular areas, it supports searching within rectangular areas. + * + *

详情说明 https://redis.io/docs/latest/commands/geosearch/

+ * + * @param key + * Key + * @param geoSearchArgument + * 搜索参数 + * + * @return The members of a sorted set populated with geospatial information using {@code GEOADD} + * + * @since 3.0.0 + */ + List geoSearch(final String key, final GeoSearchArgument geoSearchArgument); + + /** + * Return the members of a sorted set populated with geospatial information using {@code GEOADD}, which are within + * the borders of the area specified by a given shape. This command extends the {@code GEORADIUS} command, so in + * addition to searching within circular areas, it supports searching within rectangular areas. + * + *

详情说明 https://redis.io/docs/latest/commands/geosearch/

+ * + * @param key + * Key + * @param geoSearchArgument + * 搜索参数 + * + * @return The members of a sorted set populated with geospatial information using {@code GEOADD} + * + * @since 3.0.0 + */ + List geoSearch(final byte[] key, final GeoSearchArgument geoSearchArgument); + + /** + * This command is like {@code GEOSEARCH}, but stores the result in destination key. + * + *

详情说明 https://redis.io/docs/latest/commands/geosearchstore/

+ * + * @param destKey + * 目标 Key + * @param key + * Key + * @param geoSearchStoreArgument + * 搜索及存储参数 + * + * @return The members of a sorted set populated with geospatial information using {@code GEOADD} + * + * @since 3.0.0 + */ + Long geoSearchStore(final String destKey, final String key, final GeoSearchStoreArgument geoSearchStoreArgument); + + /** + * RThis command is like {@code GEOSEARCH}, but stores the result in destination key. + * + *

详情说明 https://redis.io/docs/latest/commands/geosearchstore/

+ * + * @param destKey + * 目标 Key + * @param key + * Key + * @param geoSearchStoreArgument + * 搜索及存储参数 + * + * @return The members of a sorted set populated with geospatial information using {@code GEOADD} + * + * @since 3.0.0 + */ + Long geoSearchStore(final byte[] destKey, final byte[] key, final GeoSearchStoreArgument geoSearchStoreArgument); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/HashCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/HashCommands.java new file mode 100644 index 000000000..ece6a60fa --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/HashCommands.java @@ -0,0 +1,1202 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.args.HScanArgument; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * 哈希表命令 + * + *

详情说明 https://redis.io/docs/latest/commands/?group=hash

+ * + * @author Yong.Teng + */ +public interface HashCommands extends RedisCommands { + + /** + * 删除哈希表 key 中的一个或多个指定域 + * + *

详情说明 http://redisdoc.com/hash/hdel.html

+ * + * @param key + * Key + * @param fields + * 一个或多个域 + * + * @return 被成功删除的域的数量 + */ + Long hDel(final String key, final String... fields); + + /** + * 删除哈希表 key 中的一个或多个指定域 + * + *

详情说明 http://redisdoc.com/hash/hdel.html

+ * + * @param key + * Key + * @param fields + * 一个或多个域 + * + * @return 被成功删除的域的数量 + */ + Long hDel(final byte[] key, final byte[]... fields); + + /** + * 检查给定域 field 是否存在于哈希表 key 当中 + * + *

详情说明 http://redisdoc.com/hash/hexists.html

+ * + * @param key + * Key + * @param field + * 域 + * + * @return 域 field 是否存在于哈希表 key 中返回 true,否则返回 false + */ + Boolean hExists(final String key, final String field); + + /** + * 检查给定域 field 是否存在于哈希表 key 当中 + * + *

详情说明 http://redisdoc.com/hash/hexists.html

+ * + * @param key + * Key + * @param field + * 域 + * + * @return 域 field 是否存在于哈希表 key 中返回 true,否则返回 false + */ + Boolean hExists(final byte[] key, final byte[] field); + + /** + * 为给定 key 的域 fields 设置生存时间,当域的过期时(生存时间为 0),它会被自动删除 + * + *

详情说明 https://redis.io/docs/latest/commands/hexpire/

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:秒) + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hExpire(final String key, final int lifetime, final String... fields); + + /** + * 为给定 key 的域 fields 设置生存时间,当域的过期时(生存时间为 0),它会被自动删除 + * + *

详情说明 https://redis.io/docs/latest/commands/hexpire/

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:秒) + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hExpire(final byte[] key, final int lifetime, final byte[]... fields); + + /** + * 为给定 key 的域 fields 设置生存时间,当域的过期时(生存时间为 0),它会被自动删除 + * + *

详情说明 https://redis.io/docs/latest/commands/hexpire/

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:秒) + * @param expireOption + * 过期选项 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hExpire(final String key, final int lifetime, final ExpireOption expireOption, final String... fields); + + /** + * 为给定 key 的域 fields 设置生存时间,当域的过期时(生存时间为 0),它会被自动删除 + * + *

详情说明 https://redis.io/docs/latest/commands/hexpire/

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:秒) + * @param expireOption + * 过期选项 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, final byte[]... fields); + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hexpireat/

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:秒) + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hExpireAt(final String key, final long unixTimestamp, final String... fields); + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hexpireat/

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:秒) + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields); + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hexpireat/

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:秒) + * @param expireOption + * 过期选项 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption, + final String... fields); + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hexpireat/

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:秒) + * @param expireOption + * 过期选项 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields); + + /** + * Returns the absolute Unix timestamp in seconds since Unix epoch at which the given key's field(s) will expire. + * + *

详情说明 https://redis.io/docs/latest/commands/hexpiretime/

+ * + * @param key + * Key + * @param fields + * 域 + * + * @return The expiration Unix timestamp in seconds; + * -1 if the key exists but has no associated expiration time; + * -2 if the key does not exist; + * + * @since 3.0.0 + */ + List hExpireTime(final String key, final String... fields); + + /** + * Returns the absolute Unix timestamp in seconds since Unix epoch at which the given key's field(s) will expire. + * + *

详情说明 https://redis.io/docs/latest/commands/hexpiretime/

+ * + * @param key + * Key + * @param fields + * 域 + * + * @return The expiration Unix timestamp in seconds; + * -1 if the key exists but has no associated expiration time; + * -2 if the key does not exist; + * + * @since 3.0.0 + */ + List hExpireTime(final byte[] key, final byte[]... fields); + + /** + * 获取哈希表中给定域的值 + * + *

详情说明 http://redisdoc.com/hash/hget.html

+ * + * @param key + * Key + * @param field + * 域 + * + * @return 哈希表中给定域的值,如果给定域不存在于哈希表中,又或者给定的哈希表并不存在,则返回 null + */ + String hGet(final String key, final String field); + + /** + * 获取哈希表中给定域的值 + * + *

详情说明 http://redisdoc.com/hash/hget.html

+ * + * @param key + * Key + * @param field + * 域 + * + * @return 哈希表中给定域的值,如果给定域不存在于哈希表中,又或者给定的哈希表并不存在,则返回 null + */ + byte[] hGet(final byte[] key, final byte[] field); + + /** + * 获取哈希表 key 中,所有的域和值 + * + *

详情说明 http://redisdoc.com/hash/hgetall.html

+ * + * @param key + * Key + * + * @return 哈希表 key 中,所有的域和值 + */ + Map hGetAll(final String key); + + /** + * 获取哈希表 key 中,所有的域和值 + * + *

详情说明 http://redisdoc.com/hash/hgetall.html

+ * + * @param key + * Key + * + * @return 哈希表 key 中,所有的域和值 + */ + Map hGetAll(final byte[] key); + + /** + * 为哈希表 key 中的域 field 的值加上增量 increment + * + *

详情说明 http://redisdoc.com/hash/hincrby.html

+ * + * @param key + * Key + * @param field + * 域 + * @param value + * 值 + * + * @return 哈希表 key 中域 field 增量 increment 后的值 + */ + Long hIncrBy(final String key, final String field, final long value); + + /** + * 为哈希表 key 中的域 field 的值加上增量 increment + * + *

详情说明 http://redisdoc.com/hash/hincrby.html

+ * + * @param key + * Key + * @param field + * 域 + * @param value + * 值 + * + * @return 哈希表 key 中域 field 增量 increment 后的值 + */ + Long hIncrBy(final byte[] key, final byte[] field, final long value); + + /** + * 为哈希表 key 中的域 field 加上浮点数增量 increment + * + *

详情说明 http://redisdoc.com/hash/hincrbyfloat.html

+ * + * @param key + * Key + * @param field + * 域 + * @param value + * 值 + * + * @return 哈希表 key 中域 field 增量 increment 后的值 + */ + Double hIncrByFloat(final String key, final String field, final double value); + + /** + * 为哈希表 key 中的域 field 加上浮点数增量 increment + * + *

详情说明 http://redisdoc.com/hash/hincrbyfloat.html

+ * + * @param key + * Key + * @param field + * 域 + * @param value + * 值 + * + * @return 哈希表 key 中域 field 增量 increment 后的值 + */ + Double hIncrByFloat(final byte[] key, final byte[] field, final double value); + + /** + * 获取哈希表 key 中的所有域 + * + *

详情说明 http://redisdoc.com/hash/hkeys.html

+ * + * @param key + * Key + * + * @return 哈希表 key 中的所有域 + */ + Set hKeys(final String key); + + /** + * 获取哈希表 key 中的所有域 + * + *

详情说明 http://redisdoc.com/hash/hkeys.html

+ * + * @param key + * Key + * + * @return 哈希表 key 中的所有域 + */ + Set hKeys(final byte[] key); + + /** + * 获取哈希表 key 中域的数量 + * + *

详情说明 http://redisdoc.com/hash/hlen.html

+ * + * @param key + * Key + * + * @return 哈希表 key 中域的数量 + */ + Long hLen(final String key); + + /** + * 获取哈希表 key 中域的数量 + * + *

详情说明 http://redisdoc.com/hash/hlen.html

+ * + * @param key + * Key + * + * @return 哈希表 key 中域的数量 + */ + Long hLen(final byte[] key); + + /** + * 获取哈希表 key 中,一个或多个给定域的值 + * + *

详情说明 http://redisdoc.com/hash/hmget.html

+ * + * @param key + * Key + * @param fields + * 一个或多个域 + * + * @return 一个包含多个给定域的关联值的表,值的排列顺序和给定域参数的请求顺序一样 + */ + List hMGet(final String key, final String... fields); + + /** + * 获取哈希表 key 中,一个或多个给定域的值 + * + *

详情说明 http://redisdoc.com/hash/hmget.html

+ * + * @param key + * Key + * @param fields + * 一个或多个域 + * + * @return 一个包含多个给定域的关联值的表,值的排列顺序和给定域参数的请求顺序一样 + */ + List hMGet(final byte[] key, final byte[]... fields); + + /** + * 批量将多个 field => value (域-值)对设置到哈希表 key 中 + * + *

详情说明 http://redisdoc.com/hash/hmset.html

+ * + * @param key + * Key + * @param data + * field => value (域-值)对 + * + * @return 执行成功返回 Status.Success,否则返回 Status.FAILURE + */ + Status hMSet(final String key, final Map data); + + /** + * 批量将多个 field => value (域-值)对设置到哈希表 key 中 + * + *

详情说明 http://redisdoc.com/hash/hmset.html

+ * + * @param key + * Key + * @param data + * field => value (域-值)对 + * + * @return 执行成功返回 Status.Success,否则返回 Status.FAILURE + */ + Status hMSet(final byte[] key, final Map data); + + /** + * Remove the existing expiration on a hash key's field(s), + * turning the field(s) from volatile (a field with expiration set) to persistent + * (a field that will never expire as no TTL (time to live) is associated). + * + *

详情说明 https://redis.io/docs/latest/commands/hpersist/

+ * + * @param key + * Key + * @param fields + * 域 + * + * @return The expiration Unix timestamp in seconds; + * -1 if the key exists but has no associated expiration time; + * -2 if the key does not exist; + * + * @since 3.0.0 + */ + List hPersist(final String key, final String... fields); + + /** + * Remove the existing expiration on a hash key's field(s), + * turning the field(s) from volatile (a field with expiration set) to persistent + * (a field that will never expire as no TTL (time to live) is associated). + * + *

详情说明 https://redis.io/docs/latest/commands/hpersist/

+ * + * @param key + * Key + * @param fields + * 域 + * + * @return The expiration Unix timestamp in seconds; + * -1 if the key exists but has no associated expiration time; + * -2 if the key does not exist; + * + * @since 3.0.0 + */ + List hPersist(final byte[] key, final byte[]... fields); + + /** + * 为给定 key 的域 fields 设置生存时间,当域的过期时(生存时间为 0),它会被自动删除 + * + *

详情说明 https://redis.io/docs/latest/commands/hpexpire/

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:毫秒) + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hpExpire(final String key, final int lifetime, final String... fields); + + /** + * 为给定 key 的域 fields 设置生存时间,当域的过期时(生存时间为 0),它会被自动删除 + * + *

详情说明 https://redis.io/docs/latest/commands/hpexpire/

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:毫秒) + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hpExpire(final byte[] key, final int lifetime, final byte[]... fields); + + /** + * 为给定 key 的域 fields 设置生存时间,当域的过期时(生存时间为 0),它会被自动删除 + * + *

详情说明 https://redis.io/docs/latest/commands/hpexpire/

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:毫秒) + * @param expireOption + * 过期选项 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hpExpire(final String key, final int lifetime, final ExpireOption expireOption, final String... fields); + + /** + * 为给定 key 的域 fields 设置生存时间,当域的过期时(生存时间为 0),它会被自动删除 + * + *

详情说明 https://redis.io/docs/latest/commands/hpexpire/

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:毫秒) + * @param expireOption + * 过期选项 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hpExpire(final byte[] key, final int lifetime, final ExpireOption expireOption, final byte[]... fields); + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hpexpireat/

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:毫秒) + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hpExpireAt(final String key, final long unixTimestamp, final String... fields); + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hpexpireat/

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:毫秒) + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hpExpireAt(final byte[] key, final long unixTimestamp, final byte[]... fields); + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hpexpireat/

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:毫秒) + * @param expireOption + * 过期选项 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hpExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption, + final String... fields); + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hpexpireat/

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:毫秒) + * @param expireOption + * 过期选项 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + List hpExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption, + final byte[]... fields); + + /** + * Returns the absolute Unix timestamp in milliseconds since Unix epoch at which the given key's field(s) will expire. + * + *

详情说明 https://redis.io/docs/latest/commands/hpexpiretime/

+ * + * @param key + * Key + * @param fields + * 域 + * + * @return The expiration Unix timestamp in seconds; + * -1 if the key exists but has no associated expiration time; + * -2 if the key does not exist; + * + * @since 3.0.0 + */ + List hpExpireTime(final String key, final String... fields); + + /** + * Returns the absolute Unix timestamp in milliseconds since Unix epoch at which the given key's field(s) will expire. + * + *

详情说明 https://redis.io/docs/latest/commands/hpexpiretime/

+ * + * @param key + * Key + * @param fields + * 域 + * + * @return The expiration Unix timestamp in seconds; + * -1 if the key exists but has no associated expiration time; + * -2 if the key does not exist; + * + * @since 3.0.0 + */ + List hpExpireTime(final byte[] key, final byte[]... fields); + + /** + * 获取给定 key 的域剩余生存时间 + * + *

详情说明 http://redisdoc.com/expire/pttl.html

+ * + * @param key + * Key + * @param fields + * 域 + * + * @return 当 key 不存在时,返回 -2 ; + * 当 key 存在但没有设置剩余生存时间时,返回 -1 。 + * 否则,以毫秒为单位,返回 key 的域剩余生存时间 + * + * @since 3.0.0 + */ + List hpTtl(final String key, final String... fields); + + /** + * 获取给定 key 的域剩余生存时间 + * + *

详情说明 http://redisdoc.com/expire/pttl.html

+ * + * @param key + * Key + * @param fields + * 域 + * + * @return 当 key 不存在时,返回 -2 ; + * 当 key 存在但没有设置剩余生存时间时,返回 -1 。 + * 否则,以毫秒为单位,返回 key 的域剩余生存时间 + * + * @since 3.0.0 + */ + List hpTtl(final byte[] key, final byte[]... fields); + + /** + * 随机返回一个哈希表中存在的域 + * + *

详情说明 https://redis.io/commands/hrandfield/

+ * + * @param key + * Key + * + * @return 随机获取的哈希表中存在的域 + */ + String hRandField(final String key); + + /** + * 随机返回一个哈希表中存在的域 + * + *

详情说明 https://redis.io/commands/hrandfield/

+ * + * @param key + * Key + * + * @return 随机获取的哈希表中存在的域 + */ + byte[] hRandField(final byte[] key); + + /** + * 随机返回一个哈希表中指定数量的存在的域 + * + *

详情说明 https://redis.io/commands/hrandfield/

+ * + * @param key + * Key + * @param count + * 数量 + * + * @return 随机获取指定数量的哈希表中存在的域 + */ + List hRandField(final String key, final int count); + + /** + * 随机返回一个哈希表中指定数量的存在的域 + * + *

详情说明 https://redis.io/commands/hrandfield/

+ * + * @param key + * Key + * @param count + * 数量 + * + * @return 随机获取指定数量的哈希表中存在的域 + */ + List hRandField(final byte[] key, final int count); + + /** + * When called with just the key argument, return a random field from the hash value stored at key. + * If the provided count argument is positive, return an array of distinct fields. + * The array’s length is either count or the hash’s number of fields (HLEN), whichever is lower. + * + *

详情说明 https://redis.io/commands/hrandfield/

+ * + * @param key + * Key + * @param count + * 返回数量 + * + * @return A list fields and their values from the hash + */ + List> hRandFieldWithValues(final String key, final int count); + + /** + * When called with just the key argument, return a random field from the hash value stored at key. + * If the provided count argument is positive, return an array of distinct fields. + * The array’s length is either count or the hash’s number of fields (HLEN), whichever is lower. + * + *

详情说明 https://redis.io/commands/hrandfield/

+ * + * @param key + * Key + * @param count + * 返回数量 + * + * @return A list fields and their values from the hash + */ + List> hRandFieldWithValues(final byte[] key, final int count); + + /** + * 迭代哈希键 key 中的键值对 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScan(final String key, final long cursor); + + /** + * 迭代哈希键 key 中的键值对 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScan(final byte[] key, final long cursor); + + /** + * 迭代哈希键 key 中的键值对 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScan(final String key, final String cursor); + + /** + * 迭代哈希键 key 中的键值对 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScan(final byte[] key, final byte[] cursor); + + /** + * 迭代哈希键 key 中的键值对 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param scanArgument + * {@link HScanArgument} + * + * @return 返回和给定模式相匹配的元素 + */ + ScanResult> hScan(final String key, final long cursor, + final HScanArgument scanArgument); + + /** + * 迭代哈希键 key 中的键值对 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param scanArgument + * {@link HScanArgument} + * + * @return 返回和给定模式相匹配的元素 + */ + ScanResult> hScan(final byte[] key, final long cursor, + final HScanArgument scanArgument); + + /** + * 迭代哈希键 key 中的键值对 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param scanArgument + * {@link HScanArgument} + * + * @return 返回和给定模式相匹配的元素 + */ + ScanResult> hScan(final String key, final String cursor, + final HScanArgument scanArgument); + + /** + * 迭代哈希键 key 中的键值对 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param scanArgument + * {@link HScanArgument} + * + * @return 返回和给定模式相匹配的元素 + */ + ScanResult> hScan(final byte[] key, final byte[] cursor, + final HScanArgument scanArgument); + + /** + * 将哈希表 key 中域 field 的值设置为 value。 + * 如果给定的哈希表并不存在,那么一个新的哈希表; + * 如果域 field 已经存在于哈希表中,那么 value 将覆盖旧值 + * + *

详情说明 http://redisdoc.com/hash/hset.html

+ * + * @param key + * Key + * @param data + * 域和值 + * + * @return 被修改或增加的 field 个数 + */ + Long hSet(final String key, final KeyValue... data); + + /** + * 将哈希表 key 中域 field 的值设置为 value。 + * 如果给定的哈希表并不存在,那么一个新的哈希表; + * 如果域 field 已经存在于哈希表中,那么 value 将覆盖旧值 + * + *

详情说明 http://redisdoc.com/hash/hset.html

+ * + * @param key + * Key + * @param data + * 域和值 + * + * @return 被修改或增加的 field 个数 + */ + Long hSet(final byte[] key, final KeyValue... data); + + /** + * 当且仅当域 field 尚未存在于哈希表 key 中的情况下,将它的值设置为 value + * + *

详情说明 http://redisdoc.com/hash/hsetnx.html

+ * + * @param key + * Key + * @param field + * 域 + * @param value + * 值 + * + * @return 操作结果;设置成功时返回 Status.Success,在给定域已经存在而放弃执行设置操作时返回 Status.FAILURE + */ + Status hSetNx(final String key, final String field, final String value); + + /** + * 当且仅当域 field 尚未存在于哈希表 key 中的情况下,将它的值设置为 value + * + *

详情说明 http://redisdoc.com/hash/hsetnx.html

+ * + * @param key + * Key + * @param field + * 域 + * @param value + * 值 + * + * @return 操作结果;设置成功时返回 Status.Success,在给定域已经存在而放弃执行设置操作时返回 Status.FAILURE + */ + Status hSetNx(final byte[] key, final byte[] field, final byte[] value); + + /** + * 获取哈希表 key 中,与给定域 field 相关联的值的字符串长度 + * + *

详情说明 http://redisdoc.com/hash/hstrlen.html

+ * + * @param key + * Key + * @param field + * 域 + * + * @return 哈希表 key 中,与给定域 field 相关联的值的字符串长度 + */ + Long hStrLen(final String key, final String field); + + /** + * 获取哈希表 key 中,与给定域 field 相关联的值的字符串长度 + * + *

详情说明 http://redisdoc.com/hash/hstrlen.html

+ * + * @param key + * Key + * @param field + * 域 + * + * @return 哈希表 key 中,与给定域 field 相关联的值的字符串长度 + */ + Long hStrLen(final byte[] key, final byte[] field); + + /** + * 获取给定 key 的域剩余生存时间 + * + *

详情说明 https://redis.io/docs/latest/commands/httl/

+ * + * @param key + * Key + * @param fields + * 域 + * + * @return 当域不存在时,返回 -2 ; + * 当域存在但没有设置剩余生存时间时,返回 -1 。 + * 否则,以秒为单位,返回 key 的域剩余生存时间 + * + * @since 3.0.0 + */ + List hTtl(final String key, final String... fields); + + /** + * 获取给定 key 的域剩余生存时间 + * + *

详情说明 https://redis.io/docs/latest/commands/httl/

+ * + * @param key + * Key + * @param fields + * 域 + * + * @return 当域不存在时,返回 -2 ; + * 当域存在但没有设置剩余生存时间时,返回 -1 。 + * 否则,以秒为单位,返回 key 的域剩余生存时间 + * + * @since 3.0.0 + */ + List hTtl(final byte[] key, final byte[]... fields); + + /** + * 获取哈希表 key 中所有域的值 + * + *

详情说明 http://redisdoc.com/hash/hvals.html

+ * + * @param key + * Key + * + * @return 哈希表 key 中所有域的值 + */ + List hVals(final String key); + + /** + * 获取哈希表 key 中所有域的值 + * + *

详情说明 http://redisdoc.com/hash/hvals.html

+ * + * @param key + * Key + * + * @return 哈希表 key 中所有域的值 + */ + List hVals(final byte[] key); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/HyperLogLogCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/HyperLogLogCommands.java new file mode 100644 index 000000000..97d898f66 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/HyperLogLogCommands.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.Status; + +/** + * HyperLogLog 命令 + * + *

详情说明 https://redis.io/docs/latest/commands/?group=hyperloglog

+ * + * @author Yong.Teng + */ +public interface HyperLogLogCommands extends RedisCommands { + + /** + * 将任意数量的元素添加到指定的 HyperLogLog 里面 + * + *

详情说明 http://redisdoc.com/hyperloglog/pfadd.html

+ * + * @param key + * Key + * @param elements + * 一个或多个元素 + * + * @return 操作结果,如果 HyperLogLog 的内部储存被修改了,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status pfAdd(final String key, final String... elements); + + /** + * 将任意数量的元素添加到指定的 HyperLogLog 里面 + * + *

详情说明 http://redisdoc.com/hyperloglog/pfadd.html

+ * + * @param key + * Key + * @param elements + * 一个或多个元素 + * + * @return 操作结果,如果 HyperLogLog 的内部储存被修改了,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status pfAdd(final byte[] key, final byte[]... elements); + + /** + * 获取所有给定 HyperLogLog 的并集的近似基数,这个近似基数是通过将所有给定 HyperLogLog 合并至一个临时 HyperLogLog 来计算得出的 + * + *

详情说明 https://www.redis.com.cn/commands/pfcount.html

+ * + * @param keys + * 一个或多个 Key + * + * @return 所有给定 HyperLogLog 的并集的近似基数 + */ + Long pfCount(final String... keys); + + /** + * 获取所有给定 HyperLogLog 的并集的近似基数,这个近似基数是通过将所有给定 HyperLogLog 合并至一个临时 HyperLogLog 来计算得出的 + * + *

详情说明 https://www.redis.com.cn/commands/pfcount.html

+ * + * @param keys + * 一个或多个 Key + * + * @return 所有给定 HyperLogLog 的并集的近似基数 + */ + Long pfCount(final byte[]... keys); + + /** + * 将多个 HyperLogLog 合并(merge)为一个 HyperLogLog,并保存到 destKey 中 + * + *

详情说明 http://redisdoc.com/hyperloglog/pfmerge.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个待合并的 Key + * + * @return 操作结果 + */ + Status pfMerge(final String destKey, final String... keys); + + /** + * 将多个 HyperLogLog 合并(merge)为一个 HyperLogLog,并保存到 destKey 中 + * + *

详情说明 http://redisdoc.com/hyperloglog/pfmerge.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个待合并的 Key + * + * @return 操作结果 + */ + Status pfMerge(final byte[] destKey, final byte[]... keys); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/KeyCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/KeyCommands.java new file mode 100644 index 000000000..010b172be --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/KeyCommands.java @@ -0,0 +1,1364 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.Status; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.ObjectEncoding; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Type; +import com.buession.redis.core.command.args.MigrateArgument; +import com.buession.redis.core.command.args.RestoreArgument; +import com.buession.redis.core.command.args.ScanArgument; +import com.buession.redis.core.command.args.SortArgument; + +import java.util.List; +import java.util.Set; + +/** + * KEY 命令 + * + *

详情说明 https://redis.io/docs/latest/commands/?group=generic

+ * + * @author Yong.Teng + */ +public interface KeyCommands extends RedisCommands { + + /** + * Copy the value stored at the source key to the destination key + * + *

详情说明 https://redis.io/commands/copy/

+ * + * @param key + * 待复制 key + * @param destKey + * 目标 key + * + * @return 复制成功返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status copy(final String key, final String destKey); + + /** + * Copy the value stored at the source key to the destination key + * + *

详情说明 https://redis.io/commands/copy/

+ * + * @param key + * 待复制 key + * @param destKey + * 目标 key + * + * @return 复制成功返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status copy(final byte[] key, final byte[] destKey); + + /** + * Copy the value stored at the source key to the destination key + * + *

详情说明 https://redis.io/commands/copy/

+ * + * @param key + * 待复制 key + * @param destKey + * 目标 key + * @param db + * 目标 DB + * + * @return 复制成功返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status copy(final String key, final String destKey, final int db); + + /** + * Copy the value stored at the source key to the destination key + * + *

详情说明 https://redis.io/commands/copy/

+ * + * @param key + * 待复制 key + * @param destKey + * 目标 key + * @param db + * 目标 DB + * + * @return 复制成功返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status copy(final byte[] key, final byte[] destKey, final int db); + + /** + * Copy the value stored at the source key to the destination key + * + *

详情说明 https://redis.io/commands/copy/

+ * + * @param key + * 待复制 key + * @param destKey + * 目标 key + * @param replace + * 是否替换已存在 Key + * + * @return 复制成功返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status copy(final String key, final String destKey, final boolean replace); + + /** + * Copy the value stored at the source key to the destination key + * + *

详情说明 https://redis.io/commands/copy/

+ * + * @param key + * 待复制 key + * @param destKey + * 目标 key + * @param replace + * 是否替换已存在 Key + * + * @return 复制成功返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status copy(final byte[] key, final byte[] destKey, final boolean replace); + + /** + * Copy the value stored at the source key to the destination key + * + *

详情说明 https://redis.io/commands/copy/

+ * + * @param key + * 待复制 key + * @param destKey + * 目标 key + * @param db + * 目标 DB + * @param replace + * 是否替换已存在 Key + * + * @return 复制成功返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status copy(final String key, final String destKey, final int db, final boolean replace); + + /** + * Copy the value stored at the source key to the destination key + * + *

详情说明 https://redis.io/commands/copy/

+ * + * @param key + * 待复制 key + * @param destKey + * 目标 key + * @param db + * 目标 DB + * @param replace + * 是否替换已存在 Key + * + * @return 复制成功返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace); + + /** + * 删除给定的一个或多个 key + * + *

详情说明 http://redisdoc.com/database/del.html

+ * + * @param keys + * 一个或多个 key + * + * @return 被删除 key 的数量 + */ + Long del(final String... keys); + + /** + * 删除给定的一个或多个 key + * + *

详情说明 http://redisdoc.com/database/del.html

+ * + * @param keys + * 一个或多个 key + * + * @return 被删除 key 的数量 + */ + Long del(final byte[]... keys); + + /** + * 序列化给定 key ,并返回被序列化的值 + * + *

详情说明 http://redisdoc.com/internal/dump.html

+ * + * @param key + * Key + * + * @return 被序列化的值 + */ + String dump(final String key); + + /** + * 序列化给定 key ,并返回被序列化的值 + * + *

详情说明 http://redisdoc.com/internal/dump.html

+ * + * @param key + * Key + * + * @return 被序列化的值 + */ + byte[] dump(final byte[] key); + + /** + * 检查给定 key 是否存在 + * + *

详情说明 http://redisdoc.com/database/exists.html

+ * + * @param key + * Key + * + * @return 检测结果 + */ + Boolean exists(final String key); + + /** + * 检查给定 key 是否存在 + * + *

详情说明 http://redisdoc.com/database/exists.html

+ * + * @param key + * Key + * + * @return 检测结果 + */ + Boolean exists(final byte[] key); + + /** + * 检查给定 key 是否存在 + * + *

详情说明 http://redisdoc.com/database/exists.html

+ * + * @param keys + * Key + * + * @return 检查给定 key 存在的数量 + */ + Long exists(final String... keys); + + /** + * 检查给定 key 是否存在 + * + *

详情说明 http://redisdoc.com/database/exists.html

+ * + * @param keys + * Key + * + * @return 检查给定 key 存在的数量 + */ + Long exists(final byte[]... keys); + + /** + * 为给定 key 设置生存时间,当 key 过期时(生存时间为 0),它会被自动删除 + * + *

详情说明http://redisdoc.com/expire/expire.html

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:秒) + * + * @return 操作结果 + */ + Status expire(final String key, final int lifetime); + + /** + * 为给定 key 设置生存时间,当 key 过期时(生存时间为 0),它会被自动删除 + * + *

详情说明http://redisdoc.com/expire/expire.html

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:秒) + * + * @return 操作结果 + */ + Status expire(final byte[] key, final int lifetime); + + /** + * 为给定 key 设置生存时间,当 key 过期时(生存时间为 0),它会被自动删除 + * + *

详情说明http://redisdoc.com/expire/expire.html

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:秒) + * @param expireOption + * 过期选项 + * + * @return 操作结果 + */ + Status expire(final String key, final int lifetime, final ExpireOption expireOption); + + /** + * 为给定 key 设置生存时间,当 key 过期时(生存时间为 0),它会被自动删除 + * + *

详情说明http://redisdoc.com/expire/expire.html

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:秒) + * @param expireOption + * 过期选项 + * + * @return 操作结果 + */ + Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption); + + /** + * 为给定 key 设置过期时间,具体过期时间戳 + * + *

详情说明 http://redisdoc.com/expire/expireat.html

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:秒) + * + * @return 操作结果 + */ + Status expireAt(final String key, final long unixTimestamp); + + /** + * 为给定 key 设置过期时间,具体过期时间戳 + * + *

详情说明 http://redisdoc.com/expire/expireat.html

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:秒) + * + * @return 操作结果 + */ + Status expireAt(final byte[] key, final long unixTimestamp); + + /** + * 为给定 key 设置过期时间,具体过期时间戳 + * + *

详情说明 http://redisdoc.com/expire/expireat.html

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:秒) + * @param expireOption + * 过期选项 + * + * @return 操作结果 + * + * @since 3.0.0 + */ + Status expireAt(final String key, final long unixTimestamp, final ExpireOption expireOption); + + /** + * 为给定 key 设置过期时间,具体过期时间戳 + * + *

详情说明 http://redisdoc.com/expire/expireat.html

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:秒) + * @param expireOption + * 过期选项 + * + * @return 操作结果 + * + * @since 3.0.0 + */ + Status expireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption); + + /** + * Returns the absolute Unix timestamp (since January 1, 1970) in seconds at which the given key will expire. + * + *

详情说明 https://redis.io/docs/latest/commands/expiretime/

+ * + * @param key + * Key + * + * @return The expiration Unix timestamp in seconds; + * -1 if the key exists but has no associated expiration time; + * -2 if the key does not exist; + * + * @since 3.0.0 + */ + Long expireTime(final String key); + + /** + * Returns the absolute Unix timestamp (since January 1, 1970) in seconds at which the given key will expire. + * + *

详情说明 https://redis.io/docs/latest/commands/expiretime/

+ * + * @param key + * Key + * + * @return The expiration Unix timestamp in seconds; + * -1 if the key exists but has no associated expiration time; + * -2 if the key does not exist; + * + * @since 3.0.0 + */ + Long expireTime(final byte[] key); + + /** + * 查找所有符合给定模式 pattern 的 key + * + *

详情说明 http://redisdoc.com/database/keys.html

+ * + * @param pattern + * 模式 + * + * @return 符合给定模式的 key 列表 + */ + Set keys(final String pattern); + + /** + * 查找所有符合给定模式 pattern 的 key + * + *

详情说明 http://redisdoc.com/database/keys.html

+ * + * @param pattern + * 模式 + * + * @return 符合给定模式的 key 列表 + */ + Set keys(final byte[] pattern); + + /** + * 将 key 原子性地从当前实例传送到目标实例的指定数据库上, + * 一旦传送成功,key 保证会出现在目标实例上,而当前实例上的 key 会被删除 + * + *

详情说明 http://redisdoc.com/internal/migrate.html

+ * + * @param host + * 目标 Redis Server 主机地址 + * @param port + * 目标 Redis Server 端口 + * @param db + * 目标 Redis DB + * @param timeout + * 当前实例和目标实例进行沟通的最大间隔时间,只是说数据传送的时间不能超过这个值(单位:毫秒) + * @param keys + * Keys + * + * @return 操作结果 + */ + Status migrate(final String host, final int port, final int db, final int timeout, final String... keys); + + /** + * 将 key 原子性地从当前实例传送到目标实例的指定数据库上, + * 一旦传送成功,key 保证会出现在目标实例上,而当前实例上的 key 会被删除 + * + *

详情说明 http://redisdoc.com/internal/migrate.html

+ * + * @param host + * 目标 Redis Server 主机地址 + * @param port + * 目标 Redis Server 端口 + * @param db + * 目标 Redis DB + * @param timeout + * 当前实例和目标实例进行沟通的最大间隔时间,只是说数据传送的时间不能超过这个值(单位:毫秒) + * @param keys + * Keys + * + * @return 操作结果 + */ + Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... keys); + + /** + * 将 key 原子性地从当前实例传送到目标实例的指定数据库上, + * 一旦传送成功,key 保证会出现在目标实例上,而当前实例上的 key 会被删除 + * + *

详情说明 http://redisdoc.com/internal/migrate.html

+ * + * @param host + * 目标 Redis Server 主机地址 + * @param port + * 目标 Redis Server 端口 + * @param db + * 目标 Redis DB + * @param timeout + * 当前实例和目标实例进行沟通的最大间隔时间,只是说数据传送的时间不能超过这个值(单位:毫秒) + * @param migrateArgument + * 迁移参数 + * @param keys + * Keys + * + * @return 操作结果 + */ + Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgument migrateArgument, final String... keys); + + /** + * 将 key 原子性地从当前实例传送到目标实例的指定数据库上, + * 一旦传送成功,key 保证会出现在目标实例上,而当前实例上的 key 会被删除 + * + *

详情说明 http://redisdoc.com/internal/migrate.html

+ * + * @param host + * 目标 Redis Server 主机地址 + * @param port + * 目标 Redis Server 端口 + * @param db + * 目标 Redis DB + * @param timeout + * 当前实例和目标实例进行沟通的最大间隔时间,只是说数据传送的时间不能超过这个值(单位:毫秒) + * @param migrateArgument + * 迁移参数 + * @param keys + * Keys + * + * @return 操作结果 + */ + Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgument migrateArgument, final byte[]... keys); + + /** + * 将当前数据库的 key 移动到给定的数据库 db 当中; + * 如果当前数据库(源数据库)和给定数据库(目标数据库)有相同名字的给定 key , + * 或者 key 不存在于当前数据库,那么 MOVE 没有任何效果 + * + *

详情说明 http://redisdoc.com/database/move.html

+ * + * @param key + * Key + * @param db + * 目标数据库 + * + * @return 移动成功返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status move(final String key, final int db); + + /** + * 将当前数据库的 key 移动到给定的数据库 db 当中; + * 如果当前数据库(源数据库)和给定数据库(目标数据库)有相同名字的给定 key , + * 或者 key 不存在于当前数据库,那么 MOVE 没有任何效果 + * + *

详情说明 http://redisdoc.com/database/move.html

+ * + * @param key + * Key + * @param db + * 目标数据库 + * + * @return 移动成功返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status move(final byte[] key, final int db); + + /** + * 返回指定 key 对应 value 所使用的内部表示 + * + *

详情说明 http://www.redis.cn/commands/object.html

+ * + * @param key + * Key + * + * @return key 对应 value 所使用的内部表示 + */ + ObjectEncoding objectEncoding(final String key); + + /** + * 返回指定 key 对应 value 所使用的内部表示 + * + *

详情说明 http://www.redis.cn/commands/object.html

+ * + * @param key + * Key + * + * @return key 对应 value 所使用的内部表示 + */ + ObjectEncoding objectEncoding(final byte[] key); + + /** + * This command returns the logarithmic access frequency counter of a Redis object stored a key + * + *

详情说明 https://redis.io/commands/object-freq/

+ * + * @param key + * Key + * + * @return The counter’s value + */ + Long objectFreq(final String key); + + /** + * This command returns the logarithmic access frequency counter of a Redis object stored a key + * + *

详情说明 https://redis.io/commands/object-freq/

+ * + * @param key + * Key + * + * @return The counter’s value + */ + Long objectFreq(final byte[] key); + + /** + * 返回指定 key 对应的 value 自被存储之后空闲的时间(单位:秒) + * + *

详情说明 http://www.redis.cn/commands/object.html

+ * + * @param key + * Key + * + * @return key 对应的 value 自被存储之后空闲的时间(单位:秒) + */ + Long objectIdleTime(final String key); + + /** + * 返回指定 key 对应的 value 自被存储之后空闲的时间(单位:秒) + * + *

详情说明 http://www.redis.cn/commands/object.html

+ * + * @param key + * Key + * + * @return key 对应的 value 自被存储之后空闲的时间(单位:秒) + */ + Long objectIdleTime(final byte[] key); + + /** + * 返回指定 key 所对应 value 被引用的次数 + * + *

详情说明 http://www.redis.cn/commands/object.html

+ * + * @param key + * Key + * + * @return key 所对应 value 被引用的次数 + */ + Long objectRefcount(final String key); + + /** + * 返回指定 key 所对应 value 被引用的次数 + * + *

详情说明 http://www.redis.cn/commands/object.html

+ * + * @param key + * Key + * + * @return key 所对应 value 被引用的次数 + */ + Long objectRefcount(final byte[] key); + + /** + * 将 key 设置为持久性的 Key + * + *

详情说明 http://redisdoc.com/expire/persist.html

+ * + * @param key + * Key + * + * @return 操作结果 + */ + Status persist(final String key); + + /** + * 将 key 设置为持久性的 Key + * + *

详情说明 http://redisdoc.com/expire/persist.html

+ * + * @param key + * Key + * + * @return 操作结果 + */ + Status persist(final byte[] key); + + /** + * 为给定 key 设置生存时间,当 key 过期时(生存时间为 0),它会被自动删除 + * + *

详情说明 http://redisdoc.com/expire/pexpire.html

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:毫秒) + * + * @return 操作结果 + */ + Status pExpire(final String key, final int lifetime); + + /** + * 为给定 key 设置生存时间,当 key 过期时(生存时间为 0),它会被自动删除 + * + *

详情说明 http://redisdoc.com/expire/pexpire.html

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:毫秒) + * + * @return 操作结果 + */ + Status pExpire(final byte[] key, final int lifetime); + + /** + * 为给定 key 设置生存时间,当 key 过期时(生存时间为 0),它会被自动删除 + * + *

详情说明 http://redisdoc.com/expire/pexpire.html

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:毫秒) + * @param expireOption + * 过期选项 + * + * @return 操作结果 + * + * @since 3.0.0 + */ + Status pExpire(final String key, final int lifetime, final ExpireOption expireOption); + + /** + * 为给定 key 设置生存时间,当 key 过期时(生存时间为 0),它会被自动删除 + * + *

详情说明 http://redisdoc.com/expire/pexpire.html

+ * + * @param key + * Key + * @param lifetime + * 生存时间(单位:毫秒) + * @param expireOption + * 过期选项 + * + * @return 操作结果 + * + * @since 3.0.0 + */ + Status pExpire(final byte[] key, final int lifetime, final ExpireOption expireOption); + + /** + * 为给定 key 设置过期时间,具体过期时间戳 + * + *

详情说明 http://redisdoc.com/expire/pexpireat.html

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:毫秒) + * + * @return 操作结果 + */ + Status pExpireAt(final String key, final long unixTimestamp); + + /** + * 为给定 key 设置过期时间,具体过期时间戳 + * + *

详情说明 http://redisdoc.com/expire/pexpireat.html

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:毫秒) + * + * @return 操作结果 + */ + Status pExpireAt(final byte[] key, final long unixTimestamp); + + /** + * 为给定 key 设置过期时间,具体过期时间戳 + * + *

详情说明 http://redisdoc.com/expire/pexpireat.html

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:毫秒) + * @param expireOption + * 过期选项 + * + * @return 操作结果 + * + * @since 3.0.0 + */ + Status pExpireAt(final String key, final long unixTimestamp, final ExpireOption expireOption); + + /** + * 为给定 key 设置过期时间,具体过期时间戳 + * + *

详情说明 http://redisdoc.com/expire/pexpireat.html

+ * + * @param key + * Key + * @param unixTimestamp + * 过期时间戳(单位:毫秒) + * @param expireOption + * 过期选项 + * + * @return 操作结果 + * + * @since 3.0.0 + */ + Status pExpireAt(final byte[] key, final long unixTimestamp, final ExpireOption expireOption); + + /** + * Returns the absolute Unix timestamp (since January 1, 1970) in milliseconds at which the given key will expire. + * + *

详情说明 https://redis.io/docs/latest/commands/pexpiretime/

+ * + * @param key + * Key + * + * @return The expiration Unix timestamp in milliseconds; + * -1 if the key exists but has no associated expiration time; + * -2 if the key does not exist; + * + * @since 3.0.0 + */ + Long pExpireTime(final String key); + + /** + * Returns the absolute Unix timestamp (since January 1, 1970) in milliseconds at which the given key will expire. + * + *

详情说明 https://redis.io/docs/latest/commands/pexpiretime/

+ * + * @param key + * Key + * + * @return The expiration Unix timestamp in milliseconds; + * -1 if the key exists but has no associated expiration time; + * -2 if the key does not exist; + * + * @since 3.0.0 + */ + Long pExpireTime(final byte[] key); + + /** + * 获取给定 key 的剩余生存时间 + * + *

详情说明 http://redisdoc.com/expire/pttl.html

+ * + * @param key + * Key + * + * @return 当 key 不存在时,返回 -2 ; + * 当 key 存在但没有设置剩余生存时间时,返回 -1 。 + * 否则,以毫秒为单位,返回 key 的剩余生存时间 + */ + Long pTtl(final String key); + + /** + * 获取给定 key 的剩余生存时间 + * + *

详情说明 http://redisdoc.com/expire/pttl.html

+ * + * @param key + * Key + * + * @return 当 key 不存在时,返回 -2 ; + * 当 key 存在但没有设置剩余生存时间时,返回 -1 。 + * 否则,以毫秒为单位,返回 key 的剩余生存时间 + */ + Long pTtl(final byte[] key); + + /** + * 从当前数据库中随机返回一个 key + * + *

详情说明 http://redisdoc.com/database/randomkey.html

+ * + * @return 一个随机的 key + */ + String randomKey(); + + /** + * 将 key 改名为 newkey + * + *

详情说明 http://redisdoc.com/database/renamehtml

+ * + * @param key + * Key + * @param newKey + * 新 Key + * + * @return 当改名成功时返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status rename(final String key, final String newKey); + + /** + * 将 key 改名为 newkey + * + *

详情说明 http://redisdoc.com/database/rename.html

+ * + * @param key + * Key + * @param newKey + * 新 Key + * + * @return 当改名成功时返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status rename(final byte[] key, final byte[] newKey); + + /** + * 且仅当 newkey 不存在时,将 key 改名为 newkey + * + *

详情说明 http://redisdoc.com/database/renamenx.html

+ * + * @param key + * Key + * @param newKey + * 新 Key + * + * @return 当改名成功时返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status renameNx(final String key, final String newKey); + + /** + * 且仅当 newkey 不存在时,将 key 改名为 newkey + * + *

详情说明 http://redisdoc.com/database/renamenx.html

+ * + * @param key + * Key + * @param newKey + * 新 Key + * + * @return 当改名成功时返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status renameNx(final byte[] key, final byte[] newKey); + + /** + * 反序列化给定的序列化值,并将它和给定的 key 关联 + * + *

详情说明 https://redis.io/commands/restore/

+ * + * @param key + * Key + * @param serializedValue + * 序列化值 + * @param ttl + * 生存时间(单位:毫秒) + * + * @return 操作结果 + */ + Status restore(final String key, final byte[] serializedValue, final int ttl); + + /** + * 反序列化给定的序列化值,并将它和给定的 key 关联 + * + *

详情说明 https://redis.io/commands/restore/

+ * + * @param key + * Key + * @param serializedValue + * 序列化值 + * @param ttl + * 生存时间(单位:毫秒) + * + * @return 操作结果 + */ + Status restore(final byte[] key, final byte[] serializedValue, final int ttl); + + /** + * 反序列化给定的序列化值,并将它和给定的 key 关联 + * + *

详情说明 https://redis.io/commands/restore/

+ * + * @param key + * Key + * @param serializedValue + * 序列化值 + * @param ttl + * 生存时间(单位:毫秒) + * @param restoreArgument + * {@link RestoreArgument} + * + * @return 操作结果 + */ + Status restore(final String key, final byte[] serializedValue, final int ttl, + final RestoreArgument restoreArgument); + + /** + * 反序列化给定的序列化值,并将它和给定的 key 关联 + * + *

详情说明 https://redis.io/commands/restore/

+ * + * @param key + * Key + * @param serializedValue + * 序列化值 + * @param ttl + * 生存时间(单位:毫秒) + * @param restoreArgument + * {@link RestoreArgument} + * + * @return 操作结果 + */ + Status restore(final byte[] key, final byte[] serializedValue, final int ttl, + final RestoreArgument restoreArgument); + + /** + * 迭代当前数据库中的数据库键 + * + *

详情说明http://redisdoc.com/database/scan.html

+ * + * @param cursor + * 游标 + * + * @return 返回每个元素都是一个数据库键 + */ + ScanResult> scan(final long cursor); + + /** + * 迭代当前数据库中的数据库键 + * + *

详情说明 http://redisdoc.com/database/scan.html

+ * + * @param cursor + * 游标 + * + * @return 返回每个元素都是一个数据库键 + */ + ScanResult> scan(final String cursor); + + /** + * 迭代当前数据库中的数据库键 + * + *

详情说明 http://redisdoc.com/database/scan.html

+ * + * @param cursor + * 游标 + * + * @return 返回每个元素都是一个数据库键 + */ + ScanResult> scan(final byte[] cursor); + + /** + * 迭代当前数据库中的数据库键 + * + *

详情说明 http://redisdoc.com/database/scan.html

+ * + * @param cursor + * 游标 + * @param scanArgument + * {@link ScanArgument} + * + * @return 返回和给定模式相匹配的数据库键 + * + * @since 3.0.0 + */ + ScanResult> scan(final long cursor, final ScanArgument.StringScanArgument scanArgument); + + /** + * 迭代当前数据库中的数据库键 + * + *

详情说明 http://redisdoc.com/database/scan.html

+ * + * @param cursor + * 游标 + * @param scanArgument + * {@link ScanArgument} + * + * @return 返回和给定模式相匹配的数据库键 + * + * @since 3.0.0 + */ + ScanResult> scan(final long cursor, final ScanArgument.ByteScanArgument scanArgument); + + /** + * 返回给定列表、集合、有序集合 key 中经过排序的元素 + * + *

详情说明 http://redisdoc.com/database/sort.html

+ * + * @param key + * Key + * + * @return 列表形式的排序结果 + */ + List sort(final String key); + + /** + * 返回给定列表、集合、有序集合 key 中经过排序的元素 + * + *

详情说明 http://redisdoc.com/database/sort.html

+ * + * @param key + * Key + * + * @return 列表形式的排序结果 + */ + List sort(final byte[] key); + + /** + * 返回给定列表、集合、有序集合 key 中经过排序的元素 + * + *

详情说明 http://redisdoc.com/database/sort.html

+ * + * @param key + * Key + * @param sortArgument + * 排序参数 + * + * @return 列表形式的排序结果 + */ + List sort(final String key, final SortArgument sortArgument); + + /** + * 返回给定列表、集合、有序集合 key 中经过排序的元素 + * + *

详情说明 http://redisdoc.com/database/sort.html

+ * + * @param key + * Key + * @param sortArgument + * 排序参数 + * + * @return 列表形式的排序结果 + */ + List sort(final byte[] key, final SortArgument sortArgument); + + /** + * 保存给定列表、集合、有序集合 key 中经过排序的元素到 destKey; + * 如果被指定的 key 已存在,那么原有的值将被排序结果覆盖 + * + *

详情说明 http://redisdoc.com/database/sort.html

+ * + * @param key + * Key + * @param destKey + * 目标 key + * + * @return 排序结果的元素数量 + */ + Long sort(final String key, final String destKey); + + /** + * 保存给定列表、集合、有序集合 key 中经过排序的元素到 destKey; + * 如果被指定的 key 已存在,那么原有的值将被排序结果覆盖 + * + *

详情说明 http://redisdoc.com/database/sort.html

+ * + * @param key + * Key + * @param destKey + * 目标 key + * + * @return 排序结果的元素数量 + */ + Long sort(final byte[] key, final byte[] destKey); + + /** + * 保存给定列表、集合、有序集合 key 中经过排序的元素到 destKey; + * 如果被指定的 key 已存在,那么原有的值将被排序结果覆盖 + * + *

详情说明 http://redisdoc.com/database/sort.html

+ * + * @param key + * Key + * @param destKey + * 目标 key + * @param sortArgument + * 排序参数 + * + * @return 排序结果的元素数量 + */ + Long sort(final String key, final String destKey, final SortArgument sortArgument); + + /** + * 保存给定列表、集合、有序集合 key 中经过排序的元素到 destKey; + * 如果被指定的 key 已存在,那么原有的值将被排序结果覆盖 + * + *

详情说明 http://redisdoc.com/database/sort.html

+ * + * @param key + * Key + * @param destKey + * 目标 key + * @param sortArgument + * 排序参数 + * + * @return 排序结果的元素数量 + */ + Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument); + + /** + * 返回给定列表、集合、有序集合 key 中经过排序的元素 + * + *

详情说明 https://redis.io/docs/latest/commands/sort_ro/

+ * + * @param key + * Key + * + * @return 列表形式的排序结果 + * + * @since 3.0.0 + */ + List sortRo(final String key); + + /** + * 返回给定列表、集合、有序集合 key 中经过排序的元素 + * + *

详情说明 https://redis.io/docs/latest/commands/sort_ro/

+ * + * @param key + * Key + * + * @return 列表形式的排序结果 + * + * @since 3.0.0 + */ + List sortRo(final byte[] key); + + /** + * 返回给定列表、集合、有序集合 key 中经过排序的元素 + * + *

详情说明 https://redis.io/docs/latest/commands/sort_ro/

+ * + * @param key + * Key + * @param sortArgument + * 排序参数 + * + * @return 列表形式的排序结果 + * + * @since 3.0.0 + */ + List sortRo(final String key, final SortArgument sortArgument); + + /** + * 返回给定列表、集合、有序集合 key 中经过排序的元素 + * + *

详情说明 https://redis.io/docs/latest/commands/sort_ro/

+ * + * @param key + * Key + * @param sortArgument + * 排序参数 + * + * @return 列表形式的排序结果 + * + * @since 3.0.0 + */ + List sortRo(final byte[] key, final SortArgument sortArgument); + + /** + * 修改指定一个或多个 key 最后访问时间 + * + *

详情说明 http://www.redis.cn/commands/touch.html

+ * + * @param keys + * 一个或多个 key + * + * @return 操作的 key 的数量 + */ + Long touch(final String... keys); + + /** + * 修改指定一个或多个 key 最后访问时间 + * + *

详情说明 http://www.redis.cn/commands/touch.html

+ * + * @param keys + * 一个或多个 key + * + * @return 操作的 key 的数量 + */ + Long touch(final byte[]... keys); + + /** + * 获取给定 key 的剩余生存时间 + * + *

详情说明 http://redisdoc.com/expire/ttl.html

+ * + * @param key + * Key + * + * @return 当 key 不存在时,返回 -2 ; + * 当 key 存在但没有设置剩余生存时间时,返回 -1 。 + * 否则,以秒为单位,返回 key 的剩余生存时间 + */ + Long ttl(final String key); + + /** + * 获取给定 key 的剩余生存时间 + * + *

详情说明 http://redisdoc.com/expire/ttl.html

+ * + * @param key + * Key + * + * @return 当 key 不存在时,返回 -2 ; + * 当 key 存在但没有设置剩余生存时间时,返回 -1 。 + * 否则,以秒为单位,返回 key 的剩余生存时间 + */ + Long ttl(final byte[] key); + + /** + * 获取 key 所储存的值的类型 + * + *

详情说明 http://redisdoc.com/database/type.html

+ * + * @param key + * Key + * + * @return key 所储存的值的类型 + */ + Type type(final String key); + + /** + * 获取 key 所储存的值的类型 + * + *

详情说明 http://redisdoc.com/database/type.html

+ * + * @param key + * Key + * + * @return key 所储存的值的类型 + */ + Type type(final byte[] key); + + /** + * 删除给定的一个或多个 key,该命令会在另一个线程中回收内存,因此它是非阻塞的。 + * 仅将 keys 从 keyspace 元数据中删除,真正的删除会在后续异步操作。 + * + *

详情说明 http://www.redis.cn/commands/unlink.html

+ * + * @param keys + * 一个或多个 key + * + * @return 被删除 key 的数量 + */ + Long unlink(final String... keys); + + /** + * 删除给定的一个或多个 key,该命令会在另一个线程中回收内存,因此它是非阻塞的。 + * 仅将 keys 从 keyspace 元数据中删除,真正的删除会在后续异步操作。 + * + *

详情说明 http://www.redis.cn/commands/unlink.html

+ * + * @param keys + * 一个或多个 key + * + * @return 被删除 key 的数量 + */ + Long unlink(final byte[]... keys); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ListCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ListCommands.java new file mode 100644 index 000000000..4cdd3049c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ListCommands.java @@ -0,0 +1,735 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.Status; +import com.buession.redis.core.Direction; +import com.buession.redis.core.ListPosition; +import com.buession.redis.core.command.args.LPosArgument; + +import java.util.List; + +/** + * 列表命令 + * + *

详情说明 http://redisdoc.com/list/index.html

+ * + * @author Yong.Teng + */ +public interface ListCommands extends RedisCommands { + + /** + * 获取列表 key 中,下标为 index 的元素 + * + *

详情说明 http://redisdoc.com/list/lindex.html

+ * + * @param key + * Key + * @param index + * 下标 + * + * @return 下标为 index 的元素;如果 index 参数的值不在列表的区间范围内,返回 null + */ + String lIndex(final String key, final long index); + + /** + * 获取列表 key 中,下标为 index 的元素 + * + *

详情说明 http://redisdoc.com/list/lindex.html

+ * + * @param key + * Key + * @param index + * 下标 + * + * @return 下标为 index 的元素;如果 index 参数的值不在列表的区间范围内,返回 null + */ + byte[] lIndex(final byte[] key, final long index); + + /** + * 将值 value 插入到列表 key 当中,位于值 pivot 之前或之后 + * + *

详情说明 http://redisdoc.com/list/linsert.html

+ * + * @param key + * Key + * @param position + * 位置 + * @param pivot + * pivot + * @param value + * 值 + * + * @return 执行成功,返回插入操作完成之后,列表的长度; + * 如果没有找到 pivot ,返回 -1 ;如果 key 不存在或为空列表,返回 0 。 + */ + Long lInsert(final String key, final ListPosition position, final String pivot, final String value); + + /** + * 将值 value 插入到列表 key 当中,位于值 pivot 之前或之后 + * + *

详情说明 http://redisdoc.com/list/linsert.html

+ * + * @param key + * Key + * @param position + * 位置 + * @param pivot + * pivot + * @param value + * 值 + * + * @return 执行成功,返回插入操作完成之后,列表的长度; + * 如果没有找到 pivot ,返回 -1 ;如果 key 不存在或为空列表,返回 0 。 + */ + Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value); + + /** + * 将列表 key 下标为 index 的元素的值设置为 value + * + *

详情说明 http://redisdoc.com/list/lset.html

+ * + * @param key + * Key + * @param index + * 下标 + * @param value + * 值 + * + * @return 操作结果;设置成功时返回 Status.Success,否则返回 Status.FAILURE + */ + Status lSet(final String key, final long index, final String value); + + /** + * 将列表 key 下标为 index 的元素的值设置为 value + * + *

详情说明 http://redisdoc.com/list/lset.html

+ * + * @param key + * Key + * @param index + * 下标 + * @param value + * 值 + * + * @return 操作结果;设置成功时返回 Status.Success,否则返回 Status.FAILURE + */ + Status lSet(final byte[] key, final long index, final byte[] value); + + /** + * 获取列表 key 的长度 + * + *

详情说明 http://redisdoc.com/list/llen.html

+ * + * @param key + * Key + * + * @return 列表 key 的长度,如果 key 不是列表类型,则返回 -1 + */ + Long lLen(final String key); + + /** + * 获取列表 key 的长度 + * + *

详情说明 http://redisdoc.com/list/llen.html

+ * + * @param key + * Key + * + * @return 列表 key 的长度,如果 key 不是列表类型,则返回 -1 + */ + Long lLen(final byte[] key); + + /** + * 获取列表 key 中指定区间内的元素,区间以偏移量 start 和 stop 之间的元素(包含 start 和 stop); + * 也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推 + * + *

详情说明 http://redisdoc.com/list/lrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 指定区间内的元素; + * 如果 start 下标比列表的最大下标 ( LLEN list 减去 1 )还要大,那么返回一个空列表; + * 如果 end 下标比最大下标还要大,那么最多返回到 end 个下标 + */ + List lRange(final String key, final long start, final long end); + + /** + * 获取列表 key 中指定区间内的元素,区间以偏移量 start 和 stop 之间的元素(包含 start 和 stop); + * 也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推 + * + *

详情说明 http://redisdoc.com/list/lrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 指定区间内的元素; + * 如果 start 下标比列表的最大下标 ( LLEN list 减去 1 )还要大,那么返回一个空列表; + * 如果 end 下标比最大下标还要大,那么最多返回到 end 个下标 + */ + List lRange(final byte[] key, final long start, final long end); + + /** + * 返回列表 key 中匹配给定 element 成员的索引 + * + *

详情说明 https://www.redis.com.cn/commands/lpos.html

+ * + * @param key + * Key + * @param element + * 成员 + * + * @return 整数表示匹配元素的位置,返回 null 表示没有找到匹配元素 + */ + Long lPos(final String key, final String element); + + /** + * 返回列表 key 中匹配给定 element 成员的索引 + * + *

详情说明 https://www.redis.com.cn/commands/lpos.html

+ * + * @param key + * Key + * @param element + * 成员 + * + * @return 整数表示匹配元素的位置,返回null表示没有找到匹配元素 + */ + Long lPos(final byte[] key, final byte[] element); + + /** + * 返回列表 key 中匹配给定 element 成员的索引 + * + *

详情说明 https://www.redis.com.cn/commands/lpos.html

+ * + * @param key + * Key + * @param element + * 成员 + * @param lPosArgument + * {@link LPosArgument} + * + * @return 整数表示匹配元素的位置,返回 null 表示没有找到匹配元素 + */ + Long lPos(final String key, final String element, final LPosArgument lPosArgument); + + /** + * 返回列表 key 中匹配给定 element 成员的索引 + * + *

详情说明 https://www.redis.com.cn/commands/lpos.html

+ * + * @param key + * Key + * @param element + * 成员 + * @param lPosArgument + * {@link LPosArgument} + * + * @return 整数表示匹配元素的位置,返回null表示没有找到匹配元素 + */ + Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument); + + /** + * 返回列表 key 中匹配给定 element 成员的索引 + * + *

详情说明 https://www.redis.com.cn/commands/lpos.html

+ * + * @param key + * Key + * @param element + * 成员 + * @param lPosArgument + * {@link LPosArgument} + * @param count + * 返回数量 + * + * @return 返回数据 + */ + List lPos(final String key, final String element, final LPosArgument lPosArgument, final int count); + + /** + * 返回列表 key 中匹配给定 element 成员的索引 + * + *

详情说明 https://www.redis.com.cn/commands/lpos.html

+ * + * @param key + * Key + * @param element + * 成员 + * @param lPosArgument + * {@link LPosArgument} + * @param count + * 返回数量 + * + * @return 返回数据 + */ + List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final int count); + + /** + * 移除列表中与参数 value 相等的 count 个元素元素 + * + *

详情说明 http://redisdoc.com/list/lrem.html

+ * + * @param key + * Key + * @param value + * 值 + * @param count + * 移除个数 + * + * @return 被移除元素的数量 + */ + Long lRem(final String key, final String value, final int count); + + /** + * 移除列表中与参数 value 相等的 count 个元素元素 + * + *

详情说明 http://redisdoc.com/list/lrem.html

+ * + * @param key + * Key + * @param value + * 值 + * @param count + * 移除个数 + * + * @return 被移除元素的数量 + */ + Long lRem(final byte[] key, final byte[] value, final int count); + + /** + * 移除列表指定区间外的元素; + * 如果 start 下标比列表的最大下标 end ( LLEN list 减去 1 )还要大,或者 start > stop ,则移除整个列表; + * 如果 stop 下标比 end 下标还要大,Redis将 stop 的值设置为 end + * + *

详情说明 http://redisdoc.com/list/ltrim.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 操作结果,成功返回 Status.Success,否则返回 Status.FAILURE + */ + Status lTrim(final String key, final long start, final long end); + + /** + * 移除列表指定区间外的元素; + * 如果 start 下标比列表的最大下标 end ( LLEN list 减去 1 )还要大,或者 start > stop ,则移除整个列表; + * 如果 stop 下标比 end 下标还要大,Redis将 stop 的值设置为 end + * + *

详情说明 http://redisdoc.com/list/ltrim.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 操作结果,成功返回 Status.Success,否则返回 Status.FAILURE + */ + Status lTrim(final byte[] key, final long start, final long end); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数) + * + *

详情说明 https://www.redis.com.cn/commands/lmove.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * + * @return 被移除并再次插入的元素 + */ + String lMove(final String key, final String destKey, final Direction from, final Direction to); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数) + * + *

详情说明 https://www.redis.com.cn/commands/lmove.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * + * @return 被移除并再次插入的元素 + */ + byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数); + * 是 lmove 的阻塞版 + * + *

详情说明 https://www.redis.com.cn/commands/lmove.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * @param timeout + * 超时时间 + * + * @return 被移除并再次插入的元素 + */ + String blMove(final String key, final String destKey, final Direction from, final Direction to, final int timeout); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数); + * 是 lmove 的阻塞版 + * + *

详情说明 https://www.redis.com.cn/commands/lmove.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * @param timeout + * 超时时间 + * + * @return 被移除并再次插入的元素 + */ + byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, final int timeout); + + /** + * 移除并返回列表中一个或多个 key 的头元素,BLPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/blpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值 + */ + List blPop(final String[] keys, final int timeout); + + /** + * 移除并返回列表中一个或多个 key 的头元素,BLPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/blpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值 + */ + List blPop(final byte[][] keys, final int timeout); + + /** + * 移除并返回列表中一个或多个 key 的尾元素,BRPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/brpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间(单位:秒) + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值 + */ + List brPop(final String[] keys, final int timeout); + + /** + * 移除并返回列表中一个或多个 key 的尾元素,BRPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/brpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间(单位:秒) + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值 + */ + List brPop(final byte[][] keys, final int timeout); + + /** + * 将列表 source 中的最后尾元素弹出,并返回;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 source 不存在,值 null 被返回,并且不执行其他动作; + * 如果 source 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * RPOPLPUSH 是列表的阻塞式(blocking)弹出原语 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param timeout + * 超时时间(单位:秒) + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素的值 ,第二个等待时长 + */ + String brPoplPush(final String key, final String destKey, final int timeout); + + /** + * 将列表 source 中的最后尾元素弹出,并返回;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 source 不存在,值 null 被返回,并且不执行其他动作; + * 如果 source 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * RPOPLPUSH 是列表的阻塞式(blocking)弹出原语 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param timeout + * 超时时间(单位:秒) + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素的值 ,第二个等待时长 + */ + byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout); + + /** + * 移除并返回列表 key 的头元素 + * + *

详情说明 http://redisdoc.com/list/lpop.html

+ * + * @param key + * Key + * + * @return 列表的头元素;当 key 不存在时,返回 null + */ + String lPop(final String key); + + /** + * 移除并返回列表 key 的头元素 + * + *

详情说明 http://redisdoc.com/list/lpop.html

+ * + * @param key + * Key + * + * @return 列表的头元素;当 key 不存在时,返回 null + */ + byte[] lPop(final byte[] key); + + /** + * 将一个或多个值 value 插入到列表 key 的表头 + * + *

详情说明 http://redisdoc.com/list/lpush.html

+ * + * @param key + * Key + * @param values + * 一个或多个值 + * + * @return 执行 LPUSH 命令后,列表的长度 + */ + Long lPush(final String key, final String... values); + + /** + * 将一个或多个值 value 插入到列表 key 的表头 + * + *

详情说明 http://redisdoc.com/list/lpush.html

+ * + * @param key + * Key + * @param values + * 一个或多个值 + * + * @return 执行 LPUSH 命令后,列表的长度 + */ + Long lPush(final byte[] key, final byte[]... values); + + /** + * 将一个或多个值 value 插入到列表 key 的表头,当且仅当 key 存在并且是一个列表 + * + *

详情说明 http://redisdoc.com/list/lpushx.html

+ * + * @param key + * Key + * @param values + * 一个或多个值 + * + * @return 执行 LPUSHX 命令后,列表的长度 + */ + Long lPushX(final String key, final String... values); + + /** + * 将一个或多个值 value 插入到列表 key 的表头,当且仅当 key 存在并且是一个列表 + * + *

详情说明 http://redisdoc.com/list/lpushx.html

+ * + * @param key + * Key + * @param values + * 一个或多个值 + * + * @return 执行 LPUSHX 命令后,列表的长度 + */ + Long lPushX(final byte[] key, final byte[]... values); + + /** + * 移除并返回列表 key 的尾元素 + * + *

详情说明 http://redisdoc.com/list/rpop.html

+ * + * @param key + * Key + * + * @return 列表的尾元素;当 key 不存在时,返回 null + */ + String rPop(final String key); + + /** + * 移除并返回列表 key 的尾元素 + * + *

详情说明 http://redisdoc.com/list/rpop.html

+ * + * @param key + * Key + * + * @return 列表的尾元素;当 key 不存在时,返回 null + */ + byte[] rPop(final byte[] key); + + /** + * 将列表 source 中的最后尾元素弹出,并返回;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 source 不存在,值 null 被返回,并且不执行其他动作; + * 如果 source 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param source + * Key + * @param destKey + * 目标 Key + * + * @return 被弹出的元素 + */ + String rPoplPush(final String source, final String destKey); + + /** + * 将列表 source 中的最后尾元素弹出,并返回;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 source 不存在,值 null 被返回,并且不执行其他动作; + * 如果 source 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param source + * Key + * @param destKey + * 目标 Key + * + * @return 被弹出的元素 + */ + byte[] rPoplPush(final byte[] source, final byte[] destKey); + + /** + * 将一个或多个值 value 插入到列表 key 的表尾 + * + *

详情说明 http://redisdoc.com/list/rpush.html

+ * + * @param key + * Key + * @param values + * 一个或多个值 + * + * @return 执行 RPUSH 操作后,表的长度 + */ + Long rPush(final String key, final String... values); + + /** + * 将一个或多个值 value 插入到列表 key 的表尾 + * + *

详情说明 http://redisdoc.com/list/rpush.html

+ * + * @param key + * Key + * @param values + * 一个或多个值 + * + * @return 执行 RPUSH 操作后,表的长度 + */ + Long rPush(final byte[] key, final byte[]... values); + + /** + * 将一个或多个值 value 插入到列表 key 的表尾,当且仅当 key 存在并且是一个列表 + * + *

详情说明 http://redisdoc.com/list/rpushx.html

+ * + * @param key + * Key + * @param values + * 一个或多个值 + * + * @return 执行 RPUSHX 之后,表的长度 + */ + Long rPushX(final String key, final String... values); + + /** + * 将一个或多个值 value 插入到列表 key 的表尾,当且仅当 key 存在并且是一个列表 + * + *

详情说明 http://redisdoc.com/list/rpushx.html

+ * + * @param key + * Key + * @param values + * 一个或多个值 + * + * @return 执行 RPUSHX 之后,表的长度 + */ + Long rPushX(final byte[] key, final byte[]... values); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ProtocolCommand.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ProtocolCommand.java new file mode 100644 index 000000000..0c0e9993e --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ProtocolCommand.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.core.Rawable; + +/** + * Redis 协议命令 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface ProtocolCommand extends Rawable { + + /** + * 返回命令名称 + * + * @return 命令名称 + */ + String getName(); + + /** + * 返回是否为读命令 + * + * @return true / false + */ + boolean isRead(); + + /** + * 返回是否为只读命令 + * + * @return true / false + */ + default boolean isReadonly() { + return isRead() && isWrite() == false; + } + + /** + * 返回是否为写命令 + * + * @return true / false + */ + boolean isWrite(); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/PubSubCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/PubSubCommands.java new file mode 100644 index 000000000..7c15a6a60 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/PubSubCommands.java @@ -0,0 +1,341 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2020 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.redis.core.PubSubListener; + +import java.util.List; +import java.util.Map; + +/** + * 发布与订阅命令 + * + *

详情说明 http://redisdoc.com/pubsub/index.html

+ * + * @author Yong.Teng + */ +public interface PubSubCommands extends RedisCommands { + + /** + * 订阅一个或多个符合给定模式的频道的信息 + * + *

详情说明 http://redisdoc.com/pubsub/psubscribe.html

+ * + * @param patterns + * 一个或多个模式 + * @param pubSubListener + * 订阅监听者 + */ + void pSubscribe(final String[] patterns, final PubSubListener pubSubListener); + + /** + * 订阅一个或多个符合给定模式的频道的信息 + * + *

详情说明 http://redisdoc.com/pubsub/psubscribe.html

+ * + * @param patterns + * 一个或多个模式 + * @param pubSubListener + * 订阅监听者 + */ + void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener); + + /** + * 将信息 message 发送到指定的频道 channel + * + *

详情说明 http://redisdoc.com/pubsub/publish.html

+ * + * @param channel + * 频道名称 + * @param message + * 信息 + * + * @return 接收到信息 message 的订阅者数量 + */ + Long publish(final String channel, final String message); + + /** + * 将信息 message 发送到指定的频道 channel + * + *

详情说明 http://redisdoc.com/pubsub/publish.html

+ * + * @param channel + * 频道名称 + * @param message + * 信息 + * + * @return 接收到信息 message 的订阅者数量 + */ + Long publish(final byte[] channel, final byte[] message); + + /** + * 列出当前 active channels 活跃是指信道含有一个或多个订阅者(不包括从模式接收订阅的客户端) + * 如果 pattern未提供,所有的信道都被列出,否则只列出匹配上指定全局-类型模式的信道被列出 + * + *

详情说明 https://www.redis.com.cn/commands/pubsub.html

+ * + * @return 活跃的信道列表,或者符合指定模式的信道 + */ + List pubsubChannels(); + + /** + * 列出当前 active channels 活跃是指信道含有一个或多个订阅者(不包括从模式接收订阅的客户端) + * 如果 pattern未提供,所有的信道都被列出,否则只列出匹配上指定全局-类型模式的信道被列出 + * + *

详情说明 https://www.redis.com.cn/commands/pubsub.html

+ * + * @param pattern + * 匹配模式 + * + * @return 活跃的信道列表,或者符合指定模式的信道 + */ + List pubsubChannels(final String pattern); + + /** + * 列出当前 active channels 活跃是指信道含有一个或多个订阅者(不包括从模式接收订阅的客户端) + * 如果 pattern未提供,所有的信道都被列出,否则只列出匹配上指定全局-类型模式的信道被列出 + * + *

详情说明 https://www.redis.com.cn/commands/pubsub.html

+ * + * @param pattern + * 匹配模式 + * + * @return 活跃的信道列表,或者符合指定模式的信道 + */ + List pubsubChannels(final byte[] pattern); + + /** + * 列出当前 active channels 活跃是指信道含有一个或多个订阅者(不包括从模式接收订阅的客户端) + * 如果 pattern未提供,所有的信道都被列出,否则只列出匹配上指定全局-类型模式的信道被列出 + * + *

详情说明 https://redis.io/docs/latest/commands/pubsub-shardchannels/

+ * + * @return 活跃的信道列表,或者符合指定模式的信道 + * + * @since 3.0.0 + */ + List pubsubShardChannels(); + + /** + * 列出当前 active channels 活跃是指信道含有一个或多个订阅者(不包括从模式接收订阅的客户端) + * 如果 pattern未提供,所有的信道都被列出,否则只列出匹配上指定全局-类型模式的信道被列出 + * + *

详情说明 https://redis.io/docs/latest/commands/pubsub-shardchannels/

+ * + * @param pattern + * 匹配模式 + * + * @return 活跃的信道列表,或者符合指定模式的信道 + * + * @since 3.0.0 + */ + List pubsubShardChannels(final String pattern); + + /** + * 列出当前 active channels 活跃是指信道含有一个或多个订阅者(不包括从模式接收订阅的客户端) + * 如果 pattern未提供,所有的信道都被列出,否则只列出匹配上指定全局-类型模式的信道被列出 + * + *

详情说明 https://redis.io/docs/latest/commands/pubsub-shardchannels/

+ * + * @param pattern + * 匹配模式 + * + * @return 活跃的信道列表,或者符合指定模式的信道 + * + * @since 3.0.0 + */ + List pubsubShardChannels(final byte[] pattern); + + /** + * 返回订阅模式的数量(使用命令PSUBSCRIBE实现)。 + * 注意,这个命令返回的不是订阅模式的客户端的数量, 而是客户端订阅的所有模式的数量总和。 + * + *

详情说明 https://www.redis.com.cn/commands/pubsub.html

+ * + * @return 阅模式的数量 + */ + Long pubsubNumPat(); + + /** + * 列出指定信道的订阅者个数(不包括订阅模式的客户端订阅者) + * + *

详情说明 https://redis.io/docs/latest/commands/pubsub-numsub/

+ * + * @return 指定信道的订阅者个数 + * + * @since 3.0.0 + */ + Map pubsubNumSub(); + + /** + * 列出指定信道的订阅者个数(不包括订阅模式的客户端订阅者) + * + *

详情说明 https://redis.io/docs/latest/commands/pubsub-numsub/

+ * + * @param channels + * 一个或多个频道 + * + * @return 指定信道的订阅者个数 + */ + Map pubsubNumSub(final String... channels); + + /** + * 列出指定信道的订阅者个数(不包括订阅模式的客户端订阅者) + * + *

详情说明 https://redis.io/docs/latest/commands/pubsub-numsub/

+ * + * @param channels + * 一个或多个频道 + * + * @return 指定信道的订阅者个数 + */ + Map pubsubNumSub(final byte[]... channels); + + /** + * 列出指定信道的订阅者个数(不包括订阅模式的客户端订阅者) + * + *

详情说明 https://redis.io/docs/latest/commands/pubsub-shardnumsub/

+ * + * @return 指定信道的订阅者个数 + * + * @since 3.0.0 + */ + Map pubsubShardNumSub(); + + /** + * 列出指定信道的订阅者个数(不包括订阅模式的客户端订阅者) + * + *

详情说明 https://redis.io/docs/latest/commands/pubsub-shardnumsub/

+ * + * @param shardChannels + * 一个或多个频道 + * + * @return 指定信道的订阅者个数 + */ + Map pubsubShardNumSub(final String... shardChannels); + + /** + * 列出指定信道的订阅者个数(不包括订阅模式的客户端订阅者) + * + *

详情说明 https://redis.io/docs/latest/commands/pubsub-shardnumsub/

+ * + * @param shardChannels + * 一个或多个频道 + * + * @return 指定信道的订阅者个数 + */ + Map pubsubShardNumSub(final byte[]... shardChannels); + + /** + * 指示客户端退订使用 PSUBSCRIBE pattern [pattern …] 命令订阅的所有模式消息 + * + *

详情说明 http://redisdoc.com/pubsub/punsubscribe.html

+ * + * @return 在不同的客户端中有不同的表现 + */ + Object pUnSubscribe(); + + /** + * 指示客户端退订所有给定一个或多个模式的消息 + * + *

详情说明 http://redisdoc.com/pubsub/punsubscribe.html

+ * + * @param patterns + * 一个或多个模式 + * + * @return 在不同的客户端中有不同的表现 + */ + Object pUnSubscribe(final String... patterns); + + /** + * 指示客户端退订所有给定一个或多个模式的消息 + * + *

详情说明 http://redisdoc.com/pubsub/punsubscribe.html

+ * + * @param patterns + * 一个或多个模式 + * + * @return 在不同的客户端中有不同的表现 + */ + Object pUnSubscribe(final byte[]... patterns); + + /** + * 订阅给定的一个或多个频道的信息 + * + *

详情说明 http://redisdoc.com/pubsub/subscribe.html

+ * + * @param channels + * 一个或多个频道 + * @param pubSubListener + * 订阅监听者 + */ + void subscribe(final String[] channels, final PubSubListener pubSubListener); + + /** + * 订阅给定的一个或多个频道的信息 + * + *

详情说明 http://redisdoc.com/pubsub/subscribe.html

+ * + * @param channels + * 一个或多个频道 + * @param pubSubListener + * 订阅监听者 + */ + void subscribe(final byte[][] channels, final PubSubListener pubSubListener); + + /** + * 指示客户端退订所有频道 + * + *

详情说明 http://redisdoc.com/pubsub/unsubscribe.html

+ * + * @return 在不同的客户端中有不同的表现 + */ + Object unSubscribe(); + + /** + * 指示客户端退订给定的一个或多个频道 + * + *

详情说明 http://redisdoc.com/pubsub/unsubscribe.html

+ * + * @param channels + * 一个或多个频道 + * + * @return 在不同的客户端中有不同的表现 + */ + Object unSubscribe(final String... channels); + + /** + * 指示客户端退订给定的一个或多个频道 + * + *

详情说明 http://redisdoc.com/pubsub/unsubscribe.html

+ * + * @param channels + * 一个或多个频道 + * + * @return 在不同的客户端中有不同的表现 + */ + Object unSubscribe(final byte[]... channels); + +} diff --git a/buession-session/src/main/java/com/buession/session/HttpSession.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/RedisCommands.java similarity index 95% rename from buession-session/src/main/java/com/buession/session/HttpSession.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/command/RedisCommands.java index 093cdf249..e3ee83a4c 100644 --- a/buession-session/src/main/java/com/buession/session/HttpSession.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/RedisCommands.java @@ -22,11 +22,11 @@ * | Copyright @ 2013-2019 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.session; +package com.buession.redis.core.command; /** * @author Yong.Teng */ -public interface HttpSession { +public interface RedisCommands { } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ScriptingCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ScriptingCommands.java new file mode 100644 index 000000000..334be85b1 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ScriptingCommands.java @@ -0,0 +1,287 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2020 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.Status; +import com.buession.redis.core.FlushMode; + +import java.util.List; + +/** + * LUA 脚本命令 + * + *

详情说明 http://redisdoc.com/script/index.html

+ * + * @author Yong.Teng + */ +public interface ScriptingCommands extends RedisCommands { + + /** + * 对 Lua 脚本进行求值 + * + *

详情说明 http://redisdoc.com/script/eval.html

+ * + * @param script + * 脚本程序 + * + * @return 求值结果 + */ + Object eval(final String script); + + /** + * 对 Lua 脚本进行求值 + * + *

详情说明 http://redisdoc.com/script/eval.html

+ * + * @param script + * 脚本程序 + * + * @return 求值结果 + */ + Object eval(final byte[] script); + + /** + * 对 Lua 脚本进行求值 + * + *

详情说明 http://redisdoc.com/script/eval.html

+ * + * @param script + * 脚本程序 + * @param params + * 一个或多个键名参数 + * + * @return 求值结果 + */ + Object eval(final String script, final String... params); + + /** + * 对 Lua 脚本进行求值 + * + *

详情说明 http://redisdoc.com/script/eval.html

+ * + * @param script + * 脚本程序 + * @param params + * 一个或多个键名参数 + * + * @return 求值结果 + */ + Object eval(final byte[] script, final byte[]... params); + + /** + * 对 Lua 脚本进行求值 + * + *

详情说明 http://redisdoc.com/script/eval.html

+ * + * @param script + * 脚本程序 + * @param keys + * 一个或多个键名参数 + * @param arguments + * 一个或多个键参数 + * + * @return 求值结果 + */ + Object eval(final String script, final String[] keys, final String[] arguments); + + /** + * 对 Lua 脚本进行求值 + * + *

详情说明 http://redisdoc.com/script/eval.html

+ * + * @param script + * 脚本程序 + * @param keys + * 一个或多个键名参数 + * @param arguments + * 一个或多个键参数 + * + * @return 求值结果 + */ + Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments); + + /** + * 根据给定的 SHA1 校验码,对缓存在服务器中的脚本进行求值 + * + *

详情说明 http://redisdoc.com/script/evalsha.html

+ * + * @param digest + * SHA1 校验码 + * + * @return 根据 SHA1 校验码,对脚本的求值结果 + */ + Object evalSha(final String digest); + + /** + * 根据给定的 SHA1 校验码,对缓存在服务器中的脚本进行求值 + * + *

详情说明 http://redisdoc.com/script/evalsha.html

+ * + * @param digest + * SHA1 校验码 + * + * @return 根据 SHA1 校验码,对脚本的求值结果 + */ + Object evalSha(final byte[] digest); + + /** + * 根据给定的 SHA1 校验码,对缓存在服务器中的脚本进行求值 + * + *

详情说明 http://redisdoc.com/script/evalsha.html

+ * + * @param digest + * SHA1 校验码 + * @param params + * 一个或多个键名参数 + * + * @return 根据 SHA1 校验码,对脚本的求值结果 + */ + Object evalSha(final String digest, final String... params); + + /** + * 根据给定的 SHA1 校验码,对缓存在服务器中的脚本进行求值 + * + *

详情说明 http://redisdoc.com/script/evalsha.html

+ * + * @param digest + * SHA1 校验码 + * @param params + * 一个或多个键名参数 + * + * @return 根据 SHA1 校验码,对脚本的求值结果 + */ + Object evalSha(final byte[] digest, final byte[]... params); + + /** + * 根据给定的 SHA1 校验码,对缓存在服务器中的脚本进行求值 + * + *

详情说明 http://redisdoc.com/script/evalsha.html

+ * + * @param digest + * SHA1 校验码 + * @param keys + * 一个或多个键名参数 + * @param arguments + * 一个或多个键参数 + * + * @return 根据 SHA1 校验码,对脚本的求值结果 + */ + Object evalSha(final String digest, final String[] keys, final String[] arguments); + + /** + * 根据给定的 SHA1 校验码,对缓存在服务器中的脚本进行求值 + * + *

详情说明 http://redisdoc.com/script/evalsha.html

+ * + * @param digest + * SHA1 校验码 + * @param keys + * 一个或多个键名参数 + * @param arguments + * 一个或多个键参数 + * + * @return 根据 SHA1 校验码,对脚本的求值结果 + */ + Object evalSha(final byte[] digest, final byte[][] keys, final byte[][] arguments); + + /** + * 根据一个或多个脚本的 SHA1 校验和,检测校验和所指定的脚本是否已经被保存在缓存当中 + * + *

详情说明 http://redisdoc.com/script/script_exists.html

+ * + * @param sha1 + * 一个或多个 SHA1 校验和 + * + * @return 返回一个包含布尔值的列表,true 表示脚本已经在缓存里面了;false 表示脚本不存在于缓存 + */ + List scriptExists(final String... sha1); + + /** + * 根据一个或多个脚本的 SHA1 校验和,检测校验和所指定的脚本是否已经被保存在缓存当中 + * + *

详情说明 http://redisdoc.com/script/script_exists.html

+ * + * @param sha1 + * 一个或多个 SHA1 校验和 + * + * @return 返回一个包含布尔值的列表,true 表示脚本已经在缓存里面了;false 表示脚本不存在于缓存 + */ + List scriptExists(final byte[]... sha1); + + /** + * 清除所有 Lua 脚本缓存 + * + *

详情说明 http://redisdoc.com/script/script_flush.html

+ * + * @return 操作成功返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status scriptFlush(); + + /** + * 清除所有 Lua 脚本缓存 + * + *

详情说明 http://redisdoc.com/script/script_flush.html

+ * + * @param mode + * 刷新模式 + * + * @return 操作成功返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status scriptFlush(final FlushMode mode); + + /** + * 将脚本 script 添加到脚本缓存中 + * + *

详情说明 http://redisdoc.com/script/script_load.html

+ * + * @param script + * 脚本 + * + * @return script 的 SHA1 校验和 + */ + String scriptLoad(final String script); + + /** + * 将脚本 script 添加到脚本缓存中 + * + *

详情说明 http://redisdoc.com/script/script_load.html

+ * + * @param script + * 脚本 + * + * @return script 的 SHA1 校验和 + */ + byte[] scriptLoad(final byte[] script); + + /** + * 杀死当前正在运行的 Lua 脚本,当且仅当这个脚本没有执行过任何写操作时,这个命令才生效 + * + *

详情说明 http://redisdoc.com/script/script_kill.html

+ * + * @return 操作成功返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status scriptKill(); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ServerCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ServerCommands.java new file mode 100644 index 000000000..b0e802af1 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/ServerCommands.java @@ -0,0 +1,659 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.Status; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.Info; +import com.buession.redis.core.MemoryStats; +import com.buession.redis.core.Module; +import com.buession.redis.core.RedisMonitor; +import com.buession.redis.core.RedisServerTime; +import com.buession.redis.core.Role; +import com.buession.redis.core.SlowLog; + +import java.util.List; +import java.util.Map; + +/** + * 服务端命令 + * + *

详情说明 http://www.redis.cn/commands.html#server

+ * + * @author Yong.Teng + */ +public interface ServerCommands extends RedisCommands { + + /** + * 执行一个 AOF文件 重写操作;重写会创建一个当前 AOF 文件的体积优化版本 + * + *

详情说明 http://redisdoc.com/persistence/bgrewriteaof.html

+ * + * @return 反馈信息 + */ + String bgRewriteAof(); + + /** + * 在后台异步保存当前数据库的数据到磁盘 + * + *

详情说明 http://redisdoc.com/persistence/bgsave.html

+ * + * @return 反馈信息 + */ + String bgSave(); + + /** + * 动态地调整 Redis 服务器的配置 + * + *

详情说明 http://redisdoc.com/configure/config_set.html

+ * + * @param parameter + * 配置项 + * @param value + * 配置值 + * + * @return 设置成功时返回,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status configSet(final String parameter, final String value); + + /** + * 动态地调整 Redis 服务器的配置 + * + *

详情说明 https://www.redisio.com/commands/Config-Set.html

+ * + * @param parameter + * 配置项 + * @param value + * 配置值 + * + * @return 设置成功时返回,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status configSet(final byte[] parameter, final byte[] value); + + /** + * 批量动态地调整 Redis 服务器的配置 + * + *

详情说明 https://www.redisio.com/commands/Config-Set.html

+ * + * @param configs + * 配置 + * + * @return 设置成功时返回,返回 Status.SUCCESS;否则,返回 Status.FAILURE + * + * @since 3.0.0 + */ + Status configSet(final Map configs); + + /** + * 获取 Redis 服务器的配置参数 + * + *

详情说明 https://www.redisio.com/commands/Config-Get.html

+ * + * @param pattern + * 配置项 + * + * @return 给定配置参数的值 + */ + Map configGet(final String pattern); + + /** + * 获取 Redis 服务器的配置参数 + * + *

详情说明 https://www.redisio.com/commands/Config-Get.html

+ * + * @param pattern + * 配置项 + * + * @return 给定配置参数的值 + */ + Map configGet(final byte[] pattern); + + /** + * 重置 INFO 命令中的某些统计数据,包括: + * 1)Keyspace hits (键空间命中次数) + * 2)Keyspace misses (键空间不命中次数) + * 3)Number of commands processed (执行命令的次数) + * 4)Number of connections received (连接服务器的次数) + * 5)Number of expired keys (过期key的数量) + * 6)Number of rejected connections (被拒绝的连接数量) + * 7)Latest fork(2) time(最后执行 fork(2) 的时间) + * 8)The aof_delayed_fsync counter(aof_delayed_fsync 计数器的值) + * + *

详情说明 http://redisdoc.com/configure/config_resetstat.html

+ * + * @return 总是返回 Status.SUCCESS + */ + Status configResetStat(); + + /** + * 对启动 Redis 服务器时所指定的 redis.conf 文件进行改写 + * + *

详情说明 http://redisdoc.com/configure/config_rewrite.html

+ * + * @return 如果配置重写成功则,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status configRewrite(); + + /** + * 获取数据库的 key 的数量 + * + *

详情说明 http://redisdoc.com/database/dbsize.html

+ * + * @return 数据库的 key 的数量 + */ + Long dbSize(); + + /** + * This command will start a coordinated failover between the currently-connected-to master and one of its replicas + * + *

详情说明 https://redis.io/commands/failover/

+ * + * @return Status.SUCCESS if the command was accepted and a coordinated failover is in progress + */ + Status failover(); + + /** + * This command will start a coordinated failover between the currently-connected-to master and one of its replicas + * + *

详情说明 https://redis.io/commands/failover/

+ * + * @param host + * 主机地址 + * @param port + * 端口 + * + * @return Status.SUCCESS if the command was accepted and a coordinated failover is in progress + */ + Status failover(final String host, final int port); + + /** + * This command will start a coordinated failover between the currently-connected-to master and one of its replicas + * + *

详情说明 https://redis.io/commands/failover/

+ * + * @param host + * 主机地址 + * @param port + * 端口 + * @param timeout + * 超时(单位:毫秒) + * + * @return Status.SUCCESS if the command was accepted and a coordinated failover is in progress + */ + Status failover(final String host, final int port, final int timeout); + + /** + * This command will start a coordinated failover between the currently-connected-to master and one of its replicas + * + *

详情说明 https://redis.io/commands/failover/

+ * + * @param host + * 主机地址 + * @param port + * 端口 + * @param isForce + * 是否强制 + * @param timeout + * 超时(单位:毫秒) + * + * @return Status.SUCCESS if the command was accepted and a coordinated failover is in progress + */ + Status failover(final String host, final int port, final boolean isForce, final int timeout); + + /** + * This command will start a coordinated failover between the currently-connected-to master and one of its replicas + * + *

详情说明 https://redis.io/commands/failover/

+ * + * @param timeout + * 超时(单位:毫秒) + * + * @return Status.SUCCESS if the command was accepted and a coordinated failover is in progress + */ + Status failover(final int timeout); + + /** + * 清空整个 Redis 服务器的数据(删除所有数据库的所有 key ) + * + *

详情说明 http://redisdoc.com/database/flushallhtml

+ * + * @return 始终返回 Status.SUCCESS + */ + Status flushAll(); + + /** + * 清空整个 Redis 服务器的数据(删除所有数据库的所有 key ) + * + *

详情说明 http://redisdoc.com/database/flushallhtml

+ * + * @param mode + * 刷新模式 + * + * @return 始终返回 Status.SUCCESS + */ + Status flushAll(final FlushMode mode); + + /** + * 清空当前数据库中的所有 key + * + *

详情说明 http://redisdoc.com/database/flushdb.html

+ * + * @return 始终返回 Status.SUCCESS + */ + Status flushDb(); + + /** + * 清空当前数据库中的所有 key + * + *

详情说明 http://redisdoc.com/database/flushdb.html

+ * + * @param mode + * 刷新模式 + * + * @return 始终返回 Status.SUCCESS + */ + Status flushDb(final FlushMode mode); + + /** + * 获取关于 Redis 服务器的各种信息和统计数值 + * + *

详情说明 http://redisdoc.com/client_and_server/info.html

+ * + * @return 关于 Redis 服务器的各种信息和统计数值 + */ + Info info(); + + /** + * 获取关于 Redis 服务器通过 section 指定的部分信息 + * + *

详情说明 http://redisdoc.com/client_and_server/info.html

+ * + * @param section + * InfoSection + * + * @return 关于 Redis 服务器的各种信息和统计数值 + */ + Info info(final Info.Section section); + + /** + * 获取最近一次 Redis 成功将数据保存到磁盘上的时间,以 UNIX 时间戳格式表示 + * + *

详情说明 http://redisdoc.com/persistence/lastsave.html

+ * + * @return 最近一次成功将数据保存到磁盘上的时间 + */ + Long lastSave(); + + /** + * 列出 Redis 服务器遇到的不同类型的内存相关问题,并提供相应的解决建议 + * + *

详情说明 https://redis.io/commands/memory-doctor/

+ * + * @return Redis 服务器遇到的不同类型的内存相关问题,以及解决建议 + */ + String memoryDoctor(); + + /** + * The MEMORY PURGE command attempts to purge dirty pages so these can be reclaimed by the allocator + * + *

详情说明 https://redis.io/commands/memory-purge/

+ * + * @return 操作成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status memoryPurge(); + + /** + * The MEMORY STATS command returns an Array reply about the memory usage of the server + * + *

详情说明 https://redis.io/commands/memory-stats/

+ * + * @return nested list of memory usage metrics and their values + */ + MemoryStats memoryStats(); + + /** + * The MEMORY USAGE command reports the number of bytes that a key and its value require to be stored in RAM + * + *

详情说明 https://redis.io/commands/memory-usage/

+ * + * @param key + * Key + * + * @return the memory usage in bytes + */ + Long memoryUsage(final String key); + + /** + * The MEMORY USAGE command reports the number of bytes that a key and its value require to be stored in RAM + * + *

详情说明 https://redis.io/commands/memory-usage/

+ * + * @param key + * Key + * + * @return the memory usage in bytes + */ + Long memoryUsage(final byte[] key); + + /** + * The MEMORY USAGE command reports the number of bytes that a key and its value require to be stored in RAM + * + *

详情说明 https://redis.io/commands/memory-usage/

+ * + * @param key + * Key + * @param samples + * Samples count + * + * @return the memory usage in bytes + */ + Long memoryUsage(final String key, final int samples); + + /** + * The MEMORY USAGE command reports the number of bytes that a key and its value require to be stored in RAM + * + *

详情说明 https://redis.io/commands/memory-usage/

+ * + * @param key + * Key + * @param samples + * Samples count + * + * @return the memory usage in bytes + */ + Long memoryUsage(final byte[] key, final int samples); + + /** + * Returns information about the modules loaded to the server + * + *

详情说明 https://redis.io/commands/module-list/

+ * + * @return A list of loaded modules + */ + List moduleList(); + + /** + * Returns information about the modules loaded to the server + * + *

详情说明 https://redis.io/commands/module-load/

+ * + * @param path + * Module Path + * + * @return A list of loaded modules + * + * @since 3.0.0 + */ + Status moduleLoad(final String path); + + /** + * Returns information about the modules loaded to the server + * + *

详情说明 https://redis.io/commands/module-load/

+ * + * @param path + * Module Path + * + * @return A list of loaded modules + * + * @since 3.0.0 + */ + Status moduleLoad(final byte[] path); + + /** + * Returns information about the modules loaded to the server + * + *

详情说明 https://redis.io/commands/module-load/

+ * + * @param path + * Module Path + * @param arguments + * Arguments + * + * @return A list of loaded modules + */ + Status moduleLoad(final String path, final String... arguments); + + /** + * Returns information about the modules loaded to the server + * + *

详情说明 https://redis.io/commands/module-load/

+ * + * @param path + * Module Path + * @param arguments + * Arguments + * + * @return A list of loaded modules + */ + Status moduleLoad(final byte[] path, final byte[]... arguments); + + /** + * This command unloads the module specified by name + * + *

详情说明 https://redis.io/commands/module-unload/

+ * + * @param name + * Module Name + * + * @return 操作成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status moduleUnLoad(final String name); + + /** + * This command unloads the module specified by name + * + *

详情说明 https://redis.io/commands/module-unload/

+ * + * @param name + * Module Name + * + * @return 操作成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status moduleUnLoad(final byte[] name); + + /** + * 实时打印出 Redis 服务器接收到的命令 + * + *

详情说明 http://redisdoc.com/debug/monitor.html

+ * + * @param redisMonitor + * Redis Monitor + */ + void monitor(final RedisMonitor redisMonitor); + + /** + * 用于复制功能(replication)的内部命令 + * + *

详情说明 http://redisdoc.com/internal/psync.html

+ * + * @param replicationId + * Master Run Id + * @param offset + * 偏移量 + * + * @return 序列化数据 + */ + Object pSync(final String replicationId, final long offset); + + /** + * 用于复制功能(replication)的内部命令 + * + *

详情说明 http://redisdoc.com/internal/psync.html

+ * + * @param replicationId + * Master Run Id + * @param offset + * 偏移量 + * + * @return 序列化数据 + */ + Object pSync(final byte[] replicationId, final long offset); + + /** + * 用于复制功能(replication)的内部命令 + * + *

详情说明 http://redisdoc.com/internal/sync.html

+ */ + void sync(); + + /** + * 可以在线修改当前服务器的复制设置 + * 如果当前服务器已经是副本服务器,会将当前服务器转变为某一服务器的副本服务器; + * 如果当前服务器已经是某个主服务器的副本服务器,那么将使当前服务器停止对原主服务器的同步,丢弃旧数据集,转而开始对新主服务器进行同步 + * + *

详情说明 https://redis.io/commands/replicaof/

+ * + * @param host + * Redis 主机地址 + * @param port + * Redis 端口 + * + * @return 操作结果 + */ + Status replicaOf(final String host, final int port); + + /** + * 用于在 Redis 运行时动态地修改复制(replication)功能的行为; + * 可以将当前服务器转变为指定服务器的从属服务器(slave server) + * + *

详情说明 http://redisdoc.com/replication/slaveof.html

+ * + * @param host + * Redis Slave Server 主机地址 + * @param port + * Redis Slave Server 端口 + * + * @return 总是返回 Status.SUCCESS + */ + Status slaveOf(final String host, final int port); + + /** + * 获取实例在复制中担任的角色信息 + * + *

详情说明 http://redisdoc.com/replication/role.html

+ * + * @return 实例在复制中担任的角色信息 + */ + Role role(); + + /** + * 执行一个同步保存操作,将当前 Redis 实例的所有数据快照(snapshot)以 RDB 文件的形式保存到硬盘; + * 该操作,因为它会阻塞所有客户端 + * + *

详情说明 http://redisdoc.com/persistence/save.html

+ * + * @return 保存成功返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status save(); + + /** + * SHUTDOWN 命令执行以下操作: + * 1)停止所有客户端 + * 2)如果有至少一个保存点在等待,执行 SAVE 命令 + * 3)如果 AOF 选项被打开,更新 AOF 文件 + * 4)关闭 redis 服务器 + * + *

详情说明 http://redisdoc.com/client_and_server/shutdown.html

+ */ + void shutdown(); + + /** + * SHUTDOWN 命令执行以下操作: + * 1)停止所有客户端 + * 2)如果有至少一个保存点在等待,执行 SAVE 命令 + * 3)如果 AOF 选项被打开,更新 AOF 文件 + * 4)关闭 redis 服务器(server) + * + *

详情说明 http://redisdoc.com/client_and_server/shutdown.html

+ * + * @param save + * 是否强制让数据库执行保存操作 + */ + void shutdown(final boolean save); + + /** + * The SLOWLOG GET command returns entries from the slow log in chronological order + * + *

详情说明 https://redis.io/commands/slowlog-get/

+ * + * @return A list of slow log entries + */ + List slowLogGet(); + + /** + * The SLOWLOG GET command returns entries from the slow log in chronological order + * + *

详情说明 https://redis.io/commands/slowlog-get/

+ * + * @param count + * 返回条数 + * + * @return A list of slow log entries + */ + List slowLogGet(final int count); + + /** + * This command returns the current number of entries in the slow log + * + *

详情说明 https://redis.io/commands/slowlog-len/

+ * + * @return The number of entries in the slow log + */ + Long slowLogLen(); + + /** + * This command resets the slow log, clearing all entries in it + * + *

详情说明 https://redis.io/commands/slowlog-reset/

+ * + * @return 操作成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status slowLogReset(); + + /** + * 对换指定的两个数据库,使得两个数据库的数据立即互换 + * + *

详情说明 http://redisdoc.com/database/swapdb.html

+ * + * @param db1 + * 数据库 1 索引号 + * @param db2 + * 数据库 2 索引号 + * + * @return 对换成功返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status swapdb(final int db1, final int db2); + + /** + * 获取当前服务器时间 + * + *

详情说明 http://redisdoc.com/client_and_server/time.html

+ * + * @return 当前服务器时间 + */ + RedisServerTime time(); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/SetCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/SetCommands.java new file mode 100644 index 000000000..8a7371e72 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/SetCommands.java @@ -0,0 +1,752 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.Status; +import com.buession.redis.core.ScanResult; + +import java.util.List; +import java.util.Set; + +/** + * 集合命令 + * + *

详情说明 http://redisdoc.com/set/index.html

+ * + * @author Yong.Teng + */ +public interface SetCommands extends RedisCommands { + + /** + * 将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略 + * + *

详情说明 http://redisdoc.com/set/sadd.html

+ * + * @param key + * Key + * @param members + * 元素 + * + * @return 被添加到集合中的新元素的数量,不包括被忽略的元素 + */ + Long sAdd(final String key, final String... members); + + /** + * 将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略 + * + *

详情说明 http://redisdoc.com/set/sadd.html

+ * + * @param key + * Key + * @param members + * 元素 + * + * @return 被添加到集合中的新元素的数量,不包括被忽略的元素 + */ + Long sAdd(final byte[] key, final byte[]... members); + + /** + * 获取集合存储的key的基数 (集合元素的数量) + * + *

详情说明 http://redisdoc.com/set/scard.html

+ * + * @param key + * Key + * + * @return 集合的基数 + */ + Long sCard(final String key); + + /** + * 获取集合存储的key的基数 (集合元素的数量) + * + *

详情说明 http://redisdoc.com/set/scard.html

+ * + * @param key + * Key + * + * @return 集合的基数 + */ + Long sCard(final byte[] key); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合之间的差集 + * + *

详情说明 http://redisdoc.com/set/sdiff.html

+ * + * @param keys + * 一个或多个 Key + * + * @return 一个包含差集成员的列表 + */ + Set sDiff(final String... keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合之间的差集 + * + *

详情说明 http://redisdoc.com/set/sdiff.html

+ * + * @param keys + * 一个或多个 Key + * + * @return 一个包含差集成员的列表 + */ + Set sDiff(final byte[]... keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合之间的差集,并保存到 destKey 中 + * + *

详情说明 http://redisdoc.com/set/sdiffstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * + * @return 结果集中的元素数量 + */ + Long sDiffStore(final String destKey, final String... keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合之间的差集,并保存到 destKey 中 + * + *

详情说明 http://redisdoc.com/set/sdiffstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * + * @return 结果集中的元素数量 + */ + Long sDiffStore(final byte[] destKey, final byte[]... keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的交集 + * + *

详情说明 http://redisdoc.com/set/sinter.html

+ * + * @param keys + * 一个或多个 Key + * + * @return 交集成员的列表 + */ + Set sInter(final String... keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的交集 + * + *

详情说明 http://redisdoc.com/set/sinter.html

+ * + * @param keys + * 一个或多个 Key + * + * @return 交集成员的列表 + */ + Set sInter(final byte[]... keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的交集,并保存到 destKey 中 + * + *

详情说明 http://redisdoc.com/set/sinterstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * + * @return 结果集中的元素数量 + */ + Long sInterStore(final String destKey, final String... keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的交集,并保存到 destKey 中 + * + *

详情说明 http://redisdoc.com/set/sinterstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * + * @return 结果集中的元素数量 + */ + Long sInterStore(final byte[] destKey, final byte[]... keys); + + /** + * 检测 member 元素是否集合 key 的成员 + * + *

详情说明 http://redisdoc.com/set/sismember.html

+ * + * @param key + * Key + * @param member + * 元素 + * + * @return 存在时,返回 true;否则,返回 false + */ + Boolean sIsMember(final String key, final String member); + + /** + * 检测 member 元素是否集合 key 的成员 + * + *

详情说明 http://redisdoc.com/set/sismember.html

+ * + * @param key + * Key + * @param member + * 元素 + * + * @return 存在时,返回 true;否则,返回 false + */ + Boolean sIsMember(final byte[] key, final byte[] member); + + /** + * 检查给定的 member 是不是特定集合的成员 + * + *

详情说明 https://www.redis.com.cn/commands/smismember.html

+ * + * @param key + * Key + * @param members + * 成员列表 + * + * @return 命令中member 出现的顺序,返回是否是集合成员的判断; + * 如果 member 是集合成员返回 true,如果member 不是集合成员返回 false + */ + List smIsMember(final String key, final String... members); + + /** + * 检查给定的 member 是不是特定集合的成员 + * + *

详情说明 https://www.redis.com.cn/commands/smismember.html

+ * + * @param key + * Key + * @param members + * 成员列表 + * + * @return 命令中member 出现的顺序,返回是否是集合成员的判断; + * 如果 member 是集合成员返回 true,如果member 不是集合成员返回 false + */ + List smIsMember(final byte[] key, final byte[]... members); + + /** + * 获取集合 key 中的所有成员 + * + *

详情说明 http://redisdoc.com/set/smembers.html

+ * + * @param key + * Key + * + * @return 集合中的所有成员 + */ + Set sMembers(final String key); + + /** + * 获取集合 key 中的所有成员 + * + *

详情说明 http://redisdoc.com/set/smembers.html

+ * + * @param key + * Key + * + * @return 集合中的所有成员 + */ + Set sMembers(final byte[] key); + + /** + * 将 member 元素从 source 集合移动到 destKey 集合 中 + * + *

详情说明 http://redisdoc.com/set/smove.html

+ * + * @param source + * Key + * @param destKey + * 目标 Key + * @param member + * member 元素 + * + * @return 如果 member 元素被成功移除,则返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status sMove(final String source, final String destKey, final String member); + + /** + * 将 member 元素从 source 集合移动到 destKey 集合 中 + * + *

详情说明 http://redisdoc.com/set/smove.html

+ * + * @param source + * Key + * @param destKey + * 目标 Key + * @param member + * member 元素 + * + * @return 如果 member 元素被成功移除,则返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status sMove(final byte[] source, final byte[] destKey, final byte[] member); + + /** + * 移除并返回集合 key 中的一个随机元素 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * + * @return 被移除的随机元素 + */ + String sPop(final String key); + + /** + * 移除并返回集合 key 中的一个随机元素 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * + * @return 被移除的随机元素 + */ + byte[] sPop(final byte[] key); + + /** + * 移除并返回集合 key 中的 count 个随机元素 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * @param count + * 返回删除元素个数 + * + * @return 被移除的随机元素 + */ + Set sPop(final String key, final int count); + + /** + * 移除并返回集合 key 中的 count 个随机元素 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * @param count + * 返回删除元素个数 + * + * @return 被移除的随机元素 + */ + Set sPop(final byte[] key, final int count); + + /** + * 返回集合 key 中的一个随机元素 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * + * @return 集合 key 中的一个随机元素 + */ + String sRandMember(final String key); + + /** + * 返回集合 key 中的一个随机元素 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * + * @return 集合 key 中的一个随机元素 + */ + byte[] sRandMember(final byte[] key); + + /** + * 返回集合 key 中的 count 个随机元素 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * + * @return 集合 key 中的随机元素 + */ + List sRandMember(final String key, final int count); + + /** + * 返回集合 key 中的 count 个随机元素 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * + * @return 集合 key 中的随机元素 + */ + List sRandMember(final byte[] key, final int count); + + /** + * 移除集合 key 中的一个或多个 member 元素,不存在的 member 元素会被忽略 + * + *

详情说明 http://redisdoc.com/set/srem.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素 + * + * @return 被成功移除的元素的数量,不包括被忽略的元素 + */ + Long sRem(final String key, final String... members); + + /** + * 移除集合 key 中的一个或多个 member 元素,不存在的 member 元素会被忽略 + * + *

详情说明 http://redisdoc.com/set/srem.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素 + * + * @return 被成功移除的元素的数量,不包括被忽略的元素 + */ + Long sRem(final byte[] key, final byte[]... members); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * + * @return 每个元素都是一个集合成员 + */ + ScanResult> sScan(final String key, final long cursor); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * + * @return 每个元素都是一个集合成员 + */ + ScanResult> sScan(final byte[] key, final long cursor); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * + * @return 每个元素都是一个集合成员 + */ + ScanResult> sScan(final String key, final String cursor); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * + * @return 每个元素都是一个集合成员 + */ + ScanResult> sScan(final byte[] key, final byte[] cursor); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * + * @return 返回和给定模式相匹配的元素 + */ + ScanResult> sScan(final String key, final long cursor, final String pattern); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * + * @return 返回和给定模式相匹配的元素 + */ + ScanResult> sScan(final byte[] key, final long cursor, final byte[] pattern); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * + * @return 返回和给定模式相匹配的元素 + */ + ScanResult> sScan(final String key, final String cursor, final String pattern); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * + * @return 返回和给定模式相匹配的元素 + */ + ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * + * @return 返回的指定数量的键值对 + */ + ScanResult> sScan(final String key, final long cursor, final int count); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * + * @return 返回的指定数量的键值对 + */ + ScanResult> sScan(final byte[] key, final long cursor, final int count); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * + * @return 返回的指定数量的键值对 + */ + ScanResult> sScan(final String key, final String cursor, final int count); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * + * @return 返回的指定数量的键值对 + */ + ScanResult> sScan(final byte[] key, final byte[] cursor, final int count); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * + * @return 返回和给定模式相匹配指定数量的元素 + */ + ScanResult> sScan(final String key, final long cursor, final String pattern, final int count); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * + * @return 返回和给定模式相匹配指定数量的元素 + */ + ScanResult> sScan(final byte[] key, final long cursor, final byte[] pattern, final int count); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * + * @return 返回和给定模式相匹配指定数量的元素 + */ + ScanResult> sScan(final String key, final String cursor, final String pattern, final int count); + + /** + * 迭代集合键中的元素 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * + * @return 返回和给定模式相匹配指定数量的元素 + */ + ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern, final int count); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的并集 + * + *

详情说明 http://redisdoc.com/set/sunion.html

+ * + * @param keys + * 一个或多个 Key + * + * @return 并集成员的列表 + */ + Set sUnion(final String... keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的并集 + * + *

详情说明 http://redisdoc.com/set/sunion.html

+ * + * @param keys + * 一个或多个 Key + * + * @return 并集成员的列表 + */ + Set sUnion(final byte[]... keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的并集,并保存到 destKey 中 + * + *

详情说明 http://redisdoc.com/set/sunionstorehtml

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * + * @return 结果集中的元素数量 + */ + Long sUnionStore(final String destKey, final String... keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的并集,并保存到 destKey 中 + * + *

详情说明 http://redisdoc.com/set/sunionstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * + * @return 结果集中的元素数量 + */ + Long sUnionStore(final byte[] destKey, final byte[]... keys); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/SortedSetCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/SortedSetCommands.java new file mode 100644 index 000000000..aa9b8d8a1 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/SortedSetCommands.java @@ -0,0 +1,2989 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.KeyValue; +import com.buession.redis.core.Aggregate; +import com.buession.redis.core.GtLt; +import com.buession.redis.core.NxXx; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; +import com.buession.redis.core.ZRangeBy; + +import java.util.List; +import java.util.Map; + +/** + * 有序集合命令 + * + *

详情说明 http://redisdoc.com/sorted_set/index.html

+ * + * @author Yong.Teng + */ +public interface SortedSetCommands extends RedisCommands { + + /** + * 删除并返回有序集合 key 中的 1 个具有最低得分的成员。 + * + *

详情说明 https://www.redis.com.cn/commands/zpopmin.html

+ * + * @param key + * 弹出的元素和分数列表 + * + * @return 弹出的元素和分数列表 + */ + Tuple zPopMin(final String key); + + /** + * 删除并返回有序集合 key 中的 1 个具有最低得分的成员。 + * + *

详情说明 https://www.redis.com.cn/commands/zpopmin.html

+ * + * @param key + * 弹出的元素和分数列表 + * + * @return 弹出的元素和分数列表 + */ + Tuple zPopMin(final byte[] key); + + /** + * 删除并返回有序集合 key 中的 count 个具有最低得分的成员。 + * + *

详情说明 https://www.redis.com.cn/commands/zpopmin.html

+ * + * @param key + * 弹出的元素和分数列表 + * @param count + * 删除个数 + * + * @return 弹出的元素和分数列表 + */ + List zPopMin(final String key, final int count); + + /** + * 删除并返回有序集合 key 中的 count 个具有最低得分的成员。 + * + *

详情说明 https://www.redis.com.cn/commands/zpopmin.html

+ * + * @param key + * 弹出的元素和分数列表 + * @param count + * 删除个数 + * + * @return 弹出的元素和分数列表 + */ + List zPopMin(final byte[] key, final int count); + + /** + * 删除并返回有序集合 key 中的 1 个具有最高得分的成员。 + * + * @param key + * 弹出的元素和分数列表 + * + * @return 弹出的元素和分数列表 + */ + Tuple zPopMax(final String key); + + /** + * 删除并返回有序集合 key 中的 1 个具有最高得分的成员。 + * + * @param key + * 弹出的元素和分数列表 + * + * @return 弹出的元素和分数列表 + */ + Tuple zPopMax(final byte[] key); + + /** + * 删除并返回有序集合 key 中的 count 个具有最高得分的成员。 + * + * @param key + * 弹出的元素和分数列表 + * @param count + * 删除个数 + * + * @return 弹出的元素和分数列表 + */ + List zPopMax(final String key, final int count); + + /** + * 删除并返回有序集合 key 中的 count 个具有最高得分的成员。 + * + * @param key + * 弹出的元素和分数列表 + * @param count + * 删除个数 + * + * @return 弹出的元素和分数列表 + */ + List zPopMax(final byte[] key, final int count); + + /** + * 从非空的第一个有序集中弹出得分最小的成员,按照命令中 key 出现的顺序检查;是有序集 ZPOPMIN 的阻塞变体; + * 当没有成员可以从任何给定的有序集中弹出时,它会阻塞连接 + * + *

详情说明 https://www.redis.com.cn/commands/bzpopmin.html

+ * + * @param keys + * 一个或多个 Key + * @param timeout + * 阻塞的最长时间;为 0 时,则无限期地阻塞,单位:秒 + * + * @return 元素 key 名称,成员名称,元素分数 + */ + KeyValue bzPopMin(final String[] keys, final int timeout); + + /** + * 从非空的第一个有序集中弹出得分最小的成员,按照命令中 key 出现的顺序检查;是有序集 ZPOPMIN 的阻塞变体; + * 当没有成员可以从任何给定的有序集中弹出时,它会阻塞连接 + * + *

详情说明 https://www.redis.com.cn/commands/bzpopmin.html

+ * + * @param keys + * 一个或多个 Key + * @param timeout + * 阻塞的最长时间;为 0 时,则无限期地阻塞,单位:秒 + * + * @return 元素 key 名称,成员名称,元素分数 + */ + KeyValue bzPopMin(final byte[][] keys, final int timeout); + + /** + * 从非空的第一个有序集中弹出得分最高的成员,按照命令中 key 出现的顺序检查;是有序集 ZPOPMAX 的阻塞变体; + * 当没有成员可以从任何给定的有序集中弹出时,它会阻塞连接 + * + *

详情说明 https://www.redis.com.cn/commands/bzpopmax.html

+ * + * @param keys + * 一个或多个 Key + * @param timeout + * 阻塞的最长时间;为 0 时,则无限期地阻塞,单位:秒 + * + * @return 元素 key 名称,成员名称,元素分数 + */ + KeyValue bzPopMax(final String[] keys, final int timeout); + + /** + * 从非空的第一个有序集中弹出得分最高的成员,按照命令中 key 出现的顺序检查;是有序集 ZPOPMAX 的阻塞变体; + * 当没有成员可以从任何给定的有序集中弹出时,它会阻塞连接 + * + *

详情说明 https://www.redis.com.cn/commands/bzpopmax.html

+ * + * @param keys + * 一个或多个 Key + * @param timeout + * 阻塞的最长时间;为 0 时,则无限期地阻塞,单位:秒 + * + * @return 元素 key 名称,成员名称,元素分数 + */ + KeyValue bzPopMax(final byte[][] keys, final int timeout); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final Map members); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final Map members); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final Map members, final NxXx nxXx); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 http://redisdoc.com/sorted_set/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final Map members, final NxXx nxXx); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final Map members, final GtLt gtLt); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 http://redisdoc.com/sorted_set/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final Map members, final GtLt gtLt); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final Map members, final boolean ch); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 http://redisdoc.com/sorted_set/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final Map members, final boolean ch); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 http://redisdoc.com/sorted_set/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 http://redisdoc.com/sorted_set/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 http://redisdoc.com/sorted_set/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt, final boolean ch); + + /** + * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 http://redisdoc.com/sorted_set/zadd.html

+ * + * @param key + * Key + * @param members + * 一个或多个 member 元素及其 score + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt, final boolean ch); + + /** + * 获取有序集 key 的基数 + * + *

详情说明 http://redisdoc.com/sorted_set/zcard.html

+ * + * @param key + * Key + * + * @return 有序集 key 的基数 + */ + Long zCard(final String key); + + /** + * 获取有序集 key 的基数 + * + *

详情说明 http://redisdoc.com/sorted_set/zcard.html

+ * + * @param key + * Key + * + * @return 有序集 key 的基数 + */ + Long zCard(final byte[] key); + + /** + * 获取有序集 key 中,score 值在 min 和 max 之间(包括 score 值等于 min 或 max )的成员的数量 + * + *

详情说明 http://redisdoc.com/sorted_set/zcount.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return score 值在 min 和 max 之间的成员的数量 + */ + Long zCount(final String key, final double min, final double max); + + /** + * 获取有序集 key 中,score 值在 min 和 max 之间(包括 score 值等于 min 或 max )的成员的数量 + * + *

详情说明 http://redisdoc.com/sorted_set/zcount.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return score 值在 min 和 max 之间的成员的数量 + */ + Long zCount(final byte[] key, final double min, final double max); + + /** + * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client + * + *

详情说明 https://redis.io/commands/zdiff/

+ * + * @param keys + * 一个或多个 Key + * + * @return The result of the difference + */ + List zDiff(final String... keys); + + /** + * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client + * + *

详情说明 https://redis.io/commands/zdiff/

+ * + * @param keys + * 一个或多个 Key + * + * @return The result of the difference + */ + List zDiff(final byte[]... keys); + + /** + * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client + * + *

详情说明 https://redis.io/commands/zdiff/

+ * + * @param keys + * 一个或多个 Key + * + * @return The result of the difference with their scores + */ + List zDiffWithScores(final String... keys); + + /** + * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client + * + *

详情说明 https://redis.io/commands/zdiff/

+ * + * @param keys + * 一个或多个 Key + * + * @return The result of the difference with their scores + */ + List zDiffWithScores(final byte[]... keys); + + /** + * Computes the difference between the first and all successive input sorted sets and stores the result in destination + * + *

详情说明 https://redis.io/commands/zdiffstore/

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * + * @return 结果集中的元素数量 + */ + Long zDiffStore(final String destKey, final String... keys); + + /** + * Computes the difference between the first and all successive input sorted sets and stores the result in destination + * + *

详情说明 https://redis.io/commands/zdiffstore/

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * + * @return 结果集中的元素数量 + */ + Long zDiffStore(final byte[] destKey, final byte[]... keys); + + /** + * 为有序集 key 的成员 member 的 score 值加上增量 increment + * + *

详情说明 http://redisdoc.com/sorted_set/zincrby.html

+ * + * @param key + * Key + * @param increment + * 增量 + * @param member + * member 元素 + * + * @return member 成员的新 score 值 + */ + Double zIncrBy(final String key, final double increment, final String member); + + /** + * 为有序集 key 的成员 member 的 score 值加上增量 increment + * + *

详情说明 http://redisdoc.com/sorted_set/zincrby.html

+ * + * @param key + * Key + * @param increment + * 增量 + * @param member + * member 元素 + * + * @return member 成员的新 score 值 + */ + Double zIncrBy(final byte[] key, final double increment, final byte[] member); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * + * @return 有序集合的交集 + */ + List zInter(final String... keys); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * + * @return 有序集合的交集 + */ + List zInter(final byte[]... keys); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * + * @return 有序集合的交集 + */ + List zInter(final String[] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * + * @return 有序集合的交集 + */ + List zInter(final byte[][] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 有序集合的交集 + */ + List zInter(final String[] keys, final double... weights); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 有序集合的交集 + */ + List zInter(final byte[][] keys, final double... weights); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 有序集合的交集 + */ + List zInter(final String[] keys, final Aggregate aggregate, final double... weights); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 有序集合的交集 + */ + List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * + * @return 含 scores 的有序集合的交集 + */ + List zInterWithScores(final String... keys); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * + * @return 含 scores 的有序集合的交集 + */ + List zInterWithScores(final byte[]... keys); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * + * @return 含 scores 的有序集合的交集 + */ + List zInterWithScores(final String[] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * + * @return 含 scores 的有序集合的交集 + */ + List zInterWithScores(final byte[][] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 含 scores 的有序集合的交集 + */ + List zInterWithScores(final String[] keys, final double... weights); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 含 scores 的有序集合的交集 + */ + List zInterWithScores(final byte[][] keys, final double... weights); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 含 scores 的有序集合的交集 + */ + List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights); + + /** + * 计算给定的一个或多个有序集合的交集 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 含 scores 的有序集合的交集 + */ + List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights); + + /** + * 计算给定的一个或多个有序集的交集,并将该交集储存到 destKey 中 + * + *

详情说明 http://redisdoc.com/sorted_set/zinterstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * + * @return 保存到 destKey 结果集的基数 + */ + Long zInterStore(final String destKey, final String... keys); + + /** + * 计算给定的一个或多个有序集的交集,并将该交集储存到 destKey 中 + * + *

详情说明 http://redisdoc.com/sorted_set/zinterstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * + * @return 保存到 destKey 结果集的基数 + */ + Long zInterStore(final byte[] destKey, final byte[]... keys); + + /** + * 计算给定的一个或多个有序集的交集,并将该交集储存到 destKey 中 + * + *

详情说明 http://redisdoc.com/sorted_set/zinterstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * + * @return 保存到 destKey 结果集的基数 + */ + Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集的交集,并将该交集储存到 destKey 中 + * + *

详情说明 http://redisdoc.com/sorted_set/zinterstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * + * @return 保存到 destKey 结果集的基数 + */ + Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集的交集,并将该交集储存到 destKey 中 + * + *

详情说明 http://redisdoc.com/sorted_set/zinterstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 保存到 destKey 结果集的基数 + */ + Long zInterStore(final String destKey, final String[] keys, final double... weights); + + /** + * 计算给定的一个或多个有序集的交集,并将该交集储存到 destKey 中 + * + *

详情说明 http://redisdoc.com/sorted_set/zinterstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 保存到 destKey 结果集的基数 + */ + Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights); + + /** + * 计算给定的一个或多个有序集的交集,并将该交集储存到 destKey 中 + * + *

详情说明 http://redisdoc.com/sorted_set/zinterstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 保存到 destKey 结果集的基数 + */ + Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate, final double... weights); + + /** + * 计算给定的一个或多个有序集的交集,并将该交集储存到 destKey 中 + * + *

详情说明 http://redisdoc.com/sorted_set/zinterstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 保存到 destKey 结果集的基数 + */ + Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, final double... weights); + + /** + * 获取集合 Key 中,成员介于 min 和 max 范围内的元素数量 + * + *

详情说明 http://redisdoc.com/sorted_set/zlexcount.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 集合 Key 中,成员介于 min 和 max 范围内的元素数量 + */ + Long zLexCount(final String key, final double min, final double max); + + /** + * 获取集合 Key 中,成员介于 min 和 max 范围内的元素数量 + * + *

详情说明 http://redisdoc.com/sorted_set/zlexcount.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 集合 Key 中,成员介于 min 和 max 范围内的元素数量 + */ + Long zLexCount(final byte[] key, final double min, final double max); + + /** + * 返回有序集中指定成员的 members 的 scores + * + *

详情说明 https://www.redis.com.cn/commands/zmscore.html

+ * + * @param key + * Key + * @param members + * 成员 + * + * @return 有序集中指定成员的 members 的 scores + */ + List zMScore(final String key, final String... members); + + /** + * 返回有序集中指定成员的 members 的 scores + * + *

详情说明 https://www.redis.com.cn/commands/zmscore.html

+ * + * @param key + * Key + * @param members + * 成员 + * + * @return 有序集中指定成员的 members 的 scores + */ + List zMScore(final byte[] key, final byte[]... members); + + /** + * 返回有序集合 key 中的一个随机元素 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * + * @return 有序集合 key 中的一个随机元素 + */ + String zRandMember(final String key); + + /** + * 返回有序集合 key 中的一个随机元素 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * + * @return 有序集合 key 中的一个随机元素 + */ + byte[] zRandMember(final byte[] key); + + /** + * 返回有序集合 key 中的 count 个随机元素 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * + * @return 有序集合 key 中的随机元素 + */ + List zRandMember(final String key, final int count); + + /** + * 返回有序集合 key 中的 count 个随机元素 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * + * @return 有序集合 key 中的随机元素 + */ + List zRandMember(final byte[] key, final int count); + + /** + * 返回有序集合 key 中的 count 个随机元素及 score + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * + * @return 有序集合 key 中的随机元素 + */ + List zRandMemberWithScores(final String key, final int count); + + /** + * 返回有序集合 key 中的 count 个随机元素及 score + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * + * @return 有序集合 key 中的随机元素 + */ + List zRandMemberWithScores(final byte[] key, final int count); + + /** + * 获取有序集 key 中,指定区间内的成员;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 指定区间内,有序集成员的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRange(final String key, final long start, final long end); + + /** + * 获取有序集 key 中,指定区间内的成员;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 指定区间内,有序集成员的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRange(final byte[] key, final long start, final long end); + + /** + * 获取有序集 key 中,指定区间内的带有 score 成员;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 指定区间内,带有 score 有序集成员的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRangeWithScores(final String key, final long start, final long end); + + /** + * 获取有序集 key 中,指定区间内的带有 score 成员;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 指定区间内,带有 score 有序集成员的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRangeWithScores(final byte[] key, final long start, final long end); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 包含了有序集合在指定范围内的成员的列表 + */ + List zRangeByLex(final String key, final double min, final double max); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 包含了有序集合在指定范围内的成员的列表 + */ + List zRangeByLex(final byte[] key, final double min, final double max); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的从 offset 开始的 count 个成员 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return 包含了有序集合在指定范围内从 offset 开始的 count 个成员的列表 + */ + List zRangeByLex(final String key, final double min, final double max, final long offset, final int count); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的从 offset 开始的 count 个成员 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return 包含了有序集合在指定范围内从 offset 开始的 count 个成员的列表 + */ + List zRangeByLex(final byte[] key, final double min, final double max, final long offset, final int count); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 指定区间内,有序集成员的列表 + */ + List zRangeByScore(final String key, final double min, final double max); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 指定区间内,有序集成员的列表 + */ + List zRangeByScore(final byte[] key, final double min, final double max); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )从 offset 开始的 count 个成员; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return 指定区间内从 offset 开是的 count 个,有序集成员的列表 + */ + List zRangeByScore(final String key, final double min, final double max, final long offset, + final int count); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )从 offset 开始的 count 个成员; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return 指定区间内从 offset 开是的 count 个,有序集成员的列表 + */ + List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count); + + /** + * 获取有序集 key 中,带有 score 的所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 指定区间内,带有 score 的有序集成员的列表 + */ + List zRangeByScoreWithScores(final String key, final double min, final double max); + + /** + * 获取有序集 key 中,带有 score 的所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 指定区间内,带有 score 的有序集成员的列表 + */ + List zRangeByScoreWithScores(final byte[] key, final double min, final double max); + + /** + * 获取有序集 key 中,带有 score 的所有 score 值介于 min 和 max 之间(包括等于 min 或 max )从 offset 开始的 count 个成员; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return 指定区间内带有 score 的从 offset 开是的 count 个,有序集成员的列表 + */ + List zRangeByScoreWithScores(final String key, final double min, final double max, final long offset, + final int count); + + /** + * 获取有序集 key 中,带有 score 的所有 score 值介于 min 和 max 之间(包括等于 min 或 max )从 offset 开始的 count 个成员; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return 指定区间内带有 score 的从 offset 开是的 count 个,有序集成员的列表 + */ + List zRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, + final int count); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final String destKey, final String key, final long start, final long end); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param by + * {@link ZRangeBy} + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param by + * {@link ZRangeBy} + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param rev + * The REV options reverses the order of the 'start' and 'end' elements + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param rev + * The REV options reverses the order of the 'start' and 'end' elements + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final String destKey, final String key, final long start, final long end, final long offset, + final int count); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final long offset, + final int count); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param by + * {@link ZRangeBy} + * @param rev + * The REV options reverses the order of the 'start' and 'end' elements + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, + final boolean rev); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param by + * {@link ZRangeBy} + * @param rev + * The REV options reverses the order of the 'start' and 'end' elements + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, + final boolean rev); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param by + * {@link ZRangeBy} + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, + final long offset, final int count); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param by + * {@link ZRangeBy} + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, + final long offset, final int count); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param rev + * The REV options reverses the order of the 'start' and 'end' elements + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev, + final long offset, final int count); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param rev + * The REV options reverses the order of the 'start' and 'end' elements + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev, + final long offset, final int count); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param by + * {@link ZRangeBy} + * @param rev + * The REV options reverses the order of the 'start' and 'end' elements + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count); + + /** + * 获取有序集 key 中,指定区间内的成员,并保存到 destKey 中;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + * @param destKey + * 目标 Key + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param by + * {@link ZRangeBy} + * @param rev + * The REV options reverses the order of the 'start' and 'end' elements + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return The number of elements in the resulting sorted set + */ + Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final int count); + + /** + * 获取有序集 key 中成员 member 的排名;其中有序集成员按 score 值递增(从小到大)顺序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrank.html

+ * + * @param key + * Key + * @param member + * member + * + * @return 如果 member 是有序集 key 的成员,返回 member 的排名; + * 如果 member 不是有序集 key 的成员,返回 null + */ + Long zRank(final String key, final String member); + + /** + * 获取有序集 key 中成员 member 的排名;其中有序集成员按 score 值递增(从小到大)顺序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrank.html

+ * + * @param key + * Key + * @param member + * member + * + * @return 如果 member 是有序集 key 的成员,返回 member 的排名; + * 如果 member 不是有序集 key 的成员,返回 null + */ + Long zRank(final byte[] key, final byte[] member); + + /** + * 移除有序集 key 中的一个或多个成员,不存在的成员将被忽略 + * + *

详情说明 http://redisdoc.com/sorted_set/zrem.html

+ * + * @param key + * Key + * @param members + * 一个或多个成员 + * + * @return 被成功移除的成员的数量,不包括被忽略的成员 + */ + Long zRem(final String key, final String... members); + + /** + * 移除有序集 key 中的一个或多个成员,不存在的成员将被忽略 + * + *

详情说明 http://redisdoccom/sorted_set/zrem.html

+ * + * @param key + * Key + * @param members + * 一个或多个成员 + * + * @return 被成功移除的成员的数量,不包括被忽略的成员 + */ + Long zRem(final byte[] key, final byte[]... members); + + /** + * 对于一个所有成员的分值都相同的有序集合键 key 来说,这个命令会移除该集合中,成员介于 min 和 max 范围内的所有元素 + * + *

详情说明 http://redisdoc.com/sorted_set/zremrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 被移除的元素数量 + */ + Long zRemRangeByLex(final String key, final double min, final double max); + + /** + * 对于一个所有成员的分值都相同的有序集合键 key 来说,这个命令会移除该集合中,成员介于 min 和 max 范围内的所有元素 + * + *

详情说明 http://redisdoc.com/sorted_set/zremrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 被移除的元素数量 + */ + Long zRemRangeByLex(final byte[] key, final double min, final double max); + + /** + * 移除有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员 + * + *

详情说明 http://redisdoc.com/sorted_set/zremrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 被移除成员的数量 + */ + Long zRemRangeByScore(final String key, final double min, final double max); + + /** + * 移除有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员 + * + *

详情说明 http://redisdoc.com/sorted_set/zremrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 被移除成员的数量 + */ + Long zRemRangeByScore(final byte[] key, final double min, final double max); + + /** + * 移除有序集 key 中,指定排名(rank)区间内的所有成员; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zremrangebyrank.html

+ * + * @param key + * Key + * @param start + * 开始排名 + * @param end + * 结束排名 + * + * @return 被移除成员的数量 + */ + Long zRemRangeByRank(final String key, final long start, final long end); + + /** + * 移除有序集 key 中,指定排名(rank)区间内的所有成员; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zremrangebyrank.html

+ * + * @param key + * Key + * @param start + * 开始排名 + * @param end + * 结束排名 + * + * @return 被移除成员的数量 + */ + Long zRemRangeByRank(final byte[] key, final long start, final long end); + + /** + * 获取有序集 key 中,指定区间内的成员;其中成员的位置按 score 值递减(从大到小)来排列; + * 具有相同 score 值的成员按字典序的逆序排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 指定区间内,有序集成员的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRevRange(final String key, final long start, final long end); + + /** + * 获取有序集 key 中,指定区间内的成员;其中成员的位置按 score 值递减(从大到小)来排列; + * 具有相同 score 值的成员按字典序的逆序排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 指定区间内,有序集成员的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRevRange(final byte[] key, final long start, final long end); + + /** + * 获取有序集 key 中,带有 score 指定区间内的成员;其中成员的位置按 score 值递减(从大到小)来排列; + * 具有相同 score 值的成员按字典序的逆序排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 指定区间内,有序集成员的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRevRangeWithScores(final String key, final long start, final long end); + + /** + * 获取有序集 key 中,带有 score 指定区间内的成员;其中成员的位置按 score 值递减(从大到小)来排列; + * 具有相同 score 值的成员按字典序的逆序排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 指定区间内,有序集成员的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRevRangeWithScores(final byte[] key, final long start, final long end); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 包含了有序集合在指定范围内的成员列表 + */ + List zRevRangeByLex(final String key, final double min, final double max); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 包含了有序集合在指定范围内的成员列表 + */ + List zRevRangeByLex(final byte[] key, final double min, final double max); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间从 offset 开始的 count 个成员 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return 包含了有序集合在指定范围内的成员列表 + */ + List zRevRangeByLex(final String key, final double min, final double max, final long offset, + final int count); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间从 offset 开始的 count 个成员 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * + * @return 包含了有序集合在指定范围内的成员列表 + */ + List zRevRangeByLex(final byte[] key, final double min, final double max, final long offset, + final int count); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的所有的成员; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 指定区间内,有序集成员的列表 + */ + List zRevRangeByScore(final String key, final double min, final double max); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的所有的成员; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 指定区间内,有序集成员的列表 + */ + List zRevRangeByScore(final byte[] key, final double min, final double max); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )从 offset 开始的 count 个成员; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回数量 + * + * @return 指定区间内,有序集成员的列表 + */ + List zRevRangeByScore(final String key, final double min, final double max, final long offset, + final int count); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )从 offset 开始的 count 个成员; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回数量 + * + * @return 指定区间内,有序集成员的列表 + */ + List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final int count); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的带有 score 的所有的成员; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 指定区间内,有序集成员的列表 + */ + List zRevRangeByScoreWithScores(final String key, final double min, final double max); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的带有 score 的所有的成员; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * + * @return 指定区间内,有序集成员的列表 + */ + List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )从 offset 开始的 count 个带有 score 的成员; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回数量 + * + * @return 指定区间内,有序集成员的列表 + */ + List zRevRangeByScoreWithScores(final String key, final double min, final double max, final long offset, + final int count); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )从 offset 开始的 count 个带有 score 的成员; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回数量 + * + * @return 指定区间内,有序集成员的列表 + */ + List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, + final int count); + + /** + * 获取有序集 key 中成员 member 的排名。其中有序集成员按 score 值递减(从大到小)排序 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrank.html

+ * + * @param key + * Key + * @param member + * member + * + * @return 如果 member 是有序集 key 的成员,返回 member 的排名; + * 如果 member 不是有序集 key 的成员,返回 null + */ + Long zRevRank(final String key, final String member); + + /** + * 获取有序集 key 中成员 member 的排名。其中有序集成员按 score 值递减(从大到小)排序 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrank.html

+ * + * @param key + * Key + * @param member + * member + * + * @return 如果 member 是有序集 key 的成员,返回 member 的排名; + * 如果 member 不是有序集 key 的成员,返回 null + */ + Long zRevRank(final byte[] key, final byte[] member); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> zScan(final String key, final long cursor); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> zScan(final byte[] key, final long cursor); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> zScan(final String key, final String cursor); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> zScan(final byte[] key, final byte[] cursor); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * + * @return 返回和给定模式相匹配的元素 + */ + ScanResult> zScan(final String key, final long cursor, final String pattern); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * + * @return 返回和给定模式相匹配的元素 + */ + ScanResult> zScan(final byte[] key, final long cursor, final byte[] pattern); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * + * @return 返回和给定模式相匹配的元素 + */ + ScanResult> zScan(final String key, final String cursor, final String pattern); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * + * @return 返回和给定模式相匹配的元素 + */ + ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * + * @return 返回的指定数量的键值对 + */ + ScanResult> zScan(final String key, final long cursor, final int count); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * + * @return 返回的指定数量的键值对 + */ + ScanResult> zScan(final byte[] key, final long cursor, final int count); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * + * @return 返回的指定数量的键值对 + */ + ScanResult> zScan(final String key, final String cursor, final int count); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * + * @return 返回的指定数量的键值对 + */ + ScanResult> zScan(final byte[] key, final byte[] cursor, final int count); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * + * @return 返回和给定模式相匹配指定数量的元素 + */ + ScanResult> zScan(final String key, final long cursor, final String pattern, final int count); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * + * @return 返回和给定模式相匹配指定数量的元素 + */ + ScanResult> zScan(final byte[] key, final long cursor, final byte[] pattern, final int count); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * + * @return 返回和给定模式相匹配指定数量的元素 + */ + ScanResult> zScan(final String key, final String cursor, final String pattern, final int count); + + /** + * 迭代有序集 key 中的键值对 + * + *

详情说明 http://redisdoc.com/sorted_set/zscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * + * @return 返回和给定模式相匹配指定数量的元素 + */ + ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, final int count); + + /** + * 获取有序集 key 中,成员 member 的 score 值 + * + *

详情说明 http://redisdoc.com/sorted_set/zscore.html

+ * + * @param key + * Key + * @param member + * member + * + * @return member 成员的 score 值 + */ + Double zScore(final String key, final String member); + + /** + * 获取有序集 key 中,成员 member 的 score 值 + * + *

详情说明 http://redisdoc.com/sorted_set/zscore.html

+ * + * @param key + * Key + * @param member + * member + * + * @return member 成员的 score 值 + */ + Double zScore(final byte[] key, final byte[] member); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * + * @return 集合的并集 + */ + List zUnion(final String... keys); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * + * @return 集合的并集 + */ + List zUnion(final byte[]... keys); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * + * @return 集合的并集 + */ + List zUnion(final String[] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * + * @return 集合的并集 + */ + List zUnion(final byte[][] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 集合的并集 + */ + List zUnion(final String[] keys, final double... weights); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 集合的并集 + */ + List zUnion(final byte[][] keys, final double... weights); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 集合的并集 + */ + List zUnion(final String[] keys, final Aggregate aggregate, final double... weights); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 集合的并集 + */ + List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * + * @return 带有分数的集合的并集 + */ + List zUnionWithScores(final String... keys); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * + * @return 带有分数的集合的并集 + */ + List zUnionWithScores(final byte[]... keys); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * + * @return 带有分数的集合的并集 + */ + List zUnionWithScores(final String[] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * + * @return 带有分数的集合的并集 + */ + List zUnionWithScores(final byte[][] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 带有分数的集合的并集 + */ + List zUnionWithScores(final String[] keys, final double... weights); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 带有分数的集合的并集 + */ + List zUnionWithScores(final byte[][] keys, final double... weights); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 带有分数的集合的并集 + */ + List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights); + + /** + * 计算给定的一个或多个有序集的并集 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 带有分数的集合的并集 + */ + List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights); + + /** + * 计算给定的一个或多个有序集的并集,并将该并集储存到 destKey + * + *

详情说明 http://redisdoc.com/sorted_set/zunionstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * + * @return 保存到 destKey 的结果集的基数 + */ + Long zUnionStore(final String destKey, final String... keys); + + /** + * 计算给定的一个或多个有序集的并集,并将该并集储存到 destKey + * + *

详情说明 http://redisdoc.com/sorted_set/zunionstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * + * @return 保存到 destKey 的结果集的基数 + */ + Long zUnionStore(final byte[] destKey, final byte[]... keys); + + /** + * 计算给定的一个或多个有序集的并集,并将该并集储存到 destKey + * + *

详情说明 http://redisdoc.com/sorted_set/zunionstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * + * @return 保存到 destKey 的结果集的基数 + */ + Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集的并集,并将该并集储存到 destKey + * + *

详情说明 http://redisdoc.com/sorted_set/zunionstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * + * @return 保存到 destKey 的结果集的基数 + */ + Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集的并集,并将该并集储存到 destKey + * + *

详情说明 http://redisdoc.com/sorted_set/zunionstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 保存到 destKey 的结果集的基数 + */ + Long zUnionStore(final String destKey, final String[] keys, final double... weights); + + /** + * 计算给定的一个或多个有序集的并集,并将该并集储存到 destKey + * + *

详情说明 http://redisdoc.com/sorted_set/zunionstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 保存到 destKey 的结果集的基数 + */ + Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights); + + /** + * 计算给定的一个或多个有序集的并集,并将该并集储存到 destKey + * + *

详情说明 http://redisdoc.com/sorted_set/zunionstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 保存到 destKey 的结果集的基数 + */ + Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate, final double... weights); + + /** + * 计算给定的一个或多个有序集的并集,并将该并集储存到 destKey + * + *

详情说明 http://redisdoc.com/sorted_set/zunionstore.html

+ * + * @param destKey + * 目标 Key + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param weights + * 每个给定有序集的乘法因子 + * + * @return 保存到 destKey 的结果集的基数 + */ + Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, final double... weights); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/StreamCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/StreamCommands.java new file mode 100644 index 000000000..9d95b657d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/StreamCommands.java @@ -0,0 +1,1583 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.Status; +import com.buession.redis.core.Stream; +import com.buession.redis.core.StreamConsumer; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import com.buession.redis.core.StreamGroup; +import com.buession.redis.core.StreamPending; +import com.buession.redis.core.StreamPendingSummary; +import com.buession.redis.core.command.args.XAddArgument; +import com.buession.redis.core.command.args.XClaimArgument; +import com.buession.redis.core.command.args.XReadArgument; +import com.buession.redis.core.command.args.XReadGroupArgument; +import com.buession.redis.core.command.args.XTrimArgument; + +import java.util.List; +import java.util.Map; + +/** + * Stream 命令 + * + *

详情说明 https://redis.io/commands/?group=stream

+ * + * @author Yong.Teng + * @since 2.0.0 + */ +public interface StreamCommands extends RedisCommands { + + /** + * The XACK command removes one or multiple messages from the Pending Entries List (PEL) of a stream consumer group + * + *

详情说明 https://redis.io/commands/xack/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param ids + * 一个或多个 ID + * + * @return The command returns the number of messages successfully acknowledged + */ + Long xAck(final String key, final String groupName, final StreamEntryId... ids); + + /** + * The XACK command removes one or multiple messages from the Pending Entries List (PEL) of a stream consumer group + * + *

详情说明 https://redis.io/commands/xack/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param ids + * 一个或多个 ID + * + * @return The command returns the number of messages successfully acknowledged + */ + Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId... ids); + + /** + * Appends the specified stream entry to the stream at the specified key. + * If the key does not exist, as a side effect of running this command the key is created with a stream value + * + *

详情说明 https://redis.io/commands/xadd/

+ * + * @param key + * Key + * @param id + * Id + * @param hash + * Hash + * + * @return {@link StreamEntryId} + */ + StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash); + + /** + * Appends the specified stream entry to the stream at the specified key. + * If the key does not exist, as a side effect of running this command the key is created with a stream value + * + *

详情说明 https://redis.io/commands/xadd/

+ * + * @param key + * Key + * @param id + * Id + * @param hash + * Hash + * + * @return {@link StreamEntryId} + */ + StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash); + + /** + * Appends the specified stream entry to the stream at the specified key. + * If the key does not exist, as a side effect of running this command the key is created with a stream value + * + *

详情说明 https://redis.io/commands/xadd/

+ * + * @param key + * Key + * @param id + * Id + * @param hash + * Hash + * @param xAddArgument + * {@link XAddArgument} + * + * @return {@link StreamEntryId} + */ + StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument); + + /** + * Appends the specified stream entry to the stream at the specified key. + * If the key does not exist, as a side effect of running this command the key is created with a stream value + * + *

详情说明 https://redis.io/commands/xadd/

+ * + * @param key + * Key + * @param id + * Id + * @param hash + * Hash + * @param xAddArgument + * {@link XAddArgument} + * + * @return {@link StreamEntryId} + */ + StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument); + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntry} + */ + Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start); + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntry} + */ + Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start); + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * @param count + * 数量 + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntry} + */ + Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count); + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * @param count + * 数量 + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntry} + */ + Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, + final int count); + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntryId} + */ + Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start); + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntryId} + */ + Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start); + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * @param count + * 数量 + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntryId} + */ + Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final int count); + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * @param count + * 数量 + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntryId} + */ + Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final int count); + + /** + * In the context of a stream consumer group, this command changes the ownership of a pending message, + * so that the new owner is the consumer specified as the command argument + * + *

详情说明 https://redis.io/commands/xclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param ids + * 一个或多个 ID + * + * @return {@link StreamEntry} 列表 + */ + List xClaim(final String key, final String groupName, final String consumerName, final int minIdleTime, + final StreamEntryId... ids); + + /** + * In the context of a stream consumer group, this command changes the ownership of a pending message, + * so that the new owner is the consumer specified as the command argument + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param ids + * 一个或多个 ID + * + * @return {@link StreamEntry} 列表 + */ + List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, + final StreamEntryId... ids); + + /** + * In the context of a stream consumer group, this command changes the ownership of a pending message, + * so that the new owner is the consumer specified as the command argument + * + *

详情说明 https://redis.io/commands/xclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param ids + * 一个或多个 ID + * @param xClaimArgument + * {@link XClaimArgument} + * + * @return {@link StreamEntry} 列表 + */ + List xClaim(final String key, final String groupName, final String consumerName, final int minIdleTime, + final StreamEntryId[] ids, final XClaimArgument xClaimArgument); + + /** + * In the context of a stream consumer group, this command changes the ownership of a pending message, + * so that the new owner is the consumer specified as the command argument + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param ids + * 一个或多个 ID + * @param xClaimArgument + * {@link XClaimArgument} + * + * @return {@link StreamEntry} 列表 + */ + List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, + final StreamEntryId[] ids, final XClaimArgument xClaimArgument); + + /** + * In the context of a stream consumer group, this command changes the ownership of a pending message, + * so that the new owner is the consumer specified as the command argument + * + *

详情说明 https://redis.io/commands/xclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param ids + * 一个或多个 ID + * + * @return {@link StreamEntryId} 列表 + */ + List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId... ids); + + /** + * In the context of a stream consumer group, this command changes the ownership of a pending message, + * so that the new owner is the consumer specified as the command argument + * + *

详情说明 https://redis.io/commands/xclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param ids + * 一个或多个 ID + * + * @return {@link StreamEntryId} 列表 + */ + List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids); + + /** + * In the context of a stream consumer group, this command changes the ownership of a pending message, + * so that the new owner is the consumer specified as the command argument + * + *

详情说明 https://redis.io/commands/xclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param ids + * 一个或多个 ID + * @param xClaimArgument + * {@link XClaimArgument} + * + * @return {@link StreamEntryId} 列表 + */ + List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument); + + /** + * In the context of a stream consumer group, this command changes the ownership of a pending message, + * so that the new owner is the consumer specified as the command argument + * + *

详情说明 https://redis.io/commands/xclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param ids + * 一个或多个 ID + * @param xClaimArgument + * {@link XClaimArgument} + * + * @return {@link StreamEntryId} 列表 + */ + List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument); + + /** + * Removes the specified entries from a stream, and returns the number of entries deleted + * + *

详情说明 https://redis.io/commands/xdel/

+ * + * @param key + * Key + * @param ids + * 一个或多个 ID + * + * @return The number of entries actually deleted + */ + Long xDel(final String key, final StreamEntryId... ids); + + /** + * Removes the specified entries from a stream, and returns the number of entries deleted + * + *

详情说明 https://redis.io/commands/xdel/

+ * + * @param key + * Key + * @param ids + * 一个或多个 ID + * + * @return The number of entries actually deleted + */ + Long xDel(final byte[] key, final StreamEntryId... ids); + + /** + * This command creates a new consumer group uniquely identified by groupname for the stream stored at key + * + *

详情说明 https://redis.io/commands/xgroup-create/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param id + * ID + * @param makeStream + * Can use the optional MKSTREAM subcommand as the last argument after the id to automatically create the stream (with length of 0) + * + * @return 创建成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status xGroupCreate(final String key, final String groupName, final StreamEntryId id, final boolean makeStream); + + /** + * This command creates a new consumer group uniquely identified by groupname for the stream stored at key + * + *

详情说明 https://redis.io/commands/xgroup-create/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param id + * ID + * @param makeStream + * Can use the optional MKSTREAM subcommand as the last argument after the id to automatically create the stream (with length of 0) + * + * @return 创建成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status xGroupCreate(final byte[] key, final byte[] groupName, final StreamEntryId id, final boolean makeStream); + + /** + * Create a consumer named consumername in the consumer group groupname of the stream that's stored at key + * + *

详情说明 https://redis.io/commands/xgroup-createconsumer/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * + * @return 创建成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName); + + /** + * Create a consumer named consumername in the consumer group groupname of the stream that's stored at key + * + *

详情说明 https://redis.io/commands/xgroup-createconsumer/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * + * @return 创建成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName); + + /** + * The XGROUP DELCONSUMER command deletes a consumer from the consumer group + * + *

详情说明 https://redis.io/commands/xgroup-delconsumer/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * + * @return 删除数量 + */ + Long xGroupDelConsumer(final String key, final String groupName, final String consumerName); + + /** + * The XGROUP DELCONSUMER command deletes a consumer from the consumer group + * + *

详情说明 https://redis.io/commands/xgroup-delconsumer/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * + * @return 删除数量 + */ + Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName); + + /** + * The XGROUP DESTROY command completely destroys a consumer group + * + *

详情说明 https://redis.io/commands/xgroup-destroy/

+ * + * @param key + * Key + * @param groupName + * Group Name + * + * @return 销毁成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status xGroupDestroy(final String key, final String groupName); + + /** + * The XGROUP DESTROY command completely destroys a consumer group + * + *

详情说明 https://redis.io/commands/xgroup-destroy/

+ * + * @param key + * Key + * @param groupName + * Group Name + * + * @return 销毁成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status xGroupDestroy(final byte[] key, final byte[] groupName); + + /** + * Normally, a consumer group's last delivered ID is set when the group is created with XGROUP CREATE + * + *

详情说明 https://redis.io/commands/xgroup-setid/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param id + * ID + * + * @return 销毁成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status xGroupSetId(final String key, final String groupName, final StreamEntryId id); + + /** + * Normally, a consumer group's last delivered ID is set when the group is created with XGROUP CREATE + * + *

详情说明 https://redis.io/commands/xgroup-setid/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param id + * ID + * + * @return 销毁成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + Status xGroupSetId(final byte[] key, final byte[] groupName, final StreamEntryId id); + + /** + * This command returns the list of consumers that belong to the groupname consumer group of the stream stored at key + * + *

详情说明 https://redis.io/commands/xinfo-consumers/

+ * + * @param key + * Key + * @param groupName + * Group Name + * + * @return {@link StreamConsumer} 列表 + */ + List xInfoConsumers(final String key, final String groupName); + + /** + * This command returns the list of consumers that belong to the groupname consumer group of the stream stored at key + * + *

详情说明 https://redis.io/commands/xinfo-consumers/

+ * + * @param key + * Key + * @param groupName + * Group Name + * + * @return {@link StreamConsumer} 列表 + */ + List xInfoConsumers(final byte[] key, final byte[] groupName); + + /** + * This command returns the list of all consumers groups of the stream stored at key + * + *

详情说明 https://redis.io/commands/xinfo-groups/

+ * + * @param key + * Key + * + * @return {@link StreamGroup} 列表 + */ + List xInfoGroups(final String key); + + /** + * This command returns the list of all consumers groups of the stream stored at key + * + *

详情说明 https://redis.io/commands/xinfo-groups/

+ * + * @param key + * Key + * + * @return {@link StreamGroup} 列表 + */ + List xInfoGroups(final byte[] key); + + /** + * This command returns information about the stream stored at key + * + *

详情说明 https://redis.io/commands/xinfo-stream/

+ * + * @param key + * Key + * + * @return {@link Stream} + */ + Stream xInfoStream(final String key); + + /** + * This command returns information about the stream stored at key + * + *

详情说明 https://redis.io/commands/xinfo-stream/

+ * + * @param key + * Key + * + * @return {@link Stream} + */ + Stream xInfoStream(final byte[] key); + + /** + * This command returns information about the stream stored at key + * + *

详情说明 https://redis.io/commands/xinfo-stream/

+ * + * @param key + * Key + * @param full + * Full + * + * @return {@link StreamFull} + */ + StreamFull xInfoStream(final String key, final boolean full); + + /** + * This command returns information about the stream stored at key + * + *

详情说明 https://redis.io/commands/xinfo-stream/

+ * + * @param key + * Key + * @param full + * Full + * + * @return {@link StreamFull} + */ + StreamFull xInfoStream(final byte[] key, final boolean full); + + /** + * This command returns information about the stream stored at key + * + *

详情说明 https://redis.io/commands/xinfo-stream/

+ * + * @param key + * Key + * @param full + * Full + * @param count + * 返回数量 + * + * @return {@link StreamFull} + */ + StreamFull xInfoStream(final String key, final boolean full, final int count); + + /** + * This command returns information about the stream stored at key + * + *

详情说明 https://redis.io/commands/xinfo-stream/

+ * + * @param key + * Key + * @param full + * Full + * @param count + * 返回数量 + * + * @return {@link StreamFull} + */ + StreamFull xInfoStream(final byte[] key, final boolean full, final int count); + + /** + * Returns the number of entries inside a stream + * + *

详情说明 https://redis.io/commands/xlen/

+ * + * @param key + * Key + * + * @return The number of entries of the stream at key + */ + Long xLen(final String key); + + /** + * Returns the number of entries inside a stream + * + *

详情说明 https://redis.io/commands/xlen/

+ * + * @param key + * Key + * + * @return The number of entries of the stream at key + */ + Long xLen(final byte[] key); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * + * @return {@link StreamPendingSummary} + */ + StreamPendingSummary xPending(final String key, final String groupName); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * + * @return {@link StreamPendingSummary} + */ + StreamPendingSummary xPending(final byte[] key, final byte[] groupName); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param minIdleTime + * Min Idle Time + * + * @return {@link StreamPending} 列表 + */ + List xPending(final String key, final String groupName, final long minIdleTime); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param minIdleTime + * Min Idle Time + * + * @return {@link StreamPending} 列表 + */ + List xPending(final byte[] key, final byte[] groupName, final long minIdleTime); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * + * @return {@link StreamPending} 列表 + */ + List xPending(final String key, final String groupName, final StreamEntryId start, + final StreamEntryId end, final int count); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * + * @return {@link StreamPending} 列表 + */ + List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final int count); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * + * @return {@link StreamPending} 列表 + */ + List xPending(final String key, final String groupName, final String consumerName); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * + * @return {@link StreamPending} 列表 + */ + List xPending(final byte[] key, final byte[] groupName, final byte[] consumerName); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param minIdleTime + * Min Idle Time + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * + * @return {@link StreamPending} 列表 + */ + List xPending(final String key, final String groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param minIdleTime + * Min Idle Time + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * + * @return {@link StreamPending} 列表 + */ + List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param minIdleTime + * Min Idle Time + * @param consumerName + * Consumer Name + * + * @return {@link StreamPending} 列表 + */ + List xPending(final String key, final String groupName, final long minIdleTime, + final String consumerName); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param minIdleTime + * Min Idle Time + * @param consumerName + * Consumer Name + * + * @return {@link StreamPending} 列表 + */ + List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final byte[] consumerName); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * @param consumerName + * Consumer Name + * + * @return {@link StreamPending} 列表 + */ + List xPending(final String key, final String groupName, final StreamEntryId start, + final StreamEntryId end, final int count, final String consumerName); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * @param consumerName + * Consumer Name + * + * @return {@link StreamPending} 列表 + */ + List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final int count, final byte[] consumerName); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param minIdleTime + * Min Idle Time + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * @param consumerName + * Consumer Name + * + * @return {@link StreamPending} 列表 + */ + List xPending(final String key, final String groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count, + final String consumerName); + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param minIdleTime + * Min Idle Time + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * @param consumerName + * Consumer Name + * + * @return {@link StreamPending} 列表 + */ + List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final int count, + final byte[] consumerName); + + /** + * The command returns the stream entries matching a given range of IDs + * + *

详情说明 https://redis.io/commands/xrange/

+ * + * @param key + * Key + * @param start + * Start Id + * @param end + * End Id + * + * @return {@link StreamEntry} 列表 + */ + List xRange(final String key, final StreamEntryId start, final StreamEntryId end); + + /** + * The command returns the stream entries matching a given range of IDs + * + *

详情说明 https://redis.io/commands/xrange/

+ * + * @param key + * Key + * @param start + * Start Id + * @param end + * End Id + * + * @return {@link StreamEntry} 列表 + */ + List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end); + + /** + * The command returns the stream entries matching a given range of IDs + * + *

详情说明 https://redis.io/commands/xrange/

+ * + * @param key + * Key + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * + * @return {@link StreamEntry} 列表 + */ + List xRange(final String key, final StreamEntryId start, final StreamEntryId end, final int count); + + /** + * The command returns the stream entries matching a given range of IDs + * + *

详情说明 https://redis.io/commands/xrange/

+ * + * @param key + * Key + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * + * @return {@link StreamEntry} 列表 + */ + List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end, final int count); + + /** + * Read data from one or multiple streams, only returning entries with an ID greater than the last received ID reported by the caller + * + *

详情说明 https://redis.io/commands/xread/

+ * + * @param streams + * key => StreamEntryId Streams + * + * @return {@link StreamEntry} 列表 + */ + List>> xRead(final Map streams); + + /** + * Read data from one or multiple streams, only returning entries with an ID greater than the last received ID reported by the caller + * + *

详情说明 https://redis.io/commands/xread/

+ * + * @param streams + * key => StreamEntryId Streams + * @param xReadArgument + * 读取参数 + * + * @return {@link StreamEntry} 列表 + */ + List>> xRead(final Map streams, + final XReadArgument xReadArgument); + + /** + * The XREADGROUP command is a special version of the XREAD command with support for consumer groups + * + *

详情说明 https://redis.io/commands/xreadgroup/

+ * + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param streams + * key => StreamEntryId Streams + * + * @return {@link StreamEntry} 列表 + */ + List>> xReadGroup(final String groupName, final String consumerName, + final Map streams); + + /** + * The XREADGROUP command is a special version of the XREAD command with support for consumer groups + * + *

详情说明 https://redis.io/commands/xreadgroup/

+ * + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param streams + * key => StreamEntryId Streams + * + * @return {@link StreamEntry} 列表 + */ + List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams); + + /** + * The XREADGROUP command is a special version of the XREAD command with support for consumer groups + * + *

详情说明 https://redis.io/commands/xreadgroup/

+ * + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param streams + * key => StreamEntryId Streams + * @param xReadGroupArgument + * 读取参数 + * + * @return {@link StreamEntry} 列表 + */ + List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadGroupArgument xReadGroupArgument); + + /** + * The XREADGROUP command is a special version of the XREAD command with support for consumer groups + * + *

详情说明 https://redis.io/commands/xreadgroup/

+ * + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param streams + * key => StreamEntryId Streams + * @param xReadGroupArgument + * 读取参数 + * + * @return {@link StreamEntry} 列表 + */ + List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final XReadGroupArgument xReadGroupArgument); + + /** + * The XREADGROUP command is a special version of the XREAD command with support for consumer groups + * + *

详情说明 https://redis.io/commands/xreadgroup/

+ * + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param isNoAck + * No Ack + * @param streams + * key => StreamEntryId Streams + * + * @return {@link StreamEntry} 列表 + */ + List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, final Map streams); + + /** + * The XREADGROUP command is a special version of the XREAD command with support for consumer groups + * + *

详情说明 https://redis.io/commands/xreadgroup/

+ * + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param isNoAck + * No Ack + * @param streams + * key => StreamEntryId Streams + * + * @return {@link StreamEntry} 列表 + */ + List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final boolean isNoAck, final Map streams); + + /** + * The XREADGROUP command is a special version of the XREAD command with support for consumer groups + * + *

详情说明 https://redis.io/commands/xreadgroup/

+ * + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param isNoAck + * No Ack + * @param streams + * key => StreamEntryId Streams + * @param xReadGroupArgument + * 读取参数 + * + * @return {@link StreamEntry} 列表 + */ + List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, final Map streams, + final XReadGroupArgument xReadGroupArgument); + + /** + * The XREADGROUP command is a special version of the XREAD command with support for consumer groups + * + *

详情说明 https://redis.io/commands/xreadgroup/

+ * + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param isNoAck + * No Ack + * @param streams + * key => StreamEntryId Streams + * @param xReadGroupArgument + * 读取参数 + * + * @return {@link StreamEntry} 列表 + */ + List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final boolean isNoAck, final Map streams, + final XReadGroupArgument xReadGroupArgument); + + /** + * This command is exactly like XRANGE, but with the notable difference of returning the entries in reverse order, + * and also taking the start-end range in reverse order: in XREVRANGE you need to state the end ID and later the start ID, + * and the command will produce all the element between (or exactly like) the two IDs, starting from the end side + * + *

详情说明 https://redis.io/commands/xrevrange/

+ * + * @param key + * Key + * @param end + * End Id + * @param start + * Start Id + * + * @return {@link StreamEntry} 列表 + */ + List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start); + + /** + * This command is exactly like XRANGE, but with the notable difference of returning the entries in reverse order, + * and also taking the start-end range in reverse order: in XREVRANGE you need to state the end ID and later the start ID, + * and the command will produce all the element between (or exactly like) the two IDs, starting from the end side + * + *

详情说明 https://redis.io/commands/xrevrange/

+ * + * @param key + * Key + * @param end + * End Id + * @param start + * Start Id + * + * @return {@link StreamEntry} 列表 + */ + List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start); + + /** + * This command is exactly like XRANGE, but with the notable difference of returning the entries in reverse order, + * and also taking the start-end range in reverse order: in XREVRANGE you need to state the end ID and later the start ID, + * and the command will produce all the element between (or exactly like) the two IDs, starting from the end side + * + *

详情说明 https://redis.io/commands/xrevrange/

+ * + * @param key + * Key + * @param end + * End Id + * @param start + * Start Id + * @param count + * 返回数量 + * + * @return {@link StreamEntry} 列表 + */ + List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start, final int count); + + /** + * This command is exactly like XRANGE, but with the notable difference of returning the entries in reverse order, + * and also taking the start-end range in reverse order: in XREVRANGE you need to state the end ID and later the start ID, + * and the command will produce all the element between (or exactly like) the two IDs, starting from the end side + * + *

详情说明 https://redis.io/commands/xrevrange/

+ * + * @param key + * Key + * @param end + * End Id + * @param start + * Start Id + * @param count + * 返回数量 + * + * @return {@link StreamEntry} 列表 + */ + List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start, final int count); + + /** + * XTRIM trims the stream by evicting older entries (entries with lower IDs) if needed + * + *

详情说明 https://redis.io/commands/xtrim/

+ * + * @param key + * Key + * @param xTrimArgument + * {@link XTrimArgument} + * + * @return The number of entries deleted from the stream. + */ + Long xTrim(final String key, final XTrimArgument xTrimArgument); + + /** + * XTRIM trims the stream by evicting older entries (entries with lower IDs) if needed + * + *

详情说明 https://redis.io/commands/xtrim/

+ * + * @param key + * Key + * @param xTrimArgument + * {@link XTrimArgument} + * + * @return The number of entries deleted from the stream. + */ + Long xTrim(final byte[] key, final XTrimArgument xTrimArgument); + + /** + * XTRIM trims the stream by evicting older entries (entries with lower IDs) if needed + * + *

详情说明 https://redis.io/commands/xtrim/

+ * + * @param key + * Key + * @param xTrimArgument + * {@link XTrimArgument} + * @param limit + * Limit + * + * @return The number of entries deleted from the stream. + */ + Long xTrim(final String key, final XTrimArgument xTrimArgument, final long limit); + + /** + * XTRIM trims the stream by evicting older entries (entries with lower IDs) if needed + * + *

详情说明 https://redis.io/commands/xtrim/

+ * + * @param key + * Key + * @param xTrimArgument + * {@link XTrimArgument} + * @param limit + * Limit + * + * @return The number of entries deleted from the stream. + */ + Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/StringCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/StringCommands.java new file mode 100644 index 000000000..c560750fb --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/StringCommands.java @@ -0,0 +1,642 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.Status; +import com.buession.redis.core.command.args.GetExArgument; +import com.buession.redis.core.command.args.SetArgument; + +import java.util.List; +import java.util.Map; + +/** + * 字符串命令 + * + *

详情说明 http://redisdoc.com/string/index.html

+ * + * @author Yong.Teng + */ +public interface StringCommands extends RedisCommands { + + /** + * 如果键 key 已经存在并且它的值是一个字符串,将 value 追加到键 key 现有值的末尾 + * + *

详情说明 http://redisdoc.com/string/append.html

+ * + * @param key + * Key + * @param value + * 值 + * + * @return 追加 value 之后 键 key 的值的长度 + */ + Long append(final String key, final String value); + + /** + * 如果键 key 已经存在并且它的值是一个字符串,将 value 追加到键 key 现有值的末尾 + * + *

详情说明 http://redisdoc.com/string/append.html

+ * + * @param key + * Key + * @param value + * 值 + * + * @return 追加 value 之后 键 key 的值的长度 + */ + Long append(final byte[] key, final byte[] value); + + /** + * 为键 key 储存的数字值加上一 + * + *

详情说明 http://redisdoc.com/string/incr.html

+ * + * @param key + * Key + * + * @return 键 key 在执行加一操作之后的值 + */ + Long incr(final String key); + + /** + * 为键 key 储存的数字值加上一 + * + *

详情说明 http://redisdoc.com/string/incr + * .html

+ * + * @param key + * Key + * + * @return 键 key 在执行加一操作之后的值 + */ + Long incr(final byte[] key); + + /** + * 为键 key 储存的数字值加上增量 increment + * + *

详情说明 http://redisdoc.com/string/incrby.html

+ * + * @param key + * Key + * @param value + * 值 + * + * @return 键 key 增量 increment 之后的值 + */ + Long incrBy(final String key, final long value); + + /** + * 为键 key 储存的数字值加上增量 increment + * + *

详情说明 http://redisdoc.com/string/incrby.html

+ * + * @param key + * Key + * @param value + * 值 + * + * @return 键 key 增量 increment 之后的值 + */ + Long incrBy(final byte[] key, final long value); + + /** + * 为键 key 储存的值加上浮点数增量 increment + * + *

详情说明 http://redisdoc.com/string/incrbyfloat.html

+ * + * @param key + * Key + * @param value + * 值 + * + * @return 键 key 增量 increment 之后的值 + */ + Double incrByFloat(final String key, final double value); + + /** + * 为键 key 储存的值加上浮点数增量 increment + * + *

详情说明 http://redisdoc.com/string/incrbyfloat.html

+ * + * @param key + * Key + * @param value + * 值 + * + * @return 键 key 增量 increment 之后的值 + */ + Double incrByFloat(final byte[] key, final double value); + + /** + * 键 key 储存的数字值减去一 + * + *

详情说明 http://redisdoc.com/string/decr.html

+ * + * @param key + * Key + * + * @return 键 key 在执行减一操作之后的值 + */ + Long decr(final String key); + + /** + * 键 key 储存的数字值减去一 + * + *

详情说明 http://redisdoc.com/string/decr.html

+ * + * @param key + * Key + * + * @return 键 key 在执行减一操作之后的值 + */ + Long decr(final byte[] key); + + /** + * 将键 key 储存的整数值减去减量 decrement + * + *

详情说明 http://redisdoc.com/string/decrby.html

+ * + * @param key + * Key + * @param value + * 值 + * + * @return 键 key 减量 increment 之后的值 + */ + Long decrBy(final String key, final long value); + + /** + * 将键 key 储存的整数值减去减量 decrement + * + *

详情说明 http://redisdoc.com/string/decrby.html

+ * + * @param key + * Key + * @param value + * 值 + * + * @return 键 key 减量 increment 之后的值 + */ + Long decrBy(final byte[] key, final long value); + + /** + * 获取键 key 相关联的字符串值 + * + *

详情说明 http://redisdoc.com/string/get.html

+ * + * @param key + * Key + * + * @return 如果键 key 不存在,那么返回特殊值 null ;否则,返回键 key 的值; + * 如果键 key 的值并非字符串类型,那么抛出异常 + */ + String get(final String key); + + /** + * 获取键 key 相关联的字符串值 + * + *

详情说明 http://redisdoc.com/string/get.html

+ * + * @param key + * Key + * + * @return 如果键 key 不存在,那么返回特殊值 null ;否则,返回键 key 的值; + * 如果键 key 的值并非字符串类型,那么抛出异常 + */ + byte[] get(final byte[] key); + + /** + * 获取键 key 的值,并重置 key 的过期时间 + * + *

详情说明 https://redis.io/commands/getex/

+ * + * @param key + * Key + * @param getExArgument + * Key 过期时间参数 + * + * @return 键 key 的值 + */ + String getEx(final String key, final GetExArgument getExArgument); + + /** + * 获取键 key 的值,并重置 key 的过期时间 + * + *

详情说明 https://redis.io/commands/getex/

+ * + * @param key + * Key + * @param getExArgument + * Key 过期时间参数 + * + * @return 键 key 的值 + */ + byte[] getEx(final byte[] key, final GetExArgument getExArgument); + + /** + * 将键 key 的值设为 value ,并返回键 key 在被设置之前的旧值 + * + *

详情说明 http://redisdoc.com/string/getset.html

+ * + * @param key + * Key + * @param value + * 新值 + * + * @return 键 key 的旧值 + */ + String getSet(final String key, final String value); + + /** + * 将键 key 的值设为 value ,并返回键 key 在被设置之前的旧值 + * + *

详情说明 http://redisdoc.com/string/getset.html

+ * + * @param key + * Key + * @param value + * 新值 + * + * @return 键 key 的旧值 + */ + byte[] getSet(final byte[] key, final byte[] value); + + /** + * 获取键 key 的值,并删除 key + * + *

详情说明 https://redis.io/commands/getdel/

+ * + * @param key + * Key + * + * @return 键 key 的值 + */ + String getDel(final String key); + + /** + * 获取键 key 的值,并重置 key 的过期时间 + * + *

详情说明 https://redis.io/commands/getdel/

+ * + * @param key + * Key + * + * @return 键 key 的值 + */ + byte[] getDel(final byte[] key); + + /** + * 获取给定的一个或多个字符串键的值 + * + *

详情说明 http://redisdoc.com/string/mget.html

+ * + * @param keys + * 一个或多个 key + * + * @return 返回一个列表,列表中包含了所有给定键的值;如果给定键不存在 那么这个键的值将以特殊值 null 表示 + */ + List mGet(final String... keys); + + /** + * 获取给定的一个或多个字符串键的值 + * + *

详情说明 http://redisdoc.com/string/mget.html

+ * + * @param keys + * 一个或多个 key + * + * @return 返回一个列表,列表中包含了所有给定键的值;如果给定键不存在 那么这个键的值将以特殊值 null 表示 + */ + List mGet(final byte[]... keys); + + /** + * 同时为多个键设置值,如果某个给定键已经存在 那么将使用新值去覆盖旧值 + * + *

详情说明 http://redisdoc.com/string/mset.html

+ * + * @param values + * 键值对 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status mSet(final Map values); + + /** + * 当且仅当所有给定键都不存在时,为所有给定键设置值 + * + *

详情说明 http://redisdoc.com/string/msetnx.html

+ * + * @param values + * 键值对 + * + * @return 当所有给定键都设置成功时,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status mSetNx(final Map values); + + /** + * 将键 key 的值设置为 value ,并将键 key 的生存时间设置为 lifetime; + * 如果键 key 已经存在,那么将覆盖已有的值 + * + *

详情说明 http://redisdoc.com/string/psetex.html

+ * + * @param key + * Key + * @param value + * 值 + * @param lifetime + * 生存时间(单秒:毫秒) + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status pSetEx(final String key, final String value, final int lifetime); + + /** + * 将键 key 的值设置为 value ,并将键 key 的生存时间设置为 lifetime; + * 如果键 key 已经存在,那么将覆盖已有的值 + * + *

详情说明 http://redisdoc.com/string/psetex.html

+ * + * @param key + * Key + * @param value + * 值 + * @param lifetime + * 生存时间(单秒:毫秒) + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status pSetEx(final byte[] key, final byte[] value, final int lifetime); + + /** + * 将字符串值 value 关联到 key; + * 如果 key 已经持有其他值,SET 就覆写旧值,忽略类型 + * + *

详情说明 http://redisdoc.com/string/set.html

+ * + * @param key + * Key + * @param value + * 值 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status set(final String key, final String value); + + /** + * 将字符串值 value 关联到 key; + * 如果 key 已经持有其他值,SET 就覆写旧值,忽略类型 + * + *

详情说明 http://redisdoc.com/string/set.html

+ * + * @param key + * Key + * @param value + * 值 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status set(final byte[] key, final byte[] value); + + /** + * 将字符串值 value 关联到 key; + * 如果 key 已经持有其他值,SET 就覆写旧值,忽略类型 + * + *

详情说明 http://redisdoc.com/string/set.html

+ * + * @param key + * Key + * @param value + * 值 + * @param setArgument + * 参数 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status set(final String key, final String value, final SetArgument setArgument); + + /** + * 将字符串值 value 关联到 key; + * 如果 key 已经持有其他值,SET 就覆写旧值,忽略类型 + * + *

详情说明 http://redisdoc.com/string/set.html

+ * + * @param key + * Key + * @param value + * 值 + * @param setArgument + * 参数 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status set(final byte[] key, final byte[] value, final SetArgument setArgument); + + /** + * 将键 key 的值设置为 value ,并将键 key 的生存时间设置为 lifetime; + * 如果键 key 已经存在,那么将覆盖已有的值 + * + *

详情说明 http://redisdoc.com/string/setex.html

+ * + * @param key + * Key + * @param value + * 值 + * @param lifetime + * 生存时间(单秒:秒) + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status setEx(final String key, final String value, final int lifetime); + + /** + * 将键 key 的值设置为 value ,并将键 key 的生存时间设置为 lifetime; + * 如果键 key 已经存在,那么将覆盖已有的值 + * + *

详情说明 http://redisdoc.com/string/setex.html

+ * + * @param key + * Key + * @param value + * 值 + * @param lifetime + * 生存时间(单秒:秒) + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status setEx(final byte[] key, final byte[] value, final int lifetime); + + /** + * 当键 key 不存在的情况下,将键 key 的值设置为 value + * + *

详情说明 http://redisdoc.com/string/setnx.html

+ * + * @param key + * Key + * @param value + * 值 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status setNx(final String key, final String value); + + /** + * 当键 key 不存在的情况下,将键 key 的值设置为 value + * + *

详情说明 http://redisdoc.com/string/setnx.html

+ * + * @param key + * Key + * @param value + * 值 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status setNx(final byte[] key, final byte[] value); + + /** + * 从偏移量 offset 开始,用 value 参数覆写键 key 储存的字符串值 + * + *

详情说明 http://redisdoc.com/string/setrange.html

+ * + * @param key + * Key + * @param offset + * 偏移量 + * @param value + * 值 + * + * @return 被修改之后,字符串值的长度 + */ + Long setRange(final String key, final long offset, final String value); + + /** + * 从偏移量 offset 开始,用 value 参数覆写键 key 储存的字符串值 + * + *

详情说明 http://redisdoc.com/string/setrange.html

+ * + * @param key + * Key + * @param offset + * 偏移量 + * @param value + * 值 + * + * @return 被修改之后,字符串值的长度 + */ + Long setRange(final byte[] key, final long offset, final byte[] value); + + /** + * 获取键 key 储存的字符串值的指定部分,字符串的截取范围由 start 和 end 两个偏移量决定 (包括 start 和 end 在内); + * 负数偏移量表示从字符串的末尾开始计数 -1 表示最后一个字符,-2 表示倒数第二个字符,以此类推 + * + *

详情说明 http://redisdoc.com/string/getrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 符串值的指定部分,通过保证子字符串的值域(range)不超过实际字符串的值域来处理超出范围的值域请求 + */ + String getRange(final String key, final long start, final long end); + + /** + * 获取键 key 储存的字符串值的指定部分,字符串的截取范围由 start 和 end 两个偏移量决定 (包括 start 和 end 在内); + * 负数偏移量表示从字符串的末尾开始计数 -1 表示最后一个字符,-2 表示倒数第二个字符,以此类推 + * + *

详情说明 http://redisdoc.com/string/getrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 符串值的指定部分,通过保证子字符串的值域(range)不超过实际字符串的值域来处理超出范围的值域请求 + */ + byte[] getRange(final byte[] key, final long start, final long end); + + /** + * 获取键 key 储存的字符串值的长度 + * + *

详情说明 http://redisdoc.com/string/strlen.html

+ * + * @param key + * Key + * + * @return 字符串值的长度;键 key 不存在时,命令返回 0 ;当 key 储存的不是字符串值时,抛出异常 + */ + Long strlen(final String key); + + /** + * 获取键 key 储存的字符串值的长度 + * + *

详情说明 http://redisdoc.com/string/strlen.html

+ * + * @param key + * Key + * + * @return 字符串值的长度;键 key 不存在时,命令返回 0 ;当 key 储存的不是字符串值时,抛出异常 + */ + Long strlen(final byte[] key); + + /** + * 获取键 key 储存的字符串值的指定部分,字符串的截取范围由 start 和 end 两个偏移量决定 (包括 start 和 end 在内); + * 负数偏移量表示从字符串的末尾开始计数 -1 表示最后一个字符,-2 表示倒数第二个字符,以此类推 + * + *

详情说明 http://redisdoc.com/string/substr.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 符串值的指定部分,通过保证子字符串的值域(range)不超过实际字符串的值域来处理超出范围的值域请求 + */ + String substr(final String key, final int start, final int end); + + /** + * 获取键 key 储存的字符串值的指定部分,字符串的截取范围由 start 和 end 两个偏移量决定 (包括 start 和 end 在内); + * 负数偏移量表示从字符串的末尾开始计数 -1 表示最后一个字符,-2 表示倒数第二个字符,以此类推 + * + *

详情说明 http://redisdoc.com/string/substr.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * + * @return 符串值的指定部分,通过保证子字符串的值域(range)不超过实际字符串的值域来处理超出范围的值域请求 + */ + byte[] substr(final byte[] key, final int start, final int end); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/SubCommand.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/SubCommand.java new file mode 100644 index 000000000..3f657fcfd --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/SubCommand.java @@ -0,0 +1,246 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.core.utils.StringUtils; +import com.buession.core.validator.Validate; +import com.buession.redis.utils.SafeEncoder; + +/** + * Redis 协议命令子命令 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public enum SubCommand implements ProtocolCommand { + /** + * Common command start + **/ + GET("r"), + + INFO("r"), + + LIST("r"), + + LOAD("r"), + + NODES("rw"), + + RESET("w"), + + SAVE("w"), + + SLAVES("r"), + /** + * Common command end + **/ + + /** + * Cluster command start + **/ + CLUSTER_ADDSLOTS("w"), + + CLUSTER_ADDSLOTSRANGE("w"), + + CLUSTER_BUMPEPOCH("r"), + + CLUSTER_COUNTFAILUREREPORTS("rw"), + + CLUSTER_COUNTKEYSINSLOT("r"), + + CLUSTER_DELSLOTS("w"), + + CLUSTER_DELSLOTSRANGE("w"), + + CLUSTER_FAILOVER("rw"), + + CLUSTER_FLUSHSLOTS("w"), + + CLUSTER_FORGET("w"), + + CLUSTER_GETKEYSINSLOT("r"), + + CLUSTER_KEYSLOT("r"), + + CLUSTER_LINKS("r"), + + CLUSTER_MEET("w"), + + CLUSTER_MYID("r"), + + CLUSTER_MYSHARDID("r"), + + CLUSTER_REPLICAS("rw"), + + CLUSTER_REPLICATE("rw"), + + CLUSTER_SAVECONFIG("rw"), + + CLUSTER_SETCONFIGEPOCH("rw"), + + CLUSTER_SETSLOT("w"), + + CLUSTER_SHARDS("r"), + + CLUSTER_SLOTS("r"), + /** + * Cluster command end + **/ + + /** + * Client command start + **/ + CLIENT_CACHING("r"), + + CLIENT_GETNAME("r"), + + CLIENT_GETREDIR("r"), + + CLIENT_ID("r"), + + CLIENT_INFO("r"), + + CLIENT_KILL("w"), + + CLIENT_LIST("r"), + + CLIENT_NO_EVICT("r"), + + CLIENT_NO_TOUCH("r"), + + CLIENT_PAUSE("w"), + + CLIENT_REPLY("w"), + + CLIENT_SETINFO("w"), + + CLIENT_SETNAME("w"), + + CLIENT_TRACKING("r"), + + CLIENT_TRACKINGINFO("r"), + + CLIENT_UNBLOCK("w"), + + CLIENT_UNPAUSE("w"), + /** + * Client command end + **/ + + /** + * Key command start + **/ + OBJECT_ENCODING("r"), + + OBJECT_REFQ("r"), + + OBJECT_IDLETIME("r"), + + OBJECT_REFCOUNT("r"), + /** + * Key command end + **/ + + /** + * ACL command start + **/ + ACL_CAT("r"), + + ACL_DELUSER("w"), + + ACL_DRYRUN("w"), + + ACL_GENPASS("r"), + + ACL_GETUSER("r"), + + ACL_LOG("rw"), + + ACL_SETUSER("w"), + + ACL_USERS("r"), + + ACL_WHOAMI("r"), + /** + * ACL command end + **/ + ; + + private final String name; + + private final byte[] raw; + + /** + * 是否为读操作命令 + */ + private final boolean read; + + /** + * 是否为写操作命令 + */ + private final boolean write; + + SubCommand(final String mode) { + String[] names = StringUtils.split(name(), "_", 2); + + name = names.length > 1 ? names[1] : name(); + + raw = SafeEncoder.encode(name); + if(Validate.hasText(mode)){ + String modeLower = mode.toLowerCase(); + this.read = modeLower.indexOf('r') > -1; + this.write = modeLower.indexOf('w') > -1; + }else{ + this.read = true; + this.write = false; + } + } + + @Override + public String getName() { + return name; + } + + @Override + public byte[] getRaw() { + return raw; + } + + @Override + public boolean isRead() { + return read; + } + + @Override + public boolean isWrite() { + return write; + } + + @Override + public String toString() { + return getName(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/TransactionCommands.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/TransactionCommands.java new file mode 100644 index 000000000..74e8567eb --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/TransactionCommands.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.Status; + +import java.util.List; + +/** + * 事务命令 + * + *

详情说明 http://redisdoc.com/transaction/index.html

+ * + * @author Yong.Teng + */ +public interface TransactionCommands extends RedisCommands { + + /** + * 标记事务开始 + * + *

详情说明 http://redisdoc.com/transaction/multi.html

+ * + * @return 开启事务状态 + */ + Status multi(); + + /** + * 执行所有事务块内的命令 + * + *

详情说明 http://redisdoc.com/transaction/exec.html

+ * + * @return 事务块内所有命令的返回值 + */ + List exec(); + + /** + * 取消事务,放弃执行事务块内的所有命令 + * + *

详情说明 http://redisdoc.com/transaction/discard.html

+ */ + void discard(); + + /** + * 监视一个或多个 key ,如果在事务执行之前这个或这些 key 被其他命令所改动,那么事务将被打断 + * + *

详情说明 http://redisdoc.com/transaction/watch.html

+ * + * @param keys + * 一个或多个 key + * + * @return 总是返回 Status.SUCCESS + */ + Status watch(final String... keys); + + /** + * 监视一个或多个 key ,如果在事务执行之前这个或这些 key 被其他命令所改动,那么事务将被打断 + * + *

详情说明 http://redisdoc.com/transaction/watch.html

+ * + * @param keys + * 一个或多个 key + * + * @return 总是返回 Status.SUCCESS + */ + Status watch(final byte[]... keys); + + /** + * 取消 WATCH 命令对所有 key 的监视; + * 如果在执行 WATCH 命令之后, EXEC 命令或 DISCARD 命令先被执行了的话,那么就不需要再执行 UNWATCH 了 + * + *

详情说明 http://redisdoc + * .com/transaction/unwatch.html

+ * + * @return 总是返回 Status.SUCCESS + */ + Status unwatch(); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/AclSetUserArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/AclSetUserArgument.java new file mode 100644 index 000000000..618eb8e24 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/AclSetUserArgument.java @@ -0,0 +1,688 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.core.utils.StringUtils; +import com.buession.redis.core.AclCategory; +import com.buession.redis.core.command.Command; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.command.SubCommand; +import com.buession.redis.utils.SafeEncoder; + +import java.util.ArrayList; +import java.util.List; + +/** + * {@code ACL SETUSER} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class AclSetUserArgument implements ArrayArgument { + + /** + * 参数列表 + */ + private final List arguments = new ArrayList<>(); + + /** + * 构造函数 + */ + public AclSetUserArgument() { + } + + /** + * Set user active. + * + * @return {@code this} + */ + public AclSetUserArgument on() { + return state(State.ON); + } + + /** + * Set user inactive. + * + * @return {@code this} + */ + public AclSetUserArgument off() { + return state(State.OFF); + } + + /** + * Set user active or inactive. + * + * @return {@code this} + */ + public AclSetUserArgument state(final State state) { + if(state != null){ + this.arguments.add(state); + } + + return this; + } + + /** + * Adds accessible key pattern. + * + * @param keyPattern + * accessible key pattern + * + * @return {@code this} + */ + public AclSetUserArgument keyPattern(final String keyPattern) { + this.arguments.add(new KeyPattern(keyPattern)); + return this; + } + + /** + * Allows the user to access all the keys. + * + * @return {@code this} + */ + public AclSetUserArgument allKeys() { + this.arguments.add(new AllKeys()); + return this; + } + + /** + * Removes all the key patterns from the list of key patterns the user can access. + * + * @return {@code this} + */ + public AclSetUserArgument resetKeys() { + this.arguments.add(new ResetKeys()); + return this; + } + + /** + * Adds accessible channel pattern. + * + * @param channelPattern + * accessible channel pattern + * + * @return {@code this} + */ + public AclSetUserArgument channelPattern(final String channelPattern) { + this.arguments.add(new ChannelPattern(channelPattern)); + return this; + } + + /** + * Allows the user to access all the Pub/Sub channels. + * + * @return {@code this} + */ + public AclSetUserArgument allChannels() { + this.arguments.add(new AllChannels()); + return this; + } + + /** + * Removes all channel patterns from the list of Pub/Sub channel patterns the user can access. + * + * @return {@code this} + */ + public AclSetUserArgument resetChannels() { + this.arguments.add(new ResetChannels()); + return this; + } + + /** + * Adds this command to the list of the commands the user can call. + * + * @param command + * accessible command + * + * @return {@code this} + */ + public AclSetUserArgument addCommand(final Command command) { + return addCommand(command, null); + } + + /** + * Adds this command to the list of the commands the user can call. + * + * @param command + * accessible command + * @param subCommand + * accessible subcommand + * + * @return {@code this} + */ + public AclSetUserArgument addCommand(final Command command, final SubCommand subCommand) { + this.arguments.add(new AddCommand(command, subCommand)); + return this; + } + + /** + * Adds all the commands there are in the server. + * + * @return {@code this} + */ + public AclSetUserArgument allCommands() { + this.arguments.add(new AllCommands()); + return this; + } + + /** + * Removes this command to the list of the commands the user can call. + * + * @param command + * inaccessible command + * + * @return {@code this} + */ + public AclSetUserArgument removeCommand(final Command command) { + return removeCommand(command, null); + } + + /** + * Removes the specified command to the list of the commands the user can execute. + * + * @param command + * inaccessible command + * @param subCommand + * inaccessible subcommand + * + * @return {@code this} + */ + public AclSetUserArgument removeCommand(final Command command, final SubCommand subCommand) { + this.arguments.add(new RemoveCommand(command, subCommand)); + return this; + } + + /** + * Removes all the commands the user can execute. + * + * @return {@code this} + */ + public AclSetUserArgument noCommands() { + this.arguments.add(new NoCommands()); + return this; + } + + /** + * Adds all the commands in the specified category to the list of commands the user is able to execute. + * + * @param category + * specified category + * + * @return {@code this} + */ + public AclSetUserArgument addCategory(final AclCategory category) { + this.arguments.add(new AddCategory(category)); + return this; + } + + /** + * Removes all the commands in the specified category to the list of commands the user is able to execute. + * + * @param category + * specified category + * + * @return {@code this} + */ + public AclSetUserArgument removeCategory(final AclCategory category) { + this.arguments.add(new RemoveCategory(category)); + return this; + } + + /** + * Sets the user as a "no password". + * + * @return {@code this} + */ + public AclSetUserArgument noPass() { + this.arguments.add(new NoPass()); + return this; + } + + /** + * Flushes the list of allowed passwords and removes the "no password" status. After resetting the password there is no way + * to authenticate as the user without adding some password (or setting it as {@link #noPass()} later). + * + * @return {@code this} + */ + public AclSetUserArgument resetPass() { + this.arguments.add(new ResetPass()); + return this; + } + + /** + * Adds the specified clear text password as an hashed password in the list of the users passwords. + * + * @param password + * clear text password + * + * @return {@code this} + */ + public AclSetUserArgument addPassword(final String password) { + this.arguments.add(new AddPassword(password)); + return this; + } + + /** + * Removes the specified clear text password as an hashed password in the list of the users passwords. + * + * @param password + * clear text password + * + * @return {@code this} + */ + public AclSetUserArgument removePassword(final String password) { + this.arguments.add(new RemovePassword(password)); + return this; + } + + /** + * Adds the specified hashed password to the list of user passwords. + * + * @param hashedPassword + * hashed password + * + * @return {@code this} + */ + public AclSetUserArgument addHashedPassword(final String hashedPassword) { + this.arguments.add(new AddHashedPassword(hashedPassword)); + return this; + } + + /** + * Removes the specified hashed password to the list of user passwords. + * + * @param hashedPassword + * hashed password + * + * @return {@code this} + */ + public AclSetUserArgument removeHashedPassword(final String hashedPassword) { + this.arguments.add(new RemoveHashedPassword(hashedPassword)); + return this; + } + + /** + * Removes any capability from the user. + * + * @return {@code this} + */ + public AclSetUserArgument reset() { + this.arguments.add(new Reset()); + return this; + } + + public List getArguments() { + return arguments; + } + + @Override + public String[] toArray() { + final String[] result = new String[arguments.size()]; + Argument argument; + + for(int i = 0, l = arguments.size(); i < l; i++){ + argument = arguments.get(i); + + if(argument instanceof State){ + result[i] = ((State) argument).name(); + }else{ + result[i] = argument.toString(); + } + } + + return result; + } + + @Override + public byte[][] toBinaryArray() { + final byte[][] result = new byte[arguments.size()][]; + Argument argument; + + for(int i = 0, l = arguments.size(); i < l; i++){ + argument = arguments.get(i); + + if(argument instanceof State){ + result[i] = SafeEncoder.encode(((State) argument).name()); + }else{ + result[i] = SafeEncoder.encode(argument.toString()); + } + } + + return result; + } + + @Override + public String toString() { + return StringUtils.join(arguments, " "); + } + + public interface Argument { + + } + + public enum State implements Argument { + ON, + + OFF + } + + public static abstract class StringArgument implements Argument { + + private final String value; + + public StringArgument(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + return getValue(); + } + + } + + public static abstract class ProtocolCommandArgument implements Argument { + + private final ProtocolCommand command; + + public ProtocolCommandArgument(final ProtocolCommand command) { + this.command = command; + } + + public ProtocolCommand getCommand() { + return command; + } + + @Override + public String toString() { + return getCommand().getName(); + } + + } + + public static abstract class CommandArgument implements Argument { + + private final Command command; + + private final SubCommand subCommand; + + public CommandArgument(final Command command) { + this(command, null); + } + + public CommandArgument(final Command command, final SubCommand subCommand) { + this.command = command; + this.subCommand = subCommand; + } + + public Command getCommand() { + return command; + } + + public SubCommand getSubCommand() { + return subCommand; + } + + @Override + public String toString() { + return subCommand == null ? command.getName() : command.getName() + "|" + subCommand; + } + + } + + public static abstract class AclCategoryArgument implements Argument { + + private final AclCategory aclCategory; + + AclCategoryArgument(final AclCategory aclCategory) { + this.aclCategory = aclCategory; + } + + public AclCategory getAclCategory() { + return aclCategory; + } + + @Override + public String toString() { + return aclCategory.name(); + } + + } + + public final static class KeyPattern extends StringArgument { + + KeyPattern(final String keyPattern) { + super(keyPattern); + } + + @Override + public String toString() { + return "~" + super.toString(); + } + + } + + public final static class ResetKeys extends StringArgument { + + ResetKeys() { + super("resetkeys"); + } + + } + + public final static class AllKeys extends StringArgument { + + AllKeys() { + super("allkeys"); + } + + } + + public final static class ChannelPattern extends StringArgument { + + ChannelPattern(final String channelPattern) { + super(channelPattern); + } + + @Override + public String toString() { + return "&" + super.toString(); + } + + } + + public final static class AllChannels extends StringArgument { + + AllChannels() { + super("allchannels"); + } + + } + + public final static class ResetChannels extends StringArgument { + + ResetChannels() { + super("resetchannels"); + } + + } + + public final static class AddCommand extends CommandArgument { + + AddCommand(final Command command) { + super(command); + } + + AddCommand(final Command command, final SubCommand subCommand) { + super(command, subCommand); + } + + @Override + public String toString() { + return "+" + super.toString(); + } + + } + + public final static class AllCommands extends StringArgument { + + AllCommands() { + super("allcommands"); + } + + } + + public final static class RemoveCommand extends CommandArgument { + + RemoveCommand(final Command command) { + super(command); + } + + RemoveCommand(final Command command, final SubCommand subCommand) { + super(command, subCommand); + } + + @Override + public String toString() { + return "-" + super.toString(); + } + + } + + public final static class NoCommands extends StringArgument { + + NoCommands() { + super("nocommands"); + } + + } + + public final static class AddCategory extends AclCategoryArgument { + + AddCategory(final AclCategory category) { + super(category); + } + + @Override + public String toString() { + return "+@" + super.toString(); + } + + } + + public final static class RemoveCategory extends AclCategoryArgument { + + RemoveCategory(final AclCategory category) { + super(category); + } + + @Override + public String toString() { + return "-@" + super.toString(); + } + + } + + public final static class NoPass extends StringArgument { + + NoPass() { + super("nopass"); + } + + } + + public final static class ResetPass extends StringArgument { + + ResetPass() { + super("resetpass"); + } + + } + + public final static class AddPassword extends StringArgument { + + AddPassword(String password) { + super(password); + } + + @Override + public String toString() { + return ">" + super.toString(); + } + + } + + public final static class RemovePassword extends StringArgument { + + RemovePassword(String password) { + super(password); + } + + @Override + public String toString() { + return "<" + super.toString(); + } + + } + + public final static class AddHashedPassword extends StringArgument { + + AddHashedPassword(String password) { + super(password); + } + + @Override + public String toString() { + return "#" + super.toString(); + } + + } + + public final static class RemoveHashedPassword extends StringArgument { + + RemoveHashedPassword(String password) { + super(password); + } + + @Override + public String toString() { + return "!" + super.toString(); + } + + } + + public final static class Reset extends ProtocolCommandArgument { + + Reset() { + super(SubCommand.RESET); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ApproximateExactTrimming.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ApproximateExactTrimming.java new file mode 100644 index 000000000..3688abf65 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ApproximateExactTrimming.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public enum ApproximateExactTrimming { + APPROXIMATE("~"), + + EXACT("="); + + private final String value; + + ApproximateExactTrimming(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + @Override + public String toString() { + return getValue(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ArgumentStringBuilder.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ArgumentStringBuilder.java new file mode 100644 index 000000000..b1fb9384f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ArgumentStringBuilder.java @@ -0,0 +1,295 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.core.utils.StringJoiner; +import com.buession.lang.Constants; +import com.buession.redis.utils.SafeEncoder; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +class ArgumentStringBuilder { + + private final StringJoiner joiner = new StringJoiner(Constants.SPACING_STRING); + + private ArgumentStringBuilder() { + } + + public static ArgumentStringBuilder create() { + return new ArgumentStringBuilder(); + } + + public ArgumentStringBuilder add(final String name, final Boolean value) { + if(value != null){ + joiner.add(name).add(value); + } + + return this; + } + + public ArgumentStringBuilder add(final String name, final Short value) { + if(value != null){ + joiner.add(name).add(value); + } + + return this; + } + + public ArgumentStringBuilder add(final String name, final Integer value) { + if(value != null){ + joiner.add(name).add(value); + } + + return this; + } + + public ArgumentStringBuilder add(final String name, final Long value) { + if(value != null){ + joiner.add(name).add(value); + } + + return this; + } + + public ArgumentStringBuilder add(final String name, final Float value) { + if(value != null){ + joiner.add(name).add(value); + } + + return this; + } + + public ArgumentStringBuilder add(final String name, final Double value) { + if(value != null){ + joiner.add(name).add(value); + } + + return this; + } + + public ArgumentStringBuilder add(final String name, final byte[] value) { + if(value != null){ + joiner.add(name).add(SafeEncoder.encode(value)); + } + + return this; + } + + public ArgumentStringBuilder add(final String name, final CharSequence value) { + if(value != null){ + joiner.add(name).add(value); + } + + return this; + } + + public ArgumentStringBuilder add(final String name, final Enum value) { + if(value != null){ + joiner.add(name).add(value.name()); + } + + return this; + } + + public ArgumentStringBuilder add(final String name, final Object value) { + if(value != null){ + joiner.add(name).add(value); + } + + return this; + } + + public ArgumentStringBuilder add(final Enum name, final Boolean value) { + if(value != null){ + joiner.add(name.name()).add(value); + } + + return this; + } + + public ArgumentStringBuilder add(final Enum name, final Short value) { + if(value != null){ + joiner.add(name.name()).add(value); + } + + return this; + } + + public ArgumentStringBuilder add(final Enum name, final Integer value) { + if(value != null){ + joiner.add(name.name()).add(value); + } + + return this; + } + + public ArgumentStringBuilder add(final Enum name, final Long value) { + if(value != null){ + joiner.add(name.name()).add(value); + } + + return this; + } + + public ArgumentStringBuilder add(final Enum name, final Float value) { + if(value != null){ + joiner.add(name.name()).add(value); + } + + return this; + } + + public ArgumentStringBuilder add(final Enum name, final Double value) { + if(value != null){ + joiner.add(name.name()).add(value); + } + + return this; + } + + public ArgumentStringBuilder add(final Enum name, final byte[] value) { + if(value != null){ + joiner.add(name.name()).add(SafeEncoder.encode(value)); + } + + return this; + } + + public ArgumentStringBuilder add(final Enum name, final CharSequence value) { + if(value != null){ + joiner.add(name.name()).add(value); + } + + return this; + } + + public ArgumentStringBuilder add(final Enum name, final Enum value) { + if(value != null){ + joiner.add(name.name()).add(value.name()); + } + + return this; + } + + public ArgumentStringBuilder add(final Enum name, final Object value) { + if(value != null){ + joiner.add(name.name()).add(value); + } + + return this; + } + + public ArgumentStringBuilder append(final Boolean value) { + if(value != null){ + joiner.add(value); + } + + return this; + } + + public ArgumentStringBuilder append(final Short value) { + if(value != null){ + joiner.add(value); + } + + return this; + } + + public ArgumentStringBuilder append(final Integer value) { + if(value != null){ + joiner.add(value); + } + + return this; + } + + public ArgumentStringBuilder append(final Long value) { + if(value != null){ + joiner.add(value); + } + + return this; + } + + public ArgumentStringBuilder append(final Float value) { + if(value != null){ + joiner.add(value); + } + + return this; + } + + public ArgumentStringBuilder append(final Double value) { + if(value != null){ + joiner.add(value); + } + + return this; + } + + public ArgumentStringBuilder append(final byte[] value) { + if(value != null){ + joiner.add(SafeEncoder.encode(value)); + } + + return this; + } + + public ArgumentStringBuilder append(final CharSequence value) { + if(value != null){ + joiner.add(value); + } + + return this; + } + + public ArgumentStringBuilder append(final Enum value) { + if(value != null){ + joiner.add(value.name()); + } + + return this; + } + + public ArgumentStringBuilder append(final Object value) { + if(value != null){ + joiner.add(value); + } + + return this; + } + + public String build() { + return joiner.toString(); + } + + @Override + public String toString() { + return joiner.toString(); + } + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/PoolConfiguration.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ArrayArgument.java similarity index 78% rename from buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/PoolConfiguration.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ArrayArgument.java index 5e1e2d9e9..5391fec74 100644 --- a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/PoolConfiguration.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ArrayArgument.java @@ -19,34 +19,34 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.jdbc.datasource.config; - -import java.util.Properties; +package com.buession.redis.core.command.args; /** - * 连接池配置 + * 数组参数 + * + * @param + * 值类型 * * @author Yong.Teng - * @since 1.3.2 + * @since 3.0.0 */ -public interface PoolConfiguration { +public interface ArrayArgument { /** - * 返回连接池其它属性 + * 将参数以数组形式返回 * - * @return 连接池其它属性 + * @return 以数组形式返回参数列表 */ - Properties getProperties(); + T[] toArray(); /** - * 设置连接池其它属性 + * 将参数以二进制数组形式返回 * - * @param properties - * 连接池其它属性 + * @return 以数组形式返回参数列表 */ - void setProperties(Properties properties); + byte[][] toBinaryArray(); } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/BaseGeoSearchArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/BaseGeoSearchArgument.java new file mode 100644 index 000000000..7cf230ac9 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/BaseGeoSearchArgument.java @@ -0,0 +1,363 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.lang.Geo; +import com.buession.lang.Order; +import com.buession.redis.core.GeoUnit; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +class BaseGeoSearchArgument { + + /** + * {@link FromMode} + */ + private FromMode fromMode; + + /** + * BYRADIUS / BYBOX + */ + private Predicate predicate; + + /** + * 排序 + */ + private Order order; + + /** + * 返回个数 + */ + private Integer count; + + /** + * - + */ + private Boolean any; + + /** + * 构造函数 + */ + public BaseGeoSearchArgument() { + } + + /** + * 返回 {@link FromMode} 实例 + * + * @return {@link FromMode} 实例 + */ + public FromMode getFromMode() { + return fromMode; + } + + /** + * 设置 {@link FromMode} 实例 + * + * @param fromMode + * {@link FromMode} 实例 + */ + public void setFromMode(FromMode fromMode) { + this.fromMode = fromMode; + } + + /** + * 返回 BYRADIUS / BYBOX + * + * @return BYRADIUS / BYBOX + */ + public Predicate getPredicate() { + return predicate; + } + + + /** + * 设置 BYRADIUS / BYBOX + * + * @param predicate + * BYRADIUS / BYBOX + */ + public void setPredicate(Predicate predicate) { + this.predicate = predicate; + } + + /** + * 返回排序 + * + * @return 排序 + */ + public Order getOrder() { + return order; + } + + /** + * 设置排序 + * + * @param order + * 排序 + */ + public void setOrder(Order order) { + this.order = order; + } + + /** + * 获取返回数量 + * + * @return 返回数量 + */ + public Integer getCount() { + return count; + } + + /** + * 设置返回数量 + * + * @param count + * 返回数量 + */ + public void count(final Integer count) { + this.count = count; + } + + /** + * 设置返回数量 + * + * @param count + * 返回数量 + * @param any + * - + */ + public void count(final Integer count, final Boolean any) { + this.count = count; + this.any = any; + } + + /** + * - + * + * @return true / false + */ + public Boolean isAny() { + return getAny(); + } + + /** + * - + * + * @return true / false + */ + public Boolean getAny() { + return any; + } + + public interface FromMode { + + } + + public final static class FromMember implements FromMode { + + private final String member; + + public FromMember(final String member) { + this.member = member; + } + + public String getMember() { + return member; + } + + @Override + public String toString() { + return getMember(); + } + + } + + public final static class FromLonLat implements FromMode { + + private final Geo geo; + + public FromLonLat(final Geo geo) { + this.geo = geo; + } + + public FromLonLat(final double longitude, final double latitude) { + this.geo = new Geo(longitude, latitude); + } + + public Geo getGeo() { + return geo; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + builder.append(geo.getLongitude()).append(geo.getLatitude()); + + return builder.build(); + } + + } + + public interface Predicate { + + } + + /** + * BYRADIUS + */ + public final static class RadiusPredicate implements Predicate { + + /** + * 距离范围 + */ + private final Double radius; + + /** + * 距离单位 + */ + private final GeoUnit unit; + + /** + * 构造函数 + * + * @param radius + * 距离范围 + * @param unit + * 距离单位 + */ + public RadiusPredicate(final Double radius, final GeoUnit unit) { + this.radius = radius; + this.unit = unit; + } + + /** + * 返回距离范围 + * + * @return 距离范围 + */ + public Double getRadius() { + return radius; + } + + /** + * 返回距离单位 + * + * @return 距离单位 + */ + public GeoUnit getUnit() { + return unit; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(radius != null){ + builder.add(Double.toString(radius), unit); + } + + return builder.build(); + } + } + + /** + * BYBOX + */ + public final static class BoxPredicate implements Predicate { + + /** + * 宽度 + */ + private final Double width; + + /** + * 高度 + */ + private final Double height; + + /** + * 距离单位 + */ + private final GeoUnit unit; + + /** + * 构造函数 + * + * @param width + * 宽度 + * @param height + * 高度 + * @param unit + * 单位 + */ + public BoxPredicate(final Double width, final Double height, final GeoUnit unit) { + this.width = width; + this.height = height; + this.unit = unit; + } + + /** + * 返回宽度 + * + * @return 宽度 + */ + public Double getWidth() { + return width; + } + + /** + * 返回高度 + * + * @return 高度 + */ + public Double getHeight() { + return height; + } + + /** + * 返回距离单位 + * + * @return 距离单位 + */ + public GeoUnit getUnit() { + return unit; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(width != null && height != null){ + builder.append(width).append(height).append(unit); + } + + return builder.build(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/BaseScanArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/BaseScanArgument.java new file mode 100644 index 000000000..f5e6b5f0a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/BaseScanArgument.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +/** + * {@code SCAN}、{@code SSCAN}、{@code HSCAN}、{@code ZSCAN} 参数基类 + * + * @param + * 模式值类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +abstract class BaseScanArgument { + + /** + * 模式 + */ + private T pattern; + + /** + * 返回个数 + */ + private Integer count; + + /** + * 构造函数 + */ + public BaseScanArgument() { + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + */ + public BaseScanArgument(final T pattern) { + this.pattern = pattern; + } + + /** + * 构造函数 + * + * @param count + * 返回个数 + */ + public BaseScanArgument(final int count) { + this.count = count; + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + * @param count + * 返回个数 + */ + public BaseScanArgument(final T pattern, final int count) { + this(pattern); + this.count = count; + } + + /** + * 返回模式 + * + * @return 模式 + */ + public T getPattern() { + return pattern; + } + + /** + * 设置模式 + * + * @param pattern + * 模式 + */ + public void setPattern(final T pattern) { + this.pattern = pattern; + } + + /** + * 返回个数 + * + * @return 返回个数 + */ + public Integer getCount() { + return count; + } + + /** + * 设置返回个数 + * + * @param count + * 返回个数 + */ + public void setCount(final Integer count) { + this.count = count; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/BitFieldArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/BitFieldArgument.java new file mode 100644 index 000000000..fbea31a69 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/BitFieldArgument.java @@ -0,0 +1,534 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.core.collect.Arrays; +import com.buession.core.utils.NumberUtils; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + +/** + * {@code BITFIELD} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class BitFieldArgument implements ArrayArgument { + + /** + * 子命令列表 + */ + private final List commands = new ArrayList<>(); + + /** + * 构造函数 + */ + public BitFieldArgument() { + } + + /** + * Build a new {@code GET} subcommand. + * + * @param bitFieldType + * The bit field type, must not be {@code null}. + * @param offset + * The bitfield offset. + * + * @return The {@link BitFieldArgument} instance. + */ + public BitFieldArgument get(final BitFieldType bitFieldType, final int offset) { + return get(bitFieldType, false, offset); + } + + /** + * Build a new {@code GET} subcommand. + * + * @param bitFieldType + * The bit field type, must not be {@code null}. + * @param bitOffset + * - + * @param offset + * The bitfield offset. + * + * @return The {@link BitFieldArgument} instance. + */ + public BitFieldArgument get(final BitFieldType bitFieldType, final boolean bitOffset, final int offset) { + commands.add(new Get(bitFieldType, bitOffset, offset)); + return this; + } + + /** + * Build a new {@code SET} subcommand. + * + * @param bitFieldType + * The bit field type, must not be {@code null}. + * @param offset + * The bitfield offset. + * @param value + * The value. + * + * @return The {@link BitFieldArgument} instance. + */ + public BitFieldArgument set(final BitFieldType bitFieldType, final int offset, final long value) { + return set(bitFieldType, false, offset, value); + } + + /** + * Build a new {@code SET} subcommand. + * + * @param bitFieldType + * The bit field type, must not be {@code null}. + * @param bitOffset + * - + * @param offset + * The bitfield offset. + * @param value + * The value. + * + * @return The {@link BitFieldArgument} instance. + */ + public BitFieldArgument set(final BitFieldType bitFieldType, final boolean bitOffset, final int offset, + final long value) { + commands.add(new Set(bitFieldType, bitOffset, offset, value)); + return this; + } + + /** + * Build a new {@code INCRBY} subcommand. + * + * @param bitFieldType + * The bit field type, must not be {@code null}. + * @param offset + * The bitfield offset. + * @param value + * The value. + * + * @return The {@link BitFieldArgument} instance. + */ + public BitFieldArgument incrBy(final BitFieldType bitFieldType, final int offset, final long value) { + return incrBy(bitFieldType, false, offset, value); + } + + /** + * Build a new {@code INCRBY} subcommand. + * + * @param bitFieldType + * The bit field type, must not be {@code null}. + * @param bitOffset + * - + * @param offset + * The bitfield offset. + * @param value + * The value. + * + * @return The {@link BitFieldArgument} instance. + */ + public BitFieldArgument incrBy(final BitFieldType bitFieldType, final boolean bitOffset, final int offset, + final long value) { + commands.add(new IncrBy(bitFieldType, bitOffset, offset, value)); + return this; + } + + /** + * Build a new {@code OVERFLOW} subcommand. + * + * @param overflowType + * The of overflow, must not be {@code null}. + * + * @return The {@link BitFieldArgument} instance. + */ + public BitFieldArgument overflow(final OverflowType overflowType) { + commands.add(new Overflow(overflowType)); + return this; + } + + /** + * 返回子命令列表 + * + * @return 子命令列表 + */ + public List getCommands() { + return commands; + } + + @Override + public String[] toArray() { + String[] result = new String[]{}; + + for(SubCommand subCommand : commands){ + result = Arrays.merge(result, subCommand.toArray()); + } + + return result; + } + + @Override + public byte[][] toBinaryArray() { + byte[][] result = new byte[][]{}; + + for(SubCommand subCommand : commands){ + result = Arrays.merge(result, subCommand.toBinaryArray()); + } + + return result; + } + + /** + * 子命令类型 + */ + public enum CommandType { + /** + * 返回指定的位域 + */ + GET, + + /** + * 设置指定位域的值并返回它的原值 + */ + SET, + + /** + * 递增或递减指定的位域并返回新值 + */ + INCRBY, + + /** + * 在期望整数类型的情况下,可以通过i为有符号整数和u无符号整数加上整数类型的位数来构成它 + */ + OVERFLOW + } + + /** + * 在期望整数类型的情况下,可以通过i为有符号整数和u无符号整数加上整数类型的位数来构成它 + */ + public enum OverflowType { + /** + * 环绕,包含有符号和无符号整数 + */ + WRAP, + + /** + * 使用饱和算术,即在下溢时将该值设置为最小整数值,并在溢出时将其设置为最大整数值 + */ + SAT, + + /** + * 在这种模式下,没有检测到溢出或下溢操作 + */ + FAIL + } + + public final static class BitFieldType { + + private final boolean signed; + + private final int bits; + + private BitFieldType(final boolean signed, final int bits) { + this.signed = signed; + this.bits = bits; + } + + public boolean isSigned() { + return signed; + } + + public int getBits() { + return bits; + } + + @Override + public String toString() { + return (signed ? "i" : "u") + bits; + } + + } + + public interface SubCommand extends ArrayArgument { + + CommandType getCommandType(); + + } + + /** + * Representation for the {@code GET} subcommand for {@code BITFIELD}. + */ + public final static class Get implements SubCommand { + + private final BitFieldType bitFieldType; + + private final boolean bitOffset; + + private final int offset; + + public Get(final BitFieldType bitFieldType, final boolean bitOffset, final int offset) { + this.bitFieldType = bitFieldType; + this.bitOffset = bitOffset; + this.offset = offset; + } + + @Override + public CommandType getCommandType() { + return CommandType.GET; + } + + public BitFieldType getBitFieldType() { + return bitFieldType; + } + + public boolean isBitOffset() { + return bitOffset; + } + + public int getOffset() { + return offset; + } + + @Override + public String[] toArray() { + return new String[]{ + getCommandType().name(), + bitFieldType.toString(), + bitOffset ? "#" + offset : Integer.toString(offset) + }; + } + + @Override + public byte[][] toBinaryArray() { + return new byte[][]{ + getCommandType().name().getBytes(StandardCharsets.US_ASCII), + bitFieldType.toString().getBytes(StandardCharsets.US_ASCII), + bitOffset ? ("#" + offset).getBytes(StandardCharsets.US_ASCII) : NumberUtils.int2bytes(offset) + }; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + builder.append(getCommandType()).append(bitFieldType).append(bitOffset ? "#" + offset : + Integer.toString(offset)); + + return builder.build(); + } + + } + + /** + * Representation for the {@code SET} subcommand for {@code BITFIELD}. + */ + public final static class Set implements SubCommand { + + private final BitFieldType bitFieldType; + + private final boolean bitOffset; + + private final int offset; + + private final long value; + + public Set(final BitFieldType bitFieldType, final boolean bitOffset, final int offset, final long value) { + this.bitFieldType = bitFieldType; + this.bitOffset = bitOffset; + this.offset = offset; + this.value = value; + } + + @Override + public CommandType getCommandType() { + return CommandType.SET; + } + + public BitFieldType getBitFieldType() { + return bitFieldType; + } + + public boolean isBitOffset() { + return bitOffset; + } + + public int getOffset() { + return offset; + } + + public long getValue() { + return value; + } + + @Override + public String[] toArray() { + return new String[]{ + getCommandType().name(), + bitFieldType.toString(), + bitOffset ? "#" + offset : Integer.toString(offset), + Long.toString(value) + }; + } + + @Override + public byte[][] toBinaryArray() { + return new byte[][]{ + getCommandType().name().getBytes(StandardCharsets.US_ASCII), + bitFieldType.toString().getBytes(StandardCharsets.US_ASCII), + bitOffset ? ("#" + offset).getBytes(StandardCharsets.US_ASCII) : NumberUtils.long2bytes(offset), + NumberUtils.long2bytes(value) + }; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + builder.append(getCommandType()).append(bitFieldType).append(bitOffset ? "#" + offset : + Integer.toString(offset)); + + return builder.build(); + } + + } + + /** + * Representation for the {@code INCRBY} subcommand for {@code BITFIELD}. + */ + public final static class IncrBy implements SubCommand { + + private final BitFieldType bitFieldType; + + private final boolean bitOffset; + + private final int offset; + + private final long value; + + public IncrBy(final BitFieldType bitFieldType, final boolean bitOffset, final int offset, final long value) { + this.bitFieldType = bitFieldType; + this.bitOffset = bitOffset; + this.offset = offset; + this.value = value; + } + + @Override + public CommandType getCommandType() { + return CommandType.INCRBY; + } + + public BitFieldType getBitFieldType() { + return bitFieldType; + } + + public boolean isBitOffset() { + return bitOffset; + } + + public int getOffset() { + return offset; + } + + public long getValue() { + return value; + } + + @Override + public String[] toArray() { + return new String[]{ + getCommandType().name(), + bitFieldType.toString(), + bitOffset ? "#" + offset : Integer.toString(offset), + Long.toString(value) + }; + } + + @Override + public byte[][] toBinaryArray() { + return new byte[][]{ + getCommandType().name().getBytes(StandardCharsets.US_ASCII), + bitFieldType.toString().getBytes(StandardCharsets.US_ASCII), + bitOffset ? ("#" + offset).getBytes(StandardCharsets.US_ASCII) : NumberUtils.long2bytes(offset), + NumberUtils.long2bytes(value) + }; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + builder.append(getCommandType()).append(bitFieldType).add(bitOffset ? "#" + offset : + Integer.toString(offset), value); + + return builder.build(); + } + + } + + /** + * Representation for the {@code OVERFLOW} subcommand for {@code BITFIELD}. + */ + public final static class Overflow implements SubCommand { + + private final OverflowType overflowType; + + public Overflow(final OverflowType overflowType) { + this.overflowType = overflowType; + } + + @Override + public CommandType getCommandType() { + return CommandType.OVERFLOW; + } + + public OverflowType getOverflowType() { + return overflowType; + } + + @Override + public String[] toArray() { + return new String[]{ + getCommandType().name(), + overflowType.name() + }; + } + + @Override + public byte[][] toBinaryArray() { + return new byte[][]{ + getCommandType().name().getBytes(StandardCharsets.US_ASCII), + overflowType.name().getBytes(StandardCharsets.US_ASCII) + }; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + builder.append(getCommandType()).append(overflowType); + + return builder.build(); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/BitFieldRoArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/BitFieldRoArgument.java new file mode 100644 index 000000000..05ea5b51a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/BitFieldRoArgument.java @@ -0,0 +1,204 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.core.collect.Arrays; +import com.buession.core.utils.NumberUtils; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; + +/** + * {@code BITFIELD_RO} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class BitFieldRoArgument implements ArrayArgument { + + /** + * 子命令列表 + */ + private final List commands = new ArrayList<>(); + + /** + * 构造函数 + */ + public BitFieldRoArgument() { + } + + /** + * Build a new {@code GET} subcommand. + * + * @param bitFieldType + * The bit field type, must not be {@code null}. + * @param offset + * The bitfield offset. + * + * @return The {@link BitFieldRoArgument} instance. + */ + public BitFieldRoArgument get(final BitFieldType bitFieldType, final int offset) { + return get(bitFieldType, false, offset); + } + + /** + * Build a new {@code GET} subcommand. + * + * @param bitFieldType + * The bit field type, must not be {@code null}. + * @param bitOffset + * - + * @param offset + * The bitfield offset. + * + * @return The {@link BitFieldRoArgument} instance. + */ + public BitFieldRoArgument get(final BitFieldType bitFieldType, final boolean bitOffset, final int offset) { + commands.add(new Get(bitFieldType, bitOffset, offset)); + return this; + } + + /** + * 返回子命令列表 + * + * @return 子命令列表 + */ + public List getCommands() { + return commands; + } + + @Override + public String[] toArray() { + String[] result = new String[]{}; + + for(SubCommand subCommand : commands){ + result = Arrays.merge(result, subCommand.toArray()); + } + + return result; + } + + @Override + public byte[][] toBinaryArray() { + byte[][] result = new byte[][]{}; + + for(SubCommand subCommand : commands){ + result = Arrays.merge(result, subCommand.toBinaryArray()); + } + + return result; + } + + public final static class BitFieldType { + + private final boolean signed; + + private final int bits; + + private BitFieldType(final boolean signed, final int bits) { + this.signed = signed; + this.bits = bits; + } + + public boolean isSigned() { + return signed; + } + + public int getBits() { + return bits; + } + + @Override + public String toString() { + return (signed ? "i" : "u") + bits; + } + + } + + public interface SubCommand extends ArrayArgument { + + } + + /** + * Representation for the {@code GET} subcommand for {@code BITFIELD}. + */ + public final static class Get implements SubCommand { + + private final BitFieldType bitFieldType; + + private final boolean bitOffset; + + private final int offset; + + public Get(final BitFieldType bitFieldType, final boolean bitOffset, final int offset) { + this.bitFieldType = bitFieldType; + this.bitOffset = bitOffset; + this.offset = offset; + } + + public BitFieldType getBitFieldType() { + return bitFieldType; + } + + public boolean isBitOffset() { + return bitOffset; + } + + public int getOffset() { + return offset; + } + + @Override + public String[] toArray() { + return new String[]{ + com.buession.redis.core.command.SubCommand.GET.name(), + bitFieldType.toString(), + bitOffset ? "#" + offset : Integer.toString(offset) + }; + } + + @Override + public byte[][] toBinaryArray() { + return new byte[][]{ + com.buession.redis.core.command.SubCommand.GET.name().getBytes(StandardCharsets.US_ASCII), + bitFieldType.toString().getBytes(StandardCharsets.US_ASCII), + bitOffset ? ("#" + offset).getBytes(StandardCharsets.US_ASCII) : NumberUtils.int2bytes(offset) + }; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + builder.append(com.buession.redis.core.command.SubCommand.GET).append(bitFieldType) + .append(bitOffset ? "#" + offset : Integer.toString(offset)); + + return builder.build(); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ClientKillArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ClientKillArgument.java new file mode 100644 index 000000000..ba237c4ae --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ClientKillArgument.java @@ -0,0 +1,392 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.core.validator.Validate; +import com.buession.redis.core.ClientType; +import com.buession.redis.core.Keyword; + +/** + * {@code CLIENT KILL} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class ClientKillArgument { + + /** + * 客户端 ID + */ + private Long clientId; + + /** + * 客户端类型 + */ + private ClientType clientType; + + /** + * 用户名 + */ + private String username; + + private String addr; + + private String laddr; + + /** + * 是否跳过自身 + */ + private Boolean skipMe; + + /** + * Closes all the connections that are older than the specified age, in seconds. + */ + private Long maxAge; + + /** + * 构造函数 + */ + public ClientKillArgument() { + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + */ + public ClientKillArgument(final Long clientId) { + this.clientId = clientId; + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + */ + public ClientKillArgument(final ClientType clientType) { + this.clientType = clientType; + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public ClientKillArgument(final Long clientId, final Boolean skipMe, final Long maxAge) { + this(clientId); + this.skipMe = skipMe; + this.maxAge = maxAge; + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public ClientKillArgument(final ClientType clientType, final Boolean skipMe, final Long maxAge) { + this(clientType); + this.skipMe = skipMe; + this.maxAge = maxAge; + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public ClientKillArgument(final Long clientId, final String addr, final String laddr, final Boolean skipMe, + final Long maxAge) { + this(clientId, skipMe, maxAge); + this.addr = addr; + this.laddr = laddr; + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public ClientKillArgument(final ClientType clientType, final String addr, final String laddr, final Boolean skipMe, + final Long maxAge) { + this(clientType, skipMe, maxAge); + this.addr = addr; + this.laddr = laddr; + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public ClientKillArgument(final Long clientId, final String username, final String addr, final String laddr, + final Boolean skipMe, final Long maxAge) { + this(clientId, addr, laddr, skipMe, maxAge); + this.username = username; + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public ClientKillArgument(final ClientType clientType, final String username, final String addr, final String laddr, + final Boolean skipMe, final Long maxAge) { + this(clientType, addr, laddr, skipMe, maxAge); + this.username = username; + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param clientType + * 客户端类型 + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public ClientKillArgument(final Long clientId, final ClientType clientType, final String username, + final String addr, final String laddr, final Boolean skipMe, final Long maxAge) { + this(clientId, username, addr, laddr, skipMe, maxAge); + this.clientType = clientType; + } + + /** + * 返回客户端 ID + * + * @return 客户端 ID + */ + public Long getClientId() { + return clientId; + } + + /** + * 设置客户端 ID + * + * @param clientId + * 客户端 ID + */ + public void setClientId(Long clientId) { + this.clientId = clientId; + } + + /** + * 返回客户端类型 + * + * @return 客户端类型 + */ + public ClientType getClientType() { + return clientType; + } + + /** + * 设置客户端类型 + * + * @param clientType + * 客户端类型 + */ + public void setClientType(ClientType clientType) { + this.clientType = clientType; + } + + /** + * 返回用户名 + * + * @return 用户名 + */ + public String getUsername() { + return username; + } + + /** + * 设置用户名 + * + * @param username + * 用户名 + */ + public void setUsername(String username) { + this.username = username; + } + + public String getAddr() { + return addr; + } + + public void setAddr(String addr) { + this.addr = addr; + } + + public String getLaddr() { + return laddr; + } + + public void setLaddr(String laddr) { + this.laddr = laddr; + } + + /** + * 返回是否跳过自身 + * + * @return 是否跳过自身 + */ + public Boolean isSkipMe() { + return getSkipMe(); + } + + /** + * 返回是否跳过自身 + * + * @return 是否跳过自身 + */ + public Boolean getSkipMe() { + return skipMe; + } + + /** + * 设置跳过自身 + */ + public void skipMe() { + this.skipMe = true; + } + + /** + * 设置是否跳过自身 + * + * @param skipMe + * 是否跳过自身 + */ + public void setSkipMe(Boolean skipMe) { + this.skipMe = skipMe; + } + + /** + * Return closes all the connections that are older than the specified age, in seconds. + * + * @return Closes all the connections that are older than the specified age. + */ + public Long getMaxAge() { + return maxAge; + } + + /** + * Sets closes all the connections that are older than the specified age, in seconds. + * + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public void setMaxAge(Long maxAge) { + this.maxAge = maxAge; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(clientId != null){ + builder.add(Keyword.Common.ID, clientId); + } + if(clientType != null){ + builder.add(Keyword.Common.TYPE, clientType); + } + if(Validate.hasText(username)){ + builder.add(Keyword.Common.USER, username); + } + if(Validate.hasText(addr)){ + builder.add(Keyword.Common.ADDR, addr); + } + if(Validate.hasText(laddr)){ + builder.add(Keyword.Common.LADDR, addr); + } + if(skipMe != null){ + builder.add(Keyword.Common.SKIPME, skipMe ? Keyword.Common.YES : Keyword.Common.NO); + } + if(maxAge != null){ + builder.add(Keyword.Common.MAXAGE, maxAge); + } + + return builder.build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ClientTracking.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ClientTracking.java new file mode 100644 index 000000000..0a91b72f4 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ClientTracking.java @@ -0,0 +1,216 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.core.validator.Validate; +import com.buession.redis.core.Keyword; + +/** + * {@code CLIENT TRACKING} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class ClientTracking { + + private Boolean enabled; + + private Long redirect; + + private String[] prefixes; + + private Boolean bcast; + + private Boolean optin; + + private Boolean optout; + + private Boolean noloop; + + public ClientTracking() { + } + + public ClientTracking(final Boolean enabled) { + this.enabled = enabled; + } + + public ClientTracking(final Boolean enabled, final Long redirect) { + this(enabled); + this.redirect = redirect; + } + + public ClientTracking(final Boolean enabled, final String[] prefixes) { + this(enabled); + this.prefixes = prefixes; + } + + public ClientTracking(final Boolean enabled, final Long redirect, final String[] prefixes) { + this(enabled, redirect); + this.prefixes = prefixes; + } + + public ClientTracking(final Boolean enabled, final Long redirect, final String[] prefixes, final Boolean bcast, + final Boolean optin, final Boolean optout, final Boolean noloop) { + this(enabled, redirect, prefixes); + this.bcast = bcast; + this.optin = optin; + this.optout = optout; + this.noloop = noloop; + } + + public Boolean isEnabled() { + return getEnabled(); + } + + public Boolean getEnabled() { + return enabled; + } + + public void enabled() { + this.enabled = true; + } + + public void setEnabled(Boolean enabled) { + this.enabled = enabled; + } + + public Long getRedirect() { + return redirect; + } + + public void setRedirect(Long redirect) { + this.redirect = redirect; + } + + public String[] getPrefixes() { + return prefixes; + } + + public void setPrefixes(String[] prefixes) { + this.prefixes = prefixes; + } + + public Boolean isBcast() { + return getBcast(); + } + + public Boolean getBcast() { + return bcast; + } + + public void bcast() { + this.bcast = true; + } + + public void setBcast(Boolean bcast) { + this.bcast = bcast; + } + + public Boolean isOptin() { + return getOptin(); + } + + public Boolean getOptin() { + return optin; + } + + public void optin() { + this.optin = true; + } + + public void setOptin(Boolean optin) { + this.optin = optin; + } + + public Boolean isOptout() { + return getOptout(); + } + + public Boolean getOptout() { + return optout; + } + + public void optout() { + this.optout = true; + } + + public void setOptout(Boolean optout) { + this.optout = optout; + } + + public Boolean isNoloop() { + return getNoloop(); + } + + public Boolean getNoloop() { + return noloop; + } + + public void noloop() { + this.noloop = true; + } + + public void setNoloop(Boolean noloop) { + this.noloop = noloop; + } + + @Override + public String toString() { + final ArgumentStringBuilder joiner = ArgumentStringBuilder.create(); + + if(enabled != null){ + joiner.append(enabled ? Keyword.Common.ON : Keyword.Common.OFF); + } + + if(redirect != null){ + joiner.add(Keyword.Common.REDIRECT, redirect); + } + + if(Validate.isNotEmpty(prefixes)){ + for(String prefix : prefixes){ + joiner.add(Keyword.Common.PREFIX, prefix); + } + } + + if(bcast != null){ + joiner.append(Keyword.Common.BCAST); + } + + if(optin != null){ + joiner.append(Keyword.Common.OPTIN); + } + + if(optout != null){ + joiner.append(Keyword.Common.OPTOUT); + } + + if(noloop != null){ + joiner.append(Keyword.Common.NOLOOP); + } + + return joiner.toString(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/GeoAddArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/GeoAddArgument.java new file mode 100644 index 000000000..257a01095 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/GeoAddArgument.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.redis.core.Keyword; +import com.buession.redis.core.NxXx; + +/** + * {@code GEOADD} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class GeoAddArgument { + + /** + * {@link NxXx} + */ + private NxXx nxXx; + + private Boolean ch; + + /** + * 构造函数 + */ + public GeoAddArgument() { + } + + /** + * 构造函数 + * + * @param nxXx + * {@link NxXx} + */ + public GeoAddArgument(final NxXx nxXx) { + this.nxXx = nxXx; + } + + /** + * 构造函数 + * + * @param ch + * - + */ + public GeoAddArgument(final Boolean ch) { + this.ch = ch; + } + + /** + * 构造函数 + * + * @param nxXx + * {@link NxXx} + * @param ch + * - + */ + public GeoAddArgument(final NxXx nxXx, final Boolean ch) { + this(nxXx); + this.ch = ch; + } + + public NxXx getNxXx() { + return nxXx; + } + + public void setNxXx(NxXx nxXx) { + this.nxXx = nxXx; + } + + public Boolean isCh() { + return getCh(); + } + + public Boolean getCh() { + return ch; + } + + public void ch() { + this.ch = true; + } + + public void setCh(Boolean ch) { + this.ch = ch; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(nxXx != null){ + builder.append(nxXx); + } + + if(Boolean.TRUE.equals(ch)){ + builder.append(Keyword.Common.CH); + } + + return builder.toString(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/GeoRadiusArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/GeoRadiusArgument.java new file mode 100644 index 000000000..c94a1e3e5 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/GeoRadiusArgument.java @@ -0,0 +1,451 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.lang.Order; +import com.buession.redis.core.Keyword; + +/** + * {@code GEORADIUS} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class GeoRadiusArgument { + + /** + * 将位置元素的经度和维度也一并返回 + */ + private Boolean withCoord; + + /** + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + */ + private Boolean withDist; + + /** + * 以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + */ + private Boolean withHash; + + /** + * 排序 + */ + private Order order; + + /** + * 返回个数 + */ + private Integer count; + + /** + * - + */ + private Boolean any; + + /** + * 构造函数 + */ + public GeoRadiusArgument() { + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + */ + public GeoRadiusArgument(final Boolean withCoord, final Boolean withDist, final Boolean withHash) { + this.withCoord = withCoord; + this.withDist = withDist; + this.withHash = withHash; + } + + /** + * 构造函数 + * + * @param order + * 排序 + */ + public GeoRadiusArgument(final Order order) { + this.order = order; + } + + /** + * 构造函数 + * + * @param count + * 返回数量 + */ + public GeoRadiusArgument(final Integer count) { + this.count = count; + } + + /** + * 构造函数 + * + * @param count + * 返回数量 + * @param any + * - + */ + public GeoRadiusArgument(final Integer count, final Boolean any) { + count(count, any); + } + + /** + * 构造函数 + * + * @param order + * 排序 + * @param count + * 返回数量 + */ + public GeoRadiusArgument(final Order order, final Integer count) { + this(order); + count(count); + } + + /** + * 构造函数 + * + * @param order + * 排序 + * @param count + * 返回数量 + * @param any + * - + */ + public GeoRadiusArgument(final Order order, final Integer count, final Boolean any) { + this(order, count); + this.any = any; + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param order + * 排序 + */ + public GeoRadiusArgument(final Boolean withCoord, final Boolean withDist, final Boolean withHash, + final Order order) { + this(withCoord, withDist, withHash); + this.order = order; + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param count + * 返回数量 + */ + public GeoRadiusArgument(final Boolean withCoord, final Boolean withDist, final Boolean withHash, + final Integer count) { + this(withCoord, withDist, withHash); + this.count = count; + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param count + * 返回数量 + * @param any + * - + */ + public GeoRadiusArgument(final Boolean withCoord, final Boolean withDist, final Boolean withHash, + final Integer count, final Boolean any) { + this(withCoord, withDist, withHash); + count(count, any); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param order + * 排序 + * @param count + * 返回数量 + */ + public GeoRadiusArgument(final Boolean withCoord, final Boolean withDist, final Boolean withHash, + final Order order, final Integer count) { + this(withCoord, withDist, withHash, order); + this.count = count; + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param order + * 排序 + * @param count + * 返回数量 + * 返回数量 + * @param any + * - + */ + public GeoRadiusArgument(final Boolean withCoord, final Boolean withDist, final Boolean withHash, + final Order order, final Integer count, final Boolean any) { + this(withCoord, withDist, withHash, order); + count(count, any); + } + + /** + * 获取是否将位置元素的经度和维度也一并返回 + * + * @return 是否将位置元素的经度和维度也一并返回 + */ + public Boolean isWithCoord() { + return getWithCoord(); + } + + /** + * 获取是否将位置元素的经度和维度也一并返回 + * + * @return 是否将位置元素的经度和维度也一并返回 + */ + public Boolean getWithCoord() { + return withCoord; + } + + /** + * 设置将位置元素的经度和维度也一并返回 + */ + public void withCoord() { + this.withCoord = true; + } + + /** + * 设置是否将位置元素的经度和维度也一并返回 + * + * @param withCoord + * true / false + */ + public void setWithCoord(final Boolean withCoord) { + this.withCoord = withCoord; + } + + /** + * 获取是否在返回位置元素的同时,将位置元素与中心之间的距离也一并返回 + * + * @return 是否在返回位置元素的同时,将位置元素与中心之间的距离也一并返回 + */ + public Boolean isWithDist() { + return getWithDist(); + } + + /** + * 获取是否在返回位置元素的同时,将位置元素与中心之间的距离也一并返回 + * + * @return 是否在返回位置元素的同时,将位置元素与中心之间的距离也一并返回 + */ + public Boolean getWithDist() { + return withDist; + } + + /** + * 设置在返回位置元素的同时,将位置元素与中心之间的距离也一并返回 + */ + public void withDist() { + this.withDist = true; + } + + /** + * 设置是否在返回位置元素的同时,将位置元素与中心之间的距离也一并返回 + * + * @param withDist + * true / false + */ + public void setWithDist(final Boolean withDist) { + this.withDist = withDist; + } + + /** + * 获取是否返回位置元素经过原始 geohash 编码的有序集合分值 + * + * @return 是否返回位置元素经过原始 geohash 编码的有序集合分值 + */ + public Boolean isWithHash() { + return getWithHash(); + } + + /** + * 获取是否返回位置元素经过原始 geohash 编码的有序集合分值 + * + * @return 是否返回位置元素经过原始 geohash 编码的有序集合分值 + */ + public Boolean getWithHash() { + return withHash; + } + + /** + * 设置返回位置元素经过原始 geohash 编码的有序集合分值 + */ + public void withHash() { + this.withHash = true; + } + + /** + * 设置返回位置元素经过原始 geohash 编码的有序集合分值 + * + * @param withHash + * true / false + */ + public void setWithHash(final Boolean withHash) { + this.withHash = withHash; + } + + /** + * 排序方式 + * + * @return 排序方式 + */ + public Order getOrder() { + return order; + } + + /** + * 设置排序方式 + * + * @param order + * 排序方式 + */ + public void order(final Order order) { + this.order = order; + } + + /** + * 获取返回数量 + * + * @return 返回数量 + */ + public Integer getCount() { + return count; + } + + /** + * 设置返回数量 + * + * @param count + * 返回数量 + */ + public void count(final Integer count) { + this.count = count; + } + + /** + * 设置返回数量 + * + * @param count + * 返回数量 + * @param any + * - + */ + public void count(final Integer count, final Boolean any) { + this.count = count; + this.any = any; + } + + /** + * - + * + * @return true / false + */ + public Boolean isAny() { + return getAny(); + } + + /** + * - + * + * @return true / false + */ + public Boolean getAny() { + return any; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(Boolean.TRUE.equals(withCoord)){ + builder.append(Keyword.Geo.WITHCOORD); + } + + if(Boolean.TRUE.equals(withDist)){ + builder.append(Keyword.Geo.WITHDIST); + } + + if(Boolean.TRUE.equals(withHash)){ + builder.append(Keyword.Geo.WITHHASH); + } + + if(count != null){ + builder.add(Keyword.Common.COUNT, count); + if(any != null){ + builder.append(Keyword.Common.ANY); + } + } + + builder.append(order); + + return builder.toString(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/GeoSearchArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/GeoSearchArgument.java new file mode 100644 index 000000000..7875b943c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/GeoSearchArgument.java @@ -0,0 +1,205 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.redis.core.Keyword; + +/** + * {@code GEOSEARCH} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class GeoSearchArgument extends BaseGeoSearchArgument { + + /** + * 将位置元素的经度和维度也一并返回 + */ + private Boolean withCoord; + + /** + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + */ + private Boolean withDist; + + /** + * 以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + */ + private Boolean withHash; + + /** + * 构造函数 + */ + public GeoSearchArgument() { + } + + /** + * 获取是否将位置元素的经度和维度也一并返回 + * + * @return 是否将位置元素的经度和维度也一并返回 + */ + public Boolean isWithCoord() { + return getWithCoord(); + } + + /** + * 获取是否将位置元素的经度和维度也一并返回 + * + * @return 是否将位置元素的经度和维度也一并返回 + */ + public Boolean getWithCoord() { + return withCoord; + } + + /** + * 设置将位置元素的经度和维度也一并返回 + */ + public void withCoord() { + this.withCoord = true; + } + + /** + * 设置是否将位置元素的经度和维度也一并返回 + * + * @param withCoord + * true / false + */ + public void setWithCoord(final Boolean withCoord) { + this.withCoord = withCoord; + } + + /** + * 获取是否在返回位置元素的同时,将位置元素与中心之间的距离也一并返回 + * + * @return 是否在返回位置元素的同时,将位置元素与中心之间的距离也一并返回 + */ + public Boolean isWithDist() { + return getWithDist(); + } + + /** + * 获取是否在返回位置元素的同时,将位置元素与中心之间的距离也一并返回 + * + * @return 是否在返回位置元素的同时,将位置元素与中心之间的距离也一并返回 + */ + public Boolean getWithDist() { + return withDist; + } + + /** + * 设置在返回位置元素的同时,将位置元素与中心之间的距离也一并返回 + */ + public void withDist() { + this.withDist = true; + } + + /** + * 设置是否在返回位置元素的同时,将位置元素与中心之间的距离也一并返回 + * + * @param withDist + * true / false + */ + public void setWithDist(final Boolean withDist) { + this.withDist = withDist; + } + + /** + * 获取是否返回位置元素经过原始 geohash 编码的有序集合分值 + * + * @return 是否返回位置元素经过原始 geohash 编码的有序集合分值 + */ + public Boolean isWithHash() { + return getWithHash(); + } + + /** + * 获取是否返回位置元素经过原始 geohash 编码的有序集合分值 + * + * @return 是否返回位置元素经过原始 geohash 编码的有序集合分值 + */ + public Boolean getWithHash() { + return withHash; + } + + /** + * 设置返回位置元素经过原始 geohash 编码的有序集合分值 + */ + public void withHash() { + this.withHash = true; + } + + /** + * 设置返回位置元素经过原始 geohash 编码的有序集合分值 + * + * @param withHash + * true / false + */ + public void setWithHash(final Boolean withHash) { + this.withHash = withHash; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(getFromMode() instanceof BaseGeoSearchArgument.FromMember){ + builder.add(Keyword.Geo.FROMMEMBER.name(), getFromMode().toString()); + }else if(getFromMode() instanceof BaseGeoSearchArgument.FromLonLat){ + builder.add(Keyword.Geo.FROMLONLAT.name(), getFromMode().toString()); + } + + if(getPredicate() instanceof BaseGeoSearchArgument.RadiusPredicate){ + builder.add(Keyword.Geo.FROMLONLAT.BYRADIUS.name(), getPredicate().toString()); + }else if(getPredicate() instanceof BaseGeoSearchArgument.BoxPredicate){ + builder.add(Keyword.Geo.FROMLONLAT.BYBOX.name(), getPredicate().toString()); + } + + if(getOrder() != null){ + builder.append(getOrder()); + } + + if(getCount() != null){ + builder.add(Keyword.Common.COUNT, getCount()); + if(Boolean.TRUE.equals(isAny())){ + builder.append(Keyword.Common.ANY); + } + } + + if(Boolean.TRUE.equals(isWithCoord())){ + builder.append(Keyword.Geo.WITHCOORD); + } + + if(Boolean.TRUE.equals(isWithDist())){ + builder.append(Keyword.Geo.WITHDIST); + } + + if(Boolean.TRUE.equals(isWithHash())){ + builder.append(Keyword.Geo.WITHHASH); + } + + return builder.toString(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/GeoSearchStoreArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/GeoSearchStoreArgument.java new file mode 100644 index 000000000..4d1c7dc33 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/GeoSearchStoreArgument.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.redis.core.Keyword; + +/** + * {@code GEOSEARCHSTORE} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class GeoSearchStoreArgument extends BaseGeoSearchArgument { + + private Boolean storeDist; + + /** + * 构造函数 + */ + public GeoSearchStoreArgument() { + } + + public Boolean isStoreDist() { + return getStoreDist(); + } + + public Boolean getStoreDist() { + return storeDist; + } + + public void storeDist() { + this.storeDist = true; + } + + public void setStoreDist(Boolean storeDist) { + this.storeDist = storeDist; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(getFromMode() instanceof BaseGeoSearchArgument.FromMember){ + builder.add(Keyword.Geo.FROMMEMBER.name(), getFromMode().toString()); + }else if(getFromMode() instanceof BaseGeoSearchArgument.FromLonLat){ + builder.add(Keyword.Geo.FROMLONLAT.name(), getFromMode().toString()); + } + + if(getPredicate() instanceof BaseGeoSearchArgument.RadiusPredicate){ + builder.add(Keyword.Geo.FROMLONLAT.BYRADIUS.name(), getPredicate().toString()); + }else if(getPredicate() instanceof BaseGeoSearchArgument.BoxPredicate){ + builder.add(Keyword.Geo.FROMLONLAT.BYBOX.name(), getPredicate().toString()); + } + + if(getOrder() != null){ + builder.append(getOrder()); + } + + if(getCount() != null){ + builder.add(Keyword.Common.COUNT, getCount()); + if(Boolean.TRUE.equals(isAny())){ + builder.append(Keyword.Common.ANY); + } + } + + return builder.toString(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/GetExArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/GetExArgument.java new file mode 100644 index 000000000..428f2d3d3 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/GetExArgument.java @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +/** + * GETEX 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class GetExArgument { + + /** + * 过期时间方式 + */ + private GetExType type; + + /** + * 过期时间 + */ + private Long expires; + + /** + * 构造函数 + */ + public GetExArgument() { + } + + /** + * 构造函数 + * + * @param type + * 过期时间方式 + * @param expires + * 过期时间 + */ + public GetExArgument(final GetExType type, final Long expires) { + this.type = type; + this.expires = expires; + } + + /** + * 返回过期时间方式 + * + * @return 过期时间方式 + */ + public GetExType getType() { + return type; + } + + /** + * 设置过期时间方式 + * + * @param type + * 过期时间方式 + */ + public void seType(final GetExType type) { + this.type = type; + } + + /** + * 返回过期时间 + * + * @return 过期时间 + */ + public Long getExpires() { + return expires; + } + + /** + * 设置过期时间 + * + * @param expires + * 过期时间 + */ + public void setExpires(final Long expires) { + this.expires = expires; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(type != null){ + if(type == GetExType.PERSIST){ + builder.append("PERSIST"); + }else{ + builder.add(type.name(), expires); + } + } + + return builder.build(); + } + + /** + * 过期时间方式 + */ + public enum GetExType { + /** + * 设置指定的过期时间,以秒为单位 + */ + EX, + + /** + * 设置指定的过期 Unix 时间戳,以秒为单位 + */ + EXAT, + + /** + * 设置指定的过期时间,以毫秒为单位 + */ + PX, + + /** + * 设置指定的过期 Unix 时间戳,以毫秒为单位 + */ + PXAT, + + /** + * 设置的键永不过期 + */ + PERSIST + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/HScanArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/HScanArgument.java new file mode 100644 index 000000000..d5cbe4d2f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/HScanArgument.java @@ -0,0 +1,171 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.redis.core.Keyword; +import com.buession.redis.core.Type; + +/** + * {@code HSCAN} 参数基类 + * + * @param + * 模式值类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HScanArgument extends BaseScanArgument { + + /** + * - + */ + private Boolean noValues; + + /** + * 构造函数 + */ + public HScanArgument() { + super(); + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + */ + public HScanArgument(final T pattern) { + super(pattern); + } + + /** + * 构造函数 + * + * @param count + * 返回个数 + */ + public HScanArgument(final int count) { + super(count); + } + + /** + * 构造函数 + * + * @param noValues + * - + */ + public HScanArgument(final Boolean noValues) { + this.noValues = noValues; + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + * @param noValues + * - + */ + public HScanArgument(final T pattern, final Boolean noValues) { + super(pattern); + this.noValues = noValues; + } + + /** + * 构造函数 + * + * @param count + * 返回个数 + * @param noValues + * - + */ + public HScanArgument(final int count, final Boolean noValues) { + super(count); + this.noValues = noValues; + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + * @param count + * 返回个数 + */ + public HScanArgument(final T pattern, final int count) { + super(pattern, count); + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + * @param count + * 返回个数 + * @param noValues + * - + */ + public HScanArgument(final T pattern, final int count, final Boolean noValues) { + super(pattern, count); + this.noValues = noValues; + } + + public Boolean isNoValues() { + return getNoValues(); + } + + public Boolean getNoValues() { + return noValues; + } + + public void noValues() { + this.noValues = true; + } + + public void setNoValues(final Boolean noValues) { + this.noValues = noValues; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(getPattern() != null){ + builder.add(Keyword.Key.MATCH, getPattern()); + } + + if(getCount() != null){ + builder.add(Keyword.Common.COUNT, getCount()); + } + + if(Boolean.TRUE.equals(noValues)){ + builder.append(Keyword.Key.NOVALUES); + } + + return builder.build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/HelloArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/HelloArgument.java new file mode 100644 index 000000000..25a767d30 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/HelloArgument.java @@ -0,0 +1,247 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.core.validator.Validate; +import com.buession.redis.core.Keyword; + +/** + * {@code HELLO} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class HelloArgument { + + /** + * 协议版本 + */ + private Integer protoVer; + + /** + * 用户名 + */ + private String username; + + /** + * 密码 + */ + private String password; + + /** + * 客户端名称 + */ + private String clientName; + + /** + * 构造函数 + */ + public HelloArgument() { + } + + /** + * 构造函数 + * + * @param protoVer + * 协议版本 + */ + public HelloArgument(final Integer protoVer) { + this.protoVer = protoVer; + } + + /** + * 构造函数 + * + * @param password + * 密码 + */ + public HelloArgument(final String password) { + this.password = password; + } + + /** + * 构造函数 + * + * @param username + * 用户名 + * @param password + * 密码 + */ + public HelloArgument(final String username, final String password) { + this(password); + this.username = username; + } + + /** + * 构造函数 + * + * @param protoVer + * 协议版本 + * @param password + * 密码 + */ + public HelloArgument(final Integer protoVer, final String password) { + this(protoVer); + this.password = password; + } + + /** + * 构造函数 + * + * @param protoVer + * 协议版本 + * @param username + * 用户名 + * @param password + * 密码 + */ + public HelloArgument(final Integer protoVer, final String username, final String password) { + this(protoVer); + setPassword(username, password); + } + + /** + * 构造函数 + * + * @param protoVer + * 协议版本 + * @param username + * 用户名 + * @param password + * 密码 + * @param clientName + * 客户端名称 + */ + public HelloArgument(final Integer protoVer, final String username, final String password, + final String clientName) { + this(protoVer, password, username); + this.clientName = clientName; + } + + /** + * 返回协议版本 + * + * @return 协议版本 + */ + public Integer getProtoVer() { + return protoVer; + } + + /** + * 设置协议版本 + * + * @param protoVer + * 协议版本 + */ + public void setProtoVer(final Integer protoVer) { + this.protoVer = protoVer; + } + + /** + * 返回用户名 + * + * @return 用户名 + */ + public String getUsername() { + return username; + } + + /** + * 返回密码 + * + * @return 密码 + */ + public String getPassword() { + return password; + } + + /** + * 设置密码 + * + * @param password + * 密码 + */ + public void setPassword(final String password) { + this.password = password; + } + + /** + * 设置密码 + * + * @param username + * 用户名 + * @param password + * 密码 + */ + public void setPassword(final String username, String password) { + this.password = password; + if(Validate.hasText(password)){ + this.username = username; + } + } + + /** + * 返回客户端名称 + * + * @return 客户端名称 + */ + public String getClientName() { + return clientName; + } + + /** + * 设置 + * + * @param clientName + * 客户端名称 + */ + public void setClientName(String clientName) { + this.clientName = clientName; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(protoVer != null){ + builder.append(protoVer); + } + + if(Validate.hasText(password)){ + builder.append(Keyword.Common.AUTH); + if(Validate.hasText(username)){ + builder.append(username); + } + builder.append(password); + } + + if(Validate.hasText(clientName)){ + builder.add(Keyword.Common.SETNAME, clientName); + } + + return builder.build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/LPosArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/LPosArgument.java new file mode 100644 index 000000000..f954c23b0 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/LPosArgument.java @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +/** + * {@code LPOS} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LPosArgument { + + /** + * 返回第几个匹配的元素 + */ + private Integer rank; + + /** + * 查找成员个数 + */ + private Integer maxLen; + + /** + * 构造函数 + */ + public LPosArgument() { + } + + /** + * 构造函数 + * + * @param rank + * 返回第几个匹配的元素 + */ + public LPosArgument(final Integer rank) { + this.rank = rank; + } + + /** + * 构造函数 + * + * @param rank + * 返回第几个匹配的元素 + * @param maxLen + * 查找成员个数 + */ + public LPosArgument(final Integer rank, final Integer maxLen) { + this(rank); + this.maxLen = maxLen; + } + + /** + * 返回第几个匹配的元素 + * + * @return 第几个匹配的元素 + */ + public Integer getRank() { + return rank; + } + + /** + * 设置 返回第几个匹配的元素 + * + * @param rank + * 返回第几个匹配的元素 + */ + public void setRank(final Integer rank) { + this.rank = rank; + } + + /** + * 返回查找成员个数 + * + * @return 查找成员个数 + */ + public Integer getMaxLen() { + return maxLen; + } + + /** + * 设置查找成员个数 + * + * @param maxLen + * 查找成员个数 + */ + public void setMaxLen(final Integer maxLen) { + this.maxLen = maxLen; + } + + @Override + public String toString() { + return ArgumentStringBuilder.create() + .add("RANK", rank) + .add("MAXLEN", maxLen) + .build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/MaxLenMinId.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/MaxLenMinId.java new file mode 100644 index 000000000..586917a2a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/MaxLenMinId.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.redis.core.StreamEntryId; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public interface MaxLenMinId { + + SubCommand getSubCommand(); + + T getValue(); + + abstract class BaseMaxLenMinId implements MaxLenMinId { + + private final SubCommand subCommand; + + private final T value; + + public BaseMaxLenMinId(final SubCommand subCommand, final T value) { + this.subCommand = subCommand; + this.value = value; + } + + @Override + public SubCommand getSubCommand() { + return subCommand; + } + + @Override + public T getValue() { + return value; + } + + } + + final class MaxLen extends BaseMaxLenMinId { + + public MaxLen(final Long value) { + super(SubCommand.MAXLEN, value); + } + + } + + final class MinId extends BaseMaxLenMinId { + + public MinId(final StreamEntryId value) { + super(SubCommand.MINID, value); + } + + } + + enum SubCommand { + MAXLEN, + + MINID + } + +} diff --git a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/AbstractPoolConfiguration.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/MigrateArgument.java similarity index 62% rename from buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/AbstractPoolConfiguration.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/MigrateArgument.java index 3cace8ed0..635537691 100644 --- a/buession-jdbc/src/main/java/com/buession/jdbc/datasource/config/AbstractPoolConfiguration.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/MigrateArgument.java @@ -19,81 +19,54 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.jdbc.datasource.config; +package com.buession.redis.core.command.args; -import java.util.Properties; +import com.buession.core.validator.Validate; +import com.buession.redis.core.Keyword; /** - * 连接池配置基类 + * {@code MIGRATE} 命令参数 * * @author Yong.Teng - * @since 1.3.2 + * @since 3.0.0 */ -public abstract class AbstractPoolConfiguration implements PoolConfiguration { +public class MigrateArgument { /** - * 驱动名 + * 迁移模式 */ - @Deprecated - private String driverClassName; + private Mode mode; /** - * 连接 URL + * 用户名 */ - @Deprecated - private String url; - - @Deprecated private String username; - @Deprecated - private String password; - - private Properties properties; - - /** - * 返回驱动名 - * - * @return 驱动名 - */ - @Deprecated - public String getDriverClassName() { - return driverClassName; - } - /** - * 设置驱动名 - * - * @param driverClassName - * 驱动名 + * 密码 */ - @Deprecated - public void setDriverClassName(String driverClassName) { - - } + private String password; /** - * 返回连接 URL + * 返回迁移模式 * - * @return 连接 URL + * @return 迁移模式 */ - @Deprecated - public String getUrl() { - return url; + public Mode getMode() { + return mode; } /** - * 设置连接 URL + * 设置迁移模式 * - * @param url - * 连接 URL + * @param mode + * 迁移模式 */ - @Deprecated - public void setUrl(String url) { - + public void setMode(Mode mode) { + this.mode = mode; } /** @@ -101,7 +74,6 @@ public void setUrl(String url) { * * @return 用户名 */ - @Deprecated public String getUsername() { return username; } @@ -112,9 +84,8 @@ public String getUsername() { * @param username * 用户名 */ - @Deprecated public void setUsername(String username) { - + this.username = username; } /** @@ -122,7 +93,6 @@ public void setUsername(String username) { * * @return 密码 */ - @Deprecated public String getPassword() { return password; } @@ -133,19 +103,43 @@ public String getPassword() { * @param password * 密码 */ - @Deprecated public void setPassword(String password) { - + this.password = password; } @Override - public Properties getProperties() { - return properties; + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(mode != null){ + builder.append(mode); + } + + if(Validate.hasText(password)){ + if(Validate.hasText(username)){ + builder.add(Keyword.Common.AUTH2, username); + }else{ + builder.append(Keyword.Common.AUTH); + } + builder.append(password); + } + + return builder.build(); } - @Override - public void setProperties(Properties properties) { - this.properties = properties; + /** + * 迁移模式 + */ + public enum Mode { + /** + * 将 key 原子性地从当前实例传送到目标实例的指定数据库上,不移除源实例上的 key + */ + COPY, + + /** + * 将 key 原子性地从当前实例传送到目标实例的指定数据库上,替换目标实例上已存在的 key + */ + REPLACE } } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/RestoreArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/RestoreArgument.java new file mode 100644 index 000000000..3e137c986 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/RestoreArgument.java @@ -0,0 +1,225 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.redis.core.Keyword; + +/** + * {@code RESTORE} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class RestoreArgument { + + /** + * 是否替换已存在 key + */ + private Boolean replace; + + /** + * If the ABSTTL modifier was used, + * ttl should represent an absolute Unix timestamp (in milliseconds) in which the key will expire + */ + private Boolean absTtl; + + private Long idleTime; + + private Long frequency; + + /** + * 构造函数 + */ + public RestoreArgument() { + } + + /** + * 构造函数 + * + * @param replace + * 是否替换已存在 key + */ + public RestoreArgument(final Boolean replace) { + this.replace = replace; + } + + /** + * 构造函数 + * + * @param replace + * 是否替换已存在 key + * @param absTtl + * - + */ + public RestoreArgument(final Boolean replace, final Boolean absTtl) { + this(replace); + this.absTtl = absTtl; + } + + /** + * 构造函数 + * + * @param replace + * 是否替换已存在 key + * @param idleTime + * - + * @param frequency + * - + */ + public RestoreArgument(final Boolean replace, final Long idleTime, final Long frequency) { + this(replace); + this.idleTime = idleTime; + this.frequency = frequency; + } + + /** + * 构造函数 + * + * @param replace + * 是否替换已存在 key + * @param absTtl + * - + * @param idleTime + * - + * @param frequency + * - + */ + public RestoreArgument(final Boolean replace, final Boolean absTtl, final Long idleTime, final Long frequency) { + this(replace, idleTime, frequency); + this.absTtl = absTtl; + } + + /** + * 获取是否替换已存在 key + * + * @return 是否替换已存在 key + */ + public Boolean isReplace() { + return getReplace(); + } + + /** + * 获取是否替换已存在 key + * + * @return 是否替换已存在 key + */ + public Boolean getReplace() { + return replace; + } + + /** + * 替换已存在 key + */ + public void replace() { + this.replace = true; + } + + /** + * 设置是否替换已存在 key + * + * @param replace + * true / false + */ + public void setReplace(final Boolean replace) { + this.replace = replace; + } + + /** + * If the ABSTTL modifier was used, + * ttl should represent an absolute Unix timestamp (in milliseconds) in which the key will expire + * + * @return If the ABSTTL modifier was used, + * ttl should represent an absolute Unix timestamp (in milliseconds) in which the key will expire + */ + public Boolean isAbsTtl() { + return getAbsTtl(); + } + + /** + * If the ABSTTL modifier was used, + * ttl should represent an absolute Unix timestamp (in milliseconds) in which the key will expire + * + * @return If the ABSTTL modifier was used, + * ttl should represent an absolute Unix timestamp (in milliseconds) in which the key will expire + */ + public Boolean getAbsTtl() { + return absTtl; + } + + public void absTtl() { + this.absTtl = true; + } + + /** + * f the ABSTTL modifier was used, + * ttl should represent an absolute Unix timestamp (in milliseconds) in which the key will expire + * + * @param absTtl + * true / false + */ + public void setAbsTtl(final Boolean absTtl) { + this.absTtl = absTtl; + } + + public Long getIdleTime() { + return idleTime; + } + + public void setIdleTime(final Long idleTime) { + this.idleTime = idleTime; + } + + public Long getFrequency() { + return frequency; + } + + public void setFrequency(final Long frequency) { + this.frequency = frequency; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(Boolean.TRUE.equals(replace)){ + builder.append(Keyword.Common.REPLACE); + } + + if(Boolean.TRUE.equals(absTtl)){ + builder.append(Keyword.Common.ABSTTL); + } + + if(idleTime != null){ + builder.add(Keyword.Common.IDLETIME, idleTime); + } + + if(frequency != null){ + builder.add(Keyword.Common.FREQ, frequency); + } + + return builder.build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ScanArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ScanArgument.java new file mode 100644 index 000000000..7a0bd3200 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/ScanArgument.java @@ -0,0 +1,366 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.redis.core.Keyword; +import com.buession.redis.core.Type; + +/** + * {@code SCAN} 参数基类 + * + * @param + * 模式值类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class ScanArgument extends BaseScanArgument { + + /** + * 类型 + */ + private Type type; + + /** + * 构造函数 + */ + public ScanArgument() { + super(); + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + */ + public ScanArgument(final T pattern) { + super(pattern); + } + + /** + * 构造函数 + * + * @param count + * 返回个数 + */ + public ScanArgument(final int count) { + super(count); + } + + /** + * 构造函数 + * + * @param type + * 类型 + */ + public ScanArgument(final Type type) { + this.type = type; + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + * @param type + * 类型 + */ + public ScanArgument(final T pattern, final Type type) { + super(pattern); + this.type = type; + } + + /** + * 构造函数 + * + * @param count + * 返回个数 + * @param type + * 类型 + */ + public ScanArgument(final int count, final Type type) { + super(count); + this.type = type; + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + * @param count + * 返回个数 + */ + public ScanArgument(final T pattern, final int count) { + super(pattern, count); + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + * @param count + * 返回个数 + * @param type + * 类型 + */ + public ScanArgument(final T pattern, final int count, final Type type) { + super(pattern, count); + this.type = type; + } + + /** + * 返回类型 + * + * @return 类型 + */ + public Type getType() { + return type; + } + + /** + * 设置类型 + * + * @param type + * 类型 + */ + public void setType(final Type type) { + this.type = type; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(getPattern() != null){ + builder.add(Keyword.Key.MATCH, getPattern()); + } + + if(getCount() != null){ + builder.add(Keyword.Common.COUNT, getCount()); + } + + if(type != null){ + builder.add(Keyword.Common.TYPE, type); + } + + return builder.build(); + } + + public static class StringScanArgument extends ScanArgument { + + /** + * 构造函数 + */ + public StringScanArgument() { + super(); + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + */ + public StringScanArgument(final String pattern) { + super(pattern); + } + + /** + * 构造函数 + * + * @param count + * 返回个数 + */ + public StringScanArgument(final int count) { + super(count); + } + + /** + * 构造函数 + * + * @param type + * 类型 + */ + public StringScanArgument(final Type type) { + super(type); + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + * @param type + * 类型 + */ + public StringScanArgument(final String pattern, final Type type) { + super(pattern, type); + } + + /** + * 构造函数 + * + * @param count + * 返回个数 + * @param type + * 类型 + */ + public StringScanArgument(final int count, final Type type) { + super(count, type); + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + * @param count + * 返回个数 + */ + public StringScanArgument(final String pattern, final int count) { + super(pattern, count); + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + * @param count + * 返回个数 + * @param type + * 类型 + */ + public StringScanArgument(final String pattern, final int count, final Type type) { + super(pattern, count, type); + } + + @Override + public String toString() { + return super.toString(); + } + + } + + public static class ByteScanArgument extends ScanArgument { + + /** + * 构造函数 + */ + public ByteScanArgument() { + super(); + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + */ + public ByteScanArgument(final byte[] pattern) { + super(pattern); + } + + /** + * 构造函数 + * + * @param count + * 返回个数 + */ + public ByteScanArgument(final int count) { + super(count); + } + + /** + * 构造函数 + * + * @param type + * 类型 + */ + public ByteScanArgument(final Type type) { + super(type); + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + * @param type + * 类型 + */ + public ByteScanArgument(final byte[] pattern, final Type type) { + super(pattern, type); + } + + /** + * 构造函数 + * + * @param count + * 返回个数 + * @param type + * 类型 + */ + public ByteScanArgument(final int count, final Type type) { + super(count, type); + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + * @param count + * 返回个数 + */ + public ByteScanArgument(final byte[] pattern, final int count) { + super(pattern, count); + } + + /** + * 构造函数 + * + * @param pattern + * 模式 + * @param count + * 返回个数 + * @param type + * 类型 + */ + public ByteScanArgument(final byte[] pattern, final int count, final Type type) { + super(pattern, count, type); + } + + @Override + public String toString() { + return super.toString(); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/SetArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/SetArgument.java new file mode 100644 index 000000000..ea69eafdd --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/SetArgument.java @@ -0,0 +1,275 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.redis.core.Keyword; +import com.buession.redis.core.NxXx; + +/** + * {@code SET} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class SetArgument { + + /** + * 过期时间方式 + */ + private SetType type; + + /** + * 过期时间 + */ + private Long expires; + + /** + * 只有键 key 不存在/存在的时候才会设置 key 的值 + */ + private NxXx nxXx; + + /** + * 是否获取 key 的过期时间 + */ + private Boolean keepTtl; + + /** + * 构造函数 + */ + public SetArgument() { + } + + /** + * 构造函数 + * + * @param type + * 过期时间方式 + * @param expires + * 过期时间 + */ + public SetArgument(final SetType type, final Long expires) { + this.type = type; + this.expires = expires; + } + + /** + * 构造函数 + * + * @param type + * 过期时间方式 + * @param expires + * 过期时间 + * @param nxXx + * 只有键 key 不存在/存在的时候才会设置 key 的值 + */ + public SetArgument(final SetType type, final Long expires, final NxXx nxXx) { + this(type, expires); + this.nxXx = nxXx; + } + + /** + * 构造函数 + * + * @param nxXx + * 只有键 key 不存在/存在的时候才会设置 key 的值 + */ + public SetArgument(final NxXx nxXx) { + this.nxXx = nxXx; + } + + /** + * 构造函数 + * + * @param keepTtl + * 是否获取 key 的过期时间 + */ + public SetArgument(final Boolean keepTtl) { + this.keepTtl = keepTtl; + } + + /** + * 构造函数 + * + * @param nxXx + * 只有键 key 不存在/存在的时候才会设置 key 的值 + * @param keepTtl + * 是否获取 key 的过期时间 + */ + public SetArgument(final NxXx nxXx, final Boolean keepTtl) { + this.nxXx = nxXx; + this.keepTtl = keepTtl; + } + + /** + * 构造函数 + * + * @param type + * 过期时间方式 + * @param expires + * 过期时间 + * @param nxXx + * 只有键 key 不存在/存在的时候才会设置 key 的值 + * @param keepTtl + * 是否获取 key 的过期时间 + */ + public SetArgument(final SetType type, final long expires, final NxXx nxXx, final Boolean keepTtl) { + this(type, expires, nxXx); + this.keepTtl = keepTtl; + } + + /** + * 返回过期时间方式 + * + * @return 过期时间方式 + */ + public SetType getType() { + return type; + } + + /** + * 设置过期时间方式 + * + * @param type + * 过期时间方式 + */ + public void setType(final SetType type) { + this.type = type; + } + + /** + * 返回过期时间 + * + * @return 过期时间 + */ + public Long getExpires() { + return expires; + } + + /** + * 设置过期时间 + * + * @param expires + * 过期时间 + */ + public void setExpires(final Long expires) { + this.expires = expires; + } + + /** + * 返回只有键 key 不存在/存在的时候才会设置 key 的值 + * + * @return 只有键 key 不存在/存在的时候才会设置 key 的值 + */ + public NxXx getNxXx() { + return nxXx; + } + + /** + * 设置只有键 key 不存在/存在的时候才会设置 key 的值 + * + * @param nxXx + * 只有键 key 不存在/存在的时候才会设置 key 的值 + */ + public void setNxXx(final NxXx nxXx) { + this.nxXx = nxXx; + } + + /** + * 返回是否获取 key 的过期时间 + * + * @return 是否获取 key 的过期时间 + */ + public Boolean isKeepTtl() { + return getKeepTtl(); + } + + /** + * 返回是否获取 key 的过期时间 + * + * @return 是否获取 key 的过期时间 + */ + public Boolean getKeepTtl() { + return keepTtl; + } + + /** + * 设置获取 key 的过期时间 + */ + public void keepTtl() { + this.keepTtl = true; + } + + /** + * 设置是否获取 key 的过期时间 + * + * @param keepTtl + * 是否获取 key 的过期时间 + */ + public void setKeepTtl(final Boolean keepTtl) { + this.keepTtl = keepTtl; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(type != null){ + builder.append(type); + } + builder.append(expires).append(nxXx); + + if(Boolean.TRUE.equals(keepTtl)){ + builder.append(Keyword.Common.KEEPTTL); + } + + return builder.build(); + } + + /** + * 设置过期时间方式 + */ + public enum SetType { + /** + * 设置指定的过期时间,以秒为单位 + */ + EX, + + /** + * 设置指定的过期 Unix 时间戳,以秒为单位 + */ + EXAT, + + /** + * 设置指定的过期时间,以毫秒为单位 + */ + PX, + + /** + * 设置指定的过期 Unix 时间戳,以毫秒为单位 + */ + PXAT + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/SortArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/SortArgument.java new file mode 100644 index 000000000..8152cb4fe --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/SortArgument.java @@ -0,0 +1,382 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +import com.buession.lang.Order; +import com.buession.redis.core.Limit; +import com.buession.redis.utils.SafeEncoder; + +/** + * {@code SORT} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class SortArgument { + + private String by; + + /** + * 排序方式 + */ + private Order order; + + /** + * 结果限制 + */ + private Limit limit; + + private String[] getPatterns; + + private Boolean alpha; + + /** + * 构造函数 + */ + public SortArgument() { + } + + /** + * 构造函数 + * + * @param by + * - + */ + public SortArgument(final String by) { + this.by = by; + } + + /** + * 构造函数 + * + * @param by + * - + */ + public SortArgument(final byte[] by) { + this.by = SafeEncoder.encode(by); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + */ + public SortArgument(final String by, final String[] gets) { + this(by); + this.getPatterns = gets; + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + */ + public SortArgument(final byte[] by, final byte[][] gets) { + this(by); + this.getPatterns = SafeEncoder.encode(gets); + } + + /** + * 构造函数 + * + * @param by + * - + * @param order + * 排序方式 + */ + public SortArgument(final String by, final Order order) { + this(by); + this.order = order; + } + + /** + * 构造函数 + * + * @param by + * - + * @param order + * 排序方式 + */ + public SortArgument(final byte[] by, final Order order) { + this(by); + this.order = order; + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + */ + public SortArgument(final String by, final String[] gets, final Order order) { + this(by, gets); + this.order = order; + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + */ + public SortArgument(final byte[] by, final byte[][] gets, final Order order) { + this(by, gets); + this.order = order; + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param limit + * 结果限制 + */ + public SortArgument(final String by, final String[] gets, final Limit limit) { + this(by, gets); + this.limit = limit; + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param limit + * 结果限制 + */ + public SortArgument(final byte[] by, final byte[][] gets, final Limit limit) { + this(by, gets); + this.limit = limit; + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + * @param limit + * 结果限制 + */ + public SortArgument(final String by, final String[] gets, final Order order, final Limit limit) { + this(by, gets, order); + this.limit = limit; + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + * @param limit + * 结果限制 + */ + public SortArgument(final byte[] by, final byte[][] gets, final Order order, final Limit limit) { + this(by, gets, order); + this.limit = limit; + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + * @param limit + * 结果限制 + * @param alpha + * - + */ + public SortArgument(final String by, final String[] gets, final Order order, final Limit limit, + final Boolean alpha) { + this(by, gets, order, limit); + this.alpha = alpha; + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + * @param limit + * 结果限制 + * @param alpha + * - + */ + public SortArgument(final byte[] by, final byte[][] gets, final Order order, final Limit limit, + final Boolean alpha) { + this(by, gets, order, limit); + this.alpha = alpha; + } + + public String getBy() { + return by; + } + + public byte[] getByAsBytes() { + return SafeEncoder.encode(by); + } + + public void setBy(final String by) { + this.by = by; + } + + public void setBy(final byte[] by) { + this.by = SafeEncoder.encode(by); + } + + /** + * 获取排序方式 + * + * @return 排序方式 + */ + public Order getOrder() { + return order; + } + + /** + * 设置排序方式 + * + * @param order + * 排序方式 + */ + public void setOrder(final Order order) { + this.order = order; + } + + /** + * 获取返回结果限制 + * + * @return 返回结果限制 + */ + public Limit getLimit() { + return limit; + } + + /** + * 设置结果限制 + * + * @param limit + * 结果限制 + */ + public void setLimit(final Limit limit) { + this.limit = limit; + } + + public String[] getGetPatterns() { + return getPatterns; + } + + public byte[][] getGetPatternsAsBytes() { + return SafeEncoder.encode(getPatterns); + } + + public void setGetPatterns(final String[] getPatterns) { + this.getPatterns = getPatterns; + } + + public void setGetPatterns(final byte[][] getPatterns) { + this.getPatterns = SafeEncoder.encode(getPatterns); + } + + public Boolean isAlpha() { + return getAlpha(); + } + + public Boolean getAlpha() { + return alpha; + } + + public void alpha() { + this.alpha = true; + } + + public void setAlpha(final Boolean alpha) { + this.alpha = alpha; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(by != null){ + builder.add("BY", by); + } + + if(limit != null){ + builder.add("LIMIT", limit.getOffset() + ' ' + limit.getCount()); + } + + if(getPatterns != null){ + for(final String pattern : getPatterns){ + builder.add("GET", pattern); + } + } + + if(order != null){ + builder.append(order); + } + + if(Boolean.TRUE.equals(alpha)){ + builder.append("ALPHA"); + } + + return builder.build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/XAddArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/XAddArgument.java new file mode 100644 index 000000000..3a7d34d91 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/XAddArgument.java @@ -0,0 +1,256 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +/** + * {@code XADD} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class XAddArgument { + + private MaxLenMinId maxLenMinId; + + private ApproximateExactTrimming approximateExactTrimming; + + private Boolean noMkStream; + + private Long limit; + + /** + * 构造函数 + */ + public XAddArgument() { + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + */ + public XAddArgument(final MaxLenMinId maxLenMinId) { + this.maxLenMinId = maxLenMinId; + } + + /** + * 构造函数 + * + * @param noMkStream + * - + */ + public XAddArgument(final Boolean noMkStream) { + this.noMkStream = noMkStream; + } + + /** + * 构造函数 + * + * @param limit + * - + */ + public XAddArgument(final Long limit) { + this.limit = limit; + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param noMkStream + * - + */ + public XAddArgument(final MaxLenMinId maxLenMinId, final Boolean noMkStream) { + this(maxLenMinId); + this.noMkStream = noMkStream; + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param limit + * - + */ + public XAddArgument(final MaxLenMinId maxLenMinId, final Long limit) { + this(maxLenMinId); + this.limit = limit; + } + + /** + * 构造函数 + * + * @param noMkStream + * - + * @param limit + * - + */ + public XAddArgument(final Boolean noMkStream, final Long limit) { + this(noMkStream); + this.limit = limit; + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param noMkStream + * - + * @param limit + * - + */ + public XAddArgument(final MaxLenMinId maxLenMinId, final Boolean noMkStream, final Long limit) { + this(maxLenMinId, noMkStream); + this.limit = limit; + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + */ + public XAddArgument(final MaxLenMinId maxLenMinId, final ApproximateExactTrimming approximateExactTrimming) { + this(maxLenMinId); + this.approximateExactTrimming = approximateExactTrimming; + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + */ + public XAddArgument(final MaxLenMinId maxLenMinId, final ApproximateExactTrimming approximateExactTrimming, + final Boolean noMkStream) { + this(maxLenMinId, approximateExactTrimming); + this.noMkStream = noMkStream; + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param limit + * - + */ + public XAddArgument(final MaxLenMinId maxLenMinId, final ApproximateExactTrimming approximateExactTrimming, + final Long limit) { + this(maxLenMinId, approximateExactTrimming); + this.limit = limit; + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + * @param limit + * - + */ + public XAddArgument(final MaxLenMinId maxLenMinId, final ApproximateExactTrimming approximateExactTrimming, + final Boolean noMkStream, final Long limit) { + this(maxLenMinId, approximateExactTrimming, noMkStream); + this.limit = limit; + } + + public MaxLenMinId getMaxLenMinId() { + return maxLenMinId; + } + + public void setMaxLenMinId(final MaxLenMinId maxLenMinId) { + this.maxLenMinId = maxLenMinId; + } + + public ApproximateExactTrimming getApproximateExactTrimming() { + return approximateExactTrimming; + } + + public void setApproximateExactTrimming(final ApproximateExactTrimming approximateExactTrimming) { + this.approximateExactTrimming = approximateExactTrimming; + } + + public Boolean isNoMkStream() { + return getNoMkStream(); + } + + public Boolean getNoMkStream() { + return noMkStream; + } + + public void noMkStream() { + this.noMkStream = true; + } + + public void setNoMkStream(final Boolean noMkStream) { + this.noMkStream = noMkStream; + } + + public Long getLimit() { + return limit; + } + + public void setLimit(final Long limit) { + this.limit = limit; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(maxLenMinId != null){ + builder.add(maxLenMinId.getSubCommand().name(), (approximateExactTrimming != null ? + approximateExactTrimming.getValue() + " " : "") + maxLenMinId.getValue()); + } + + if(Boolean.TRUE.equals(noMkStream)){ + builder.append("NOMKSTREAM"); + } + + if(limit != null){ + builder.add("LIMIT", limit); + } + + return builder.build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/XClaimArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/XClaimArgument.java new file mode 100644 index 000000000..ecbf34f59 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/XClaimArgument.java @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +/** + * {@code XCLAIM} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class XClaimArgument { + + private IdleType idleType; + + private Long idleTime; + + private Integer retryCount; + + private Boolean force; + + public XClaimArgument(final IdleType idleType, final Long idleTime) { + this.idleType = idleType; + this.idleTime = idleTime; + } + + public XClaimArgument(final Integer retryCount) { + this.retryCount = retryCount; + } + + public XClaimArgument(final Boolean force) { + this.force = force; + } + + public XClaimArgument(final IdleType idleType, final Long idleTime, final Integer retryCount) { + this(idleType, idleTime); + this.retryCount = retryCount; + } + + public XClaimArgument(final IdleType idleType, final Long idleTime, final Boolean force) { + this(idleType, idleTime); + this.force = force; + } + + public XClaimArgument(final IdleType idleType, final Long idleTime, final Integer retryCount, final Boolean force) { + this(idleType, idleTime, retryCount); + this.force = force; + } + + public void idelTime(final Long idleTime) { + this.idleType = IdleType.IDLE; + this.idleTime = idleTime; + } + + public void unixTime(final Long unixTime) { + this.idleType = IdleType.UNIX_TIME; + this.idleTime = unixTime; + } + + public IdleType getIdleType() { + return idleType; + } + + public void setIdleType(final IdleType idleType) { + this.idleType = idleType; + } + + public Long getIdleTime() { + return idleTime; + } + + public void setIdleTime(final Long idleTime) { + this.idleTime = idleTime; + } + + public Integer getRetryCount() { + return retryCount; + } + + public void setRetryCount(final Integer retryCount) { + this.retryCount = retryCount; + } + + public Boolean isForce() { + return getForce(); + } + + public Boolean getForce() { + return force; + } + + public void force() { + this.force = true; + } + + public void setForce(final Boolean force) { + this.force = force; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(idleType != null){ + if(idleType == IdleType.IDLE){ + builder.add("IDLE", idleTime); + }else if(idleType == IdleType.UNIX_TIME){ + builder.add("TIME", idleTime); + } + } + + if(retryCount != null){ + builder.add("RETRYCOUNT", retryCount); + } + + if(Boolean.TRUE.equals(force)){ + builder.append("FORCE"); + } + + return builder.build(); + } + + /** + * 设置过期时间方式 + */ + public enum IdleType { + + IDLE, + + UNIX_TIME + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/XReadArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/XReadArgument.java new file mode 100644 index 000000000..99673e238 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/XReadArgument.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +/** + * {@code XREAD} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class XReadArgument { + + /** + * 返回数量 + */ + private Integer count; + + /** + * 阻塞时间(单位:毫秒) + */ + private Integer block; + + /** + * 返回数量 + * + * @return 返回数量 + */ + public Integer getCount() { + return count; + } + + /** + * 设置返回数量 + * + * @param count + * 返回数量 + */ + public void setCount(Integer count) { + this.count = count; + } + + /** + * 返回阻塞时间(单位:毫秒) + * + * @return 阻塞时间 + */ + public Integer getBlock() { + return block; + } + + /** + * 设置阻塞时间 + * + * @param block + * 阻塞时间(单位:毫秒) + */ + public void setBlock(Integer block) { + this.block = block; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(count != null){ + builder.add("COUNT", count); + } + + if(block != null){ + builder.add("BLOCK", block); + } + + return builder.build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/XReadGroupArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/XReadGroupArgument.java new file mode 100644 index 000000000..40c9ee808 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/XReadGroupArgument.java @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +/** + * {@code XREADGROUP} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class XReadGroupArgument { + + /** + * 返回数量 + */ + private Integer count; + + /** + * 阻塞时间(单位:毫秒) + */ + private Integer block; + + private Boolean noAck; + + /** + * 返回数量 + * + * @return 返回数量 + */ + public Integer getCount() { + return count; + } + + /** + * 设置返回数量 + * + * @param count + * 返回数量 + */ + public void setCount(Integer count) { + this.count = count; + } + + /** + * 返回阻塞时间(单位:毫秒) + * + * @return 阻塞时间 + */ + public Integer getBlock() { + return block; + } + + /** + * 设置阻塞时间 + * + * @param block + * 阻塞时间(单位:毫秒) + */ + public void setBlock(Integer block) { + this.block = block; + } + + public Boolean isNoAck() { + return getNoAck(); + } + + public Boolean getNoAck() { + return noAck; + } + + public void noAck() { + this.noAck = true; + } + + public void setNoAck(Boolean noAck) { + this.noAck = noAck; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(count != null){ + builder.add("COUNT", count); + } + + if(block != null){ + builder.add("BLOCK", block); + } + + if(noAck != null){ + builder.append("NOACK"); + } + + return builder.build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/XTrimArgument.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/XTrimArgument.java new file mode 100644 index 000000000..89a868d82 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/XTrimArgument.java @@ -0,0 +1,149 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command.args; + +/** + * {@code XTRIM} 命令参数 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class XTrimArgument { + + private MaxLenMinId maxLenMinId; + + private ApproximateExactTrimming approximateExactTrimming; + + private Long limit; + + /** + * 构造函数 + */ + public XTrimArgument() { + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + */ + public XTrimArgument(final MaxLenMinId maxLenMinId) { + this.maxLenMinId = maxLenMinId; + } + + /** + * 构造函数 + * + * @param limit + * - + */ + public XTrimArgument(final Long limit) { + this.limit = limit; + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + */ + public XTrimArgument(final MaxLenMinId maxLenMinId, final ApproximateExactTrimming approximateExactTrimming) { + this(maxLenMinId); + this.approximateExactTrimming = approximateExactTrimming; + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param limit + * - + */ + public XTrimArgument(final MaxLenMinId maxLenMinId, final Long limit) { + this(maxLenMinId); + this.limit = limit; + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param limit + * - + */ + public XTrimArgument(final MaxLenMinId maxLenMinId, final ApproximateExactTrimming approximateExactTrimming, + final Long limit) { + this(maxLenMinId, approximateExactTrimming); + this.limit = limit; + } + + public MaxLenMinId getMaxLenMinId() { + return maxLenMinId; + } + + public void setMaxLenMinId(final MaxLenMinId maxLenMinId) { + this.maxLenMinId = maxLenMinId; + } + + public ApproximateExactTrimming getApproximateExactTrimming() { + return approximateExactTrimming; + } + + public void setApproximateExactTrimming(final ApproximateExactTrimming approximateExactTrimming) { + this.approximateExactTrimming = approximateExactTrimming; + } + + public Long getLimit() { + return limit; + } + + public void setLimit(final Long limit) { + this.limit = limit; + } + + @Override + public String toString() { + final ArgumentStringBuilder builder = ArgumentStringBuilder.create(); + + if(maxLenMinId != null){ + builder.add(maxLenMinId.getSubCommand().name(), (approximateExactTrimming != null ? + approximateExactTrimming.getValue() + " " : "") + maxLenMinId.getValue()); + } + + if(limit != null){ + builder.add("LIMIT", limit); + } + + return builder.build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/package-info.java new file mode 100644 index 000000000..d9e17acf9 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/args/package-info.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + * @since 3.0.0 + */ +package com.buession.redis.core.command.args; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/command/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/package-info.java new file mode 100644 index 000000000..ab2d5efd6 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/command/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.core.command; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/Converters.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/Converters.java new file mode 100644 index 000000000..c40bd7e79 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/Converters.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert; + +import com.buession.core.converter.ArrayConverter; +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.ListSetConverter; +import com.buession.core.converter.MapConverter; +import com.buession.core.converter.SetConverter; +import com.buession.core.converter.SetListConverter; +import com.buession.redis.utils.SafeEncoder; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public interface Converters { + + static ArrayConverter objectArrayToStringArrayConverter() { + return new ArrayConverter<>((o)->o == null ? null : o.toString(), String.class); + } + + static ArrayConverter objectArrayToBinaryArrayConverter() { + return new ArrayConverter<>((o)->o == null ? null : SafeEncoder.encode(o.toString()), byte[].class); + } + + static ListConverter listStringToBinary() { + return new ListConverter<>(SafeEncoder::encode); + } + + static ListConverter listBinaryToString() { + return new ListConverter<>(SafeEncoder::encode); + } + + static SetConverter setStringToBinary() { + return new SetConverter<>(SafeEncoder::encode); + } + + static SetConverter setBinaryToString() { + return new SetConverter<>(SafeEncoder::encode); + } + + static ListSetConverter listSetStringToBinary() { + return new ListSetConverter<>(SafeEncoder::encode); + } + + static ListSetConverter listSetBinaryToString() { + return new ListSetConverter<>(SafeEncoder::encode); + } + + static SetListConverter setListStringToBinary() { + return new SetListConverter<>(SafeEncoder::encode); + } + + static SetListConverter setListBinaryToString() { + return new SetListConverter<>(SafeEncoder::encode); + } + + static MapConverter mapStringToBinary() { + return new MapConverter<>(SafeEncoder::encode, SafeEncoder::encode); + } + + static MapConverter mapBinaryToString() { + return new MapConverter<>(SafeEncoder::encode, SafeEncoder::encode); + } + + @SuppressWarnings({"unchecked"}) + static Converter always() { + return (value)->(T) value; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/BitOperationConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/BitOperationConverter.java new file mode 100644 index 000000000..30c76f388 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/BitOperationConverter.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.params; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.BitOperation; +import redis.clients.jedis.args.BitOP; + +/** + * {@link BitOperation} 转换为 jedis {@link BitOP} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class BitOperationConverter implements Converter { + + @Override + public BitOP convert(final BitOperation source) { + switch(source){ + case AND: + return BitOP.AND; + case OR: + return BitOP.OR; + case NOT: + return BitOP.NOT; + case XOR: + return BitOP.XOR; + default: + return null; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/BitTypeConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/BitTypeConverter.java new file mode 100644 index 000000000..40786c715 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/BitTypeConverter.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.params; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.BitType; +import redis.clients.jedis.args.BitCountOption; + +/** + * {@link BitType} 转换为 Jedis {@link BitCountOption} 互转 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class BitTypeConverter implements Converter { + + @Override + public BitCountOption convert(final BitType source) { + if(source != null){ + switch(source){ + case BYTE: + return BitCountOption.BYTE; + case BIT: + return BitCountOption.BIT; + default: + break; + } + } + + return null; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ClientAttributeOptionConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ClientAttributeOptionConverter.java new file mode 100644 index 000000000..24d90fa56 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ClientAttributeOptionConverter.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.params; + +import com.buession.core.converter.Converter; +import org.springframework.lang.Nullable; + +/** + * {@link com.buession.redis.core.ClientAttributeOption} 转换为 {@link redis.clients.jedis.args.ClientAttributeOption} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class ClientAttributeOptionConverter implements + Converter { + + @Nullable + @Override + public redis.clients.jedis.args.ClientAttributeOption convert( + final com.buession.redis.core.ClientAttributeOption source) { + if(source == null){ + return null; + }else{ + switch(source){ + case LIB_NAME: + return redis.clients.jedis.args.ClientAttributeOption.LIB_NAME; + case LIB_VER: + return redis.clients.jedis.args.ClientAttributeOption.LIB_VER; + default: + return null; + } + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ClientPauseModeConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ClientPauseModeConverter.java new file mode 100644 index 000000000..2c664f3b1 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ClientPauseModeConverter.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.params; + +import com.buession.core.converter.Converter; +import org.springframework.lang.Nullable; + +/** + * {@link com.buession.redis.core.ClientPauseMode} 转换为 {@link redis.clients.jedis.args.ClientPauseMode} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class ClientPauseModeConverter + implements Converter { + + @Nullable + @Override + public redis.clients.jedis.args.ClientPauseMode convert(final com.buession.redis.core.ClientPauseMode source) { + if(source == null){ + return null; + }else{ + switch(source){ + case WRITE: + return redis.clients.jedis.args.ClientPauseMode.WRITE; + case ALL: + return redis.clients.jedis.args.ClientPauseMode.ALL; + default: + return null; + } + } + } + +} diff --git a/buession-web/src/main/java/com/buession/web/reactive/filter/MobileFilter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ClientTypeConverter.java similarity index 65% rename from buession-web/src/main/java/com/buession/web/reactive/filter/MobileFilter.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ClientTypeConverter.java index 6a856c72f..871927a52 100644 --- a/buession-web/src/main/java/com/buession/web/reactive/filter/MobileFilter.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ClientTypeConverter.java @@ -22,29 +22,35 @@ * | Copyright @ 2013-2022 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.web.reactive.filter; +package com.buession.redis.core.internal.convert.jedis.params; -import com.buession.web.reactive.http.request.RequestUtils; -import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.web.server.ServerWebExchange; -import org.springframework.web.server.WebFilter; -import org.springframework.web.server.WebFilterChain; -import reactor.core.publisher.Mono; +import com.buession.core.converter.Converter; +import com.buession.redis.core.ClientType; /** - * 移动设备过滤器,通过 {@link RequestUtils#isMobile(ServerHttpRequest)} 获取到的值设置到 ServerHttpRequest attribute 中 + * {@link ClientType} 转换为 jedis {@link redis.clients.jedis.args.ClientType} * * @author Yong.Teng + * @since 2.0.0 */ -@Deprecated -public class MobileFilter implements WebFilter { +public final class ClientTypeConverter implements Converter { @Override - public Mono filter(ServerWebExchange exchange, WebFilterChain chain){ - ServerHttpRequest request = exchange.getRequest(); - - exchange.getAttributes().put("isMobile", RequestUtils.isMobile(request)); - return chain.filter(exchange); + public redis.clients.jedis.args.ClientType convert(final ClientType source) { + switch(source){ + case NORMAL: + return redis.clients.jedis.args.ClientType.NORMAL; + case MASTER: + return redis.clients.jedis.args.ClientType.MASTER; + case SLAVE: + return redis.clients.jedis.args.ClientType.SLAVE; + case REPLICA: + return redis.clients.jedis.args.ClientType.REPLICA; + case PUBSUB: + return redis.clients.jedis.args.ClientType.PUBSUB; + default: + return null; + } } } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ClientUnblockTypeConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ClientUnblockTypeConverter.java new file mode 100644 index 000000000..ed9b2a877 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ClientUnblockTypeConverter.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.params; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.ClientUnblockType; +import redis.clients.jedis.args.UnblockType; + +/** + * {@link ClientUnblockType} 转换为 jedis {@link UnblockType} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class ClientUnblockTypeConverter implements Converter { + + @Override + public UnblockType convert(final ClientUnblockType source) { + switch(source){ + case TIMEOUT: + return UnblockType.TIMEOUT; + case ERROR: + return UnblockType.ERROR; + default: + return null; + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/LPosArgumentConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ClusterFailoverOptionConverter.java similarity index 66% rename from buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/LPosArgumentConverter.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ClusterFailoverOptionConverter.java index c6567e237..f6adb79b9 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/LPosArgumentConverter.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ClusterFailoverOptionConverter.java @@ -19,35 +19,33 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; import com.buession.core.converter.Converter; -import com.buession.core.converter.mapper.PropertyMapper; -import com.buession.redis.core.command.ListCommands; -import redis.clients.jedis.params.LPosParams; +import com.buession.redis.core.ClusterFailoverOption; /** - * {@link ListCommands.LPosArgument} 转换为 jedis {@link LPosParams} + * {@link ClusterFailoverOption} 转换为 jedis {@link redis.clients.jedis.args.ClusterFailoverOption} * * @author Yong.Teng * @since 2.0.0 */ -public final class LPosArgumentConverter implements Converter { - - public final static LPosArgumentConverter INSTANCE = new LPosArgumentConverter(); +public final class ClusterFailoverOptionConverter + implements Converter { @Override - public LPosParams convert(final ListCommands.LPosArgument source) { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - final LPosParams lPosParams = new LPosParams(); - - propertyMapper.from(source.getRank()).to(lPosParams::rank); - propertyMapper.from(source.getMaxLen()).to(lPosParams::maxlen); - - return lPosParams; + public redis.clients.jedis.args.ClusterFailoverOption convert(final ClusterFailoverOption source) { + switch(source){ + case FORCE: + return redis.clients.jedis.args.ClusterFailoverOption.FORCE; + case TAKEOVER: + return redis.clients.jedis.args.ClusterFailoverOption.TAKEOVER; + default: + return null; + } } } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/DirectionConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/DirectionConverter.java new file mode 100644 index 000000000..08f04a77b --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/DirectionConverter.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.params; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.Direction; +import redis.clients.jedis.args.ListDirection; + +/** + * {@link Direction} 转换为 jedis {@link ListDirection} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class DirectionConverter implements Converter { + + @Override + public ListDirection convert(final Direction source) { + switch(source){ + case LEFT: + return ListDirection.LEFT; + case RIGHT: + return ListDirection.RIGHT; + default: + return null; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ExpireOptionConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ExpireOptionConverter.java new file mode 100644 index 000000000..9f6886d66 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ExpireOptionConverter.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.params; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.ExpireOption; +import redis.clients.jedis.args.ExpiryOption; + +/** + * {@link ExpireOption} 转换为 jedis {@link ExpiryOption} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class ExpireOptionConverter implements Converter { + + @Override + public ExpiryOption convert(final ExpireOption source) { + switch(source){ + case NX: + return ExpiryOption.NX; + case XX: + return ExpiryOption.XX; + case GT: + return ExpiryOption.GT; + case LT: + return ExpiryOption.LT; + default: + return null; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/FlushModeConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/FlushModeConverter.java new file mode 100644 index 000000000..5616a2187 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/FlushModeConverter.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.params; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.FlushMode; + +/** + * {@link FlushMode} 转换为 jedis {@link redis.clients.jedis.args.FlushMode} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class FlushModeConverter implements Converter { + + @Override + public redis.clients.jedis.args.FlushMode convert(final FlushMode source) { + switch(source){ + case ASYNC: + return redis.clients.jedis.args.FlushMode.ASYNC; + case SYNC: + return redis.clients.jedis.args.FlushMode.SYNC; + default: + return null; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/GeoUnitConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/GeoUnitConverter.java new file mode 100644 index 000000000..4d57fa146 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/GeoUnitConverter.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.params; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.GeoUnit; + +/** + * {@link GeoUnit} 转换为 jedis {@link redis.clients.jedis.args.GeoUnit} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class GeoUnitConverter implements Converter { + + @Override + public redis.clients.jedis.args.GeoUnit convert(final GeoUnit source) { + switch(source){ + case M: + return redis.clients.jedis.args.GeoUnit.M; + case KM: + return redis.clients.jedis.args.GeoUnit.KM; + case MI: + return redis.clients.jedis.args.GeoUnit.MI; + case FT: + return redis.clients.jedis.args.GeoUnit.FT; + default: + return null; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ListPositionConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ListPositionConverter.java new file mode 100644 index 000000000..52779a0c0 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/ListPositionConverter.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.params; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.ListPosition; + +/** + * {@link ListPosition} 转换为 jedis {@link redis.clients.jedis.args.ListPosition} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class ListPositionConverter implements Converter { + + @Override + public redis.clients.jedis.args.ListPosition convert(final ListPosition source) { + switch(source){ + case BEFORE: + return redis.clients.jedis.args.ListPosition.BEFORE; + case AFTER: + return redis.clients.jedis.args.ListPosition.AFTER; + default: + return null; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/OrderConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/OrderConverter.java new file mode 100644 index 000000000..407b68779 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/OrderConverter.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.params; + +import com.buession.core.converter.Converter; +import com.buession.lang.Order; +import redis.clients.jedis.args.SortingOrder; + +/** + * {@link com.buession.lang.Order} 转换为 jedis {@link SortingOrder} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class OrderConverter implements Converter { + + @Override + public SortingOrder convert(final Order source) { + if(source != null){ + switch(source){ + case ASC: + return SortingOrder.ASC; + case DESC: + return SortingOrder.DESC; + default: + break; + } + } + + return null; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/XClaimArgumentConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/StreamEntryIdConverter.java similarity index 63% rename from buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/XClaimArgumentConverter.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/StreamEntryIdConverter.java index 2c219c76b..96fa7be03 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/XClaimArgumentConverter.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/StreamEntryIdConverter.java @@ -19,38 +19,39 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; +import com.buession.core.converter.ArrayConverter; import com.buession.core.converter.Converter; -import com.buession.core.converter.mapper.PropertyMapper; -import com.buession.redis.core.command.StreamCommands; -import redis.clients.jedis.params.XClaimParams; +import com.buession.core.converter.MapConverter; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.internal.jedis.JedisStreamEntryID; +import redis.clients.jedis.StreamEntryID; + +import java.util.Map; /** + * {@link StreamEntryId} 转换为 jedis {@link StreamEntryID} + * * @author Yong.Teng * @since 2.0.0 */ -public final class XClaimArgumentConverter implements Converter { - - public final static XClaimArgumentConverter INSTANCE = new XClaimArgumentConverter(); +@FunctionalInterface +public interface StreamEntryIdConverter extends Converter { - @Override - public XClaimParams convert(final StreamCommands.XClaimArgument source) { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - final XClaimParams xClaimParams = new XClaimParams(); - - propertyMapper.from(source.getIdleTime()).to(xClaimParams::idle); - propertyMapper.from(source.getIdleUnixTime()).to(xClaimParams::time); - propertyMapper.from(source.getRetryCount()).to(xClaimParams::retryCount); + static ArrayConverter arrayConverter() { + return new ArrayConverter<>(JedisStreamEntryID::from, StreamEntryID.class); + } - if(Boolean.TRUE.equals(source.isForce())){ - xClaimParams.force(); - } + static ArrayConverter binaryArrayConverter() { + return new ArrayConverter<>(StreamEntryId::getRaw, byte[].class); + } - return xClaimParams; + static MapConverter mapConverter() { + return new MapConverter<>((key)->key, JedisStreamEntryID::from); } } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/package-info.java new file mode 100644 index 000000000..fe224ae97 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/params/package-info.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + * @since 2.0.0 + */ +package com.buession.redis.core.internal.convert.jedis.params; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/AccessControlLogEntryConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/AccessControlLogEntryConverter.java new file mode 100644 index 000000000..ce775c9cd --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/AccessControlLogEntryConverter.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.AclLog; +import com.buession.redis.core.Client; +import com.buession.redis.core.internal.convert.response.ClientConverter; +import redis.clients.jedis.resps.AccessControlLogEntry; + +/** + * Jedis {@link AccessControlLogEntry} 转换为 {@link AclLog} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class AccessControlLogEntryConverter implements Converter { + + private final static ClientConverter clientConverter = new ClientConverter(); + + @Override + public AclLog convert(final AccessControlLogEntry source) { + final Client client = clientConverter.convert((String) source.getlogEntry().get(AclLog.CLIENT_INFO)); + + return new AclLog(source.getEntryId(), source.getCount(), source.getReason(), source.getContext(), + source.getObject(), source.getUsername(), source.getAgeSeconds(), client, source.getTimestampCreated(), + source.getTimestampLastUpdated(), source.getlogEntry()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new AccessControlLogEntryConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/AccessControlUserConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/AccessControlUserConverter.java new file mode 100644 index 000000000..ca2007f53 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/AccessControlUserConverter.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.AclUser; +import redis.clients.jedis.resps.AccessControlUser; + +/** + * jedis {@link AccessControlUser} 转换为 {@link AclUser} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class AccessControlUserConverter implements Converter { + + @Override + public AclUser convert(final AccessControlUser source) { + return new AclUser(source.getCommands(), source.getUserInfo(), source.getPasswords(), source.getFlags(), + source.getKeysList(), source.getChannelsList(), source.getSelectors()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/AclCategoryConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/AclCategoryConverter.java new file mode 100644 index 000000000..7c95220bf --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/AclCategoryConverter.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.EnumConverter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.AclCategory; + +/** + * Jedis 字符串形式的 AclCategory 转换为 {@link AclCategory} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class AclCategoryConverter extends EnumConverter { + + public AclCategoryConverter() { + super(AclCategory.class); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new AclCategoryConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/BinaryAclCategoryConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/BinaryAclCategoryConverter.java new file mode 100644 index 000000000..f717e4146 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/BinaryAclCategoryConverter.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.BinaryEnumConverter; +import com.buession.redis.core.AclCategory; + +/** + * Jedis 二进制形式的 AclCategory 转换为 {@link AclCategory} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class BinaryAclCategoryConverter extends BinaryEnumConverter { + + public BinaryAclCategoryConverter() { + super(AclCategory.class); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ClusterLinkConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ClusterLinkConverter.java new file mode 100644 index 000000000..a1962d0b0 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ClusterLinkConverter.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.ClusterLink; +import org.springframework.lang.Nullable; + +import java.util.Map; + +/** + * Jedis {@code CLUSTER LINKS} 命令结果转换为 {@link ClusterLink} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class ClusterLinkConverter implements Converter, ClusterLink> { + + @Nullable + @Override + public ClusterLink convert(final Map source) { + if(source == null){ + return null; + }else{ + final ClusterLink clusterLink = new ClusterLink(); + + clusterLink.setNode((String) source.get("node")); + + String direction = (String) source.get("direction"); + if("from".equals(direction)){ + clusterLink.setDirection(ClusterLink.Direction.FROM); + }else if("to".equals(direction)){ + clusterLink.setDirection(ClusterLink.Direction.TO); + } + + clusterLink.setCreateTime((Long) source.get("create-time")); + + String event = (String) source.get("events"); + if(event != null){ + boolean containsR = event.contains("r"); + boolean containsW = event.contains("w"); + + if(containsR && containsW){ + clusterLink.setEvents(new ClusterLink.Event[]{ClusterLink.Event.R, ClusterLink.Event.W}); + }else if(containsR && containsW == false){ + clusterLink.setEvents(new ClusterLink.Event[]{ClusterLink.Event.R}); + }else if(containsR == false && containsW){ + clusterLink.setEvents(new ClusterLink.Event[]{ClusterLink.Event.W}); + } + } + + clusterLink.setSendBufferAllocated((Integer) source.get("send-buffer-allocated")); + clusterLink.setSendBufferUsed((Integer) source.get("send-buffer-used")); + + return clusterLink; + } + } + + public static ListConverter, ClusterLink> listConverter() { + return new ListConverter<>(new ClusterLinkConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ClusterReplicasConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ClusterReplicasConverter.java new file mode 100644 index 000000000..a931de928 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ClusterReplicasConverter.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.EnumUtils; +import com.buession.core.utils.StringUtils; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.RedisClusterServer; +import com.buession.redis.core.SlotRange; + +import java.util.Arrays; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Jedis Cluster Replicas 命令结果转换为 {@link RedisClusterServer} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class ClusterReplicasConverter implements Converter { + + @Override + public ClusterRedisNode convert(final String source) { + String[] values = StringUtils.split(source, " "); + String[] hostAndPort = StringUtils.split(values[1], ':'); + String host = hostAndPort[0]; + String port = hostAndPort[1].substring(0, hostAndPort[1].indexOf('@')); + String[] flagsValues = StringUtils.split(values[2], ':'); + Set flags = + Arrays.stream(flagsValues).map((v)->EnumUtils.getEnumIgnoreCase(ClusterRedisNode.Flag.class, v)) + .collect(Collectors.toSet()); + + ClusterRedisNode.LinkState linkState = EnumUtils.getEnumIgnoreCase(ClusterRedisNode.LinkState.class, values[7]); + SlotRange slotRange = null; + + if(values.length == 9){ + String[] slotRangeValues = StringUtils.split(values[8], '-'); + slotRange = new SlotRange(Integer.parseInt(slotRangeValues[0]), Integer.parseInt(slotRangeValues[1])); + } + + return new ClusterRedisNode(values[0], host, Integer.parseInt(port), flags, values[3], + Long.parseLong(values[4]), Long.parseLong(values[5]), Long.parseLong(values[6]), linkState, slotRange); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new ClusterReplicasConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ClusterResetOptionConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ClusterResetOptionConverter.java new file mode 100644 index 000000000..f397cc96f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ClusterResetOptionConverter.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.ClusterResetOption; +import redis.clients.jedis.args.ClusterResetType; + +/** + * {@link ClusterResetOption} 转换为 Jedis {@link ClusterResetType} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class ClusterResetOptionConverter implements Converter { + + @Override + public ClusterResetType convert(final ClusterResetOption source) { + switch(source){ + case SOFT: + return ClusterResetType.SOFT; + case HARD: + return ClusterResetType.HARD; + default: + return null; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/GeoCoordinateConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/GeoCoordinateConverter.java new file mode 100644 index 000000000..63b52c566 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/GeoCoordinateConverter.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Geo; +import redis.clients.jedis.GeoCoordinate; + +import java.util.List; + +/** + * Jedis {@link GeoCoordinate} 转换为 {@link Geo} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class GeoCoordinateConverter implements Converter { + + @Override + public Geo convert(final GeoCoordinate source) { + return new Geo(source.getLongitude(), source.getLatitude()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new GeoCoordinateConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/GeoRadiusResponseConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/GeoRadiusResponseConverter.java new file mode 100644 index 000000000..0df49185b --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/GeoRadiusResponseConverter.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.GeoRadius; +import redis.clients.jedis.resps.GeoRadiusResponse; + +import java.util.List; + +/** + * Jedis {@link GeoRadiusResponse} 转换为 {@link GeoRadius} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public class GeoRadiusResponseConverter implements Converter { + + private final GeoCoordinateConverter geoCoordinateConverter = new GeoCoordinateConverter(); + + @Override + public GeoRadius convert(final GeoRadiusResponse source) { + return new GeoRadius(source.getMember(), source.getDistance(), + source.getCoordinate() == null ? null : geoCoordinateConverter.convert(source.getCoordinate())); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new GeoRadiusResponseConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/KeyValueConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/KeyValueConverter.java new file mode 100644 index 000000000..2e18ea30f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/KeyValueConverter.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.lang.KeyValue; +import org.springframework.lang.Nullable; + +/** + * Jedis {@link redis.clients.jedis.util.KeyValue} 转换为 {@link com.buession.lang.KeyValue} + * + * @param + * 原始 Key 类型 + * @param + * 原始值类型 + * @param + * 目标 Key 类型 + * @param + * 目标值类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class KeyValueConverter implements Converter, + com.buession.lang.KeyValue> { + + /** + * Key 转换器 + */ + private final Converter keyConverter; + + /** + * 值转换器 + */ + private final Converter valueConverter; + + /** + * 构造函数 + * + * @param keyConverter + * Key 转换器 + * @param valueConverter + * 值转换器 + */ + public KeyValueConverter(final Converter keyConverter, final Converter valueConverter) { + this.keyConverter = keyConverter; + this.valueConverter = valueConverter; + } + + @Nullable + @Override + public KeyValue convert(final redis.clients.jedis.util.KeyValue source) { + return new com.buession.lang.KeyValue<>(keyConverter.convert(source.getKey()), valueConverter.convert( + source.getValue())); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/MemoryStatsConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/MemoryStatsConverter.java new file mode 100644 index 000000000..dee03de4f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/MemoryStatsConverter.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.utils.StringUtils; +import com.buession.redis.core.MemoryStats; + +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +/** + * Jedis memory-stats 命令结果转换 + * + * @author Yong.Teng + * @since 2.3.0 + */ +public final class MemoryStatsConverter implements Converter, MemoryStats> { + + @SuppressWarnings({"unchecked"}) + @Override + public MemoryStats convert(final Map source) { + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); + final MemoryStats memoryStats = new MemoryStats(); + + source.forEach((name, value)->{ + if("dataset.bytes".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setDataset); + }else if("dataset.percentage".equals(name)){ + propertyMapper.from(value).as((v)->Double.parseDouble(v.toString())) + .to(memoryStats::setDatasetPercentage); + }else if("rss-overhead.bytes".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setRssOverhead); + }else if("rss-overhead.ratio".equals(name)){ + propertyMapper.from(value).as((v)->Double.parseDouble(v.toString())) + .to(memoryStats::setRssOverheadRatio); + }else if("peak.percentage".equals(name)){ + propertyMapper.from(value).as((v)->Double.parseDouble(v.toString())).to(memoryStats::setPeakPercentage); + }else if("aof.buffer".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setAofBuffer); + }else if("keys.bytes-per-key".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setKeysBytesPerKey); + }else if("allocator.allocated".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setAllocatorAllocated); + }else if("allocator-fragmentation.bytes".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setAllocatorFragmentation); + }else if("allocator-fragmentation.ratio".equals(name)){ + propertyMapper.from(value).as((v)->Double.parseDouble(v.toString())) + .to(memoryStats::setAllocatorFragmentationRatio); + }else if("allocator.active".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setAllocatorActive); + }else if("allocator-rss.bytes".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setAllocatorRss); + }else if("allocator-rss.ratio".equals(name)){ + propertyMapper.from(value).as((v)->Double.parseDouble(v.toString())) + .to(memoryStats::setAllocatorRssRatio); + }else if("allocator.resident".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setAllocatorResident); + }else if("clients.normal".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setClientsNormal); + }else if("clients.slaves".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setClientsSlaves); + }else if("fragmentation.bytes".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setFragmentation); + }else if("fragmentation".equals(name)){ + propertyMapper.from(value).as((v)->Double.parseDouble(v.toString())) + .to(memoryStats::setFragmentationRatio); + }else if("lua.caches".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setLuaCaches); + }else if("peak.allocated".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setPeakAllocated); + }else if("total.allocated".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setTotalAllocated); + }else if("replication.backlog".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setReplicationBacklog); + }else if("startup.allocated".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setStartupAllocated); + }else if("overhead.total".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setOverheadTotal); + }else if("keys.count".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setKeysCount); + }else if(name.startsWith("db.")){ + String[] nameParts = StringUtils.split(name, '.'); + int db = Integer.parseInt(nameParts[1]); + MemoryStats.Db dbStat = new MemoryStats.Db(); + List dbStatTmp = (List) value; + + if(memoryStats.getDbs() == null){ + memoryStats.setDbs(new TreeMap<>()); + } + + for(int j = 0, jl = dbStatTmp.size(); j < jl; j++){ + Object v = dbStatTmp.get(j); + j++; + + if("overhead.hashtable.main".equals(v)){ + propertyMapper.from(v).as((dv)->(Long) dv).to(dbStat::setOverheadHashTableMain); + }else if("overhead.hashtable.expires".equals(v)){ + propertyMapper.from(v).as((dv)->(Long) dv).to(dbStat::setOverheadHashTableExpires); + } + } + + memoryStats.getDbs().put(db, dbStat); + } + }); + + return memoryStats; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ModuleConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ModuleConverter.java new file mode 100644 index 000000000..54c1602be --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ModuleConverter.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.Module; + +import java.util.List; + +/** + * jedis {@link redis.clients.jedis.Module} 转换为 {@link Module} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class ModuleConverter implements Converter { + + @Override + public Module convert(final redis.clients.jedis.Module source) { + return new Module(source.getName(), source.getVersion()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new ModuleConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ProtocolCommandConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ProtocolCommandConverter.java new file mode 100644 index 000000000..f66af6880 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ProtocolCommandConverter.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.EnumConverter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.command.Command; + +/** + * Jedis 字符串形式的 ProtocolCommand 转换为 {@link Command} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class ProtocolCommandConverter extends EnumConverter { + + public ProtocolCommandConverter() { + super(Command.class); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new ProtocolCommandConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/RedisServerTimeConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/RedisServerTimeConverter.java new file mode 100644 index 000000000..f5ccbf7aa --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/RedisServerTimeConverter.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.RedisServerTime; + +import java.util.Date; +import java.util.List; + +/** + * Jedis 返回的服务器时间转换为 {@link RedisServerTime} + * + * @author Yong.Teng + * @since 1.2.1 + */ +public final class RedisServerTimeConverter implements Converter, RedisServerTime> { + + @Override + public RedisServerTime convert(final List source) { + Date date = new Date(Long.parseLong(source.get(0)) * 1000L); + return new RedisServerTime(date, Long.parseLong(source.get(1))); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/RoleConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/RoleConverter.java new file mode 100644 index 000000000..60be6747d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/RoleConverter.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.EnumUtils; +import com.buession.redis.core.Role; + +import java.util.List; + +/** + * Jedis 角色信息 转换为 {@link Role} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class RoleConverter implements Converter { + + @Override + public Role convert(final Object source) { + if(source instanceof List){ + List tmp = (List) source; + + if(tmp.size() == 3){ + return EnumUtils.getEnum(Role.class, tmp.get(0).toString().toUpperCase()); + } + } + + return null; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ScanResultConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ScanResultConverter.java new file mode 100644 index 000000000..6343e474c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/ScanResultConverter.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * {@link ScanResult} 和 jedis {@link redis.clients.jedis.resps.ScanResult} 互转 + * + * @author Yong.Teng + * @since 2.0.0 + */ +@FunctionalInterface +public interface ScanResultConverter extends Converter, ScanResult> { + + /** + * jedis {@link redis.clients.jedis.resps.ScanResult} 转换为 {@link java.util.List}<ScanResult> + * + * @author Yong.Teng + * @since 2.0.0 + */ + final class ListScanResultConverter implements ScanResultConverter> { + + @Override + public ScanResult> convert(final redis.clients.jedis.resps.ScanResult source) { + return new ScanResult<>(source.getCursor(), source.getResult()); + } + + } + + /** + * jedis {@link redis.clients.jedis.resps.Tuple} 转换为 {@link java.util.List}<T> + * + * @author Yong.Teng + * @since 2.0.0 + */ + final class ListTupleScanResultConverter + implements ScanResultConverter> { + + private final ListConverter listTupleConverter = + TupleConverter.listConverter(); + + @Override + public ScanResult> convert( + final redis.clients.jedis.resps.ScanResult source) { + return new com.buession.redis.core.ScanResult<>(source.getCursor(), + listTupleConverter.convert(source.getResult())); + } + + } + + /** + * jedis {@link redis.clients.jedis.resps.ScanResult}<Map.Entry<K>, <K>> 转换为 {@link ScanResult} + * <Map<K>, <K>> + * + * @param + * Map Key 类型 + * @param + * Map 值类型 + * + * @author Yong.Teng + * @since 2.0.0 + */ + final class MapScanResultConverter implements ScanResultConverter, Map> { + + @Override + public ScanResult> convert(final redis.clients.jedis.resps.ScanResult> source) { + final Map data = source.getResult().stream().collect(Collectors.toMap(Map.Entry::getKey, + Map.Entry::getValue, (a, b)->a, LinkedHashMap::new)); + return new ScanResult<>(source.getCursorAsBytes(), data); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/SlowlogConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/SlowlogConverter.java new file mode 100644 index 000000000..990d29932 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/SlowlogConverter.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.Client; +import com.buession.redis.core.SlowLog; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.resps.Slowlog; + +/** + * jedis {@link Slowlog} 转换为 {@link SlowLog} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class SlowlogConverter implements Converter { + + @Override + public SlowLog convert(final Slowlog source) { + final Client client = new Client(); + final HostAndPort clientIpPort = source.getClientIpPort(); + + if(clientIpPort != null){ + client.setHost(clientIpPort.getHost()); + client.setPort(clientIpPort.getPort()); + } + + return new SlowLog(source.getId(), source.getTimeStamp(), source.getExecutionTime(), source.getArgs(), + client, source.getClientName()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new SlowlogConverter()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/KeyedZSetElementConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumerFullInfoConverter.java similarity index 61% rename from buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/KeyedZSetElementConverter.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumerFullInfoConverter.java index ffe75f142..f019e5405 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/KeyedZSetElementConverter.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumerFullInfoConverter.java @@ -19,42 +19,45 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; import com.buession.core.converter.Converter; -import com.buession.redis.core.KeyedZSetElement; -import redis.clients.jedis.BuilderFactory; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamConsumerFull; +import redis.clients.jedis.resps.StreamConsumerFullInfo; +import java.util.ArrayList; import java.util.List; /** - * jedis {@link redis.clients.jedis.resps.KeyedZSetElement} 转换为 {@link KeyedZSetElement} + * jedis {@link StreamConsumerFullInfo} 转换为 {@link StreamConsumerFull} * * @author Yong.Teng * @since 2.0.0 */ -public final class KeyedZSetElementConverter - implements Converter { - - public final static KeyedZSetElementConverter INSTANCE = new KeyedZSetElementConverter(); +public final class StreamConsumerFullInfoConverter implements Converter { @Override - public KeyedZSetElement convert(final redis.clients.jedis.resps.KeyedZSetElement source){ - return new KeyedZSetElement(source.getKey(), source.getElement(), source.getScore()); - } - - public final static class BinaryDataKeyedZSetElementConverter implements Converter, KeyedZSetElement> { - - public final static BinaryDataKeyedZSetElementConverter INSTANCE = new BinaryDataKeyedZSetElementConverter(); - - @Override - public KeyedZSetElement convert(final List source){ - return new KeyedZSetElement(source.get(0), source.get(1), BuilderFactory.DOUBLE.build(source.get(2))); + public StreamConsumerFull convert(final StreamConsumerFullInfo source) { + final List pendings = new ArrayList<>(); + + if(source.getPending() != null){ + for(List pending : source.getPending()){ + for(Object item : pending){ + pendings.add((Long) item); + } + } } + return new StreamConsumerFull(source.getName(), source.getSeenTime(), source.getPelCount(), pendings, + source.getConsumerInfo()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new StreamConsumerFullInfoConverter()); } } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumerInfoConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumerInfoConverter.java new file mode 100644 index 000000000..c6c686b34 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumerInfoConverter.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamConsumer; +import redis.clients.jedis.resps.StreamConsumerInfo; + +/** + * jedis {@link StreamConsumerInfo} 转换为 {@link StreamConsumer} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class StreamConsumerInfoConverter implements Converter { + + @Override + public StreamConsumer convert(final StreamConsumerInfo source) { + return new StreamConsumer(source.getName(), source.getIdle(), source.getPending(), source.getConsumerInfo()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new StreamConsumerInfoConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumersInfoConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumersInfoConverter.java new file mode 100644 index 000000000..91b5c5155 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumersInfoConverter.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamConsumer; +import redis.clients.jedis.resps.StreamConsumersInfo; + +/** + * jedis {@link StreamConsumersInfo} 转换为 {@link StreamConsumer} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class StreamConsumersInfoConverter implements Converter { + + @Override + public StreamConsumer convert(final StreamConsumersInfo source) { + return new StreamConsumer(source.getName(), source.getIdle(), source.getPending(), source.getConsumerInfo()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new StreamConsumersInfoConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamEntryConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamEntryConverter.java new file mode 100644 index 000000000..5da4e699e --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamEntryConverter.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapEntryMapConverter; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; + +import java.util.List; +import java.util.Map; + +/** + * Jedis {@link redis.clients.jedis.resps.StreamEntry} 转换为 {@link StreamEntry} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class StreamEntryConverter implements Converter { + + private final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + @Override + public StreamEntry convert(final redis.clients.jedis.resps.StreamEntry source) { + final StreamEntryId id = streamEntryIDConverter.convert(source.getID()); + return new StreamEntry(id, source.getFields()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new StreamEntryConverter()); + } + + /** + * Jedis {@link redis.clients.jedis.resps.StreamEntry} 转换为 {@link StreamEntry} + * + * @param + * 转换器 key 类型 + * @param + * 目标 key 类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ + public final static class MapEntryStreamEntryConverter extends + MapEntryMapConverter, TK, List> { + + public MapEntryStreamEntryConverter(final Converter keyConverter) { + super(keyConverter, StreamEntryConverter.listConverter()); + } + + } + + /** + * Jedis {@link redis.clients.jedis.resps.StreamEntry} 转换为 {@link StreamEntry} + * + * @param + * 转换器 key 类型 + * @param + * 目标 key 类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ + public final static class ListMapEntryStreamEntryConverter extends + ListConverter>, Map>> { + + public ListMapEntryStreamEntryConverter(final Converter keyConverter) { + super(new MapEntryStreamEntryConverter<>(keyConverter)); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamEntryIDConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamEntryIDConverter.java new file mode 100644 index 000000000..b843ebb84 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamEntryIDConverter.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapEntryMapConverter; +import com.buession.redis.core.StreamEntryId; +import redis.clients.jedis.StreamEntryID; + +import java.util.List; + +/** + * Jedis {@link StreamEntryID} 转换为 {@link StreamEntryId} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class StreamEntryIDConverter implements Converter { + + @Override + public StreamEntryId convert(final StreamEntryID source) { + return new StreamEntryId(source.getTime(), source.getSequence()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new StreamEntryIDConverter()); + } + + public static MapEntryMapConverter, StreamEntryId, List> mapEntryMapConverter() { + return new MapEntryMapConverter<>(new StreamEntryIDConverter(), listConverter()); + } + + /** + * Jedis {@link StreamEntryID} 转换为 {@link StreamEntryId} + * + * @author Yong.Teng + * @since 2.0.0 + */ + public final static class BinaryStreamEntryIdConverter implements Converter { + + @Override + public StreamEntryId convert(final byte[] source) { + return new StreamEntryId(source); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamFullInfoConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamFullInfoConverter.java new file mode 100644 index 000000000..1f259338e --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamFullInfoConverter.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import redis.clients.jedis.resps.StreamFullInfo; +import redis.clients.jedis.resps.StreamGroupFullInfo; + +import java.util.List; + +/** + * jedis {@link StreamFullInfo} 转换为 {@link StreamFull} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class StreamFullInfoConverter implements Converter { + + private final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + private final ListConverter listStreamFullInfoGroupConverter = + StreamFullInfoGroupConverter.listConverter(); + + private final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + @Override + public StreamFull convert(final StreamFullInfo source) { + final List groups = listStreamFullInfoGroupConverter.convert(source.getGroups()); + final StreamEntryId lastGeneratedId = streamEntryIDConverter.convert(source.getLastGeneratedId()); + final List entries = listStreamEntryConverter.convert(source.getEntries()); + return new StreamFull(source.getLength(), source.getRadixTreeKeys(), source.getRadixTreeNodes(), + groups, lastGeneratedId, entries, source.getStreamFullInfo()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamFullInfoGroupConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamFullInfoGroupConverter.java new file mode 100644 index 000000000..048608e6c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamFullInfoGroupConverter.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamConsumerFull; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import redis.clients.jedis.resps.StreamConsumerFullInfo; +import redis.clients.jedis.resps.StreamGroupFullInfo; + +import java.util.List; + +/** + * Jedis {@link StreamGroupFullInfo} 转换为 {@link StreamFull.Group} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class StreamFullInfoGroupConverter implements Converter { + + private final ListConverter listStreamConsumerFullInfoConverter = + StreamConsumerFullInfoConverter.listConverter(); + + private final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + @Override + public StreamFull.Group convert(final StreamGroupFullInfo source) { + final List consumers = listStreamConsumerFullInfoConverter.convert( + source.getConsumers()); + final StreamEntryId lastDeliveredId = streamEntryIDConverter.convert(source.getLastDeliveredId()); + + return new StreamFull.Group(source.getName(), consumers, source.getPending(), source.getPelCount(), + lastDeliveredId, source.getGroupFullInfo()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new StreamFullInfoGroupConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamGroupInfoConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamGroupInfoConverter.java new file mode 100644 index 000000000..53d062eb1 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamGroupInfoConverter.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamGroup; +import redis.clients.jedis.resps.StreamGroupInfo; + +import java.util.List; + +/** + * jedis {@link StreamGroupInfo} 转换为 {@link StreamGroup} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class StreamGroupInfoConverter implements Converter { + + private final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + @Override + public StreamGroup convert(final StreamGroupInfo source) { + final StreamEntryId lastDeliveredId = streamEntryIDConverter.convert(source.getLastDeliveredId()); + return new StreamGroup(source.getName(), source.getConsumers(), source.getPending(), lastDeliveredId, + source.getGroupInfo()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new StreamGroupInfoConverter()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/XTrimArgumentConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamInfoConverter.java similarity index 57% rename from buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/XTrimArgumentConverter.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamInfoConverter.java index ad435fbd7..745060355 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/XTrimArgumentConverter.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamInfoConverter.java @@ -19,43 +19,37 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.redis.core.internal.convert.jedis.params; +package com.buession.redis.core.internal.convert.jedis.response; import com.buession.core.converter.Converter; -import com.buession.core.converter.mapper.PropertyMapper; -import com.buession.redis.core.command.StreamCommands; -import redis.clients.jedis.params.XTrimParams; +import com.buession.redis.core.Stream; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamGroup; +import redis.clients.jedis.resps.StreamInfo; /** - * {@link StreamCommands.XTrimArgument} 转换为 jedis {@link XTrimParams} + * jedis {@link StreamInfo} 转换为 {@link StreamGroup} * * @author Yong.Teng * @since 2.0.0 */ -public class XTrimArgumentConverter implements Converter { +public final class StreamInfoConverter implements Converter { - public final static XTrimArgumentConverter INSTANCE = new XTrimArgumentConverter(); + private final StreamEntryConverter streamEntryConverter = new StreamEntryConverter(); - @Override - public XTrimParams convert(final StreamCommands.XTrimArgument source) { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - final XTrimParams xTrimParams = new XTrimParams(); - - propertyMapper.from(source.getMaxLen()).to(xTrimParams::maxLen); - propertyMapper.from(source.getMinId()).to(xTrimParams::minId); - - if(Boolean.TRUE.equals(source.isApproximateTrimming())){ - xTrimParams.approximateTrimming(); - } + private final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); - if(Boolean.TRUE.equals(source.isExactTrimming())){ - xTrimParams.exactTrimming(); - } - - return xTrimParams; + @Override + public Stream convert(final StreamInfo source) { + final StreamEntryId lastGeneratedId = streamEntryIDConverter.convert(source.getLastGeneratedId()); + final StreamEntry firstEntry = streamEntryConverter.convert(source.getFirstEntry()); + final StreamEntry lastEntry = streamEntryConverter.convert(source.getLastEntry()); + return new Stream(source.getLength(), source.getRadixTreeKeys(), source.getRadixTreeNodes(), + source.getGroups(), lastGeneratedId, firstEntry, lastEntry, source.getStreamInfo()); } } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamPendingEntryConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamPendingEntryConverter.java new file mode 100644 index 000000000..ba8704e9d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamPendingEntryConverter.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamPending; +import redis.clients.jedis.resps.StreamPendingEntry; + +import java.util.List; + +/** + * jedis {@link StreamPendingEntry} 转换为 {@link StreamPending} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class StreamPendingEntryConverter implements Converter { + + private final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + @Override + public StreamPending convert(final StreamPendingEntry source) { + final StreamEntryId id = streamEntryIDConverter.convert(source.getID()); + return new StreamPending(id, source.getConsumerName(), source.getIdleTime(), source.getDeliveredTimes()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new StreamPendingEntryConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamPendingSummaryConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamPendingSummaryConverter.java new file mode 100644 index 000000000..a97ec439d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/StreamPendingSummaryConverter.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamPendingSummary; + +/** + * jedis {@link redis.clients.jedis.resps.StreamPendingSummary} 转换为 {@link StreamPendingSummary} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class StreamPendingSummaryConverter + implements Converter { + + private final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + @Override + public StreamPendingSummary convert(final redis.clients.jedis.resps.StreamPendingSummary source) { + final StreamEntryId minId = streamEntryIDConverter.convert(source.getMinId()); + final StreamEntryId maxId = streamEntryIDConverter.convert(source.getMaxId()); + return new StreamPendingSummary(source.getTotal(), minId, maxId, source.getConsumerMessageCount()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/TupleConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/TupleConverter.java new file mode 100644 index 000000000..2cc64187c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/TupleConverter.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.Tuple; + +/** + * jedis {@link redis.clients.jedis.resps.Tuple} 转换为 {@link Tuple} + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class TupleConverter implements Converter { + + @Override + public Tuple convert(final redis.clients.jedis.resps.Tuple source) { + return new Tuple(source.getBinaryElement(), source.getScore()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new TupleConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/package-info.java new file mode 100644 index 000000000..fc1c1bd0a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/jedis/response/package-info.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + * @since 2.0.0 + */ +package com.buession.redis.core.internal.convert.jedis.response; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/AclCategoryConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/AclCategoryConverter.java new file mode 100644 index 000000000..ade13ead7 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/AclCategoryConverter.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.params; + +import com.buession.core.converter.Converter; +import org.springframework.lang.Nullable; + +/** + * {@link com.buession.redis.core.AclCategory} 转换为 Lettuce {@link io.lettuce.core.AclCategory} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class AclCategoryConverter + implements Converter { + + @Nullable + @Override + public io.lettuce.core.AclCategory convert(final com.buession.redis.core.AclCategory source) { + return source == null ? null : Enum.valueOf(io.lettuce.core.AclCategory.class, source.name()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/ClientTypeConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/ClientTypeConverter.java new file mode 100644 index 000000000..f8c9588e0 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/ClientTypeConverter.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.params; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.ClientType; +import io.lettuce.core.ClientListArgs; +import org.springframework.lang.Nullable; + +/** + * {@link ClientType} 转换为 Lettuce {@link ClientListArgs} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class ClientTypeConverter implements Converter { + + @Nullable + @Override + public ClientListArgs convert(final ClientType source) { + if(source == null){ + return null; + }else{ + switch(source){ + case NORMAL: + return ClientListArgs.Builder.typeNormal(); + case MASTER: + return ClientListArgs.Builder.typeMaster(); + case SLAVE: + break; + case REPLICA: + return ClientListArgs.Builder.typeReplica(); + case PUBSUB: + return ClientListArgs.Builder.typePubsub(); + default: + break; + } + } + return null; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/ClientUnblockTypeConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/ClientUnblockTypeConverter.java new file mode 100644 index 000000000..4c15e5cc5 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/ClientUnblockTypeConverter.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.params; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.ClientUnblockType; +import io.lettuce.core.UnblockType; + +/** + * {@link ClientUnblockType} 转换为 Lettuce {@link UnblockType} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class ClientUnblockTypeConverter implements Converter { + + @Override + public UnblockType convert(final ClientUnblockType source) { + if(source == null){ + return null; + } + + switch(source){ + case TIMEOUT: + return UnblockType.TIMEOUT; + case ERROR: + return UnblockType.ERROR; + default: + return null; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/CommandConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/CommandConverter.java new file mode 100644 index 000000000..f5d913ec5 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/CommandConverter.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.params; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.command.Command; +import io.lettuce.core.protocol.CommandType; +import org.springframework.lang.Nullable; + +/** + * {@link Command} 转换为 Lettuce {@link CommandType} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class CommandConverter implements Converter { + + @Nullable + @Override + public CommandType convert(final Command source) { + if(source == null){ + return null; + }else{ + switch(source){ + case BITCOUNT: + return CommandType.BITCOUNT; + case BITFIELD: + return CommandType.BITFIELD; + case BITFIELD_RO: + break; + case BITOP: + return CommandType.BITOP; + case BITPOS: + return CommandType.BITPOS; + case GETBIT: + return CommandType.GETBIT; + case SETBIT: + return CommandType.SETBIT; + case CLUSTER_MY_ID: + return CommandType.CLUSTER; + + } + } + + return null; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/FlushModeConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/FlushModeConverter.java new file mode 100644 index 000000000..e38bb1448 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/FlushModeConverter.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.params; + +import com.buession.core.converter.Converter; +import org.springframework.lang.Nullable; + +/** + * {@link com.buession.redis.core.FlushMode} 转换为 Lettuce {@link io.lettuce.core.FlushMode} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class FlushModeConverter + implements Converter { + + @Nullable + @Override + public io.lettuce.core.FlushMode convert(final com.buession.redis.core.FlushMode source) { + if(source == null){ + return null; + } + + switch(source){ + case ASYNC: + return io.lettuce.core.FlushMode.ASYNC; + case SYNC: + return io.lettuce.core.FlushMode.SYNC; + default: + return null; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/GeoUnitConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/GeoUnitConverter.java new file mode 100644 index 000000000..01b0b0842 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/GeoUnitConverter.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.params; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.GeoUnit; +import io.lettuce.core.GeoArgs; + +/** + * {@link GeoUnit} 转换为 Lettuce {@link GeoArgs.Unit} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class GeoUnitConverter implements Converter { + + @Override + public GeoArgs.Unit convert(final GeoUnit source) { + if(source == null){ + return null; + } + + switch(source){ + case M: + return GeoArgs.Unit.m; + case KM: + return GeoArgs.Unit.km; + case MI: + return GeoArgs.Unit.mi; + case FT: + return GeoArgs.Unit.ft; + default: + return null; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/RangeConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/RangeConverter.java new file mode 100644 index 000000000..fb0202928 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/RangeConverter.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.params; + +import com.buession.core.converter.Converter; +import io.lettuce.core.Range; +import org.springframework.lang.Nullable; + +/** + * 从 {@link com.buession.core.Range} 转换为 {@link io.lettuce.core.Range} + * + * @param + * 值类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class RangeConverter implements Converter, io.lettuce.core.Range> { + + @Nullable + @Override + public Range convert(final com.buession.core.Range source) { + return source == null ? null : io.lettuce.core.Range.create(source.getStart(), source.getEnd()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/StreamEntryIdConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/StreamEntryIdConverter.java new file mode 100644 index 000000000..e576cdb77 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/StreamEntryIdConverter.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.params; + +import com.buession.core.converter.ArrayConverter; +import com.buession.core.converter.Converter; +import com.buession.redis.core.StreamEntryId; + +/** + * {@link StreamEntryId} 转换为 Lettuce Stream MessageId + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class StreamEntryIdConverter implements Converter { + + @Override + public String convert(final StreamEntryId source) { + return source == null ? null : source.toString(); + } + + public static ArrayConverter arrayConverter() { + return new ArrayConverter<>(new StreamEntryIdConverter(), String.class); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/package-info.java new file mode 100644 index 000000000..eb5f6e1df --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/params/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.core.internal.convert.lettuce.params; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/AclCategoryConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/AclCategoryConverter.java new file mode 100644 index 000000000..4f37285df --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/AclCategoryConverter.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.SetListConverter; +import org.springframework.lang.Nullable; + +/** + * Lettuce {@link io.lettuce.core.AclCategory} 转换为 {@link com.buession.redis.core.AclCategory} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class AclCategoryConverter implements Converter { + + @Nullable + @Override + public com.buession.redis.core.AclCategory convert(final io.lettuce.core.AclCategory source) { + return source == null ? null : Enum.valueOf(com.buession.redis.core.AclCategory.class, source.name()); + } + + public static SetListConverter setListConverter() { + return new SetListConverter<>(new AclCategoryConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/AclGetUserConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/AclGetUserConverter.java new file mode 100644 index 000000000..b442fda69 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/AclGetUserConverter.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.AclUser; +import org.springframework.lang.Nullable; + +import java.util.List; + +/** + * Lettuce {@code ACL GETUSER} 命令结果转换为 {@link AclUser} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class AclGetUserConverter implements Converter, AclUser> { + + @Nullable + @Override + public AclUser convert(final List source) { + return null; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/AclLogConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/AclLogConverter.java new file mode 100644 index 000000000..b70c5f805 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/AclLogConverter.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.AclLog; +import com.buession.redis.core.Client; +import com.buession.redis.core.internal.convert.response.ClientConverter; +import org.springframework.lang.Nullable; + +import java.util.Map; + +/** + * Lettuce {@code ACL LOG} 命令结果转换为 {@link AclLog} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class AclLogConverter extends ListConverter, AclLog> { + + public AclLogConverter() { + super(new AclLogEntryConverter()); + } + + private final static class AclLogEntryConverter implements Converter, AclLog> { + + private final static ClientConverter clientConverter = new ClientConverter(); + + @Nullable + @Override + public AclLog convert(final Map source) { + final long entryId = (long) source.get(AclLog.ENTRY_ID); + final long count = (long) source.get(AclLog.COUNT); + final String reason = (String) source.get(AclLog.REASON); + final String context = (String) source.get(AclLog.CONTEXT); + final String object = (String) source.get(AclLog.OBJECT); + final String username = (String) source.get(AclLog.USERNAME); + final Double ageSeconds = (Double) source.get(AclLog.AGE_SECONDS); + final Client client = clientConverter.convert((String) source.get(AclLog.CLIENT_INFO)); + final long timestampCreated = (long) source.get(AclLog.TIMESTAMP_CREATED); + final long timestampLastUpdated = (long) source.get(AclLog.TIMESTAMP_LAST_UPDATED); + + return new AclLog(entryId, count, reason, context, object, username, ageSeconds, client, + timestampCreated, timestampLastUpdated, source); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/ClusterReplicasConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/ClusterReplicasConverter.java new file mode 100644 index 000000000..e1e56fa56 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/ClusterReplicasConverter.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.utils.EnumUtils; +import com.buession.core.utils.StringUtils; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.RedisClusterServer; +import com.buession.redis.core.SlotRange; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Lettuce Cluster Replicas 命令结果转换为 {@link RedisClusterServer} 列表 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class ClusterReplicasConverter implements Converter> { + + @Override + public List convert(final String source) { + String[] rows = source.split("\r\n"); + return Arrays.stream(rows).map(this::rowConvert).collect(Collectors.toList()); + } + + private ClusterRedisNode rowConvert(final String row) { + String[] values = StringUtils.split(row, " "); + String[] hostAndPort = StringUtils.split(values[1], ':'); + String host = hostAndPort[0]; + String port = hostAndPort[1].substring(0, hostAndPort[1].indexOf('@')); + String[] flagsValues = StringUtils.split(values[2], ':'); + Set flags = + Arrays.stream(flagsValues).map((v)->EnumUtils.getEnumIgnoreCase(ClusterRedisNode.Flag.class, v)) + .collect(Collectors.toSet()); + + ClusterRedisNode.LinkState linkState = EnumUtils.getEnumIgnoreCase(ClusterRedisNode.LinkState.class, values[7]); + SlotRange slotRange = null; + + if(values.length == 9){ + String[] slotRangeValues = StringUtils.split(values[8], '-'); + slotRange = new SlotRange(Integer.parseInt(slotRangeValues[0]), Integer.parseInt(slotRangeValues[1])); + } + + return new ClusterRedisNode(values[0], host, Integer.parseInt(port), flags, values[3], + Long.parseLong(values[4]), Long.parseLong(values[5]), Long.parseLong(values[6]), linkState, slotRange); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/CommandTypeConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/CommandTypeConverter.java new file mode 100644 index 000000000..b68d30dbc --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/CommandTypeConverter.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.SetListConverter; +import com.buession.redis.core.command.Command; +import io.lettuce.core.protocol.CommandType; +import org.springframework.lang.Nullable; + +/** + * Lettuce {@link CommandType} 转换为 {@link com.buession.redis.core.AclCategory} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class CommandTypeConverter implements Converter { + + @Nullable + @Override + public Command convert(final CommandType source) { + return source == null ? null : Enum.valueOf(Command.class, source.name()); + } + + public static SetListConverter setListConverter() { + return new SetListConverter<>(new CommandTypeConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/GeoCoordinateConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/GeoCoordinateConverter.java new file mode 100644 index 000000000..7b62b91cc --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/GeoCoordinateConverter.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Geo; +import io.lettuce.core.GeoCoordinates; + +import java.util.List; + +/** + * Lettuce {@link GeoCoordinates} 转换为 {@link Geo} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class GeoCoordinateConverter implements Converter { + + @Override + public Geo convert(final GeoCoordinates source) { + return new Geo(source.getX().doubleValue(), source.getY().doubleValue()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new GeoCoordinateConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/GeoRadiusGeneralResultConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/GeoRadiusGeneralResultConverter.java new file mode 100644 index 000000000..953f613e9 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/GeoRadiusGeneralResultConverter.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.SetListConverter; +import com.buession.redis.core.GeoRadius; + +import java.util.List; + +/** + * Lettuce georadius 命令结果转换为 {@link GeoRadius} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class GeoRadiusGeneralResultConverter implements Converter { + + @Override + public GeoRadius convert(final byte[] source) { + return new GeoRadius(source); + } + + public static SetListConverter setListConverter() { + return new SetListConverter<>(new GeoRadiusGeneralResultConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/GeoRadiusResponseConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/GeoRadiusResponseConverter.java new file mode 100644 index 000000000..476115213 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/GeoRadiusResponseConverter.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.SetListConverter; +import com.buession.redis.core.GeoRadius; +import io.lettuce.core.GeoWithin; + +import java.util.List; + +/** + * Lettuce georadius 命令结果转换为 {@link GeoRadius} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class GeoRadiusResponseConverter implements Converter, GeoRadius> { + + private final GeoCoordinateConverter geoCoordinateConverter = new GeoCoordinateConverter(); + + @Override + public GeoRadius convert(final GeoWithin source) { + return new GeoRadius(source.getMember(), source.getDistance(), + source.getCoordinates() == null ? null : geoCoordinateConverter.convert(source.getCoordinates())); + } + + public static ListConverter, GeoRadius> listConverter() { + return new ListConverter<>(new GeoRadiusResponseConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/KeyValueConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/KeyValueConverter.java new file mode 100644 index 000000000..5c3d1835c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/KeyValueConverter.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.lang.KeyValue; +import org.springframework.lang.Nullable; + +/** + * Lettuce {@link io.lettuce.core.KeyValue} 转换为 {@link KeyValue} + * + * @param + * 原始 Key 类型 + * @param + * 原始值类型 + * @param + * 目标 Key 类型 + * @param + * 目标值类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class KeyValueConverter implements Converter, + KeyValue> { + + /** + * Key 转换器 + */ + private final Converter keyConverter; + + /** + * 值转换器 + */ + private final Converter valueConverter; + + /** + * 构造函数 + * + * @param keyConverter + * Key 转换器 + * @param valueConverter + * 值转换器 + */ + public KeyValueConverter(final Converter keyConverter, final Converter valueConverter) { + this.keyConverter = keyConverter; + this.valueConverter = valueConverter; + } + + @Nullable + @Override + public KeyValue convert(final io.lettuce.core.KeyValue source) { + return new KeyValue<>(keyConverter.convert(source.getKey()), valueConverter.convert( + source.getValue())); + } + + public static ListConverter, KeyValue> listConverter( + final Converter keyConverter, final Converter valueConverter) { + return new ListConverter<>(new KeyValueConverter<>(keyConverter, valueConverter)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/PendingMessageConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/PendingMessageConverter.java new file mode 100644 index 000000000..2c811cf49 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/PendingMessageConverter.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamPending; +import io.lettuce.core.models.stream.PendingMessage; +import org.springframework.lang.Nullable; + +/** + * Lettuce {@link PendingMessage} 转换为 {@link StreamPending} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class PendingMessageConverter implements Converter { + + @Nullable + @Override + public StreamPending convert(final PendingMessage source) { + if(source == null){ + return null; + }else{ + return new StreamPending(new StreamEntryId(source.getId()), source.getConsumer(), + source.getMsSinceLastDelivery(), source.getRedeliveryCount()); + } + } + + public static ListConverter listConverter() { + return new ListConverter<>(new PendingMessageConverter()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GetExArgumentConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/PendingMessagesConverter.java similarity index 58% rename from buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GetExArgumentConverter.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/PendingMessagesConverter.java index e21393835..c7b0b5068 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GetExArgumentConverter.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/PendingMessagesConverter.java @@ -19,41 +19,43 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.redis.core.internal.convert.jedis.params; +package com.buession.redis.core.internal.convert.lettuce.response; import com.buession.core.converter.Converter; -import com.buession.core.converter.mapper.PropertyMapper; -import com.buession.redis.core.command.StringCommands; -import redis.clients.jedis.params.GetExParams; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamPendingSummary; +import io.lettuce.core.Range; +import io.lettuce.core.models.stream.PendingMessages; +import org.springframework.lang.Nullable; /** - * {@link StringCommands.GetExArgument} 转换为 jedis {@link GetExParams} + * Lettuce {@link PendingMessages} 转换为 {@link StreamPendingSummary} * * @author Yong.Teng - * @since 2.0.0 + * @since 3.0.0 */ -public final class GetExArgumentConverter implements Converter { - - public final static GetExArgumentConverter INSTANCE = new GetExArgumentConverter(); +public class PendingMessagesConverter implements Converter { + @Nullable @Override - public GetExParams convert(final StringCommands.GetExArgument source) { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - final GetExParams getExParams = new GetExParams(); - - propertyMapper.from(source.getEx()).to(getExParams::ex); - propertyMapper.from(source.getPx()).to(getExParams::px); - propertyMapper.from(source.getExAt()).to(getExParams::exAt); - propertyMapper.from(source.getPxAt()).to(getExParams::pxAt); - - if(Boolean.TRUE.equals(source.isPersist())){ - getExParams.persist(); + public StreamPendingSummary convert(final PendingMessages source) { + if(source == null){ + return null; + }else{ + final Range messageIds = source.getMessageIds(); + + return new StreamPendingSummary(source.getCount(), + new StreamEntryId(messageIds.getLower().getValue()), + new StreamEntryId(messageIds.getUpper().getValue()), source.getConsumerMessageCount()); } + } - return getExParams; + public static ListConverter listConverter() { + return new ListConverter<>(new PendingMessagesConverter()); } } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/RedisServerTimeConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/RedisServerTimeConverter.java new file mode 100644 index 000000000..540e93656 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/RedisServerTimeConverter.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.RedisServerTime; +import com.buession.redis.utils.SafeEncoder; + +import java.util.Date; +import java.util.List; + +/** + * Lettuce 返回的服务器时间转换为 {@link RedisServerTime} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class RedisServerTimeConverter implements Converter, RedisServerTime> { + + @Override + public RedisServerTime convert(final List source) { + if(source != null && source.size() == 2){ + Date date = new Date(Long.parseLong(SafeEncoder.encode(source.get(0))) * 1000L); + return new RedisServerTime(date, Long.parseLong(SafeEncoder.encode(source.get(1)))); + } + + return null; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/RoleConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/RoleConverter.java new file mode 100644 index 000000000..b6316afc4 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/RoleConverter.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.utils.EnumUtils; +import com.buession.redis.core.Role; + +import java.util.List; + +/** + * Lettuce 角色信息 转换为 {@link Role} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class RoleConverter implements Converter, Role> { + + @Override + public Role convert(final List source) { + if(source != null && source.size() == 3){ + return EnumUtils.getEnum(Role.class, new String((byte[]) source.get(0)).toUpperCase()); + } + + return null; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/ScanCursorConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/ScanCursorConverter.java new file mode 100644 index 000000000..c0e15dcd6 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/ScanCursorConverter.java @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapConverter; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; +import com.buession.redis.core.internal.convert.Converters; +import io.lettuce.core.KeyScanCursor; +import io.lettuce.core.MapScanCursor; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.ScoredValue; +import io.lettuce.core.ScoredValueScanCursor; +import io.lettuce.core.ValueScanCursor; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce {@link ScanCursor} 转换为 {@link ScanResult} + * + * @param + * {@link ScanCursor} 类型 + * @param + * {@link ScanResult} 类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface ScanCursorConverter extends Converter> { + + /** + * Lettuce {@link KeyScanCursor} 转换为 {@link ScanResult} + * + * @param + * Key 类型 + * + * @author Yong.Teng + */ + final class KeyScanCursorConverter implements ScanCursorConverter, List> { + + @Override + public ScanResult> convert(final KeyScanCursor source) { + return new ScanResult<>(source.getCursor(), source.getKeys()); + } + + /** + * Lettuce {@link KeyScanCursor} 转换为 {@link ScanResult} + * + * @author Yong.Teng + */ + public final static class BSKeyScanCursorConverter implements ScanCursorConverter, + List> { + + private final ListConverter binaryToStringListConverter = Converters.listBinaryToString(); + + @Override + public ScanResult> convert(final KeyScanCursor source) { + return new ScanResult<>(source.getCursor(), binaryToStringListConverter.convert(source.getKeys())); + } + + } + + } + + /** + * Lettuce {@link ValueScanCursor} 转换为 {@link ScanResult} + * + * @param + * Key 类型 + * + * @author Yong.Teng + */ + final class ValueScanCursorConverter implements ScanCursorConverter, List> { + + @Override + public ScanResult> convert(final ValueScanCursor source) { + return new ScanResult<>(source.getCursor(), source.getValues()); + } + + /** + * Lettuce {@link ValueScanCursor} 转换为 {@link ScanResult} + * + * @author Yong.Teng + */ + public final static class BSKeyScanCursorConverter implements ScanCursorConverter, + List> { + + private final ListConverter binaryToStringListConverter = Converters.listBinaryToString(); + + @Override + public ScanResult> convert(final ValueScanCursor source) { + return new ScanResult<>(source.getCursor(), binaryToStringListConverter.convert(source.getValues())); + } + + } + + /** + * Lettuce {@link ScoredValueScanCursor} 转换为 {@link ScanResult} + * + * @author Yong.Teng + */ + public final static class ScoredValueScanCursorConverter + implements ScanCursorConverter, List> { + + private final ListConverter, Tuple> listScoredValueConverter + = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + @Override + public ScanResult> convert(final ScoredValueScanCursor source) { + return new ScanResult<>(source.getCursor(), listScoredValueConverter.convert(source.getValues())); + } + + } + + } + + /** + * Lettuce {@link MapScanCursor} 转换为 {@link ScanResult} + * + * @param + * Key 类型 + * @param + * 值类型 + * + * @author Yong.Teng + */ + final class MapScanCursorConverter implements ScanCursorConverter, Map> { + + @Override + public ScanResult> convert(final MapScanCursor source) { + return new ScanResult<>(source.getCursor(), source.getMap()); + } + + /** + * Lettuce {@link MapScanCursor} 转换为 {@link ScanResult} + * + * @author Yong.Teng + */ + public final static class BvSvMapScanCursorConverter implements ScanCursorConverter, Map> { + + private final MapConverter binaryToStringMapConverter = + Converters.mapBinaryToString(); + + @Override + public ScanResult> convert(final MapScanCursor source) { + return new ScanResult<>(source.getCursor(), binaryToStringMapConverter.convert(source.getMap())); + } + + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/ScoredValueTupleConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/ScoredValueTupleConverter.java new file mode 100644 index 000000000..afff0cce6 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/ScoredValueTupleConverter.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.Tuple; +import io.lettuce.core.ScoredValue; +import org.springframework.lang.Nullable; + +/** + * Lettuce {@link ScoredValue} 转换为 {@link Tuple} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface ScoredValueTupleConverter extends Converter, Tuple> { + + final class StringScoredValueTupleConverter implements ScoredValueTupleConverter { + + @Nullable + @Override + public Tuple convert(final ScoredValue source) { + if(source == null){ + return null; + }else{ + return new Tuple(source.getValue(), source.getScore()); + } + } + + public static ListConverter, Tuple> listConverter() { + return new ListConverter<>(new StringScoredValueTupleConverter()); + } + + } + + final class BinaryScoredValueTupleConverter implements ScoredValueTupleConverter { + + @Nullable + @Override + public Tuple convert(final ScoredValue source) { + if(source == null){ + return null; + }else{ + return new Tuple(source.getValue(), source.getScore()); + } + } + + public static ListConverter, Tuple> listConverter() { + return new ListConverter<>(new BinaryScoredValueTupleConverter()); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/SlowlogConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/SlowlogConverter.java new file mode 100644 index 000000000..604c8bb45 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/SlowlogConverter.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.StringUtils; +import com.buession.redis.core.Client; +import com.buession.redis.core.SlowLog; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Lettuce 慢日志对象转换为 {@link SlowLog} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class SlowlogConverter implements Converter { + + @Override + public SlowLog convert(final Object source) { + if(source instanceof List){ + final List tmp = (List) source; + + if(tmp.size() == 6){ + final Client client = parseHostAndPort(tmp.get(4)); + final String clientName = parseClientName(tmp.get(5)); + + return new SlowLog((long) tmp.get(0), (long) tmp.get(1), (long) tmp.get(2), parseArgs(tmp.get(3)), + client, clientName); + } + } + + return null; + } + + private static Client parseHostAndPort(final Object value) { + final Client client = new Client(); + + if(value != null){ + String[] hostAndPort = StringUtils.split(new String((byte[]) value), ':'); + client.setHost(hostAndPort[0]); + client.setPort(Integer.parseInt(hostAndPort[1])); + } + + return client; + } + + private static String parseClientName(final Object value) { + return value == null ? null : new String((byte[]) value); + } + + private static List parseArgs(final Object value) { + if(value == null){ + return null; + } + + final List tmp = (List) value; + return tmp.stream().map((v)->v == null ? null : new String(v)).collect(Collectors.toList()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new SlowlogConverter()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/PoolConfigConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamConsumersInfoConverter.java similarity index 69% rename from buession-redis/src/main/java/com/buession/redis/client/connection/PoolConfigConverter.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamConsumersInfoConverter.java index 04415ee78..9b037a568 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/PoolConfigConverter.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamConsumersInfoConverter.java @@ -19,35 +19,34 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.redis.client.connection; +package com.buession.redis.core.internal.convert.lettuce.response; import com.buession.core.converter.Converter; -import com.buession.core.utils.Assert; -import com.buession.redis.core.PoolConfig; -import org.apache.commons.pool2.impl.GenericObjectPoolConfig; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamConsumer; import org.springframework.lang.Nullable; +import java.util.List; + /** + * Lettuce 'xinfo-consumers' 命令结果转换为 {@link StreamConsumer} + * * @author Yong.Teng - * @since 2.3.0 + * @since 3.0.0 */ -@Deprecated -public class PoolConfigConverter implements Converter> { - - private final GenericObjectPoolConfig poolConfig; - - public PoolConfigConverter(final GenericObjectPoolConfig poolConfig) { - Assert.isNull(poolConfig, "GenericObjectPoolConfig cloud not be null."); - this.poolConfig = poolConfig; - } +public final class StreamConsumersInfoConverter implements Converter { @Nullable @Override - public GenericObjectPoolConfig convert(PoolConfig config) { - return config.toGenericObjectPoolConfig(poolConfig); + public StreamConsumer convert(final Object source) { + return null; + } + + public static ListConverter listConverter() { + return new ListConverter<>(new StreamConsumersInfoConverter()); } } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamEntryIDConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamEntryIDConverter.java new file mode 100644 index 000000000..ee7dc9802 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamEntryIDConverter.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.StreamEntryId; +import org.springframework.lang.Nullable; + +/** + * Lettuce Message Id 转换为 {@link StreamEntryId} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class StreamEntryIDConverter implements Converter { + + @Nullable + @Override + public StreamEntryId convert(final String source) { + return source == null ? null : new StreamEntryId(source); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamFullInfoConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamFullInfoConverter.java new file mode 100644 index 000000000..b742f5a20 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamFullInfoConverter.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.StreamFull; +import org.springframework.lang.Nullable; + +import java.util.List; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public final class StreamFullInfoConverter implements Converter, StreamFull> { + + @Nullable + @Override + public StreamFull convert(final List source) { + return null; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamGroupInfoConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamGroupInfoConverter.java new file mode 100644 index 000000000..c4b84e0ec --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamGroupInfoConverter.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamGroup; +import org.springframework.lang.Nullable; + +import java.util.List; + +/** + * Lettuce 'xinfo-groups' 命令结果转换为 {@link StreamGroup} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class StreamGroupInfoConverter implements Converter { + + @Nullable + @Override + public StreamGroup convert(final Object source) { + return null; + } + + public static ListConverter listConverter() { + return new ListConverter<>(new StreamGroupInfoConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamInfoConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamInfoConverter.java new file mode 100644 index 000000000..51ec549c8 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamInfoConverter.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.Stream; +import org.springframework.lang.Nullable; + +import java.util.List; + +/** + * Lettuce 'xinfo-consumers' 命令结果转换为 {@link Stream} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class StreamInfoConverter implements Converter, Stream> { + + @Nullable + @Override + public Stream convert(final List source) { + return null; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamMessageConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamMessageConverter.java new file mode 100644 index 000000000..95aeef72a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamMessageConverter.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapConverter; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.internal.convert.Converters; +import io.lettuce.core.StreamMessage; +import org.springframework.lang.Nullable; + +/** + * Lettuce {@link StreamMessage} 转换为 {@link StreamEntry} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class StreamMessageConverter implements Converter, StreamEntry> { + + private final MapConverter binaryToStringMapConverter = + Converters.mapBinaryToString(); + + @Nullable + @Override + public StreamEntry convert(final StreamMessage source) { + return new StreamEntry(new StreamEntryId(source.getId()), binaryToStringMapConverter.convert(source.getBody())); + } + + public static ListConverter, StreamEntry> listConverter() { + return new ListConverter<>(new StreamMessageConverter()); + } + + /** + * Lettuce {@link StreamMessage} 转换为 {@link StreamEntryId} + * + * @author Yong.Teng + * @since 3.0.0 + */ + public final static class StreamMessageStreamEntryIdConverter implements Converter, + StreamEntryId> { + + @Override + public StreamEntryId convert(final StreamMessage source) { + return new StreamEntryId(source.getId()); + } + + public static ListConverter, StreamEntryId> listConverter() { + return new ListConverter<>(new StreamMessageStreamEntryIdConverter()); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamMessageMapConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamMessageMapConverter.java new file mode 100644 index 000000000..6300db7e4 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamMessageMapConverter.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapConverter; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.internal.convert.Converters; +import io.lettuce.core.StreamMessage; +import org.springframework.lang.Nullable; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce {@link StreamMessage} 转换为 {@link StreamEntry} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class StreamMessageMapConverter + implements Converter, Map>> { + + private final MapConverter binaryToStringMapConverter = + Converters.mapBinaryToString(); + + @Nullable + @Override + public Map> convert(final StreamMessage source) { + //return new StreamEntry(new StreamEntryId(source.getId()), + //binaryToStringMapConverter.convert(source.getBody())); + return null; + } + + public static ListConverter, Map>> listConverter() { + return new ListConverter<>(new StreamMessageMapConverter<>()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamPendingConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamPendingConverter.java new file mode 100644 index 000000000..531c57c91 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamPendingConverter.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamPending; +import io.lettuce.core.models.stream.PendingMessage; +import org.springframework.lang.Nullable; + +/** + * 'xpending' 命令结果转换为 {@link StreamPending} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class StreamPendingConverter implements Converter { + + @Nullable + @Override + public StreamPending convert(final PendingMessage source) { + return null; + } + + public static ListConverter listConverter() { + return new ListConverter<>(new StreamPendingConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamPendingSummaryConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamPendingSummaryConverter.java new file mode 100644 index 000000000..a8583d4cd --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/StreamPendingSummaryConverter.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.StreamPendingSummary; +import org.springframework.lang.Nullable; + +import java.util.List; + +/** + * 'xpending' 命令结果转换为 {@link StreamPendingSummary} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class StreamPendingSummaryConverter implements Converter, StreamPendingSummary> { + + @Nullable + @Override + public StreamPendingSummary convert(final List source) { + return null; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/TransactionResultConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/TransactionResultConverter.java new file mode 100644 index 000000000..d9c7112b3 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/TransactionResultConverter.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import io.lettuce.core.TransactionResult; +import org.springframework.lang.Nullable; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Lettuce {@link TransactionResult} 转换为 List>Object< + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class TransactionResultConverter implements Converter> { + + @Nullable + @Override + public List convert(final TransactionResult source) { + if(source == null){ + return null; + }else{ + return source.stream().collect(Collectors.toList()); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/ValueConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/ValueConverter.java new file mode 100644 index 000000000..db17f963e --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/ValueConverter.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import io.lettuce.core.Value; +import org.springframework.lang.Nullable; + +/** + * Lettuce {@link Value} 转换为 >T< + * + * @param + * 源类型 + * @param + * 目标类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class ValueConverter implements Converter, TV> { + + private final Converter valueConverter; + + public ValueConverter(final Converter valueConverter) { + this.valueConverter = valueConverter; + } + + @Nullable + @Override + public TV convert(final Value source) { + return source == null ? null : valueConverter.convert(source.getValue()); + } + + public static ListConverter, TV> listConverter(final Converter valueConverter) { + return new ListConverter<>(new ValueConverter<>(valueConverter)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/package-info.java new file mode 100644 index 000000000..6642a50b8 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/lettuce/response/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.core.internal.convert.lettuce.response; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/BinaryObjectEncodingConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/BinaryObjectEncodingConverter.java new file mode 100644 index 000000000..4d0084184 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/BinaryObjectEncodingConverter.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.BinaryEnumConverter; +import com.buession.redis.core.ObjectEncoding; + +/** + * byte[] 形式的 ObjectEncoding 转换为 {@link ObjectEncoding} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class BinaryObjectEncodingConverter extends BinaryEnumConverter { + + public BinaryObjectEncodingConverter() { + super(ObjectEncoding.class); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/BumpEpochConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/BumpEpochConverter.java new file mode 100644 index 000000000..bdc5e5114 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/BumpEpochConverter.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.Converter; +import com.buession.core.utils.EnumUtils; +import com.buession.core.utils.KeyValueParser; +import com.buession.lang.KeyValue; +import com.buession.redis.core.BumpEpoch; + +/** + * Cluster BumpEpoch 命令结果转换为 {@link BumpEpoch} + * + * @author Yong.Teng + * @since 2.3.0 + */ +public final class BumpEpochConverter implements Converter> { + + @Override + public KeyValue convert(final String source) { + final KeyValueParser keyValueParser = new KeyValueParser(source, " "); + return new KeyValue<>(EnumUtils.getEnum(BumpEpoch.class, keyValueParser.getKey()), + keyValueParser.getIntValue()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ClientConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ClientConverter.java new file mode 100644 index 000000000..d41f02550 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ClientConverter.java @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.Converter; +import com.buession.core.utils.EnumUtils; +import com.buession.core.utils.KeyValueParser; +import com.buession.core.utils.StringUtils; +import com.buession.core.validator.Validate; +import com.buession.redis.core.Client; +import com.buession.redis.core.command.Command; + +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Client Info 命令结果转换为 {@link Client} + * + * @author Yong.Teng + * @since 2.3.0 + */ +public final class ClientConverter implements Converter { + + @Override + public Client convert(final String source) { + String[] properties = StringUtils.splitByWholeSeparatorPreserveAllTokens(source, " "); + + if(Validate.isEmpty(properties)){ + return null; + } + + Client client = new Client(); + KeyValueParser keyValueParser; + + for(String property : properties){ + keyValueParser = new KeyValueParser(property, '='); + + if("id".equals(keyValueParser.getKey())){ + client.setId(keyValueParser.getIntValue()); + }else if("addr".equals(keyValueParser.getKey())){ + int ci = keyValueParser.getValue().indexOf(':'); + + client.setAddr(keyValueParser.getValue()); + client.setHost(keyValueParser.getValue().substring(0, ci)); + client.setPort(Integer.parseInt(keyValueParser.getValue().substring(ci + 1))); + }else if("name".equals(keyValueParser.getKey())){ + client.setName(keyValueParser.getValue()); + }else if("fd".equals(keyValueParser.getKey())){ + client.setFd(keyValueParser.getIntValue()); + }else if("age".equals(keyValueParser.getKey())){ + client.setAge(keyValueParser.getIntValue()); + }else if("idle".equals(keyValueParser.getKey())){ + client.setIdle(keyValueParser.getIntValue()); + }else if("flags".equals(keyValueParser.getKey())){ + String[] flagsArr = StringUtils.splitByWholeSeparatorPreserveAllTokens(keyValueParser.getValue(), + ","); + + if(flagsArr != null){ + Set flags = new LinkedHashSet<>(flagsArr.length); + + for(String s : flagsArr){ + Client.Flag flag = EnumUtils.valueOf(Client.Flag.class, s); + + if(flag != null){ + flags.add(flag); + } + } + + client.setFlags(flags); + } + }else if("db".equals(keyValueParser.getKey())){ + client.setDb(keyValueParser.getIntValue()); + }else if("sub".equals(keyValueParser.getKey())){ + client.setSub(keyValueParser.getIntValue()); + }else if("psub".equals(keyValueParser.getKey())){ + client.setPsub(keyValueParser.getIntValue()); + }else if("multi".equals(keyValueParser.getKey())){ + client.setMulti(keyValueParser.getIntValue()); + }else if("qbuf".equals(keyValueParser.getKey())){ + client.setQBuf(keyValueParser.getIntValue()); + }else if("qbuf-free".equals(keyValueParser.getKey())){ + client.setQBufFree(keyValueParser.getIntValue()); + }else if("obl".equals(keyValueParser.getKey())){ + client.setObl(keyValueParser.getIntValue()); + }else if("oll".equals(keyValueParser.getKey())){ + client.setOll(keyValueParser.getIntValue()); + }else if("omem".equals(keyValueParser.getKey())){ + client.setOmem(keyValueParser.getIntValue()); + }else if("events".equals(keyValueParser.getKey())){ + client.setEvents(keyValueParser.getEnumValue(Client.Event.class)); + }else if("cmd".equals(keyValueParser.getKey())){ + client.setCmd(keyValueParser.getEnumValue(Command.class)); + } + } + + return client; + } + + /** + * Client Info 命令结果转换为 {@link List} {@link Client} + * + * @author Yong.Teng + * @since 2.3.0 + */ + public final static class ClientListConverter implements Converter> { + + private final ClientConverter clientConverter = new ClientConverter(); + + @Override + public List convert(final String source) { + return Arrays.stream(StringUtils.split(source, "\r\n")).map(clientConverter::convert).collect( + Collectors.toList()); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ClusterInfoConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ClusterInfoConverter.java new file mode 100644 index 000000000..8fa81d747 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ClusterInfoConverter.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.Converter; +import com.buession.core.utils.KeyValueParser; +import com.buession.core.utils.StringUtils; +import com.buession.redis.core.ClusterInfo; + +/** + * Cluster Info 命令结果转换为 {@link ClusterInfo} + * + * @author Yong.Teng + * @since 2.3.0 + */ +public final class ClusterInfoConverter implements Converter { + + @Override + public ClusterInfo convert(final String source) { + String[] rows = StringUtils.split(source, "\r\n"); + KeyValueParser keyValueParser; + ClusterInfo.State state = null; + int slotsAssigned = 0; + int slotsOk = 0; + int slotsPfail = 0; + int slotsFail = 0; + int knownNodes = 0; + int size = 0; + int currentEpoch = 0; + int myEpoch = 0; + long messagesPingSent = 0; + long messagesPongSent = 0; + long messagesSent = 0; + long messagesPingReceived = 0; + long messagesPongReceived = 0; + long messagesMeetReceived = 0; + long messagesReceived = 0; + + for(String row : rows){ + keyValueParser = new KeyValueParser(row, ':'); + + if(ClusterInfo.Key.STATE.getValue().equals(keyValueParser.getKey())){ + state = "ok".equalsIgnoreCase( + keyValueParser.getValue()) ? ClusterInfo.State.OK : ClusterInfo.State.FAIL; + }else if(ClusterInfo.Key.SLOTS_ASSIGNED.getValue().equals(keyValueParser.getKey())){ + slotsAssigned = keyValueParser.getIntValue(); + }else if(ClusterInfo.Key.SLOTS_OK.getValue().equals(keyValueParser.getKey())){ + slotsOk = keyValueParser.getIntValue(); + }else if(ClusterInfo.Key.SLOTS_PFAIL.getValue().equals(keyValueParser.getKey())){ + slotsPfail = keyValueParser.getIntValue(); + }else if(ClusterInfo.Key.SLOTS_FAIL.getValue().equals(keyValueParser.getKey())){ + slotsFail = keyValueParser.getIntValue(); + }else if(ClusterInfo.Key.KNOWN_NODES.getValue().equals(keyValueParser.getKey())){ + knownNodes = keyValueParser.getIntValue(); + }else if(ClusterInfo.Key.SIZE.getValue().equals(keyValueParser.getKey())){ + size = keyValueParser.getIntValue(); + }else if(ClusterInfo.Key.CURRENT_EPOCH.getValue().equals(keyValueParser.getKey())){ + currentEpoch = keyValueParser.getIntValue(); + }else if(ClusterInfo.Key.MY_EPOCH.getValue().equals(keyValueParser.getKey())){ + myEpoch = keyValueParser.getIntValue(); + }else if(ClusterInfo.Key.MESSAGES_PING_SENT.getValue().equals(keyValueParser.getKey())){ + messagesPingSent = keyValueParser.getIntValue(); + }else if(ClusterInfo.Key.MESSAGES_PONG_SENT.getValue().equals(keyValueParser.getKey())){ + messagesPongSent = keyValueParser.getIntValue(); + }else if(ClusterInfo.Key.MESSAGES_SENT.getValue().equals(keyValueParser.getKey())){ + messagesSent = keyValueParser.getIntValue(); + }else if(ClusterInfo.Key.MESSAGES_PING_RECEIVED.getValue().equals(keyValueParser.getKey())){ + messagesPingReceived = keyValueParser.getIntValue(); + }else if(ClusterInfo.Key.MESSAGES_PONG_RECEIVED.getValue().equals(keyValueParser.getKey())){ + messagesPongReceived = keyValueParser.getIntValue(); + }else if(ClusterInfo.Key.MESSAGES_MEET_RECEIVED.getValue().equals(keyValueParser.getKey())){ + messagesMeetReceived = keyValueParser.getIntValue(); + }else if(ClusterInfo.Key.MESSAGES_RECEIVED.getValue().equals(keyValueParser.getKey())){ + messagesReceived = keyValueParser.getIntValue(); + } + } + + return new ClusterInfo(state, slotsAssigned, slotsOk, slotsPfail, slotsFail, knownNodes, size, currentEpoch, + myEpoch, messagesPingSent, messagesPongSent, messagesSent, messagesPingReceived, messagesPongReceived, + messagesMeetReceived, messagesReceived); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ClusterNodeConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ClusterNodeConverter.java new file mode 100644 index 000000000..b043333f9 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ClusterNodeConverter.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.EnumUtils; +import com.buession.core.utils.StringUtils; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.SlotRange; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * Cluster Slaves 命令结果转换为 {@link ClusterRedisNode} + * + * @author Yong.Teng + * @since 2.3.0 + */ +public final class ClusterNodeConverter implements Converter { + + @Override + public ClusterRedisNode convert(final String source) { + String[] values = StringUtils.split(source, " "); + String[] hostAndPort = StringUtils.split(values[1], ":"); + String host = hostAndPort[0]; + String port = hostAndPort[1].substring(0, hostAndPort[1].indexOf('@')); + String[] flagsValues = StringUtils.split(values[2], ":"); + Set flags = new HashSet<>(flagsValues.length); + + for(String flagsValue : flagsValues){ + flags.add(EnumUtils.getEnumIgnoreCase(ClusterRedisNode.Flag.class, flagsValue)); + } + + ClusterRedisNode.LinkState linkState = EnumUtils.getEnumIgnoreCase(ClusterRedisNode.LinkState.class, values[7]); + SlotRange slotRange = null; + + if(values.length == 9){ + String[] slotRangeValues = StringUtils.split(values[8], "-"); + slotRange = new SlotRange(Integer.parseInt(slotRangeValues[0]), Integer.parseInt(slotRangeValues[1])); + } + + return new ClusterRedisNode(values[0], host, Integer.parseInt(port), flags, values[3], + Long.parseLong(values[4]), Long.parseLong(values[5]), Long.parseLong(values[6]), linkState, slotRange); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new ClusterNodeConverter()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ClusterNodesConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ClusterNodesConverter.java new file mode 100644 index 000000000..c929c1311 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ClusterNodesConverter.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.Converter; +import com.buession.core.utils.StringUtils; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.RedisClusterServer; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Cluster Nodes 命令结果转换为 {@link RedisClusterServer} 列表 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class ClusterNodesConverter implements Converter> { + + private final ClusterNodeConverter clusterNodeConverter = new ClusterNodeConverter(); + + @Override + public List convert(final String source) { + return Arrays.stream(StringUtils.split(source, "\r\n")).map(clusterNodeConverter::convert).collect( + Collectors.toList()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/SortArgumentConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ClusterSlotConverter.java similarity index 54% rename from buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/SortArgumentConverter.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ClusterSlotConverter.java index 556ddfa3f..384b9f9c3 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/SortArgumentConverter.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ClusterSlotConverter.java @@ -19,52 +19,60 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.redis.core.internal.convert.jedis.params; +package com.buession.redis.core.internal.convert.response; import com.buession.core.converter.Converter; -import com.buession.core.converter.mapper.PropertyMapper; -import com.buession.lang.Order; -import com.buession.redis.core.Limit; -import com.buession.redis.core.command.KeyCommands; -import redis.clients.jedis.params.SortingParams; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.ClusterSlot; +import com.buession.redis.core.RedisServer; +import com.buession.redis.utils.SafeEncoder; + +import java.util.ArrayList; +import java.util.List; /** - * {@link KeyCommands.SortArgument} 转换为 jedis {@link SortingParams} + * Cluster Slots 命令结果转换为 {@link ClusterSlot} * * @author Yong.Teng - * @since 2.0.0 + * @since 2.3.0 */ -public final class SortArgumentConverter implements Converter { - - public final static SortArgumentConverter INSTANCE = new SortArgumentConverter(); +public final class ClusterSlotConverter implements Converter { @Override - public SortingParams convert(final KeyCommands.SortArgument source) { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - final SortingParams sortingParams = new SortingParams(); + @SuppressWarnings({"unchecked"}) + public ClusterSlot convert(final Object source) { + if(source instanceof List){ + List data = (List) source; - propertyMapper.from(source.getBy()).to(sortingParams::by); - propertyMapper.from(source.getGetPatterns()).to(sortingParams::get); + if(data.size() >= 3){ + final long start = (long) data.get(0); + final long end = (long) data.get(1); + final List masterNodes = new ArrayList<>(data.size() - 2); + List masterNode; - if(source.getOrder() == Order.ASC){ - sortingParams.asc(); - }else if(source.getOrder() == Order.DESC){ - sortingParams.desc(); - } + for(int i = 2; i < data.size(); i++){ + masterNode = (List) data.get(i); - if(source.getLimit() != null){ - Limit limit = source.getLimit(); - sortingParams.limit((int) limit.getOffset(), (int) limit.getCount()); - } + RedisServer redisServer = new RedisServer( + SafeEncoder.encode((byte[]) masterNode.get(0)), ((Long) masterNode.get(1)).intValue()); - if(Boolean.TRUE.equals(source.isAlpha())){ - sortingParams.alpha(); + redisServer.setId(SafeEncoder.encode((byte[]) masterNode.get(2))); + + masterNodes.add(redisServer); + } + + return new ClusterSlot(start, end, masterNodes); + } } - return sortingParams; + return null; + } + + public static ListConverter listConverter() { + return new ListConverter<>(new ClusterSlotConverter()); } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/InfoConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/InfoConverter.java similarity index 98% rename from buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/InfoConverter.java rename to buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/InfoConverter.java index 6ac13d85d..9ab5936cb 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/InfoConverter.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/InfoConverter.java @@ -19,10 +19,10 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.redis.core.internal.convert.jedis.response; +package com.buession.redis.core.internal.convert.response; import com.buession.core.converter.Converter; import com.buession.core.utils.EnumUtils; @@ -49,14 +49,12 @@ * Info 转换 * * @author Yong.Teng - * @since 2.0.0 + * @since 3.0.0 */ -public class InfoConverter implements Converter { +public final class InfoConverter implements Converter { private final static Pattern PATTERN = Pattern.compile("# (\\S+)[\\s]+([^#]+)"); - public final static InfoConverter INSTANCE = new InfoConverter(); - @Override public Info convert(final String source) { Info.Server server = null; diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ObjectEncodingConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ObjectEncodingConverter.java new file mode 100644 index 000000000..171ecd107 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/ObjectEncodingConverter.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.EnumConverter; +import com.buession.redis.core.ObjectEncoding; + +/** + * 字符串形式的 ObjectEncoding 转换为 {@link ObjectEncoding} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class ObjectEncodingConverter extends EnumConverter { + + public ObjectEncodingConverter() { + super(ObjectEncoding.class); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/OkStatusConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/OkStatusConverter.java new file mode 100644 index 000000000..cb31b8b0a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/OkStatusConverter.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.core.Constants; + +/** + * OK 结果转换器 + * + * @author Yong.Teng + * @since 1.2.2 + */ +public final class OkStatusConverter implements Converter { + + @Override + public Status convert(final String source) { + return Status.valueOf(Constants.OK.equalsIgnoreCase(source)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/OneBooleanConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/OneBooleanConverter.java new file mode 100644 index 000000000..2cb302758 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/OneBooleanConverter.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.PredicateConverter; + +/** + * "1" 到 {@link Boolean} 转换 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class OneBooleanConverter extends PredicateConverter { + + public OneBooleanConverter() { + super((val)->val == 1L); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/OneStatusConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/OneStatusConverter.java new file mode 100644 index 000000000..8582481b7 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/OneStatusConverter.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.PredicateStatusConverter; +import com.buession.lang.Status; + +/** + * "1" 到 {@link Status} 转换 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class OneStatusConverter extends PredicateStatusConverter { + + public OneStatusConverter() { + super((val)->val == 1L); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/PingResultConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/PingResultConverter.java new file mode 100644 index 000000000..906967fe8 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/PingResultConverter.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.core.Constants; + +/** + * Ping 结果转换器 + * + * @author Yong.Teng + * @since 1.2.2 + */ +public final class PingResultConverter implements Converter { + + @Override + public Status convert(final String source) { + return Status.valueOf(Constants.PONG.equalsIgnoreCase(source)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/TypeConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/TypeConverter.java new file mode 100644 index 000000000..3732d3e18 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/TypeConverter.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.EnumConverter; +import com.buession.redis.core.Type; + +/** + * 字符串形式的 type 转换为 {@link Type} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class TypeConverter extends EnumConverter { + + public TypeConverter() { + super(Type.class); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/package-info.java new file mode 100644 index 000000000..c9b91c3f1 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/convert/response/package-info.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + * @since 2.0.0 + */ +package com.buession.redis.core.internal.convert.response; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisBitPosParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisBitPosParams.java new file mode 100644 index 000000000..7d0129f38 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisBitPosParams.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.BitType; +import com.buession.redis.core.internal.convert.jedis.params.BitTypeConverter; +import redis.clients.jedis.args.BitCountOption; +import redis.clients.jedis.params.BitPosParams; + +/** + * Jedis {@link BitPosParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisBitPosParams extends BitPosParams { + + private final static BitTypeConverter bitTypeConverter = new BitTypeConverter(); + + /** + * 构造函数 + */ + public JedisBitPosParams() { + super(); + } + + /** + * 构造函数 + * + * @param start + * 开始位置 + */ + public JedisBitPosParams(final long start) { + super(start); + } + + /** + * 构造函数 + * + * @param start + * 开始位置 + * @param end + * 结束位置 + */ + public JedisBitPosParams(final long start, final long end) { + super(start, end); + } + + /** + * 构造函数 + * + * @param start + * 开始位置 + * @param modifier + * {@link BitCountOption} + */ + public JedisBitPosParams(final long start, final BitCountOption modifier) { + super(start); + modifier(modifier); + } + + /** + * 构造函数 + * + * @param start + * 开始位置 + * @param bitType + * {@link BitType} + */ + public JedisBitPosParams(final long start, final BitType bitType) { + super(start); + modifier(bitType); + } + + /** + * 构造函数 + * + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param modifier + * {@link BitCountOption} + */ + public JedisBitPosParams(final long start, final long end, final BitCountOption modifier) { + super(start, end); + modifier(modifier); + } + + /** + * 构造函数 + * + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param bitType + * {@link BitType} + */ + public JedisBitPosParams(final long start, final long end, final BitType bitType) { + super(start, end); + modifier(bitType); + } + + public JedisBitPosParams modifier(final BitType bitType) { + modifier(bitTypeConverter.convert(bitType)); + return this; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisClientConfigBuilder.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisClientConfigBuilder.java new file mode 100644 index 000000000..80d4e764d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisClientConfigBuilder.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.validator.Validate; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.datasource.jedis.JedisRedisDataSource; +import redis.clients.jedis.DefaultJedisClientConfig; + +/** + * @author Yong.Teng + * @since 2.1.2 + */ +public class JedisClientConfigBuilder { + + private final DefaultJedisClientConfig.Builder builder = DefaultJedisClientConfig.builder(); + + private final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); + + private JedisClientConfigBuilder(final JedisRedisDataSource dataSource, final SslConfiguration sslConfiguration) { + builder.connectionTimeoutMillis(dataSource.getConnectTimeout()) + .socketTimeoutMillis(dataSource.getSoTimeout()) + .blockingSocketTimeoutMillis(dataSource.getInfiniteSoTimeout()) + .ssl(sslConfiguration != null); + + propertyMapper.from(dataSource.getClientName()).to(builder::clientName); + + if(Validate.hasText(dataSource.getPassword())){ + propertyMapper.from(dataSource.getUsername()).to(builder::user); + builder.password(dataSource.getPassword()); + } + + if(sslConfiguration != null){ + builder.sslSocketFactory(sslConfiguration.getSslSocketFactory()) + .sslParameters(sslConfiguration.getSslParameters()) + .hostnameVerifier(sslConfiguration.getHostnameVerifier()); + } + } + + public static JedisClientConfigBuilder create(final JedisRedisDataSource dataSource, + final SslConfiguration sslConfiguration) { + return new JedisClientConfigBuilder(dataSource, sslConfiguration); + } + + public JedisClientConfigBuilder user(final String user) { + propertyMapper.from(user).to(builder::user); + return this; + } + + public JedisClientConfigBuilder password(final String password) { + propertyMapper.from(password).to(builder::password); + return this; + } + + public JedisClientConfigBuilder database(final int database) { + if(database >= 0){ + builder.database(database); + } + return this; + } + + public JedisClientConfigBuilder clientName(final String clientName) { + propertyMapper.from(clientName).to(builder::clientName); + return this; + } + + public JedisClientConfigBuilder connectTimeout(final int connectTimeout) { + builder.connectionTimeoutMillis(connectTimeout); + return this; + } + + public JedisClientConfigBuilder socketTimeout(final int socketTimeout) { + builder.socketTimeoutMillis(socketTimeout); + return this; + } + + public JedisClientConfigBuilder infiniteSoTimeout(final int blockingSocketTimeout) { + builder.blockingSocketTimeoutMillis(blockingSocketTimeout); + return this; + } + + public DefaultJedisClientConfig build() { + return builder.build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisClientKillParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisClientKillParams.java new file mode 100644 index 000000000..6830acf7f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisClientKillParams.java @@ -0,0 +1,869 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.ClientType; +import com.buession.redis.core.command.args.ClientKillArgument; +import com.buession.redis.core.internal.convert.jedis.params.ClientTypeConverter; +import redis.clients.jedis.params.ClientKillParams; + +import java.util.Optional; + +/** + * Jedis {@link ClientKillParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisClientKillParams extends ClientKillParams { + + /** + * 构造函数 + */ + public JedisClientKillParams() { + super(); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + */ + public JedisClientKillParams(final long clientId) { + super(); + id(clientId); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + */ + public JedisClientKillParams(final String clientId) { + super(); + id(clientId); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + */ + public JedisClientKillParams(final byte[] clientId) { + super(); + id(clientId); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + */ + public JedisClientKillParams(final ClientType clientType) { + super(); + type(clientType); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + */ + public JedisClientKillParams(final redis.clients.jedis.args.ClientType clientType) { + super(); + type(clientType); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final long clientId, final boolean skipMe, final long maxAge) { + this(clientId); + skipMe(skipMe ? SkipMe.YES : SkipMe.NO); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final String clientId, final boolean skipMe, final long maxAge) { + this(clientId); + skipMe(skipMe ? SkipMe.YES : SkipMe.NO); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final byte[] clientId, final boolean skipMe, final long maxAge) { + this(clientId); + skipMe(skipMe ? SkipMe.YES : SkipMe.NO); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final ClientType clientType, final boolean skipMe, final long maxAge) { + this(clientType); + skipMe(skipMe ? SkipMe.YES : SkipMe.NO); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final redis.clients.jedis.args.ClientType clientType, final boolean skipMe, + final long maxAge) { + this(clientType); + skipMe(skipMe ? SkipMe.YES : SkipMe.NO); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final long clientId, final SkipMe skipMe, final long maxAge) { + this(clientId); + skipMe(skipMe); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final String clientId, final SkipMe skipMe, final long maxAge) { + this(clientId); + skipMe(skipMe); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final byte[] clientId, final SkipMe skipMe, final long maxAge) { + this(clientId); + skipMe(skipMe); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final ClientType clientType, final SkipMe skipMe, final long maxAge) { + this(clientType); + skipMe(skipMe); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final redis.clients.jedis.args.ClientType clientType, final SkipMe skipMe, + final long maxAge) { + this(clientType); + skipMe(skipMe); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final long clientId, final String addr, final String laddr, final boolean skipMe, + final long maxAge) { + this(clientId, skipMe, maxAge); + addr(addr); + laddr(laddr); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final String clientId, final String addr, final String laddr, final boolean skipMe, + final long maxAge) { + this(clientId, skipMe, maxAge); + addr(addr); + laddr(laddr); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final byte[] clientId, final String addr, final String laddr, final boolean skipMe, + final long maxAge) { + this(clientId, skipMe, maxAge); + addr(addr); + laddr(laddr); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final ClientType clientType, final String addr, final String laddr, + final boolean skipMe, final long maxAge) { + this(clientType, skipMe, maxAge); + addr(addr); + laddr(laddr); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final redis.clients.jedis.args.ClientType clientType, final String addr, + final String laddr, final boolean skipMe, final long maxAge) { + this(clientType, skipMe, maxAge); + addr(addr); + laddr(laddr); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final long clientId, final String addr, final String laddr, final SkipMe skipMe, + final long maxAge) { + this(clientId, skipMe, maxAge); + addr(addr); + laddr(laddr); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final String clientId, final String addr, final String laddr, final SkipMe skipMe, + final long maxAge) { + this(clientId, skipMe, maxAge); + addr(addr); + laddr(laddr); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final byte[] clientId, final String addr, final String laddr, final SkipMe skipMe, + final long maxAge) { + this(clientId, skipMe, maxAge); + addr(addr); + laddr(laddr); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final ClientType clientType, final String addr, final String laddr, + final SkipMe skipMe, final long maxAge) { + this(clientType, skipMe, maxAge); + addr(addr); + laddr(laddr); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final redis.clients.jedis.args.ClientType clientType, final String addr, + final String laddr, final SkipMe skipMe, final long maxAge) { + this(clientType, skipMe, maxAge); + addr(addr); + laddr(laddr); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final long clientId, final String username, final String addr, final String laddr, + final boolean skipMe, final long maxAge) { + this(clientId, addr, laddr, skipMe, maxAge); + user(username); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final String clientId, final String username, final String addr, final String laddr, + final boolean skipMe, final long maxAge) { + this(clientId, addr, laddr, skipMe, maxAge); + user(username); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final byte[] clientId, final String username, final String addr, final String laddr, + final boolean skipMe, final long maxAge) { + this(clientId, addr, laddr, skipMe, maxAge); + user(username); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final ClientType clientType, final String username, final String addr, + final String laddr, final boolean skipMe, final long maxAge) { + this(clientType, addr, laddr, skipMe, maxAge); + user(username); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final redis.clients.jedis.args.ClientType clientType, final String username, + final String addr, final String laddr, final boolean skipMe, final long maxAge) { + this(clientType, addr, laddr, skipMe, maxAge); + user(username); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final long clientId, final String username, final String addr, final String laddr, + final SkipMe skipMe, final long maxAge) { + this(clientId, addr, laddr, skipMe, maxAge); + user(username); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final String clientId, final String username, final String addr, final String laddr, + final SkipMe skipMe, final long maxAge) { + this(clientId, addr, laddr, skipMe, maxAge); + user(username); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final byte[] clientId, final String username, final String addr, final String laddr, + final SkipMe skipMe, final long maxAge) { + this(clientId, addr, laddr, skipMe, maxAge); + user(username); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final ClientType clientType, final String username, final String addr, + final String laddr, final SkipMe skipMe, final long maxAge) { + this(clientType, addr, laddr, skipMe, maxAge); + user(username); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final redis.clients.jedis.args.ClientType clientType, final String username, + final String addr, final String laddr, final SkipMe skipMe, final long maxAge) { + this(clientType, addr, laddr, skipMe, maxAge); + user(username); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param clientType + * 客户端类型 + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final long clientId, final ClientType clientType, final String username, + final String addr, final String laddr, final boolean skipMe, final long maxAge) { + this(clientType, username, addr, laddr, skipMe, maxAge); + id(Long.toString(clientId)); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param clientType + * 客户端类型 + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final String clientId, final ClientType clientType, final String username, + final String addr, final String laddr, final boolean skipMe, final long maxAge) { + this(clientType, username, addr, laddr, skipMe, maxAge); + id(clientId); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param clientType + * 客户端类型 + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final byte[] clientId, final ClientType clientType, final String username, + final String addr, final String laddr, final boolean skipMe, final long maxAge) { + this(clientType, username, addr, laddr, skipMe, maxAge); + id(clientId); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param clientType + * 客户端类型 + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final long clientId, final redis.clients.jedis.args.ClientType clientType, + final String username, final String addr, final String laddr, final boolean skipMe, + final long maxAge) { + this(clientType, username, addr, laddr, skipMe, maxAge); + id(Long.toString(clientId)); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param clientType + * 客户端类型 + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final String clientId, final redis.clients.jedis.args.ClientType clientType, + final String username, final String addr, final String laddr, final boolean skipMe, + final long maxAge) { + this(clientType, username, addr, laddr, skipMe, maxAge); + id(clientId); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param clientType + * 客户端类型 + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public JedisClientKillParams(final byte[] clientId, final redis.clients.jedis.args.ClientType clientType, + final String username, final String addr, final String laddr, final boolean skipMe, + final long maxAge) { + this(clientType, username, addr, laddr, skipMe, maxAge); + id(clientId); + } + + public JedisClientKillParams id(final long clientId) { + id(Long.toString(clientId)); + return this; + } + + public JedisClientKillParams type(final ClientType clientType) { + type((new ClientTypeConverter()).convert(clientType)); + return this; + } + + public JedisClientKillParams skipMe(final boolean skipMe) { + skipMe(skipMe ? SkipMe.YES : SkipMe.NO); + return this; + } + + /** + * 从 {@link ClientKillArgument} 创建 {@link ClientKillParams} 实例 + * + * @param clientKillArgument + * {@link ClientKillArgument} + * + * @return {@link JedisClientKillParams} 实例 + */ + public static JedisClientKillParams from(final ClientKillArgument clientKillArgument) { + final JedisClientKillParams clientKillParams = new JedisClientKillParams(); + + Optional.ofNullable(clientKillArgument.getClientId()).ifPresent(clientKillParams::id); + Optional.ofNullable(clientKillArgument.getClientType()).ifPresent(clientKillParams::type); + Optional.ofNullable(clientKillArgument.getUsername()).ifPresent(clientKillParams::user); + Optional.ofNullable(clientKillArgument.getAddr()).ifPresent(clientKillParams::addr); + Optional.ofNullable(clientKillArgument.getLaddr()).ifPresent(clientKillParams::laddr); + Optional.ofNullable(clientKillArgument.getSkipMe()).ifPresent(clientKillParams::skipMe); + + return clientKillParams; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisFailoverParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisFailoverParams.java new file mode 100644 index 000000000..ab3acbe5b --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisFailoverParams.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import redis.clients.jedis.params.FailoverParams; + +/** + * Jedis {@link FailoverParams} 扩展 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisFailoverParams extends FailoverParams { + + /** + * 构造函数 + */ + public JedisFailoverParams() { + super(); + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + */ + public JedisFailoverParams(final String host, final int port) { + super(); + to(host, port); + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + * @param timeout + * 超时 + */ + public JedisFailoverParams(final String host, final int port, final int timeout) { + this(host, port); + timeout(timeout); + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + * @param force + * 是否强制 + */ + public JedisFailoverParams(final String host, final int port, final boolean force) { + this(host, port); + force(force); + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + * @param timeout + * 超时 + * @param force + * 是否强制 + */ + public JedisFailoverParams(final String host, final int port, final int timeout, final boolean force) { + this(host, port, timeout); + force(force); + } + + /** + * 构造函数 + * + * @param timeout + * 超时 + */ + public JedisFailoverParams(final int timeout) { + super(); + timeout(timeout); + } + + /** + * 构造函数 + * + * @param timeout + * 超时 + * @param force + * 是否强制 + */ + public JedisFailoverParams(final int timeout, final boolean force) { + this(timeout); + force(force); + } + + private void force(boolean force) { + if(force){ + force(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGeoAddParam.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGeoAddParam.java new file mode 100644 index 000000000..fef21a2d8 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGeoAddParam.java @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.NxXx; +import com.buession.redis.core.command.args.GeoAddArgument; +import redis.clients.jedis.params.GeoAddParams; + +/** + * Jedis {@link redis.clients.jedis.params.GeoAddParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisGeoAddParam extends GeoAddParams { + + /** + * 构造函数 + */ + public JedisGeoAddParam() { + super(); + } + + /** + * 构造函数 + * + * @param nxXx + * {@link NxXx} + */ + public JedisGeoAddParam(final NxXx nxXx) { + super(); + nxXx(this, nxXx); + } + + /** + * 构造函数 + * + * @param ch + * - + */ + public JedisGeoAddParam(final boolean ch) { + super(); + ch(this, ch); + } + + /** + * 构造函数 + * + * @param nxXx + * {@link NxXx} + * @param ch + * - + */ + public JedisGeoAddParam(final NxXx nxXx, final boolean ch) { + super(); + nxXx(this, nxXx); + ch(this, ch); + } + + /** + * 从 {@link GeoAddArgument} 创建 {@link GeoAddParams} 实例 + * + * @param geoAddArgument + * {@link GeoAddArgument} + * + * @return {@link JedisGeoAddParam} 实例 + */ + public static JedisGeoAddParam from(final GeoAddArgument geoAddArgument) { + final JedisGeoAddParam geoAddParam = new JedisGeoAddParam(); + + nxXx(geoAddParam, geoAddArgument.getNxXx()); + ch(geoAddParam, geoAddArgument.isCh()); + + return geoAddParam; + } + + private static void nxXx(final JedisGeoAddParam geoAddParam, final NxXx nxXx) { + if(nxXx != null){ + switch(nxXx){ + case NX: + geoAddParam.nx(); + break; + case XX: + geoAddParam.xx(); + break; + default: + break; + } + } + } + + private static void ch(final JedisGeoAddParam geoRadiusParam, final Boolean ch) { + if(Boolean.TRUE.equals(ch)){ + geoRadiusParam.ch(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGeoCoordinate.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGeoCoordinate.java new file mode 100644 index 000000000..569541e9e --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGeoCoordinate.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.lang.Geo; +import redis.clients.jedis.GeoCoordinate; + +/** + * Jedis {@link GeoCoordinate} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisGeoCoordinate extends GeoCoordinate { + + /** + * 构造函数 + * + * @param longitude + * 精度 + * @param latitude + * 纬度 + */ + public JedisGeoCoordinate(final double longitude, final double latitude) { + super(longitude, latitude); + } + + /** + * 从 {@link Geo} 创建 {@link GeoCoordinate} 实例 + * + * @param geo + * {@link Geo} + * + * @return {@link JedisGeoCoordinate} 实例 + */ + public static JedisGeoCoordinate from(final Geo geo) { + return new JedisGeoCoordinate(geo.getLongitude(), geo.getLatitude()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGeoRadiusParam.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGeoRadiusParam.java new file mode 100644 index 000000000..b1b5b8def --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGeoRadiusParam.java @@ -0,0 +1,280 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.lang.Order; +import com.buession.redis.core.command.args.GeoRadiusArgument; +import redis.clients.jedis.params.GeoRadiusParam; + +/** + * Jedis {@link GeoRadiusParam} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisGeoRadiusParam extends GeoRadiusParam { + + /** + * 构造函数 + */ + public JedisGeoRadiusParam() { + super(); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + */ + public JedisGeoRadiusParam(final boolean withCoord, final boolean withDist, final boolean withHash) { + super(); + withCoord(this, withCoord); + withDist(this, withDist); + withHash(this, withHash); + } + + /** + * 构造函数 + * + * @param order + * 排序 + */ + public JedisGeoRadiusParam(final Order order) { + super(); + sort(this, order); + } + + /** + * 构造函数 + * + * @param count + * 返回数量 + */ + public JedisGeoRadiusParam(final int count) { + super(); + count(count); + } + + /** + * 构造函数 + * + * @param count + * 返回数量 + * @param any + * - + */ + public JedisGeoRadiusParam(final int count, final boolean any) { + super(); + count(count, any); + } + + /** + * 构造函数 + * + * @param order + * 排序 + * @param count + * 返回数量 + */ + public JedisGeoRadiusParam(final Order order, final int count) { + this(order); + count(count); + } + + /** + * 构造函数 + * + * @param order + * 排序 + * @param count + * 返回数量 + * @param any + * - + */ + public JedisGeoRadiusParam(final Order order, final int count, final boolean any) { + this(order); + count(count, any); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param order + * 排序 + */ + public JedisGeoRadiusParam(final boolean withCoord, final boolean withDist, final boolean withHash, + final Order order) { + this(withCoord, withDist, withHash); + sort(this, order); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param count + * 返回数量 + */ + public JedisGeoRadiusParam(final boolean withCoord, final boolean withDist, final boolean withHash, + final int count) { + this(withCoord, withDist, withHash); + count(count); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param count + * 返回数量 + * @param any + * - + */ + public JedisGeoRadiusParam(final boolean withCoord, final boolean withDist, final boolean withHash, + final int count, final boolean any) { + this(withCoord, withDist, withHash); + count(count, any); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param order + * 排序 + * @param count + * 返回数量 + */ + public JedisGeoRadiusParam(final boolean withCoord, final boolean withDist, final boolean withHash, + final Order order, final int count) { + this(withCoord, withDist, withHash, order); + count(count); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param order + * 排序 + * @param count + * 返回数量 + * 返回数量 + * @param any + * - + */ + public JedisGeoRadiusParam(final boolean withCoord, final boolean withDist, final boolean withHash, + final Order order, final int count, final boolean any) { + this(withCoord, withDist, withHash, order); + count(count, any); + } + + /** + * 从 {@link GeoRadiusArgument} 创建 {@link GeoRadiusParam} 实例 + * + * @param geoRadiusArgument + * {@link GeoRadiusArgument} + * + * @return {@link JedisGeoRadiusParam} 实例 + * + * @since 3.0.0 + */ + public static JedisGeoRadiusParam from(final GeoRadiusArgument geoRadiusArgument) { + final JedisGeoRadiusParam geoRadiusParam = new JedisGeoRadiusParam(); + + withCoord(geoRadiusParam, geoRadiusArgument.isWithCoord()); + withDist(geoRadiusParam, geoRadiusArgument.isWithDist()); + withHash(geoRadiusParam, geoRadiusArgument.isWithHash()); + sort(geoRadiusParam, geoRadiusArgument.getOrder()); + + if(geoRadiusArgument.getCount() != null){ + if(geoRadiusArgument.isAny() != null){ + geoRadiusParam.count(geoRadiusArgument.getCount(), geoRadiusArgument.isAny()); + }else{ + geoRadiusParam.count(geoRadiusArgument.getCount()); + } + } + + return geoRadiusParam; + } + + private static void withCoord(final JedisGeoRadiusParam geoRadiusParam, final Boolean withCoord) { + if(Boolean.TRUE.equals(withCoord)){ + geoRadiusParam.withCoord(); + } + } + + private static void withDist(final JedisGeoRadiusParam geoRadiusParam, final Boolean withDist) { + if(Boolean.TRUE.equals(withDist)){ + geoRadiusParam.withDist(); + } + } + + private static void withHash(final JedisGeoRadiusParam geoRadiusParam, final Boolean withHash) { + if(Boolean.TRUE.equals(withHash)){ + geoRadiusParam.withHash(); + } + } + + private static void sort(final JedisGeoRadiusParam geoRadiusParam, final Order order) { + if(order == Order.ASC){ + geoRadiusParam.sortAscending(); + }else if(order == Order.DESC){ + geoRadiusParam.sortDescending(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGeoSearchParam.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGeoSearchParam.java new file mode 100644 index 000000000..d7dd0077f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGeoSearchParam.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.lang.Geo; +import com.buession.redis.core.command.args.GeoSearchArgument; +import com.buession.redis.core.internal.convert.jedis.params.GeoUnitConverter; +import com.buession.redis.core.internal.convert.jedis.params.OrderConverter; +import redis.clients.jedis.params.GeoSearchParam; + +/** + * Redis {@link GeoSearchParam} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisGeoSearchParam extends GeoSearchParam { + + private final GeoUnitConverter geoUnitConverter = new GeoUnitConverter(); + + private final OrderConverter orderConverter = new OrderConverter(); + + /** + * 从 {@link GeoSearchArgument} 创建 {@link GeoSearchParam} 实例 + * + * @param geoSearchArgument + * {@link GeoSearchArgument} + * + * @return {@link JedisGeoSearchParam} 实例 + */ + public static JedisGeoSearchParam from(final GeoSearchArgument geoSearchArgument) { + final JedisGeoSearchParam geoSearchParam = new JedisGeoSearchParam(); + + if(geoSearchArgument.getFromMode() instanceof GeoSearchArgument.FromMember){ + geoSearchParam.fromMember(((GeoSearchArgument.FromMember) geoSearchArgument.getFromMode()).getMember()); + }else if(geoSearchArgument.getFromMode() instanceof GeoSearchArgument.FromLonLat){ + final Geo geo = ((GeoSearchArgument.FromLonLat) geoSearchArgument.getFromMode()).getGeo(); + geoSearchParam.fromLonLat(geo.getLongitude(), geo.getLatitude()); + } + + if(geoSearchArgument.getPredicate() instanceof GeoSearchArgument.RadiusPredicate){ + final GeoSearchArgument.RadiusPredicate radius = + (GeoSearchArgument.RadiusPredicate) geoSearchArgument.getPredicate(); + geoSearchParam.byRadius(radius.getRadius(), geoSearchParam.geoUnitConverter.convert(radius.getUnit())); + }else if(geoSearchArgument.getPredicate() instanceof GeoSearchArgument.BoxPredicate){ + final GeoSearchArgument.BoxPredicate box = + (GeoSearchArgument.BoxPredicate) geoSearchArgument.getPredicate(); + geoSearchParam.byBox(box.getWidth(), box.getHeight(), + geoSearchParam.geoUnitConverter.convert(box.getUnit())); + } + + if(geoSearchArgument.getOrder() != null){ + geoSearchParam.sortingOrder(geoSearchParam.orderConverter.convert(geoSearchArgument.getOrder())); + } + + if(geoSearchArgument.getCount() != null){ + if(geoSearchArgument.isAny() != null){ + geoSearchParam.count(geoSearchArgument.getCount(), geoSearchArgument.isAny()); + }else{ + geoSearchParam.count(geoSearchArgument.getCount()); + } + } + + if(Boolean.TRUE.equals(geoSearchArgument.getWithCoord())){ + geoSearchParam.withCoord(); + } + + if(Boolean.TRUE.equals(geoSearchArgument.isWithHash())){ + geoSearchParam.withDist(); + } + + if(Boolean.TRUE.equals(geoSearchArgument.isWithHash())){ + geoSearchParam.withHash(); + } + + return geoSearchParam; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGeoSearchStoreParam.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGeoSearchStoreParam.java new file mode 100644 index 000000000..c36ae6ddd --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGeoSearchStoreParam.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.lang.Geo; +import com.buession.redis.core.command.args.GeoSearchArgument; +import com.buession.redis.core.command.args.GeoSearchStoreArgument; +import com.buession.redis.core.internal.convert.jedis.params.GeoUnitConverter; +import com.buession.redis.core.internal.convert.jedis.params.OrderConverter; +import redis.clients.jedis.params.GeoSearchParam; + +/** + * Redis {@link GeoSearchParam} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisGeoSearchStoreParam extends GeoSearchParam { + + private final GeoUnitConverter geoUnitConverter = new GeoUnitConverter(); + + private final OrderConverter orderConverter = new OrderConverter(); + + /** + * 从 {@link GeoSearchStoreArgument} 创建 {@link GeoSearchParam} 实例 + * + * @param geoSearchStoreArgument + * {@link GeoSearchStoreArgument} + * + * @return {@link JedisGeoSearchStoreParam} 实例 + */ + public static JedisGeoSearchStoreParam from(final GeoSearchStoreArgument geoSearchStoreArgument) { + final JedisGeoSearchStoreParam geoSearchStoreParam = new JedisGeoSearchStoreParam(); + + if(geoSearchStoreArgument.getFromMode() instanceof GeoSearchStoreArgument.FromMember){ + geoSearchStoreParam.fromMember( + ((GeoSearchStoreArgument.FromMember) geoSearchStoreArgument.getFromMode()).getMember()); + }else if(geoSearchStoreArgument.getFromMode() instanceof GeoSearchStoreArgument.FromLonLat){ + final Geo geo = ((GeoSearchStoreArgument.FromLonLat) geoSearchStoreArgument.getFromMode()).getGeo(); + geoSearchStoreParam.fromLonLat(geo.getLongitude(), geo.getLatitude()); + } + + if(geoSearchStoreArgument.getPredicate() instanceof GeoSearchArgument.RadiusPredicate){ + final GeoSearchArgument.RadiusPredicate radius = + (GeoSearchArgument.RadiusPredicate) geoSearchStoreArgument.getPredicate(); + geoSearchStoreParam.byRadius(radius.getRadius(), + geoSearchStoreParam.geoUnitConverter.convert(radius.getUnit())); + }else if(geoSearchStoreArgument.getPredicate() instanceof GeoSearchArgument.BoxPredicate){ + final GeoSearchArgument.BoxPredicate box = + (GeoSearchArgument.BoxPredicate) geoSearchStoreArgument.getPredicate(); + geoSearchStoreParam.byBox(box.getWidth(), box.getHeight(), + geoSearchStoreParam.geoUnitConverter.convert(box.getUnit())); + } + + if(geoSearchStoreArgument.getOrder() != null){ + geoSearchStoreParam.sortingOrder( + geoSearchStoreParam.orderConverter.convert(geoSearchStoreArgument.getOrder())); + } + + if(geoSearchStoreArgument.getCount() != null){ + if(geoSearchStoreArgument.isAny() != null){ + geoSearchStoreParam.count(geoSearchStoreArgument.getCount(), geoSearchStoreArgument.isAny()); + }else{ + geoSearchStoreParam.count(geoSearchStoreArgument.getCount()); + } + } + + return geoSearchStoreParam; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGetExParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGetExParams.java new file mode 100644 index 000000000..40c288600 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisGetExParams.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.command.args.GetExArgument; +import redis.clients.jedis.params.GetExParams; + +/** + * Jedis {@link GetExParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisGetExParams extends GetExParams { + + /** + * 构造函数 + */ + public JedisGetExParams() { + super(); + } + + /** + * 构造函数 + * + * @param type + * 键过期设置方式 + * @param value + * 键过期时间 + */ + public JedisGetExParams(final GetExArgument.GetExType type, final Long value) { + super(); + + if(type != null && value != null){ + switch(type){ + case EX: + ex(value); + break; + case EXAT: + exAt(value); + break; + case PX: + px(value); + break; + case PXAT: + pxAt(value); + break; + case PERSIST: + persist(); + break; + default: + break; + } + } + } + + /** + * 构造函数 + * + * @param persist + * 设置键是否持久化 + */ + public JedisGetExParams(final Boolean persist) { + super(); + if(Boolean.TRUE.equals(persist)){ + persist(); + } + } + + /** + * 从 {@link GetExArgument} 创建 {@link GetExParams} 实例 + * + * @param getExArgument + * {@link GetExArgument} + * + * @return {@link JedisGetExParams} 实例 + */ + public static JedisGetExParams from(final GetExArgument getExArgument) { + return new JedisGetExParams(getExArgument.getType(), getExArgument.getExpires()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisLPosParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisLPosParams.java new file mode 100644 index 000000000..2e0c4b978 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisLPosParams.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.command.ListCommands; +import com.buession.redis.core.command.args.LPosArgument; +import redis.clients.jedis.params.LPosParams; + +import java.util.Optional; + +/** + * Jedis {@link LPosParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisLPosParams extends LPosParams { + + /** + * 构造函数 + */ + public JedisLPosParams() { + super(); + } + + /** + * 构造函数 + * + * @param rank + * 返回第几个匹配的元素 + */ + public JedisLPosParams(final int rank) { + super(); + rank(rank); + } + + /** + * 构造函数 + * + * @param rank + * 返回第几个匹配的元素 + * @param maxLen + * 查找成员个数 + */ + public JedisLPosParams(final int rank, final int maxLen) { + super(); + rank(rank); + maxlen(maxLen); + } + + /** + * 从 {@link LPosArgument} 创建 {@link LPosParams} 实例 + * + * @param lPosArgument + * {@link LPosArgument} + * + * @return {@link JedisLPosParams} 实例 + */ + public static JedisLPosParams from(final LPosArgument lPosArgument) { + final JedisLPosParams lPosParams = new JedisLPosParams(); + + Optional.ofNullable(lPosArgument.getRank()).ifPresent(lPosParams::rank); + Optional.ofNullable(lPosArgument.getMaxLen()).ifPresent(lPosParams::maxlen); + + return lPosParams; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisMigrateParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisMigrateParams.java new file mode 100644 index 000000000..092259e19 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisMigrateParams.java @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.core.validator.Validate; +import com.buession.redis.core.command.args.MigrateArgument; +import com.buession.redis.utils.SafeEncoder; +import redis.clients.jedis.params.MigrateParams; + +/** + * Jedis {@link MigrateParams} 扩展 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisMigrateParams extends MigrateParams { + + /** + * 构造函数 + */ + public JedisMigrateParams() { + super(); + } + + /** + * 构造函数 + * + * @param migrateOperation + * 迁移方式 + */ + public JedisMigrateParams(final MigrateArgument.Mode migrateOperation) { + super(); + mode(this, migrateOperation); + } + + /** + * 构造函数 + * + * @param password + * 密码 + */ + public JedisMigrateParams(final String password) { + super(); + auth(password); + } + + /** + * 构造函数 + * + * @param password + * 密码 + */ + public JedisMigrateParams(final byte[] password) { + this(SafeEncoder.encode(password)); + } + + /** + * 构造函数 + * + * @param username + * 用户名 + * @param password + * 密码 + */ + public JedisMigrateParams(final String username, final String password) { + super(); + auth2(username, password); + } + + /** + * 构造函数 + * + * @param username + * 用户名 + * @param password + * 密码 + */ + public JedisMigrateParams(final byte[] username, final byte[] password) { + this(SafeEncoder.encode(username), SafeEncoder.encode(password)); + } + + /** + * 构造函数 + * + * @param migrateOperation + * 迁移方式 + * @param password + * 密码 + */ + public JedisMigrateParams(final MigrateArgument.Mode migrateOperation, final String password) { + this(migrateOperation); + auth(password); + } + + /** + * 构造函数 + * + * @param migrateOperation + * 迁移方式 + * @param password + * 密码 + */ + public JedisMigrateParams(final MigrateArgument.Mode migrateOperation, final byte[] password) { + this(migrateOperation, SafeEncoder.encode(password)); + } + + /** + * 构造函数 + * + * @param migrateOperation + * 迁移方式 + * @param username + * 用户名 + * @param password + * 密码 + */ + public JedisMigrateParams(final MigrateArgument.Mode migrateOperation, final String username, + final String password) { + this(migrateOperation); + auth2(username, password); + } + + /** + * 构造函数 + * + * @param migrateOperation + * 迁移方式 + * @param username + * 用户名 + * @param password + * 密码 + */ + public JedisMigrateParams(final MigrateArgument.Mode migrateOperation, final byte[] username, + final byte[] password) { + this(migrateOperation, SafeEncoder.encode(username), SafeEncoder.encode(password)); + } + + /** + * 从 {@link MigrateArgument} 创建 {@link MigrateParams} 实例 + * + * @param migrateArgument + * {@link MigrateArgument} + * + * @return {@link JedisMigrateParams} 实例 + * + * @since 3.0.0 + */ + public static JedisMigrateParams from(final MigrateArgument migrateArgument) { + final JedisMigrateParams migrateParams = new JedisMigrateParams(); + + mode(migrateParams, migrateArgument.getMode()); + + if(Validate.hasText(migrateArgument.getPassword())){ + if(Validate.hasText(migrateArgument.getUsername())){ + migrateParams.auth2(migrateArgument.getUsername(), migrateArgument.getPassword()); + }else{ + migrateParams.auth(migrateArgument.getPassword()); + } + } + + return migrateParams; + } + + private static void mode(final MigrateParams migrateParams, final MigrateArgument.Mode migrateOperation) { + if(migrateOperation == MigrateArgument.Mode.COPY){ + migrateParams.copy(); + }else if(migrateOperation == MigrateArgument.Mode.REPLACE){ + migrateParams.replace(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisRestoreParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisRestoreParams.java new file mode 100644 index 000000000..462053664 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisRestoreParams.java @@ -0,0 +1,149 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.command.args.RestoreArgument; +import redis.clients.jedis.params.RestoreParams; + +import java.util.Optional; + +/** + * Jedis {@link RestoreParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisRestoreParams extends RestoreParams { + + /** + * 构造函数 + */ + public JedisRestoreParams() { + super(); + } + + /** + * 构造函数 + * + * @param replace + * 是否替换已存在 key + */ + public JedisRestoreParams(final boolean replace) { + super(); + replace(this, replace); + } + + /** + * 构造函数 + * + * @param replace + * 是否替换已存在 key + * @param absTtl + * - + */ + public JedisRestoreParams(final boolean replace, final boolean absTtl) { + this(replace); + absTtl(this, absTtl); + } + + /** + * 构造函数 + * + * @param replace + * 是否替换已存在 key + * @param idleTime + * - + * @param frequency + * - + */ + public JedisRestoreParams(final boolean replace, final long idleTime, final long frequency) { + this(replace); + idleTime(idleTime); + frequency(frequency); + } + + /** + * 构造函数 + * + * @param replace + * 是否替换已存在 key + * @param absTtl + * - + * @param idleTime + * - + * @param frequency + * - + */ + public JedisRestoreParams(final boolean replace, final boolean absTtl, final long idleTime, final long frequency) { + this(replace, idleTime, frequency); + absTtl(this, absTtl); + } + + /** + * 构造函数 + * + * @param idleTime + * - + * @param frequency + * - + */ + public JedisRestoreParams(final long idleTime, final long frequency) { + super(); + idleTime(idleTime); + frequency(frequency); + } + + /** + * 从 {@link RestoreArgument} 创建 {@link RestoreParams} 实例 + * + * @param restoreArgument + * {@link RestoreArgument} + * + * @return {@link JedisRestoreParams} 实例 + */ + public static JedisRestoreParams from(final RestoreArgument restoreArgument) { + final JedisRestoreParams restoreParams = new JedisRestoreParams(); + + replace(restoreParams, restoreArgument.isReplace()); + absTtl(restoreParams, restoreArgument.isAbsTtl()); + Optional.ofNullable(restoreArgument.getIdleTime()).ifPresent(restoreParams::idleTime); + Optional.ofNullable(restoreArgument.getFrequency()).ifPresent(restoreParams::frequency); + + return restoreParams; + } + + private static void replace(final JedisRestoreParams restoreParams, final Boolean replace) { + if(Boolean.TRUE.equals(replace)){ + restoreParams.replace(); + } + } + + private static void absTtl(final JedisRestoreParams restoreParams, final Boolean absTtl) { + if(Boolean.TRUE.equals(absTtl)){ + restoreParams.absTtl(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisResult.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisResult.java new file mode 100644 index 000000000..5a11bc56f --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisResult.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.FutureResult; +import com.buession.redis.core.internal.convert.Converters; +import redis.clients.jedis.Response; + +/** + * Jedis 事务、管道异步结果 + * + * @author Yong.Teng + */ +public class JedisResult extends FutureResult> { + + public JedisResult(final Response resultHolder) { + super(resultHolder); + } + + public JedisResult(final Response resultHolder, final Converter converter) { + super(resultHolder, converter); + } + + @Override + public SV get() { + return getHolder().get(); + } + + public final static class Builder { + + private final Response response; + + private Converter converter; + + private Builder(final Response response, final Converter converter) { + this.response = response; + this.converter = converter; + } + + public static Builder fromResponse(Response response) { + return new Builder<>(response, Converters.always()); + } + + public Builder mappedWith(Converter converter) { + this.converter = converter; + return this; + } + + public JedisResult build() { + return new JedisResult<>(response, converter); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisScanParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisScanParams.java new file mode 100644 index 000000000..ae4ac5a1b --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisScanParams.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.command.args.HScanArgument; +import redis.clients.jedis.params.ScanParams; + +import java.util.Optional; + +/** + * Jedis {@link ScanParams} 扩展 + * + * @author Yong.Teng + */ +public final class JedisScanParams extends ScanParams { + + /** + * 构造函数 + */ + public JedisScanParams() { + super(); + } + + /** + * 构造函数 + * + * @param pattern + * 匹配模式 + */ + public JedisScanParams(final String pattern) { + super(); + match(pattern); + } + + /** + * 构造函数 + * + * @param pattern + * 匹配模式 + */ + public JedisScanParams(final byte[] pattern) { + super(); + match(pattern); + } + + /** + * 构造函数 + * + * @param count + * 返回数量 + */ + public JedisScanParams(final int count) { + super(); + count(count); + } + + /** + * 构造函数 + * + * @param pattern + * 匹配模式 + * @param count + * 返回数量 + */ + public JedisScanParams(final String pattern, final int count) { + this(pattern); + count(count); + } + + /** + * 构造函数 + * + * @param pattern + * 匹配模式 + * @param count + * 返回数量 + */ + public JedisScanParams(final byte[] pattern, final int count) { + this(pattern); + count(count); + } + + /** + * 从 {@link HScanArgument} 创建 {@link ScanParams} 实例 + * + * @param scanArgument + * {@link HScanArgument} + * + * @return {@link JedisScanParams} 实例 + */ + public static JedisScanParams from(final HScanArgument scanArgument) { + final JedisScanParams scanParams = new JedisScanParams(); + + if(scanArgument.getPattern() instanceof String){ + scanParams.match((String) scanArgument.getPattern()); + }else if(scanArgument.getPattern() instanceof byte[]){ + scanParams.match((byte[]) scanArgument.getPattern()); + } + Optional.ofNullable(scanArgument.getCount()).ifPresent(scanParams::count); + + return scanParams; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisSetParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisSetParams.java new file mode 100644 index 000000000..ebd2eeeb3 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisSetParams.java @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.NxXx; +import com.buession.redis.core.command.args.SetArgument; +import redis.clients.jedis.params.SetParams; + +/** + * Jedis {@link SetParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisSetParams extends SetParams { + + /** + * 构造函数 + */ + public JedisSetParams() { + super(); + } + + /** + * 构造函数 + * + * @param type + * 过期时间方式 + * @param expires + * 过期时间 + */ + public JedisSetParams(final SetArgument.SetType type, final long expires) { + expx(this, type, expires); + } + + /** + * 构造函数 + * + * @param type + * 过期时间方式 + * @param expires + * 过期时间 + * @param nxXx + * 只有键 key 不存在/存在的时候才会设置 key 的值 + */ + public JedisSetParams(final SetArgument.SetType type, final long expires, final NxXx nxXx) { + this(type, expires); + nxxx(this, nxXx); + } + + /** + * 构造函数 + * + * @param nxXx + * 只有键 key 不存在/存在的时候才会设置 key 的值 + */ + public JedisSetParams(final NxXx nxXx) { + super(); + nxxx(this, nxXx); + } + + /** + * 构造函数 + * + * @param keepTtl + * 是否获取 key 的过期时间 + */ + public JedisSetParams(final boolean keepTtl) { + super(); + keepTtl(this, keepTtl); + } + + /** + * 构造函数 + * + * @param nxXx + * 只有键 key 不存在/存在的时候才会设置 key 的值 + * @param keepTtl + * 是否获取 key 的过期时间 + */ + public JedisSetParams(final NxXx nxXx, final boolean keepTtl) { + super(); + nxxx(this, nxXx); + keepTtl(this, keepTtl); + } + + /** + * 构造函数 + * + * @param type + * 过期时间方式 + * @param expires + * 过期时间 + * @param nxXx + * 只有键 key 不存在/存在的时候才会设置 key 的值 + * @param keepTtl + * 是否获取 key 的过期时间 + */ + public JedisSetParams(final SetArgument.SetType type, final long expires, final NxXx nxXx, final boolean keepTtl) { + this(type, expires, nxXx); + keepTtl(this, keepTtl); + } + + /** + * 从 {@link SetArgument} 创建 {@link SetParams} 实例 + * + * @param setArgument + * {@link SetArgument} + * + * @return {@link JedisSetParams} 实例 + */ + public static JedisSetParams from(final SetArgument setArgument) { + final JedisSetParams setParams = new JedisSetParams(); + + expx(setParams, setArgument.getType(), setArgument.getExpires()); + nxxx(setParams, setArgument.getNxXx()); + keepTtl(setParams, setArgument.isKeepTtl()); + + return setParams; + } + + private static void expx(final JedisSetParams setParams, final SetArgument.SetType type, final Long expires) { + if(type != null && expires != null){ + switch(type){ + case EX: + setParams.ex(expires); + break; + case EXAT: + setParams.exAt(expires); + break; + case PX: + setParams.px(expires); + break; + case PXAT: + setParams.pxAt(expires); + break; + default: + break; + } + } + } + + private static void nxxx(final JedisSetParams setParams, final NxXx nx) { + if(nx == NxXx.NX){ + setParams.nx(); + }else if(nx == NxXx.XX){ + setParams.xx(); + } + } + + private static void keepTtl(final JedisSetParams setParams, final Boolean keepTtl) { + if(Boolean.TRUE.equals(keepTtl)){ + setParams.keepttl(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisSortingParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisSortingParams.java new file mode 100644 index 000000000..0b9f2bd81 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisSortingParams.java @@ -0,0 +1,299 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.lang.Order; +import com.buession.redis.core.Limit; +import com.buession.redis.core.command.args.SortArgument; +import redis.clients.jedis.params.SortingParams; + +import java.util.Optional; + +/** + * Jedis {@link SortingParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisSortingParams extends SortingParams { + + /** + * 构造函数 + */ + public JedisSortingParams() { + super(); + } + + /** + * 构造函数 + * + * @param by + * - + */ + public JedisSortingParams(final String by) { + super(); + by(by); + } + + /** + * 构造函数 + * + * @param by + * - + */ + public JedisSortingParams(final byte[] by) { + super(); + by(by); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + */ + public JedisSortingParams(final String by, final String[] gets) { + super(); + by(by); + get(gets); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + */ + public JedisSortingParams(final byte[] by, final byte[][] gets) { + super(); + by(by); + get(gets); + } + + /** + * 构造函数 + * + * @param by + * - + * @param order + * 排序方式 + */ + public JedisSortingParams(final String by, final Order order) { + this(by); + order(this, order); + } + + /** + * 构造函数 + * + * @param by + * - + * @param order + * 排序方式 + */ + public JedisSortingParams(final byte[] by, final Order order) { + this(by); + order(this, order); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + */ + public JedisSortingParams(final String by, final String[] gets, final Order order) { + this(by, gets); + order(this, order); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + */ + public JedisSortingParams(final byte[] by, final byte[][] gets, final Order order) { + this(by, gets); + order(this, order); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param limit + * 结果限制 + */ + public JedisSortingParams(final String by, final String[] gets, final Limit limit) { + this(by, gets); + limit(this, limit); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param limit + * 结果限制 + */ + public JedisSortingParams(final byte[] by, final byte[][] gets, final Limit limit) { + this(by, gets); + limit(this, limit); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + * @param limit + * 结果限制 + */ + public JedisSortingParams(final String by, final String[] gets, final Order order, final Limit limit) { + this(by, gets, order); + limit(this, limit); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + * @param limit + * 结果限制 + */ + public JedisSortingParams(final byte[] by, final byte[][] gets, final Order order, final Limit limit) { + this(by, gets, order); + limit(this, limit); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + * @param limit + * 结果限制 + * @param alpha + * - + */ + public JedisSortingParams(final String by, final String[] gets, final Order order, final Limit limit, + final boolean alpha) { + this(by, gets, order, limit); + alpha(this, alpha); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + * @param limit + * 结果限制 + * @param alpha + * - + */ + public JedisSortingParams(final byte[] by, final byte[][] gets, final Order order, final Limit limit, + final boolean alpha) { + this(by, gets, order, limit); + alpha(this, alpha); + } + + /** + * 从 {@link SortArgument} 创建 {@link SortingParams} 实例 + * + * @param sortArgument + * {@link SortArgument} + * + * @return {@link JedisSortingParams} 实例 + */ + public static JedisSortingParams from(final SortArgument sortArgument) { + final JedisSortingParams sortingParams = new JedisSortingParams(); + + Optional.ofNullable(sortArgument.getBy()).ifPresent(sortingParams::by); + Optional.ofNullable(sortArgument.getGetPatterns()).ifPresent(sortingParams::get); + order(sortingParams, sortArgument.getOrder()); + limit(sortingParams, sortArgument.getLimit()); + alpha(sortingParams, sortArgument.isAlpha()); + + return sortingParams; + } + + private static void alpha(final JedisSortingParams sortingParams, final Boolean alpha) { + if(Boolean.TRUE.equals(alpha)){ + sortingParams.alpha(); + } + } + + private static void limit(final JedisSortingParams sortingParams, final Limit limit) { + if(limit != null){ + sortingParams.limit((int) limit.getOffset(), (int) limit.getCount()); + } + } + + private static void order(final JedisSortingParams sortingParams, final Order order) { + if(order == Order.ASC){ + sortingParams.asc(); + }else if(order == Order.DESC){ + sortingParams.desc(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisStreamEntryID.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisStreamEntryID.java new file mode 100644 index 000000000..e5f8a8e11 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisStreamEntryID.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.StreamEntryId; +import redis.clients.jedis.StreamEntryID; + +import java.util.Objects; + +/** + * Jedis {@link StreamEntryID} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class JedisStreamEntryID extends StreamEntryID { + + /** + * 构造函数 + */ + public JedisStreamEntryID() { + super(); + } + + /** + * 构造函数 + * + * @param id + * Stream Entry ID + */ + public JedisStreamEntryID(final String id) { + super(id); + } + + /** + * 构造函数 + * + * @param id + * Stream Entry ID + */ + public JedisStreamEntryID(final byte[] id) { + super(id); + } + + /** + * 构造函数 + * + * @param time + * Stream Entry ID 生成时间戳 + */ + public JedisStreamEntryID(final long time) { + super(time); + } + + /** + * 构造函数 + * + * @param time + * Stream Entry ID 生成时间戳 + * @param sequence + * 序号 + */ + public JedisStreamEntryID(final long time, final long sequence) { + super(time, sequence); + } + + /** + * 从 {@link StreamEntryId} 创建 {@link StreamEntryID} 实例 + * + * @param streamEntryId + * {@link StreamEntryId} + * + * @return {@link JedisStreamEntryID} 实例 + */ + public static JedisStreamEntryID from(final StreamEntryId streamEntryId) { + final String str = streamEntryId.toString(); + + if(Objects.equals(str, NEW_ENTRY.toString()) + || Objects.equals(str, UNRECEIVED_ENTRY.toString()) + || Objects.equals(str, LAST_ENTRY.toString()) + || Objects.equals(str, MINIMUM_ID.toString()) + || Objects.equals(str, MAXIMUM_ID.toString())){ + return new JedisStreamEntryID() { + + @Override + public String toString() { + return str; + } + + }; + }else{ + return new JedisStreamEntryID(streamEntryId.getTime(), streamEntryId.getSequence()); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXAddParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXAddParams.java new file mode 100644 index 000000000..97c01f815 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXAddParams.java @@ -0,0 +1,788 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.command.args.ApproximateExactTrimming; +import com.buession.redis.core.command.args.MaxLenMinId; +import com.buession.redis.core.command.args.XAddArgument; +import redis.clients.jedis.StreamEntryID; +import redis.clients.jedis.params.XAddParams; + +import java.util.Optional; + +/** + * Jedis {@link XAddParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisXAddParams extends XAddParams { + + /** + * 构造函数 + */ + public JedisXAddParams() { + super(); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + */ + public JedisXAddParams(final String id) { + super(); + id(id); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + */ + public JedisXAddParams(final byte[] id) { + super(); + id(id); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + */ + public JedisXAddParams(final StreamEntryID id) { + super(); + id(id); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + */ + public JedisXAddParams(final StreamEntryId id) { + this(JedisStreamEntryID.from(id)); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + */ + public JedisXAddParams(final String id, final MaxLenMinId maxLenMinId) { + this(id); + maxLenMinId(this, maxLenMinId); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + */ + public JedisXAddParams(final byte[] id, final MaxLenMinId maxLenMinId) { + this(id); + maxLenMinId(this, maxLenMinId); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + */ + public JedisXAddParams(final StreamEntryID id, final MaxLenMinId maxLenMinId) { + this(id); + maxLenMinId(this, maxLenMinId); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + */ + public JedisXAddParams(final StreamEntryId id, final MaxLenMinId maxLenMinId) { + this(id); + maxLenMinId(this, maxLenMinId); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param noMkStream + * - + */ + public JedisXAddParams(final String id, final boolean noMkStream) { + this(id); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param noMkStream + * - + */ + public JedisXAddParams(final byte[] id, final boolean noMkStream) { + this(id); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param noMkStream + * - + */ + public JedisXAddParams(final StreamEntryID id, final boolean noMkStream) { + this(id); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param noMkStream + * - + */ + public JedisXAddParams(final StreamEntryId id, final boolean noMkStream) { + this(id); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param limit + * - + */ + public JedisXAddParams(final String id, final long limit) { + this(id); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param limit + * - + */ + public JedisXAddParams(final byte[] id, final long limit) { + this(id); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param limit + * - + */ + public JedisXAddParams(final StreamEntryID id, final long limit) { + this(id); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param limit + * - + */ + public JedisXAddParams(final StreamEntryId id, final long limit) { + this(id); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param noMkStream + * - + */ + public JedisXAddParams(final String id, final MaxLenMinId maxLenMinId, final boolean noMkStream) { + this(id, maxLenMinId); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param noMkStream + * - + */ + public JedisXAddParams(final byte[] id, final MaxLenMinId maxLenMinId, final boolean noMkStream) { + this(id, maxLenMinId); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param noMkStream + * - + */ + public JedisXAddParams(final StreamEntryID id, final MaxLenMinId maxLenMinId, final boolean noMkStream) { + this(id, maxLenMinId); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param noMkStream + * - + */ + public JedisXAddParams(final StreamEntryId id, final MaxLenMinId maxLenMinId, final boolean noMkStream) { + this(id, maxLenMinId); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param limit + * - + */ + public JedisXAddParams(final String id, final MaxLenMinId maxLenMinId, final long limit) { + this(id, maxLenMinId); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param limit + * - + */ + public JedisXAddParams(final byte[] id, final MaxLenMinId maxLenMinId, final long limit) { + this(id, maxLenMinId); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param limit + * - + */ + public JedisXAddParams(final StreamEntryID id, final MaxLenMinId maxLenMinId, final long limit) { + this(id, maxLenMinId); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param limit + * - + */ + public JedisXAddParams(final StreamEntryId id, final MaxLenMinId maxLenMinId, final long limit) { + this(id, maxLenMinId); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param noMkStream + * - + * @param limit + * - + */ + public JedisXAddParams(final String id, final MaxLenMinId maxLenMinId, final boolean noMkStream, + final long limit) { + this(id, maxLenMinId, noMkStream); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param noMkStream + * - + * @param limit + * - + */ + public JedisXAddParams(final byte[] id, final MaxLenMinId maxLenMinId, final boolean noMkStream, + final long limit) { + this(id, maxLenMinId, noMkStream); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param noMkStream + * - + * @param limit + * - + */ + public JedisXAddParams(final StreamEntryID id, final MaxLenMinId maxLenMinId, final boolean noMkStream, + final long limit) { + this(id, maxLenMinId, noMkStream); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param noMkStream + * - + * @param limit + * - + */ + public JedisXAddParams(final StreamEntryId id, final MaxLenMinId maxLenMinId, final boolean noMkStream, + final long limit) { + this(id, maxLenMinId, noMkStream); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + */ + public JedisXAddParams(final String id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming) { + this(id); + maxLenMinId(this, maxLenMinId, approximateExactTrimming); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + */ + public JedisXAddParams(final byte[] id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming) { + this(id); + maxLenMinId(this, maxLenMinId, approximateExactTrimming); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + */ + public JedisXAddParams(final StreamEntryID id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming) { + this(id); + maxLenMinId(this, maxLenMinId, approximateExactTrimming); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + */ + public JedisXAddParams(final StreamEntryId id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming) { + this(id); + maxLenMinId(this, maxLenMinId, approximateExactTrimming); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + */ + public JedisXAddParams(final String id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final boolean noMkStream) { + this(id, maxLenMinId, approximateExactTrimming); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + */ + public JedisXAddParams(final byte[] id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final boolean noMkStream) { + this(id, maxLenMinId, approximateExactTrimming); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + */ + public JedisXAddParams(final StreamEntryID id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final boolean noMkStream) { + this(id, maxLenMinId, approximateExactTrimming); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + */ + public JedisXAddParams(final StreamEntryId id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final boolean noMkStream) { + this(id, maxLenMinId, approximateExactTrimming); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param limit + * - + */ + public JedisXAddParams(final String id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final long limit) { + this(id, maxLenMinId, approximateExactTrimming); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param limit + * - + */ + public JedisXAddParams(final byte[] id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final long limit) { + this(id, maxLenMinId, approximateExactTrimming); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param limit + * - + */ + public JedisXAddParams(final StreamEntryID id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final long limit) { + this(id, maxLenMinId, approximateExactTrimming); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param limit + * - + */ + public JedisXAddParams(final StreamEntryId id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final long limit) { + this(id, maxLenMinId, approximateExactTrimming); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + * @param limit + * - + */ + public JedisXAddParams(final String id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final boolean noMkStream, + final long limit) { + this(id, maxLenMinId, approximateExactTrimming, noMkStream); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + * @param limit + * - + */ + public JedisXAddParams(final byte[] id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final boolean noMkStream, + final long limit) { + this(id, maxLenMinId, approximateExactTrimming, noMkStream); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + * @param limit + * - + */ + public JedisXAddParams(final StreamEntryID id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final boolean noMkStream, + final long limit) { + this(id, maxLenMinId, approximateExactTrimming, noMkStream); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + * @param limit + * - + */ + public JedisXAddParams(final StreamEntryId id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final boolean noMkStream, + final long limit) { + this(id, maxLenMinId, approximateExactTrimming, noMkStream); + Optional.ofNullable(limit).ifPresent(this::limit); + } + + public JedisXAddParams id(final StreamEntryId id) { + if(id != null){ + id(JedisStreamEntryID.from(id)); + } + + return this; + } + + /** + * 从 {@link XAddArgument} 创建 {@link XAddParams} 实例 + * + * @param xAddArgument + * {@link XAddArgument} + * + * @return {@link JedisXAddParams} 实例 + */ + public static JedisXAddParams from(final XAddArgument xAddArgument) { + final JedisXAddParams xAddParams = new JedisXAddParams(); + + maxLenMinId(xAddParams, xAddArgument.getMaxLenMinId(), xAddArgument.getApproximateExactTrimming()); + noMkStream(xAddParams, xAddArgument.isNoMkStream()); + Optional.ofNullable(xAddArgument.getLimit()).ifPresent(xAddParams::limit); + + return xAddParams; + } + + private static void maxLenMinId(final JedisXAddParams xAddParams, final MaxLenMinId maxLenMinId) { + if(maxLenMinId != null){ + if(maxLenMinId instanceof MaxLenMinId.MaxLen){ + xAddParams.maxLen(((MaxLenMinId.MaxLen) maxLenMinId).getValue()); + }else if(maxLenMinId instanceof MaxLenMinId.MinId){ + xAddParams.minId(((MaxLenMinId.MinId) maxLenMinId).getValue().toString()); + } + } + } + + private static void maxLenMinId(final JedisXAddParams xAddParams, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming) { + maxLenMinId(xAddParams, maxLenMinId); + if(maxLenMinId != null){ + if(approximateExactTrimming == ApproximateExactTrimming.APPROXIMATE){ + xAddParams.approximateTrimming(); + }else if(approximateExactTrimming == ApproximateExactTrimming.EXACT){ + xAddParams.exactTrimming(); + } + } + } + + private static void noMkStream(final JedisXAddParams xAddParams, final Boolean noMkStream) { + if(Boolean.TRUE.equals(noMkStream)){ + xAddParams.noMkStream(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXAutoClaimParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXAutoClaimParams.java new file mode 100644 index 000000000..b9f66aff4 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXAutoClaimParams.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import redis.clients.jedis.params.XAutoClaimParams; + +/** + * Jedis {@link XAutoClaimParams} 扩展 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisXAutoClaimParams extends XAutoClaimParams { + + /** + * 构造函数 + */ + public JedisXAutoClaimParams() { + super(); + } + + /** + * 构造函数 + * + * @param count + * 返回数量 + */ + public JedisXAutoClaimParams(final int count) { + super(); + count(count); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXClaimParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXClaimParams.java new file mode 100644 index 000000000..2bafb8004 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXClaimParams.java @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.command.args.XClaimArgument; +import redis.clients.jedis.params.XClaimParams; + +import java.util.Optional; + +/** + * Jedis {@link XClaimParams} 扩展类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class JedisXClaimParams extends XClaimParams { + + /** + * 构造函数 + */ + public JedisXClaimParams() { + super(); + } + + /** + * 构造函数 + * + * @param idleType + * 设置过期时间方式 + * @param expires + * 过期时间 + */ + public JedisXClaimParams(final XClaimArgument.IdleType idleType, final long expires) { + super(); + idleTime(this, idleType, expires); + } + + /** + * 构造函数 + * + * @param retryCount + * 重试次数 + */ + public JedisXClaimParams(final int retryCount) { + super(); + retryCount(retryCount); + } + + /** + * 构造函数 + * + * @param force + * 是否强制 + */ + public JedisXClaimParams(final boolean force) { + super(); + force(this, force); + } + + /** + * 构造函数 + * + * @param idleType + * 设置过期时间方式 + * @param expires + * 过期时间 + * @param retryCount + * 重试次数 + */ + public JedisXClaimParams(final XClaimArgument.IdleType idleType, final long expires, final int retryCount) { + this(idleType, expires); + retryCount(retryCount); + } + + /** + * 构造函数 + * + * @param idleType + * 设置过期时间方式 + * @param expires + * 过期时间 + * @param force + * 是否强制 + */ + public JedisXClaimParams(final XClaimArgument.IdleType idleType, final long expires, final boolean force) { + this(idleType, expires); + force(this, force); + } + + /** + * 构造函数 + * + * @param idleType + * 设置过期时间方式 + * @param expires + * 过期时间 + * @param retryCount + * 重试次数 + * @param force + * 是否强制 + */ + public JedisXClaimParams(final XClaimArgument.IdleType idleType, final long expires, final int retryCount, + final boolean force) { + this(idleType, expires, retryCount); + force(this, force); + } + + /** + * 从 {@link XClaimArgument} 创建 {@link XClaimParams} 实例 + * + * @param xClaimArgument + * {@link XClaimArgument} + * + * @return {@link JedisXClaimParams} 实例 + */ + public static JedisXClaimParams from(final XClaimArgument xClaimArgument) { + final JedisXClaimParams xClaimParams = new JedisXClaimParams(); + + idleTime(xClaimParams, xClaimArgument.getIdleType(), xClaimArgument.getIdleTime()); + Optional.ofNullable(xClaimArgument.getRetryCount()).ifPresent(xClaimParams::retryCount); + force(xClaimParams, xClaimArgument.isForce()); + + return xClaimParams; + } + + private static void idleTime(final XClaimParams xClaimParams, final XClaimArgument.IdleType idleType, + final Long idleTime) { + if(idleType != null && idleTime != null){ + switch(idleType){ + case IDLE: + xClaimParams.idle(idleTime); + break; + case UNIX_TIME: + xClaimParams.time(idleTime); + break; + default: + break; + } + } + } + + private static void force(final XClaimParams xClaimParams, final Boolean force) { + if(Boolean.TRUE.equals(force)){ + xClaimParams.force(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXPendingParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXPendingParams.java new file mode 100644 index 000000000..dc0c240e9 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXPendingParams.java @@ -0,0 +1,448 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.StreamEntryId; +import redis.clients.jedis.StreamEntryID; +import redis.clients.jedis.params.XPendingParams; + +/** + * Jedis {@link XPendingParams} 扩展 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisXPendingParams extends XPendingParams { + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + */ + public JedisXPendingParams(final String start, final String end, final int count) { + this(new StreamEntryID(start), new StreamEntryID(end), count); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + */ + public JedisXPendingParams(final byte[] start, final byte[] end, final int count) { + super(new StreamEntryID(start), new StreamEntryID(end), count); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + */ + public JedisXPendingParams(final StreamEntryId start, final StreamEntryId end, final int count) { + super(JedisStreamEntryID.from(start), JedisStreamEntryID.from(end), count); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + */ + public JedisXPendingParams(final StreamEntryID start, final StreamEntryID end, final int count) { + super(start, end, count); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + */ + public JedisXPendingParams(final String start, final String end, final int count, final long idle) { + this(start, end, count); + idle(idle); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + */ + public JedisXPendingParams(final byte[] start, final byte[] end, final int count, final long idle) { + this(start, end, count); + idle(idle); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + */ + public JedisXPendingParams(final StreamEntryId start, final StreamEntryId end, final int count, final long idle) { + this(start, end, count); + idle(idle); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + */ + public JedisXPendingParams(final StreamEntryID start, final StreamEntryID end, final int count, final long idle) { + super(start, end, count); + idle(idle); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param consumer + * - + */ + public JedisXPendingParams(final String start, final String end, final int count, final String consumer) { + this(start, end, count); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param consumer + * - + */ + public JedisXPendingParams(final byte[] start, final byte[] end, final int count, final byte[] consumer) { + this(start, end, count); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param consumer + * - + */ + public JedisXPendingParams(final StreamEntryId start, final StreamEntryId end, final int count, + final String consumer) { + this(start, end, count); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param consumer + * - + */ + public JedisXPendingParams(final StreamEntryId start, final StreamEntryId end, final int count, + final byte[] consumer) { + this(start, end, count); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param consumer + * - + */ + public JedisXPendingParams(final StreamEntryID start, final StreamEntryID end, final int count, + final String consumer) { + super(start, end, count); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param consumer + * - + */ + public JedisXPendingParams(final StreamEntryID start, final StreamEntryID end, final int count, + final byte[] consumer) { + super(start, end, count); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + * @param consumer + * - + */ + public JedisXPendingParams(final String start, final String end, final int count, final long idle, + final String consumer) { + this(start, end, count, idle); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + * @param consumer + * - + */ + public JedisXPendingParams(final byte[] start, final byte[] end, final int count, final long idle, + final byte[] consumer) { + this(start, end, count, idle); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + * @param consumer + * - + */ + public JedisXPendingParams(final StreamEntryId start, final StreamEntryId end, final int count, final long idle, + final String consumer) { + this(start, end, count, idle); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + * @param consumer + * - + */ + public JedisXPendingParams(final StreamEntryId start, final StreamEntryId end, final int count, final long idle, + final byte[] consumer) { + this(start, end, count, idle); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + * @param consumer + * - + */ + public JedisXPendingParams(final StreamEntryID start, final StreamEntryID end, final int count, final long idle, + final String consumer) { + this(start, end, count, idle); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + * @param consumer + * - + */ + public JedisXPendingParams(final StreamEntryID start, final StreamEntryID end, final int count, final long idle, + final byte[] consumer) { + this(start, end, count, idle); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param idle + * - + */ + public JedisXPendingParams(final long idle) { + super(); + idle(idle); + } + + /** + * 构造函数 + * + * @param consumer + * - + */ + public JedisXPendingParams(final String consumer) { + super(); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param consumer + * - + */ + public JedisXPendingParams(final byte[] consumer) { + super(); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param idle + * - + * @param consumer + * - + */ + public JedisXPendingParams(final long idle, final String consumer) { + idle(idle); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param idle + * - + * @param consumer + * - + */ + public JedisXPendingParams(final long idle, final byte[] consumer) { + idle(idle); + consumer(consumer); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXReadGroupParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXReadGroupParams.java new file mode 100644 index 000000000..8f7c7a180 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXReadGroupParams.java @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.command.args.XReadGroupArgument; +import redis.clients.jedis.params.XReadGroupParams; + +import java.util.Optional; + +/** + * Jedis {@link XReadGroupParams} 扩展 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisXReadGroupParams extends XReadGroupParams { + + /** + * 构造函数 + */ + public JedisXReadGroupParams() { + super(); + } + + /** + * 构造函数 + * + * @param count + * 返回条数 + */ + public JedisXReadGroupParams(final int count) { + super(); + count(count); + } + + /** + * 构造函数 + * + * @param count + * 返回条数 + * @param block + * - + */ + public JedisXReadGroupParams(final int count, final int block) { + this(count); + block(block); + } + + /** + * 构造函数 + * + * @param noAck + * - + */ + public JedisXReadGroupParams(final boolean noAck) { + super(); + noAck(this, noAck); + } + + /** + * 构造函数 + * + * @param noAck + * - + * @param count + * 返回条数 + */ + public JedisXReadGroupParams(final boolean noAck, final int count) { + this(noAck); + count(count); + } + + /** + * 构造函数 + * + * @param noAck + * - + * @param count + * 返回数量 + * @param block + * 阻塞时间 + */ + public JedisXReadGroupParams(final boolean noAck, final int count, final int block) { + this(noAck, count); + block(block); + } + + public JedisXReadGroupParams noAck(final boolean noAck) { + noAck(this, noAck); + return this; + } + + /** + * 从 {@link XReadGroupArgument} 创建 {@link XReadGroupParams} 实例 + * + * @param xReadArgument + * {@link XReadGroupArgument} + * + * @return {@link JedisXReadGroupParams} 实例 + */ + public static JedisXReadGroupParams from(final XReadGroupArgument xReadArgument) { + final JedisXReadGroupParams xReadGroupParams = new JedisXReadGroupParams(); + + Optional.ofNullable(xReadArgument.getCount()).ifPresent(xReadGroupParams::count); + Optional.ofNullable(xReadArgument.getBlock()).ifPresent(xReadGroupParams::block); + noAck(xReadGroupParams, xReadArgument.isNoAck()); + + return xReadGroupParams; + } + + private static void noAck(final JedisXReadGroupParams xReadGroupParams, final Boolean noAck) { + if(Boolean.TRUE.equals(noAck)){ + xReadGroupParams.noAck(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXReadParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXReadParams.java new file mode 100644 index 000000000..c41e7204c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXReadParams.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.command.args.XReadArgument; +import redis.clients.jedis.params.XReadParams; + +import java.util.Optional; + +/** + * Jedis {@link XReadParams} 扩展 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisXReadParams extends XReadParams { + + /** + * 构造函数 + */ + public JedisXReadParams() { + super(); + } + + /** + * 构造函数 + * + * @param count + * 返回条数 + */ + public JedisXReadParams(final int count) { + super(); + count(count); + } + + /** + * 构造函数 + * + * @param count + * 返回条数 + * @param block + * - + */ + public JedisXReadParams(final int count, final int block) { + this(count); + block(block); + } + + /** + * 从 {@link XReadArgument} 创建 {@link XReadParams} 实例 + * + * @param xReadArgument + * {@link XReadArgument} + * + * @return {@link JedisXReadParams} 实例 + */ + public static JedisXReadParams from(final XReadArgument xReadArgument) { + final JedisXReadParams xReadParams = new JedisXReadParams(); + + Optional.ofNullable(xReadArgument.getCount()).ifPresent(xReadParams::count); + Optional.ofNullable(xReadArgument.getBlock()).ifPresent(xReadParams::block); + + return xReadParams; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXTrimParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXTrimParams.java new file mode 100644 index 000000000..dca6bc793 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisXTrimParams.java @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.command.args.ApproximateExactTrimming; +import com.buession.redis.core.command.args.MaxLenMinId; +import com.buession.redis.core.command.args.XTrimArgument; +import redis.clients.jedis.params.XTrimParams; + +import java.util.Optional; + +/** + * Jedis {@link XTrimParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisXTrimParams extends XTrimParams { + + /** + * 构造函数 + */ + public JedisXTrimParams() { + super(); + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + */ + public JedisXTrimParams(final MaxLenMinId maxLenMinId) { + super(); + maxLenMinId(this, maxLenMinId); + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param limit + * - + */ + public JedisXTrimParams(final MaxLenMinId maxLenMinId, final long limit) { + this(maxLenMinId); + limit(limit); + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + */ + public JedisXTrimParams(final MaxLenMinId maxLenMinId, final ApproximateExactTrimming approximateExactTrimming) { + super(); + maxLenMinId(this, maxLenMinId, approximateExactTrimming); + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param limit + * - + */ + public JedisXTrimParams(final MaxLenMinId maxLenMinId, final ApproximateExactTrimming approximateExactTrimming, + final long limit) { + this(maxLenMinId, approximateExactTrimming); + limit(limit); + } + + /** + * 构造函数 + * + * @param limit + * - + */ + public JedisXTrimParams(final long limit) { + super(); + limit(limit); + } + + /** + * 从 {@link XTrimArgument} 创建 {@link XTrimParams} 实例 + * + * @param xTrimArgument + * {@link XTrimArgument} + * + * @return {@link JedisXTrimParams} 实例 + */ + public static JedisXTrimParams from(final XTrimArgument xTrimArgument) { + final JedisXTrimParams xTrimParams = new JedisXTrimParams(); + + if(xTrimArgument != null){ + maxLenMinId(xTrimParams, xTrimArgument.getMaxLenMinId()); + Optional.ofNullable(xTrimArgument.getLimit()).ifPresent(xTrimParams::limit); + } + + return xTrimParams; + } + + private static void maxLenMinId(final JedisXTrimParams xTrimParams, final MaxLenMinId maxLenMinId) { + if(maxLenMinId != null){ + if(maxLenMinId instanceof MaxLenMinId.MaxLen){ + xTrimParams.maxLen(((MaxLenMinId.MaxLen) maxLenMinId).getValue()); + }else if(maxLenMinId instanceof MaxLenMinId.MinId){ + xTrimParams.minId(((MaxLenMinId.MinId) maxLenMinId).getValue().toString()); + } + } + } + + private static void maxLenMinId(final JedisXTrimParams xTrimParams, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming) { + maxLenMinId(xTrimParams, maxLenMinId); + if(maxLenMinId != null){ + if(approximateExactTrimming == ApproximateExactTrimming.APPROXIMATE){ + xTrimParams.approximateTrimming(); + }else if(approximateExactTrimming == ApproximateExactTrimming.EXACT){ + xTrimParams.exactTrimming(); + } + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisZAddParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisZAddParams.java new file mode 100644 index 000000000..ba315c618 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisZAddParams.java @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.GtLt; +import com.buession.redis.core.NxXx; +import redis.clients.jedis.params.ZAddParams; + +/** + * Jedis {@link ZAddParams} 扩展 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisZAddParams extends ZAddParams { + + /** + * 构造函数 + */ + public JedisZAddParams() { + super(); + } + + /** + * 构造函数 + * + * @param nxXx + * 更新成员方式 + */ + public JedisZAddParams(final NxXx nxXx) { + super(); + if(nxXx != null){ + switch(nxXx){ + case NX: + nx(); + break; + case XX: + xx(); + break; + default: + break; + } + } + } + + /** + * 构造函数 + * + * @param gtLt + * {@link GtLt} + */ + public JedisZAddParams(final GtLt gtLt) { + super(); + gtLt(gtLt); + } + + /** + * 构造函数 + * + * @param ch + * 是否返回变更成员的数量 + */ + public JedisZAddParams(final boolean ch) { + super(); + ch(ch); + } + + /** + * 构造函数 + * + * @param nxXx + * 更新成员方式 + * @param gtLt + * 更新新的分值方式 + */ + public JedisZAddParams(final NxXx nxXx, final GtLt gtLt) { + this(nxXx); + gtLt(gtLt); + } + + /** + * 构造函数 + * + * @param nxXx + * 更新成员方式 + * @param ch + * 是否返回变更成员的数量 + */ + public JedisZAddParams(final NxXx nxXx, final boolean ch) { + this(nxXx); + ch(ch); + } + + /** + * 构造函数 + * + * @param gtLt + * 更新新的分值方式 + * @param ch + * 是否返回变更成员的数量 + */ + public JedisZAddParams(final GtLt gtLt, final boolean ch) { + this(gtLt); + ch(ch); + } + + /** + * 构造函数 + * + * @param nxXx + * 更新成员方式 + * @param gtLt + * 更新新的分值方式 + * @param ch + * 是否返回变更成员的数量 + */ + public JedisZAddParams(final NxXx nxXx, final GtLt gtLt, final boolean ch) { + this(nxXx, gtLt); + ch(ch); + } + + private void gtLt(final GtLt gtLt) { + if(gtLt != null){ + switch(gtLt){ + case GT: + gt(); + break; + case LT: + lt(); + break; + default: + break; + } + } + } + + private void ch(boolean ch) { + if(ch){ + ch(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisZParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisZParams.java new file mode 100644 index 000000000..0665e3b3d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisZParams.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import redis.clients.jedis.params.ZParams; + +/** + * Jedis {@link ZParams} 扩展 + * + * @author Yong.Teng + */ +public final class JedisZParams extends ZParams { + + /** + * 构造函数 + */ + public JedisZParams() { + super(); + } + + /** + * 构造函数 + * + * @param aggregate + * {@link Aggregate} + */ + public JedisZParams(final com.buession.redis.core.Aggregate aggregate) { + super(); + if(aggregate != null){ + switch(aggregate){ + case MIN: + aggregate(Aggregate.MIN); + break; + case MAX: + aggregate(Aggregate.MAX); + break; + case SUM: + aggregate(Aggregate.SUM); + break; + default: + break; + } + } + } + + /** + * 构造函数 + * + * @param weights + * 权重 + */ + public JedisZParams(final double... weights) { + super(); + weights(weights); + } + + /** + * 构造函数 + * + * @param aggregate + * {@link Aggregate} + * @param weights + * 权重 + */ + public JedisZParams(final com.buession.redis.core.Aggregate aggregate, final double... weights) { + this(aggregate); + weights(weights); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisZRangeParams.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisZRangeParams.java new file mode 100644 index 000000000..f010d8468 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/JedisZRangeParams.java @@ -0,0 +1,195 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.ZRangeBy; +import redis.clients.jedis.Protocol; +import redis.clients.jedis.params.ZRangeParams; + +/** + * Jedis {@link ZRangeParams} 扩展 + * + * @author Yong.Teng + * @since 2.0.0 + */ +public final class JedisZRangeParams extends ZRangeParams { + + /** + * 构造函数 + * + * @param min + * 最小值 + * @param max + * 最大值 + */ + public JedisZRangeParams(final long min, final long max) { + super(min, max); + } + + /** + * 构造函数 + * + * @param by + * {@link ZRangeBy} + * @param min + * 最小值 + * @param max + * 最大值 + */ + public JedisZRangeParams(final ZRangeBy by, final long min, final long max) { + super(byKeyword(by), Long.toString(min), Long.toString(max)); + } + + /** + * 构造函数 + * + * @param by + * {@link ZRangeBy} + * @param min + * 最小值 + * @param max + * 最大值 + * @param rev + * - + */ + public JedisZRangeParams(final ZRangeBy by, final long min, final long max, final boolean rev) { + this(by, min, max); + rev(rev); + } + + /** + * 构造函数 + * + * @param by + * {@link ZRangeBy} + * @param min + * 最小值 + * @param max + * 最大值 + * @param offset + * 偏移量 + * @param count + * 返回数量 + */ + public JedisZRangeParams(final ZRangeBy by, final long min, final long max, final long offset, final int count) { + this(by, min, max); + limit((int) offset, count); + } + + /** + * 构造函数 + * + * @param min + * 最小值 + * @param max + * 最大值 + * @param rev + * - + */ + public JedisZRangeParams(final long min, final long max, final boolean rev) { + this(min, max); + rev(rev); + } + + /** + * 构造函数 + * + * @param min + * 最小值 + * @param max + * 最大值 + * @param offset + * 偏移量 + * @param count + * 返回数量 + */ + public JedisZRangeParams(final long min, final long max, final long offset, final int count) { + this(min, max); + limit((int) offset, count); + } + + /** + * 构造函数 + * + * @param min + * 最小值 + * @param max + * 最大值 + * @param rev + * - + * @param offset + * 偏移量 + * @param count + * 返回数量 + */ + public JedisZRangeParams(final long min, final long max, final boolean rev, final long offset, final int count) { + this(min, max, rev); + limit((int) offset, count); + } + + /** + * 构造函数 + * + * @param by + * {@link ZRangeBy} + * @param min + * 最小值 + * @param max + * 最大值 + * @param rev + * - + * @param offset + * 偏移量 + * @param count + * 返回数量 + */ + public JedisZRangeParams(final ZRangeBy by, final long min, final long max, final boolean rev, final long offset, + final int count) { + this(by, min, max, rev); + limit((int) offset, count); + } + + private static Protocol.Keyword byKeyword(final ZRangeBy by) { + if(by != null){ + switch(by){ + case BYLEX: + return Protocol.Keyword.BYLEX; + case BYSCORE: + return Protocol.Keyword.BYSCORE; + default: + break; + } + } + + return null; + } + + private void rev(boolean rev) { + if(rev){ + rev(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/package-info.java new file mode 100644 index 000000000..c8d311672 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/jedis/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.core.internal.jedis; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceAclSetuserArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceAclSetuserArgs.java new file mode 100644 index 000000000..8d1c2a5bd --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceAclSetuserArgs.java @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.command.args.AclSetUserArgument; +import com.buession.redis.core.internal.convert.lettuce.params.AclCategoryConverter; +import com.buession.redis.core.internal.convert.lettuce.params.CommandConverter; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.AclSetuserArgs; +import io.lettuce.core.protocol.ProtocolKeyword; + +/** + * Lettuce {@link AclSetuserArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceAclSetuserArgs extends AclSetuserArgs { + + private final static CommandConverter commandConverter = new CommandConverter(); + + private final static AclCategoryConverter aclCategoryConverter = new AclCategoryConverter(); + + /** + * 构造函数 + */ + public LettuceAclSetuserArgs() { + super(); + } + + /** + * 从 {@link AclSetUserArgument} 创建 {@link AclSetuserArgs} 实例 + * + * @param aclSetUserArgument + * {@link AclSetUserArgument} + * + * @return {@link LettuceAclSetuserArgs} 实例 + */ + public static LettuceAclSetuserArgs from(final AclSetUserArgument aclSetUserArgument) { + final LettuceAclSetuserArgs aclSetuserArgs = new LettuceAclSetuserArgs(); + + for(AclSetUserArgument.Argument argument : aclSetUserArgument.getArguments()){ + if(argument instanceof AclSetUserArgument.State){ + AclSetUserArgument.State state = (AclSetUserArgument.State) argument; + + if(state == AclSetUserArgument.State.ON){ + aclSetuserArgs.on(); + }else if(state == AclSetUserArgument.State.OFF){ + aclSetuserArgs.off(); + } + }else if(argument instanceof AclSetUserArgument.KeyPattern){ + aclSetuserArgs.keyPattern(((AclSetUserArgument.KeyPattern) argument).getValue()); + }else if(argument instanceof AclSetUserArgument.AllKeys){ + aclSetuserArgs.allKeys(); + }else if(argument instanceof AclSetUserArgument.ResetKeys){ + aclSetuserArgs.resetKeys(); + }else if(argument instanceof AclSetUserArgument.ChannelPattern){ + aclSetuserArgs.channelPattern(((AclSetUserArgument.ChannelPattern) argument).getValue()); + }else if(argument instanceof AclSetUserArgument.AllChannels){ + aclSetuserArgs.allChannels(); + }else if(argument instanceof AclSetUserArgument.ResetChannels){ + aclSetuserArgs.resetChannels(); + }else if(argument instanceof AclSetUserArgument.AddCommand){ + final AclSetUserArgument.AddCommand addCommand = (AclSetUserArgument.AddCommand) argument; + + aclSetuserArgs.addCommand( + commandConverter.convert(addCommand.getCommand()), addCommand.getSubCommand() == null ? null + : new LettuceCommandProtocolKeyword(addCommand.getSubCommand())); + }else if(argument instanceof AclSetUserArgument.AllCommands){ + aclSetuserArgs.allCommands(); + }else if(argument instanceof AclSetUserArgument.RemoveCommand){ + final AclSetUserArgument.RemoveCommand removeCommand = (AclSetUserArgument.RemoveCommand) argument; + + aclSetuserArgs.removeCommand( + commandConverter.convert(removeCommand.getCommand()), + removeCommand.getSubCommand() == null ? null + : new LettuceCommandProtocolKeyword(removeCommand.getSubCommand())); + }else if(argument instanceof AclSetUserArgument.NoCommands){ + aclSetuserArgs.noCommands(); + }else if(argument instanceof AclSetUserArgument.AddCategory){ + aclSetuserArgs.addCategory(aclCategoryConverter.convert( + ((AclSetUserArgument.AddCategory) argument).getAclCategory())); + }else if(argument instanceof AclSetUserArgument.RemoveCategory){ + aclSetuserArgs.removeCategory(aclCategoryConverter.convert( + ((AclSetUserArgument.RemoveCategory) argument).getAclCategory())); + }else if(argument instanceof AclSetUserArgument.NoPass){ + aclSetuserArgs.nopass(); + }else if(argument instanceof AclSetUserArgument.ResetPass){ + aclSetuserArgs.resetpass(); + }else if(argument instanceof AclSetUserArgument.AddPassword){ + aclSetuserArgs.addPassword(((AclSetUserArgument.AddPassword) argument).getValue()); + }else if(argument instanceof AclSetUserArgument.RemovePassword){ + aclSetuserArgs.removePassword(((AclSetUserArgument.RemovePassword) argument).getValue()); + }else if(argument instanceof AclSetUserArgument.AddHashedPassword){ + aclSetuserArgs.addHashedPassword(((AclSetUserArgument.AddHashedPassword) argument).getValue()); + }else if(argument instanceof AclSetUserArgument.RemoveHashedPassword){ + aclSetuserArgs.removeHashedPassword(((AclSetUserArgument.RemoveHashedPassword) argument).getValue()); + } + } + + return aclSetuserArgs; + } + + protected static class LettuceCommandProtocolKeyword implements ProtocolKeyword { + + private final ProtocolCommand command; + + protected LettuceCommandProtocolKeyword(final ProtocolCommand command) { + this.command = command; + } + + @Override + public byte[] getBytes() { + return SafeEncoder.encode(name()); + } + + @Override + public String name() { + return command.getName(); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceBitFieldArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceBitFieldArgs.java new file mode 100644 index 000000000..4826ea153 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceBitFieldArgs.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.command.args.BitFieldArgument; +import io.lettuce.core.BitFieldArgs; + +import java.util.List; + +/** + * Lettuce {@link BitFieldArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceBitFieldArgs extends BitFieldArgs { + + /** + * 构造函数 + */ + public LettuceBitFieldArgs() { + super(); + } + + /** + * 从 {@link BitFieldArgument} 创建 {@link BitFieldArgs} 实例 + * + * @param bitFieldArgument + * {@link BitFieldArgument} + * + * @return {@link LettuceBitFieldArgs} 实例 + */ + public static LettuceBitFieldArgs from(final BitFieldArgument bitFieldArgument) { + final LettuceBitFieldArgs bitFieldArgs = new LettuceBitFieldArgs(); + + if(bitFieldArgument != null){ + List commands = bitFieldArgument.getCommands(); + + if(commands != null){ + for(BitFieldArgument.SubCommand command : commands){ + switch(command.getCommandType()){ + case GET: + get(bitFieldArgs, (BitFieldArgument.Get) command); + break; + case SET: + set(bitFieldArgs, (BitFieldArgument.Set) command); + break; + case INCRBY: + incry(bitFieldArgs, (BitFieldArgument.IncrBy) command); + break; + case OVERFLOW: + overflow(bitFieldArgs, (BitFieldArgument.Overflow) command); + break; + default: + break; + } + } + } + } + + return bitFieldArgs; + } + + private static void get(final BitFieldArgs bitFieldArgs, final BitFieldArgument.Get get) { + if(get != null && get.getBitFieldType() != null){ + final BitFieldArgument.BitFieldType bitFieldType = get.getBitFieldType(); + bitFieldArgs.get(bitFieldType.isSigned() ? BitFieldArgs.signed(bitFieldType.getBits()) : + BitFieldArgs.unsigned(bitFieldType.getBits()), get.getOffset()); + } + } + + private static void set(final BitFieldArgs bitFieldArgs, final BitFieldArgument.Set set) { + if(set != null && set.getBitFieldType() != null){ + final BitFieldArgument.BitFieldType bitFieldType = set.getBitFieldType(); + bitFieldArgs.set(bitFieldType.isSigned() ? BitFieldArgs.signed(bitFieldType.getBits()) : + BitFieldArgs.unsigned(bitFieldType.getBits()), set.getOffset(), set.getValue()); + } + } + + private static void incry(final BitFieldArgs bitFieldArgs, final BitFieldArgument.IncrBy incrBy) { + if(incrBy != null && incrBy.getBitFieldType() != null){ + final BitFieldArgument.BitFieldType bitFieldType = incrBy.getBitFieldType(); + bitFieldArgs.set(bitFieldType.isSigned() ? BitFieldArgs.signed(bitFieldType.getBits()) : + BitFieldArgs.unsigned(bitFieldType.getBits()), incrBy.getOffset(), incrBy.getValue()); + } + } + + private static void overflow(final BitFieldArgs bitFieldArgs, + final BitFieldArgument.Overflow overflow) { + if(overflow != null && overflow.getOverflowType() != null){ + switch(overflow.getOverflowType()){ + case FAIL: + bitFieldArgs.overflow(OverflowType.FAIL); + break; + case SAT: + bitFieldArgs.overflow(OverflowType.SAT); + break; + case WRAP: + bitFieldArgs.overflow(OverflowType.WRAP); + break; + default: + break; + } + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceClientConfigBuilder.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceClientConfigBuilder.java new file mode 100644 index 000000000..0dba10b56 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceClientConfigBuilder.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.validator.Validate; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.datasource.lettuce.LettuceRedisDataSource; +import io.lettuce.core.DefaultLettuceClientConfig; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceClientConfigBuilder { + + private final DefaultLettuceClientConfig.Builder builder = DefaultLettuceClientConfig.builder(); + + private final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); + + private LettuceClientConfigBuilder(final LettuceRedisDataSource dataSource, + final SslConfiguration sslConfiguration) { + builder.connectionTimeoutMillis(dataSource.getConnectTimeout()) + .socketTimeoutMillis(dataSource.getSoTimeout()) + .ssl(sslConfiguration != null); + + propertyMapper.from(dataSource.getClientName()).to(builder::clientName); + + if(Validate.hasText(dataSource.getPassword())){ + propertyMapper.from(dataSource.getUsername()).to(builder::user); + builder.password(dataSource.getPassword()); + } + + if(sslConfiguration != null){ + builder.sslSocketFactory(sslConfiguration.getSslSocketFactory()) + .sslParameters(sslConfiguration.getSslParameters()) + .hostnameVerifier(sslConfiguration.getHostnameVerifier()); + } + } + + public static LettuceClientConfigBuilder create(final LettuceRedisDataSource dataSource, + final SslConfiguration sslConfiguration) { + return new LettuceClientConfigBuilder(dataSource, sslConfiguration); + } + + public LettuceClientConfigBuilder user(final String user) { + propertyMapper.from(user).to(builder::user); + return this; + } + + public LettuceClientConfigBuilder password(final String password) { + propertyMapper.from(password).to(builder::password); + return this; + } + + public LettuceClientConfigBuilder database(final int database) { + if(database >= 0){ + builder.database(database); + } + return this; + } + + public LettuceClientConfigBuilder clientName(final String clientName) { + propertyMapper.from(clientName).to(builder::clientName); + return this; + } + + public LettuceClientConfigBuilder connectTimeout(final int connectTimeout) { + builder.connectionTimeoutMillis(connectTimeout); + return this; + } + + public LettuceClientConfigBuilder socketTimeout(final int socketTimeout) { + builder.socketTimeoutMillis(socketTimeout); + return this; + } + + public LettuceClientConfigBuilder infiniteSoTimeout(final int blockingSocketTimeout) { + return this; + } + + public DefaultLettuceClientConfig build() { + return builder.build(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceCopyArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceCopyArgs.java new file mode 100644 index 000000000..873f80116 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceCopyArgs.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import io.lettuce.core.CopyArgs; + +/** + * Lettuce {@link CopyArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceCopyArgs extends CopyArgs { + + /** + * 构造函数 + */ + public LettuceCopyArgs() { + super(); + } + + /** + * 构造函数 + * + * @param destinationDb + * 目标 DB + */ + public LettuceCopyArgs(final int destinationDb) { + super(); + destinationDb(destinationDb); + } + + /** + * 构造函数 + * + * @param replace + * 是否替换已存在 key + */ + public LettuceCopyArgs(final boolean replace) { + super(); + replace(replace); + } + + /** + * 构造函数 + * + * @param destinationDb + * 目标 DB + * @param replace + * 是否替换已存在 key + */ + public LettuceCopyArgs(final int destinationDb, final boolean replace) { + this(destinationDb); + replace(replace); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceExpireArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceExpireArgs.java new file mode 100644 index 000000000..3d9186495 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceExpireArgs.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.ExpireOption; +import io.lettuce.core.ExpireArgs; + +/** + * Lettuce {@link ExpireArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceExpireArgs extends ExpireArgs { + + /** + * 构造函数 + */ + public LettuceExpireArgs() { + super(); + } + + /** + * 构造函数 + * + * @param expireOption + * 过期选项 + */ + public LettuceExpireArgs(final ExpireOption expireOption) { + super(); + expireOption(this, expireOption); + } + + private static void expireOption(final ExpireArgs expireArgs, final ExpireOption expireOption) { + if(expireOption != null){ + switch(expireOption){ + case NX: + expireArgs.nx(); + break; + case XX: + expireArgs.xx(); + break; + case LT: + expireArgs.gt(); + break; + case GT: + expireArgs.gt(); + break; + default: + break; + } + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceGeoAddArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceGeoAddArgs.java new file mode 100644 index 000000000..d3064547b --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceGeoAddArgs.java @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.NxXx; +import com.buession.redis.core.command.args.GeoAddArgument; +import io.lettuce.core.GeoAddArgs; + +/** + * Lettuce {@link GeoAddArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceGeoAddArgs extends GeoAddArgs { + + /** + * 构造函数 + */ + public LettuceGeoAddArgs() { + super(); + } + + /** + * 构造函数 + * + * @param nxXx + * {@link NxXx} + */ + public LettuceGeoAddArgs(final NxXx nxXx) { + super(); + nxXx(this, nxXx); + } + + /** + * 构造函数 + * + * @param ch + * - + */ + public LettuceGeoAddArgs(final boolean ch) { + super(); + ch(this, ch); + } + + /** + * 构造函数 + * + * @param nxXx + * {@link NxXx} + * @param ch + * - + */ + public LettuceGeoAddArgs(final NxXx nxXx, final boolean ch) { + super(); + nxXx(this, nxXx); + ch(this, ch); + } + + /** + * 从 {@link GeoAddArgument} 创建 {@link GeoAddArgs} 实例 + * + * @param geoAddArgument + * {@link GeoAddArgument} + * + * @return {@link LettuceGeoAddArgs} 实例 + */ + public static LettuceGeoAddArgs from(final GeoAddArgument geoAddArgument) { + final LettuceGeoAddArgs geoAddParam = new LettuceGeoAddArgs(); + + nxXx(geoAddParam, geoAddArgument.getNxXx()); + ch(geoAddParam, geoAddArgument.isCh()); + + return geoAddParam; + } + + private static void nxXx(final LettuceGeoAddArgs geoAddArgs, final NxXx nxXx) { + if(nxXx != null){ + switch(nxXx){ + case NX: + geoAddArgs.nx(); + break; + case XX: + geoAddArgs.xx(); + break; + default: + break; + } + } + } + + private static void ch(final LettuceGeoAddArgs geoAddArgs, final Boolean ch) { + if(Boolean.TRUE.equals(ch)){ + geoAddArgs.ch(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceGeoArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceGeoArgs.java new file mode 100644 index 000000000..69cacfc7e --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceGeoArgs.java @@ -0,0 +1,332 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.lang.Order; +import com.buession.redis.core.command.args.GeoRadiusArgument; +import com.buession.redis.core.command.args.GeoSearchArgument; +import com.buession.redis.core.command.args.GeoSearchStoreArgument; +import io.lettuce.core.GeoArgs; + +/** + * Lettuce {@link GeoArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceGeoArgs extends GeoArgs { + + /** + * 构造函数 + */ + public LettuceGeoArgs() { + super(); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + */ + public LettuceGeoArgs(final boolean withCoord, final boolean withDist, final boolean withHash) { + super(); + withCoordinates(this, withCoord); + withDistance(this, withDist); + withHash(this, withHash); + } + + /** + * 构造函数 + * + * @param order + * 排序 + */ + public LettuceGeoArgs(final Order order) { + super(); + sort(this, order); + } + + /** + * 构造函数 + * + * @param count + * 返回数量 + */ + public LettuceGeoArgs(final int count) { + super(); + withCount(count); + } + + /** + * 构造函数 + * + * @param count + * 返回数量 + * @param any + * - + */ + public LettuceGeoArgs(final int count, final boolean any) { + super(); + withCount(count, any); + } + + /** + * 构造函数 + * + * @param order + * 排序 + * @param count + * 返回数量 + */ + public LettuceGeoArgs(final Order order, final int count) { + this(order); + withCount(count); + } + + /** + * 构造函数 + * + * @param order + * 排序 + * @param count + * 返回数量 + * @param any + * - + */ + public LettuceGeoArgs(final Order order, final int count, final boolean any) { + this(order); + withCount(count, any); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param order + * 排序 + */ + public LettuceGeoArgs(final boolean withCoord, final boolean withDist, final boolean withHash, + final Order order) { + this(withCoord, withDist, withHash); + sort(this, order); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param count + * 返回数量 + */ + public LettuceGeoArgs(final boolean withCoord, final boolean withDist, final boolean withHash, + final int count) { + this(withCoord, withDist, withHash); + withCount(count); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param count + * 返回数量 + * @param any + * - + */ + public LettuceGeoArgs(final boolean withCoord, final boolean withDist, final boolean withHash, + final int count, final boolean any) { + this(withCoord, withDist, withHash); + withCount(count, any); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param order + * 排序 + * @param count + * 返回数量 + */ + public LettuceGeoArgs(final boolean withCoord, final boolean withDist, final boolean withHash, + final Order order, final int count) { + this(withCoord, withDist, withHash, order); + withCount(count); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param order + * 排序 + * @param count + * 返回数量 + * @param any + * - + */ + public LettuceGeoArgs(final boolean withCoord, final boolean withDist, final boolean withHash, + final Order order, final int count, final boolean any) { + this(withCoord, withDist, withHash, order); + withCount(count, any); + } + + /** + * 从 {@link GeoRadiusArgument} 创建 {@link GeoArgs} 实例 + * + * @param geoRadiusArgument + * {@link GeoRadiusArgument} + * + * @return {@link LettuceGeoArgs} 实例 + */ + public static LettuceGeoArgs from(final GeoRadiusArgument geoRadiusArgument) { + final LettuceGeoArgs geoArgs = new LettuceGeoArgs(); + + if(geoRadiusArgument != null){ + withCoordinates(geoArgs, geoRadiusArgument.isWithCoord()); + withDistance(geoArgs, geoRadiusArgument.isWithDist()); + withHash(geoArgs, geoRadiusArgument.isWithHash()); + sort(geoArgs, geoRadiusArgument.getOrder()); + + if(geoRadiusArgument.getCount() != null){ + if(geoRadiusArgument.isAny() != null){ + geoArgs.withCount(geoRadiusArgument.getCount(), geoRadiusArgument.isAny()); + }else{ + geoArgs.withCount(geoRadiusArgument.getCount()); + } + } + } + + return geoArgs; + } + + /** + * 从 {@link GeoSearchArgument} 创建 {@link GeoArgs} 实例 + * + * @param geoSearchArgument + * {@link GeoRadiusArgument} + * + * @return {@link LettuceGeoArgs} 实例 + */ + public static LettuceGeoArgs from(final GeoSearchArgument geoSearchArgument) { + final LettuceGeoArgs geoArgs = new LettuceGeoArgs(); + + withCoordinates(geoArgs, geoSearchArgument.isWithCoord()); + withDistance(geoArgs, geoSearchArgument.isWithDist()); + withHash(geoArgs, geoSearchArgument.isWithHash()); + sort(geoArgs, geoSearchArgument.getOrder()); + + if(geoSearchArgument.getCount() != null){ + if(geoSearchArgument.isAny() != null){ + geoArgs.withCount(geoSearchArgument.getCount(), geoSearchArgument.isAny()); + }else{ + geoArgs.withCount(geoSearchArgument.getCount()); + } + } + + return geoArgs; + } + + /** + * 从 {@link GeoSearchStoreArgument} 创建 {@link GeoArgs} 实例 + * + * @param geoSearchStoreArgument + * {@link GeoSearchStoreArgument} + * + * @return {@link LettuceGeoArgs} 实例 + */ + public static LettuceGeoArgs from(final GeoSearchStoreArgument geoSearchStoreArgument) { + final LettuceGeoArgs geoArgs = new LettuceGeoArgs(); + + sort(geoArgs, geoSearchStoreArgument.getOrder()); + + if(geoSearchStoreArgument.getCount() != null){ + if(geoSearchStoreArgument.isAny() != null){ + geoArgs.withCount(geoSearchStoreArgument.getCount(), geoSearchStoreArgument.isAny()); + }else{ + geoArgs.withCount(geoSearchStoreArgument.getCount()); + } + } + + return geoArgs; + } + + private static void withCoordinates(final LettuceGeoArgs geoArgs, final Boolean withCoord) { + if(Boolean.TRUE.equals(withCoord)){ + geoArgs.withCoordinates(); + } + } + + private static void withDistance(final LettuceGeoArgs geoArgs, final Boolean withDist) { + if(Boolean.TRUE.equals(withDist)){ + geoArgs.withDistance(); + } + } + + private static void withHash(final LettuceGeoArgs geoArgs, final Boolean withHash) { + if(Boolean.TRUE.equals(withHash)){ + geoArgs.withHash(); + } + } + + private static void sort(final LettuceGeoArgs geoArgs, final Order order) { + if(order == Order.ASC){ + geoArgs.sort(Sort.asc); + }else if(order == Order.DESC){ + geoArgs.sort(Sort.desc); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceGeoValue.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceGeoValue.java new file mode 100644 index 000000000..b89f93a47 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceGeoValue.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.lang.Geo; +import io.lettuce.core.GeoValue; + +/** + * Lettuce {@link GeoValue} 扩展 + * + * @param + * 值类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceGeoValue extends GeoValue { + + private final static long serialVersionUID = -818577420137908972L; + + /** + * 构造函数 + */ + public LettuceGeoValue() { + super(); + } + + /** + * 构造函数 + * + * @param member + * 成员 + * @param longitude + * 经度 + * @param latitude + * 纬度 + */ + public LettuceGeoValue(final V member, final double longitude, final double latitude) { + super(); + } + + /** + * 从 {@link Geo} 创建 {@link GeoValue} 实例 + * + * @param member + * 成员 + * @param geo + * {@link Geo} + * @param + * 值类型 + * + * @return {@link LettuceGeoValue} 实例 + */ + public static GeoValue from(final V member, final Geo geo) { + return just(geo.getLongitude(), geo.getLatitude(), member); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceGetExArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceGetExArgs.java new file mode 100644 index 000000000..7dc09cef8 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceGetExArgs.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.command.args.GetExArgument; +import io.lettuce.core.GetExArgs; + +/** + * Lettuce {@link GetExArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceGetExArgs extends GetExArgs { + + /** + * 构造函数 + */ + public LettuceGetExArgs() { + super(); + } + + /** + * 构造函数 + * + * @param type + * 键过期设置方式 + * @param value + * 键过期时间 + */ + public LettuceGetExArgs(final GetExArgument.GetExType type, final long value) { + super(); + + if(type != null){ + switch(type){ + case EX: + ex(value); + break; + case EXAT: + exAt(value); + break; + case PX: + px(value); + break; + case PXAT: + pxAt(value); + break; + case PERSIST: + persist(); + break; + default: + break; + } + } + } + + /** + * 构造函数 + * + * @param persist + * 设置键是否持久化 + */ + public LettuceGetExArgs(final boolean persist) { + super(); + if(Boolean.TRUE.equals(persist)){ + persist(); + } + } + + /** + * 从 {@link GetExArgument} 创建 {@link GetExArgs} 实例 + * + * @param getExArgument + * {@link GetExArgument} + * + * @return {@link LettuceGetExArgs} 实例 + */ + public static LettuceGetExArgs from(final GetExArgument getExArgument) { + return getExArgument != null && getExArgument.getType() != null && getExArgument.getExpires() != null ? + new LettuceGetExArgs(getExArgument.getType(), getExArgument.getExpires()) : + new LettuceGetExArgs(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceKillArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceKillArgs.java new file mode 100644 index 000000000..475f0a99b --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceKillArgs.java @@ -0,0 +1,272 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.core.utils.FieldUtils; +import com.buession.redis.core.ClientType; +import com.buession.redis.core.command.args.ClientKillArgument; +import io.lettuce.core.KillArgs; + +import java.util.Optional; + +/** + * Lettuce {@link KillArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceKillArgs extends KillArgs { + + /** + * 构造函数 + */ + public LettuceKillArgs() { + super(); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + */ + public LettuceKillArgs(final long clientId) { + super(); + id(clientId); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + */ + public LettuceKillArgs(final ClientType clientType) { + super(); + type(clientType); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public LettuceKillArgs(final long clientId, final boolean skipMe, final long maxAge) { + this(clientId); + skipme(skipMe); + maxAge(maxAge); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public LettuceKillArgs(final ClientType clientType, final boolean skipMe, final long maxAge) { + this(clientType); + skipme(skipMe); + maxAge(maxAge); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public LettuceKillArgs(final long clientId, final String addr, final String laddr, final boolean skipMe, + final long maxAge) { + this(clientId, skipMe, maxAge); + addr(addr); + laddr(laddr); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public LettuceKillArgs(final ClientType clientType, final String addr, final String laddr, + final boolean skipMe, final long maxAge) { + this(clientType, skipMe, maxAge); + addr(addr); + laddr(laddr); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public LettuceKillArgs(final long clientId, final String username, final String addr, final String laddr, + final boolean skipMe, final long maxAge) { + this(clientId, addr, laddr, skipMe, maxAge); + user(username); + } + + /** + * 构造函数 + * + * @param clientType + * 客户端类型 + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public LettuceKillArgs(final ClientType clientType, final String username, final String addr, + final String laddr, final boolean skipMe, final long maxAge) { + this(clientType, addr, laddr, skipMe, maxAge); + user(username); + } + + /** + * 构造函数 + * + * @param clientId + * 客户端 ID + * @param clientType + * 客户端类型 + * @param username + * 用户名 + * @param addr + * - + * @param laddr + * - + * @param skipMe + * 是否跳过自身 + * @param maxAge + * Closes all the connections that are older than the specified age, in seconds. + */ + public LettuceKillArgs(final long clientId, final ClientType clientType, final String username, + final String addr, final String laddr, final boolean skipMe, final long maxAge) { + this(clientType, username, addr, laddr, skipMe, maxAge); + id(clientId); + } + + public LettuceKillArgs type(final ClientType clientType) { + if(clientType != null){ + KillArgs killArgs = null; + switch(clientType){ + case NORMAL: + killArgs = Builder.typeNormal(); + break; + case MASTER: + killArgs = Builder.typeMaster(); + break; + case SLAVE: + killArgs = Builder.typeSlave(); + break; + case REPLICA: + break; + case PUBSUB: + killArgs = Builder.typePubsub(); + break; + default: + break; + } + + if(killArgs != null){ + try{ + Object type = FieldUtils.readField(killArgs, "type"); + if(type != null){ + FieldUtils.writeField(this, "type", type); + } + }catch(IllegalAccessException e){ + throw new RuntimeException(e); + } + } + } + + return this; + } + + /** + * 从 {@link ClientKillArgument} 创建 {@link KillArgs} 实例 + * + * @param clientKillArgument + * {@link ClientKillArgument} + * + * @return {@link LettuceKillArgs} 实例 + */ + public static LettuceKillArgs from(final ClientKillArgument clientKillArgument) { + final LettuceKillArgs killArgs = new LettuceKillArgs(); + + Optional.ofNullable(clientKillArgument.getClientId()).ifPresent(killArgs::id); + Optional.ofNullable(clientKillArgument.getClientType()).ifPresent(killArgs::type); + Optional.ofNullable(clientKillArgument.getUsername()).ifPresent(killArgs::user); + Optional.ofNullable(clientKillArgument.getAddr()).ifPresent(killArgs::addr); + Optional.ofNullable(clientKillArgument.getLaddr()).ifPresent(killArgs::laddr); + Optional.ofNullable(clientKillArgument.getSkipMe()).ifPresent(killArgs::skipme); + Optional.ofNullable(clientKillArgument.getMaxAge()).ifPresent(killArgs::maxAge); + + return killArgs; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceLPosArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceLPosArgs.java new file mode 100644 index 000000000..907418c78 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceLPosArgs.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.command.args.LPosArgument; +import io.lettuce.core.LPosArgs; + +import java.util.Optional; + +/** + * Lettuce {@link LPosArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceLPosArgs extends LPosArgs { + + /** + * 构造函数 + */ + public LettuceLPosArgs() { + super(); + } + + /** + * 构造函数 + * + * @param rank + * 返回第几个匹配的元素 + */ + public LettuceLPosArgs(final int rank) { + super(); + rank(rank); + } + + /** + * 构造函数 + * + * @param rank + * 返回第几个匹配的元素 + * @param maxLen + * 查找成员个数 + */ + public LettuceLPosArgs(final int rank, final int maxLen) { + super(); + rank(rank); + maxlen(maxLen); + } + + /** + * 从 {@link LPosArgument} 创建 {@link LPosArgs} 实例 + * + * @param lPosArgument + * {@link LPosArgument} + * + * @return {@link LettuceLPosArgs} 实例 + */ + public static LettuceLPosArgs from(final LPosArgument lPosArgument) { + final LettuceLPosArgs lPosArgs = new LettuceLPosArgs(); + + Optional.ofNullable(lPosArgument.getRank()).ifPresent(lPosArgs::rank); + Optional.ofNullable(lPosArgument.getMaxLen()).ifPresent(lPosArgs::maxlen); + + return lPosArgs; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceMigrateArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceMigrateArgs.java new file mode 100644 index 000000000..bc328a355 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceMigrateArgs.java @@ -0,0 +1,341 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.core.validator.Validate; +import com.buession.redis.core.command.args.MigrateArgument; +import com.buession.redis.core.internal.jedis.JedisMigrateParams; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.MigrateArgs; +import redis.clients.jedis.params.MigrateParams; + +/** + * Lettuce {@link MigrateArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceMigrateArgs extends MigrateArgs { + + /** + * 构造函数 + */ + public LettuceMigrateArgs() { + super(); + } + + /** + * 构造函数 + * + * @param migrateOperation + * 迁移方式 + */ + public LettuceMigrateArgs(final MigrateArgument.Mode migrateOperation) { + super(); + mode(this, migrateOperation); + } + + /** + * 构造函数 + * + * @param migrateOperation + * 迁移方式 + * @param keys + * 迁移 Key + */ + public LettuceMigrateArgs(final MigrateArgument.Mode migrateOperation, final T[] keys) { + this(migrateOperation); + keys(keys); + } + + /** + * 构造函数 + * + * @param password + * 密码 + */ + public LettuceMigrateArgs(final String password) { + super(); + auth(password); + } + + /** + * 构造函数 + * + * @param password + * 密码 + */ + public LettuceMigrateArgs(final byte[] password) { + this(SafeEncoder.encode(password)); + } + + /** + * 构造函数 + * + * @param username + * 用户名 + * @param password + * 密码 + */ + public LettuceMigrateArgs(final String username, final String password) { + super(); + auth2(username, password); + } + + /** + * 构造函数 + * + * @param username + * 用户名 + * @param password + * 密码 + */ + public LettuceMigrateArgs(final byte[] username, final byte[] password) { + this(SafeEncoder.encode(username), SafeEncoder.encode(password)); + } + + /** + * 构造函数 + * + * @param keys + * 迁移 Key + * @param password + * 密码 + */ + public LettuceMigrateArgs(final T[] keys, final String password) { + this(keys); + auth(password); + } + + /** + * 构造函数 + * + * @param keys + * 迁移 Key + * @param password + * 密码 + */ + public LettuceMigrateArgs(final T[] keys, final byte[] password) { + this(keys, SafeEncoder.encode(password)); + } + + /** + * 构造函数 + * + * @param keys + * 迁移 Key + * @param username + * 用户名 + * @param password + * 密码 + */ + public LettuceMigrateArgs(final T[] keys, final String username, final String password) { + this(username, password); + keys(keys); + } + + /** + * 构造函数 + * + * @param keys + * 迁移 Key + * @param username + * 用户名 + * @param password + * 密码 + */ + public LettuceMigrateArgs(final T[] keys, final byte[] username, final byte[] password) { + this(username, password); + keys(keys); + } + + /** + * 构造函数 + * + * @param migrateOperation + * 迁移方式 + * @param password + * 密码 + */ + public LettuceMigrateArgs(final MigrateArgument.Mode migrateOperation, final String password) { + this(migrateOperation); + auth(password); + } + + /** + * 构造函数 + * + * @param migrateOperation + * 迁移方式 + * @param password + * 密码 + */ + public LettuceMigrateArgs(final MigrateArgument.Mode migrateOperation, final byte[] password) { + this(migrateOperation, SafeEncoder.encode(password)); + } + + /** + * 构造函数 + * + * @param migrateOperation + * 迁移方式 + * @param username + * 用户名 + * @param password + * 密码 + */ + public LettuceMigrateArgs(final MigrateArgument.Mode migrateOperation, final String username, + final String password) { + this(migrateOperation); + auth2(username, password); + } + + /** + * 构造函数 + * + * @param migrateOperation + * 迁移方式 + * @param username + * 用户名 + * @param password + * 密码 + */ + public LettuceMigrateArgs(final MigrateArgument.Mode migrateOperation, final byte[] username, + final byte[] password) { + this(migrateOperation, SafeEncoder.encode(username), SafeEncoder.encode(password)); + } + + /** + * 构造函数 + * + * @param migrateOperation + * 迁移方式 + * @param keys + * 迁移 Key + * @param password + * 密码 + */ + public LettuceMigrateArgs(final MigrateArgument.Mode migrateOperation, final T[] keys, final String password) { + this(migrateOperation, keys); + auth(password); + } + + /** + * 构造函数 + * + * @param migrateOperation + * 迁移方式 + * @param keys + * 迁移 Key + * @param password + * 密码 + */ + public LettuceMigrateArgs(final MigrateArgument.Mode migrateOperation, final T[] keys, final byte[] password) { + this(migrateOperation, password); + keys(keys); + } + + /** + * 构造函数 + * + * @param migrateOperation + * 迁移方式 + * @param keys + * 迁移 Key + * @param username + * 用户名 + * @param password + * 密码 + */ + public LettuceMigrateArgs(final MigrateArgument.Mode migrateOperation, final T[] keys, final String username, + final String password) { + this(migrateOperation, keys); + auth2(username, password); + } + + /** + * 构造函数 + * + * @param migrateOperation + * 迁移方式 + * @param keys + * 迁移 Key + * @param username + * 用户名 + * @param password + * 密码 + */ + public LettuceMigrateArgs(final MigrateArgument.Mode migrateOperation, final T[] keys, final byte[] username, + final byte[] password) { + this(migrateOperation, username, password); + keys(keys); + } + + /** + * 构造函数 + * + * @param keys + * 迁移 Key + */ + public LettuceMigrateArgs(final T[] keys) { + super(); + keys(keys); + } + + /** + * 从 {@link MigrateArgument} 创建 {@link MigrateParams} 实例 + * + * @param migrateArgument + * {@link MigrateArgument} + * + * @return {@link JedisMigrateParams} 实例 + * + * @since 3.0.0 + */ + public static LettuceMigrateArgs from(final MigrateArgument migrateArgument) { + final LettuceMigrateArgs migrateArgs = new LettuceMigrateArgs<>(); + + mode(migrateArgs, migrateArgument.getMode()); + + if(Validate.hasText(migrateArgument.getPassword())){ + if(Validate.hasText(migrateArgument.getUsername())){ + migrateArgs.auth2(migrateArgument.getUsername(), migrateArgument.getPassword()); + }else{ + migrateArgs.auth(migrateArgument.getPassword()); + } + } + + return migrateArgs; + } + + private static void mode(final MigrateArgs migrateArgs, final MigrateArgument.Mode migrateOperation) { + if(migrateOperation == MigrateArgument.Mode.COPY){ + migrateArgs.copy(); + }else if(migrateOperation == MigrateArgument.Mode.REPLACE){ + migrateArgs.replace(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceRestoreArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceRestoreArgs.java new file mode 100644 index 000000000..cc3ccdef0 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceRestoreArgs.java @@ -0,0 +1,152 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.command.args.RestoreArgument; +import io.lettuce.core.RestoreArgs; + +import java.util.Optional; + +/** + * Lettuce {@link RestoreArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceRestoreArgs extends RestoreArgs { + + /** + * 构造函数 + */ + public LettuceRestoreArgs() { + super(); + } + + /** + * 构造函数 + * + * @param replace + * 是否替换已存在 key + */ + + public LettuceRestoreArgs(final boolean replace) { + super(); + replace(this, replace); + } + + /** + * 构造函数 + * + * @param replace + * 是否替换已存在 key + * @param absTtl + * - + */ + public LettuceRestoreArgs(final boolean replace, final boolean absTtl) { + super(); + replace(this, replace); + absTtl(this, absTtl); + } + + /** + * 构造函数 + * + * @param replace + * 是否替换已存在 key + * @param idleTime + * - + * @param frequency + * - + */ + public LettuceRestoreArgs(final boolean replace, final long idleTime, final long frequency) { + super(); + replace(this, replace); + idleTime(idleTime); + frequency(frequency); + } + + /** + * 构造函数 + * + * @param replace + * 是否替换已存在 key + * @param absTtl + * - + * @param idleTime + * - + * @param frequency + * - + */ + public LettuceRestoreArgs(final boolean replace, final boolean absTtl, final long idleTime, final long frequency) { + this(replace, idleTime, frequency); + absTtl(this, absTtl); + } + + /** + * 构造函数 + * + * @param idleTime + * - + * @param frequency + * - + */ + public LettuceRestoreArgs(final long idleTime, final long frequency) { + super(); + idleTime(idleTime); + frequency(frequency); + } + + /** + * 从 {@link RestoreArgument} 创建 {@link RestoreArgs} 实例 + * + * @param restoreArgument + * {@link RestoreArgument} + * + * @return {@link LettuceRestoreArgs} 实例 + */ + public static LettuceRestoreArgs from(final RestoreArgument restoreArgument) { + final LettuceRestoreArgs restoreArgs = new LettuceRestoreArgs(); + + replace(restoreArgs, restoreArgument.isReplace()); + absTtl(restoreArgs, restoreArgument.isAbsTtl()); + Optional.ofNullable(restoreArgument.getIdleTime()).ifPresent(restoreArgs::idleTime); + Optional.ofNullable(restoreArgument.getFrequency()).ifPresent(restoreArgs::frequency); + + return restoreArgs; + } + + private static void replace(final LettuceRestoreArgs restoreArgs, final Boolean replace) { + if(Boolean.TRUE.equals(replace)){ + restoreArgs.replace(); + } + } + + private static void absTtl(final LettuceRestoreArgs restoreArgs, final Boolean absTtl) { + if(Boolean.TRUE.equals(absTtl)){ + restoreArgs.absttl(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceResult.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceResult.java new file mode 100644 index 000000000..dbf9f39d9 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceResult.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.FutureResult; +import com.buession.redis.core.internal.convert.Converters; +import io.lettuce.core.RedisFuture; +import io.lettuce.core.protocol.RedisCommand; + +/** + * Lettuce 事务、管道异步结果 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceResult extends FutureResult> { + + @SuppressWarnings({"unchecked"}) + public LettuceResult(final RedisFuture resultHolder) { + super((RedisCommand) resultHolder); + } + + @SuppressWarnings({"unchecked"}) + public LettuceResult(final RedisFuture resultHolder, final Converter converter) { + super((RedisCommand) resultHolder, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + public SV get() { + return (SV) getHolder().getOutput().get(); + } + + public final static class Builder { + + private final RedisFuture response; + + private Converter converter; + + private Builder(final RedisFuture response, final Converter converter) { + this.response = response; + this.converter = converter; + } + + public static Builder fromRedisFuture(RedisFuture redisFuture) { + return new LettuceResult.Builder<>(redisFuture, Converters.always()); + } + + public Builder mappedWith(Converter converter) { + this.converter = converter; + return this; + } + + public LettuceResult build() { + return new LettuceResult<>(response, converter); + } + + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceScanArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceScanArgs.java new file mode 100644 index 000000000..7ec728fe4 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceScanArgs.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.command.args.HScanArgument; +import io.lettuce.core.ScanArgs; + +import java.util.Optional; + +/** + * Lettuce {@link ScanArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceScanArgs extends ScanArgs { + + /** + * 构造函数 + */ + public LettuceScanArgs() { + super(); + } + + /** + * 构造函数 + * + * @param pattern + * 匹配模式 + */ + public LettuceScanArgs(final String pattern) { + super(); + match(pattern); + } + + /** + * 构造函数 + * + * @param pattern + * 匹配模式 + */ + public LettuceScanArgs(final byte[] pattern) { + super(); + match(pattern); + } + + /** + * 构造函数 + * + * @param count + * 返回数量 + */ + public LettuceScanArgs(final int count) { + super(); + limit(count); + } + + /** + * 构造函数 + * + * @param pattern + * 匹配模式 + * @param count + * 返回数量 + */ + public LettuceScanArgs(final String pattern, final int count) { + this(pattern); + limit(count); + } + + /** + * 构造函数 + * + * @param pattern + * 匹配模式 + * @param count + * 返回数量 + */ + public LettuceScanArgs(final byte[] pattern, final int count) { + this(pattern); + limit(count); + } + + /** + * 从 {@link HScanArgument} 创建 {@link ScanArgs} 实例 + * + * @param scanArgument + * {@link HScanArgument} + * + * @return {@link LettuceScanArgs} 实例 + */ + public static LettuceScanArgs from(final HScanArgument scanArgument) { + final LettuceScanArgs scanArgs = new LettuceScanArgs(); + + if(scanArgument.getPattern() instanceof String){ + scanArgs.match((String) scanArgument.getPattern()); + }else if(scanArgument.getPattern() instanceof byte[]){ + scanArgs.match((byte[]) scanArgument.getPattern()); + } + Optional.ofNullable(scanArgument.getCount()).ifPresent(scanArgs::limit); + + return scanArgs; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceScanCursor.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceScanCursor.java new file mode 100644 index 000000000..11f33bd36 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceScanCursor.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ScanCursor; + +/** + * Lettuce {@link ScanCursor} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceScanCursor extends ScanCursor { + + public LettuceScanCursor() { + super(); + } + + public LettuceScanCursor(final String pattern) { + super(pattern, false); + } + + public LettuceScanCursor(final byte[] pattern) { + this(SafeEncoder.encode(pattern)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceSetArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceSetArgs.java new file mode 100644 index 000000000..f9ddfd9f8 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceSetArgs.java @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.NxXx; +import com.buession.redis.core.command.args.SetArgument; +import io.lettuce.core.SetArgs; + +/** + * Lettuce {@link SetArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceSetArgs extends SetArgs { + + /** + * 构造函数 + */ + public LettuceSetArgs() { + super(); + } + + /** + * 构造函数 + * + * @param type + * 过期时间方式 + * @param expires + * 过期时间 + */ + public LettuceSetArgs(final SetArgument.SetType type, final long expires) { + expx(this, type, expires); + } + + /** + * 构造函数 + * + * @param type + * 过期时间方式 + * @param expires + * 过期时间 + * @param nxXx + * 只有键 key 不存在/存在的时候才会设置 key 的值 + */ + public LettuceSetArgs(final SetArgument.SetType type, final long expires, final NxXx nxXx) { + this(type, expires); + nxxx(this, nxXx); + } + + /** + * 构造函数 + * + * @param nxXx + * 只有键 key 不存在/存在的时候才会设置 key 的值 + */ + public LettuceSetArgs(final NxXx nxXx) { + super(); + nxxx(this, nxXx); + } + + /** + * 构造函数 + * + * @param keepTtl + * 是否获取 key 的过期时间 + */ + public LettuceSetArgs(final boolean keepTtl) { + super(); + keepTtl(this, keepTtl); + } + + /** + * 构造函数 + * + * @param nxXx + * 只有键 key 不存在/存在的时候才会设置 key 的值 + * @param keepTtl + * 是否获取 key 的过期时间 + */ + public LettuceSetArgs(final NxXx nxXx, final boolean keepTtl) { + super(); + nxxx(this, nxXx); + keepTtl(this, keepTtl); + } + + /** + * 构造函数 + * + * @param type + * 过期时间方式 + * @param expires + * 过期时间 + * @param nxXx + * 只有键 key 不存在/存在的时候才会设置 key 的值 + * @param keepTtl + * 是否获取 key 的过期时间 + */ + public LettuceSetArgs(final SetArgument.SetType type, final long expires, final NxXx nxXx, final Boolean keepTtl) { + this(type, expires, nxXx); + keepTtl(this, keepTtl); + } + + /** + * 从 {@link SetArgument} 创建 {@link SetArgs} 实例 + * + * @param setArgument + * {@link SetArgument} + * + * @return {@link LettuceSetArgs} 实例 + */ + public static LettuceSetArgs from(final SetArgument setArgument) { + final LettuceSetArgs setArgs = new LettuceSetArgs(); + + expx(setArgs, setArgument.getType(), setArgument.getExpires()); + nxxx(setArgs, setArgument.getNxXx()); + keepTtl(setArgs, setArgument.isKeepTtl()); + + return setArgs; + } + + private static void expx(final LettuceSetArgs setArgs, final SetArgument.SetType type, final Long expires) { + if(type != null && expires != null){ + switch(type){ + case EX: + setArgs.ex(expires); + break; + case EXAT: + setArgs.exAt(expires); + break; + case PX: + setArgs.px(expires); + break; + case PXAT: + setArgs.pxAt(expires); + break; + default: + break; + } + } + } + + private static void nxxx(final LettuceSetArgs setArgs, final NxXx nx) { + if(nx == NxXx.NX){ + setArgs.nx(); + }else if(nx == NxXx.XX){ + setArgs.xx(); + } + } + + private static void keepTtl(final LettuceSetArgs setArgs, final Boolean keepTtl) { + if(Boolean.TRUE.equals(keepTtl)){ + setArgs.keepttl(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceSortArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceSortArgs.java new file mode 100644 index 000000000..32a0e6a33 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceSortArgs.java @@ -0,0 +1,323 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.lang.Order; +import com.buession.redis.core.Limit; +import com.buession.redis.core.command.args.SortArgument; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.SortArgs; + +import java.util.Arrays; +import java.util.Optional; + +/** + * Lettuce {@link SortArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSortArgs extends SortArgs { + + /** + * 构造函数 + */ + public LettuceSortArgs() { + super(); + } + + /** + * 构造函数 + * + * @param by + * - + */ + public LettuceSortArgs(final String by) { + super(); + by(by); + } + + /** + * 构造函数 + * + * @param by + * - + */ + public LettuceSortArgs(final byte[] by) { + super(); + by(by); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + */ + public LettuceSortArgs(final String by, final String[] gets) { + this(by); + if(gets != null){ + Arrays.stream(gets).forEach(this::get); + } + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + */ + public LettuceSortArgs(final byte[] by, final byte[][] gets) { + this(by); + if(gets != null){ + Arrays.stream(gets).forEach(this::get); + } + } + + /** + * 构造函数 + * + * @param by + * - + * @param order + * 排序方式 + */ + public LettuceSortArgs(final String by, final Order order) { + this(by); + order(this, order); + } + + /** + * 构造函数 + * + * @param by + * - + * @param order + * 排序方式 + */ + public LettuceSortArgs(final byte[] by, final Order order) { + this(by); + order(this, order); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + */ + public LettuceSortArgs(final String by, final String[] gets, final Order order) { + this(by, gets); + order(this, order); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + */ + public LettuceSortArgs(final byte[] by, final byte[][] gets, final Order order) { + this(by, gets); + order(this, order); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param limit + * 结果限制 + */ + public LettuceSortArgs(final String by, final String[] gets, final Limit limit) { + this(by, gets); + limit(this, limit); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param limit + * 结果限制 + */ + public LettuceSortArgs(final byte[] by, final byte[][] gets, final Limit limit) { + this(by, gets); + limit(this, limit); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + * @param limit + * 结果限制 + */ + public LettuceSortArgs(final String by, final String[] gets, final Order order, final Limit limit) { + this(by, gets, order); + limit(this, limit); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + * @param limit + * 结果限制 + */ + public LettuceSortArgs(final byte[] by, final byte[][] gets, final Order order, final Limit limit) { + this(by, gets, order); + limit(this, limit); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + * @param limit + * 结果限制 + * @param alpha + * - + */ + public LettuceSortArgs(final String by, final String[] gets, final Order order, final Limit limit, + final boolean alpha) { + this(by, gets, order, limit); + alpha(this, alpha); + } + + /** + * 构造函数 + * + * @param by + * - + * @param gets + * - + * @param order + * 排序方式 + * @param limit + * 结果限制 + * @param alpha + * - + */ + public LettuceSortArgs(final byte[] by, final byte[][] gets, final Order order, final Limit limit, + final boolean alpha) { + this(by, gets, order, limit); + alpha(this, alpha); + } + + public LettuceSortArgs by(byte[] pattern) { + if(pattern != null){ + by(SafeEncoder.encode(pattern)); + } + + return this; + } + + public LettuceSortArgs get(byte[] pattern) { + if(pattern != null){ + get(SafeEncoder.encode(pattern)); + } + + return this; + } + + /** + * 从 {@link SortArgument} 创建 {@link SortArgs} 实例 + * + * @param sortArgument + * {@link SortArgument} + * + * @return {@link LettuceSortArgs} 实例 + */ + public static LettuceSortArgs from(final SortArgument sortArgument) { + final LettuceSortArgs sortArgs = new LettuceSortArgs(); + + if(sortArgument != null){ + Optional.ofNullable(sortArgument.getBy()).ifPresent(sortArgs::by); + if(sortArgument.getGetPatterns() != null){ + Arrays.stream(sortArgument.getGetPatterns()).forEach(sortArgs::get); + } + order(sortArgs, sortArgument.getOrder()); + limit(sortArgs, sortArgument.getLimit()); + alpha(sortArgs, sortArgument.isAlpha()); + } + + return sortArgs; + } + + private static void alpha(final LettuceSortArgs sortArgs, final Boolean alpha) { + if(Boolean.TRUE.equals(alpha)){ + sortArgs.alpha(); + } + } + + private static void limit(final LettuceSortArgs sortArgs, final Limit limit) { + if(limit != null){ + sortArgs.limit((int) limit.getOffset(), (int) limit.getCount()); + } + } + + private static void order(final LettuceSortArgs sortArgs, final Order order) { + if(order == Order.ASC){ + sortArgs.asc(); + }else if(order == Order.DESC){ + sortArgs.desc(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceTrackingArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceTrackingArgs.java new file mode 100644 index 000000000..9d76ec4be --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceTrackingArgs.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.command.args.ClientTracking; +import io.lettuce.core.TrackingArgs; + +import java.util.Optional; + +/** + * Lettuce {@link TrackingArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceTrackingArgs extends TrackingArgs { + + public LettuceTrackingArgs() { + super(); + } + + public LettuceTrackingArgs(final boolean enabled) { + super(); + enabled(enabled); + } + + public LettuceTrackingArgs(final boolean enabled, final long redirect) { + this(enabled); + redirect(redirect); + } + + public LettuceTrackingArgs(final boolean enabled, final String[] prefixes) { + this(enabled); + prefixes(prefixes); + } + + public LettuceTrackingArgs(final boolean enabled, final long redirect, final String[] prefixes) { + this(enabled, redirect); + prefixes(prefixes); + } + + public LettuceTrackingArgs(final boolean enabled, final long redirect, final String[] prefixes, final boolean bcast, + final boolean optin, final boolean optout, final boolean noloop) { + this(enabled, redirect, prefixes); + bcast(this, bcast); + optin(this, optin); + optout(this, optout); + noloop(this, noloop); + } + + public static LettuceTrackingArgs from(final ClientTracking clientTracking) { + final LettuceTrackingArgs trackArgs = new LettuceTrackingArgs(); + + Optional.ofNullable(clientTracking.isEnabled()).ifPresent(trackArgs::enabled); + Optional.ofNullable(clientTracking.getRedirect()).ifPresent(trackArgs::redirect); + Optional.ofNullable(clientTracking.getPrefixes()).ifPresent(trackArgs::prefixes); + bcast(trackArgs, clientTracking.isBcast()); + optin(trackArgs, clientTracking.isOptin()); + optout(trackArgs, clientTracking.isOptout()); + noloop(trackArgs, clientTracking.isNoloop()); + + return trackArgs; + } + + private static void bcast(final TrackingArgs trackingArgs, final Boolean bcast) { + if(Boolean.TRUE.equals(bcast)){ + trackingArgs.bcast(); + } + } + + private static void optin(final TrackingArgs trackingArgs, final Boolean optin) { + if(Boolean.TRUE.equals(optin)){ + trackingArgs.optin(); + } + } + + private static void optout(final TrackingArgs trackingArgs, final Boolean optout) { + if(Boolean.TRUE.equals(optout)){ + trackingArgs.optout(); + } + } + + private static void noloop(final TrackingArgs trackingArgs, final Boolean noloop) { + if(Boolean.TRUE.equals(noloop)){ + trackingArgs.noloop(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXAddArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXAddArgs.java new file mode 100644 index 000000000..696e9322e --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXAddArgs.java @@ -0,0 +1,629 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.command.args.ApproximateExactTrimming; +import com.buession.redis.core.command.args.MaxLenMinId; +import com.buession.redis.core.command.args.XAddArgument; +import com.buession.redis.core.internal.convert.lettuce.params.StreamEntryIdConverter; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.XAddArgs; +import redis.clients.jedis.StreamEntryID; + +import java.util.Optional; + +/** + * Lettuce {@link XAddArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceXAddArgs extends XAddArgs { + + /** + * 构造函数 + */ + public LettuceXAddArgs() { + super(); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + */ + public LettuceXAddArgs(final String id) { + super(); + id(id); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + */ + public LettuceXAddArgs(final byte[] id) { + super(); + id(id); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + */ + public LettuceXAddArgs(final StreamEntryId id) { + this(id.toString()); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + */ + public LettuceXAddArgs(final String id, final MaxLenMinId maxLenMinId) { + this(id); + maxLenMinId(this, maxLenMinId); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + */ + public LettuceXAddArgs(final byte[] id, final MaxLenMinId maxLenMinId) { + this(id); + maxLenMinId(this, maxLenMinId); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + */ + public LettuceXAddArgs(final StreamEntryId id, final MaxLenMinId maxLenMinId) { + this(id); + maxLenMinId(this, maxLenMinId); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param noMkStream + * - + */ + public LettuceXAddArgs(final String id, final boolean noMkStream) { + this(id); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param noMkStream + * - + */ + public LettuceXAddArgs(final byte[] id, final boolean noMkStream) { + this(id); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param noMkStream + * - + */ + public LettuceXAddArgs(final StreamEntryId id, final boolean noMkStream) { + this(id); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param limit + * - + */ + public LettuceXAddArgs(final String id, final Long limit) { + this(id); + Optional.ofNullable(limit).ifPresent(this::limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param limit + * - + */ + public LettuceXAddArgs(final byte[] id, final long limit) { + this(id); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param limit + * - + */ + public LettuceXAddArgs(final StreamEntryId id, final long limit) { + this(id); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param noMkStream + * - + */ + public LettuceXAddArgs(final String id, final MaxLenMinId maxLenMinId, final boolean noMkStream) { + this(id, maxLenMinId); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param noMkStream + * - + */ + public LettuceXAddArgs(final byte[] id, final MaxLenMinId maxLenMinId, final boolean noMkStream) { + this(id, maxLenMinId); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param noMkStream + * - + */ + public LettuceXAddArgs(final StreamEntryId id, final MaxLenMinId maxLenMinId, final boolean noMkStream) { + this(id, maxLenMinId); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param limit + * - + */ + public LettuceXAddArgs(final String id, final MaxLenMinId maxLenMinId, final long limit) { + this(id, maxLenMinId); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param limit + * - + */ + public LettuceXAddArgs(final byte[] id, final MaxLenMinId maxLenMinId, final long limit) { + this(id, maxLenMinId); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param limit + * - + */ + public LettuceXAddArgs(final StreamEntryId id, final MaxLenMinId maxLenMinId, final long limit) { + this(id, maxLenMinId); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param noMkStream + * - + * @param limit + * - + */ + public LettuceXAddArgs(final String id, final MaxLenMinId maxLenMinId, final boolean noMkStream, + final long limit) { + this(id, maxLenMinId, noMkStream); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param noMkStream + * - + * @param limit + * - + */ + public LettuceXAddArgs(final byte[] id, final MaxLenMinId maxLenMinId, final boolean noMkStream, + final long limit) { + this(id, maxLenMinId, noMkStream); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param noMkStream + * - + * @param limit + * - + */ + public LettuceXAddArgs(final StreamEntryId id, final MaxLenMinId maxLenMinId, final boolean noMkStream, + final long limit) { + this(id, maxLenMinId, noMkStream); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + */ + public LettuceXAddArgs(final String id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming) { + this(id); + maxLenMinId(this, maxLenMinId, approximateExactTrimming); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + */ + public LettuceXAddArgs(final byte[] id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming) { + this(id); + maxLenMinId(this, maxLenMinId, approximateExactTrimming); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + */ + public LettuceXAddArgs(final StreamEntryId id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming) { + this(id); + maxLenMinId(this, maxLenMinId, approximateExactTrimming); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + */ + public LettuceXAddArgs(final String id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final boolean noMkStream) { + this(id, maxLenMinId, approximateExactTrimming); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + */ + public LettuceXAddArgs(final byte[] id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final boolean noMkStream) { + this(id, maxLenMinId, approximateExactTrimming); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + */ + public LettuceXAddArgs(final StreamEntryId id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final boolean noMkStream) { + this(id, maxLenMinId, approximateExactTrimming); + noMkStream(this, noMkStream); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param limit + * - + */ + public LettuceXAddArgs(final String id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final long limit) { + this(id, maxLenMinId, approximateExactTrimming); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param limit + * - + */ + public LettuceXAddArgs(final byte[] id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final long limit) { + this(id, maxLenMinId, approximateExactTrimming); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param limit + * - + */ + public LettuceXAddArgs(final StreamEntryId id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final long limit) { + this(id, maxLenMinId, approximateExactTrimming); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + * @param limit + * - + */ + public LettuceXAddArgs(final String id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final boolean noMkStream, + final long limit) { + this(id, maxLenMinId, approximateExactTrimming, noMkStream); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + * @param limit + * - + */ + public LettuceXAddArgs(final byte[] id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final boolean noMkStream, + final long limit) { + this(id, maxLenMinId, approximateExactTrimming, noMkStream); + limit(limit); + } + + /** + * 构造函数 + * + * @param id + * Stream Id + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param noMkStream + * - + * @param limit + * - + */ + public LettuceXAddArgs(final StreamEntryId id, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming, final boolean noMkStream, + final long limit) { + this(id, maxLenMinId, approximateExactTrimming, noMkStream); + limit(limit); + } + + public LettuceXAddArgs id(final StreamEntryId id) { + if(id != null){ + id(id.toString()); + } + + return this; + } + + public LettuceXAddArgs id(byte[] id) { + if(id != null){ + id(SafeEncoder.encode(id)); + } + + return this; + } + + /** + * 从 {@link XAddArgument} 创建 {@link XAddArgs} 实例 + * + * @param xAddArgument + * {@link XAddArgument} + * + * @return {@link LettuceXAddArgs} 实例 + */ + public static LettuceXAddArgs from(final XAddArgument xAddArgument) { + final LettuceXAddArgs xAddArgs = new LettuceXAddArgs(); + + if(xAddArgument != null){ + maxLenMinId(xAddArgs, xAddArgument.getMaxLenMinId()); + noMkStream(xAddArgs, xAddArgument.getNoMkStream()); + Optional.ofNullable(xAddArgument.getLimit()).ifPresent(xAddArgs::limit); + } + + return xAddArgs; + } + + private static void maxLenMinId(final LettuceXAddArgs xAddArgs, final MaxLenMinId maxLenMinId) { + if(maxLenMinId != null){ + if(maxLenMinId instanceof MaxLenMinId.MaxLen){ + xAddArgs.maxlen(((MaxLenMinId.MaxLen) maxLenMinId).getValue()); + }else if(maxLenMinId instanceof MaxLenMinId.MinId){ + xAddArgs.minId(((MaxLenMinId.MinId) maxLenMinId).getValue().toString()); + } + } + } + + private static void maxLenMinId(final LettuceXAddArgs xAddArgs, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming) { + maxLenMinId(xAddArgs, maxLenMinId); + if(maxLenMinId != null){ + if(approximateExactTrimming == ApproximateExactTrimming.APPROXIMATE){ + xAddArgs.approximateTrimming(); + }else if(approximateExactTrimming == ApproximateExactTrimming.EXACT){ + xAddArgs.exactTrimming(); + } + } + } + + private static void noMkStream(final LettuceXAddArgs xAddArgs, final Boolean noMkStream) { + if(Boolean.TRUE.equals(noMkStream)){ + xAddArgs.nomkstream(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXClaimArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXClaimArgs.java new file mode 100644 index 000000000..75718b0f6 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXClaimArgs.java @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.command.args.XClaimArgument; +import io.lettuce.core.XClaimArgs; + +import java.util.Optional; + +/** + * Lettuce {@link XClaimArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceXClaimArgs extends XClaimArgs { + + /** + * 构造函数 + */ + public LettuceXClaimArgs() { + super(); + } + + /** + * 构造函数 + * + * @param idleType + * 设置过期时间方式 + * @param expires + * 过期时间 + */ + public LettuceXClaimArgs(final XClaimArgument.IdleType idleType, final long expires) { + super(); + idleTime(this, idleType, expires); + } + + /** + * 构造函数 + * + * @param retryCount + * 重试次数 + */ + public LettuceXClaimArgs(final int retryCount) { + super(); + retryCount(retryCount); + } + + /** + * 构造函数 + * + * @param force + * 是否强制 + */ + public LettuceXClaimArgs(final boolean force) { + super(); + force(this, force); + } + + /** + * 构造函数 + * + * @param idleType + * 设置过期时间方式 + * @param expires + * 过期时间 + * @param retryCount + * 重试次数 + */ + public LettuceXClaimArgs(final XClaimArgument.IdleType idleType, final long expires, final int retryCount) { + this(idleType, expires); + retryCount(retryCount); + } + + /** + * 构造函数 + * + * @param idleType + * 设置过期时间方式 + * @param expires + * 过期时间 + * @param force + * 是否强制 + */ + public LettuceXClaimArgs(final XClaimArgument.IdleType idleType, final long expires, final boolean force) { + this(idleType, expires); + force(this, force); + } + + /** + * 构造函数 + * + * @param idleType + * 设置过期时间方式 + * @param expires + * 过期时间 + * @param retryCount + * 重试次数 + * @param force + * 是否强制 + */ + public LettuceXClaimArgs(final XClaimArgument.IdleType idleType, final long expires, final int retryCount, + final boolean force) { + this(idleType, expires, retryCount); + force(this, force); + } + + /** + * 从 {@link XClaimArgument} 创建 {@link XClaimArgs} 实例 + * + * @param xClaimArgument + * {@link XClaimArgument} + * + * @return {@link LettuceXClaimArgs} 实例 + */ + public static LettuceXClaimArgs from(final XClaimArgument xClaimArgument) { + final LettuceXClaimArgs xClaimArgs = new LettuceXClaimArgs(); + + idleTime(xClaimArgs, xClaimArgument.getIdleType(), xClaimArgument.getIdleTime()); + Optional.ofNullable(xClaimArgument.getRetryCount()).ifPresent(xClaimArgs::retryCount); + force(xClaimArgs, xClaimArgument.isForce()); + + return xClaimArgs; + } + + private static void idleTime(final LettuceXClaimArgs xClaimArgs, final XClaimArgument.IdleType idleType, + final Long idleTime) { + if(idleType != null && idleTime != null){ + switch(idleType){ + case IDLE: + xClaimArgs.idle(idleTime); + break; + case UNIX_TIME: + xClaimArgs.time(idleTime); + break; + default: + break; + } + } + } + + private static void force(final LettuceXClaimArgs xClaimArgs, final Boolean force) { + if(Boolean.TRUE.equals(force)){ + xClaimArgs.force(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXGroupCreateArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXGroupCreateArgs.java new file mode 100644 index 000000000..6c402282a --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXGroupCreateArgs.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import io.lettuce.core.XGroupCreateArgs; + +/** + * Lettuce {@link XGroupCreateArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceXGroupCreateArgs extends XGroupCreateArgs { + + /** + * 构造函数 + */ + public LettuceXGroupCreateArgs() { + super(); + } + + /** + * 构造函数 + * + * @param mkstream + * - + */ + public LettuceXGroupCreateArgs(final boolean mkstream) { + super(); + mkstream(mkstream); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXPendingArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXPendingArgs.java new file mode 100644 index 000000000..741b5a5bc --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXPendingArgs.java @@ -0,0 +1,451 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.Consumer; +import io.lettuce.core.Limit; +import io.lettuce.core.Range; +import io.lettuce.core.XPendingArgs; + +/** + * Lettuce {@link XPendingArgs} 扩展 + * + * @param + * 类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceXPendingArgs extends XPendingArgs { + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + */ + public LettuceXPendingArgs(final String start, final String end, final int count) { + super(); + range(Range.create(start, end)); + count(count); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + */ + public LettuceXPendingArgs(final byte[] start, final byte[] end, final int count) { + this(SafeEncoder.encode(start), SafeEncoder.encode(end), count); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + */ + public LettuceXPendingArgs(final StreamEntryId start, final StreamEntryId end, final int count) { + this(start.toString(), end.toString(), count); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + */ + public LettuceXPendingArgs(final String start, final String end, final int count, final long idle) { + this(start, end, count); + idle(idle); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + */ + public LettuceXPendingArgs(final byte[] start, final byte[] end, final int count, final long idle) { + this(start, end, count); + idle(idle); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + */ + public LettuceXPendingArgs(final StreamEntryId start, final StreamEntryId end, final int count, final long idle) { + this(start, end, count); + idle(idle); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param groupName + * - + * @param consumerName + * - + */ + public LettuceXPendingArgs(final String start, final String end, final int count, + final T groupName, final T consumerName) { + this(start, end, count); + consumer(groupName, consumerName); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param groupName + * - + * @param consumerName + * - + */ + public LettuceXPendingArgs(final byte[] start, final byte[] end, final int count, final T groupName, + final T consumerName) { + this(start, end, count); + consumer(groupName, consumerName); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param groupName + * - + * @param consumerName + * - + */ + public LettuceXPendingArgs(final StreamEntryId start, final StreamEntryId end, final int count, final T groupName, + final T consumerName) { + this(start, end, count); + consumer(groupName, consumerName); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param consumer + * - + */ + public LettuceXPendingArgs(final String start, final String end, final int count, final Consumer consumer) { + this(start, end, count); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param consumer + * - + */ + public LettuceXPendingArgs(final byte[] start, final byte[] end, final int count, final Consumer consumer) { + this(start, end, count); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param consumer + * - + */ + public LettuceXPendingArgs(final StreamEntryId start, final StreamEntryId end, final int count, + final Consumer consumer) { + this(start, end, count); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + * @param groupName + * - + * @param consumerName + * - + */ + public LettuceXPendingArgs(final String start, final String end, final int count, final long idle, + final T groupName, final T consumerName) { + this(start, end, count, idle); + consumer(groupName, consumerName); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + * @param groupName + * - + * @param consumerName + * - + */ + public LettuceXPendingArgs(final byte[] start, final byte[] end, final int count, final long idle, + final T groupName, final T consumerName) { + this(start, end, count, idle); + consumer(groupName, consumerName); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + * @param groupName + * - + * @param consumerName + * - + */ + public LettuceXPendingArgs(final StreamEntryId start, final StreamEntryId end, final int count, final long idle, + final T groupName, final T consumerName) { + this(start, end, count, idle); + consumer(groupName, consumerName); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + * @param consumer + * - + */ + public LettuceXPendingArgs(final String start, final String end, final int count, final long idle, + final Consumer consumer) { + this(start, end, count, idle); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + * @param consumer + * - + */ + public LettuceXPendingArgs(final byte[] start, final byte[] end, final int count, final long idle, + final Consumer consumer) { + this(start, end, count, idle); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param start + * - + * @param end + * - + * @param count + * 返回数量 + * @param idle + * - + * @param consumer + * - + */ + public LettuceXPendingArgs(final StreamEntryId start, final StreamEntryId end, final int count, final long idle, + final Consumer consumer) { + this(start, end, count, idle); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param idle + * - + */ + public LettuceXPendingArgs(final long idle) { + super(); + idle(idle); + } + + /** + * 构造函数 + * + * @param groupName + * - + * @param consumerName + * - + */ + public LettuceXPendingArgs(final T groupName, final T consumerName) { + super(); + consumer(groupName, consumerName); + } + + /** + * 构造函数 + * + * @param consumer + * - + */ + public LettuceXPendingArgs(final Consumer consumer) { + super(); + consumer(consumer); + } + + /** + * 构造函数 + * + * @param idle + * - + * @param groupName + * - + * @param consumerName + * - + */ + public LettuceXPendingArgs(final long idle, final T groupName, final T consumerName) { + this(idle); + consumer(groupName, consumerName); + } + + /** + * 构造函数 + * + * @param idle + * 返回数量 + * @param consumer + * - + */ + public LettuceXPendingArgs(final long idle, final Consumer consumer) { + this(idle); + consumer(consumer); + } + + public LettuceXPendingArgs consumer(final T groupName, final T consumerName) { + consumer(Consumer.from(groupName, consumerName)); + return this; + } + + public LettuceXPendingArgs count(final int count) { + limit(Limit.from(count)); + return this; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXReadArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXReadArgs.java new file mode 100644 index 000000000..fcf68ba68 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXReadArgs.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.command.args.XReadArgument; +import io.lettuce.core.XReadArgs; + +import java.util.Optional; + +/** + * Lettuce {@link XReadArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceXReadArgs extends XReadArgs { + + /** + * 构造函数 + */ + public LettuceXReadArgs() { + super(); + } + + /** + * 构造函数 + * + * @param count + * 返回数量 + */ + public LettuceXReadArgs(final int count) { + super(); + count(count); + } + + /** + * 构造函数 + * + * @param count + * 返回数量 + * @param block + * 阻塞时间 + */ + public LettuceXReadArgs(final int count, final int block) { + this(count); + block(block); + } + + @Override + public LettuceXReadArgs noack(boolean noAck) { + return this; + } + + /** + * 从 {@link XReadArgument} 创建 {@link XReadArgs} 实例 + * + * @param xReadArgument + * {@link XReadArgument} + * + * @return {@link LettuceXReadArgs} 实例 + */ + public static LettuceXReadArgs from(final XReadArgument xReadArgument) { + final LettuceXReadArgs xReadArgs = new LettuceXReadArgs(); + + Optional.ofNullable(xReadArgument.getCount()).ifPresent(xReadArgs::count); + Optional.ofNullable(xReadArgument.getBlock()).ifPresent(xReadArgs::block); + + return xReadArgs; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXReadGroupArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXReadGroupArgs.java new file mode 100644 index 000000000..c039588a4 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXReadGroupArgs.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.command.args.XReadGroupArgument; +import io.lettuce.core.XReadArgs; + +import java.util.Optional; + +/** + * Lettuce {@link XReadArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceXReadGroupArgs extends XReadArgs { + + /** + * 构造函数 + */ + public LettuceXReadGroupArgs() { + super(); + } + + /** + * 构造函数 + * + * @param count + * 返回数量 + */ + public LettuceXReadGroupArgs(final int count) { + super(); + count(count); + } + + /** + * 构造函数 + * + * @param count + * 返回数量 + * @param block + * 阻塞时间 + */ + public LettuceXReadGroupArgs(final int count, final int block) { + this(count); + block(block); + } + + /** + * 构造函数 + * + * @param noAck + * - + */ + public LettuceXReadGroupArgs(final boolean noAck) { + super(); + noack(noAck); + } + + /** + * 构造函数 + * + * @param noAck + * - + * @param count + * 返回数量 + */ + public LettuceXReadGroupArgs(final boolean noAck, final int count) { + this(count); + noack(noAck); + } + + /** + * 构造函数 + * + * @param noAck + * - + * @param count + * 返回数量 + * @param block + * 阻塞时间 + */ + public LettuceXReadGroupArgs(final boolean noAck, final int count, final int block) { + this(block, count); + noack(noAck); + } + + /** + * 从 {@link XReadGroupArgument} 创建 {@link XReadArgs} 实例 + * + * @param xReadArgument + * {@link XReadGroupArgument} + * + * @return {@link LettuceXReadGroupArgs} 实例 + */ + public static LettuceXReadGroupArgs from(final XReadGroupArgument xReadArgument) { + final LettuceXReadGroupArgs xReadArgs = new LettuceXReadGroupArgs(); + + Optional.ofNullable(xReadArgument.getCount()).ifPresent(xReadArgs::count); + Optional.ofNullable(xReadArgument.getBlock()).ifPresent(xReadArgs::block); + Optional.ofNullable(xReadArgument.isNoAck()).ifPresent(xReadArgs::noack); + + return xReadArgs; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXTrimArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXTrimArgs.java new file mode 100644 index 000000000..aa1fda698 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceXTrimArgs.java @@ -0,0 +1,152 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.command.args.ApproximateExactTrimming; +import com.buession.redis.core.command.args.MaxLenMinId; +import com.buession.redis.core.command.args.XTrimArgument; +import io.lettuce.core.XTrimArgs; + +import java.util.Optional; + +/** + * Lettuce {@link XTrimArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceXTrimArgs extends XTrimArgs { + + /** + * 构造函数 + */ + public LettuceXTrimArgs() { + super(); + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + */ + public LettuceXTrimArgs(final MaxLenMinId maxLenMinId) { + super(); + maxLenMinId(this, maxLenMinId); + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param limit + * - + */ + public LettuceXTrimArgs(final MaxLenMinId maxLenMinId, final long limit) { + this(maxLenMinId); + limit(limit); + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + */ + public LettuceXTrimArgs(final MaxLenMinId maxLenMinId, final ApproximateExactTrimming approximateExactTrimming) { + super(); + maxLenMinId(this, maxLenMinId, approximateExactTrimming); + } + + /** + * 构造函数 + * + * @param maxLenMinId + * - + * @param approximateExactTrimming + * - + * @param limit + * - + */ + public LettuceXTrimArgs(final MaxLenMinId maxLenMinId, final ApproximateExactTrimming approximateExactTrimming, + final long limit) { + this(maxLenMinId, approximateExactTrimming); + limit(limit); + } + + /** + * 构造函数 + * + * @param limit + * - + */ + public LettuceXTrimArgs(final long limit) { + super(); + limit(limit); + } + + /** + * 从 {@link XTrimArgument} 创建 {@link XTrimArgs} 实例 + * + * @param xTrimArgument + * {@link XTrimArgument} + * + * @return {@link LettuceXTrimArgs} 实例 + */ + public static LettuceXTrimArgs from(final XTrimArgument xTrimArgument) { + final LettuceXTrimArgs xTrimArgs = new LettuceXTrimArgs(); + + maxLenMinId(xTrimArgs, xTrimArgument.getMaxLenMinId()); + Optional.ofNullable(xTrimArgument.getLimit()).ifPresent(xTrimArgs::limit); + + return xTrimArgs; + } + + private static void maxLenMinId(final LettuceXTrimArgs xTrimArgs, final MaxLenMinId maxLenMinId) { + if(maxLenMinId != null){ + if(maxLenMinId instanceof MaxLenMinId.MaxLen){ + xTrimArgs.maxlen(((MaxLenMinId.MaxLen) maxLenMinId).getValue()); + }else if(maxLenMinId instanceof MaxLenMinId.MinId){ + xTrimArgs.minId(((MaxLenMinId.MinId) maxLenMinId).getValue().toString()); + } + } + } + + private static void maxLenMinId(final LettuceXTrimArgs xTrimArgs, final MaxLenMinId maxLenMinId, + final ApproximateExactTrimming approximateExactTrimming) { + maxLenMinId(xTrimArgs, maxLenMinId); + if(maxLenMinId != null){ + if(approximateExactTrimming == ApproximateExactTrimming.APPROXIMATE){ + xTrimArgs.approximateTrimming(); + }else if(approximateExactTrimming == ApproximateExactTrimming.EXACT){ + xTrimArgs.exactTrimming(); + } + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceZAddArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceZAddArgs.java new file mode 100644 index 000000000..04a1ccd94 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceZAddArgs.java @@ -0,0 +1,169 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.GtLt; +import com.buession.redis.core.NxXx; +import io.lettuce.core.ZAddArgs; + +/** + * Lettuce {@link ZAddArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceZAddArgs extends ZAddArgs { + + /** + * 构造函数 + */ + public LettuceZAddArgs() { + super(); + } + + /** + * 构造函数 + * + * @param nxXx + * 更新成员方式 + */ + public LettuceZAddArgs(final NxXx nxXx) { + super(); + if(nxXx != null){ + switch(nxXx){ + case NX: + nx(); + break; + case XX: + xx(); + break; + default: + break; + } + } + } + + /** + * 构造函数 + * + * @param gtLt + * {@link GtLt} + */ + public LettuceZAddArgs(final GtLt gtLt) { + super(); + gtLt(gtLt); + } + + /** + * 构造函数 + * + * @param ch + * 是否返回变更成员的数量 + */ + public LettuceZAddArgs(final boolean ch) { + super(); + ch(ch); + } + + /** + * 构造函数 + * + * @param nxXx + * 更新成员方式 + * @param gtLt + * 更新新的分值方式 + */ + public LettuceZAddArgs(final NxXx nxXx, final GtLt gtLt) { + this(nxXx); + gtLt(gtLt); + } + + /** + * 构造函数 + * + * @param nxXx + * 更新成员方式 + * @param ch + * 是否返回变更成员的数量 + */ + public LettuceZAddArgs(final NxXx nxXx, final boolean ch) { + this(nxXx); + ch(ch); + } + + /** + * 构造函数 + * + * @param gtLt + * 更新新的分值方式 + * @param ch + * 是否返回变更成员的数量 + */ + public LettuceZAddArgs(final GtLt gtLt, final boolean ch) { + this(gtLt); + ch(ch); + } + + /** + * 构造函数 + * + * @param nxXx + * 更新成员方式 + * @param gtLt + * 更新新的分值方式 + * @param ch + * 是否返回变更成员的数量 + */ + public LettuceZAddArgs(final NxXx nxXx, final GtLt gtLt, final boolean ch) { + this(nxXx, gtLt); + ch(ch); + } + + /** + * 更新新的分值方式 + * + * @param gtLt + * 更新新的分值方式 + */ + private void gtLt(final GtLt gtLt) { + if(gtLt != null){ + switch(gtLt){ + case GT: + break; + case LT: + break; + default: + break; + } + } + } + + private void ch(boolean ch) { + if(ch){ + ch(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceZStoreArgs.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceZStoreArgs.java new file mode 100644 index 000000000..458468277 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/LettuceZStoreArgs.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import io.lettuce.core.ZStoreArgs; +import redis.clients.jedis.params.ZParams; + +/** + * Lettuce {@link ZStoreArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceZStoreArgs extends ZStoreArgs { + + /** + * 构造函数 + */ + public LettuceZStoreArgs() { + super(); + } + + /** + * 构造函数 + * + * @param aggregate + * {@link ZParams.Aggregate} + */ + public LettuceZStoreArgs(final com.buession.redis.core.Aggregate aggregate) { + super(); + if(aggregate != null){ + switch(aggregate){ + case MIN: + min(); + break; + case MAX: + max(); + break; + case SUM: + sum(); + break; + default: + break; + } + } + } + + /** + * 构造函数 + * + * @param weights + * 权重 + */ + public LettuceZStoreArgs(final double... weights) { + super(); + weights(weights); + } + + /** + * 构造函数 + * + * @param aggregate + * {@link ZParams.Aggregate} + * @param weights + * 权重 + */ + public LettuceZStoreArgs(final com.buession.redis.core.Aggregate aggregate, final double... weights) { + this(aggregate); + weights(weights); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/package-info.java new file mode 100644 index 000000000..501fa66ee --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.core.internal.lettuce; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/utils/LMoveArgsUtils.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/utils/LMoveArgsUtils.java new file mode 100644 index 000000000..95cee819e --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/utils/LMoveArgsUtils.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce.utils; + +import com.buession.redis.core.Direction; +import io.lettuce.core.LMoveArgs; + +/** + * Lettuce {@link LMoveArgs} 工具类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LMoveArgsUtils { + + protected LMoveArgsUtils() { + + } + + public static LMoveArgs fromDirection(final Direction from, final Direction to) { + if(Direction.LEFT == from){ + if(Direction.LEFT == to){ + return LMoveArgs.Builder.leftLeft(); + }else if(Direction.RIGHT == to){ + return LMoveArgs.Builder.leftRight(); + } + }else if(Direction.RIGHT == from){ + if(Direction.LEFT == to){ + return LMoveArgs.Builder.rightLeft(); + }else if(Direction.RIGHT == to){ + return LMoveArgs.Builder.rightRight(); + } + } + + return null; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/utils/ScoredValueUtils.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/utils/ScoredValueUtils.java new file mode 100644 index 000000000..ab7bcfa30 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/utils/ScoredValueUtils.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce.utils; + +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ScoredValue; + +import java.util.Map; + +/** + * Lettuce {@link ScoredValue} 工具类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class ScoredValueUtils { + + protected ScoredValueUtils() { + + } + + @SuppressWarnings({"unchecked"}) + public static ScoredValue[] fromStringMap(final Map values) { + if(values == null){ + return null; + }else{ + final ScoredValue[] result = new ScoredValue[values.size()]; + int i = 0; + + for(Map.Entry e : values.entrySet()){ + result[i++] = e.getValue() == null ? ScoredValue.empty() : ScoredValue.just(e.getValue(), + SafeEncoder.encode(e.getKey())); + } + + return result; + } + } + + @SuppressWarnings({"unchecked"}) + public static ScoredValue[] fromBinaryMap(final Map values) { + if(values == null){ + return null; + }else{ + final ScoredValue[] result = new ScoredValue[values.size()]; + int i = 0; + + for(Map.Entry e : values.entrySet()){ + result[i++] = e.getValue() == null ? ScoredValue.empty() : ScoredValue.just(e.getValue(), + e.getKey()); + } + + return result; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/utils/StreamOffsetUtils.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/utils/StreamOffsetUtils.java new file mode 100644 index 000000000..b7d2c039d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/utils/StreamOffsetUtils.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce.utils; + +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.XReadArgs; + +import java.util.Map; + +/** + * Lettuce {@link XReadArgs.StreamOffset} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class StreamOffsetUtils { + + protected StreamOffsetUtils() { + + } + + @SuppressWarnings({"unchecked"}) + public static XReadArgs.StreamOffset[] fromStringMap(final Map streams) { + if(streams == null){ + return null; + }else{ + final XReadArgs.StreamOffset[] result = new XReadArgs.StreamOffset[streams.size()]; + int i = 0; + + for(Map.Entry e : streams.entrySet()){ + result[i++] = XReadArgs.StreamOffset.from(SafeEncoder.encode(e.getKey()), + e.getValue().toString()); + } + + return result; + } + } + + @SuppressWarnings({"unchecked"}) + public static XReadArgs.StreamOffset[] fromBinaryMap(final Map streams) { + if(streams == null){ + return null; + }else{ + final XReadArgs.StreamOffset[] result = new XReadArgs.StreamOffset[streams.size()]; + int i = 0; + + for(Map.Entry e : streams.entrySet()){ + result[i++] = XReadArgs.StreamOffset.from(e.getKey(), e.getValue().toString()); + } + + return result; + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/utils/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/utils/package-info.java new file mode 100644 index 000000000..48b2f2adf --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/internal/lettuce/utils/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.core.internal.lettuce.utils; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/AclOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/AclOperations.java new file mode 100644 index 000000000..e5472b92c --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/AclOperations.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.operations; + +import com.buession.redis.core.AclCategory; +import com.buession.redis.core.command.AclCommands; +import com.buession.redis.core.command.Command; + +import java.util.List; + +/** + * 权限运算 + * + *

详情说明 https://redis.io/docs/latest/commands/acl/

+ * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface AclOperations extends AclCommands, RedisOperations { + + /** + * The command shows all the Redis commands in the specified category + * + *

详情说明 https://redis.io/commands/acl-cat/

+ * + * @param categoryName + * Category Name + * + * @return A list of ACL categories or a list of commands inside a given category + * + * @since 3.0.0 + */ + default List aclCat(final String categoryName) { + return aclCat(AclCategory.from(categoryName)); + } + + /** + * The command shows all the Redis commands in the specified category + * + *

详情说明 https://redis.io/commands/acl-cat/

+ * + * @param categoryName + * Category Name + * + * @return A list of ACL categories or a list of commands inside a given category + * + * @since 3.0.0 + */ + default List aclCat(final byte[] categoryName) { + return aclCat(AclCategory.from(categoryName)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/ClusterOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/ClusterOperations.java new file mode 100644 index 000000000..4a2e5410b --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/ClusterOperations.java @@ -0,0 +1,268 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.operations; + +import com.buession.core.utils.Assert; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.core.BumpEpoch; +import com.buession.redis.core.ClusterFailoverOption; +import com.buession.redis.core.ClusterInfo; +import com.buession.redis.core.ClusterLink; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.ClusterResetOption; +import com.buession.redis.core.ClusterSetSlotOption; +import com.buession.redis.core.ClusterRedisShard; +import com.buession.redis.core.ClusterSlot; +import com.buession.redis.core.RedisNode; +import com.buession.redis.core.SlotRange; +import com.buession.redis.core.command.ClusterCommands; + +import java.util.List; + +/** + * 集群命令 + * + *

详情说明 https://redis.io/docs/latest/commands/?group=cluster

+ * + * @author Yong.Teng + * @since 2.0.0 + */ +public interface ClusterOperations extends ClusterCommands, RedisOperations { + + @Override + default Status asking() { + return execute((client)->client.clusterOperations().asking()); + } + + @Override + default Status clusterAddSlots(final int... slots) { + return execute((client)->client.clusterOperations().clusterAddSlots(slots)); + } + + @Override + default Status clusterAddSlotsRange(final SlotRange... slots) { + return execute((client)->client.clusterOperations().clusterAddSlotsRange(slots)); + } + + @Override + default KeyValue clusterBumpEpoch() { + return execute((client)->client.clusterOperations().clusterBumpEpoch()); + } + + @Override + default Long clusterCountFailureReports(final String nodeId) { + return execute((client)->client.clusterOperations().clusterCountFailureReports(nodeId)); + } + + @Override + default Long clusterCountFailureReports(final byte[] nodeId) { + return execute((client)->client.clusterOperations().clusterCountFailureReports(nodeId)); + } + + @Override + default Long clusterCountKeysInSlot(final int slot) { + return execute((client)->client.clusterOperations().clusterCountKeysInSlot(slot)); + } + + @Override + default Status clusterDelSlots(final int... slots) { + return execute((client)->client.clusterOperations().clusterDelSlots(slots)); + } + + @Override + default Status clusterDelSlotsRange(final SlotRange... slots) { + return execute((client)->client.clusterOperations().clusterDelSlotsRange(slots)); + } + + @Override + default Status clusterFailover(final ClusterFailoverOption clusterFailoverOption) { + return execute((client)->client.clusterOperations().clusterFailover(clusterFailoverOption)); + } + + @Override + default Status clusterFlushSlots() { + return execute((client)->client.clusterOperations().clusterFlushSlots()); + } + + @Override + default Status clusterForget(final String nodeId) { + return execute((client)->client.clusterOperations().clusterForget(nodeId)); + } + + @Override + default Status clusterForget(final byte[] nodeId) { + return execute((client)->client.clusterOperations().clusterForget(nodeId)); + } + + @Override + default List clusterGetKeysInSlot(final int slot, final int count) { + return execute((client)->client.clusterOperations().clusterGetKeysInSlot(slot, count)); + } + + @Override + default ClusterInfo clusterInfo() { + return execute((client)->client.clusterOperations().clusterInfo()); + } + + @Override + default List clusterLinks() { + return execute((client)->client.clusterOperations().clusterLinks()); + } + + @Override + default Status clusterMeet(final String ip, final int port) { + return execute((client)->client.clusterOperations().clusterMeet(ip, port)); + } + + /** + * 用来连接不同的开启集群支持的 Redis 节点,以进入工作集群 + * + *

详情说明 + * http://www.redis.cn/commands/cluster-meet.html

+ * + * @param ip + * Redis 集群节点 IP + * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + default Status clusterMeet(final String ip) { + return clusterMeet(ip, RedisNode.DEFAULT_PORT); + } + + /** + * 用来连接不同的开启集群支持的 Redis 节点,以进入工作集群 + * + *

详情说明 + * http://www.redis.cn/commands/cluster-meet.html

+ * + * @param node + * Redis 集群节点 + * + * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + default Status clusterMeet(final RedisNode node) { + Assert.isNull(node, "Redis cluster node cloud not be null"); + Assert.isBlank(node.getHost(), "Redis cluster host cloud not be null or empty"); + + return clusterMeet(node.getHost(), node.getPort()); + } + + @Override + default String clusterMyId() { + return execute((client)->client.clusterOperations().clusterMyId()); + } + + @Override + default String clusterMyShardId() { + return execute((client)->client.clusterOperations().clusterMyShardId()); + } + + @Override + default List clusterNodes() { + return execute((client)->client.clusterOperations().clusterNodes()); + } + + @Override + default List clusterReplicas(final String nodeId) { + return execute((client)->client.clusterOperations().clusterReplicas(nodeId)); + } + + @Override + default List clusterReplicas(final byte[] nodeId) { + return execute((client)->client.clusterOperations().clusterReplicas(nodeId)); + } + + @Override + default Status clusterReplicate(final String nodeId) { + return execute((client)->client.clusterOperations().clusterReplicate(nodeId)); + } + + @Override + default Status clusterReplicate(final byte[] nodeId) { + return execute((client)->client.clusterOperations().clusterReplicate(nodeId)); + } + + @Override + default Status clusterReset() { + return execute((client)->client.clusterOperations().clusterReset()); + } + + @Override + default Status clusterReset(final ClusterResetOption clusterResetOption) { + return execute((client)->client.clusterOperations().clusterReset(clusterResetOption)); + } + + @Override + default Status clusterSaveConfig() { + return execute((client)->client.clusterOperations().clusterSaveConfig()); + } + + @Override + default Status clusterSetConfigEpoch(final long configEpoch) { + return execute((client)->client.clusterOperations().clusterSetConfigEpoch(configEpoch)); + } + + @Override + default Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId) { + return execute((client)->client.clusterOperations().clusterSetSlot(slot, setSlotOption, nodeId)); + } + + @Override + default Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final byte[] nodeId) { + return execute((client)->client.clusterOperations().clusterSetSlot(slot, setSlotOption, nodeId)); + } + + @Override + default List clusterShards() { + return execute((client)->client.clusterOperations().clusterShards()); + } + + @Override + default List clusterSlaves(final String nodeId) { + return execute((client)->client.clusterOperations().clusterSlaves(nodeId)); + } + + @Override + default List clusterSlaves(final byte[] nodeId) { + return execute((client)->client.clusterOperations().clusterSlaves(nodeId)); + } + + @Override + default List clusterSlots() { + return execute((client)->client.clusterOperations().clusterSlots()); + } + + @Override + default Status readOnly() { + return execute((client)->client.clusterOperations().readOnly()); + } + + @Override + default Status readWrite() { + return execute((client)->client.clusterOperations().readWrite()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/ConnectionOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/ConnectionOperations.java new file mode 100644 index 000000000..e2fc370a1 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/ConnectionOperations.java @@ -0,0 +1,249 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.operations; + +import com.buession.core.utils.Assert; +import com.buession.lang.Status; +import com.buession.redis.core.Client; +import com.buession.redis.core.ClientAttributeOption; +import com.buession.redis.core.ClientPauseMode; +import com.buession.redis.core.ClientReply; +import com.buession.redis.core.ClientTrackingInfo; +import com.buession.redis.core.ClientType; +import com.buession.redis.core.ClientUnblockType; +import com.buession.redis.core.RedisNode; +import com.buession.redis.core.RedisServer; +import com.buession.redis.core.command.ConnectionCommands; +import com.buession.redis.core.command.args.ClientKillArgument; +import com.buession.redis.core.command.args.ClientTracking; +import com.buession.redis.core.command.args.HelloArgument; + +import java.util.List; + +/** + * 连接相关命令 + * + *

详情说明 http://www.redis.cn/commands.html#connection

+ * + * @author Yong.Teng + */ +public interface ConnectionOperations extends ConnectionCommands, RedisOperations { + + @Override + default Status auth(final String user, final String password) { + return execute((client)->client.connectionOperations().auth(user, password)); + } + + @Override + default Status auth(final byte[] user, final byte[] password) { + return execute((client)->client.connectionOperations().auth(user, password)); + } + + @Override + default Status auth(final String password) { + return execute((client)->client.connectionOperations().auth(password)); + } + + @Override + default Status auth(final byte[] password) { + return execute((client)->client.connectionOperations().auth(password)); + } + + @Override + default Status clientCaching() { + return execute((client)->client.connectionOperations().clientCaching()); + } + + @Override + default Status clientCaching(final boolean isYes) { + return execute((client)->client.connectionOperations().clientCaching(isYes)); + } + + @Override + default String clientGetName() { + return execute((client)->client.connectionOperations().clientGetName()); + } + + @Override + default Integer clientGetRedir() { + return execute((client)->client.connectionOperations().clientGetRedir()); + } + + @Override + default Long clientId() { + return execute((client)->client.connectionOperations().clientId()); + } + + @Override + default Client clientInfo() { + return execute((client)->client.connectionOperations().clientInfo()); + } + + @Override + default Status clientKill(final String host, final int port) { + return execute((client)->client.connectionOperations().clientKill(host, port)); + } + + @Override + default Long clientKill(final ClientKillArgument... clientKillArguments) { + return execute((client)->client.connectionOperations().clientKill(clientKillArguments)); + } + + /** + * 关闭地址为 host:port 的客户端 + * + *

详情说明 http://redisdoc.com/client_and_server/client_kill.html

+ * + * @param client + * 客户端地址 + * + * @return 当指定的客户端存在,且被成功关闭时,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + default Status clientKill(final RedisNode client) { + Assert.isNull(client, "Redis client cloud not be null."); + return clientKill(client.getHost(), client.getPort()); + } + + @Override + default List clientList() { + return execute((client)->client.connectionOperations().clientList()); + } + + @Override + default List clientList(final ClientType clientType) { + return execute((client)->client.connectionOperations().clientList(clientType)); + } + + @Override + default List clientList(final long... clientIds) { + return execute((client)->client.connectionOperations().clientList(clientIds)); + } + + @Override + default Status clientNoEvict(final boolean on) { + return execute((client)->client.connectionOperations().clientNoEvict(on)); + } + + @Override + default Status clientNoTouch(final boolean on) { + return execute((client)->client.connectionOperations().clientNoTouch(on)); + } + + @Override + default Status clientPause(final int timeout) { + return execute((client)->client.connectionOperations().clientPause(timeout)); + } + + @Override + default Status clientPause(final int timeout, final ClientPauseMode pauseMode) { + return execute((client)->client.connectionOperations().clientPause(timeout, pauseMode)); + } + + @Override + default Status clientReply(final ClientReply option) { + return execute((client)->client.connectionOperations().clientReply(option)); + } + + @Override + default Status clientSetInfo(final ClientAttributeOption clientAttributeOption, String value) { + return execute((client)->client.connectionOperations().clientSetInfo(clientAttributeOption, value)); + } + + @Override + default Status clientSetInfo(final ClientAttributeOption clientAttributeOption, byte[] value) { + return execute((client)->client.connectionOperations().clientSetInfo(clientAttributeOption, value)); + } + + @Override + default Status clientSetName(final String name) { + return execute((client)->client.connectionOperations().clientSetName(name)); + } + + @Override + default Status clientSetName(final byte[] name) { + return execute((client)->client.connectionOperations().clientSetName(name)); + } + + @Override + default Status clientTracking(final ClientTracking clientTracking) { + return execute((client)->client.connectionOperations().clientTracking(clientTracking)); + } + + @Override + default ClientTrackingInfo clientTrackingInfo() { + return execute((client)->client.connectionOperations().clientTrackingInfo()); + } + + @Override + default Status clientUnblock(final int clientId) { + return execute((client)->client.connectionOperations().clientUnblock(clientId)); + } + + @Override + default Status clientUnblock(final int clientId, final ClientUnblockType type) { + return execute((client)->client.connectionOperations().clientUnblock(clientId, type)); + } + + @Override + default Status clientUnPause() { + return execute((client)->client.connectionOperations().clientUnPause()); + } + + @Override + default String echo(final String str) { + return execute((client)->client.connectionOperations().echo(str)); + } + + @Override + default byte[] echo(final byte[] str) { + return execute((client)->client.connectionOperations().echo(str)); + } + + @Override + default RedisServer hello(final HelloArgument helloArgument) { + return execute((client)->client.connectionOperations().hello(helloArgument)); + } + + @Override + default Status ping() { + return execute((client)->client.connectionOperations().ping()); + } + + @Override + default Status quit() { + return execute((client)->client.connectionOperations().quit()); + } + + @Override + default Status reset() { + return execute((client)->client.connectionOperations().reset()); + } + + @Override + default Status select(final int db) { + return execute((client)->client.connectionOperations().select(db)); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/GeoOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/GeoOperations.java new file mode 100644 index 000000000..22ff43772 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/GeoOperations.java @@ -0,0 +1,254 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.operations; + +import com.buession.lang.Geo; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import com.buession.redis.core.command.GeoCommands; +import com.buession.redis.core.command.args.GeoRadiusArgument; + +import java.util.List; + +/** + * 地理位置运算 + * + *

详情说明 https://redis.io/docs/latest/commands/?group=geo

+ * + * @author Yong.Teng + */ +public interface GeoOperations extends GeoCommands, RedisOperations { + + /** + * 将给定的空间元素(经度、纬度、名字)添加到指定的键里面 + * + *

详情说明 http://redisdoc.com/geo/geoadd.html

+ * + * @param key + * Key + * @param member + * 名字 + * @param geo + * 经纬度对象 + * + * @return 新添加到键里面的空间元素数量,不包括那些已经存在但是被更新的元素 + */ + default Long geoAdd(final String key, final String member, final Geo geo) { + return geoAdd(key, member, geo.getLongitude(), geo.getLatitude()); + } + + /** + * 将给定的空间元素(经度、纬度、名字)添加到指定的键里面 + * + *

详情说明 http://redisdoc.com/geo/geoadd.html

+ * + * @param key + * Key + * @param member + * 名字 + * @param geo + * 经纬度对象 + * + * @return 新添加到键里面的空间元素数量,不包括那些已经存在但是被更新的元素 + */ + default Long geoAdd(final byte[] key, final byte[] member, final Geo geo) { + return geoAdd(key, member, geo.getLongitude(), geo.getLatitude()); + } + + /** + * 以给定的经纬度为中心,返回键包含的位置元素当中,与中心的距离不超过给定最大距离的所有位置元素 + * + *

详情说明 http://redisdoc.com/geo/georadius.html

+ * + * @param key + * Key + * @param geo + * 经纬度对象 + * 纬度 + * @param radius + * 范围 + * @param unit + * 距离单位 + * + * @return 位置元素 + */ + default List geoRadius(final String key, final Geo geo, final double radius, final GeoUnit unit) { + return geoRadius(key, geo.getLongitude(), geo.getLatitude(), radius, unit); + } + + /** + * 以给定的经纬度为中心,返回键包含的位置元素当中,与中心的距离不超过给定最大距离的所有位置元素 + * + *

详情说明 http://redisdoc.com/geo/georadius.html

+ * + * @param key + * Key + * @param geo + * 经纬度对象 + * @param radius + * 范围 + * @param unit + * 距离单位 + * + * @return 位置元素 + */ + default List geoRadius(final byte[] key, final Geo geo, final double radius, final GeoUnit unit) { + return geoRadius(key, geo.getLongitude(), geo.getLatitude(), radius, unit); + } + + /** + * 以给定的经纬度为中心,返回键包含的位置元素当中,与中心的距离不超过给定最大距离的所有位置元素 + * + *

详情说明 http://redisdoc.com/geo/georadius.html

+ * + * @param key + * Key + * @param geo + * 经纬度对象 + * @param radius + * 范围 + * @param unit + * 距离单位 + * @param geoRadiusArgument + * GEO 参数 + * + * @return 位置元素 + */ + default List geoRadius(final String key, final Geo geo, final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + return geoRadius(key, geo.getLongitude(), geo.getLatitude(), radius, unit, geoRadiusArgument); + } + + /** + * 以给定的经纬度为中心,返回键包含的位置元素当中,与中心的距离不超过给定最大距离的所有位置元素 + * + *

详情说明 http://redisdoc.com/geo/georadius.html

+ * + * @param key + * KeyG + * @param geo + * 经纬度对象 + * @param radius + * 范围 + * @param unit + * 距离单位 + * @param geoRadiusArgument + * GEO 参数 + * + * @return 位置元素 + */ + default List geoRadius(final byte[] key, final Geo geo, final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + return geoRadius(key, geo.getLongitude(), geo.getLatitude(), radius, unit, geoRadiusArgument); + } + + /** + * Read-only variant of the GEORADIUS command + * + *

详情说明 https://redis.io/commands/georadius_ro/

+ * + * @param key + * Key + * @param geo + * 经纬度对象 + * 纬度 + * @param radius + * 范围 + * @param unit + * 距离单位 + * + * @return 位置元素 + */ + default List geoRadiusRo(final String key, final Geo geo, final double radius, final GeoUnit unit) { + return geoRadiusRo(key, geo.getLongitude(), geo.getLatitude(), radius, unit); + } + + /** + * Read-only variant of the GEORADIUS command + * + *

详情说明 https://redis.io/commands/georadius_ro/

+ * + * @param key + * Key + * @param geo + * 经纬度对象 + * @param radius + * 范围 + * @param unit + * 距离单位 + * + * @return 位置元素 + */ + default List geoRadiusRo(final byte[] key, final Geo geo, final double radius, final GeoUnit unit) { + return geoRadiusRo(key, geo.getLongitude(), geo.getLatitude(), radius, unit); + } + + /** + * Read-only variant of the GEORADIUS command + * + *

详情说明 https://redis.io/commands/georadius_ro/

+ * + * @param key + * Key + * @param geo + * 经纬度对象 + * @param radius + * 范围 + * @param unit + * 距离单位 + * @param geoRadiusArgument + * GEO 参数 + * + * @return 位置元素 + */ + default List geoRadiusRo(final String key, final Geo geo, final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + return geoRadiusRo(key, geo.getLongitude(), geo.getLatitude(), radius, unit, geoRadiusArgument); + } + + /** + * Read-only variant of the GEORADIUS command + * + *

详情说明 https://redis.io/commands/georadius_ro/

+ * + * @param key + * KeyG + * @param geo + * 经纬度对象 + * @param radius + * 范围 + * @param unit + * 距离单位 + * @param geoRadiusArgument + * GEO 参数 + * + * @return 位置元素 + */ + default List geoRadiusRo(final byte[] key, final Geo geo, final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + return geoRadiusRo(key, geo.getLongitude(), geo.getLatitude(), radius, unit, geoRadiusArgument); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/HashOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/HashOperations.java new file mode 100644 index 000000000..f1688c3a0 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/HashOperations.java @@ -0,0 +1,1994 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.operations; + +import com.buession.core.type.TypeReference; +import com.buession.core.utils.Assert; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.HashCommands; + +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * 哈希表运算 + * + *

详情说明 https://redis.io/docs/latest/commands/?group=hash

+ * + * @author Yong.Teng + */ +public interface HashOperations extends HashCommands, RedisOperations { + + /** + * 删除哈希表 key 中的一个或多个指定域 + * + *

详情说明 http://redisdoc.com/hash/hdel.html

+ * + * @param key + * Key + * @param fields + * 一个或多个域 + * + * @return 被成功删除的域的数量 + */ + default Long hDelete(final String key, final String... fields) { + return hDel(key, fields); + } + + /** + * 删除哈希表 key 中的一个或多个指定域 + * + *

详情说明 http://redisdoc.com/hash/hdel.html

+ * + * @param key + * Key + * @param fields + * 一个或多个域 + * + * @return 被成功删除的域的数量 + */ + default Long hDelete(final byte[] key, final byte[]... fields) { + return hDel(key, fields); + } + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hexpireat/

+ * + * @param key + * Key + * @param date + * 过期时间 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + default List hExpireAt(final String key, final Date date, final String... fields) { + Assert.isNull(date, "Expire date could not be null"); + return hExpireAt(key, date.getTime() / 1000L, fields); + } + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hexpireat/

+ * + * @param key + * Key + * @param date + * 过期时间 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + default List hExpireAt(final byte[] key, final Date date, final byte[]... fields) { + Assert.isNull(date, "Expire date could not be null"); + return hExpireAt(key, date.getTime() / 1000L, fields); + } + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hexpireat/

+ * + * @param key + * Key + * @param date + * 过期时间 + * @param expireOption + * 过期选项 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + default List hExpireAt(final String key, final Date date, final ExpireOption expireOption, + final String... fields) { + Assert.isNull(date, "Expire date could not be null"); + return hExpireAt(key, date.getTime() / 1000L, expireOption, fields); + } + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hexpireat/

+ * + * @param key + * Key + * @param date + * 过期时间 + * @param expireOption + * 过期选项 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + default List hExpireAt(final byte[] key, final Date date, final ExpireOption expireOption, + final byte[]... fields) { + Assert.isNull(date, "Expire date could not be null"); + return hExpireAt(key, date.getTime() / 1000L, expireOption, fields); + } + + /** + * Returns the absolute Unix timestamp in seconds since Unix epoch at which the given key's field(s) will expire. + * + *

详情说明 https://redis.io/docs/latest/commands/hexpiretime/

+ * + * @param key + * Key + * @param fields + * 域 + * + * @return The expiration Unix timestamp in seconds; + * -1 if the key exists but has no associated expiration time; + * -2 if the key does not exist; + * + * @since 3.0.0 + */ + default List hExpireTimeAt(final String key, final String... fields) { + List data = hExpireTime(key, fields); + return data == null ? null : data.stream().map((v)->v != null && v > 0 ? new Date(v * 1000) : null) + .collect(Collectors.toList()); + } + + /** + * Returns the absolute Unix timestamp in seconds since Unix epoch at which the given key's field(s) will expire. + * + *

详情说明 https://redis.io/docs/latest/commands/hexpiretime/

+ * + * @param key + * Key + * @param fields + * 域 + * + * @return The expiration Unix timestamp in seconds; + * -1 if the key exists but has no associated expiration time; + * -2 if the key does not exist; + * + * @since 3.0.0 + */ + default List hExpireTimeAt(final byte[] key, final byte[]... fields) { + List data = hExpireTime(key, fields); + return data == null ? null : data.stream().map((v)->v != null && v > 0 ? new Date(v * 1000) : null) + .collect(Collectors.toList()); + } + + /** + * 获取哈希表中给定域的值,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hget.html

+ * + * @param key + * Key + * @param field + * 域 + * @param + * 值类型 + * + * @return 哈希表中给定域的值反序列化后的对象,如果给定域不存在于哈希表中,又或者给定的哈希表并不存在,则返回 null + */ + V hGetObject(final String key, final String field); + + /** + * 获取哈希表中给定域的值,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hget.html

+ * + * @param key + * Key + * @param field + * 域 + * @param + * 值类型 + * + * @return 哈希表中给定域的值反序列化后的对象,如果给定域不存在于哈希表中,又或者给定的哈希表并不存在,则返回 null + */ + V hGetObject(final byte[] key, final byte[] field); + + /** + * 获取哈希表中给定域的值,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hget.html

+ * + * @param key + * Key + * @param field + * 域 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 哈希表中给定域的值反序列化后的对象,如果给定域不存在于哈希表中,又或者给定的哈希表并不存在,则返回 null + */ + V hGetObject(final String key, final String field, final Class clazz); + + /** + * 获取哈希表中给定域的值,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hget.html

+ * + * @param key + * Key + * @param field + * 域 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 哈希表中给定域的值反序列化后的对象,如果给定域不存在于哈希表中,又或者给定的哈希表并不存在,则返回 null + */ + V hGetObject(final byte[] key, final byte[] field, final Class clazz); + + /** + * 获取哈希表中给定域的值,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hget.html

+ * + * @param key + * Key + * @param field + * 域 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 哈希表中给定域的值反序列化后的对象,如果给定域不存在于哈希表中,又或者给定的哈希表并不存在,则返回 null + * + * @see TypeReference + */ + V hGetObject(final String key, final String field, final TypeReference type); + + /** + * 获取哈希表中给定域的值,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hget.html

+ * + * @param key + * Key + * @param field + * 域 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 哈希表中给定域的值反序列化后的对象,如果给定域不存在于哈希表中,又或者给定的哈希表并不存在,则返回 null + * + * @see TypeReference + */ + V hGetObject(final byte[] key, final byte[] field, final TypeReference type); + + /** + * 获取哈希表 key 中,所有的域和值,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hgetall.html

+ * + * @param key + * Key + * @param + * 值类型 + * + * @return 哈希表 key 中,所有的域和值 + */ + Map hGetAllObject(final String key); + + /** + * 获取哈希表 key 中,所有的域和值,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hgetall.html

+ * + * @param key + * Key + * @param + * 值类型 + * + * @return 哈希表 key 中,所有的域和值 + */ + Map hGetAllObject(final byte[] key); + + /** + * 获取哈希表 key 中,所有的域和值,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hgetall.html

+ * + * @param key + * Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 哈希表 key 中,所有的域和值 + */ + Map hGetAllObject(final String key, final Class clazz); + + /** + * 获取哈希表 key 中,所有的域和值,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hgetall.html

+ * + * @param key + * Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 哈希表 key 中,所有的域和值 + */ + Map hGetAllObject(final byte[] key, final Class clazz); + + /** + * 获取哈希表 key 中,所有的域和值,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hgetall.html

+ * + * @param key + * Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 哈希表 key 中,所有的域和值 + * + * @see TypeReference + */ + Map hGetAllObject(final String key, final TypeReference type); + + /** + * 获取哈希表 key 中,所有的域和值,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hgetall.html

+ * + * @param key + * Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 哈希表 key 中,所有的域和值 + * + * @see TypeReference + */ + Map hGetAllObject(final byte[] key, TypeReference type); + + /** + * 获取哈希表 key 中,一个或多个给定域的值,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hmget.html

+ * + * @param key + * Key + * @param fields + * 一个或多个域 + * @param + * 值类型 + * + * @return 一个包含多个给定域的关联值的表,值的排列顺序和给定域参数的请求顺序一样 + */ + List hMGetObject(final String key, final String... fields); + + /** + * 获取哈希表 key 中,一个或多个给定域的值,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hmget.html

+ * + * @param key + * Key + * @param fields + * 一个或多个域 + * @param + * 值类型 + * + * @return 一个包含多个给定域的关联值的表,值的排列顺序和给定域参数的请求顺序一样 + */ + List hMGetObject(final byte[] key, final byte[]... fields); + + /** + * 获取哈希表 key 中,一个或多个给定域的值,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hmget.html

+ * + * @param key + * Key + * @param fields + * 一个或多个域 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 一个包含多个给定域的关联值的表,值的排列顺序和给定域参数的请求顺序一样 + */ + List hMGetObject(final String key, final String[] fields, final Class clazz); + + /** + * 获取哈希表 key 中,一个或多个给定域的值,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hmget.html

+ * + * @param key + * Key + * @param fields + * 一个或多个域 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 一个包含多个给定域的关联值的表,值的排列顺序和给定域参数的请求顺序一样 + */ + List hMGetObject(final byte[] key, final byte[][] fields, final Class clazz); + + /** + * 获取哈希表 key 中,一个或多个给定域的值,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hmget.html

+ * + * @param key + * Key + * @param fields + * 一个或多个域 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 一个包含多个给定域的关联值的表,值的排列顺序和给定域参数的请求顺序一样 + * + * @see TypeReference + */ + List hMGetObject(final String key, final String[] fields, final TypeReference type); + + /** + * 获取哈希表 key 中,一个或多个给定域的值,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hmget.html

+ * + * @param key + * Key + * @param fields + * 一个或多个域 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 一个包含多个给定域的关联值的表,值的排列顺序和给定域参数的请求顺序一样 + * + * @see TypeReference + */ + List hMGetObject(final byte[] key, final byte[][] fields, final TypeReference type); + + /** + * 批量将多个 field => value (域-值)对设置到哈希表 key 中 + * + *

详情说明 http://redisdoc.com/hash/hmset.html

+ * + * @param key + * Key + * @param data + * field => value (域-值)对 + * @param + * 值类型 + * + * @return 执行成功返回 Status.Success,否则返回 Status.FAILURE + * + * @since 3.0.0 + */ + Status hMSet(final String key, final KeyValue... data); + + /** + * 批量将多个 field => value (域-值)对设置到哈希表 key 中 + * + *

详情说明 http://redisdoc.com/hash/hmset.html

+ * + * @param key + * Key + * @param data + * field => value (域-值)对 + * @param + * 值类型 + * + * @return 执行成功返回 Status.Success,否则返回 Status.FAILURE + * + * @since 3.0.0 + */ + Status hMSet(final byte[] key, final KeyValue... data); + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hpexpire/

+ * + * @param key + * Key + * @param date + * 过期时间 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + default List hpExpireAt(final String key, final Date date, final String... fields) { + Assert.isNull(date, "Expire date could not be null"); + return hpExpireAt(key, date.getTime(), fields); + } + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hpexpire/

+ * + * @param key + * Key + * @param date + * 过期时间 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + default List hpExpireAt(final byte[] key, final Date date, final byte[]... fields) { + Assert.isNull(date, "Expire date could not be null"); + return hpExpireAt(key, date.getTime(), fields); + } + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hpexpire/

+ * + * @param key + * Key + * @param date + * 过期时间 + * @param expireOption + * 过期选项 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + default List hpExpireAt(final String key, final Date date, final ExpireOption expireOption, + final String... fields) { + Assert.isNull(date, "Expire date could not be null"); + return hpExpireAt(key, date.getTime(), expireOption, fields); + } + + /** + * 为给定 key 的域 fields 设置过期时间,具体过期时间戳 + * + *

详情说明 https://redis.io/docs/latest/commands/hpexpire/

+ * + * @param key + * Key + * @param date + * 过期时间 + * @param expireOption + * 过期选项 + * @param fields + * 域 + * + * @return -2 if no such field exists in the provided hash key, or the provided key does not exist. + * 0 if the specified {@code NX | XX | GT | LT} condition has not been met. + * 1 if the expiration time was set/updated. + * 2 when {@code HEXPIRE/HPEXPIRE} is called with 0 seconds/milliseconds or when {@code HEXPIREAT/HPEXPIREAT} is called + * with a past Unixtime in seconds/milliseconds. + * + * @since 3.0.0 + */ + default List hpExpireAt(final byte[] key, final Date date, final ExpireOption expireOption, + final byte[]... fields) { + Assert.isNull(date, "Expire date could not be null"); + return hpExpireAt(key, date.getTime(), expireOption, fields); + } + + /** + * Returns the absolute Unix timestamp in milliseconds since Unix epoch at which the given key's field(s) will expire. + * + *

详情说明 https://redis.io/docs/latest/commands/hexpiretime/

+ * + * @param key + * Key + * @param fields + * 域 + * + * @return The expiration Unix timestamp in seconds; + * -1 if the key exists but has no associated expiration time; + * -2 if the key does not exist; + * + * @since 3.0.0 + */ + default List hpExpireTimeAt(final String key, final String... fields) { + List data = hpExpireTime(key, fields); + return data == null ? null : data.stream().map((v)->v != null && v > 0 ? new Date(v) : null) + .collect(Collectors.toList()); + } + + /** + * Returns the absolute Unix timestamp in milliseconds since Unix epoch at which the given key's field(s) will expire. + * + *

详情说明 https://redis.io/docs/latest/commands/hexpiretime/

+ * + * @param key + * Key + * @param fields + * 域 + * + * @return The expiration Unix timestamp in seconds; + * -1 if the key exists but has no associated expiration time; + * -2 if the key does not exist; + * + * @since 3.0.0 + */ + default List hpExpireTimeAt(final byte[] key, final byte[]... fields) { + List data = hpExpireTime(key, fields); + return data == null ? null : data.stream().map((v)->v != null && v > 0 ? new Date(v) : null) + .collect(Collectors.toList()); + } + + /** + * When called with just the key argument, return a random field from the hash value stored at key. + * If the provided count argument is positive, return an array of distinct fields. + * The array’s length is either count or the hash’s number of fields (HLEN), whichever is lower. + * + *

详情说明 https://redis.io/commands/hrandfield/

+ * + * @param key + * Key + * @param count + * 返回数量 + * @param + * 值类型 + * + * @return A list fields and their values from the hash + */ + List> hRandFieldWithValuesObject(final String key, final int count); + + /** + * When called with just the key argument, return a random field from the hash value stored at key. + * If the provided count argument is positive, return an array of distinct fields. + * The array’s length is either count or the hash’s number of fields (HLEN), whichever is lower. + * + *

详情说明 https://redis.io/commands/hrandfield/

+ * + * @param key + * Key + * @param count + * 返回数量 + * @param + * 值类型 + * + * @return A list fields and their values from the hash + */ + List> hRandFieldWithValuesObject(final byte[] key, final int count); + + /** + * When called with just the key argument, return a random field from the hash value stored at key. + * If the provided count argument is positive, return an array of distinct fields. + * The array’s length is either count or the hash’s number of fields (HLEN), whichever is lower. + * + *

详情说明 https://redis.io/commands/hrandfield/

+ * + * @param key + * Key + * @param count + * 返回数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return A list fields and their values from the hash + */ + List> hRandFieldWithValuesObject(final String key, final int count, final Class clazz); + + /** + * When called with just the key argument, return a random field from the hash value stored at key. + * If the provided count argument is positive, return an array of distinct fields. + * The array’s length is either count or the hash’s number of fields (HLEN), whichever is lower. + * + *

详情说明 https://redis.io/commands/hrandfield/

+ * + * @param key + * Key + * @param count + * 返回数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return A list fields and their values from the hash + */ + List> hRandFieldWithValuesObject(final byte[] key, final int count, final Class clazz); + + /** + * When called with just the key argument, return a random field from the hash value stored at key. + * If the provided count argument is positive, return an array of distinct fields. + * The array’s length is either count or the hash’s number of fields (HLEN), whichever is lower. + * + *

详情说明 https://redis.io/commands/hrandfield/

+ * + * @param key + * Key + * @param count + * 返回数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return A list fields and their values from the hash + * + * @see TypeReference + */ + List> hRandFieldWithValuesObject(final String key, final int count, + final TypeReference type); + + /** + * When called with just the key argument, return a random field from the hash value stored at key. + * If the provided count argument is positive, return an array of distinct fields. + * The array’s length is either count or the hash’s number of fields (HLEN), whichever is lower. + * + *

详情说明 https://redis.io/commands/hrandfield/

+ * + * @param key + * Key + * @param count + * 返回数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return A list fields and their values from the hash + * + * @see TypeReference + */ + List> hRandFieldWithValuesObject(final byte[] key, final int count, + final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html + *

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final long cursor); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html + *

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final long cursor); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html + *

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final long cursor, final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final long cursor, final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final String key, final long cursor, final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final byte[] key, final long cursor, final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final String cursor); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final byte[] cursor); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final String cursor, final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final byte[] cursor, final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final String key, final String cursor, final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final byte[] key, final byte[] cursor, final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final long cursor, final String pattern); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final long cursor, final String pattern, + final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern, + final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final String key, final long cursor, final String pattern, + final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern, + final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final String cursor, final String pattern); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final String cursor, final String pattern, + final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final String key, final String cursor, final String pattern, + final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final long cursor, final int count); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final long cursor, final int count); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final long cursor, final int count, + final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final long cursor, final int count, + final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final String key, final long cursor, final int count, + final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final byte[] key, final long cursor, final int count, + final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final String cursor, final int count); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final byte[] cursor, final int count); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final String cursor, final int count, + final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final byte[] cursor, final int count, + final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final String key, final String cursor, final int count, + final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final byte[] key, final byte[] cursor, final int count, + final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final long cursor, final String pattern, + final int count); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern, + final int count); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final long cursor, final String pattern, + final int count, + final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern, + final int count, + final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final String key, final long cursor, final String pattern, + final int count, final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern, + final int count, + final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final String cursor, final String pattern, + final int count); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final String key, final String cursor, final String pattern, + final int count, final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count, final Class clazz); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param pattern + * glob 风格的模式参数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final String key, final String cursor, final String pattern, + final int count, final TypeReference type); + + /** + * 迭代哈希键 key 中的键值对,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/hash/hscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final int count, final TypeReference type); + + /** + * 将哈希表 key 中域 field 的值设置为 value。 + * 如果给定的哈希表并不存在,那么一个新的哈希表; + * 如果域 field 已经存在于哈希表中,那么 value 将覆盖旧值 + * + * @param key + * Key + * @param data + * 域和值 + * @param + * 值类型 + * + * @return 被修改或增加的 field 个数 + */ + Long hSet(final String key, final KeyValue... data); + + /** + * 将哈希表 key 中域 field 的值设置为 value。 + * 如果给定的哈希表并不存在,那么一个新的哈希表; + * 如果域 field 已经存在于哈希表中,那么 value 将覆盖旧值 + * + * @param key + * Key + * @param data + * 域和值 + * @param + * 值类型 + * + * @return 被修改或增加的 field 个数 + */ + Long hSet(final byte[] key, KeyValue... data); + + /** + * 当且仅当域 field 尚未存在于哈希表 key 中的情况下,将它的值设置为 value + * + * @param key + * Key + * @param field + * 域 + * @param value + * 值 + * @param + * 值类型 + * + * @return 操作结果;设置成功时返回 Status.Success,在给定域已经存在而放弃执行设置操作时返回 Status.FAILURE + */ + Status hSetNx(final String key, final String field, final V value); + + /** + * 当且仅当域 field 尚未存在于哈希表 key 中的情况下,将它的值设置为 value + * + * @param key + * Key + * @param field + * 域 + * @param value + * 值 + * @param + * 值类型 + * + * @return 操作结果;设置成功时返回 Status.Success,在给定域已经存在而放弃执行设置操作时返回 Status.FAILURE + */ + Status hSetNx(final byte[] key, final byte[] field, final V value); + + /** + * 获取哈希表 key 中所有域的值,并将值反序列化为对象 + * + * @param key + * Key + * @param + * 值类型 + * + * @return 哈希表 key 中所有域的值反序列化后的对象 + */ + List hValsObject(final String key); + + /** + * 获取哈希表 key 中所有域的值,并将值反序列化为对象 + * + * @param key + * Key + * @param + * 值类型 + * + * @return 哈希表 key 中所有域的值反序列化后的对象 + */ + List hValsObject(final byte[] key); + + /** + * 获取哈希表 key 中所有域的值,并将值反序列化为 clazz 指定的对象 + * + * @param key + * Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 哈希表 key 中所有域的值反序列化后的对象 + */ + List hValsObject(final String key, final Class clazz); + + /** + * 获取哈希表 key 中所有域的值,并将值反序列化为 clazz 指定的对象 + * + * @param key + * Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 哈希表 key 中所有域的值反序列化后的对象 + */ + List hValsObject(final byte[] key, final Class clazz); + + /** + * 获取哈希表 key 中所有域的值,并将值反序列化为 type 指定的对象 + * + * @param key + * Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 哈希表 key 中所有域的值反序列化后的对象 + * + * @see TypeReference + */ + List hValsObject(final String key, final TypeReference type); + + /** + * 获取哈希表 key 中所有域的值,并将值反序列化为 type 指定的对象 + * + * @param key + * Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 哈希表 key 中所有域的值反序列化后的对象 + * + * @see TypeReference + */ + List hValsObject(final byte[] key, final TypeReference type); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/KeyOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/KeyOperations.java new file mode 100644 index 000000000..bce3675ed --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/KeyOperations.java @@ -0,0 +1,494 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.operations; + +import com.buession.core.utils.Assert; +import com.buession.lang.Status; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.RedisNode; +import com.buession.redis.core.command.KeyCommands; +import com.buession.redis.core.command.args.MigrateArgument; + +import java.util.Date; +import java.util.Set; + +/** + * KEY 运算 + * + *

详情说明 http://redisdoc.com/database/index.html + * 和 http://redisdoc.com/expire/index.html

+ * + * @author Yong.Teng + */ +public interface KeyOperations extends KeyCommands, RedisOperations { + + /** + * 删除给定的一个或多个 key + * + *

详情说明 http://redisdoc.com/database/del.html

+ * + * @param keys + * 一个或多个 key + * + * @return 被删除 key 的数量 + */ + default Long delete(final String... keys) { + return del(keys); + } + + /** + * 删除给定的一个或多个 key + * + *

详情说明 http://redisdoc.com/database/del.html

+ * + * @param keys + * 一个或多个 key + * + * @return 被删除 key 的数量 + */ + default Long delete(final byte[]... keys) { + return del(keys); + } + + /** + * 为给定 key 设置过期时间 + * + *

详情说明 http://redisdoc.com/expire/expireat.html

+ * + * @param key + * Key + * @param date + * 过期时间 + * + * @return 操作结果 + */ + default Status expireAt(final String key, final Date date) { + Assert.isNull(date, "Expire date could not be null"); + return expireAt(key, date.getTime() / 1000L); + } + + /** + * 为给定 key 设置过期时间 + * + *

详情说明 http://redisdoc.com/expire/expireat.html

+ * + * @param key + * Key + * @param date + * 过期时间 + * + * @return 操作结果 + */ + default Status expireAt(final byte[] key, final Date date) { + Assert.isNull(date, "Expire date could not be null"); + return expireAt(key, date.getTime() / 1000L); + } + + /** + * 为给定 key 设置过期时间 + * + *

详情说明 http://redisdoc.com/expire/expireat.html

+ * + * @param key + * Key + * @param date + * 过期时间 + * @param expireOption + * 过期选项 + * + * @return 操作结果 + * + * @since 3.0.0 + */ + default Status expireAt(final String key, final Date date, final ExpireOption expireOption) { + Assert.isNull(date, "Expire date could not be null"); + return expireAt(key, date.getTime() / 1000L, expireOption); + } + + /** + * 为给定 key 设置过期时间 + * + *

详情说明 http://redisdoc.com/expire/expireat.html

+ * + * @param key + * Key + * @param date + * 过期时间 + * @param expireOption + * 过期选项 + * + * @return 操作结果 + * + * @since 3.0.0 + */ + default Status expireAt(final byte[] key, final Date date, final ExpireOption expireOption) { + Assert.isNull(date, "Expire date could not be null"); + return expireAt(key, date.getTime() / 1000L, expireOption); + } + + /** + * 获取给定 key 的过期时间 + * + *

详情说明 https://redis.io/docs/latest/commands/expiretime/

+ * + * @param key + * Key + * + * @return 当 key 不存在时,或没有设置剩余生存时间时,返回 null;否则返回过期时间 + * + * @since 3.0.0 + */ + default Date expireTimeAt(final String key) { + Long expireTime = expireTime(key); + return expireTime != null && expireTime > 0 ? new Date(System.currentTimeMillis() + expireTime) : null; + } + + /** + * 获取给定 key 的过期时间 + * + *

详情说明 https://redis.io/docs/latest/commands/expiretime/

+ * + * @param key + * Key + * + * @return 当 key 不存在时,或没有设置剩余生存时间时,返回 null;否则返回过期时间 + * + * @since 3.0.0 + */ + default Date expireTimeAt(final byte[] key) { + Long expireTime = expireTime(key); + return expireTime != null && expireTime > 0 ? new Date(System.currentTimeMillis() + expireTime) : null; + } + + @Override + default Set keys(final String pattern) { + return execute((client)->client.keyOperations().keys(pattern)); + } + + @Override + default Set keys(final byte[] pattern) { + return execute((client)->client.keyOperations().keys(pattern)); + } + + /** + * 将 key 原子性地从当前实例传送到目标实例的指定数据库上, + * 一旦传送成功,key 保证会出现在目标实例上,而当前实例上的 key 会被删除 + * + *

详情说明 http://redisdoc.com/internal/migrate.html

+ * + * @param host + * 目标 Redis Server 主机地址 + * @param db + * 目标 Redis DB + * @param timeout + * 当前实例和目标实例进行沟通的最大间隔时间,只是说数据传送的时间不能超过这个值(单位:毫秒) + * @param keys + * Keys + * + * @return 操作结果 + */ + default Status migrate(final String host, final int db, final int timeout, final String... keys) { + return migrate(host, RedisNode.DEFAULT_PORT, db, timeout, keys); + } + + /** + * 将 key 原子性地从当前实例传送到目标实例的指定数据库上, + * 一旦传送成功,key 保证会出现在目标实例上,而当前实例上的 key 会被删除 + * + *

详情说明 http://redisdoc.com/internal/migrate.html

+ * + * @param host + * 目标 Redis Server 主机地址 + * @param db + * 目标 Redis DB + * @param timeout + * 当前实例和目标实例进行沟通的最大间隔时间,只是说数据传送的时间不能超过这个值(单位:毫秒) + * @param keys + * Keys + * + * @return 操作结果 + */ + default Status migrate(final String host, final int db, final int timeout, final byte[]... keys) { + return migrate(host, RedisNode.DEFAULT_PORT, db, timeout, keys); + } + + /** + * 将 key 原子性地从当前实例传送到目标实例的指定数据库上, + * 一旦传送成功,key 保证会出现在目标实例上,而当前实例上的 key 会被删除 + * + *

详情说明 http://redisdoc.com/internal/migrate.html

+ * + * @param host + * 目标 Redis Server 主机地址 + * @param db + * 目标 Redis DB + * @param timeout + * 当前实例和目标实例进行沟通的最大间隔时间,只是说数据传送的时间不能超过这个值(单位:毫秒) + * @param migrateArgument + * 迁移参数 + * @param keys + * Keys + * + * @return 操作结果 + */ + default Status migrate(final String host, final int db, final int timeout, final MigrateArgument migrateArgument, + final String... keys) { + return migrate(host, RedisNode.DEFAULT_PORT, db, timeout, migrateArgument, keys); + } + + /** + * 将 key 原子性地从当前实例传送到目标实例的指定数据库上, + * 一旦传送成功,key 保证会出现在目标实例上,而当前实例上的 key 会被删除 + * + *

详情说明 http://redisdoc.com/internal/migrate.html

+ * + * @param host + * 目标 Redis Server 主机地址 + * @param db + * 目标 Redis DB + * @param timeout + * 当前实例和目标实例进行沟通的最大间隔时间,只是说数据传送的时间不能超过这个值(单位:毫秒) + * @param migrateArgument + * 迁移参数 + * @param keys + * Keys + * + * @return 操作结果 + */ + default Status migrate(final String host, final int db, final int timeout, final MigrateArgument migrateArgument, + final byte[]... keys) { + return migrate(host, RedisNode.DEFAULT_PORT, db, timeout, migrateArgument, keys); + } + + /** + * 将 key 原子性地从当前实例传送到目标实例的指定数据库上, + * 一旦传送成功,key 保证会出现在目标实例上,而当前实例上的 key 会被删除 + * + *

详情说明 http://redisdoc.com/internal/migrate.html

+ * + * @param server + * 目标 Redis Server + * @param db + * 目标 Redis DB + * @param timeout + * 当前实例和目标实例进行沟通的最大间隔时间,只是说数据传送的时间不能超过这个值(单位:毫秒) + * @param keys + * Keys + * + * @return 操作结果 + */ + default Status migrate(final RedisNode server, final int db, final int timeout, final String... keys) { + Assert.isNull(server, "Destination redis node cloud not be null"); + Assert.isBlank(server.getHost(), "Destination redis host cloud not be null or empty"); + + return migrate(server.getHost(), server.getPort(), db, timeout, keys); + } + + /** + * 将 key 原子性地从当前实例传送到目标实例的指定数据库上, + * 一旦传送成功,key 保证会出现在目标实例上,而当前实例上的 key 会被删除 + * + *

详情说明 http://redisdoc.com/internal/migrate.html

+ * + * @param server + * 目标 Redis Server + * @param db + * 目标 Redis DB + * @param timeout + * 当前实例和目标实例进行沟通的最大间隔时间,只是说数据传送的时间不能超过这个值(单位:毫秒) + * @param keys + * Keys + * + * @return 操作结果 + */ + default Status migrate(final RedisNode server, final int db, final int timeout, final byte[]... keys) { + Assert.isNull(server, "Destination redis node cloud not be null"); + Assert.isBlank(server.getHost(), "Destination redis host cloud not be null or empty"); + + return migrate(server.getHost(), server.getPort(), db, timeout, keys); + } + + /** + * 将 key 原子性地从当前实例传送到目标实例的指定数据库上, + * 一旦传送成功,key 保证会出现在目标实例上,而当前实例上的 key 会被删除 + * + *

详情说明 http://redisdoc.com/internal/migrate.html

+ * + * @param server + * 目标 Redis Server + * @param db + * 目标 Redis DB + * @param timeout + * 当前实例和目标实例进行沟通的最大间隔时间,只是说数据传送的时间不能超过这个值(单位:毫秒) + * @param migrateArgument + * 迁移参数 + * @param keys + * Keys + * + * @return 操作结果 + */ + default Status migrate(final RedisNode server, final int db, final int timeout, + final MigrateArgument migrateArgument, final String... keys) { + Assert.isNull(server, "Destination redis node cloud not be null"); + Assert.isBlank(server.getHost(), "Destination redis host cloud not be null or empty"); + + return migrate(server.getHost(), server.getPort(), db, timeout, migrateArgument, keys); + } + + /** + * 将 key 原子性地从当前实例传送到目标实例的指定数据库上, + * 一旦传送成功,key 保证会出现在目标实例上,而当前实例上的 key 会被删除 + * + *

详情说明 http://redisdoc.com/internal/migrate.html

+ * + * @param server + * 目标 Redis Server + * @param db + * 目标 Redis DB + * @param timeout + * 当前实例和目标实例进行沟通的最大间隔时间,只是说数据传送的时间不能超过这个值(单位:毫秒) + * @param migrateArgument + * 迁移参数 + * @param keys + * Keys + * + * @return 操作结果 + */ + default Status migrate(final RedisNode server, final int db, final int timeout, + final MigrateArgument migrateArgument, final byte[]... keys) { + Assert.isNull(server, "Destination redis node cloud not be null"); + Assert.isBlank(server.getHost(), "Destination redis host cloud not be null or empty"); + + return migrate(server.getHost(), server.getPort(), db, timeout, migrateArgument, keys); + } + + /** + * 为给定 key 设置过期时间 + * + *

详情说明 http://redisdoc.com/expire/pexpireat.html

+ * + * @param key + * Key + * @param date + * 过期时间 + * + * @return 操作结果 + */ + default Status pExpireAt(final String key, final Date date) { + Assert.isNull(date, "Expire date could not be null"); + return pExpireAt(key, date.getTime()); + } + + /** + * 为给定 key 设置过期时间 + * + *

详情说明 http://redisdoc.com/expire/pexpireat.html

+ * + * @param key + * Key + * @param date + * 过期时间 + * + * @return 操作结果 + */ + default Status pExpireAt(final byte[] key, final Date date) { + Assert.isNull(date, "Expire date could not be null"); + return pExpireAt(key, date.getTime()); + } + + /** + * 获取给定 key 的过期时间 + * + *

详情说明 https://redis.io/docs/latest/commands/expiretime/

+ * + * @param key + * Key + * + * @return 当 key 不存在时,或没有设置剩余生存时间时,返回 null;否则返回过期时间 + * + * @since 3.0.0 + */ + default Date pExpireTimeAt(final String key) { + Long expireTime = pExpireTime(key); + return expireTime != null && expireTime > 0 ? new Date(expireTime) : null; + } + + /** + * 获取给定 key 的过期时间 + * + *

详情说明 https://redis.io/docs/latest/commands/expiretime/

+ * + * @param key + * Key + * + * @return 当 key 不存在时,或没有设置剩余生存时间时,返回 null;否则返回过期时间 + * + * @since 3.0.0 + */ + default Date pExpireTimeAt(final byte[] key) { + Long expireTime = pExpireTime(key); + return expireTime != null && expireTime > 0 ? new Date(expireTime) : null; + } + + @Override + default String randomKey() { + return execute((client)->client.keyOperations().randomKey()); + } + + /** + * 反序列化给定的序列化值,并将它和给定的 key 关联 + * + * @param key + * Key + * @param serializedValue + * 序列化值 + * @param ttl + * 过期时间 + * + * @return 操作结果 + */ + default Status restore(final String key, final byte[] serializedValue, final Date ttl) { + Assert.isNull(ttl, "Ttl date could not be null"); + return restore(key, serializedValue, (int) (ttl.getTime() - System.currentTimeMillis())); + } + + /** + * 反序列化给定的序列化值,并将它和给定的 key 关联 + * + * @param key + * Key + * @param serializedValue + * 序列化值 + * @param ttl + * 过期时间 + * + * @return 操作结果 + */ + default Status restore(final byte[] key, final byte[] serializedValue, final Date ttl) { + Assert.isNull(ttl, "Ttl date could not be null"); + return restore(key, serializedValue, (int) (ttl.getTime() - System.currentTimeMillis())); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/ListOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/ListOperations.java new file mode 100644 index 000000000..932e30451 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/ListOperations.java @@ -0,0 +1,1572 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.operations; + +import com.buession.core.type.TypeReference; +import com.buession.lang.Status; +import com.buession.redis.core.Direction; +import com.buession.redis.core.ListPosition; +import com.buession.redis.core.command.ListCommands; + +import java.util.List; + +/** + * 列表运算 + * + *

详情说明 http://redisdoc.com/list/index.html

+ * + * @author Yong.Teng + */ +public interface ListOperations extends ListCommands, RedisOperations { + + /** + * 获取列表 key 中,下标为 index 的元素,并反序列为对象 + * + *

详情说明 http://redisdoc.com/list/lindex.html

+ * + * @param key + * Key + * @param index + * 下标 + * @param + * 值类型 + * + * @return 下标为 index 的元素反序列化后的值;如果 index 参数的值不在列表的区间范围内,返回 null + */ + V lIndexObject(final String key, final long index); + + /** + * 获取列表 key 中,下标为 index 的元素,并反序列为对象 + * + *

详情说明 http://redisdoc.com/list/lindex.html

+ * + * @param key + * Key + * @param index + * 下标 + * @param + * 值类型 + * + * @return 下标为 index 的元素反序列化后的值;如果 index 参数的值不在列表的区间范围内,返回 null + */ + V lIndexObject(final byte[] key, final long index); + + /** + * 获取列表 key 中,下标为 index 的元素,并反序列为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/list/lindex.html

+ * + * @param key + * Key + * @param index + * 下标 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 下标为 index 的元素反序列化后的值;如果 index 参数的值不在列表的区间范围内,返回 null + * + * @see java.lang.Class + */ + V lIndexObject(final String key, final long index, final Class clazz); + + /** + * 获取列表 key 中,下标为 index 的元素,并反序列为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/list/lindex.html

+ * + * @param key + * Key + * @param index + * 下标 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 下标为 index 的元素反序列化后的值;如果 index 参数的值不在列表的区间范围内,返回 null + * + * @see java.lang.Class + */ + V lIndexObject(final byte[] key, final long index, final Class clazz); + + /** + * 获取列表 key 中,下标为 index 的元素,并反序列为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/list/lindex.html

+ * + * @param key + * Key + * @param index + * 下标 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 下标为 index 的元素反序列化后的值;如果 index 参数的值不在列表的区间范围内,返回 null + * + * @see TypeReference + */ + V lIndexObject(final String key, final long index, final TypeReference type); + + /** + * 获取列表 key 中,下标为 index 的元素,并反序列为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/list/lindex.html

+ * + * @param key + * Key + * @param index + * 下标 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 下标为 index 的元素反序列化后的值;如果 index 参数的值不在列表的区间范围内,返回 null + * + * @see TypeReference + */ + V lIndexObject(final byte[] key, final long index, final TypeReference type); + + /** + * 将值 value 序列化后,插入到列表 key 当中,位于值 pivot 之前或之后 + * + *

详情说明 http://redisdoc.com/list/linsert.html

+ * + * @param key + * Key + * @param position + * 位置 + * @param pivot + * pivot + * @param value + * 值 + * @param + * 值类型 + * + * @return 执行成功,返回插入操作完成之后,列表的长度; + * 如果没有找到 pivot ,返回 -1 ;如果 key 不存在或为空列表,返回 0 。 + */ + Long lInsert(final String key, final ListPosition position, final V pivot, final V value); + + /** + * 将值 value 序列化后,插入到列表 key 当中,位于值 pivot 之前或之后 + * + *

详情说明 http://redisdoc.com/list/linsert.html

+ * + * @param key + * Key + * @param position + * 位置 + * @param pivot + * pivot + * @param value + * 值 + * @param + * 值类型 + * + * @return 执行成功,返回插入操作完成之后,列表的长度; + * 如果没有找到 pivot ,返回 -1 ;如果 key 不存在或为空列表,返回 0 。 + */ + Long lInsert(final byte[] key, final ListPosition position, final V pivot, final V value); + + /** + * 将列表 key 下标为 index 的元素的值设置为 value 序列化的值 + * + *

详情说明 http://redisdoc.com/list/lset.html

+ * + * @param key + * Key + * @param index + * 下标 + * @param value + * 值 + * @param + * 值类型 + * + * @return 操作结果;设置成功时返回 Status.Success,否则返回 Status.FAILURE + */ + Status lSet(final String key, final long index, final V value); + + /** + * 将列表 key 下标为 index 的元素的值设置为 value 序列化的值 + * + *

详情说明 http://redisdoc.com/list/lset.html

+ * + * @param key + * Key + * @param index + * 下标 + * @param value + * 值 + * @param + * 值类型 + * + * @return 操作结果;设置成功时返回 Status.Success,否则返回 Status.FAILURE + */ + Status lSet(final byte[] key, final long index, final V value); + + /** + * 获取列表 key 中指定区间内的元素,区间以偏移量 start 和 stop 之间的元素(包含 start 和 stop)并反序列化为对象; + * 也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推 + * + *

详情说明 http://redisdoc.com/list/lrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param + * 值类型 + * + * @return 指定区间内的元素反序列化后的对象; + * 如果 start 下标比列表的最大下标 ( LLEN list 减去 1 )还要大,那么返回一个空列表; + * 如果 end 下标比最大下标还要大,那么最多返回到 end 个下标 + */ + List lRangeObject(final String key, final long start, final long end); + + /** + * 获取列表 key 中指定区间内的元素,区间以偏移量 start 和 stop 之间的元素(包含 start 和 stop)并反序列化为对象; + * 也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推 + * + *

详情说明 http://redisdoc.com/list/lrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param + * 值类型 + * + * @return 指定区间内的元素反序列化后的对象; + * 如果 start 下标比列表的最大下标 ( LLEN list 减去 1 )还要大,那么返回一个空列表; + * 如果 end 下标比最大下标还要大,那么最多返回到 end 个下标 + */ + List lRangeObject(final byte[] key, final long start, final long end); + + /** + * 获取列表 key 中指定区间内的元素,区间以偏移量 start 和 stop 之间的元素(包含 start 和 stop)并反序列化为 clazz 指定的对象; + * 也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推 + * + *

详情说明 http://redisdoc.com/list/lrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 指定区间内的元素反序列化后的对象; + * 如果 start 下标比列表的最大下标 ( LLEN list 减去 1 )还要大,那么返回一个空列表; + * 如果 end 下标比最大下标还要大,那么最多返回到 end 个下标 + */ + List lRangeObject(final String key, final long start, final long end, final Class clazz); + + /** + * 获取列表 key 中指定区间内的元素,区间以偏移量 start 和 stop 之间的元素(包含 start 和 stop)并反序列化为 clazz 指定的对象; + * 也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推 + * + *

详情说明 http://redisdoc.com/list/lrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 指定区间内的元素反序列化后的对象; + * 如果 start 下标比列表的最大下标 ( LLEN list 减去 1 )还要大,那么返回一个空列表; + * 如果 end 下标比最大下标还要大,那么最多返回到 end 个下标 + */ + List lRangeObject(final byte[] key, final long start, final long end, final Class clazz); + + /** + * 获取列表 key 中指定区间内的元素,区间以偏移量 start 和 stop 之间的元素(包含 start 和 stop)并反序列化为 type 指定的对象; + * 也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推 + * + *

详情说明 http://redisdoc.com/list/lrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 指定区间内的元素反序列化后的对象; + * 如果 start 下标比列表的最大下标 ( LLEN list 减去 1 )还要大,那么返回一个空列表; + * 如果 end 下标比最大下标还要大,那么最多返回到 end 个下标 + * + * @see TypeReference + */ + List lRangeObject(final String key, final long start, final long end, final TypeReference type); + + /** + * 获取列表 key 中指定区间内的元素,区间以偏移量 start 和 stop 之间的元素(包含 start 和 stop)并反序列化为 type 指定的对象; + * 也可以使用负数下标,以 -1 表示列表的最后一个元素, -2 表示列表的倒数第二个元素,以此类推 + * + *

详情说明 http://redisdoc.com/list/lrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 指定区间内的元素反序列化后的对象; + * 如果 start 下标比列表的最大下标 ( LLEN list 减去 1 )还要大,那么返回一个空列表; + * 如果 end 下标比最大下标还要大,那么最多返回到 end 个下标 + * + * @see TypeReference + */ + List lRangeObject(final byte[] key, final long start, final long end, final TypeReference type); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素反序列化后的对象(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数) + * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * @param + * 元素值类型 + * + * @return 被移除并再次插入的元素 + */ + V lMoveObject(final String key, final String destKey, final Direction from, final Direction to); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素反序列化后的对象(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数) + * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * @param + * 元素值类型 + * + * @return 被移除并再次插入的元素 + */ + V lMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素反序列化为 clazz 的对象(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数) + * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * @param clazz + * 元素值对象类 + * @param + * 元素值类型 + * + * @return 被移除并再次插入的元素 + */ + V lMoveObject(final String key, final String destKey, final Direction from, final Direction to, + final Class clazz); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素反序列化为 clazz 的对象(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数) + * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * @param clazz + * 元素值对象类 + * @param + * 元素值类型 + * + * @return 被移除并再次插入的元素 + */ + V lMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final Class clazz); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素反序列化为 type 指定的对象(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数) + * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * @param type + * 元素值类型引用 + * @param + * 元素值类型 + * + * @return 被移除并再次插入的元素 + * + * @see TypeReference + */ + V lMoveObject(final String key, final String destKey, final Direction from, final Direction to, + final TypeReference type); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素反序列化为 type 指定的对象(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数) + * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * @param type + * 元素值类型引用 + * @param + * 元素值类型 + * + * @return 被移除并再次插入的元素 + * + * @see TypeReference + */ + V lMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final TypeReference type); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素反序列化后的对象(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数); + * 是 lmove 的阻塞版 + * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * @param timeout + * 超时时间 + * @param + * 元素值类型 + * + * @return 被移除并再次插入的元素 + */ + V blMoveObject(final String key, final String destKey, final Direction from, final Direction to, + final int timeout); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素反序列化后的对象(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数); + * 是 lmove 的阻塞版 + * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * @param timeout + * 超时时间 + * @param + * 元素值类型 + * + * @return 被移除并再次插入的元素 + */ + V blMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素反序列化为 clazz 的对象(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数); + * 是 lmove 的阻塞版 + * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * @param timeout + * 超时时间 + * @param clazz + * 元素值对象类 + * @param + * 元素值类型 + * + * @return 被移除并再次插入的元素 + */ + V blMoveObject(final String key, final String destKey, final Direction from, final Direction to, + final int timeout, final Class clazz); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素反序列化为 clazz 的对象(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数); + * 是 lmove 的阻塞版 + * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * @param timeout + * 超时时间 + * @param clazz + * 元素值对象类 + * @param + * 元素值类型 + * + * @return 被移除并再次插入的元素 + */ + V blMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout, final Class clazz); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素反序列化为 type 指定的对象(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数); + * 是 lmove 的阻塞版 + * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * @param timeout + * 超时时间 + * @param type + * 元素值类型引用 + * @param + * 元素值类型 + * + * @return 被移除并再次插入的元素 + * + * @see TypeReference + */ + V blMoveObject(final String key, final String destKey, final Direction from, final Direction to, + final int timeout, final TypeReference type); + + /** + * 用于原子地从列表 key 中移除并返回第一个或最后一个元素反序列化为 type 指定的对象(头或尾取决于 from 参数),然后把这个元素插入到列表 destKey 的第一个或最后一个元素(头或尾取决于 to 参数); + * 是 lmove 的阻塞版 + * + * @param key + * Key + * @param destKey + * 目标 Key + * @param from + * 第一个或最后一个元素 + * @param to + * 第一个或最后一个元素 + * @param timeout + * 超时时间 + * @param type + * 元素值类型引用 + * @param + * 元素值类型 + * + * @return 被移除并再次插入的元素 + * + * @see TypeReference + */ + V blMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout, final TypeReference type); + + /** + * 移除并返回 key 的头元素反序列化后的对象,BLPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/blpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值反序列化后的对象。 + */ + List blPopObject(final String[] keys, final int timeout); + + /** + * 移除并返回 key 的头元素反序列化后的对象,BLPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/blpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值反序列化后的对象。 + */ + List blPopObject(final byte[][] keys, final int timeout); + + /** + * 移除并返回 key 的头元素反序列化为 clazz 指定的对象,BLPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/blpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值反序列化为 clazz 指定的对象。 + * + * @see java.lang.Class + */ + List blPopObject(final String[] keys, final int timeout, final Class clazz); + + /** + * 移除并返回 key 的头元素反序列化为 clazz 指定的对象,BLPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/blpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值反序列化为 clazz 指定的对象。 + */ + List blPopObject(final byte[][] keys, final int timeout, final Class clazz); + + /** + * 移除并返回 key 的头元素反序列化为 type 指定的对象,BLPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/blpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值反序列化为 type 指定的对象。 + * + * @see TypeReference + */ + List blPopObject(final String[] keys, final int timeout, final TypeReference type); + + /** + * 移除并返回 key 的头元素反序列化为 type 指定的对象,BLPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/blpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值反序列化为 type 指定的对象。 + * + * @see TypeReference + */ + List blPopObject(final byte[][] keys, final int timeout, final TypeReference type); + + /** + * 移除并返回列表中 key 的尾元素反序列化后的对象,BRPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/brpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值反序列化后的对象。 + */ + List brPopObject(final String[] keys, final int timeout); + + /** + * 移除并返回列表中 key 的尾元素反序列化后的对象,BRPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/brpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值反序列化后的对象。 + */ + List brPopObject(final byte[][] keys, final int timeout); + + /** + * 移除并返回列表中 key 的尾元素反序列化为 clazz 指定的对象,BRPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/brpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值序列化为 clazz 指定的对象。 + */ + List brPopObject(final String[] keys, final int timeout, final Class clazz); + + /** + * 移除并返回列表中 key 的尾元素反序列化为 clazz 指定的对象,BRPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/brpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值序列化为 clazz 指定的对象。 + */ + List brPopObject(final byte[][] keys, final int timeout, final Class clazz); + + /** + * 移除并返回列表中 key 的尾元素反序列化为 type 指定的对象,BRPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/brpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值序列化为 type 指定的对象。 + * + * @see TypeReference + */ + List brPopObject(final String[] keys, final int timeout, final TypeReference type); + + /** + * 移除并返回列表中 key 的尾元素反序列化为 type 指定的对象,BRPOP 是列表的阻塞式(blocking)弹出原语; + * 当给定列表内没有任何元素可供弹出的时候,连接将被阻塞,直到等待超时或发现可弹出元素为止 + * + *

详情说明 http://redisdoc.com/list/brpop.html

+ * + * @param keys + * 一个或多个 key + * @param timeout + * 超时时间 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素所属的 key ,第二个元素是被弹出元素的值序列化为 type 指定的对象。 + * + * @see TypeReference + */ + List brPopObject(final byte[][] keys, final int timeout, final TypeReference type); + + /** + * 将列表 key 中的最后尾元素弹出,并返回反序列化后的对象;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 key 不存在,值 null 被返回,并且不执行其他动作; + * 如果 key 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * RPOPLPUSH 是列表的阻塞式(blocking)弹出原语 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param timeout + * 超时时间(单位:秒) + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素的值反序列化后的对象 ,第二个等待时长 + */ + V brPoplPushObject(final String key, final String destKey, final int timeout); + + /** + * 将列表 key 中的最后尾元素弹出,并返回反序列化后的对象;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 key 不存在,值 null 被返回,并且不执行其他动作; + * 如果 key 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * RPOPLPUSH 是列表的阻塞式(blocking)弹出原语 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param timeout + * 超时时间(单位:秒) + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素的值反序列化后的对象 ,第二个等待时长 + */ + V brPoplPushObject(final byte[] key, final byte[] destKey, final int timeout); + + /** + * 将列表 key 中的最后尾元素弹出,并返回反序列化为 clazz 指定的对象;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 key 不存在,值 null 被返回,并且不执行其他动作; + * 如果 key 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * RPOPLPUSH 是列表的阻塞式(blocking)弹出原语 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param timeout + * 超时时间(单位:秒) + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素的值反序列化为 clazz 指定的对象 ,第二个等待时长 + */ + V brPoplPushObject(final String key, final String destKey, final int timeout, final Class clazz); + + /** + * 将列表 key 中的最后尾元素弹出,并返回反序列化为 clazz 指定的对象;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 key 不存在,值 null 被返回,并且不执行其他动作; + * 如果 key 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * RPOPLPUSH 是列表的阻塞式(blocking)弹出原语 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param timeout + * 超时时间(单位:秒) + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素的值反序列化为 clazz 指定的对象 ,第二个等待时长 + */ + V brPoplPushObject(final byte[] key, final byte[] destKey, final int timeout, final Class clazz); + + /** + * 将列表 key 中的最后尾元素弹出,并返回反序列化为 type 指定的对象;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 key 不存在,值 null 被返回,并且不执行其他动作; + * 如果 key 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * RPOPLPUSH 是列表的阻塞式(blocking)弹出原语 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param timeout + * 超时时间(单位:秒) + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素的值反序列化为 type 指定的对象 ,第二个等待时长 + * + * @see TypeReference + */ + V brPoplPushObject(final String key, final String destKey, final int timeout, final TypeReference type); + + /** + * 将列表 key 中的最后尾元素弹出,并返回反序列化为 type 指定的对象;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 key 不存在,值 null 被返回,并且不执行其他动作; + * 如果 key 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * RPOPLPUSH 是列表的阻塞式(blocking)弹出原语 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param timeout + * 超时时间(单位:秒) + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 如果列表为空,返回一个 null;否则,返回一个含有两个元素的列表,第一个元素是被弹出元素的值反序列化为 type 指定的对象 ,第二个等待时长 + * + * @see TypeReference + */ + V brPoplPushObject(final byte[] key, final byte[] destKey, final int timeout, final TypeReference type); + + /** + * 移除并返回列表 key 的头元素,并反序列为对象 + * + *

详情说明 http://redisdoc.com/list/lpop.html

+ * + * @param key + * Key + * @param + * 值类型 + * + * @return 列表的头元素反序列化后的值;当 key 不存在时,返回 null + */ + V lPopObject(final String key); + + /** + * 移除并返回列表 key 的头元素,并反序列为对象 + * + *

详情说明 http://redisdoc.com/list/lpop.html

+ * + * @param key + * Key + * @param + * 值类型 + * + * @return 列表的头元素反序列化后的值;当 key 不存在时,返回 null + */ + V lPopObject(final byte[] key); + + /** + * 移除并返回列表 key 的头元素,并反序列为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/list/lpop.html

+ * + * @param key + * Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 列表的头元素反序列化后的值;当 key 不存在时,返回 null + */ + V lPopObject(final String key, final Class clazz); + + /** + * 移除并返回列表 key 的头元素,并反序列为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/list/lpop.html

+ * + * @param key + * Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 列表的头元素反序列化后的值;当 key 不存在时,返回 null + */ + V lPopObject(final byte[] key, final Class clazz); + + /** + * 移除并返回列表 key 的头元素,并反序列为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/list/lpop.html

+ * + * @param key + * Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 列表的头元素反序列化后的值;当 key 不存在时,返回 null + * + * @see TypeReference + */ + V lPopObject(final String key, final TypeReference type); + + /** + * 移除并返回列表 key 的头元素,并反序列为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/list/lpop.html

+ * + * @param key + * Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 列表的头元素反序列化后的值;当 key 不存在时,返回 null + * + * @see TypeReference + */ + V lPopObject(final byte[] key, final TypeReference type); + + /** + * 将一个值 value 序列化后,插入到列表 key 的表头 + * + *

详情说明 http://redisdoc.com/list/lpush.html

+ * + * @param key + * Key + * @param value + * 值 + * @param + * 值类型 + * + * @return 执行 LPUSH 命令后,列表的长度 + */ + Long lPush(final String key, final V value); + + /** + * 将一个或多个值 value 序列化后,插入到列表 key 的表头 + * + *

详情说明 http://redisdoc.com/list/lpush.html

+ * + * @param key + * Key + * @param value + * 值 + * @param + * 值类型 + * + * @return 执行 LPUSH 命令后,列表的长度 + */ + Long lPush(final byte[] key, final V value); + + /** + * 将一个或多个值 value 序列化后,插入到列表 key 的表头 + * + *

详情说明 http://redisdoc.com/list/lpush.html

+ * + * @param key + * Key + * @param values + * 一个或多个值 + * @param + * 值类型 + * + * @return 执行 LPUSH 命令后,列表的长度 + */ + Long lPush(final String key, final V... values); + + /** + * 将一个或多个值 value 序列化后,插入到列表 key 的表头 + * + *

详情说明 http://redisdoc.com/list/lpush.html

+ * + * @param key + * Key + * @param values + * 一个或多个值 + * @param + * 值类型 + * + * @return 执行 LPUSH 命令后,列表的长度 + */ + Long lPush(final byte[] key, final V... values); + + /** + * 将值 value 序列化后,插入到列表 key 的表头,当且仅当 key 存在并且是一个列表 + * + *

详情说明 http://redisdoc.com/list/lpushx.html

+ * + * @param key + * Key + * @param value + * 值 + * @param + * 值类型 + * + * @return 执行 LPUSHX 命令后,列表的长度 + */ + Long lPushX(final String key, final V value); + + /** + * 将值 value 序列化后,插入到列表 key 的表头,当且仅当 key 存在并且是一个列表 + * + *

详情说明 http://redisdoc.com/list/lpushx.html

+ * + * @param key + * Key + * @param value + * 值 + * @param + * 值类型 + * + * @return 执行 LPUSHX 命令后,列表的长度 + */ + Long lPushX(final byte[] key, final V value); + + /** + * 将一个或多个值 value 序列化后,插入到列表 key 的表头,当且仅当 key 存在并且是一个列表 + * + *

详情说明 http://redisdoc.com/list/lpushx.html

+ * + * @param key + * Key + * @param values + * 值 + * @param + * 值类型 + * + * @return 执行 LPUSHX 命令后,列表的长度 + */ + Long lPushX(final String key, final V... values); + + /** + * 将一个或多个值 value 序列化后,插入到列表 key 的表头,当且仅当 key 存在并且是一个列表 + * + *

详情说明 http://redisdoc.com/list/lpushx.html

+ * + * @param key + * Key + * @param values + * 值 + * @param + * 值类型 + * + * @return 执行 LPUSHX 命令后,列表的长度 + */ + Long lPushX(final byte[] key, final V... values); + + /** + * 移除并返回列表 key 的尾元素,并反序列化为对象 + * + * @param key + * Key + * @param + * 值类型 + * + * @return 列表的尾元素反序列化后的值;当 key 不存在时,返回 null + */ + V rPopObject(final String key); + + /** + * 移除并返回列表 key 的尾元素,并反序列化为对象 + * + * @param key + * Key + * @param + * 值类型 + * + * @return 列表的尾元素反序列化后的值;当 key 不存在时,返回 null + */ + V rPopObject(final byte[] key); + + /** + * 移除并返回列表 key 的尾元素,并反序列化为 clazz 指定的对象对象 + * + *

详情说明 http://redisdoc.com/list/rpop.html

+ * + * @param key + * Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 列表的尾元素反序列化后的值;当 key 不存在时,返回 null + */ + V rPopObject(final String key, final Class clazz); + + /** + * 移除并返回列表 key 的尾元素,并反序列化为 clazz 指定的对象对象 + * + *

详情说明 http://redisdoc.com/list/rpop.html

+ * + * @param key + * Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 列表的尾元素反序列化后的值;当 key 不存在时,返回 null + */ + V rPopObject(final byte[] key, final Class clazz); + + /** + * 移除并返回列表 key 的尾元素,并反序列化为 type 指定的对象对象 + * + *

详情说明 http://redisdoc.com/list/rpop.html

+ * + * @param key + * Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 列表的尾元素反序列化后的值;当 key 不存在时,返回 null + * + * @see TypeReference + */ + V rPopObject(final String key, final TypeReference type); + + /** + * 移除并返回列表 key 的尾元素,并反序列化为 type 指定的对象对象 + * + *

详情说明 http://redisdoc.com/list/rpop.html

+ * + * @param key + * Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 列表的尾元素反序列化后的值;当 key 不存在时,返回 null + * + * @see TypeReference + */ + V rPopObject(final byte[] key, final TypeReference type); + + /** + * 将列表 key 中的最后尾元素弹出,并反序列化为对象后返回;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 key 不存在,值 null 被返回,并且不执行其他动作; + * 如果 key 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param + * 值类型 + * + * @return 被弹出的元素反序列化后的对象 + */ + V rPoplPushObject(final String key, final String destKey); + + /** + * 将列表 key 中的最后尾元素弹出,并反序列化为对象后返回;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 key 不存在,值 null 被返回,并且不执行其他动作; + * 如果 key 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param + * 值类型 + * + * @return 被弹出的元素反序列化后的对象 + */ + V rPoplPushObject(final byte[] key, final byte[] destKey); + + /** + * 将列表 key 中的最后尾元素弹出,并反序列化为 clazz 指定的对象后返回;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 key 不存在,值 null 被返回,并且不执行其他动作; + * 如果 key 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 被弹出的元素反序列化后的对象 + */ + V rPoplPushObject(final String key, final String destKey, final Class clazz); + + /** + * 将列表 key 中的最后尾元素弹出,并反序列化为 clazz 指定的对象后返回;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 key 不存在,值 null 被返回,并且不执行其他动作; + * 如果 key 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 被弹出的元素反序列化后的对象 + */ + V rPoplPushObject(final byte[] key, final byte[] destKey, final Class clazz); + + /** + * 将列表 key 中的最后尾元素弹出,并反序列化为 type 指定的对象后返回;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 key 不存在,值 null 被返回,并且不执行其他动作; + * 如果 key 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 被弹出的元素反序列化后的对象 + * + * @see TypeReference + */ + V rPoplPushObject(final String key, final String destKey, final TypeReference type); + + /** + * 将列表 key 中的最后尾元素弹出,并反序列化为 type 指定的对象后返回;弹出的元素插入到列表 destKey ,作为 destKey 列表的的头元素; + * 如果 key 不存在,值 null 被返回,并且不执行其他动作; + * 如果 key 和 destKey 相同,则列表中的表尾元素被移动到表头,并返回该元素,可以把这种特殊情况视作列表的旋转(rotation)操作 + * + *

详情说明 http://redisdoc.com/list/rpoplpush.html

+ * + * @param key + * Key + * @param destKey + * 目标 Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 被弹出的元素反序列化后的对象 + * + * @see TypeReference + */ + V rPoplPushObject(final byte[] key, final byte[] destKey, final TypeReference type); + + /** + * 将值 value 序列化后,插入到列表 key 的表尾 + * + *

详情说明 http://redisdoc.com/list/rpush.html

+ * + * @param key + * Key + * @param value + * 值 + * @param + * 值类型 + * + * @return 执行 RPUSH 操作后,表的长度 + */ + Long rPush(final String key, final V value); + + /** + * 将值 value 序列化后,插入到列表 key 的表尾 + * + *

详情说明 http://redisdoc.com/list/rpush.html

+ * + * @param key + * Key + * @param value + * 值 + * @param + * 值类型 + * + * @return 执行 RPUSH 操作后,表的长度 + */ + Long rPush(final byte[] key, final V value); + + /** + * 将一个或多个值 value 序列化后,插入到列表 key 的表尾 + * + *

详情说明 http://redisdoc.com/list/rpush.html

+ * + * @param key + * Key + * @param values + * 一个或多个值 + * @param + * 值类型 + * + * @return 执行 RPUSH 操作后,表的长度 + */ + Long rPush(final String key, final V... values); + + /** + * 将一个或多个值 value 序列化后,插入到列表 key 的表尾 + * + *

详情说明 http://redisdoc.com/list/rpush.html

+ * + * @param key + * Key + * @param values + * 一个或多个值 + * @param + * 值类型 + * + * @return 执行 RPUSH 操作后,表的长度 + */ + Long rPush(final byte[] key, final V... values); + + /** + * 将值 value 序列化后,插入到列表 key 的表尾,当且仅当 key 存在并且是一个列表 + * + *

详情说明 http://redisdoc.com/list/rpushx.html

+ * + * @param key + * Key + * @param value + * 值 + * @param + * 值类型 + * + * @return 执行 RPUSHX 之后,表的长度 + */ + Long rPushX(final String key, final V value); + + /** + * 将值 value 序列化后,插入到列表 key 的表尾,当且仅当 key 存在并且是一个列表 + * + *

详情说明 http://redisdoc.com/list/rpushx.html

+ * + * @param key + * Key + * @param value + * 值 + * @param + * 值类型 + * + * @return 执行 RPUSHX 之后,表的长度 + */ + Long rPushX(final byte[] key, final V value); + + /** + * 将一个或多个值 value 序列化后,插入到列表 key 的表尾,当且仅当 key 存在并且是一个列表 + * + *

详情说明 http://redisdoc.com/list/rpushx.html

+ * + * @param key + * Key + * @param values + * 一个或多个值 + * @param + * 值类型 + * + * @return 执行 RPUSHX 之后,表的长度 + */ + Long rPushX(final String key, final V... values); + + /** + * 将一个或多个值 value 序列化后,插入到列表 key 的表尾,当且仅当 key 存在并且是一个列表 + * + *

详情说明 http://redisdoc.com/list/rpushx.html

+ * + * @param key + * Key + * @param values + * 一个或多个值 + * @param + * 值类型 + * + * @return 执行 RPUSHX 之后,表的长度 + */ + Long rPushX(final byte[] key, final V... values); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/ScriptingOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/ScriptingOperations.java new file mode 100644 index 000000000..480fe3a9d --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/ScriptingOperations.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.operations; + +import com.buession.redis.core.command.ScriptingCommands; + +/** + * LUA 脚本运算 + * + *

详情说明 http://redisdoc.com/script/index.html

+ * + * @author Yong.Teng + */ +public interface ScriptingOperations extends ScriptingCommands, RedisOperations { + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/ServerOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/ServerOperations.java new file mode 100644 index 000000000..701f0914e --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/ServerOperations.java @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.operations; + +import com.buession.core.utils.Assert; +import com.buession.lang.Status; +import com.buession.redis.core.RedisNode; +import com.buession.redis.core.command.ServerCommands; + +import java.util.Date; + +/** + * 服务端运算 + * + *

详情说明 http://www.redis.cn/commands.html#server

+ * + * @author Yong.Teng + */ +public interface ServerOperations extends ServerCommands, RedisOperations { + + /** + * This command will start a coordinated failover between the currently-connected-to master and one of its replicas + * + *

详情说明 https://redis.io/commands/failover/

+ * + * @param server + * Redis 主机 + * + * @return Status.SUCCESS if the command was accepted and a coordinated failover is in progress + */ + default Status failover(final RedisNode server) { + Assert.isNull(server, "Redis server cloud not be null"); + return failover(server.getHost(), server.getPort()); + } + + /** + * This command will start a coordinated failover between the currently-connected-to master and one of its replicas + * + *

详情说明 https://redis.io/commands/failover/

+ * + * @param server + * Redis 主机 + * @param timeout + * 超时(单位:毫秒) + * + * @return Status.SUCCESS if the command was accepted and a coordinated failover is in progress + */ + default Status failover(final RedisNode server, final int timeout) { + Assert.isNull(server, "Redis server cloud not be null"); + return failover(server.getHost(), server.getPort(), timeout); + } + + /** + * This command will start a coordinated failover between the currently-connected-to master and one of its replicas + * + *

详情说明 https://redis.io/commands/failover/

+ * + * @param server + * Redis 主机 + * @param isForce + * 是否强制 + * @param timeout + * 超时(单位:毫秒) + * + * @return Status.SUCCESS if the command was accepted and a coordinated failover is in progress + */ + default Status failover(final RedisNode server, final boolean isForce, final int timeout) { + Assert.isNull(server, "Redis server cloud not be null"); + return failover(server.getHost(), server.getPort(), isForce, timeout); + } + + /** + * 获取最近一次 Redis 成功将数据保存到磁盘上的时间 + * + *

详情说明 http://redisdoc.com/persistence/lastsave.html

+ * + * @return 最近一次成功将数据保存到磁盘上的时间 + */ + default Date lastSaveAt() { + return new Date(lastSave()); + } + + /** + * 用于在 Redis 运行时动态地修改复制(replication)功能的行为; + * 可以将当前服务器转变为指定服务器的从属服务器(slave server) + * + *

详情说明 https://redis.io/commands/replicaof/

+ * + * @param host + * Redis Slave Server 主机地址 + * + * @return 总是返回 Status.SUCCESS + */ + default Status replicaOf(final String host) { + return replicaOf(host, RedisNode.DEFAULT_PORT); + } + + /** + * 可以在线修改当前服务器的复制设置 + * 如果当前服务器已经是副本服务器,会将当前服务器转变为某一服务器的副本服务器; + * 如果当前服务器已经是某个主服务器的副本服务器,那么将使当前服务器停止对原主服务器的同步,丢弃旧数据集,转而开始对新主服务器进行同步 + * + *

详情说明 https://redis.io/commands/replicaof/

+ * + * @param server + * Redis 主机 + * + * @return 操作结果 + */ + default Status replicaOf(final RedisNode server) { + Assert.isNull(server, "Redis server cloud not be null."); + return replicaOf(server.getHost(), server.getPort()); + } + + /** + * 用于在 Redis 运行时动态地修改复制(replication)功能的行为; + * 可以将当前服务器转变为指定服务器的从属服务器(slave server) + * + *

详情说明 http://redisdoc.com/replication/slaveof.html

+ * + * @param host + * Redis Slave Server 主机地址 + * + * @return 总是返回 Status.SUCCESS + */ + default Status slaveOf(final String host) { + return slaveOf(host, RedisNode.DEFAULT_PORT); + } + + /** + * 用于在 Redis 运行时动态地修改复制(replication)功能的行为; + * 可以将当前服务器转变为指定服务器的从属服务器(slave server) + * + *

详情说明 http://redisdoc.com/replication/slaveof.html

+ * + * @param server + * Redis Slave Server 主机地址 + * + * @return 总是返回 Status.SUCCESS + */ + default Status slaveOf(final RedisNode server) { + Assert.isNull(server, "Redis server cloud not be null."); + return replicaOf(server.getHost(), server.getPort()); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/SetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/SetOperations.java new file mode 100644 index 000000000..3d310cee6 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/SetOperations.java @@ -0,0 +1,1911 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.operations; + +import com.buession.core.type.TypeReference; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.SetCommands; + +import java.util.List; +import java.util.Set; + +/** + * 集合运算 + * + *

详情说明 http://redisdoc.com/set/index.html

+ * + * @author Yong.Teng + */ +public interface SetOperations extends SetCommands, RedisOperations { + + /** + * 将一个或多个 member 元素序列化后加入到集合 key 当中,已经存在于集合的 member 元素将被忽略 + * + *

详情说明 http://redisdoc.com/set/sadd.html

+ * + * @param key + * Key + * @param members + * 元素 + * @param + * 元素值类型 + * + * @return 被添加到集合中的新元素的数量,不包括被忽略的元素 + */ + Long sAdd(final String key, final V... members); + + /** + * 将一个或多个 member 元素序列化后加入到集合 key 当中,已经存在于集合的 member 元素将被忽略 + * + *

详情说明 http://redisdoc.com/set/sadd.html

+ * + * @param key + * Key + * @param members + * 元素 + * @param + * 元素值类型 + * + * @return 被添加到集合中的新元素的数量,不包括被忽略的元素 + */ + Long sAdd(final byte[] key, final V... members); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合之间的差集,并反序列为对象 + * + *

详情说明 http://redisdoc.com/set/sdiff.html

+ * + * @param keys + * 一个或多个 Key + * @param + * 值类型 + * + * @return 一个包含差集成员反序列化为对象的列表 + */ + Set sDiffObject(final String[] keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合之间的差集,并反序列为对象 + * + *

详情说明 http://redisdoc.com/set/sdiff.html

+ * + * @param keys + * 一个或多个 Key + * @param + * 值类型 + * + * @return 一个包含差集成员反序列化为对象的列表 + */ + Set sDiffObject(final byte[][] keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合之间的差集,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sdiff.html

+ * + * @param keys + * 一个或多个 Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 一个包含差集成员反序列化为对象的列表 + */ + Set sDiffObject(final String[] keys, final Class clazz); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合之间的差集,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sdiff.html

+ * + * @param keys + * 一个或多个 Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 一个包含差集成员反序列化为对象的列表 + */ + Set sDiffObject(final byte[][] keys, final Class clazz); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合之间的差集,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sdiff.html

+ * + * @param keys + * 一个或多个 Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 一个包含差集成员反序列化为对象的列表 + * + * @see TypeReference + */ + Set sDiffObject(final String[] keys, final TypeReference type); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合之间的差集,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sdiff.html

+ * + * @param keys + * 一个或多个 Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 一个包含差集成员反序列化为对象的列表 + * + * @see TypeReference + */ + Set sDiffObject(final byte[][] keys, final TypeReference type); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的交集,并反序列为对象 + * + *

详情说明 http://redisdoc.com/set/sinter.html

+ * + * @param keys + * 一个或多个 Key + * @param + * 值类型 + * + * @return 交集成员反序列化为对象的列表 + */ + Set sInterObject(final String[] keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的交集,并反序列为对象 + * + *

详情说明 http://redisdoc.com/set/sinter.html

+ * + * @param keys + * 一个或多个 Key + * @param + * 值类型 + * + * @return 交集成员反序列化为对象的列表 + */ + Set sInterObject(final byte[][] keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的交集,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sinter.html

+ * + * @param keys + * 一个或多个 Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 交集成员反序列化为对象的列表 + */ + Set sInterObject(final String[] keys, final Class clazz); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的交集,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sinter.html

+ * + * @param keys + * 一个或多个 Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 交集成员反序列化为对象的列表 + */ + Set sInterObject(final byte[][] keys, final Class clazz); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的交集,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sinter.html

+ * + * @param keys + * 一个或多个 Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 交集成员反序列化为对象的列表 + * + * @see TypeReference + */ + Set sInterObject(final String[] keys, final TypeReference type); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的交集,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sinter.html

+ * + * @param keys + * 一个或多个 Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 交集成员反序列化为对象的列表 + * + * @see TypeReference + */ + Set sInterObject(final byte[][] keys, final TypeReference type); + + /** + * 获取集合 key 中的所有成员反序列化后的对象 + * + *

详情说明 http://redisdoc.com/set/smembers.html

+ * + * @param key + * Key + * @param + * 元素值类型 + * + * @return 集合中的所有成员 + */ + Set sMembersObject(final String key); + + /** + * 获取集合 key 中的所有成员反序列化后的对象 + * + *

详情说明 http://redisdoc.com/set/smembers.html

+ * + * @param key + * Key + * @param + * 元素值类型 + * + * @return 集合中的所有成员 + */ + Set sMembersObject(final byte[] key); + + /** + * 获取集合 key 中的所有成员反序列化 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/smembers.html

+ * + * @param key + * Key + * @param clazz + * 元素值对象类 + * @param + * 元素值类型 + * + * @return 集合中的所有成员 + */ + Set sMembersObject(final String key, final Class clazz); + + /** + * 获取集合 key 中的所有成员反序列化 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/smembers.html

+ * + * @param key + * Key + * @param clazz + * 元素值对象类 + * @param + * 元素值类型 + * + * @return 集合中的所有成员 + */ + Set sMembersObject(final byte[] key, final Class clazz); + + /** + * 获取集合 key 中的所有成员反序列化 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/smembers.html

+ * + * @param key + * Key + * @param type + * 元素值类型引用 + * @param + * 元素值类型 + * + * @return 集合中的所有成员 + * + * @see TypeReference + */ + Set sMembersObject(final String key, final TypeReference type); + + /** + * 获取集合 key 中的所有成员反序列化 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/smembers.html

+ * + * @param key + * Key + * @param type + * 元素值类型引用 + * @param + * 元素值类型 + * + * @return 集合中的所有成员 + * + * @see TypeReference + */ + Set sMembersObject(final byte[] key, final TypeReference type); + + /** + * 移除并返回集合 key 中的一个随机元素反序列化后的对象 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * @param + * 元素值类型 + * + * @return 被移除的随机元素反序列化后的对象 + */ + V sPopObject(final String key); + + /** + * 移除并返回集合 key 中的一个随机元素反序列化后的对象 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * @param + * 元素值类型 + * + * @return 被移除的随机元素反序列化后的对象 + */ + V sPopObject(final byte[] key); + + /** + * 移除并返回集合 key 中的一个随机元素反序列化 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * @param clazz + * 元素值对象类 + * @param + * 元素值类型 + * + * @return 被移除的随机元素反序列化后的对象 + */ + V sPopObject(final String key, final Class clazz); + + /** + * 移除并返回集合 key 中的一个随机元素反序列化 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * @param clazz + * 元素值对象类 + * @param + * 元素值类型 + * + * @return 被移除的随机元素反序列化后的对象 + */ + V sPopObject(final byte[] key, final Class clazz); + + /** + * 移除并返回集合 key 中的一个随机元素反序列化 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * @param type + * 元素值类型引用 + * @param + * 元素值类型 + * + * @return 被移除的随机元素反序列化后的对象 + * + * @see TypeReference + */ + V sPopObject(final String key, final TypeReference type); + + /** + * 移除并返回集合 key 中的一个随机元素反序列化 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * @param type + * 元素值类型引用 + * @param + * 元素值类型 + * + * @return 被移除的随机元素反序列化后的对象 + * + * @see TypeReference + */ + V sPopObject(final byte[] key, final TypeReference type); + + /** + * 移除并返回集合 key 中的 count 个随机元素反序列化后的对象 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * @param count + * 返回删除元素个数 + * @param + * 元素值类型 + * + * @return 被移除的随机元素反序列化后的对象 + */ + Set sPopObject(final String key, final int count); + + /** + * 移除并返回集合 key 中的 count 个随机元素反序列化后的对象 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * @param count + * 返回删除元素个数 + * @param + * 元素值类型 + * + * @return 被移除的随机元素反序列化后的对象 + */ + Set sPopObject(final byte[] key, final int count); + + /** + * 移除并返回集合 key 中的 count 个随机元素反序列化 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * @param count + * 返回删除元素个数 + * @param clazz + * 元素值对象类 + * @param + * 元素值类型 + * + * @return 被移除的随机元素反序列化后的对象 + */ + Set sPopObject(final String key, final int count, final Class clazz); + + /** + * 移除并返回集合 key 中的 count 个随机元素反序列化 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * @param count + * 返回删除元素个数 + * @param clazz + * 元素值对象类 + * @param + * 元素值类型 + * + * @return 被移除的随机元素反序列化后的对象 + */ + Set sPopObject(final byte[] key, final int count, final Class clazz); + + /** + * 移除并返回集合 key 中的 count 个随机元素反序列化 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * @param count + * 返回删除元素个数 + * @param type + * 元素值类型引用 + * @param + * 元素值类型 + * + * @return 被移除的随机元素反序列化后的对象 + * + * @see TypeReference + */ + Set sPopObject(final String key, final int count, final TypeReference type); + + /** + * 移除并返回集合 key 中的 count 个随机元素反序列化 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/spop.html

+ * + * @param key + * Key + * @param count + * 返回删除元素个数 + * @param type + * 元素值类型引用 + * @param + * 元素值类型 + * + * @return 被移除的随机元素反序列化后的对象 + * + * @see TypeReference + */ + Set sPopObject(final byte[] key, final int count, final TypeReference type); + + /** + * 返回集合 key 中的一个随机元素,并反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * @param + * 元素值类型 + * + * @return 集合 key 中的一个随机元素,反序列化后的对象 + */ + V sRandMemberObject(final String key); + + /** + * 返回集合 key 中的一个随机元素,并反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * @param + * 元素值类型 + * + * @return 集合 key 中的一个随机元素,反序列化后的对象 + */ + V sRandMemberObject(final byte[] key); + + /** + * 返回集合 key 中的一个随机元素,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * @param clazz + * 元素值对象类 + * @param + * 元素值类型 + * + * @return 集合 key 中的一个随机元素,反序列化后的对象 + */ + V sRandMemberObject(final String key, final Class clazz); + + /** + * 返回集合 key 中的一个随机元素,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * @param clazz + * 元素值对象类 + * @param + * 元素值类型 + * + * @return 集合 key 中的一个随机元素,反序列化后的对象 + */ + V sRandMemberObject(final byte[] key, final Class clazz); + + /** + * 返回集合 key 中的一个随机元素,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * @param type + * 元素值类型引用 + * @param + * 元素值类型 + * + * @return 集合 key 中的一个随机元素,反序列化后的对象 + * + * @see TypeReference + */ + V sRandMemberObject(final String key, final TypeReference type); + + /** + * 返回集合 key 中的一个随机元素,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * @param type + * 元素值类型引用 + * @param + * 元素值类型 + * + * @return 集合 key 中的一个随机元素,反序列化后的对象 + * + * @see TypeReference + */ + V sRandMemberObject(final byte[] key, final TypeReference type); + + /** + * 返回集合 key 中的 count 个随机元素,并反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * @param + * 元素值类型 + * + * @return 集合 key 中的随机元素,反序列化后的对象列表 + */ + List sRandMemberObject(final String key, final int count); + + /** + * 返回集合 key 中的 count 个随机元素,并反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * @param + * 元素值类型 + * + * @return 集合 key 中的随机元素,反序列化后的对象列表 + */ + List sRandMemberObject(final byte[] key, final int count); + + /** + * 返回集合 key 中的 count 个随机元素,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * @param clazz + * 元素值对象类 + * @param + * 元素值类型 + * + * @return 集合 key 中的随机元素,反序列化后的对象列表 + */ + List sRandMemberObject(final String key, final int count, final Class clazz); + + /** + * 返回集合 key 中的 count 个随机元素,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * @param clazz + * 元素值对象类 + * @param + * 元素值类型 + * + * @return 集合 key 中的随机元素,反序列化后的对象列表 + */ + List sRandMemberObject(final byte[] key, final int count, final Class clazz); + + /** + * 返回集合 key 中的 count 个随机元素,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * @param type + * 元素值类型引用 + * @param + * 元素值类型 + * + * @return 集合 key 中的随机元素,序列化后的对象列表 + * + * @see TypeReference + */ + List sRandMemberObject(final String key, final int count, final TypeReference type); + + /** + * 返回集合 key 中的 count 个随机元素,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/srandmember.html

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * @param type + * 元素值类型引用 + * @param + * 元素值类型 + * + * @return 集合 key 中的随机元素,序列化后的对象列表 + * + * @see TypeReference + */ + List sRandMemberObject(final byte[] key, final int count, final TypeReference type); + + /** + * 移除集合 key 中的 member 序列化后的元素,不存在的 member 元素会被忽略 + * + *

详情说明 http://redisdoc.com/set/srem.html

+ * + * @param key + * Key + * @param member + * 元素 + * @param + * 元素值类型 + * + * @return 被成功移除的元素的数量,不包括被忽略的元素 + */ + Long sRem(final String key, final V member); + + /** + * 移除集合 key 中的 member 序列化后的元素,不存在的 member 元素会被忽略 + * + *

详情说明 http://redisdoc.com/set/srem.html

+ * + * @param key + * Key + * @param member + * 元素 + * @param + * 元素值类型 + * + * @return 被成功移除的元素的数量,不包括被忽略的元素 + */ + Long sRem(final byte[] key, final V member); + + /** + * 移除集合 key 中的一个或多个 member 序列化后的元素,不存在的 member 元素会被忽略 + * + *

详情说明 http://redisdoc.com/set/srem.html

+ * + * @param key + * Key + * @param members + * 一个或多个元素 + * @param + * 元素值类型 + * + * @return 被成功移除的元素的数量,不包括被忽略的元素 + */ + Long sRem(final String key, final V... members); + + /** + * 移除集合 key 中的一个或多个 member 序列化后的元素,不存在的 member 元素会被忽略 + * + *

详情说明 http://redisdoc.com/set/srem.html

+ * + * @param key + * Key + * @param members + * 一个或多个元素 + * @param + * 元素值类型 + * + * @return 被成功移除的元素的数量,不包括被忽略的元素 + */ + Long sRem(final byte[] key, final V... members); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final long cursor); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final long cursor); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final long cursor, final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final long cursor, final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final String key, final long cursor, final TypeReference type); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final byte[] key, final long cursor, final TypeReference type); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final String cursor); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final byte[] cursor); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final String cursor, final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final byte[] cursor, final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final String key, final String cursor, final TypeReference type); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final byte[] key, final byte[] cursor, final TypeReference type); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final long cursor, final String pattern); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final long cursor, final String pattern, + final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern, + final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final String key, final long cursor, final String pattern, + final TypeReference type); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern, + final TypeReference type); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final String cursor, final String pattern); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final String cursor, final String pattern, + final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final String key, final String cursor, final String pattern, + final TypeReference type); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, + final TypeReference type); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final long cursor, final int count); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final long cursor, final int count); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final long cursor, final int count, final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final long cursor, final int count, final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final String key, final long cursor, final int count, + final TypeReference type); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final byte[] key, final long cursor, final int count, + final TypeReference type); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final String cursor, final int count); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final byte[] cursor, final int count); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final String cursor, final int count, final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final byte[] cursor, final int count, final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final String key, final String cursor, final int count, + final TypeReference type); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final byte[] key, final byte[] cursor, final int count, + final TypeReference type); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final long cursor, final String pattern, final int count); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern, final int count); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final long cursor, final String pattern, final int count, + final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern, final int count, + final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final String key, final long cursor, final String pattern, final int count, + final TypeReference type); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern, final int count, + final TypeReference type); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final String cursor, final String pattern, final int count); + + /** + * 迭代集合键中的元素,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, final int count); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final String key, final String cursor, final String pattern, final int count, + final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + */ + ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, final int count, + final Class clazz); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param count + * 返回元素数量 + * @param pattern + * glob 风格的模式参数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final String key, final String cursor, final String pattern, final int count, + final TypeReference type); + + /** + * 迭代集合键中的元素,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sscan.html

+ * + * @param key + * Key + * @param cursor + * 游标 + * @param pattern + * glob 风格的模式参数 + * @param count + * 返回元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回的每个元素都是一个键值对 + * + * @see TypeReference + */ + ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, final int count, + final TypeReference type); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的并集,并反序列为对象 + * + *

详情说明 http://redisdoc.com/set/sunion.html

+ * + * @param keys + * 一个或多个 Key + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + Set sUnionObject(final String[] keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的并集,并反序列为对象 + * + *

详情说明 http://redisdoc.com/set/sunion.html

+ * + * @param keys + * 一个或多个 Key + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + Set sUnionObject(final byte[][] keys); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的并集,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sunion.html

+ * + * @param keys + * 一个或多个 Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + Set sUnionObject(final String[] keys, final Class clazz); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的并集,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sunion.html

+ * + * @param keys + * 一个或多个 Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + Set sUnionObject(final byte[][] keys, final Class clazz); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的并集,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sunion.html

+ * + * @param keys + * 一个或多个 Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + * + * @see TypeReference + */ + Set sUnionObject(final String[] keys, final TypeReference type); + + /** + * 获取一个集合的全部成员,该集合是所有给定集合的并集,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/set/sunion.html

+ * + * @param keys + * 一个或多个 Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + * + * @see TypeReference + */ + Set sUnionObject(final byte[][] keys, final TypeReference type); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/SortedSetOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/SortedSetOperations.java new file mode 100644 index 000000000..8e19b0d67 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/SortedSetOperations.java @@ -0,0 +1,3371 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.operations; + +import com.buession.core.builder.MapBuilder; +import com.buession.core.type.TypeReference; +import com.buession.redis.core.Aggregate; +import com.buession.redis.core.GtLt; +import com.buession.redis.core.NxXx; +import com.buession.redis.core.command.SortedSetCommands; + +import java.util.List; + +/** + * 有序集合运算 + * + *

详情说明 http://redisdoc.com/sorted_set/index.html

+ * + * @author Yong.Teng + */ +public interface SortedSetOperations extends SortedSetCommands, RedisOperations { + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final String key, final double score, final String member) { + return zAdd(key, MapBuilder.of(member, score)); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final byte[] key, final double score, final byte[] member) { + return zAdd(key, MapBuilder.of(member, score)); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final String key, final double score, final String member, final NxXx nxXx) { + return zAdd(key, MapBuilder.of(member, score), nxXx); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 http://redisdoc.com/sorted_set/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final byte[] key, final double score, final byte[] member, final NxXx nxXx) { + return zAdd(key, MapBuilder.of(member, score), nxXx); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final String key, final double score, final String member, final GtLt gtLt) { + return zAdd(key, MapBuilder.of(member, score), gtLt); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 http://redisdoc.com/sorted_set/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final byte[] key, final double score, final byte[] member, final GtLt gtLt) { + return zAdd(key, MapBuilder.of(member, score), gtLt); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final String key, final double score, final String member, final boolean ch) { + return zAdd(key, MapBuilder.of(member, score), ch); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 http://redisdoc.com/sorted_set/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final byte[] key, final double score, final byte[] member, final boolean ch) { + return zAdd(key, MapBuilder.of(member, score), ch); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final String key, final double score, final String member, final NxXx nxXx, final GtLt gtLt) { + return zAdd(key, MapBuilder.of(member, score), nxXx, gtLt); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 http://redisdoc.com/sorted_set/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final byte[] key, final double score, final byte[] member, final NxXx nxXx, final GtLt gtLt) { + return zAdd(key, MapBuilder.of(member, score), nxXx, gtLt); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final String key, final double score, final String member, final NxXx nxXx, final boolean ch) { + return zAdd(key, MapBuilder.of(member, score), nxXx, ch); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 http://redisdoc.com/sorted_set/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final byte[] key, final double score, final byte[] member, final NxXx nxXx, final boolean ch) { + return zAdd(key, MapBuilder.of(member, score), nxXx, ch); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final String key, final double score, final String member, final GtLt gtLt, final boolean ch) { + return zAdd(key, MapBuilder.of(member, score), gtLt, ch); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 http://redisdoc.com/sorted_set/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final byte[] key, final double score, final byte[] member, final GtLt gtLt, final boolean ch) { + return zAdd(key, MapBuilder.of(member, score), gtLt, ch); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final String key, final double score, final String member, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + return zAdd(key, MapBuilder.of(member, score), nxXx, gtLt, ch); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 http://redisdoc.com/sorted_set/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + default Long zAdd(final byte[] key, final double score, final byte[] member, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + return zAdd(key, MapBuilder.of(member, score), nxXx, gtLt, ch); + } + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final double score, final V member); + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final double score, final V member); + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final double score, final V member, final NxXx nxXx); + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final double score, final V member, final NxXx nxXx); + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final double score, final V member, final GtLt gtLt); + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final double score, final V member, final GtLt gtLt); + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final double score, final V member, final boolean ch); + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final double score, final V member, final boolean ch); + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final double score, final V member, final NxXx nxXx, final GtLt gtLt); + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final double score, final V member, final NxXx nxXx, final GtLt gtLt); + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final double score, final V member, final NxXx nxXx, final boolean ch); + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final double score, final V member, final NxXx nxXx, final boolean ch); + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final double score, final V member, final GtLt gtLt, final boolean ch); + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final double score, final V member, final GtLt gtLt, final boolean ch); + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final String key, final double score, final V member, final NxXx nxXx, final GtLt gtLt, + final boolean ch); + + /** + * 将元素及其 score 值加入到有序集 key 当中 + * + *

详情说明 https://www.redis.com.cn/commands/zadd.html

+ * + * @param key + * Key + * @param score + * score + * @param member + * 元素 + * @param nxXx + * 更新成员方式: + * 1)NxXx.NX:不更新存在的成员,只添加新成员 + * 2)NxXx.XX:仅更新存在的成员,不添加新成员 + * @param gtLt + * 更新新的分值方式: + * 1)GtLt.LT: 更新新的分值比当前分值小的成员,不存在则新增 + * 2)GtLt.GT: 更新新的分值比当前分值大的成员,不存在则新增 + * @param ch + * 是否返回变更成员的数量;变更的成员是指新增成员 和 score值更新的成员,命令指明的和之前 score 值相同的成员不计在内; + * 在通常情况下,ZADD返回值只计算新添加成员的数量 + * @param + * 元素值类型 + * + * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 + */ + Long zAdd(final byte[] key, final double score, final V member, final NxXx nxXx, final GtLt gtLt, + final boolean ch); + + /** + * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client + * + *

详情说明 https://redis.io/commands/zdiff/

+ * + * @param keys + * 一个或多个 Key + * @param + * 值类型 + * + * @return The result of the difference + */ + List zDiffObject(final String[] keys); + + /** + * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client + * + *

详情说明 https://redis.io/commands/zdiff/

+ * + * @param keys + * 一个或多个 Key + * @param + * 值类型 + * + * @return The result of the difference + */ + List zDiffObject(final byte[][] keys); + + /** + * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client + * + *

详情说明 https://redis.io/commands/zdiff/

+ * + * @param keys + * 一个或多个 Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return The result of the difference + */ + List zDiffObject(final String[] keys, final Class clazz); + + /** + * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client + * + *

详情说明 https://redis.io/commands/zdiff/

+ * + * @param keys + * 一个或多个 Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return The result of the difference + */ + List zDiffObject(final byte[][] keys, final Class clazz); + + /** + * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client + * + *

详情说明 https://redis.io/commands/zdiff/

+ * + * @param keys + * 一个或多个 Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return The result of the difference + * + * @see TypeReference + */ + List zDiffObject(final String[] keys, final TypeReference type); + + /** + * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client + * + *

详情说明 https://redis.io/commands/zdiff/

+ * + * @param keys + * 一个或多个 Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return The result of the difference + * + * @see TypeReference + */ + List zDiffObject(final byte[][] keys, final TypeReference type); + + /** + * 为有序集 key 的成员 member 的 score 值加上增量一 + * + * @param key + * Key + * @param member + * member 元素 + * + * @return member 成员的新 score 值 + */ + default Double zIncr(final String key, final String member) { + return zIncrBy(key, 1, member); + } + + /** + * 为有序集 key 的成员 member 的 score 值加上增量一 + * + * @param key + * Key + * @param member + * member 元素 + * + * @return member 成员的新 score 值 + */ + default Double zIncr(final byte[] key, final byte[] member) { + return zIncrBy(key, 1, member); + } + + /** + * 为有序集 key 的成员 member 的 score 值加上减量一 + * + * @param key + * Key + * @param member + * member 元素 + * + * @return member 成员的新 score 值 + */ + default Double zDecr(final String key, final String member) { + return zIncrBy(key, -1, member); + } + + /** + * 为有序集 key 的成员 member 的 score 值加上减量一 + * + * @param key + * Key + * @param member + * member 元素 + * + * @return member 成员的新 score 值 + */ + default Double zDecr(final byte[] key, final byte[] member) { + return zIncrBy(key, -1, member); + } + + /** + * 为有序集 key 的成员 member 的 score 值加上减量 increment + * + *

详情说明 http://redisdoc.com/sorted_set/zincrby.html

+ * + * @param key + * Key + * @param increment + * 增量 + * @param member + * member 元素 + * + * @return member 成员的新 score 值 + */ + default Double zDecrBy(final String key, final double increment, final String member) { + return zIncrBy(key, increment * -1, member); + } + + /** + * 为有序集 key 的成员 member 的 score 值加上减量 increment + * + *

详情说明 http://redisdoc.com/sorted_set/zincrby.html

+ * + * @param key + * Key + * @param increment + * 增量 + * @param member + * member 元素 + * + * @return member 成员的新 score 值 + */ + default Double zDecrBy(final byte[] key, final double increment, final byte[] member) { + return zIncrBy(key, increment * -1, member); + } + + /** + * 计算给定的一个或多个有序集合的交集,并反序列为对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + */ + List zInterObject(final String[] keys); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列为对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + */ + List zInterObject(final byte[][] keys); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + */ + List zInterObject(final String[] keys, final Class clazz); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + */ + List zInterObject(final byte[][] keys, final Class clazz); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 type 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + * + * @see TypeReference + */ + List zInterObject(final String[] keys, final TypeReference type); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 type 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + * + * @see TypeReference + */ + List zInterObject(final byte[][] keys, final TypeReference type); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + */ + List zInterObject(final String[] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + */ + List zInterObject(final byte[][] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + */ + List zInterObject(final String[] keys, final Aggregate aggregate, final Class clazz); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + */ + List zInterObject(final byte[][] keys, final Aggregate aggregate, final Class clazz); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + * + * @see TypeReference + */ + List zInterObject(final String[] keys, final Aggregate aggregate, final TypeReference type); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 type 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + * + * @see TypeReference + */ + List zInterObject(final byte[][] keys, final Aggregate aggregate, final TypeReference type); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + */ + List zInterObject(final String[] keys, final double[] weights); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + */ + List zInterObject(final byte[][] keys, final double[] weights); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + */ + List zInterObject(final String[] keys, final double[] weights, final Class clazz); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + */ + List zInterObject(final byte[][] keys, final double[] weights, final Class clazz); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 type 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + * + * @see TypeReference + */ + List zInterObject(final String[] keys, final double[] weights, final TypeReference type); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 type 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + * + * @see TypeReference + */ + List zInterObject(final byte[][] keys, final double[] weights, final TypeReference type); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param weights + * 每个给定有序集的乘法因子 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + */ + List zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param weights + * 每个给定有序集的乘法因子 + * @param + * 值类型 + * + * @return The result of intersection + */ + List zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param weights + * 每个给定有序集的乘法因子 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + */ + List zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final Class clazz); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param weights + * 每个给定有序集的乘法因子 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + */ + List zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final Class clazz); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 type 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param weights + * 每个给定有序集的乘法因子 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 有序集合的交集反序列为对象 + * + * @see TypeReference + */ + List zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type); + + /** + * 计算给定的一个或多个有序集合的交集,并反序列化为 type 指定的对象 + * + *

详情说明 https://redis.io/commands/zinter/

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * {@link Aggregate} + * @param weights + * 每个给定有序集的乘法因子 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return The result of intersection + * + * @see TypeReference + */ + List zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type); + + /** + * 返回有序集合 key 中的一个随机元素,并反序列为对象 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param + * 值类型 + * + * @return 有序集合 key 中的一个随机元素反序列化后的对象 + */ + V zRandMemberObject(final String key); + + /** + * 返回有序集合 key 中的一个随机元素,并反序列为对象 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param + * 值类型 + * + * @return 有序集合 key 中的一个随机元素反序列化后的对象 + */ + V zRandMemberObject(final byte[] key); + + /** + * 返回有序集合 key 中的一个随机元素,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 有序集合 key 中的一个随机元素反序列化后的对象 + */ + V zRandMemberObject(final String key, final Class clazz); + + /** + * 返回有序集合 key 中的一个随机元素,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 有序集合 key 中的一个随机元素反序列化后的对象 + */ + V zRandMemberObject(final byte[] key, final Class clazz); + + /** + * 返回有序集合 key 中的一个随机元素,并反序列化为 type 指定的对象 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 有序集合 key 中的一个随机元素反序列化后的对象 + * + * @see TypeReference + */ + V zRandMemberObject(final String key, final TypeReference type); + + /** + * 返回有序集合 key 中的一个随机元素,并反序列化为 type 指定的对象 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 有序集合 key 中的一个随机元素反序列化后的对象 + * + * @see TypeReference + */ + V zRandMemberObject(final byte[] key, final TypeReference type); + + /** + * 返回有序集合 key 中的 count 个随机元素,并反序列为对象 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * @param + * 值类型 + * + * @return 有序集合 key 中的随机元素反序列化后的对象 + */ + List zRandMemberObject(final String key, final int count); + + /** + * 返回有序集合 key 中的 count 个随机元素,并反序列为对象 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * @param + * 值类型 + * + * @return 有序集合 key 中的随机元素反序列化后的对象 + */ + List zRandMemberObject(final byte[] key, final int count); + + /** + * 返回有序集合 key 中的 count 个随机元素,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 有序集合 key 中的随机元素反序列化后的对象 + */ + List zRandMemberObject(final String key, final int count, final Class clazz); + + /** + * 返回有序集合 key 中的 count 个随机元素,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 有序集合 key 中的随机元素反序列化后的对象 + */ + List zRandMemberObject(final byte[] key, final int count, final Class clazz); + + /** + * 返回有序集合 key 中的 count 个随机元素,并反序列化为 type 指定的对象 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 有序集合 key 中的随机元素反序列化后的对象 + * + * @see TypeReference + */ + List zRandMemberObject(final String key, final int count, final TypeReference type); + + /** + * 返回有序集合 key 中的 count 个随机元素,并反序列化为 type 指定的对象 + * + *

详情说明 https://redis.io/commands/zrandmember/

+ * + * @param key + * Key + * @param count + * 需要返回的元素数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 有序集合 key 中的随机元素反序列化后的对象 + * + * @see TypeReference + */ + List zRandMemberObject(final byte[] key, final int count, final TypeReference type); + + /** + * 获取有序集 key 中,指定区间内的成员,并反序列为对象;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param + * 值类型 + * + * @return 指定区间内,反序列化为对象的有序集成员的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRangeObject(final String key, final long start, final long end); + + /** + * 获取有序集 key 中,指定区间内的成员,并反序列为对象;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param + * 值类型 + * + * @return 指定区间内,反序列化为对象的有序集成员的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRangeObject(final byte[] key, final long start, final long end); + + /** + * 获取有序集 key 中,指定区间内的成员,并反序列化为 clazz 指定的对象;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 指定区间内,反序列化为对象的有序集成员的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRangeObject(final String key, final long start, final long end, final Class clazz); + + /** + * 获取有序集 key 中,指定区间内的成员,并反序列化为 clazz 指定的对象;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 指定区间内,反序列化为对象的有序集成员的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRangeObject(final byte[] key, final long start, final long end, final Class clazz); + + /** + * 获取有序集 key 中,指定区间内的成员,并反序列化为 type 指定的对象;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 指定区间内,反序列化为对象的有序集成员的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + * + * @see TypeReference + */ + List zRangeObject(final String key, final long start, final long end, final TypeReference type); + + /** + * 获取有序集 key 中,指定区间内的成员,并反序列化为 type 指定的对象;其中成员的位置按 score 值递增(从小到大)来排序; + * 具有相同 score 值的成员按字典序来排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 指定区间内,反序列化为对象的有序集成员的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + * + * @see TypeReference + */ + List zRangeObject(final byte[] key, final long start, final long end, final TypeReference type); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列为对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内的成员反序列化为对象后的列表 + */ + List zRangeByLexObject(final String key, final double min, final double max); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列为对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内的成员反序列化为对象后的列表 + */ + List zRangeByLexObject(final byte[] key, final double min, final double max); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内的成员反序列化为对象后的列表 + */ + List zRangeByLexObject(final String key, final double min, final double max, final Class clazz); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内的成员反序列化为对象后的列表 + */ + List zRangeByLexObject(final byte[] key, final double min, final double max, final Class clazz); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内的成员反序列化为对象后的列表 + * + * @see TypeReference + */ + List zRangeByLexObject(final String key, final double min, final double max, final TypeReference type); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内的成员反序列化为对象后的列表 + * + * @see TypeReference + */ + List zRangeByLexObject(final byte[] key, final double min, final double max, final TypeReference type); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员,并反序列为对象; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRangeByScoreObject(final String key, final double min, final double max); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员,并反序列为对象; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRangeByScoreObject(final byte[] key, final double min, final double max); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员,并反序列化为 clazz 指定的对象; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRangeByScoreObject(final String key, final double min, final double max, final Class clazz); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员,并反序列化为 clazz 指定的对象; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRangeByScoreObject(final byte[] key, final double min, final double max, final Class clazz); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员,并反序列化为 type 指定的对象; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + * + * @see TypeReference + */ + List zRangeByScoreObject(final String key, final double min, final double max, final TypeReference type); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员,并反序列化为 type 指定的对象; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + * + * @see TypeReference + */ + List zRangeByScoreObject(final byte[] key, final double min, final double max, final TypeReference type); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员,并反序列为对象; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRangeByScoreObject(final String key, final double min, final double max, final long offset, + final int count); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员,并反序列为对象; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRangeByScoreObject(final byte[] key, final double min, final double max, final long offset, + final int count); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员,并反序列化为 clazz 指定的对象; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRangeByScoreObject(final String key, final double min, final double max, final long offset, + final int count, final Class clazz); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员,并反序列化为 clazz 指定的对象; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRangeByScoreObject(final byte[] key, final double min, final double max, final long offset, + final int count, final Class clazz); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员,并反序列化为 type 指定的对象; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + * + * @see TypeReference + */ + List zRangeByScoreObject(final String key, final double min, final double max, final long offset, + final int count, final TypeReference type); + + /** + * 获取有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员,并反序列化为 type 指定的对象; + * 有序集成员按 score 值递增(从小到大)次序排列,具有相同 score 值的成员按字典序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + * + * @see TypeReference + */ + List zRangeByScoreObject(final byte[] key, final double min, final double max, final long offset, + final int count, final TypeReference type); + + /** + * 移除有序集 key 中的成员,不存在的成员将被忽略 + * + *

详情说明 http://redisdoccom/sorted_set/zrem.html

+ * + * @param key + * Key + * @param member + * 成员 + * + * @return 被成功移除的成员的数量,不包括被忽略的成员 + */ + default long zRem(final String key, final String member) { + return zRem(key, new String[]{member}); + } + + /** + * 移除有序集 key 中的成员,不存在的成员将被忽略 + * + *

详情说明 http://redisdoccom/sorted_set/zrem.html

+ * + * @param key + * Key + * @param member + * 成员 + * + * @return 被成功移除的成员的数量,不包括被忽略的成员 + */ + default long zRem(final byte[] key, final byte[] member) { + return zRem(key, new byte[][]{member}); + } + + /** + * 获取有序集 key 中,指定区间内的成员,并反序列为对象;其中成员的位置按 score 值递减(从大到小)来排列; + * 具有相同 score 值的成员按字典序的逆序排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象后的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRevRangeObject(final String key, final long start, final long end); + + /** + * 获取有序集 key 中,指定区间内的成员,并反序列为对象;其中成员的位置按 score 值递减(从大到小)来排列; + * 具有相同 score 值的成员按字典序的逆序排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象后的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRevRangeObject(final byte[] key, final long start, final long end); + + /** + * 获取有序集 key 中,指定区间内的成员,并反序列化为 clazz 指定的对象;其中成员的位置按 score 值递减(从大到小)来排列; + * 具有相同 score 值的成员按字典序的逆序排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象后的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRevRangeObject(final String key, final long start, final long end, final Class clazz); + + /** + * 获取有序集 key 中,指定区间内的成员,并反序列化为 clazz 指定的对象;其中成员的位置按 score 值递减(从大到小)来排列; + * 具有相同 score 值的成员按字典序的逆序排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象后的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + */ + List zRevRangeObject(final byte[] key, final long start, final long end, final Class clazz); + + /** + * 获取有序集 key 中,指定区间内的成员,并反序列化为 type 指定的对象;其中成员的位置按 score 值递减(从大到小)来排列; + * 具有相同 score 值的成员按字典序的逆序排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象后的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + * + * @see TypeReference + */ + List zRevRangeObject(final String key, final long start, final long end, final TypeReference type); + + /** + * 获取有序集 key 中,指定区间内的成员,并反序列化为 type 指定的对象;其中成员的位置按 score 值递减(从大到小)来排列; + * 具有相同 score 值的成员按字典序的逆序排列; + * 也可以使用负数下标,以 -1 表示最后一个成员,-2 表示倒数第二个成员,以此类推 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrange.html

+ * + * @param key + * Key + * @param start + * 开始位置 + * @param end + * 结束位置 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象后的列表; + * 当 start 的值比有序集的最大下标还要大,或是 start > end 时,返回一个空列表; + * 当 end 参数的值比有序集的最大下标还要大时,最多返回到 end + * + * @see TypeReference + */ + List zRevRangeObject(final byte[] key, final long start, final long end, final TypeReference type); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列为对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内反序列化为对象后的成员列表 + */ + List zRevRangeByLexObject(final String key, final double min, final double max); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列为对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内反序列化为对象后的成员列表 + */ + List zRevRangeByLexObject(final byte[] key, final double min, final double max); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内反序列化为对象后的成员列表 + */ + List zRevRangeByLexObject(final String key, final double min, final double max, final Class clazz); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内反序列化为对象后的成员列表 + */ + List zRevRangeByLexObject(final byte[] key, final double min, final double max, final Class clazz); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内反序列化为对象后的成员列表 + * + * @see TypeReference + */ + List zRevRangeByLexObject(final String key, final double min, final double max, final TypeReference type); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内反序列化为对象后的成员列表 + * + * @see TypeReference + */ + List zRevRangeByLexObject(final byte[] key, final double min, final double max, final TypeReference type); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列为对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内反序列化为对象后的成员列表 + */ + List zRevRangeByLexObject(final String key, final double min, final double max, final long offset, + final int count); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列为对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内反序列化为对象后的成员列表 + */ + List zRevRangeByLexObject(final byte[] key, final double min, final double max, final long offset, + final int count); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内反序列化为对象后的成员列表 + */ + List zRevRangeByLexObject(final String key, final double min, final double max, final long offset, + final int count, final Class clazz); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内反序列化为对象后的成员列表 + */ + List zRevRangeByLexObject(final byte[] key, final double min, final double max, final long offset, + final int count, final Class clazz); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内反序列化为对象后的成员列表 + * + * @see TypeReference + */ + List zRevRangeByLexObject(final String key, final double min, final double max, final long offset, + final int count, final TypeReference type); + + /** + * 当有序集合的所有成员都具有相同的分值时,有序集合的元素会根据成员的字典序来进行排序, + * 而这个命令则可以返回给定的有序集合键 key 中,值介于 min 和 max 之间的成员,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/sorted_set/zrangebylex.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回个数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 包含了有序集合在指定范围内反序列化为对象后的成员列表 + * + * @see TypeReference + */ + List zRevRangeByLexObject(final byte[] key, final double min, final double max, final long offset, + final int count, final TypeReference type); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的所有的成员,并反序列为对象; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRevRangeByScoreObject(final String key, final double min, final double max); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的所有的成员,并反序列为对象; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRevRangeByScoreObject(final byte[] key, final double min, final double max); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的所有的成员,并反序列化为 clazz 指定的对象; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRevRangeByScoreObject(final String key, final double min, final double max, final Class clazz); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的所有的成员,并反序列化为 clazz 指定的对象; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRevRangeByScoreObject(final byte[] key, final double min, final double max, final Class clazz); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的所有的成员,并反序列化为 type 指定的对象; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + * + * @see TypeReference + */ + List zRevRangeByScoreObject(final String key, final double min, final double max, + final TypeReference type); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的所有的成员,并反序列化为 type 指定的对象; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + * + * @see TypeReference + */ + List zRevRangeByScoreObject(final byte[] key, final double min, final double max, + final TypeReference type); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的所有的成员,并反序列为对象; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回数量 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRevRangeByScoreObject(final String key, final double min, final double max, final long offset, + final int count); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的所有的成员,并反序列为对象; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回数量 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRevRangeByScoreObject(final byte[] key, final double min, final double max, final long offset, + final int count); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的所有的成员,并反序列化为 clazz 指定的对象; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRevRangeByScoreObject(final String key, final double min, final double max, final long offset, + final int count, final Class clazz); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的所有的成员,并反序列化为 clazz 指定的对象; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回数量 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + */ + List zRevRangeByScoreObject(final byte[] key, final double min, final double max, final long offset, + final int count, final Class clazz); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的所有的成员,并反序列化为 type 指定的对象; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + * + * @see TypeReference + */ + List zRevRangeByScoreObject(final String key, final double min, final double max, final long offset, + final int count, final TypeReference type); + + /** + * 获取有序集 key 中,score 值介于 min 和 max 之间(包括等于 min 或 max )的所有的成员,并反序列化为 type 指定的对象; + * 有序集成员按 score 值递减(从大到小)的次序排列; + * 具有相同 score 值的成员按字典序的逆序排列 + * + *

详情说明 http://redisdoc.com/sorted_set/zrevrangebyscore.html

+ * + * @param key + * Key + * @param min + * 最小 score + * @param max + * 最大 score + * @param offset + * 偏移量 + * @param count + * 返回数量 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 指定区间内,有序集成员反序列化为对象的列表 + * + * @see TypeReference + */ + List zRevRangeByScoreObject(final byte[] key, final double min, final double max, final long offset, + final int count, final TypeReference type); + + /** + * 计算给定的一个或多个有序集的并集,并反序列为对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param + * 值类型 + * + * @return 反序列化为对象后的集合并集 + */ + List zUnionObject(final String[] keys); + + /** + * 计算给定的一个或多个有序集的并集,并反序列为对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param + * 值类型 + * + * @return 反序列化为对象后的集合并集 + */ + List zUnionObject(final byte[][] keys); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 反序列化为对象后的集合并集 + */ + List zUnionObject(final String[] keys, final Class clazz); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 反序列化为对象后的集合并集 + */ + List zUnionObject(final byte[][] keys, final Class clazz); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 反序列化为对象后的集合并集 + * + * @see TypeReference + */ + List zUnionObject(final String[] keys, final TypeReference type); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 反序列化为对象后的集合并集 + * + * @see TypeReference + */ + List zUnionObject(final byte[][] keys, final TypeReference type); + + /** + * 计算给定的一个或多个有序集的并集,并反序列为对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + List zUnionObject(final String[] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集的并集,并反序列为对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + List zUnionObject(final byte[][] keys, final Aggregate aggregate); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + List zUnionObject(final String[] keys, final Aggregate aggregate, final Class clazz); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + List zUnionObject(final byte[][] keys, final Aggregate aggregate, final Class clazz); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + * + * @see TypeReference + */ + List zUnionObject(final String[] keys, final Aggregate aggregate, final TypeReference type); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + * + * @see TypeReference + */ + List zUnionObject(final byte[][] keys, final Aggregate aggregate, final TypeReference type); + + /** + * 计算给定的一个或多个有序集的并集,并反序列为对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + List zUnionObject(final String[] keys, final double[] weights); + + /** + * 计算给定的一个或多个有序集的并集,并反序列为对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + List zUnionObject(final byte[][] keys, final double[] weights); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + List zUnionObject(final String[] keys, final double[] weights, final Class clazz); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + List zUnionObject(final byte[][] keys, final double[] weights, final Class clazz); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + * + * @see TypeReference + */ + List zUnionObject(final String[] keys, final double[] weights, final TypeReference type); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param weights + * 每个给定有序集的乘法因子 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + * + * @see TypeReference + */ + List zUnionObject(final byte[][] keys, final double[] weights, final TypeReference type); + + /** + * 计算给定的一个或多个有序集的并集,并反序列为对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param weights + * 每个给定有序集的乘法因子 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + List zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights); + + /** + * 计算给定的一个或多个有序集的并集,并反序列为对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param weights + * 每个给定有序集的乘法因子 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + List zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param weights + * 每个给定有序集的乘法因子 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + List zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final Class clazz); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param weights + * 每个给定有序集的乘法因子 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + */ + List zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final Class clazz); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param weights + * 每个给定有序集的乘法因子 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + * + * @see TypeReference + */ + List zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type); + + /** + * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 + * + *

详情说明 https://www.redis.com.cn/commands/zunion.html

+ * + * @param keys + * 一个或多个 Key + * @param aggregate + * 并集的结果集的聚合方式 + * @param weights + * 每个给定有序集的乘法因子 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 并集成员反序列化为对象的列表 + * + * @see TypeReference + */ + List zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/StreamOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/StreamOperations.java new file mode 100644 index 000000000..793849246 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/StreamOperations.java @@ -0,0 +1,998 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.operations; + +import com.buession.core.collect.Arrays; +import com.buession.lang.Status; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamPending; +import com.buession.redis.core.command.StreamCommands; +import com.buession.redis.core.command.args.XAddArgument; +import com.buession.redis.core.command.args.XClaimArgument; + +import java.util.List; +import java.util.Map; + +/** + * Stream 命令 + * + *

详情说明 https://redis.io/commands/?group=stream

+ * + * @author Yong.Teng + * @since 2.0.0 + */ +public interface StreamOperations extends StreamCommands, RedisOperations { + + /** + * The XACK command removes one or multiple messages from the Pending Entries List (PEL) of a stream consumer group + * + *

详情说明 https://redis.io/commands/xack/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param ids + * 一个或多个 ID + * + * @return The command returns the number of messages successfully acknowledged + */ + default Long xAck(final String key, final String groupName, final String[] ids) { + final StreamEntryId[] streamEntryIds = Arrays.map(ids, StreamEntryId.class, StreamEntryId::new); + return xAck(key, groupName, streamEntryIds); + } + + /** + * The XACK command removes one or multiple messages from the Pending Entries List (PEL) of a stream consumer group + * + *

详情说明 https://redis.io/commands/xack/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param ids + * 一个或多个 ID + * + * @return The command returns the number of messages successfully acknowledged + */ + default Long xAck(final byte[] key, final byte[] groupName, final byte[][] ids) { + final StreamEntryId[] streamEntryIds = Arrays.map(ids, StreamEntryId.class, StreamEntryId::new); + return xAck(key, groupName, streamEntryIds); + } + + /** + * Appends the specified stream entry to the stream at the specified key. + * If the key does not exist, as a side effect of running this command the key is created with a stream value + * + *

详情说明 https://redis.io/commands/xadd/

+ * + * @param key + * Key + * @param id + * Id + * @param hash + * Hash + * + * @return {@link StreamEntryId} + */ + default StreamEntryId xAdd(final String key, final String id, final Map hash) { + return xAdd(key, new StreamEntryId(id), hash); + } + + /** + * Appends the specified stream entry to the stream at the specified key. + * If the key does not exist, as a side effect of running this command the key is created with a stream value + * + *

详情说明 https://redis.io/commands/xadd/

+ * + * @param key + * Key + * @param id + * Id + * @param hash + * Hash + * + * @return {@link StreamEntryId} + */ + default StreamEntryId xAdd(final byte[] key, byte[] id, final Map hash) { + return xAdd(key, new StreamEntryId(id), hash); + } + + /** + * Appends the specified stream entry to the stream at the specified key. + * If the key does not exist, as a side effect of running this command the key is created with a stream value + * + *

详情说明 https://redis.io/commands/xadd/

+ * + * @param key + * Key + * @param id + * Id + * @param hash + * Hash + * @param xAddArgument + * {@link XAddArgument} + * + * @return {@link StreamEntryId} + */ + default StreamEntryId xAdd(final String key, final String id, final Map hash, + final XAddArgument xAddArgument) { + return xAdd(key, new StreamEntryId(id), hash, xAddArgument); + } + + /** + * Appends the specified stream entry to the stream at the specified key. + * If the key does not exist, as a side effect of running this command the key is created with a stream value + * + *

详情说明 https://redis.io/commands/xadd/

+ * + * @param key + * Key + * @param id + * Id + * @param hash + * Hash + * @param xAddArgument + * {@link XAddArgument} + * + * @return {@link StreamEntryId} + */ + default StreamEntryId xAdd(final byte[] key, final byte[] id, final Map hash, + final XAddArgument xAddArgument) { + return xAdd(key, new StreamEntryId(id), hash, xAddArgument); + } + + /** + * In the context of a stream consumer group, this command changes the ownership of a pending message, + * so that the new owner is the consumer specified as the command argument + * + *

详情说明 https://redis.io/commands/xclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param ids + * 一个或多个 ID + * + * @return {@link StreamEntry} 列表 + */ + default List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final String[] ids) { + final StreamEntryId[] streamEntryIds = Arrays.map(ids, StreamEntryId.class, StreamEntryId::new); + return xClaim(key, groupName, consumerName, minIdleTime, streamEntryIds); + } + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntry} + */ + default Map> xAutoClaim(final String key, final String groupName, + final String consumerName, + final int minIdleTime, final String start) { + return xAutoClaim(key, groupName, consumerName, minIdleTime, new StreamEntryId(start)); + } + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntry} + */ + default Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, + final int minIdleTime, final byte[] start) { + return xAutoClaim(key, groupName, consumerName, minIdleTime, new StreamEntryId(start)); + } + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * @param count + * 数量 + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntry} + */ + default Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final String start, final int count) { + return xAutoClaim(key, groupName, consumerName, minIdleTime, new StreamEntryId(start), count); + } + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * @param count + * 数量 + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntry} + */ + default Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final byte[] start, final int count) { + return xAutoClaim(key, groupName, consumerName, minIdleTime, new StreamEntryId(start), count); + } + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntryId} + */ + default Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final String start) { + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, new StreamEntryId(start)); + } + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntryId} + */ + default Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final byte[] start) { + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, new StreamEntryId(start)); + } + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * @param count + * 数量 + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntryId} + */ + default Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final String start, final int count) { + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, new StreamEntryId(start), count); + } + + /** + * This command transfers ownership of pending stream entries that match the specified criteria + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param start + * greater ID than + * @param count + * 数量 + * + * @return {@link StreamEntryId} 和对应的 {@link StreamEntryId} + */ + default Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final byte[] start, final int count) { + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, new StreamEntryId(start), count); + } + + /** + * In the context of a stream consumer group, this command changes the ownership of a pending message, + * so that the new owner is the consumer specified as the command argument + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param ids + * 一个或多个 ID + * + * @return {@link StreamEntry} 列表 + */ + default List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final byte[][] ids) { + final StreamEntryId[] streamEntryIds = Arrays.map(ids, StreamEntryId.class, StreamEntryId::new); + return xClaim(key, groupName, consumerName, minIdleTime, streamEntryIds); + } + + + /** + * In the context of a stream consumer group, this command changes the ownership of a pending message, + * so that the new owner is the consumer specified as the command argument + * + *

详情说明 https://redis.io/commands/xclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param ids + * 一个或多个 ID + * @param xClaimArgument + * {@link XClaimArgument} + * + * @return {@link StreamEntry} 列表 + */ + default List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final String[] ids, final XClaimArgument xClaimArgument) { + final StreamEntryId[] streamEntryIds = Arrays.map(ids, StreamEntryId.class, StreamEntryId::new); + return xClaim(key, groupName, consumerName, minIdleTime, streamEntryIds, xClaimArgument); + } + + /** + * In the context of a stream consumer group, this command changes the ownership of a pending message, + * so that the new owner is the consumer specified as the command argument + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param ids + * 一个或多个 ID + * @param xClaimArgument + * {@link XClaimArgument} + * + * @return {@link StreamEntry} 列表 + */ + default List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final byte[][] ids, final XClaimArgument xClaimArgument) { + final StreamEntryId[] streamEntryIds = Arrays.map(ids, StreamEntryId.class, StreamEntryId::new); + return xClaim(key, groupName, consumerName, minIdleTime, streamEntryIds, xClaimArgument); + } + + /** + * In the context of a stream consumer group, this command changes the ownership of a pending message, + * so that the new owner is the consumer specified as the command argument + * + *

详情说明 https://redis.io/commands/xclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param ids + * 一个或多个 ID + * + * @return {@link StreamEntryId} 列表 + */ + default List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final String[] ids) { + final StreamEntryId[] streamEntryIds = Arrays.map(ids, StreamEntryId.class, StreamEntryId::new); + return xClaimJustId(key, groupName, consumerName, minIdleTime, streamEntryIds); + } + + /** + * In the context of a stream consumer group, this command changes the ownership of a pending message, + * so that the new owner is the consumer specified as the command argument + * + *

详情说明 https://redis.io/commands/xautoclaim/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param consumerName + * Consumer Name + * @param minIdleTime + * Min Idle Time + * @param ids + * 一个或多个 ID + * + * @return {@link StreamEntryId} 列表 + */ + default List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final byte[][] ids) { + final StreamEntryId[] streamEntryIds = Arrays.map(ids, StreamEntryId.class, StreamEntryId::new); + return xClaimJustId(key, groupName, consumerName, minIdleTime, streamEntryIds); + } + + /** + * Removes the specified entries from a stream, and returns the number of entries deleted + * + *

详情说明 https://redis.io/commands/xdel/

+ * + * @param key + * Key + * @param ids + * 一个或多个 ID + * + * @return The number of entries actually deleted + */ + default Long xDel(final String key, final String... ids) { + final StreamEntryId[] streamEntryIds = Arrays.map(ids, StreamEntryId.class, StreamEntryId::new); + return xDel(key, streamEntryIds); + } + + /** + * Removes the specified entries from a stream, and returns the number of entries deleted + * + *

详情说明 https://redis.io/commands/xdel/

+ * + * @param key + * Key + * @param ids + * 一个或多个 ID + * + * @return The number of entries actually deleted + */ + default Long xDel(final byte[] key, final byte[]... ids) { + final StreamEntryId[] streamEntryIds = Arrays.map(ids, StreamEntryId.class, StreamEntryId::new); + return xDel(key, streamEntryIds); + } + + /** + * This command creates a new consumer group uniquely identified by groupname for the stream stored at key + * + *

详情说明 https://redis.io/commands/xgroup-create/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param id + * ID + * @param makeStream + * Can use the optional MKSTREAM subcommand as the last argument after the id to automatically create the stream (with length of 0) + * + * @return 创建成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + default Status xGroupCreate(final String key, final String groupName, final String id, final boolean makeStream) { + return xGroupCreate(key, groupName, new StreamEntryId(id), makeStream); + } + + /** + * This command creates a new consumer group uniquely identified by groupname for the stream stored at key + * + *

详情说明 https://redis.io/commands/xgroup-create/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param id + * ID + * @param makeStream + * Can use the optional MKSTREAM subcommand as the last argument after the id to automatically create the stream (with length of 0) + * + * @return 创建成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + default Status xGroupCreate(final byte[] key, final byte[] groupName, final byte[] id, final boolean makeStream) { + return xGroupCreate(key, groupName, new StreamEntryId(id), makeStream); + } + + /** + * Normally, a consumer group's last delivered ID is set when the group is created with XGROUP CREATE + * + *

详情说明 https://redis.io/commands/xgroup-setid/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param id + * ID + * + * @return 销毁成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + default Status xGroupSetId(final String key, final String groupName, final String id) { + return xGroupSetId(key, groupName, new StreamEntryId(id)); + } + + /** + * Normally, a consumer group's last delivered ID is set when the group is created with XGROUP CREATE + * + *

详情说明 https://redis.io/commands/xgroup-setid/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param id + * ID + * + * @return 销毁成功,返回 Status.SUCCESS;否则,返回 Status.FAILURE + */ + default Status xGroupSetId(final byte[] key, final byte[] groupName, final byte[] id) { + return xGroupSetId(key, groupName, new StreamEntryId(id)); + } + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * + * @return {@link StreamPending} 列表 + */ + default List xPending(final String key, final String groupName, final String start, final String end, + final int count) { + return xPending(key, groupName, new StreamEntryId(start), new StreamEntryId(end), count); + } + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * + * @return {@link StreamPending} 列表 + */ + default List xPending(final byte[] key, final byte[] groupName, final byte[] start, final byte[] end, + final int count) { + return xPending(key, groupName, new StreamEntryId(start), new StreamEntryId(end), count); + } + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param minIdleTime + * Min Idle Time + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * + * @return {@link StreamPending} 列表 + */ + default List xPending(final String key, final String groupName, final long minIdleTime, + final String start, final String end, final int count) { + return xPending(key, groupName, minIdleTime, new StreamEntryId(start), new StreamEntryId(end), count); + } + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param minIdleTime + * Min Idle Time + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * + * @return {@link StreamPending} 列表 + */ + default List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final byte[] start, final byte[] end, final int count) { + return xPending(key, groupName, minIdleTime, new StreamEntryId(start), new StreamEntryId(end), count); + } + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * @param consumerName + * Consumer Name + * + * @return {@link StreamPending} 列表 + */ + default List xPending(final String key, final String groupName, final String start, + final String end, final int count, final String consumerName) { + return xPending(key, groupName, new StreamEntryId(start), new StreamEntryId(end), count, consumerName); + } + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * @param consumerName + * Consumer Name + * + * @return {@link StreamPending} 列表 + */ + default List xPending(final byte[] key, final byte[] groupName, final byte[] start, + final byte[] end, final int count, final byte[] consumerName) { + return xPending(key, groupName, new StreamEntryId(start), new StreamEntryId(end), count, consumerName); + } + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param minIdleTime + * Min Idle Time + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * @param consumerName + * Consumer Name + * + * @return {@link StreamPending} 列表 + */ + default List xPending(final String key, final String groupName, final long minIdleTime, + final String start, final String end, final int count, + final String consumerName) { + return xPending(key, groupName, minIdleTime, new StreamEntryId(start), new StreamEntryId(end), count, + consumerName); + } + + /** + * Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries + * + *

详情说明 https://redis.io/commands/xpending/

+ * + * @param key + * Key + * @param groupName + * Group Name + * @param minIdleTime + * Min Idle Time + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * @param consumerName + * Consumer Name + * + * @return {@link StreamPending} 列表 + */ + default List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final byte[] start, final byte[] end, final int count, + final byte[] consumerName) { + return xPending(key, groupName, minIdleTime, new StreamEntryId(start), new StreamEntryId(end), count, + consumerName); + } + + /** + * The command returns the stream entries matching a given range of IDs + * + *

详情说明 https://redis.io/commands/xrange/

+ * + * @param key + * Key + * @param start + * Start Id + * @param end + * End Id + * + * @return {@link StreamEntry} 列表 + */ + default List xRange(final String key, final String start, final String end) { + return xRange(key, new StreamEntryId(start), new StreamEntryId(end)); + } + + /** + * The command returns the stream entries matching a given range of IDs + * + *

详情说明 https://redis.io/commands/xrange/

+ * + * @param key + * Key + * @param start + * Start Id + * @param end + * End Id + * + * @return {@link StreamEntry} 列表 + */ + default List xRange(final byte[] key, final byte[] start, final byte[] end) { + return xRange(key, new StreamEntryId(start), new StreamEntryId(end)); + } + + /** + * The command returns the stream entries matching a given range of IDs + * + *

详情说明 https://redis.io/commands/xrange/

+ * + * @param key + * Key + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * + * @return {@link StreamEntry} 列表 + */ + default List xRange(final String key, final String start, final String end, final int count) { + return xRange(key, new StreamEntryId(start), new StreamEntryId(end), count); + } + + /** + * The command returns the stream entries matching a given range of IDs + * + *

详情说明 https://redis.io/commands/xrange/

+ * + * @param key + * Key + * @param start + * Start Id + * @param end + * End Id + * @param count + * 返回数量 + * + * @return {@link StreamEntry} 列表 + */ + default List xRange(final byte[] key, final byte[] start, final byte[] end, final int count) { + return xRange(key, new StreamEntryId(start), new StreamEntryId(end), count); + } + + /** + * This command is exactly like XRANGE, but with the notable difference of returning the entries in reverse order, + * and also taking the start-end range in reverse order: in XREVRANGE you need to state the end ID and later the start ID, + * and the command will produce all the element between (or exactly like) the two IDs, starting from the end side + * + *

详情说明 https://redis.io/commands/xrevrange/

+ * + * @param key + * Key + * @param end + * End Id + * @param start + * Start Id + * + * @return {@link StreamEntry} 列表 + */ + default List xRevRange(final String key, final String end, final String start) { + return xRevRange(key, new StreamEntryId(end), new StreamEntryId(start)); + } + + /** + * This command is exactly like XRANGE, but with the notable difference of returning the entries in reverse order, + * and also taking the start-end range in reverse order: in XREVRANGE you need to state the end ID and later the start ID, + * and the command will produce all the element between (or exactly like) the two IDs, starting from the end side + * + *

详情说明 https://redis.io/commands/xrevrange/

+ * + * @param key + * Key + * @param end + * End Id + * @param start + * Start Id + * + * @return {@link StreamEntry} 列表 + */ + default List xRevRange(final byte[] key, final byte[] end, final byte[] start) { + return xRevRange(key, new StreamEntryId(end), new StreamEntryId(start)); + } + + /** + * This command is exactly like XRANGE, but with the notable difference of returning the entries in reverse order, + * and also taking the start-end range in reverse order: in XREVRANGE you need to state the end ID and later the start ID, + * and the command will produce all the element between (or exactly like) the two IDs, starting from the end side + * + *

详情说明 https://redis.io/commands/xrevrange/

+ * + * @param key + * Key + * @param end + * End Id + * @param start + * Start Id + * @param count + * 返回数量 + * + * @return {@link StreamEntry} 列表 + */ + default List xRevRange(final String key, final String end, final String start, final int count) { + return xRevRange(key, new StreamEntryId(end), new StreamEntryId(start), count); + } + + /** + * This command is exactly like XRANGE, but with the notable difference of returning the entries in reverse order, + * and also taking the start-end range in reverse order: in XREVRANGE you need to state the end ID and later the start ID, + * and the command will produce all the element between (or exactly like) the two IDs, starting from the end side + * + *

详情说明 https://redis.io/commands/xrevrange/

+ * + * @param key + * Key + * @param end + * End Id + * @param start + * Start Id + * @param count + * 返回数量 + * + * @return {@link StreamEntry} 列表 + */ + default List xRevRange(final byte[] key, final byte[] end, final byte[] start, final int count) { + return xRevRange(key, new StreamEntryId(end), new StreamEntryId(start), count); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/StringOperations.java b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/StringOperations.java new file mode 100644 index 000000000..b7aa49cbb --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/core/operations/StringOperations.java @@ -0,0 +1,797 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.operations; + +import com.buession.core.type.TypeReference; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.core.command.StringCommands; +import com.buession.redis.core.command.args.GetExArgument; +import com.buession.redis.core.command.args.SetArgument; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * STRING 运算 + * + *

详情说明 http://redisdoc.com/string/index.html

+ * + * @author Yong.Teng + */ +public interface StringOperations extends StringCommands, RedisOperations { + + /** + * 获取键 key 相关联的字符串值,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/string/get.html

+ * + * @param key + * Key + * @param + * 值类型 + * + * @return 如果键 key 不存在,那么返回特殊值 null ;否则,返回键 key 的值; + * 如果键 key 的值并非字符串类型,那么抛出异常 + */ + V getObject(final String key); + + /** + * 获取键 key 相关联的字符串值,并将值反序列化为对象 + * + *

详情说明 http://redisdoc.com/string/get.html

+ * + * @param key + * Key + * @param + * 值类型 + * + * @return 如果键 key 不存在,那么返回特殊值 null ;否则,返回键 key 的值; + * 如果键 key 的值并非字符串类型,那么抛出异常 + */ + V getObject(final byte[] key); + + /** + * 获取键 key 相关联的字符串值,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/string/get.html

+ * + * @param key + * Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 如果键 key 不存在,那么返回特殊值 null ;否则,返回键 key 的值; + * 如果键 key 的值并非字符串类型,那么抛出异常 + */ + V getObject(final String key, final Class clazz); + + /** + * 获取键 key 相关联的字符串值,并将值反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/string/get.html

+ * + * @param key + * Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 如果键 key 不存在,那么返回特殊值 null ;否则,返回键 key 的值; + * 如果键 key 的值并非字符串类型,那么抛出异常 + */ + V getObject(final byte[] key, final Class clazz); + + /** + * 获取键 key 相关联的字符串值,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/string/get.html

+ * + * @param key + * Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 如果键 key 不存在,那么返回特殊值 null ;否则,返回键 key 的值; + * 如果键 key 的值并非字符串类型,那么抛出异常 + * + * @see TypeReference + */ + V getObject(final String key, final TypeReference type); + + /** + * 获取键 key 相关联的字符串值,并将值反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/string/get.html

+ * + * @param key + * Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 如果键 key 不存在,那么返回特殊值 null ;否则,返回键 key 的值; + * 如果键 key 的值并非字符串类型,那么抛出异常 + * + * @see TypeReference + */ + V getObject(final byte[] key, final TypeReference type); + + /** + * 获取键 key 的值反序列化后对象,并重置 key 的过期时间 + * + *

详情说明 https://redis.io/commands/getex/

+ * + * @param key + * Key + * @param getExArgument + * Key 过期时间参数 + * @param + * 值类型 + * + * @return 键 key 的值反序列化后对象 + */ + V getExObject(final String key, final GetExArgument getExArgument); + + /** + * 获取键 key 的值反序列化后对象,并重置 key 的过期时间 + * + *

详情说明 https://redis.io/commands/getex/

+ * + * @param key + * Key + * @param getExArgument + * Key 过期时间参数 + * @param + * 值类型 + * + * @return 键 key 的值反序列化后对象 + */ + V getExObject(final byte[] key, final GetExArgument getExArgument); + + /** + * 获取键 key 的值反序列化为 clazz 指定类型后的对象,并重置 key 的过期时间 + * + *

详情说明 https://redis.io/commands/getex/

+ * + * @param key + * Key + * @param getExArgument + * Key 过期时间参数 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 键 key 的值反序列化后对象 + */ + V getExObject(final String key, final GetExArgument getExArgument, final Class clazz); + + /** + * 获取键 key 的值反序列化为 clazz 指定类型后的对象,并重置 key 的过期时间 + * + *

详情说明 https://redis.io/commands/getex/

+ * + * @param key + * Key + * @param getExArgument + * Key 过期时间参数 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 键 key 的值反序列化后对象 + */ + V getExObject(final byte[] key, final GetExArgument getExArgument, final Class clazz); + + /** + * 获取键 key 的值反序列化为 type 指定类型后的对象,并重置 key 的过期时间 + * + *

详情说明 https://redis.io/commands/getex/

+ * + * @param key + * Key + * @param getExArgument + * Key 过期时间参数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 键 key 的值反序列化后对象 + * + * @see TypeReference + */ + V getExObject(final String key, final GetExArgument getExArgument, final TypeReference type); + + /** + * 获取键 key 的值反序列化为 type 指定类型后的对象,并重置 key 的过期时间 + * + *

详情说明 https://redis.io/commands/getex/

+ * + * @param key + * Key + * @param getExArgument + * Key 过期时间参数 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 键 key 的值反序列化后对象 + * + * @see TypeReference + */ + V getExObject(final byte[] key, final GetExArgument getExArgument, final TypeReference type); + + /** + * 将键 key 的值设为 value ,并返回键 key 在被设置之前的旧值反序列化后对象 + * + *

详情说明 http://redisdoc.com/string/getset.html

+ * + * @param key + * Key + * @param value + * 新值 + * @param + * 值类型 + * + * @return 键 key 的旧值反序列化后对象 + */ + V getSet(final String key, final V value); + + /** + * 将键 key 的值设为 value ,并返回键 key 在被设置之前的旧值反序列化后对象 + * + *

详情说明 http://redisdoc.com/string/getset.html

+ * + * @param key + * Key + * @param value + * 新值 + * @param + * 值类型 + * + * @return 键 key 的旧值反序列化后对象 + */ + V getSet(final byte[] key, final V value); + + /** + * 将键 key 的值设为 value ,并返回键 key 在被设置之前的旧值反序列化为 clazz 指定类型后的对象 + * + *

详情说明 http://redisdoc.com/string/getset.html

+ * + * @param key + * Key + * @param value + * 新值 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 键 key 的旧值反序列化后对象 + */ + V getSet(final String key, final V value, final Class clazz); + + /** + * 将键 key 的值设为 value ,并返回键 key 在被设置之前的旧值反序列化为 clazz 指定类型后的对象 + * + *

详情说明 http://redisdoc.com/string/getset.html

+ * + * @param key + * Key + * @param value + * 新值 + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 键 key 的旧值反序列化后对象 + */ + V getSet(final byte[] key, final V value, final Class clazz); + + /** + * 将键 key 的值设为 value ,并返回键 key 在被设置之前的旧值反序列化为 type 指定类型后的对象 + * + *

详情说明 http://redisdoc.com/string/getset.html

+ * + * @param key + * Key + * @param value + * 新值 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 键 key 的旧值反序列化后对象 + * + * @see TypeReference + */ + V getSet(final String key, final V value, final TypeReference type); + + /** + * 将键 key 的值设为 value ,并返回键 key 在被设置之前的旧值反序列化为 type 指定类型后的对象 + * + *

详情说明 http://redisdoc.com/string/getset.html

+ * + * @param key + * Key + * @param value + * 新值 + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 键 key 的旧值反序列化后对象 + * + * @see TypeReference + */ + V getSet(final byte[] key, final V value, final TypeReference type); + + /** + * 获取键 key 相关联的字符串值,并将值反序列化为对象;并删除该 key + * + *

详情说明 http://redisdoc.com/string/get.html

+ * + * @param key + * Key + * @param + * 值类型 + * + * @return 如果键 key 不存在,那么返回特殊值 null ;否则,返回键 key 的值; + * 如果键 key 的值并非字符串类型,那么抛出异常 + */ + V getDelObject(final String key); + + /** + * 获取键 key 相关联的字符串值,并将值反序列化为对象;并删除该 key + * + *

详情说明 http://redisdoc.com/string/get.html

+ * + * @param key + * Key + * @param + * 值类型 + * + * @return 如果键 key 不存在,那么返回特殊值 null ;否则,返回键 key 的值; + * 如果键 key 的值并非字符串类型,那么抛出异常 + */ + V getDelObject(final byte[] key); + + /** + * 获取键 key 相关联的字符串值,并将值反序列化为 clazz 指定的对象;并删除该 key + * + *

详情说明 https://redis.io/commands/getdel/

+ * + * @param key + * Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 如果键 key 不存在,那么返回特殊值 null ;否则,返回键 key 的值; + * 如果键 key 的值并非字符串类型,那么抛出异常 + */ + V getDelObject(final String key, final Class clazz); + + /** + * 获取键 key 相关联的字符串值,并将值反序列化为 clazz 指定的对象;并删除该 key + * + *

详情说明 https://redis.io/commands/getdel/

+ * + * @param key + * Key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 如果键 key 不存在,那么返回特殊值 null ;否则,返回键 key 的值; + * 如果键 key 的值并非字符串类型,那么抛出异常 + */ + V getDelObject(final byte[] key, final Class clazz); + + /** + * 获取键 key 相关联的字符串值,并将值反序列化为 type 指定的对象;并删除该 key + * + *

详情说明 https://redis.io/commands/getdel/

+ * + * @param key + * Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 如果键 key 不存在,那么返回特殊值 null ;否则,返回键 key 的值; + * 如果键 key 的值并非字符串类型,那么抛出异常 + * + * @see TypeReference + */ + V getDelObject(final String key, final TypeReference type); + + /** + * 获取键 key 相关联的字符串值,并将值反序列化为 type 指定的对象;并删除该 key + * + *

详情说明 https://redis.io/commands/getdel/

+ * + * @param key + * Key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 如果键 key 不存在,那么返回特殊值 null ;否则,返回键 key 的值; + * 如果键 key 的值并非字符串类型,那么抛出异常 + * + * @see TypeReference + */ + V getDelObject(final byte[] key, final TypeReference type); + + /** + * 获取给定的一个或多个字符串键的值,并反序列化为对象 + * + *

详情说明 http://redisdoc.com/string/mget.html

+ * + * @param keys + * 一个或多个 key + * @param + * 值类型 + * + * @return 返回一个列表,列表中包含了所有给定键的值的反序列化对象; + * 如果给定键不存在 那么这个键的值将以特殊值 null 表示 + */ + List mGetObject(final String... keys); + + /** + * 获取给定的一个或多个字符串键的值,并反序列化为对象 + * + *

详情说明 http://redisdoc.com/string/mget.html

+ * + * @param keys + * 一个或多个 key + * @param + * 值类型 + * + * @return 返回一个列表,列表中包含了所有给定键的值的反序列化对象; + * 如果给定键不存在 那么这个键的值将以特殊值 null 表示 + */ + List mGetObject(final byte[]... keys); + + /** + * 获取给定的一个或多个字符串键的值,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/string/mget.html

+ * + * @param keys + * 一个或多个 key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回一个列表,列表中包含了所有给定键的值的反序列化对象; + * 如果给定键不存在 那么这个键的值将以特殊值 null 表示 + */ + List mGetObject(final String[] keys, final Class clazz); + + /** + * 获取给定的一个或多个字符串键的值,并反序列化为 clazz 指定的对象 + * + *

详情说明 http://redisdoc.com/string/mget.html

+ * + * @param keys + * 一个或多个 key + * @param clazz + * 值对象类 + * @param + * 值类型 + * + * @return 返回一个列表,列表中包含了所有给定键的值的反序列化对象; + * 如果给定键不存在 那么这个键的值将以特殊值 null 表示 + */ + List mGetObject(final byte[][] keys, final Class clazz); + + /** + * 获取给定的一个或多个字符串键的值,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/string/mget.html

+ * + * @param keys + * 一个或多个 key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回一个列表,列表中包含了所有给定键的值的反序列化对象; + * 如果给定键不存在 那么这个键的值将以特殊值 null 表示 + * + * @see TypeReference + */ + List mGetObject(final String[] keys, final TypeReference type); + + /** + * 获取给定的一个或多个字符串键的值,并反序列化为 type 指定的对象 + * + *

详情说明 http://redisdoc.com/string/mget.html

+ * + * @param keys + * 一个或多个 key + * @param type + * 值类型引用 + * @param + * 值类型 + * + * @return 返回一个列表,列表中包含了所有给定键的值的反序列化对象; + * 如果给定键不存在 那么这个键的值将以特殊值 null 表示 + * + * @see TypeReference + */ + List mGetObject(final byte[][] keys, final TypeReference type); + + /** + * 同时为多个键设置值,如果某个给定键已经存在 那么将使用新值去覆盖旧值 + * + *

详情说明 http://redisdoc.com/string/mset.html

+ * + * @param values + * 键值对 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + default Status mSet(final List> values) { + if(values == null){ + return Status.FAILURE; + }else{ + Map data = new LinkedHashMap<>(values.size()); + + for(KeyValue v : values){ + data.put(v.getKey(), v.getValue()); + } + + return mSet(data); + } + } + + /** + * 当且仅当所有给定键都不存在时, 为所有给定键设置值 + * + *

详情说明 http://redisdoc.com/string/msetnx.html

+ * + * @param values + * 键值对 + * + * @return 当所有给定键都设置成功时,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + default Status mSetNx(final List> values) { + if(values == null){ + return Status.FAILURE; + }else{ + Map data = new LinkedHashMap<>(values.size()); + + for(KeyValue v : values){ + data.put(v.getKey(), v.getValue()); + } + + return mSetNx(data); + } + } + + /** + * 将键 key 的值设置为 value ,并将键 key 的生存时间设置为 lifetime; + * 如果键 key 已经存在,那么将覆盖已有的值 + * + *

详情说明 http://redisdoc.com/string/psetex.html

+ * + * @param key + * Key + * @param value + * 值 + * @param lifetime + * 生存时间(单秒:毫秒) + * @param + * 值类型 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status pSetEx(final String key, final V value, final int lifetime); + + /** + * 将键 key 的值设置为 value ,并将键 key 的生存时间设置为 lifetime; + * 如果键 key 已经存在,那么将覆盖已有的值 + * + *

详情说明 http://redisdoc.com/string/psetex.html

+ * + * @param key + * Key + * @param value + * 值 + * @param lifetime + * 生存时间(单秒:毫秒) + * @param + * 值类型 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status pSetEx(final byte[] key, final V value, final int lifetime); + + /** + * 将对象 value 序列化后关联到 key; + * 如果 key 已经持有其他值,SET 就覆写旧值,忽略类型 + * + *

详情说明 http://redisdoc.com/string/set.html

+ * + * @param key + * Key + * @param value + * 值 + * @param + * 值类型 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status set(final String key, final V value); + + /** + * 将对象 value 序列化后关联到 key; + * 如果 key 已经持有其他值,SET 就覆写旧值,忽略类型 + * + *

详情说明 http://redisdoc.com/string/set.html

+ * + * @param key + * Key + * @param value + * 值 + * @param + * 值类型 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status set(final byte[] key, final V value); + + /** + * 将字符串值 value 关联到 key; + * 如果 key 已经持有其他值,SET 就覆写旧值,忽略类型 + * + *

详情说明 http://redisdoc.com/string/set.html

+ * + * @param key + * Key + * @param value + * 值 + * @param setArgument + * 参数 + * @param + * 值类型 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status set(final String key, final V value, final SetArgument setArgument); + + /** + * 将字符串值 value 关联到 key; + * 如果 key 已经持有其他值,SET 就覆写旧值,忽略类型 + * + *

详情说明 http://redisdoc.com/string/set.html

+ * + * @param key + * Key + * @param value + * 值 + * @param setArgument + * 参数 + * @param + * 值类型 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status set(final byte[] key, final V value, final SetArgument setArgument); + + /** + * 将键 key 的值设置为 value ,并将键 key 的生存时间设置为 lifetime; + * 如果键 key 已经存在,那么将覆盖已有的值 + * + *

详情说明 http://redisdoc.com/string/setex.html

+ * + * @param key + * Key + * @param value + * 值 + * @param lifetime + * 生存时间(单秒:秒) + * @param + * 值类型 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status setEx(final String key, final V value, final int lifetime); + + /** + * 将键 key 的值设置为 value ,并将键 key 的生存时间设置为 lifetime; + * 如果键 key 已经存在,那么将覆盖已有的值 + * + *

详情说明 http://redisdoc.com/string/setex.html

+ * + * @param key + * Key + * @param value + * 值 + * @param lifetime + * 生存时间(单秒:秒) + * @param + * 值类型 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status setEx(final byte[] key, final V value, final int lifetime); + + /** + * 当键 key 不存在的情况下,将键 key 的值设置为 value + * + *

详情说明 http://redisdoc.com/string/setnx.html

+ * + * @param key + * Key + * @param value + * 值 + * @param + * 值类型 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status setNx(final String key, final V value); + + /** + * 当键 key 不存在的情况下,将键 key 的值设置为 value + * + *

详情说明 http://redisdoc.com/string/setnx.html

+ * + * @param key + * Key + * @param value + * 值 + * @param + * 值类型 + * + * @return 如果设置操作成功,返回 Status.SUCCESS;否则返回 Status.FAILURE + */ + Status setNx(final byte[] key, final V value); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/jedis/JedisClusterPipeline.java b/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/jedis/JedisClusterPipeline.java new file mode 100644 index 000000000..1586b87ad --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/jedis/JedisClusterPipeline.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.pipeline.jedis; + +import com.buession.core.utils.Assert; +import com.buession.redis.pipeline.Pipeline; + +import java.util.List; + +/** + * Jedis 集群模式管道 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class JedisClusterPipeline implements Pipeline { + + private final redis.clients.jedis.ClusterPipeline delegate; + + public JedisClusterPipeline(final redis.clients.jedis.ClusterPipeline pipeline) { + Assert.isNull(pipeline, "Redis Pipeline cloud not be null."); + this.delegate = pipeline; + } + + @Override + public void sync() { + delegate.sync(); + } + + @Override + public List syncAndReturnAll() { + return null; + } + + @Override + public void close() { + delegate.close(); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/jedis/JedisPipeline.java b/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/jedis/JedisPipeline.java new file mode 100644 index 000000000..ea97563ad --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/jedis/JedisPipeline.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.pipeline.jedis; + +import com.buession.core.utils.Assert; +import com.buession.redis.pipeline.Pipeline; + +import java.util.List; + +/** + * Jedis 单例、哨兵模式管道 + * + * @author Yong.Teng + */ +public class JedisPipeline implements Pipeline { + + private final redis.clients.jedis.Pipeline delegate; + + public JedisPipeline(final redis.clients.jedis.Pipeline pipeline) { + Assert.isNull(pipeline, "Redis Pipeline cloud not be null."); + this.delegate = pipeline; + } + + @Override + public void sync() { + delegate.sync(); + } + + @Override + public List syncAndReturnAll() { + return delegate.syncAndReturnAll(); + } + + @Override + public void close() { + delegate.close(); + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheRequest.java b/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/jedis/JedisPipelineProxy.java similarity index 75% rename from buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheRequest.java rename to buession-redis/src/main-tmp/java/com/buession/redis/pipeline/jedis/JedisPipelineProxy.java index b21974e39..c8718d352 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/apache/ApacheRequest.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/jedis/JedisPipelineProxy.java @@ -19,30 +19,25 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.httpclient.apache; +package com.buession.redis.pipeline.jedis; -import com.buession.httpclient.core.Request; -import org.apache.http.client.methods.HttpRequestBase; +import com.buession.redis.core.internal.jedis.JedisResult; +import com.buession.redis.pipeline.AbstractPipelineProxy; +import com.buession.redis.pipeline.Pipeline; /** - * Apache Http Client Request. + * Jedis 管道代理 * * @author Yong.Teng - * @since 2.3.0 + * @since 3.0.0 */ -public class ApacheRequest extends Request { +public class JedisPipelineProxy extends AbstractPipelineProxy> { - private HttpRequestBase httpRequest; - - public HttpRequestBase getHttpRequest(){ - return httpRequest; - } - - public void setHttpRequest(HttpRequestBase httpRequest){ - this.httpRequest = httpRequest; + public JedisPipelineProxy(final Pipeline target, final T object) { + super(target, object); } } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/jedis/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/jedis/package-info.java new file mode 100644 index 000000000..629905b82 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/jedis/package-info.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.pipeline.jedis; \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/lettuce/LettucePipeline.java b/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/lettuce/LettucePipeline.java new file mode 100644 index 000000000..412b71ef9 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/lettuce/LettucePipeline.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.pipeline.lettuce; + +import com.buession.core.utils.Assert; +import com.buession.redis.core.internal.lettuce.LettuceResult; +import com.buession.redis.exception.RedisPipelineException; +import com.buession.redis.pipeline.Pipeline; +import io.lettuce.core.LettuceFutures; +import io.lettuce.core.RedisFuture; +import io.lettuce.core.api.PipeliningFlushState; +import io.lettuce.core.api.StatefulConnection; +import io.lettuce.core.output.CommandOutput; +import io.lettuce.core.protocol.RedisCommand; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.Queue; +import java.util.concurrent.TimeUnit; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettucePipeline implements Pipeline { + + private final PipeliningFlushState flushState; + + private final StatefulConnection connection; + + private Queue> ppline; + + public LettucePipeline(final StatefulConnection connection, final PipeliningFlushState flushState) { + Assert.isNull(flushState, "Redis Pipeline cloud not be null."); + this.connection = connection; + this.flushState = flushState; + this.flushState.onOpen(connection); + } + + public LettucePipeline(final StatefulConnection connection, final PipeliningFlushState flushState + , final Queue> ppline) { + this(connection, flushState); + this.ppline = Optional.ofNullable(ppline).orElse(new LinkedList<>()); + } + + @Override + public void sync() { + List> futures = new ArrayList<>(ppline.size()); + + for(LettuceResult result : ppline){ + futures.add(result.getHolder()); + } + + try{ + boolean done = LettuceFutures.awaitAll(connection.getTimeout().toMillis(), TimeUnit.MILLISECONDS, + futures.toArray(new RedisFuture[futures.size()])); + + Exception problem = null; + + if(done){ + CommandOutput output; + + for(LettuceResult result : ppline){ + output = result.getHolder().getOutput(); + if(output.hasError()){ + Exception err = new RedisPipelineException(output.getError()); + if(problem == null){ + problem = err; + } + }else{ + result.get(); + } + } + } + + if(problem != null){ + throw new RedisPipelineException(problem.getMessage(), problem); + } + + if(done){ + return; + } + + throw new RedisPipelineException("Redis command timed out"); + }catch(Exception e){ + throw new RedisPipelineException(e); + } + } + + @Override + public List syncAndReturnAll() { + List> futures = new ArrayList<>(ppline.size()); + + for(LettuceResult result : ppline){ + futures.add(result.getHolder()); + } + + try{ + boolean done = LettuceFutures.awaitAll(connection.getTimeout().toMillis(), TimeUnit.MILLISECONDS, + futures.toArray(new RedisFuture[futures.size()])); + + List results = new ArrayList<>(futures.size()); + + Exception problem = null; + + if(done){ + CommandOutput output; + + for(LettuceResult result : ppline){ + output = result.getHolder().getOutput(); + if(output.hasError()){ + Exception err = new RedisPipelineException(output.getError()); + if(problem == null){ + problem = err; + } + results.add(err); + }else{ + try{ + results.add(result.get()); + }catch(Exception e){ + if(problem == null){ + problem = e; + } + results.add(e); + } + } + } + } + + if(problem != null){ + throw new RedisPipelineException(problem.getMessage(), problem); + } + + if(done){ + return results; + } + + throw new RedisPipelineException("Redis command timed out"); + }catch(Exception e){ + throw new RedisPipelineException(e); + } + } + + @Override + public void close() { + flushState.onClose(connection); + if(ppline != null){ + ppline.clear(); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/lettuce/LettucePipelineProxy.java b/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/lettuce/LettucePipelineProxy.java new file mode 100644 index 000000000..79127d633 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/lettuce/LettucePipelineProxy.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.pipeline.lettuce; + +import com.buession.redis.core.internal.lettuce.LettuceResult; +import com.buession.redis.pipeline.AbstractPipelineProxy; +import com.buession.redis.pipeline.Pipeline; + +/** + * Lettuce 管道代理 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettucePipelineProxy extends AbstractPipelineProxy> { + + public LettucePipelineProxy(final T object) { + super(null, object); + } + + public LettucePipelineProxy(final Pipeline target, final T object) { + super(target, object); + } + + @Override + public void setTarget(Pipeline target) { + super.setTarget(target); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/lettuce/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/lettuce/package-info.java new file mode 100644 index 000000000..43b559102 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/pipeline/lettuce/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.pipeline.lettuce; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/XAddArgumentConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/pubsub/jedis/DefaultBinaryJedisPubSub.java similarity index 56% rename from buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/XAddArgumentConverter.java rename to buession-redis/src/main-tmp/java/com/buession/redis/pubsub/jedis/DefaultBinaryJedisPubSub.java index 27d3aa9ce..bb289b911 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/XAddArgumentConverter.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/pubsub/jedis/DefaultBinaryJedisPubSub.java @@ -22,45 +22,52 @@ * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.redis.core.internal.convert.jedis.params; +package com.buession.redis.pubsub.jedis; -import com.buession.core.converter.Converter; -import com.buession.core.converter.mapper.PropertyMapper; -import com.buession.redis.core.command.StreamCommands; -import redis.clients.jedis.params.XAddParams; +import com.buession.core.utils.Assert; +import com.buession.redis.core.PubSubListener; +import redis.clients.jedis.BinaryJedisPubSub; /** - * {@link StreamCommands.XAddArgument} 转换为 jedis {@link XAddParams} - * * @author Yong.Teng - * @since 2.0.0 */ -public final class XAddArgumentConverter implements Converter { +public class DefaultBinaryJedisPubSub extends BinaryJedisPubSub { + + private final PubSubListener delegate; - public final static XAddArgumentConverter INSTANCE = new XAddArgumentConverter(); + public DefaultBinaryJedisPubSub(PubSubListener pubSubListener) { + Assert.isNull(pubSubListener, "Pubsub listener cloud not be null."); + this.delegate = pubSubListener; + } @Override - public XAddParams convert(final StreamCommands.XAddArgument source) { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - final XAddParams xAddParams = new XAddParams(); + public void onMessage(byte[] channel, byte[] message) { + delegate.onMessage(channel, message); + } - propertyMapper.from(source.getMaxLen()).to(xAddParams::maxLen); - propertyMapper.from(source.getMinId()).to(xAddParams::minId); - propertyMapper.from(source.getLimit()).to(xAddParams::limit); + @Override + public void onPMessage(byte[] pattern, byte[] channel, byte[] message) { + delegate.onPMessage(pattern, channel, message); + } - if(Boolean.TRUE.equals(source.isApproximateTrimming())){ - xAddParams.approximateTrimming(); - } + @Override + public void onSubscribe(byte[] channel, int subscribedChannels) { + delegate.onSubscribe(channel, subscribedChannels); + } - if(Boolean.TRUE.equals(source.isExactTrimming())){ - xAddParams.exactTrimming(); - } + @Override + public void onUnsubscribe(byte[] channel, int subscribedChannels) { + delegate.onUnsubscribe(channel, subscribedChannels); + } - if(Boolean.TRUE.equals(source.isNoMkStream())){ - xAddParams.noMkStream(); - } + @Override + public void onPUnsubscribe(byte[] pattern, int subscribedChannels) { + delegate.onPUnsubscribe(pattern, subscribedChannels); + } - return xAddParams; + @Override + public void onPSubscribe(byte[] pattern, int subscribedChannels) { + delegate.onPSubscribe(pattern, subscribedChannels); } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/SetArgumentConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/pubsub/jedis/DefaultJedisPubSub.java similarity index 55% rename from buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/SetArgumentConverter.java rename to buession-redis/src/main-tmp/java/com/buession/redis/pubsub/jedis/DefaultJedisPubSub.java index 99c7a658f..6b461d3b6 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/SetArgumentConverter.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/pubsub/jedis/DefaultJedisPubSub.java @@ -22,47 +22,57 @@ * | Copyright @ 2013-2023 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.redis.core.internal.convert.jedis.params; +package com.buession.redis.pubsub.jedis; -import com.buession.core.converter.Converter; -import com.buession.core.converter.mapper.PropertyMapper; -import com.buession.redis.core.NxXx; -import com.buession.redis.core.command.StringCommands; -import redis.clients.jedis.params.SetParams; - -import java.util.Objects; +import com.buession.core.utils.Assert; +import com.buession.redis.core.PubSubListener; +import redis.clients.jedis.JedisPubSub; /** - * {@link StringCommands.SetArgument} 转换为 jedis {@link SetParams} - * * @author Yong.Teng - * @since 2.0.0 */ -public final class SetArgumentConverter implements Converter { +public class DefaultJedisPubSub extends JedisPubSub { + + private final PubSubListener delegate; + + public DefaultJedisPubSub(PubSubListener pubSubListener) { + Assert.isNull(pubSubListener, "Pubsub listener cloud not be null."); + this.delegate = pubSubListener; + } - public final static SetArgumentConverter INSTANCE = new SetArgumentConverter(); + @Override + public void onMessage(String channel, String message) { + delegate.onMessage(channel, message); + } + + @Override + public void onPMessage(String pattern, String channel, String message) { + delegate.onPMessage(pattern, channel, message); + } @Override - public SetParams convert(final StringCommands.SetArgument source) { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - final SetParams setParams = new SetParams(); + public void onSubscribe(String channel, int subscribedChannels) { + delegate.onSubscribe(channel, subscribedChannels); + } - propertyMapper.from(source.getEx()).to(setParams::ex); - propertyMapper.from(source.getExAt()).to(setParams::exAt); - propertyMapper.from(source.getPx()).to(setParams::px); - propertyMapper.from(source.getPxAt()).to(setParams::pxAt); + @Override + public void onUnsubscribe(String channel, int subscribedChannels) { + delegate.onUnsubscribe(channel, subscribedChannels); + } - if(source.getNxXx() == NxXx.NX){ - setParams.nx(); - }else if(source.getNxXx() == NxXx.XX){ - setParams.xx(); - } + @Override + public void onPUnsubscribe(String pattern, int subscribedChannels) { + delegate.onPUnsubscribe(pattern, subscribedChannels); + } - if(Boolean.TRUE.equals(source.isKeepTtl())){ - setParams.keepttl(); - } + @Override + public void onPSubscribe(String pattern, int subscribedChannels) { + delegate.onPSubscribe(pattern, subscribedChannels); + } - return setParams; + @Override + public void onPong(String pattern) { + delegate.onPong(pattern); } } diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/transaction/AbstractTransactionProxy.java b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/AbstractTransactionProxy.java new file mode 100644 index 000000000..09823b9af --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/AbstractTransactionProxy.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.transaction; + +import com.buession.redis.core.FutureResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.stream.Collectors; + +/** + * 事务代理抽象类 + * + * @param + * 原生事务类型 + * @param + * 事务异步结果 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractTransactionProxy> implements TransactionProxy { + + private Transaction target; + + private final T object; + + private final Queue txResults = new LinkedList<>(); + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + public AbstractTransactionProxy(final Transaction target, final T object) { + //Assert.isNull(target, "Redis Transaction cloud not be null."); + this.target = target; + this.object = object; + } + + @Override + public T getObject() { + return object; + } + + @Override + public Queue getTxResults() { + return txResults; + } + + @Override + public List exec() { + logger.info("Redis transaction exec."); + target.exec(); + return txResults.stream().map((r)->r.convert(r.get())).collect(Collectors.toList()); + } + + @Override + public String discard() { + logger.info("Redis transaction discard."); + return target.discard(); + } + + @Override + public void close() { + logger.info("Redis pipeline close."); + txResults.clear(); + target.close(); + } + + protected void setTarget(Transaction target) { + this.target = target; + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/transaction/RedisTransactionSynchronizationAdapter.java b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/RedisTransactionSynchronizationAdapter.java new file mode 100644 index 000000000..9e0d90b86 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/RedisTransactionSynchronizationAdapter.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.transaction; + +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.client.connection.RedisConnectionFactory; +import com.buession.redis.client.connection.RedisConnectionHolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.transaction.support.TransactionSynchronization; +import org.springframework.transaction.support.TransactionSynchronizationAdapter; +import org.springframework.transaction.support.TransactionSynchronizationManager; + +import java.io.IOException; + +/** + * @author Yong.Teng + */ +public class RedisTransactionSynchronizationAdapter extends TransactionSynchronizationAdapter { + + private final RedisConnectionFactory factory; + + private final RedisConnectionHolder connectionHolder; + + private final RedisConnection connection; + + private final static Logger logger = LoggerFactory.getLogger(RedisTransactionSynchronizationAdapter.class); + + public RedisTransactionSynchronizationAdapter(final RedisConnectionFactory factory, final RedisConnectionHolder + connectionHolder, final RedisConnection connection){ + this.factory = factory; + this.connectionHolder = connectionHolder; + this.connection = connection; + } + + @Override + public void afterCompletion(final int status){ + try{ + switch(status){ + case TransactionSynchronization.STATUS_COMMITTED: + connection.exec(); + break; + case TransactionSynchronization.STATUS_ROLLED_BACK: + case TransactionSynchronization.STATUS_UNKNOWN: + connection.discard(); + break; + default: + connection.discard(); + break; + } + }finally{ + final String message = "Closing bound redisConnection after transaction completed with {}"; + logger.debug(message, status); + + connectionHolder.setTransactionSyncronisationActive(false); + try{ + connection.close(); + }catch(IOException e){ + logger.error(message + ", error: {}", status, e.getMessage()); + } + TransactionSynchronizationManager.unbindResource(factory); + } + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/transaction/TransactionProxy.java b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/TransactionProxy.java new file mode 100644 index 000000000..57c566ba2 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/TransactionProxy.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.transaction; + +import com.buession.redis.core.FutureResult; + +import java.util.Queue; + +/** + * 事务代理 + * + * @param + * 事务管道类型 + * @param + * 事务异步结果 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface TransactionProxy> extends Transaction { + + /** + * 返回原生事务实例 + * + * @return 原生事务实例 + */ + T getObject(); + + Queue getTxResults(); + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/transaction/TransactionUtils.java b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/TransactionUtils.java new file mode 100644 index 000000000..ddc34bdf0 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/TransactionUtils.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2022 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.transaction; + +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.client.connection.RedisConnectionFactory; +import com.buession.redis.client.connection.RedisConnectionHolder; +import org.springframework.transaction.support.TransactionSynchronizationManager; + +/** + * @author Yong.Teng + */ +public class TransactionUtils { + + private TransactionUtils(){ + } + + public static boolean isActualNonReadonlyTransactionActive(){ + return TransactionSynchronizationManager.isActualTransactionActive() && + !TransactionSynchronizationManager.isCurrentTransactionReadOnly(); + } + + public static void bindResource(final RedisConnectionFactory factory, + final RedisConnectionHolder connectionHolder){ + TransactionSynchronizationManager.bindResource(factory, connectionHolder); + } + + public static RedisConnectionHolder getResource(final RedisConnectionFactory factory){ + return (RedisConnectionHolder) TransactionSynchronizationManager.getResource(factory); + } + + public static RedisConnectionHolder unbindResourceIfPossible(final RedisConnectionFactory factory){ + return (RedisConnectionHolder) TransactionSynchronizationManager.unbindResourceIfPossible(factory); + } + + public static void registerSynchronization(final RedisConnectionFactory factory, + final RedisConnectionHolder connectionHolder, + final RedisConnection connection){ + TransactionSynchronizationManager.registerSynchronization(new RedisTransactionSynchronizationAdapter(factory, + connectionHolder, connection)); + } + + public static boolean isCurrentTransactionReadOnly(){ + return TransactionSynchronizationManager.isCurrentTransactionReadOnly(); + } + +} \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/transaction/jedis/JedisTransaction.java b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/jedis/JedisTransaction.java new file mode 100644 index 000000000..8ffbb88fd --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/jedis/JedisTransaction.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.transaction.jedis; + +import com.buession.core.utils.Assert; +import com.buession.redis.transaction.Transaction; + +import java.util.List; + +/** + * Jedis 事务 + * + * @author Yong.Teng + */ +public class JedisTransaction implements Transaction { + + private final redis.clients.jedis.Transaction delegate; + + public JedisTransaction(redis.clients.jedis.Transaction transaction) { + Assert.isNull(transaction, "Redis Transaction cloud not be null."); + this.delegate = transaction; + } + + @Override + public List exec() { + return delegate.exec(); + } + + @Override + public String discard() { + return delegate.discard(); + } + + @Override + public void close() { + delegate.close(); + } + +} \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/transaction/jedis/JedisTransactionProxy.java b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/jedis/JedisTransactionProxy.java new file mode 100644 index 000000000..adc34b1d8 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/jedis/JedisTransactionProxy.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.transaction.jedis; + +import com.buession.redis.core.internal.jedis.JedisResult; +import com.buession.redis.transaction.AbstractTransactionProxy; +import com.buession.redis.transaction.Transaction; + +/** + * Jedis 事务代理类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class JedisTransactionProxy + extends AbstractTransactionProxy> { + + public JedisTransactionProxy(final Transaction target, final redis.clients.jedis.Transaction object) { + super(target, object); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/transaction/jedis/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/jedis/package-info.java new file mode 100644 index 000000000..aa99b7878 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/jedis/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.transaction.jedis; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/TransactionResultConverter.java b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/lettuce/LettuceTransaction.java similarity index 59% rename from buession-redis/src/main/java/com/buession/redis/core/internal/convert/TransactionResultConverter.java rename to buession-redis/src/main-tmp/java/com/buession/redis/transaction/lettuce/LettuceTransaction.java index 9e6ffc116..6549b2e68 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/TransactionResultConverter.java +++ b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/lettuce/LettuceTransaction.java @@ -19,50 +19,53 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.redis.core.internal.convert; +package com.buession.redis.transaction.lettuce; -import com.buession.core.converter.Converter; import com.buession.core.utils.Assert; -import com.buession.redis.core.FutureResult; +import com.buession.redis.transaction.Transaction; +import io.lettuce.core.api.sync.RedisCommands; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import java.util.ArrayList; import java.util.List; -import java.util.Queue; +import java.util.stream.Collectors; /** - * 事务结果转换器 - * - * @param - * 事务结果类型 + * Lettuce 事务 * * @author Yong.Teng - * @since 1.2.0 + * @since 3.0.0 */ -public final class TransactionResultConverter implements Converter, List> { +public class LettuceTransaction implements Transaction { + + private final RedisCommands delegate; - private final Queue> txResults; + private final static Logger logger = LoggerFactory.getLogger(LettuceTransaction.class); - public TransactionResultConverter(Queue> txResults){ - this.txResults = txResults; + public LettuceTransaction(RedisCommands transaction) { + Assert.isNull(transaction, "Redis Transaction cloud not be null."); + this.delegate = transaction; } @Override - public List convert(final List rawResults){ - Assert.isTrue(rawResults.size() != txResults.size(), - "Incorrect number of transaction results. Expected: " + txResults.size() + " Actual: " + - rawResults.size()); - - List result = new ArrayList<>(rawResults.size()); + public List exec() { + logger.info("Redis transaction exec."); + return delegate.exec().stream().collect(Collectors.toList()); + } - for(Object rawResult : rawResults){ - FutureResult futureResult = txResults.remove(); - result.add(futureResult.convert(rawResult)); - } + @Override + public String discard() { + logger.info("Redis transaction discard."); + return delegate.discard(); + } - return result; + @Override + public void close() { + logger.info("Redis transaction close."); + //delegate.close(); } -} +} \ No newline at end of file diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/transaction/lettuce/LettuceTransactionProxy.java b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/lettuce/LettuceTransactionProxy.java new file mode 100644 index 000000000..48d0ae587 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/lettuce/LettuceTransactionProxy.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.transaction.lettuce; + +import com.buession.redis.core.internal.lettuce.LettuceResult; +import com.buession.redis.transaction.AbstractTransactionProxy; +import com.buession.redis.transaction.Transaction; +import io.lettuce.core.api.sync.RedisCommands; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceTransactionProxy + extends AbstractTransactionProxy, LettuceResult> { + + public LettuceTransactionProxy(final Transaction target, final RedisCommands object) { + super(target, object); + } + +} diff --git a/buession-redis/src/main-tmp/java/com/buession/redis/transaction/lettuce/package-info.java b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/lettuce/package-info.java new file mode 100644 index 000000000..f922efaf0 --- /dev/null +++ b/buession-redis/src/main-tmp/java/com/buession/redis/transaction/lettuce/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.transaction.lettuce; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/AbstractRedisTemplate.java b/buession-redis/src/main/java/com/buession/redis/AbstractRedisTemplate.java index 0e57ff60b..652082bc5 100644 --- a/buession-redis/src/main/java/com/buession/redis/AbstractRedisTemplate.java +++ b/buession-redis/src/main/java/com/buession/redis/AbstractRedisTemplate.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis; @@ -35,14 +35,14 @@ * @author Yong.Teng */ public abstract class AbstractRedisTemplate extends RedisAccessor implements BitMapCommands, ClusterCommands, - ConnectionCommands, GeoCommands, HashCommands, HyperLogLogCommands, KeyCommands, ListCommands, PubSubCommands, - ScriptingCommands, ServerCommands, SetCommands, SortedSetCommands, StreamCommands, StringCommands, - TransactionCommands { + ConnectionCommands, GenericCommand, GeoCommands, HashCommands, HyperLogLogCommands, KeyCommands, ListCommands, + PubSubCommands, ScriptingCommands, ServerCommands, SetCommands, SortedSetCommands, StreamCommands, + StringCommands, TransactionCommands { /** * 构造函数 */ - public AbstractRedisTemplate(){ + public AbstractRedisTemplate() { super(); } @@ -52,26 +52,26 @@ public AbstractRedisTemplate(){ * @param dataSource * 数据源 */ - public AbstractRedisTemplate(DataSource dataSource){ + public AbstractRedisTemplate(DataSource dataSource) { super(dataSource); } - protected final String rawKey(final String key){ + protected final String rawKey(final String key) { String prefix = getOptions().getPrefix(); return Validate.isEmpty(prefix) ? key : prefix.concat(key); } - protected final byte[] rawKey(byte[] key){ + protected final byte[] rawKey(byte[] key) { String prefix = getOptions().getPrefix(); return Validate.isEmpty(prefix) ? key : ByteUtils.concat(SafeEncoder.encode(prefix), key); } - protected final String[] rawKeys(final String[] keys){ + protected final String[] rawKeys(final String[] keys) { String prefix = getOptions().getPrefix(); return Validate.isEmpty(prefix) || Validate.isEmpty(keys) ? keys : Arrays.map(keys, String.class, this::rawKey); } - protected final byte[][] rawKeys(final byte[][] keys){ + protected final byte[][] rawKeys(final byte[][] keys) { String prefix = getOptions().getPrefix(); if(Validate.isEmpty(prefix) || Validate.isEmpty(keys)){ diff --git a/buession-redis/src/main/java/com/buession/redis/BaseRedisTemplate.java b/buession-redis/src/main/java/com/buession/redis/BaseRedisTemplate.java index d0800ec93..1cb344e24 100644 --- a/buession-redis/src/main/java/com/buession/redis/BaseRedisTemplate.java +++ b/buession-redis/src/main/java/com/buession/redis/BaseRedisTemplate.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis; @@ -28,43 +28,20 @@ import com.buession.lang.Geo; import com.buession.lang.KeyValue; import com.buession.lang.Status; -import com.buession.redis.client.connection.RedisConnection; import com.buession.redis.client.connection.datasource.DataSource; -import com.buession.redis.core.AclLog; import com.buession.redis.core.Aggregate; import com.buession.redis.core.BitCountOption; import com.buession.redis.core.BitOperation; -import com.buession.redis.core.BumpEpoch; -import com.buession.redis.core.Client; -import com.buession.redis.core.ClientReply; -import com.buession.redis.core.ClientType; -import com.buession.redis.core.ClientUnblockType; -import com.buession.redis.core.ClusterFailoverOption; -import com.buession.redis.core.ClusterInfo; -import com.buession.redis.core.ClusterRedisNode; -import com.buession.redis.core.ClusterResetOption; -import com.buession.redis.core.ClusterSetSlotOption; -import com.buession.redis.core.ClusterSlot; import com.buession.redis.core.Direction; import com.buession.redis.core.ExpireOption; import com.buession.redis.core.GeoRadius; import com.buession.redis.core.GeoUnit; import com.buession.redis.core.GtLt; -import com.buession.redis.core.Info; -import com.buession.redis.core.KeyedZSetElement; import com.buession.redis.core.ListPosition; -import com.buession.redis.core.MemoryStats; import com.buession.redis.core.MigrateOperation; -import com.buession.redis.core.Module; import com.buession.redis.core.NxXx; import com.buession.redis.core.ObjectEncoding; -import com.buession.redis.core.PubSubListener; -import com.buession.redis.core.RedisMonitor; -import com.buession.redis.core.RedisServerTime; -import com.buession.redis.core.Role; import com.buession.redis.core.ScanResult; -import com.buession.redis.core.FlushMode; -import com.buession.redis.core.SlowLog; import com.buession.redis.core.Stream; import com.buession.redis.core.StreamConsumer; import com.buession.redis.core.StreamEntry; @@ -75,9 +52,7 @@ import com.buession.redis.core.StreamPendingSummary; import com.buession.redis.core.Tuple; import com.buession.redis.core.Type; -import com.buession.redis.core.AclUser; import com.buession.redis.core.ZRangeBy; -import com.buession.redis.pipeline.Pipeline; import java.util.LinkedHashMap; import java.util.List; @@ -89,12 +64,12 @@ * * @author Yong.Teng */ -public class BaseRedisTemplate extends AbstractRedisTemplate { +public abstract class BaseRedisTemplate extends AbstractRedisTemplate { /** * 构造函数 */ - public BaseRedisTemplate(){ + public BaseRedisTemplate() { super(); } @@ -104,483 +79,196 @@ public BaseRedisTemplate(){ * @param dataSource * 数据源 */ - public BaseRedisTemplate(DataSource dataSource){ + public BaseRedisTemplate(DataSource dataSource) { super(dataSource); } @Override - public Long bitCount(final String key){ + public Long bitCount(final String key) { return execute((client)->client.bitMapOperations().bitCount(rawKey(key))); } @Override - public Long bitCount(final byte[] key){ + public Long bitCount(final byte[] key) { return execute((client)->client.bitMapOperations().bitCount(rawKey(key))); } @Override - public Long bitCount(final String key, final long start, final long end){ + public Long bitCount(final String key, final long start, final long end) { return execute((client)->client.bitMapOperations().bitCount(rawKey(key), start, end)); } @Override - public Long bitCount(final byte[] key, final long start, final long end){ + public Long bitCount(final byte[] key, final long start, final long end) { return execute((client)->client.bitMapOperations().bitCount(rawKey(key), start, end)); } @Override - public Long bitCount(final String key, final long start, final long end, final BitCountOption bitCountOption){ + public Long bitCount(final String key, final long start, final long end, final BitCountOption bitCountOption) { return execute((client)->client.bitMapOperations().bitCount(rawKey(key), start, end, bitCountOption)); } @Override - public Long bitCount(final byte[] key, final long start, final long end, final BitCountOption bitCountOption){ + public Long bitCount(final byte[] key, final long start, final long end, final BitCountOption bitCountOption) { return execute((client)->client.bitMapOperations().bitCount(rawKey(key), start, end, bitCountOption)); } @Override - public List bitField(final String key, final BitFieldArgument argument){ + public List bitField(final String key, final BitFieldArgument argument) { return execute((client)->client.bitMapOperations().bitField(rawKey(key), argument)); } @Override - public List bitField(final byte[] key, final BitFieldArgument argument){ + public List bitField(final byte[] key, final BitFieldArgument argument) { return execute((client)->client.bitMapOperations().bitField(rawKey(key), argument)); } - @Deprecated - @Override - public List bitField(final String key, final String... arguments){ - return execute((client)->client.bitMapOperations().bitField(rawKey(key), arguments)); - } - - @Deprecated - @Override - public List bitField(final byte[] key, final byte[]... arguments){ - return execute((client)->client.bitMapOperations().bitField(rawKey(key), arguments)); - } - @Override - public List bitFieldRo(final String key, final String... arguments){ + public List bitFieldRo(final String key, final String... arguments) { return execute((client)->client.bitMapOperations().bitFieldRo(rawKey(key), arguments)); } @Override - public List bitFieldRo(final byte[] key, final byte[]... arguments){ + public List bitFieldRo(final byte[] key, final byte[]... arguments) { return execute((client)->client.bitMapOperations().bitFieldRo(rawKey(key), arguments)); } @Override - public Long bitOp(final BitOperation operation, final String destKey, final String... keys){ + public Long bitOp(final BitOperation operation, final String destKey, final String... keys) { return execute((client)->client.bitMapOperations().bitOp(operation, rawKey(destKey), rawKeys(keys))); } @Override - public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys){ + public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys) { return execute((client)->client.bitMapOperations().bitOp(operation, rawKey(destKey), rawKeys(keys))); } @Override - public Long bitPos(final String key, final boolean value){ + public Long bitPos(final String key, final boolean value) { return execute((client)->client.bitMapOperations().bitPos(rawKey(key), value)); } @Override - public Long bitPos(final byte[] key, final boolean value){ + public Long bitPos(final byte[] key, final boolean value) { return execute((client)->client.bitMapOperations().bitPos(rawKey(key), value)); } @Override - public Long bitPos(final String key, final boolean value, final long start, final long end){ + public Long bitPos(final String key, final boolean value, final long start, final long end) { return execute((client)->client.bitMapOperations().bitPos(rawKey(key), value, start, end)); } @Override - public Long bitPos(final byte[] key, final boolean value, final long start, final long end){ + public Long bitPos(final byte[] key, final boolean value, final long start, final long end) { return execute((client)->client.bitMapOperations().bitPos(rawKey(key), value, start, end)); } @Override - public Boolean getBit(final String key, final long offset){ + public Boolean getBit(final String key, final long offset) { return execute((client)->client.bitMapOperations().getBit(rawKey(key), offset)); } @Override - public Boolean getBit(final byte[] key, final long offset){ + public Boolean getBit(final byte[] key, final long offset) { return execute((client)->client.bitMapOperations().getBit(rawKey(key), offset)); } @Override - public Boolean setBit(final String key, final long offset, final boolean value){ + public Boolean setBit(final String key, final long offset, final boolean value) { return execute((client)->client.bitMapOperations().setBit(rawKey(key), offset, value)); } @Override - public Boolean setBit(final byte[] key, final long offset, final boolean value){ + public Boolean setBit(final byte[] key, final long offset, final boolean value) { return execute((client)->client.bitMapOperations().setBit(rawKey(key), offset, value)); } @Override - public String clusterMyId(){ - return execute((client)->client.clusterOperations().clusterMyId()); - } - - @Override - public Status clusterAddSlots(final int... slots){ - return execute((client)->client.clusterOperations().clusterAddSlots(slots)); - } - - @Override - public List clusterSlots(){ - return execute((client)->client.clusterOperations().clusterSlots()); - } - - @Override - public Integer clusterCountFailureReports(final String nodeId){ - return execute((client)->client.clusterOperations().clusterCountFailureReports(nodeId)); - } - - @Override - public Integer clusterCountFailureReports(final byte[] nodeId){ - return execute((client)->client.clusterOperations().clusterCountFailureReports(nodeId)); - } - - @Override - public Long clusterCountKeysInSlot(final int slot){ - return execute((client)->client.clusterOperations().clusterCountKeysInSlot(slot)); - } - - @Override - public Status clusterDelSlots(final int... slots){ - return execute((client)->client.clusterOperations().clusterDelSlots(slots)); - } - - @Override - public Status clusterFlushSlots(){ - return execute((client)->client.clusterOperations().clusterFlushSlots()); - } - - @Override - public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption){ - return execute((client)->client.clusterOperations().clusterFailover(clusterFailoverOption)); - } - - @Override - public Status clusterForget(final String nodeId){ - return execute((client)->client.clusterOperations().clusterForget(nodeId)); - } - - @Override - public Status clusterForget(final byte[] nodeId){ - return execute((client)->client.clusterOperations().clusterForget(nodeId)); - } - - @Override - public List clusterGetKeysInSlot(final int slot, final long count){ - return execute((client)->client.clusterOperations().clusterGetKeysInSlot(slot, count)); - } - - @Override - public Long clusterKeySlot(final String key){ + public Long clusterKeySlot(final String key) { return execute((client)->client.clusterOperations().clusterKeySlot(rawKey(key))); } @Override - public Long clusterKeySlot(final byte[] key){ + public Long clusterKeySlot(final byte[] key) { return execute((client)->client.clusterOperations().clusterKeySlot(rawKey(key))); } @Override - public ClusterInfo clusterInfo(){ - return execute((client)->client.clusterOperations().clusterInfo()); - } - - @Override - public Status clusterMeet(final String ip, final int port){ - return execute((client)->client.clusterOperations().clusterMeet(ip, port)); - } - - @Override - public List clusterNodes(){ - return execute((client)->client.clusterOperations().clusterNodes()); - } - - @Override - public List clusterSlaves(final String nodeId){ - return execute((client)->client.clusterOperations().clusterSlaves(nodeId)); - } - - @Override - public List clusterSlaves(final byte[] nodeId){ - return execute((client)->client.clusterOperations().clusterSlaves(nodeId)); - } - - @Override - public List clusterReplicas(final String nodeId){ - return execute((client)->client.clusterOperations().clusterReplicas(nodeId)); - } - - @Override - public List clusterReplicas(final byte[] nodeId){ - return execute((client)->client.clusterOperations().clusterReplicas(nodeId)); - } - - @Override - public Status clusterReplicate(final String nodeId){ - return execute((client)->client.clusterOperations().clusterReplicate(nodeId)); - } - - @Override - public Status clusterReplicate(final byte[] nodeId){ - return execute((client)->client.clusterOperations().clusterReplicate(nodeId)); - } - - @Override - public Status clusterReset(){ - return execute((client)->client.clusterOperations().clusterReset()); - } - - @Override - public Status clusterReset(final ClusterResetOption clusterResetOption){ - return execute((client)->client.clusterOperations().clusterReset(clusterResetOption)); - } - - @Override - public Status clusterSaveConfig(){ - return execute((client)->client.clusterOperations().clusterSaveConfig()); - } - - @Override - public Status clusterSetConfigEpoch(final long configEpoch){ - return execute((client)->client.clusterOperations().clusterSetConfigEpoch(configEpoch)); - } - - @Override - public KeyValue clusterBumpEpoch(){ - return execute((client)->client.clusterOperations().clusterBumpEpoch()); - } - - @Override - public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId){ - return execute((client)->client.clusterOperations().clusterSetSlot(slot, setSlotOption, nodeId)); - } - - @Override - public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final byte[] nodeId){ - return execute((client)->client.clusterOperations().clusterSetSlot(slot, setSlotOption, nodeId)); - } - - @Override - public Status asking(){ - return execute((client)->client.clusterOperations().asking()); - } - - @Override - public Status readWrite(){ - return execute((client)->client.clusterOperations().readWrite()); - } - - @Override - public Status readOnly(){ - return execute((client)->client.clusterOperations().readOnly()); - } - - @Override - public Status auth(final String user, final String password){ - return execute((client)->client.connectionOperations().auth(user, password)); - } - - @Override - public Status auth(final byte[] user, final byte[] password){ - return execute((client)->client.connectionOperations().auth(user, password)); - } - - @Override - public Status auth(final String password){ - return execute((client)->client.connectionOperations().auth(password)); - } - - @Override - public Status auth(final byte[] password){ - return execute((client)->client.connectionOperations().auth(password)); - } - - @Override - public String echo(final String str){ - return execute((client)->client.connectionOperations().echo(str)); - } - - @Override - public byte[] echo(final byte[] str){ - return execute((client)->client.connectionOperations().echo(str)); - } - - @Override - public Status ping(){ - return execute((client)->client.connectionOperations().ping()); - } - - @Override - public Status reset(){ - return execute((client)->client.connectionOperations().reset()); - } - - @Override - public Status quit(){ - return execute((client)->client.connectionOperations().quit()); - } - - @Override - public Status select(final int db){ - return execute((client)->client.connectionOperations().select(db)); - } - - @Override - public Status clientCaching(final boolean isYes){ - return execute((client)->client.connectionOperations().clientCaching(isYes)); - } - - @Override - public Long clientId(){ - return execute((client)->client.connectionOperations().clientId()); - } - - @Override - public Status clientSetName(final String name){ - return execute((client)->client.connectionOperations().clientSetName(name)); - } - - @Override - public Status clientSetName(final byte[] name){ - return execute((client)->client.connectionOperations().clientSetName(name)); - } - - @Override - public String clientGetName(){ - return execute((client)->client.connectionOperations().clientGetName()); - } - - @Override - public Integer clientGetRedir(){ - return execute((client)->client.connectionOperations().clientGetRedir()); - } - - @Override - public List clientList(){ - return execute((client)->client.connectionOperations().clientList()); - } - - @Override - public List clientList(final ClientType clientType){ - return execute((client)->client.connectionOperations().clientList(clientType)); - } - - @Override - public Client clientInfo(){ - return execute((client)->client.connectionOperations().clientInfo()); - } - - @Override - public Status clientPause(final int timeout){ - return execute((client)->client.connectionOperations().clientPause(timeout)); - } - - @Override - public Status clientReply(final ClientReply option){ - return execute((client)->client.connectionOperations().clientReply(option)); - } - - @Override - public Status clientKill(final String host, final int port){ - return execute((client)->client.connectionOperations().clientKill(host, port)); - } - - @Override - public Status clientUnblock(final int clientId){ - return execute((client)->client.connectionOperations().clientUnblock(clientId)); - } - - @Override - public Status clientUnblock(final int clientId, final ClientUnblockType type){ - return execute((client)->client.connectionOperations().clientUnblock(clientId, type)); - } - - @Override - public Long geoAdd(final String key, final String member, final double longitude, final double latitude){ + public Long geoAdd(final String key, final String member, final double longitude, final double latitude) { return execute((client)->client.geoOperations().geoAdd(rawKey(key), member, longitude, latitude)); } @Override - public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude){ + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude) { return execute((client)->client.geoOperations().geoAdd(rawKey(key), member, longitude, latitude)); } @Override - public Long geoAdd(final String key, final Map memberCoordinates){ + public Long geoAdd(final String key, final Map memberCoordinates) { return execute((client)->client.geoOperations().geoAdd(rawKey(key), memberCoordinates)); } @Override - public Long geoAdd(final byte[] key, final Map memberCoordinates){ + public Long geoAdd(final byte[] key, final Map memberCoordinates) { return execute((client)->client.geoOperations().geoAdd(rawKey(key), memberCoordinates)); } @Override - public List geoHash(final String key, final String... members){ + public List geoHash(final String key, final String... members) { return execute((client)->client.geoOperations().geoHash(rawKey(key), members)); } @Override - public List geoHash(final byte[] key, final byte[]... members){ + public List geoHash(final byte[] key, final byte[]... members) { return execute((client)->client.geoOperations().geoHash(rawKey(key), members)); } @Override - public List geoPos(final String key, final String... members){ + public List geoPos(final String key, final String... members) { return execute((client)->client.geoOperations().geoPos(rawKey(key), members)); } @Override - public List geoPos(final byte[] key, final byte[]... members){ + public List geoPos(final byte[] key, final byte[]... members) { return execute((client)->client.geoOperations().geoPos(rawKey(key), members)); } @Override - public Double geoDist(final String key, final String member1, final String member2){ + public Double geoDist(final String key, final String member1, final String member2) { return execute((client)->client.geoOperations().geoDist(rawKey(key), member1, member2)); } @Override - public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2){ + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2) { return execute((client)->client.geoOperations().geoDist(rawKey(key), member1, member2)); } @Override - public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit){ + public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit) { return execute((client)->client.geoOperations().geoDist(rawKey(key), member1, member2, unit)); } @Override - public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit){ + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit) { return execute((client)->client.geoOperations().geoDist(rawKey(key), member1, member2, unit)); } @Override public List geoRadius(final String key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { return execute((client)->client.geoOperations().geoRadius(rawKey(key), longitude, latitude, radius, unit)); } @Override public List geoRadius(final byte[] key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { return execute((client)->client.geoOperations().geoRadius(rawKey(key), longitude, latitude, radius, unit)); } @Override public List geoRadius(final String key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { return execute((client)->client.geoOperations() .geoRadius(rawKey(key), longitude, latitude, radius, unit, geoRadiusArgument)); } @@ -588,27 +276,27 @@ public List geoRadius(final String key, final double longitude, final @Override public List geoRadius(final byte[] key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { return execute((client)->client.geoOperations() .geoRadius(rawKey(key), longitude, latitude, radius, unit, geoRadiusArgument)); } @Override public List geoRadiusRo(final String key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { return execute((client)->client.geoOperations().geoRadiusRo(rawKey(key), longitude, latitude, radius, unit)); } @Override public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { return execute((client)->client.geoOperations().geoRadiusRo(rawKey(key), longitude, latitude, radius, unit)); } @Override public List geoRadiusRo(final String key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { return execute((client)->client.geoOperations() .geoRadiusRo(rawKey(key), longitude, latitude, radius, unit, geoRadiusArgument)); } @@ -616,2999 +304,2524 @@ public List geoRadiusRo(final String key, final double longitude, fin @Override public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { return execute((client)->client.geoOperations() .geoRadiusRo(rawKey(key), longitude, latitude, radius, unit, geoRadiusArgument)); } @Override public List geoRadiusByMember(final String key, final String member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { return execute((client)->client.geoOperations().geoRadiusByMember(rawKey(key), member, radius, unit)); } @Override public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { return execute((client)->client.geoOperations().geoRadiusByMember(rawKey(key), member, radius, unit)); } @Override public List geoRadiusByMember(final String key, final String member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { return execute((client)->client.geoOperations() .geoRadiusByMember(rawKey(key), member, radius, unit, geoRadiusArgument)); } @Override public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { return execute((client)->client.geoOperations() .geoRadiusByMember(rawKey(key), member, radius, unit, geoRadiusArgument)); } @Override public List geoRadiusByMemberRo(final String key, final String member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { return execute((client)->client.geoOperations().geoRadiusByMemberRo(rawKey(key), member, radius, unit)); } @Override public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { return execute((client)->client.geoOperations().geoRadiusByMemberRo(rawKey(key), member, radius, unit)); } @Override public List geoRadiusByMemberRo(final String key, final String member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { return execute((client)->client.geoOperations() .geoRadiusByMemberRo(rawKey(key), member, radius, unit, geoRadiusArgument)); } @Override public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { return execute((client)->client.geoOperations() .geoRadiusByMemberRo(rawKey(key), member, radius, unit, geoRadiusArgument)); } @Override - public Long hDel(final String key, final String... fields){ + public Long hDel(final String key, final String... fields) { return execute((client)->client.hashOperations().hDel(rawKey(key), fields)); } @Override - public Long hDel(final byte[] key, final byte[]... fields){ + public Long hDel(final byte[] key, final byte[]... fields) { return execute((client)->client.hashOperations().hDel(rawKey(key), fields)); } @Override - public Boolean hExists(final String key, final String field){ + public Boolean hExists(final String key, final String field) { return execute((client)->client.hashOperations().hExists(rawKey(key), field)); } @Override - public Boolean hExists(final byte[] key, final byte[] field){ + public Boolean hExists(final byte[] key, final byte[] field) { return execute((client)->client.hashOperations().hExists(rawKey(key), field)); } @Override - public String hGet(final String key, final String field){ + public String hGet(final String key, final String field) { return execute((client)->client.hashOperations().hGet(rawKey(key), field)); } @Override - public byte[] hGet(final byte[] key, final byte[] field){ + public byte[] hGet(final byte[] key, final byte[] field) { return execute((client)->client.hashOperations().hGet(rawKey(key), field)); } @Override - public Map hGetAll(final String key){ + public Map hGetAll(final String key) { return execute((client)->client.hashOperations().hGetAll(rawKey(key))); } @Override - public Map hGetAll(final byte[] key){ + public Map hGetAll(final byte[] key) { return execute((client)->client.hashOperations().hGetAll(rawKey(key))); } @Override - public Long hIncrBy(final String key, final String field, final long value){ + public Long hIncrBy(final String key, final String field, final long value) { return execute((client)->client.hashOperations().hIncrBy(rawKey(key), field, value)); } @Override - public Long hIncrBy(final byte[] key, final byte[] field, final long value){ + public Long hIncrBy(final byte[] key, final byte[] field, final long value) { return execute((client)->client.hashOperations().hIncrBy(rawKey(key), field, value)); } @Override - public Double hIncrByFloat(final String key, final String field, final double value){ + public Double hIncrByFloat(final String key, final String field, final double value) { return execute((client)->client.hashOperations().hIncrByFloat(rawKey(key), field, value)); } @Override - public Double hIncrByFloat(final byte[] key, final byte[] field, final double value){ + public Double hIncrByFloat(final byte[] key, final byte[] field, final double value) { return execute((client)->client.hashOperations().hIncrByFloat(rawKey(key), field, value)); } @Override - public Set hKeys(final String key){ + public Set hKeys(final String key) { return execute((client)->client.hashOperations().hKeys(rawKey(key))); } @Override - public Set hKeys(final byte[] key){ + public Set hKeys(final byte[] key) { return execute((client)->client.hashOperations().hKeys(rawKey(key))); } @Override - public Long hLen(final String key){ + public Long hLen(final String key) { return execute((client)->client.hashOperations().hLen(rawKey(key))); } @Override - public Long hLen(final byte[] key){ + public Long hLen(final byte[] key) { return execute((client)->client.hashOperations().hLen(rawKey(key))); } @Override - public List hMGet(final String key, final String... fields){ + public List hMGet(final String key, final String... fields) { return execute((client)->client.hashOperations().hMGet(rawKey(key), fields)); } @Override - public List hMGet(final byte[] key, final byte[]... fields){ + public List hMGet(final byte[] key, final byte[]... fields) { return execute((client)->client.hashOperations().hMGet(rawKey(key), fields)); } @Override - public Status hMSet(final String key, final Map data){ + public Status hMSet(final String key, final Map data) { return execute((client)->client.hashOperations().hMSet(rawKey(key), data)); } @Override - public Status hMSet(final byte[] key, final Map data){ + public Status hMSet(final byte[] key, final Map data) { return execute((client)->client.hashOperations().hMSet(rawKey(key), data)); } @Override - public String hRandField(final String key){ + public String hRandField(final String key) { return execute((client)->client.hashOperations().hRandField(rawKey(key))); } @Override - public byte[] hRandField(final byte[] key){ + public byte[] hRandField(final byte[] key) { return execute((client)->client.hashOperations().hRandField(rawKey(key))); } @Override - public List hRandField(final String key, final long count){ + public List hRandField(final String key, final long count) { return execute((client)->client.hashOperations().hRandField(rawKey(key), count)); } @Override - public List hRandField(final byte[] key, final long count){ + public List hRandField(final byte[] key, final long count) { return execute((client)->client.hashOperations().hRandField(rawKey(key), count)); } @Override - public Map hRandFieldWithValues(final String key, final long count){ + public Map hRandFieldWithValues(final String key, final long count) { return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count)); } @Override - public Map hRandFieldWithValues(final byte[] key, final long count){ + public Map hRandFieldWithValues(final byte[] key, final long count) { return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count)); } @Override - public ScanResult> hScan(final String key, final long cursor){ + public ScanResult> hScan(final String key, final long cursor) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor)); } @Override - public ScanResult> hScan(final byte[] key, final long cursor){ + public ScanResult> hScan(final byte[] key, final long cursor) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor)); } @Override - public ScanResult> hScan(final String key, final String cursor){ + public ScanResult> hScan(final String key, final String cursor) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor)); } @Override - public ScanResult> hScan(final byte[] key, final byte[] cursor){ + public ScanResult> hScan(final byte[] key, final byte[] cursor) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor)); } @Override - public ScanResult> hScan(final String key, final long cursor, final String pattern){ + public ScanResult> hScan(final String key, final long cursor, final String pattern) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern)); } @Override - public ScanResult> hScan(final byte[] key, final long cursor, final byte[] pattern){ + public ScanResult> hScan(final byte[] key, final long cursor, final byte[] pattern) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern)); } @Override - public ScanResult> hScan(final String key, final String cursor, final String pattern){ + public ScanResult> hScan(final String key, final String cursor, final String pattern) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern)); } @Override - public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern){ + public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern)); } @Override - public ScanResult> hScan(final String key, final long cursor, final long count){ + public ScanResult> hScan(final String key, final long cursor, final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count)); } @Override - public ScanResult> hScan(final byte[] key, final long cursor, final long count){ + public ScanResult> hScan(final byte[] key, final long cursor, final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count)); } @Override - public ScanResult> hScan(final String key, final String cursor, final long count){ + public ScanResult> hScan(final String key, final String cursor, final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count)); } @Override - public ScanResult> hScan(final byte[] key, final byte[] cursor, final long count){ + public ScanResult> hScan(final byte[] key, final byte[] cursor, final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count)); } @Override public ScanResult> hScan(final String key, final long cursor, final String pattern, - final long count){ + final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count)); } @Override public ScanResult> hScan(final byte[] key, final long cursor, final byte[] pattern, - final long count){ + final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count)); } @Override public ScanResult> hScan(final String key, final String cursor, final String pattern, - final long count){ + final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count)); } @Override public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern, - final long count){ + final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count)); } @Override - public Long hSet(final String key, final String field, final String value){ + public Long hSet(final String key, final String field, final String value) { return execute((client)->client.hashOperations().hSet(rawKey(key), field, value)); } @Override - public Long hSet(final byte[] key, final byte[] field, final byte[] value){ + public Long hSet(final byte[] key, final byte[] field, final byte[] value) { return execute((client)->client.hashOperations().hSet(rawKey(key), field, value)); } @Override - public Status hSetNx(final String key, final String field, final String value){ + public Status hSetNx(final String key, final String field, final String value) { return execute((client)->client.hashOperations().hSetNx(rawKey(key), field, value)); } @Override - public Status hSetNx(final byte[] key, final byte[] field, final byte[] value){ + public Status hSetNx(final byte[] key, final byte[] field, final byte[] value) { return execute((client)->client.hashOperations().hSetNx(rawKey(key), field, value)); } @Override - public Long hStrLen(final String key, final String field){ + public Long hStrLen(final String key, final String field) { return execute((client)->client.hashOperations().hStrLen(rawKey(key), field)); } @Override - public Long hStrLen(final byte[] key, final byte[] field){ + public Long hStrLen(final byte[] key, final byte[] field) { return execute((client)->client.hashOperations().hStrLen(rawKey(key), field)); } @Override - public List hVals(final String key){ + public List hVals(final String key) { return execute((client)->client.hashOperations().hVals(rawKey(key))); } @Override - public List hVals(final byte[] key){ + public List hVals(final byte[] key) { return execute((client)->client.hashOperations().hVals(rawKey(key))); } @Override - public Status pfAdd(final String key, final String... elements){ + public Status pfAdd(final String key, final String... elements) { return execute((client)->client.hyperLogLogOperations().pfAdd(rawKey(key), elements)); } @Override - public Status pfAdd(final byte[] key, final byte[]... elements){ + public Status pfAdd(final byte[] key, final byte[]... elements) { return execute((client)->client.hyperLogLogOperations().pfAdd(rawKey(key), elements)); } @Override - public Status pfMerge(final String destKey, final String... keys){ + public Status pfMerge(final String destKey, final String... keys) { return execute((client)->client.hyperLogLogOperations().pfMerge(rawKey(destKey), rawKeys(keys))); } @Override - public Status pfMerge(final byte[] destKey, final byte[]... keys){ + public Status pfMerge(final byte[] destKey, final byte[]... keys) { return execute((client)->client.hyperLogLogOperations().pfMerge(rawKey(destKey), rawKeys(keys))); } @Override - public Long pfCount(final String... keys){ + public Long pfCount(final String... keys) { return execute((client)->client.hyperLogLogOperations().pfCount(rawKeys(keys))); } @Override - public Long pfCount(final byte[]... keys){ + public Long pfCount(final byte[]... keys) { return execute((client)->client.hyperLogLogOperations().pfCount(rawKeys(keys))); } @Override - public Long del(final String... keys){ + public Long del(final String... keys) { return execute((client)->client.keyOperations().del(rawKeys(keys))); } @Override - public Long del(final byte[]... keys){ + public Long del(final byte[]... keys) { return execute((client)->client.keyOperations().del(rawKeys(keys))); } @Override - public String dump(final String key){ + public String dump(final String key) { return execute((client)->client.keyOperations().dump(rawKey(key))); } @Override - public byte[] dump(final byte[] key){ + public byte[] dump(final byte[] key) { return execute((client)->client.keyOperations().dump(rawKey(key))); } @Override - public Boolean exists(final String key){ + public Boolean exists(final String key) { return execute((client)->client.keyOperations().exists(rawKey(key))); } @Override - public Boolean exists(final byte[] key){ + public Boolean exists(final byte[] key) { return execute((client)->client.keyOperations().exists(rawKey(key))); } @Override - public Long exists(final String... keys){ + public Long exists(final String... keys) { return execute((client)->client.keyOperations().exists(rawKeys(keys))); } @Override - public Long exists(final byte[]... keys){ + public Long exists(final byte[]... keys) { return execute((client)->client.keyOperations().exists(rawKeys(keys))); } @Override - public Status expire(final String key, final int lifetime){ + public Status expire(final String key, final int lifetime) { return execute((client)->client.keyOperations().expire(rawKey(key), lifetime)); } @Override - public Status expire(final byte[] key, final int lifetime){ + public Status expire(final byte[] key, final int lifetime) { return execute((client)->client.keyOperations().expire(rawKey(key), lifetime)); } @Override - public Status expire(final String key, final int lifetime, final ExpireOption expireOption){ + public Status expire(final String key, final int lifetime, final ExpireOption expireOption) { return execute((client)->client.keyOperations().expire(rawKey(key), lifetime, expireOption)); } @Override - public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption){ + public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption) { return execute((client)->client.keyOperations().expire(rawKey(key), lifetime, expireOption)); } @Override - public Status expireAt(final String key, final long unixTimestamp){ - return execute((client)->client.keyOperations().expireAt(rawKey(key), unixTimestamp)); - } - - @Override - public Status expireAt(final byte[] key, final long unixTimestamp){ + public Status expireAt(final String key, final long unixTimestamp) { return execute((client)->client.keyOperations().expireAt(rawKey(key), unixTimestamp)); } @Override - public Status pExpire(final String key, final int lifetime){ - return execute((client)->client.keyOperations().pExpire(rawKey(key), lifetime)); - } - - @Override - public Status pExpire(final byte[] key, final int lifetime){ - return execute((client)->client.keyOperations().pExpire(rawKey(key), lifetime)); - } - - @Override - public Status pExpireAt(final String key, final long unixTimestamp){ - return execute((client)->client.keyOperations().pExpireAt(rawKey(key), unixTimestamp)); - } - - @Override - public Status pExpireAt(final byte[] key, final long unixTimestamp){ - return execute((client)->client.keyOperations().pExpireAt(rawKey(key), unixTimestamp)); - } - - @Override - public Status persist(final String key){ - return execute((client)->client.keyOperations().persist(rawKey(key))); - } - - @Override - public Status persist(final byte[] key){ - return execute((client)->client.keyOperations().persist(rawKey(key))); - } - - @Override - public Long ttl(final String key){ - return execute((client)->client.keyOperations().ttl(rawKey(key))); - } - - @Override - public Long ttl(final byte[] key){ - return execute((client)->client.keyOperations().ttl(rawKey(key))); - } - - @Override - public Long pTtl(final String key){ - return execute((client)->client.keyOperations().pTtl(rawKey(key))); - } - - @Override - public Long pTtl(final byte[] key){ - return execute((client)->client.keyOperations().pTtl(rawKey(key))); - } - - @Override - public Status copy(final String key, final String destKey){ - return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey))); - } - - @Override - public Status copy(final byte[] key, final byte[] destKey){ - return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey))); - } - - @Override - public Status copy(final String key, final String destKey, final int db){ - return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), db)); - } - - @Override - public Status copy(final byte[] key, final byte[] destKey, final int db){ - return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), db)); - } - - @Override - public Status copy(final String key, final String destKey, final boolean replace){ - return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), replace)); - } - - @Override - public Status copy(final byte[] key, final byte[] destKey, final boolean replace){ - return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), replace)); - } - - @Override - public Status copy(final String key, final String destKey, final int db, final boolean replace){ - return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), db, replace)); - } - - @Override - public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace){ - return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), db, replace)); - } - - @Override - public Status move(final String key, final int db){ - return execute((client)->client.keyOperations().move(rawKey(key), db)); - } - - @Override - public Status move(final byte[] key, final int db){ - return execute((client)->client.keyOperations().move(rawKey(key), db)); - } - - @Override - public Status migrate(final String host, final int port, final int db, final int timeout, final String... keys){ - return execute((client)->client.keyOperations().migrate(host, port, db, timeout, rawKeys(keys))); - } - - @Override - public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... keys){ - return execute((client)->client.keyOperations().migrate(host, port, db, timeout, rawKeys(keys))); - } - - @Override - public Status migrate(final String host, final int port, final int db, final int timeout, - final MigrateOperation operation, final String... keys){ - return execute((client)->client.keyOperations().migrate(host, port, db, timeout, operation, rawKeys(keys))); - } - - @Override - public Status migrate(final String host, final int port, final int db, final int timeout, - final MigrateOperation operation, final byte[]... keys){ - return execute((client)->client.keyOperations().migrate(host, port, db, timeout, operation, rawKeys(keys))); - } - - @Override - public Status migrate(final String host, final int port, final int db, final String password, final int timeout, - final String... keys){ - return execute((client)->client.keyOperations().migrate(host, port, db, password, timeout, rawKeys(keys))); - } - - @Override - public Status migrate(final String host, final int port, final int db, final byte[] password, final int timeout, - final byte[]... keys){ - return execute((client)->client.keyOperations().migrate(host, port, db, password, timeout, rawKeys(keys))); - } - - @Override - public Status migrate(final String host, final int port, final int db, final String password, final int timeout, - final MigrateOperation operation, final String... keys){ - return execute( - (client)->client.keyOperations().migrate(host, port, db, password, timeout, operation, rawKeys(keys))); - } - - @Override - public Status migrate(final String host, final int port, final int db, final byte[] password, final int timeout, - final MigrateOperation operation, final byte[]... keys){ - return execute( - (client)->client.keyOperations().migrate(host, port, db, password, timeout, operation, rawKeys(keys))); - } - - @Override - public Status migrate(final String host, final int port, final int db, final String user, final String password, - final int timeout, final String... keys){ - return execute( - (client)->client.keyOperations().migrate(host, port, db, user, password, timeout, rawKeys(keys))); - } - - @Override - public Status migrate(final String host, final int port, final int db, final byte[] user, final byte[] password, - final int timeout, final byte[]... keys){ - return execute( - (client)->client.keyOperations().migrate(host, port, db, user, password, timeout, rawKeys(keys))); - } - - @Override - public Status migrate(final String host, final int port, final int db, final String user, final String password, - final int timeout, final MigrateOperation operation, final String... keys){ - return execute((client)->client.keyOperations() - .migrate(host, port, db, user, password, timeout, operation, rawKeys(keys))); - } - - @Override - public Status migrate(final String host, final int port, final int db, final byte[] user, final byte[] password, - final int timeout, final MigrateOperation operation, final byte[]... keys){ - return execute((client)->client.keyOperations() - .migrate(host, port, db, user, password, timeout, operation, rawKeys(keys))); - } - - @Override - public Set keys(final String pattern){ - return execute((client)->client.keyOperations().keys(pattern)); - } - - @Override - public Set keys(final byte[] pattern){ - return execute((client)->client.keyOperations().keys(pattern)); - } - - @Override - public String randomKey(){ - return execute((client)->client.keyOperations().randomKey()); - } - - @Override - public Status rename(final String key, final String newKey){ - return execute((client)->client.keyOperations().rename(rawKey(key), rawKey(newKey))); - } - - @Override - public Status rename(final byte[] key, final byte[] newKey){ - return execute((client)->client.keyOperations().rename(rawKey(key), rawKey(newKey))); - } - - @Override - public Status renameNx(final String key, final String newKey){ - return execute((client)->client.keyOperations().renameNx(rawKey(key), rawKey(newKey))); - } - - @Override - public Status renameNx(final byte[] key, final byte[] newKey){ - return execute((client)->client.keyOperations().renameNx(rawKey(key), rawKey(newKey))); - } - - @Override - public Status restore(final String key, final byte[] serializedValue, final int ttl){ - return execute((client)->client.keyOperations().restore(rawKey(key), serializedValue, ttl)); - } - - @Override - public Status restore(final byte[] key, final byte[] serializedValue, final int ttl){ - return execute((client)->client.keyOperations().restore(rawKey(key), serializedValue, ttl)); - } - - @Override - public Status restore(final String key, final byte[] serializedValue, final int ttl, - final RestoreArgument argument){ - return execute((client)->client.keyOperations().restore(rawKey(key), serializedValue, ttl, argument)); - } - - @Override - public Status restore(final byte[] key, final byte[] serializedValue, final int ttl, - final RestoreArgument argument){ - return execute((client)->client.keyOperations().restore(rawKey(key), serializedValue, ttl, argument)); - } - - @Override - public ScanResult> scan(final long cursor){ - return execute((client)->client.keyOperations().scan(cursor)); - } - - @Override - public ScanResult> scan(final String cursor){ - return execute((client)->client.keyOperations().scan(cursor)); - } - - @Override - public ScanResult> scan(final byte[] cursor){ - return execute((client)->client.keyOperations().scan(cursor)); - } - - @Override - public ScanResult> scan(final long cursor, final String pattern){ - return execute((client)->client.keyOperations().scan(cursor, pattern)); - } - - @Override - public ScanResult> scan(final long cursor, final byte[] pattern){ - return execute((client)->client.keyOperations().scan(cursor, pattern)); - } - - @Override - public ScanResult> scan(final String cursor, final String pattern){ - return execute((client)->client.keyOperations().scan(cursor, pattern)); - } - - @Override - public ScanResult> scan(final byte[] cursor, final byte[] pattern){ - return execute((client)->client.keyOperations().scan(cursor, pattern)); - } - - @Override - public ScanResult> scan(final long cursor, final long count){ - return execute((client)->client.keyOperations().scan(cursor, count)); - } - - @Override - public ScanResult> scan(final String cursor, final long count){ - return execute((client)->client.keyOperations().scan(cursor, count)); - } - - @Override - public ScanResult> scan(final byte[] cursor, final long count){ - return execute((client)->client.keyOperations().scan(cursor, count)); - } - - @Override - public ScanResult> scan(final long cursor, final String pattern, final long count){ - return execute((client)->client.keyOperations().scan(cursor, pattern, count)); - } - - @Override - public ScanResult> scan(final long cursor, final byte[] pattern, final long count){ - return execute((client)->client.keyOperations().scan(cursor, pattern, count)); - } - - @Override - public ScanResult> scan(final String cursor, final String pattern, final long count){ - return execute((client)->client.keyOperations().scan(cursor, pattern, count)); - } - - @Override - public ScanResult> scan(final byte[] cursor, final byte[] pattern, final long count){ - return execute((client)->client.keyOperations().scan(cursor, pattern, count)); - } - - @Override - public List sort(final String key){ - return execute((client)->client.keyOperations().sort(rawKey(key))); - } - - @Override - public List sort(final byte[] key){ - return execute((client)->client.keyOperations().sort(rawKey(key))); - } - - @Override - public List sort(final String key, final SortArgument sortArgument){ - return execute((client)->client.keyOperations().sort(rawKey(key), sortArgument)); - } - - @Override - public List sort(final byte[] key, final SortArgument sortArgument){ - return execute((client)->client.keyOperations().sort(rawKey(key), sortArgument)); - } - - @Override - public Long sort(final String key, final String destKey){ - return execute((client)->client.keyOperations().sort(rawKey(key), rawKey(destKey))); - } - - @Override - public Long sort(final byte[] key, final byte[] destKey){ - return execute((client)->client.keyOperations().sort(rawKey(key), rawKey(destKey))); - } - - @Override - public Long sort(final String key, final String destKey, final SortArgument sortArgument){ - return execute((client)->client.keyOperations().sort(rawKey(key), rawKey(destKey), sortArgument)); - } - - @Override - public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument){ - return execute((client)->client.keyOperations().sort(rawKey(key), rawKey(destKey), sortArgument)); - } - - @Override - public Long touch(final String... keys){ - return execute((client)->client.keyOperations().touch(rawKeys(keys))); - } - - @Override - public Long touch(final byte[]... keys){ - return execute((client)->client.keyOperations().touch(rawKeys(keys))); - } - - @Override - public Type type(final String key){ - return execute((client)->client.keyOperations().type(rawKey(key))); - } - - @Override - public Type type(final byte[] key){ - return execute((client)->client.keyOperations().type(rawKey(key))); - } - - @Override - public Long unlink(final String... keys){ - return execute((client)->client.keyOperations().unlink(rawKeys(keys))); - } - - @Override - public Long unlink(final byte[]... keys){ - return execute((client)->client.keyOperations().unlink(rawKeys(keys))); - } - - @Override - public Long wait(final int replicas, final int timeout){ - return execute((client)->client.keyOperations().wait(replicas, timeout)); - } - - @Override - public ObjectEncoding objectEncoding(final String key){ - return execute((client)->client.keyOperations().objectEncoding(rawKey(key))); - } - - @Override - public ObjectEncoding objectEncoding(final byte[] key){ - return execute((client)->client.keyOperations().objectEncoding(rawKey(key))); - } - - @Override - public Long objectFreq(final String key){ - return execute((client)->client.keyOperations().objectFreq(rawKey(key))); - } - - @Override - public Long objectFreq(final byte[] key){ - return execute((client)->client.keyOperations().objectFreq(rawKey(key))); - } - - @Override - public Long objectIdleTime(final String key){ - return execute((client)->client.keyOperations().objectIdleTime(rawKey(key))); - } - - @Override - public Long objectIdleTime(final byte[] key){ - return execute((client)->client.keyOperations().objectIdleTime(rawKey(key))); - } - - @Override - public Long objectRefcount(final String key){ - return execute((client)->client.keyOperations().objectRefcount(rawKey(key))); - } - - @Override - public Long objectRefcount(final byte[] key){ - return execute((client)->client.keyOperations().objectRefcount(rawKey(key))); - } - - @Override - public String lIndex(final String key, final long index){ - return execute((client)->client.listOperations().lIndex(rawKey(key), index)); - } - - @Override - public byte[] lIndex(final byte[] key, final long index){ - return execute((client)->client.listOperations().lIndex(rawKey(key), index)); - } - - @Override - public Long lInsert(final String key, final ListPosition position, final String pivot, final String value){ - return execute((client)->client.listOperations().lInsert(rawKey(key), position, pivot, value)); - } - - @Override - public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value){ - return execute((client)->client.listOperations().lInsert(rawKey(key), position, pivot, value)); - } - - @Override - public Status lSet(final String key, final long index, final String value){ - return execute((client)->client.listOperations().lSet(rawKey(key), index, value)); - } - - @Override - public Status lSet(final byte[] key, final long index, final byte[] value){ - return execute((client)->client.listOperations().lSet(rawKey(key), index, value)); - } - - @Override - public Long lLen(final String key){ - return execute((client)->client.listOperations().lLen(rawKey(key))); - } - - @Override - public Long lLen(final byte[] key){ - return execute((client)->client.listOperations().lLen(rawKey(key))); - } - - @Override - public List lRange(final String key, final long start, final long end){ - return execute((client)->client.listOperations().lRange(rawKey(key), start, end)); - } - - @Override - public List lRange(final byte[] key, final long start, final long end){ - return execute((client)->client.listOperations().lRange(rawKey(key), start, end)); - } - - @Override - public Long lPos(final String key, final String element){ - return execute((client)->client.listOperations().lPos(rawKey(key), element)); - } - - @Override - public Long lPos(final byte[] key, final byte[] element){ - return execute((client)->client.listOperations().lPos(rawKey(key), element)); - } - - @Override - public Long lPos(final String key, final String element, final LPosArgument lPosArgument){ - return execute((client)->client.listOperations().lPos(rawKey(key), element, lPosArgument)); - } - - @Override - public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument){ - return execute((client)->client.listOperations().lPos(rawKey(key), element, lPosArgument)); - } - - @Override - public List lPos(final String key, String element, final LPosArgument lPosArgument, final long count){ - return execute((client)->client.listOperations().lPos(rawKey(key), element, lPosArgument, count)); - } - - @Override - public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final long count){ - return execute((client)->client.listOperations().lPos(rawKey(key), element, lPosArgument, count)); - } - - @Override - public Long lRem(final String key, final String value, final long count){ - return execute((client)->client.listOperations().lRem(rawKey(key), value, count)); + public Status expireAt(final byte[] key, final long unixTimestamp) { + return execute((client)->client.keyOperations().expireAt(rawKey(key), unixTimestamp)); } @Override - public Long lRem(final byte[] key, final byte[] value, final long count){ - return execute((client)->client.listOperations().lRem(rawKey(key), value, count)); + public Status pExpire(final String key, final int lifetime) { + return execute((client)->client.keyOperations().pExpire(rawKey(key), lifetime)); } @Override - public Status lTrim(final String key, final long start, final long end){ - return execute((client)->client.listOperations().lTrim(rawKey(key), start, end)); + public Status pExpire(final byte[] key, final int lifetime) { + return execute((client)->client.keyOperations().pExpire(rawKey(key), lifetime)); } @Override - public Status lTrim(final byte[] key, final long start, final long end){ - return execute((client)->client.listOperations().lTrim(rawKey(key), start, end)); + public Status pExpireAt(final String key, final long unixTimestamp) { + return execute((client)->client.keyOperations().pExpireAt(rawKey(key), unixTimestamp)); } @Override - public String lMove(final String key, final String destKey, final Direction from, final Direction to){ - return execute((client)->client.listOperations().lMove(rawKey(destKey), rawKey(destKey), from, to)); + public Status pExpireAt(final byte[] key, final long unixTimestamp) { + return execute((client)->client.keyOperations().pExpireAt(rawKey(key), unixTimestamp)); } @Override - public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to){ - return execute((client)->client.listOperations().lMove(rawKey(key), rawKey(destKey), from, to)); + public Status persist(final String key) { + return execute((client)->client.keyOperations().persist(rawKey(key))); } @Override - public String blMove(final String key, final String destKey, final Direction from, final Direction to, - final int timeout){ - return execute((client)->client.listOperations().blMove(rawKey(destKey), rawKey(destKey), from, to, timeout)); + public Status persist(final byte[] key) { + return execute((client)->client.keyOperations().persist(rawKey(key))); } @Override - public byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, - final int timeout){ - return execute((client)->client.listOperations().blMove(rawKey(key), rawKey(destKey), from, to, timeout)); + public Long ttl(final String key) { + return execute((client)->client.keyOperations().ttl(rawKey(key))); } @Override - public List blPop(final String[] keys, final int timeout){ - return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout)); + public Long ttl(final byte[] key) { + return execute((client)->client.keyOperations().ttl(rawKey(key))); } @Override - public List blPop(final byte[][] keys, final int timeout){ - return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout)); + public Long pTtl(final String key) { + return execute((client)->client.keyOperations().pTtl(rawKey(key))); } @Override - public List brPop(final String[] keys, final int timeout){ - return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout)); + public Long pTtl(final byte[] key) { + return execute((client)->client.keyOperations().pTtl(rawKey(key))); } @Override - public List brPop(final byte[][] keys, final int timeout){ - return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout)); + public Status copy(final String key, final String destKey) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey))); } @Override - public String brPoplPush(final String key, final String destKey, final int timeout){ - return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout)); + public Status copy(final byte[] key, final byte[] destKey) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey))); } @Override - public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout){ - return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout)); + public Status copy(final String key, final String destKey, final int db) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), db)); } @Override - public String lPop(final String key){ - return execute((client)->client.listOperations().lPop(rawKey(key))); + public Status copy(final byte[] key, final byte[] destKey, final int db) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), db)); } @Override - public byte[] lPop(final byte[] key){ - return execute((client)->client.listOperations().lPop(rawKey(key))); + public Status copy(final String key, final String destKey, final boolean replace) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), replace)); } @Override - public Long lPush(final String key, final String... values){ - return execute((client)->client.listOperations().lPush(rawKey(key), values)); + public Status copy(final byte[] key, final byte[] destKey, final boolean replace) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), replace)); } @Override - public Long lPush(final byte[] key, final byte[]... values){ - return execute((client)->client.listOperations().lPush(rawKey(key), values)); + public Status copy(final String key, final String destKey, final int db, final boolean replace) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), db, replace)); } @Override - public Long lPushX(final String key, final String... values){ - return execute((client)->client.listOperations().lPushX(rawKey(key), values)); + public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace) { + return execute((client)->client.keyOperations().copy(rawKey(key), rawKey(destKey), db, replace)); } @Override - public Long lPushX(final byte[] key, final byte[]... values){ - return execute((client)->client.listOperations().lPushX(rawKey(key), values)); + public Status move(final String key, final int db) { + return execute((client)->client.keyOperations().move(rawKey(key), db)); } @Override - public String rPop(final String key){ - return execute((client)->client.listOperations().rPop(rawKey(key))); + public Status move(final byte[] key, final int db) { + return execute((client)->client.keyOperations().move(rawKey(key), db)); } @Override - public byte[] rPop(final byte[] key){ - return execute((client)->client.listOperations().rPop(rawKey(key))); + public Status migrate(final String host, final int port, final int db, final int timeout, final String... keys) { + return execute((client)->client.keyOperations().migrate(host, port, db, timeout, rawKeys(keys))); } @Override - public String rPoplPush(final String key, final String destKey){ - return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey))); + public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... keys) { + return execute((client)->client.keyOperations().migrate(host, port, db, timeout, rawKeys(keys))); } @Override - public byte[] rPoplPush(final byte[] key, final byte[] destKey){ - return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey))); + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateOperation operation, final String... keys) { + return execute((client)->client.keyOperations().migrate(host, port, db, timeout, operation, rawKeys(keys))); } @Override - public Long rPush(final String key, final String... values){ - return execute((client)->client.listOperations().rPush(rawKey(key), values)); + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateOperation operation, final byte[]... keys) { + return execute((client)->client.keyOperations().migrate(host, port, db, timeout, operation, rawKeys(keys))); } @Override - public Long rPush(final byte[] key, final byte[]... values){ - return execute((client)->client.listOperations().rPush(rawKey(key), values)); + public Status migrate(final String host, final int port, final int db, final String password, final int timeout, + final String... keys) { + return execute((client)->client.keyOperations().migrate(host, port, db, password, timeout, rawKeys(keys))); } @Override - public Long rPushX(final String key, final String... values){ - return execute((client)->client.listOperations().rPushX(rawKey(key), values)); + public Status migrate(final String host, final int port, final int db, final byte[] password, final int timeout, + final byte[]... keys) { + return execute((client)->client.keyOperations().migrate(host, port, db, password, timeout, rawKeys(keys))); } @Override - public Long rPushX(final byte[] key, final byte[]... values){ - return execute((client)->client.listOperations().rPushX(rawKey(key), values)); + public Status migrate(final String host, final int port, final int db, final String password, final int timeout, + final MigrateOperation operation, final String... keys) { + return execute( + (client)->client.keyOperations().migrate(host, port, db, password, timeout, operation, rawKeys(keys))); } @Override - public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener){ - execute((client)->{ - client.pubSubOperations().pSubscribe(patterns, pubSubListener); - return null; - }); + public Status migrate(final String host, final int port, final int db, final byte[] password, final int timeout, + final MigrateOperation operation, final byte[]... keys) { + return execute( + (client)->client.keyOperations().migrate(host, port, db, password, timeout, operation, rawKeys(keys))); } @Override - public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener){ - execute((client)->{ - client.pubSubOperations().pSubscribe(patterns, pubSubListener); - return null; - }); + public Status migrate(final String host, final int port, final int db, final String user, final String password, + final int timeout, final String... keys) { + return execute( + (client)->client.keyOperations().migrate(host, port, db, user, password, timeout, rawKeys(keys))); } @Override - public Long publish(final String channel, final String message){ - return execute((client)->client.pubSubOperations().publish(channel, message)); + public Status migrate(final String host, final int port, final int db, final byte[] user, final byte[] password, + final int timeout, final byte[]... keys) { + return execute( + (client)->client.keyOperations().migrate(host, port, db, user, password, timeout, rawKeys(keys))); } @Override - public Long publish(final byte[] channel, final byte[] message){ - return execute((client)->client.pubSubOperations().publish(channel, message)); + public Status migrate(final String host, final int port, final int db, final String user, final String password, + final int timeout, final MigrateOperation operation, final String... keys) { + return execute((client)->client.keyOperations() + .migrate(host, port, db, user, password, timeout, operation, rawKeys(keys))); } @Override - public List pubsubChannels(){ - return execute((client)->client.pubSubOperations().pubsubChannels()); + public Status migrate(final String host, final int port, final int db, final byte[] user, final byte[] password, + final int timeout, final MigrateOperation operation, final byte[]... keys) { + return execute((client)->client.keyOperations() + .migrate(host, port, db, user, password, timeout, operation, rawKeys(keys))); } @Override - public List pubsubChannels(final String pattern){ - return execute((client)->client.pubSubOperations().pubsubChannels(pattern)); + public Set keys(final String pattern) { + return execute((client)->client.keyOperations().keys(pattern)); } @Override - public List pubsubChannels(final byte[] pattern){ - return execute((client)->client.pubSubOperations().pubsubChannels(pattern)); + public Set keys(final byte[] pattern) { + return execute((client)->client.keyOperations().keys(pattern)); } @Override - public Long pubsubNumPat(){ - return execute((client)->client.pubSubOperations().pubsubNumPat()); + public String randomKey() { + return execute((client)->client.keyOperations().randomKey()); } @Override - public Map pubsubNumSub(final String... channels){ - return execute((client)->client.pubSubOperations().pubsubNumSub(channels)); + public Status rename(final String key, final String newKey) { + return execute((client)->client.keyOperations().rename(rawKey(key), rawKey(newKey))); } @Override - public Map pubsubNumSub(final byte[]... channels){ - return execute((client)->client.pubSubOperations().pubsubNumSub(channels)); + public Status rename(final byte[] key, final byte[] newKey) { + return execute((client)->client.keyOperations().rename(rawKey(key), rawKey(newKey))); } @Override - public Object pUnSubscribe(){ - return execute((client)->client.pubSubOperations().pUnSubscribe()); + public Status renameNx(final String key, final String newKey) { + return execute((client)->client.keyOperations().renameNx(rawKey(key), rawKey(newKey))); } @Override - public Object pUnSubscribe(final String... patterns){ - return execute((client)->client.pubSubOperations().pUnSubscribe(patterns)); + public Status renameNx(final byte[] key, final byte[] newKey) { + return execute((client)->client.keyOperations().renameNx(rawKey(key), rawKey(newKey))); } @Override - public Object pUnSubscribe(final byte[]... patterns){ - return execute((client)->client.pubSubOperations().pUnSubscribe(patterns)); + public Status restore(final String key, final byte[] serializedValue, final int ttl) { + return execute((client)->client.keyOperations().restore(rawKey(key), serializedValue, ttl)); } @Override - public void subscribe(final String[] channels, final PubSubListener pubSubListener){ - execute((client)->{ - client.pubSubOperations().subscribe(channels, pubSubListener); - return null; - }); + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl) { + return execute((client)->client.keyOperations().restore(rawKey(key), serializedValue, ttl)); } @Override - public void subscribe(final byte[][] channels, final PubSubListener pubSubListener){ - execute((client)->{ - client.pubSubOperations().subscribe(channels, pubSubListener); - return null; - }); + public Status restore(final String key, final byte[] serializedValue, final int ttl, + final RestoreArgument argument) { + return execute((client)->client.keyOperations().restore(rawKey(key), serializedValue, ttl, argument)); } @Override - public Object unSubscribe(){ - return execute((client)->client.pubSubOperations().unSubscribe()); + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl, + final RestoreArgument argument) { + return execute((client)->client.keyOperations().restore(rawKey(key), serializedValue, ttl, argument)); } @Override - public Object unSubscribe(final String... channels){ - return execute((client)->client.pubSubOperations().unSubscribe(channels)); + public ScanResult> scan(final long cursor) { + return execute((client)->client.keyOperations().scan(cursor)); } @Override - public Object unSubscribe(final byte[]... channels){ - return execute((client)->client.pubSubOperations().unSubscribe(channels)); + public ScanResult> scan(final String cursor) { + return execute((client)->client.keyOperations().scan(cursor)); } @Override - public Object eval(final String script){ - return execute((client)->client.scriptingOperations().eval(script)); + public ScanResult> scan(final byte[] cursor) { + return execute((client)->client.keyOperations().scan(cursor)); } @Override - public Object eval(final byte[] script){ - return execute((client)->client.scriptingOperations().eval(script)); + public ScanResult> scan(final long cursor, final String pattern) { + return execute((client)->client.keyOperations().scan(cursor, pattern)); } @Override - public Object eval(final String script, final String... params){ - return execute((client)->client.scriptingOperations().eval(script, params)); + public ScanResult> scan(final long cursor, final byte[] pattern) { + return execute((client)->client.keyOperations().scan(cursor, pattern)); } @Override - public Object eval(final byte[] script, final byte[]... params){ - return execute((client)->client.scriptingOperations().eval(script, params)); + public ScanResult> scan(final String cursor, final String pattern) { + return execute((client)->client.keyOperations().scan(cursor, pattern)); } @Override - public Object eval(final String script, final String[] keys, final String[] arguments){ - return execute((client)->client.scriptingOperations().eval(script, rawKeys(keys), arguments)); + public ScanResult> scan(final byte[] cursor, final byte[] pattern) { + return execute((client)->client.keyOperations().scan(cursor, pattern)); } @Override - public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments){ - return execute((client)->client.scriptingOperations().eval(script, rawKeys(keys), arguments)); + public ScanResult> scan(final long cursor, final long count) { + return execute((client)->client.keyOperations().scan(cursor, count)); } @Override - public Object evalSha(final String digest){ - return execute((client)->client.scriptingOperations().evalSha(digest)); + public ScanResult> scan(final String cursor, final long count) { + return execute((client)->client.keyOperations().scan(cursor, count)); } @Override - public Object evalSha(final byte[] digest){ - return execute((client)->client.scriptingOperations().evalSha(digest)); + public ScanResult> scan(final byte[] cursor, final long count) { + return execute((client)->client.keyOperations().scan(cursor, count)); } @Override - public Object evalSha(final String digest, final String... params){ - return execute((client)->client.scriptingOperations().evalSha(digest, params)); + public ScanResult> scan(final long cursor, final String pattern, final long count) { + return execute((client)->client.keyOperations().scan(cursor, pattern, count)); } @Override - public Object evalSha(final byte[] digest, final byte[]... params){ - return execute((client)->client.scriptingOperations().evalSha(digest, params)); + public ScanResult> scan(final long cursor, final byte[] pattern, final long count) { + return execute((client)->client.keyOperations().scan(cursor, pattern, count)); } @Override - public Object evalSha(final String digest, final String[] keys, final String[] arguments){ - return execute((client)->client.scriptingOperations().evalSha(digest, rawKeys(keys), arguments)); + public ScanResult> scan(final String cursor, final String pattern, final long count) { + return execute((client)->client.keyOperations().scan(cursor, pattern, count)); } @Override - public Object evalSha(final byte[] digest, final byte[][] keys, final byte[][] arguments){ - return execute((client)->client.scriptingOperations().evalSha(digest, rawKeys(keys), arguments)); + public ScanResult> scan(final byte[] cursor, final byte[] pattern, final long count) { + return execute((client)->client.keyOperations().scan(cursor, pattern, count)); } @Override - public List scriptExists(final String... sha1){ - return execute((client)->client.scriptingOperations().scriptExists(sha1)); + public List sort(final String key) { + return execute((client)->client.keyOperations().sort(rawKey(key))); } @Override - public List scriptExists(final byte[]... sha1){ - return execute((client)->client.scriptingOperations().scriptExists(sha1)); + public List sort(final byte[] key) { + return execute((client)->client.keyOperations().sort(rawKey(key))); } @Override - public Status scriptFlush(){ - return execute((client)->client.scriptingOperations().scriptFlush()); + public List sort(final String key, final SortArgument sortArgument) { + return execute((client)->client.keyOperations().sort(rawKey(key), sortArgument)); } @Override - public Status scriptFlush(final FlushMode mode){ - return execute((client)->client.scriptingOperations().scriptFlush(mode)); + public List sort(final byte[] key, final SortArgument sortArgument) { + return execute((client)->client.keyOperations().sort(rawKey(key), sortArgument)); } @Override - public String scriptLoad(final String script){ - return execute((client)->client.scriptingOperations().scriptLoad(script)); + public Long sort(final String key, final String destKey) { + return execute((client)->client.keyOperations().sort(rawKey(key), rawKey(destKey))); } @Override - public byte[] scriptLoad(final byte[] script){ - return execute((client)->client.scriptingOperations().scriptLoad(script)); + public Long sort(final byte[] key, final byte[] destKey) { + return execute((client)->client.keyOperations().sort(rawKey(key), rawKey(destKey))); } @Override - public Status scriptKill(){ - return execute((client)->client.scriptingOperations().scriptKill()); + public Long sort(final String key, final String destKey, final SortArgument sortArgument) { + return execute((client)->client.keyOperations().sort(rawKey(key), rawKey(destKey), sortArgument)); } @Override - public List aclCat(){ - return execute((client)->client.serverOperations().aclCat()); + public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument) { + return execute((client)->client.keyOperations().sort(rawKey(key), rawKey(destKey), sortArgument)); } @Override - public List aclCat(final String categoryName){ - return execute((client)->client.serverOperations().aclCat(categoryName)); + public Long touch(final String... keys) { + return execute((client)->client.keyOperations().touch(rawKeys(keys))); } @Override - public List aclCat(final byte[] categoryName){ - return execute((client)->client.serverOperations().aclCat(categoryName)); + public Long touch(final byte[]... keys) { + return execute((client)->client.keyOperations().touch(rawKeys(keys))); } @Override - public Status aclSetUser(final String username, final String... rules){ - return execute((client)->client.serverOperations().aclSetUser(username, rules)); + public Type type(final String key) { + return execute((client)->client.keyOperations().type(rawKey(key))); } @Override - public Status aclSetUser(final byte[] username, final byte[]... rules){ - return execute((client)->client.serverOperations().aclSetUser(username, rules)); + public Type type(final byte[] key) { + return execute((client)->client.keyOperations().type(rawKey(key))); } @Override - public AclUser aclGetUser(final String username){ - return execute((client)->client.serverOperations().aclGetUser(username)); + public Long unlink(final String... keys) { + return execute((client)->client.keyOperations().unlink(rawKeys(keys))); } @Override - public AclUser aclGetUser(final byte[] username){ - return execute((client)->client.serverOperations().aclGetUser(username)); + public Long unlink(final byte[]... keys) { + return execute((client)->client.keyOperations().unlink(rawKeys(keys))); } @Override - public List aclUsers(){ - return execute((client)->client.serverOperations().aclUsers()); + public ObjectEncoding objectEncoding(final String key) { + return execute((client)->client.keyOperations().objectEncoding(rawKey(key))); } @Override - public String aclWhoAmI(){ - return execute((client)->client.serverOperations().aclWhoAmI()); + public ObjectEncoding objectEncoding(final byte[] key) { + return execute((client)->client.keyOperations().objectEncoding(rawKey(key))); } @Override - public Long aclDelUser(final String... usernames){ - return execute((client)->client.serverOperations().aclDelUser(usernames)); + public Long objectFreq(final String key) { + return execute((client)->client.keyOperations().objectFreq(rawKey(key))); } @Override - public Long aclDelUser(final byte[]... username){ - return execute((client)->client.serverOperations().aclDelUser(username)); + public Long objectFreq(final byte[] key) { + return execute((client)->client.keyOperations().objectFreq(rawKey(key))); } @Override - public String aclGenPass(){ - return execute((client)->client.serverOperations().aclGenPass()); + public Long objectIdleTime(final String key) { + return execute((client)->client.keyOperations().objectIdleTime(rawKey(key))); } @Override - public List aclList(){ - return execute((client)->client.serverOperations().aclList()); + public Long objectIdleTime(final byte[] key) { + return execute((client)->client.keyOperations().objectIdleTime(rawKey(key))); } @Override - public Status aclLoad(){ - return execute((client)->client.serverOperations().aclLoad()); + public Long objectRefcount(final String key) { + return execute((client)->client.keyOperations().objectRefcount(rawKey(key))); } @Override - public List aclLog(){ - return execute((client)->client.serverOperations().aclLog()); + public Long objectRefcount(final byte[] key) { + return execute((client)->client.keyOperations().objectRefcount(rawKey(key))); } @Override - public List aclLog(final long count){ - return execute((client)->client.serverOperations().aclLog(count)); + public String lIndex(final String key, final long index) { + return execute((client)->client.listOperations().lIndex(rawKey(key), index)); } @Override - public Status aclLogReset(){ - return execute((client)->client.serverOperations().aclLogReset()); + public byte[] lIndex(final byte[] key, final long index) { + return execute((client)->client.listOperations().lIndex(rawKey(key), index)); } @Override - public Status aclLogSave(){ - return execute((client)->client.serverOperations().aclLogSave()); + public Long lInsert(final String key, final ListPosition position, final String pivot, final String value) { + return execute((client)->client.listOperations().lInsert(rawKey(key), position, pivot, value)); } @Override - public String bgRewriteAof(){ - return execute((client)->client.serverOperations().bgRewriteAof()); + public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value) { + return execute((client)->client.listOperations().lInsert(rawKey(key), position, pivot, value)); } @Override - public String bgSave(){ - return execute((client)->client.serverOperations().bgSave()); + public Status lSet(final String key, final long index, final String value) { + return execute((client)->client.listOperations().lSet(rawKey(key), index, value)); } @Override - public Status configSet(final String parameter, final String value){ - return execute((client)->client.serverOperations().configSet(parameter, value)); + public Status lSet(final byte[] key, final long index, final byte[] value) { + return execute((client)->client.listOperations().lSet(rawKey(key), index, value)); } @Override - public Status configSet(final byte[] parameter, final byte[] value){ - return execute((client)->client.serverOperations().configSet(parameter, value)); + public Long lLen(final String key) { + return execute((client)->client.listOperations().lLen(rawKey(key))); } @Override - public List configGet(final String parameter){ - return execute((client)->client.serverOperations().configGet(parameter)); + public Long lLen(final byte[] key) { + return execute((client)->client.listOperations().lLen(rawKey(key))); } @Override - public List configGet(final byte[] parameter){ - return execute((client)->client.serverOperations().configGet(parameter)); + public List lRange(final String key, final long start, final long end) { + return execute((client)->client.listOperations().lRange(rawKey(key), start, end)); } @Override - public Status configResetStat(){ - return execute((client)->client.serverOperations().configResetStat()); + public List lRange(final byte[] key, final long start, final long end) { + return execute((client)->client.listOperations().lRange(rawKey(key), start, end)); } @Override - public Status configRewrite(){ - return execute((client)->client.serverOperations().configRewrite()); + public Long lPos(final String key, final String element) { + return execute((client)->client.listOperations().lPos(rawKey(key), element)); } @Override - public Long dbSize(){ - return execute((client)->client.serverOperations().dbSize()); + public Long lPos(final byte[] key, final byte[] element) { + return execute((client)->client.listOperations().lPos(rawKey(key), element)); } @Override - public Status failover(){ - return execute((client)->client.serverOperations().failover()); + public Long lPos(final String key, final String element, final LPosArgument lPosArgument) { + return execute((client)->client.listOperations().lPos(rawKey(key), element, lPosArgument)); } @Override - public Status failover(final String host, final int port){ - return execute((client)->client.serverOperations().failover(host, port)); + public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument) { + return execute((client)->client.listOperations().lPos(rawKey(key), element, lPosArgument)); } @Override - public Status failover(final String host, final int port, final int timeout){ - return execute((client)->client.serverOperations().failover(host, port, timeout)); + public List lPos(final String key, String element, final LPosArgument lPosArgument, final long count) { + return execute((client)->client.listOperations().lPos(rawKey(key), element, lPosArgument, count)); } @Override - public Status failover(final String host, final int port, final boolean isForce, final int timeout){ - return execute((client)->client.serverOperations().failover(host, port, isForce, timeout)); + public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final long count) { + return execute((client)->client.listOperations().lPos(rawKey(key), element, lPosArgument, count)); } @Override - public Status failover(final int timeout){ - return execute((client)->client.serverOperations().failover(timeout)); + public Long lRem(final String key, final String value, final long count) { + return execute((client)->client.listOperations().lRem(rawKey(key), value, count)); } @Override - public Status flushAll(){ - return execute((client)->client.serverOperations().flushAll()); + public Long lRem(final byte[] key, final byte[] value, final long count) { + return execute((client)->client.listOperations().lRem(rawKey(key), value, count)); } @Override - public Status flushAll(final FlushMode mode){ - return execute((client)->client.serverOperations().flushAll(mode)); + public Status lTrim(final String key, final long start, final long end) { + return execute((client)->client.listOperations().lTrim(rawKey(key), start, end)); } @Override - public Status flushDb(){ - return execute((client)->client.serverOperations().flushDb()); + public Status lTrim(final byte[] key, final long start, final long end) { + return execute((client)->client.listOperations().lTrim(rawKey(key), start, end)); } @Override - public Status flushDb(final FlushMode mode){ - return execute((client)->client.serverOperations().flushDb(mode)); + public String lMove(final String key, final String destKey, final Direction from, final Direction to) { + return execute((client)->client.listOperations().lMove(rawKey(destKey), rawKey(destKey), from, to)); } @Override - public Info info(){ - return execute((client)->client.serverOperations().info()); + public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { + return execute((client)->client.listOperations().lMove(rawKey(key), rawKey(destKey), from, to)); } @Override - public Info info(final Info.Section section){ - return execute((client)->client.serverOperations().info(section)); + public String blMove(final String key, final String destKey, final Direction from, final Direction to, + final int timeout) { + return execute((client)->client.listOperations().blMove(rawKey(destKey), rawKey(destKey), from, to, timeout)); } @Override - public Long lastSave(){ - return execute((client)->client.serverOperations().lastSave()); + public byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout) { + return execute((client)->client.listOperations().blMove(rawKey(key), rawKey(destKey), from, to, timeout)); } @Override - public String memoryDoctor(){ - return execute((client)->client.serverOperations().memoryDoctor()); + public List blPop(final String[] keys, final int timeout) { + return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout)); } @Override - public Status memoryPurge(){ - return execute((client)->client.serverOperations().memoryPurge()); + public List blPop(final byte[][] keys, final int timeout) { + return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout)); } @Override - public MemoryStats memoryStats(){ - return execute((client)->client.serverOperations().memoryStats()); + public List brPop(final String[] keys, final int timeout) { + return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout)); } @Override - public Long memoryUsage(final String key){ - return execute((client)->client.serverOperations().memoryUsage(key)); + public List brPop(final byte[][] keys, final int timeout) { + return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout)); } @Override - public Long memoryUsage(final byte[] key){ - return execute((client)->client.serverOperations().memoryUsage(key)); + public String brPoplPush(final String key, final String destKey, final int timeout) { + return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout)); } @Override - public Long memoryUsage(final String key, final int samples){ - return execute((client)->client.serverOperations().memoryUsage(rawKey(key), samples)); + public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout) { + return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout)); } @Override - public Long memoryUsage(final byte[] key, final int samples){ - return execute((client)->client.serverOperations().memoryUsage(rawKey(key), samples)); + public String lPop(final String key) { + return execute((client)->client.listOperations().lPop(rawKey(key))); } @Override - public List moduleList(){ - return execute((client)->client.serverOperations().moduleList()); + public byte[] lPop(final byte[] key) { + return execute((client)->client.listOperations().lPop(rawKey(key))); } @Override - public Status moduleLoad(final String path, final String... arguments){ - return execute((client)->client.serverOperations().moduleLoad(path, arguments)); + public Long lPush(final String key, final String... values) { + return execute((client)->client.listOperations().lPush(rawKey(key), values)); } @Override - public Status moduleLoad(final byte[] path, final byte[]... arguments){ - return execute((client)->client.serverOperations().moduleLoad(path, arguments)); + public Long lPush(final byte[] key, final byte[]... values) { + return execute((client)->client.listOperations().lPush(rawKey(key), values)); } @Override - public Status moduleUnLoad(final String name){ - return execute((client)->client.serverOperations().moduleUnLoad(name)); + public Long lPushX(final String key, final String... values) { + return execute((client)->client.listOperations().lPushX(rawKey(key), values)); } @Override - public Status moduleUnLoad(final byte[] name){ - return execute((client)->client.serverOperations().moduleUnLoad(name)); + public Long lPushX(final byte[] key, final byte[]... values) { + return execute((client)->client.listOperations().lPushX(rawKey(key), values)); } @Override - public void monitor(final RedisMonitor redisMonitor){ - execute((client)->{ - client.serverOperations().monitor(redisMonitor); - return null; - }); + public String rPop(final String key) { + return execute((client)->client.listOperations().rPop(rawKey(key))); } @Override - public Object pSync(final String replicationId, final long offset){ - return execute((client)->client.serverOperations().pSync(replicationId, offset)); + public byte[] rPop(final byte[] key) { + return execute((client)->client.listOperations().rPop(rawKey(key))); } @Override - public Object pSync(final byte[] replicationId, final long offset){ - return execute((client)->client.serverOperations().pSync(replicationId, offset)); + public String rPoplPush(final String key, final String destKey) { + return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey))); } @Override - public void sync(){ - execute((client)->{ - client.serverOperations().sync(); - return null; - }); + public byte[] rPoplPush(final byte[] key, final byte[] destKey) { + return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey))); } @Override - public Status replicaOf(final String host, final int port){ - return execute((client)->client.serverOperations().replicaOf(host, port)); + public Long rPush(final String key, final String... values) { + return execute((client)->client.listOperations().rPush(rawKey(key), values)); } @Override - public Status slaveOf(final String host, final int port){ - return execute((client)->client.serverOperations().slaveOf(host, port)); + public Long rPush(final byte[] key, final byte[]... values) { + return execute((client)->client.listOperations().rPush(rawKey(key), values)); } @Override - public List role(){ - return execute((client)->client.serverOperations().role()); + public Long rPushX(final String key, final String... values) { + return execute((client)->client.listOperations().rPushX(rawKey(key), values)); } @Override - public Status save(){ - return execute((client)->client.serverOperations().save()); + public Long rPushX(final byte[] key, final byte[]... values) { + return execute((client)->client.listOperations().rPushX(rawKey(key), values)); } @Override - public void shutdown(){ - execute((client)->{ - client.serverOperations().shutdown(); - return null; - }); + public Object eval(final String script, final String[] keys, final String[] arguments) { + return execute((client)->client.scriptingOperations().eval(script, rawKeys(keys), arguments)); } @Override - public void shutdown(final boolean save){ - execute((client)->{ - client.serverOperations().shutdown(save); - return null; - }); + public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments) { + return execute((client)->client.scriptingOperations().eval(script, rawKeys(keys), arguments)); } @Override - public List slowLogGet(){ - return execute((client)->client.serverOperations().slowLogGet()); + public Object evalSha(final String digest, final String[] keys, final String[] arguments) { + return execute((client)->client.scriptingOperations().evalSha(digest, rawKeys(keys), arguments)); } @Override - public List slowLogGet(final long count){ - return execute((client)->client.serverOperations().slowLogGet(count)); + public Object evalSha(final byte[] digest, final byte[][] keys, final byte[][] arguments) { + return execute((client)->client.scriptingOperations().evalSha(digest, rawKeys(keys), arguments)); } @Override - public Long slowLogLen(){ - return execute((client)->client.serverOperations().slowLogLen()); + public Long memoryUsage(final String key) { + return execute((client)->client.serverOperations().memoryUsage(key)); } @Override - public Status slowLogReset(){ - return execute((client)->client.serverOperations().slowLogReset()); + public Long memoryUsage(final byte[] key) { + return execute((client)->client.serverOperations().memoryUsage(key)); } @Override - public Status swapdb(final int db1, final int db2){ - return execute((client)->client.serverOperations().swapdb(db1, db2)); + public Long memoryUsage(final String key, final int samples) { + return execute((client)->client.serverOperations().memoryUsage(rawKey(key), samples)); } @Override - public RedisServerTime time(){ - return execute((client)->client.serverOperations().time()); + public Long memoryUsage(final byte[] key, final int samples) { + return execute((client)->client.serverOperations().memoryUsage(rawKey(key), samples)); } @Override - public Long sAdd(final String key, final String... members){ + public Long sAdd(final String key, final String... members) { return execute((client)->client.setOperations().sAdd(rawKey(key), members)); } @Override - public Long sAdd(final byte[] key, final byte[]... members){ + public Long sAdd(final byte[] key, final byte[]... members) { return execute((client)->client.setOperations().sAdd(rawKey(key), members)); } @Override - public Long sCard(final String key){ + public Long sCard(final String key) { return execute((client)->client.setOperations().sCard(rawKey(key))); } @Override - public Long sCard(final byte[] key){ + public Long sCard(final byte[] key) { return execute((client)->client.setOperations().sCard(rawKey(key))); } @Override - public Set sDiff(final String... keys){ + public Set sDiff(final String... keys) { return execute((client)->client.setOperations().sDiff(rawKeys(keys))); } @Override - public Set sDiff(final byte[]... keys){ + public Set sDiff(final byte[]... keys) { return execute((client)->client.setOperations().sDiff(rawKeys(keys))); } @Override - public Long sDiffStore(final String destKey, final String... keys){ + public Long sDiffStore(final String destKey, final String... keys) { return execute((client)->client.setOperations().sDiffStore(rawKey(destKey), rawKeys(keys))); } @Override - public Long sDiffStore(final byte[] destKey, final byte[]... keys){ + public Long sDiffStore(final byte[] destKey, final byte[]... keys) { return execute((client)->client.setOperations().sDiffStore(rawKey(destKey), rawKeys(keys))); } @Override - public Set sInter(final String... keys){ + public Set sInter(final String... keys) { return execute((client)->client.setOperations().sInter(rawKeys(keys))); } @Override - public Set sInter(final byte[]... keys){ + public Set sInter(final byte[]... keys) { return execute((client)->client.setOperations().sInter(rawKeys(keys))); } @Override - public Long sInterStore(final String destKey, final String... keys){ + public Long sInterStore(final String destKey, final String... keys) { return execute((client)->client.setOperations().sDiffStore(rawKey(destKey), rawKeys(keys))); } @Override - public Long sInterStore(final byte[] destKey, final byte[]... keys){ + public Long sInterStore(final byte[] destKey, final byte[]... keys) { return execute((client)->client.setOperations().sDiffStore(rawKey(destKey), rawKeys(keys))); } @Override - public Boolean sIsMember(final String key, final String member){ + public Boolean sIsMember(final String key, final String member) { return execute((client)->client.setOperations().sIsMember(rawKey(key), member)); } @Override - public Boolean sIsMember(final byte[] key, final byte[] member){ + public Boolean sIsMember(final byte[] key, final byte[] member) { return execute((client)->client.setOperations().sIsMember(rawKey(key), member)); } @Override - public List smIsMember(final String key, final String... members){ + public List smIsMember(final String key, final String... members) { return execute((client)->client.setOperations().smIsMember(rawKey(key), members)); } @Override - public List smIsMember(final byte[] key, final byte[]... members){ + public List smIsMember(final byte[] key, final byte[]... members) { return execute((client)->client.setOperations().smIsMember(rawKey(key), members)); } @Override - public Set sMembers(final String key){ + public Set sMembers(final String key) { return execute((client)->client.setOperations().sMembers(rawKey(key))); } @Override - public Set sMembers(final byte[] key){ + public Set sMembers(final byte[] key) { return execute((client)->client.setOperations().sMembers(rawKey(key))); } @Override - public Status sMove(final String key, final String destKey, final String member){ + public Status sMove(final String key, final String destKey, final String member) { return execute((client)->client.setOperations().sMove(rawKey(key), rawKey(destKey), member)); } @Override - public Status sMove(final byte[] key, final byte[] destKey, final byte[] member){ + public Status sMove(final byte[] key, final byte[] destKey, final byte[] member) { return execute((client)->client.setOperations().sMove(rawKey(key), rawKey(destKey), member)); } @Override - public String sPop(final String key){ + public String sPop(final String key) { return execute((client)->client.setOperations().sPop(rawKey(key))); } @Override - public byte[] sPop(final byte[] key){ + public byte[] sPop(final byte[] key) { return execute((client)->client.setOperations().sPop(rawKey(key))); } @Override - public Set sPop(final String key, final long count){ + public Set sPop(final String key, final long count) { return execute((client)->client.setOperations().sPop(rawKey(key), count)); } @Override - public Set sPop(final byte[] key, final long count){ + public Set sPop(final byte[] key, final long count) { return execute((client)->client.setOperations().sPop(rawKey(key), count)); } @Override - public String sRandMember(final String key){ + public String sRandMember(final String key) { return execute((client)->client.setOperations().sRandMember(rawKey(key))); } @Override - public byte[] sRandMember(final byte[] key){ + public byte[] sRandMember(final byte[] key) { return execute((client)->client.setOperations().sRandMember(rawKey(key))); } @Override - public List sRandMember(final String key, final long count){ + public List sRandMember(final String key, final long count) { return execute((client)->client.setOperations().sRandMember(rawKey(key), count)); } @Override - public List sRandMember(final byte[] key, final long count){ + public List sRandMember(final byte[] key, final long count) { return execute((client)->client.setOperations().sRandMember(rawKey(key), count)); } @Override - public Long sRem(final String key, final String... members){ + public Long sRem(final String key, final String... members) { return execute((client)->client.setOperations().sRem(rawKey(key), members)); } @Override - public Long sRem(final byte[] key, final byte[]... members){ + public Long sRem(final byte[] key, final byte[]... members) { return execute((client)->client.setOperations().sRem(rawKey(key), members)); } @Override - public ScanResult> sScan(final String key, final long cursor){ + public ScanResult> sScan(final String key, final long cursor) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor)); } @Override - public ScanResult> sScan(final byte[] key, final long cursor){ + public ScanResult> sScan(final byte[] key, final long cursor) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor)); } @Override - public ScanResult> sScan(final String key, final String cursor){ + public ScanResult> sScan(final String key, final String cursor) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor)); } @Override - public ScanResult> sScan(final byte[] key, final byte[] cursor){ + public ScanResult> sScan(final byte[] key, final byte[] cursor) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor)); } @Override - public ScanResult> sScan(final String key, final long cursor, final String pattern){ + public ScanResult> sScan(final String key, final long cursor, final String pattern) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern)); } @Override - public ScanResult> sScan(final byte[] key, final long cursor, final byte[] pattern){ + public ScanResult> sScan(final byte[] key, final long cursor, final byte[] pattern) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern)); } @Override - public ScanResult> sScan(final String key, final String cursor, final String pattern){ + public ScanResult> sScan(final String key, final String cursor, final String pattern) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern)); } @Override - public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern){ + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern)); } @Override - public ScanResult> sScan(final String key, final long cursor, final long count){ + public ScanResult> sScan(final String key, final long cursor, final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count)); } @Override - public ScanResult> sScan(final byte[] key, final long cursor, final long count){ + public ScanResult> sScan(final byte[] key, final long cursor, final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count)); } @Override - public ScanResult> sScan(final String key, final String cursor, final long count){ + public ScanResult> sScan(final String key, final String cursor, final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count)); } @Override - public ScanResult> sScan(final byte[] key, final byte[] cursor, final long count){ + public ScanResult> sScan(final byte[] key, final byte[] cursor, final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count)); } @Override - public ScanResult> sScan(final String key, final long cursor, final String pattern, final long count){ + public ScanResult> sScan(final String key, final long cursor, final String pattern, final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count)); } @Override - public ScanResult> sScan(final byte[] key, final long cursor, final byte[] pattern, final long count){ + public ScanResult> sScan(final byte[] key, final long cursor, final byte[] pattern, final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count)); } @Override public ScanResult> sScan(final String key, final String cursor, final String pattern, - final long count){ + final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count)); } @Override public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern, - final long count){ + final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count)); } @Override - public Set sUnion(final String... keys){ + public Set sUnion(final String... keys) { return execute((client)->client.setOperations().sUnion(rawKeys(keys))); } @Override - public Set sUnion(final byte[]... keys){ + public Set sUnion(final byte[]... keys) { return execute((client)->client.setOperations().sUnion(rawKeys(keys))); } @Override - public Long sUnionStore(final String destKey, final String... keys){ + public Long sUnionStore(final String destKey, final String... keys) { return execute((client)->client.setOperations().sUnionStore(rawKey(destKey), rawKeys(keys))); } @Override - public Long sUnionStore(final byte[] destKey, final byte[]... keys){ + public Long sUnionStore(final byte[] destKey, final byte[]... keys) { return execute((client)->client.setOperations().sUnionStore(rawKey(destKey), rawKeys(keys))); } @Override - public Tuple zPopMin(final String key){ + public Tuple zPopMin(final String key) { return execute((client)->client.sortedSetOperations().zPopMin(rawKey(key))); } @Override - public Tuple zPopMin(final byte[] key){ + public Tuple zPopMin(final byte[] key) { return execute((client)->client.sortedSetOperations().zPopMin(rawKey(key))); } @Override - public List zPopMin(final String key, long count){ + public List zPopMin(final String key, long count) { return execute((client)->client.sortedSetOperations().zPopMin(rawKey(key), count)); } @Override - public List zPopMin(final byte[] key, long count){ + public List zPopMin(final byte[] key, long count) { return execute((client)->client.sortedSetOperations().zPopMin(rawKey(key), count)); } @Override - public Tuple zPopMax(final String key){ + public Tuple zPopMax(final String key) { return execute((client)->client.sortedSetOperations().zPopMax(rawKey(key))); } @Override - public Tuple zPopMax(final byte[] key){ + public Tuple zPopMax(final byte[] key) { return execute((client)->client.sortedSetOperations().zPopMax(rawKey(key))); } @Override - public List zPopMax(final String key, final long count){ + public List zPopMax(final String key, final long count) { return execute((client)->client.sortedSetOperations().zPopMax(rawKey(key), count)); } @Override - public List zPopMax(final byte[] key, final long count){ + public List zPopMax(final byte[] key, final long count) { return execute((client)->client.sortedSetOperations().zPopMax(rawKey(key), count)); } @Override - public KeyedZSetElement bzPopMin(final String[] keys, final int timeout){ + public KeyValue bzPopMin(final String[] keys, final int timeout) { return execute((client)->client.sortedSetOperations().bzPopMin(rawKeys(keys), timeout)); } @Override - public KeyedZSetElement bzPopMin(final byte[][] keys, final int timeout){ + public KeyValue bzPopMin(final byte[][] keys, final int timeout) { return execute((client)->client.sortedSetOperations().bzPopMin(rawKeys(keys), timeout)); } @Override - public KeyedZSetElement bzPopMax(final String[] keys, final int timeout){ + public KeyValue bzPopMax(final String[] keys, final int timeout) { return execute((client)->client.sortedSetOperations().bzPopMax(rawKeys(keys), timeout)); } @Override - public KeyedZSetElement bzPopMax(final byte[][] keys, final int timeout){ + public KeyValue bzPopMax(final byte[][] keys, final int timeout) { return execute((client)->client.sortedSetOperations().bzPopMax(rawKeys(keys), timeout)); } @Override - public Long zAdd(final String key, final Map members){ + public Long zAdd(final String key, final Map members) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members)); } @Override - public Long zAdd(final byte[] key, final Map members){ + public Long zAdd(final byte[] key, final Map members) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members)); } @Override - public Long zAdd(final String key, final Map members, final NxXx nxXx){ + public Long zAdd(final String key, final Map members, final NxXx nxXx) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx)); } @Override - public Long zAdd(final byte[] key, final Map members, final NxXx nxXx){ + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx)); } @Override - public Long zAdd(final String key, final Map members, final GtLt gtLt){ + public Long zAdd(final String key, final Map members, final GtLt gtLt) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, gtLt)); } @Override - public Long zAdd(final byte[] key, final Map members, final GtLt gtLt){ + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, gtLt)); } @Override - public Long zAdd(final String key, final Map members, final boolean ch){ + public Long zAdd(final String key, final Map members, final boolean ch) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, ch)); } @Override - public Long zAdd(final byte[] key, final Map members, final boolean ch){ + public Long zAdd(final byte[] key, final Map members, final boolean ch) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, ch)); } @Override - public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt){ + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx, gtLt)); } @Override - public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt){ + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx, gtLt)); } @Override - public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch){ + public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx, ch)); } @Override - public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch){ + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx, ch)); } @Override - public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch){ + public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, gtLt, ch)); } @Override - public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch){ + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, gtLt, ch)); } @Override public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt, - final boolean ch){ + final boolean ch) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx, gtLt, ch)); } @Override public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt, - final boolean ch){ + final boolean ch) { return execute((client)->client.sortedSetOperations().zAdd(rawKey(key), members, nxXx, gtLt, ch)); } @Override - public Long zCard(final String key){ + public Long zCard(final String key) { return execute((client)->client.sortedSetOperations().zCard(rawKey(key))); } @Override - public Long zCard(final byte[] key){ + public Long zCard(final byte[] key) { return execute((client)->client.sortedSetOperations().zCard(rawKey(key))); } @Override - public Long zCount(final String key, final double min, final double max){ + public Long zCount(final String key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zCount(rawKey(key), min, max)); } @Override - public Long zCount(final byte[] key, final double min, final double max){ + public Long zCount(final byte[] key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zCount(rawKey(key), min, max)); } + @Deprecated @Override - public Long zCount(final String key, final String min, final String max){ + public Long zCount(final String key, final String min, final String max) { return execute((client)->client.sortedSetOperations().zCount(rawKey(key), min, max)); } + @Deprecated @Override - public Long zCount(final byte[] key, final byte[] min, final byte[] max){ + public Long zCount(final byte[] key, final byte[] min, final byte[] max) { return execute((client)->client.sortedSetOperations().zCount(rawKey(key), min, max)); } @Override - public Set zDiff(final String... keys){ + public List zDiff(final String... keys) { return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys))); } @Override - public Set zDiff(final byte[]... keys){ + public List zDiff(final byte[]... keys) { return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys))); } @Override - public Set zDiffWithScores(final String... keys){ + public List zDiffWithScores(final String... keys) { return execute((client)->client.sortedSetOperations().zDiffWithScores(rawKeys(keys))); } @Override - public Set zDiffWithScores(final byte[]... keys){ + public List zDiffWithScores(final byte[]... keys) { return execute((client)->client.sortedSetOperations().zDiffWithScores(rawKeys(keys))); } @Override - public Long zDiffStore(final String destKey, final String... keys){ + public Long zDiffStore(final String destKey, final String... keys) { return execute((client)->client.sortedSetOperations().zDiffStore(rawKey(destKey), rawKeys(keys))); } @Override - public Long zDiffStore(final byte[] destKey, final byte[]... keys){ + public Long zDiffStore(final byte[] destKey, final byte[]... keys) { return execute((client)->client.sortedSetOperations().zDiffStore(rawKey(destKey), rawKeys(keys))); } @Override - public Double zIncrBy(final String key, final double increment, final String member){ + public Double zIncrBy(final String key, final double increment, final String member) { return execute((client)->client.sortedSetOperations().zIncrBy(rawKey(key), increment, member)); } @Override - public Double zIncrBy(final byte[] key, final double increment, final byte[] member){ + public Double zIncrBy(final byte[] key, final double increment, final byte[] member) { return execute((client)->client.sortedSetOperations().zIncrBy(rawKey(key), increment, member)); } @Override - public Set zInter(final String... keys){ + public List zInter(final String... keys) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys))); } @Override - public Set zInter(final byte[]... keys){ + public List zInter(final byte[]... keys) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys))); } @Override - public Set zInter(final String[] keys, final Aggregate aggregate){ + public List zInter(final String[] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate)); } @Override - public Set zInter(final byte[][] keys, final Aggregate aggregate){ + public List zInter(final byte[][] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate)); } @Override - public Set zInter(final String[] keys, final double... weights){ + public List zInter(final String[] keys, final double... weights) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights)); } @Override - public Set zInter(final byte[][] keys, final double... weights){ + public List zInter(final byte[][] keys, final double... weights) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights)); } @Override - public Set zInter(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zInter(final String[] keys, final Aggregate aggregate, final double... weights) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights)); } @Override - public Set zInter(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights)); } @Override - public Set zInterWithScores(final String... keys){ + public List zInterWithScores(final String... keys) { return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys))); } @Override - public Set zInterWithScores(final byte[]... keys){ + public List zInterWithScores(final byte[]... keys) { return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys))); } @Override - public Set zInterWithScores(final String[] keys, final Aggregate aggregate){ + public List zInterWithScores(final String[] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys), aggregate)); } @Override - public Set zInterWithScores(final byte[][] keys, final Aggregate aggregate){ + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys), aggregate)); } @Override - public Set zInterWithScores(final String[] keys, final double... weights){ + public List zInterWithScores(final String[] keys, final double... weights) { return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys), weights)); } @Override - public Set zInterWithScores(final byte[][] keys, final double... weights){ + public List zInterWithScores(final byte[][] keys, final double... weights) { return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys), weights)); } @Override - public Set zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys), aggregate, weights)); } @Override - public Set zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { return execute((client)->client.sortedSetOperations().zInterWithScores(rawKeys(keys), aggregate, weights)); } @Override - public Long zInterStore(final String destKey, final String... keys){ + public Long zInterStore(final String destKey, final String... keys) { return execute((client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys))); } @Override - public Long zInterStore(final byte[] destKey, final byte[]... keys){ + public Long zInterStore(final byte[] destKey, final byte[]... keys) { return execute((client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys))); } @Override - public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate){ + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys), aggregate)); } @Override - public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate){ + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys), aggregate)); } @Override - public Long zInterStore(final String destKey, final String[] keys, final double... weights){ + public Long zInterStore(final String destKey, final String[] keys, final double... weights) { return execute((client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys), weights)); } @Override - public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights){ + public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights) { return execute((client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys), weights)); } @Override public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { return execute( (client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys), aggregate, weights)); } @Override public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { return execute( (client)->client.sortedSetOperations().zInterStore(rawKey(destKey), rawKeys(keys), aggregate, weights)); } @Override - public Long zLexCount(final String key, final double min, final double max){ + public Long zLexCount(final String key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zLexCount(rawKey(key), min, max)); } @Override - public Long zLexCount(final byte[] key, final double min, final double max){ + public Long zLexCount(final byte[] key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zLexCount(rawKey(key), min, max)); } + @Deprecated @Override - public Long zLexCount(final String key, final String min, final String max){ + public Long zLexCount(final String key, final String min, final String max) { return execute((client)->client.sortedSetOperations().zLexCount(rawKey(key), min, max)); } + @Deprecated @Override - public Long zLexCount(final byte[] key, final byte[] min, final byte[] max){ + public Long zLexCount(final byte[] key, final byte[] min, final byte[] max) { return execute((client)->client.sortedSetOperations().zLexCount(rawKey(key), min, max)); } @Override - public List zMScore(final String key, final String... members){ + public List zMScore(final String key, final String... members) { return execute((client)->client.sortedSetOperations().zMScore(rawKey(key), members)); } @Override - public List zMScore(final byte[] key, final byte[]... members){ + public List zMScore(final byte[] key, final byte[]... members) { return execute((client)->client.sortedSetOperations().zMScore(rawKey(key), members)); } @Override - public String zRandMember(final String key){ + public String zRandMember(final String key) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key))); } @Override - public byte[] zRandMember(final byte[] key){ + public byte[] zRandMember(final byte[] key) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key))); } @Override - public List zRandMember(final String key, final long count){ + public List zRandMember(final String key, final long count) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count)); } @Override - public List zRandMember(final byte[] key, final long count){ + public List zRandMember(final byte[] key, final long count) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count)); } @Override - public List zRandMemberWithScores(final String key, final long count){ + public List zRandMemberWithScores(final String key, final long count) { return execute((client)->client.sortedSetOperations().zRandMemberWithScores(rawKey(key), count)); } @Override - public List zRandMemberWithScores(final byte[] key, final long count){ + public List zRandMemberWithScores(final byte[] key, final long count) { return execute((client)->client.sortedSetOperations().zRandMemberWithScores(rawKey(key), count)); } @Override - public List zRange(final String key, final long start, final long end){ + public List zRange(final String key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end)); } @Override - public List zRange(final byte[] key, final long start, final long end){ + public List zRange(final byte[] key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end)); } @Override - public List zRangeWithScores(final String key, final long start, final long end){ + public List zRangeWithScores(final String key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRangeWithScores(rawKey(key), start, end)); } @Override - public List zRangeWithScores(final byte[] key, final long start, final long end){ + public List zRangeWithScores(final byte[] key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRangeWithScores(rawKey(key), start, end)); } @Override - public List zRangeByLex(final String key, final double min, final double max){ + public List zRangeByLex(final String key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max)); } @Override - public List zRangeByLex(final byte[] key, final double min, final double max){ + public List zRangeByLex(final byte[] key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max)); } + @Deprecated @Override - public List zRangeByLex(final String key, final String min, final String max){ + public List zRangeByLex(final String key, final String min, final String max) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max)); } + @Deprecated @Override - public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max){ + public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max)); } @Override public List zRangeByLex(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max, offset, count)); } @Override public List zRangeByLex(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max, offset, count)); } + @Deprecated @Override public List zRangeByLex(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max, offset, count)); } + @Deprecated @Override public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max, offset, count)); } @Override - public List zRangeByScore(final String key, final double min, final double max){ + public List zRangeByScore(final String key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max)); } @Override - public List zRangeByScore(final byte[] key, final double min, final double max){ + public List zRangeByScore(final byte[] key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRangeByScore(rawKey(key), min, max)); } + @Deprecated @Override - public List zRangeByScore(final String key, final String min, final String max){ + public List zRangeByScore(final String key, final String min, final String max) { return execute((client)->client.sortedSetOperations().zRangeByScore(rawKey(key), min, max)); } + @Deprecated @Override - public List zRangeByScore(final byte[] key, final byte[] min, final byte[] max){ + public List zRangeByScore(final byte[] key, final byte[] min, final byte[] max) { return execute((client)->client.sortedSetOperations().zRangeByScore(rawKey(key), min, max)); } @Override public List zRangeByScore(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRangeByScore(rawKey(key), min, max, offset, count)); } @Override public List zRangeByScore(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRangeByScore(rawKey(key), min, max, offset, count)); } + @Deprecated @Override public List zRangeByScore(final String key, String min, String max, long offset, - long count){ + long count) { return execute((client)->client.sortedSetOperations().zRangeByScore(rawKey(key), min, max, offset, count)); } + @Deprecated @Override public List zRangeByScore(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRangeByScore(rawKey(key), min, max, offset, count)); } @Override - public List zRangeByScoreWithScores(final String key, final double min, final double max){ + public List zRangeByScoreWithScores(final String key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRangeByScoreWithScores(rawKey(key), min, max)); } @Override - public List zRangeByScoreWithScores(final byte[] key, final double min, final double max){ + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRangeByScoreWithScores(rawKey(key), min, max)); } + @Deprecated @Override - public List zRangeByScoreWithScores(final String key, final String min, final String max){ + public List zRangeByScoreWithScores(final String key, final String min, final String max) { return execute((client)->client.sortedSetOperations().zRangeByScoreWithScores(rawKey(key), min, max)); } + @Deprecated @Override - public List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max){ + public List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max) { return execute((client)->client.sortedSetOperations().zRangeByScoreWithScores(rawKey(key), min, max)); } @Override public List zRangeByScoreWithScores(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute( (client)->client.sortedSetOperations().zRangeByScoreWithScores(rawKey(key), min, max, offset, count)); } @Override public List zRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute( (client)->client.sortedSetOperations().zRangeByScoreWithScores(rawKey(key), min, max, offset, count)); } + @Deprecated @Override public List zRangeByScoreWithScores(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { return execute( (client)->client.sortedSetOperations().zRangeByScoreWithScores(rawKey(key), min, max, offset, count)); } + @Deprecated @Override public List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { return execute( (client)->client.sortedSetOperations().zRangeByScoreWithScores(rawKey(key), min, max, offset, count)); } @Override - public Long zRangeStore(final String destKey, final String key, final long start, final long end){ + public Long zRangeStore(final String destKey, final String key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end)); } @Override - public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end){ + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end)); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, - final ZRangeBy by){ + final ZRangeBy by) { return execute( (client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end, by)); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, - final ZRangeBy by){ + final ZRangeBy by) { return execute( (client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end, by)); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, - final boolean rev){ + final boolean rev) { return execute( (client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end, rev)); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, - final boolean rev){ + final boolean rev) { return execute( (client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end, rev)); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations() .zRangeStore(rawKey(destKey), rawKey(key), start, end, offset, count)); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations() .zRangeStore(rawKey(destKey), rawKey(key), start, end, offset, count)); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, - final boolean rev){ + final boolean rev) { return execute( (client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end, by, rev)); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, - final boolean rev){ + final boolean rev) { return execute( (client)->client.sortedSetOperations().zRangeStore(rawKey(destKey), rawKey(key), start, end, by, rev)); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, - final long offset, final long count){ + final long offset, final long count) { return execute((client)->client.sortedSetOperations() .zRangeStore(rawKey(destKey), rawKey(key), start, end, by, offset, count)); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, - final long offset, final long count){ + final long offset, final long count) { return execute((client)->client.sortedSetOperations() .zRangeStore(rawKey(destKey), rawKey(key), start, end, by, offset, count)); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev, - final long offset, final long count){ + final long offset, final long count) { return execute((client)->client.sortedSetOperations() .zRangeStore(rawKey(destKey), rawKey(key), start, end, rev, offset, count)); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev, - final long offset, final long count){ + final long offset, final long count) { return execute((client)->client.sortedSetOperations() .zRangeStore(rawKey(destKey), rawKey(key), start, end, rev, offset, count)); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, - final boolean rev, final long offset, final long count){ + final boolean rev, final long offset, final long count) { return execute((client)->client.sortedSetOperations() .zRangeStore(rawKey(destKey), rawKey(key), start, end, by, rev, offset, count)); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, - final boolean rev, final long offset, final long count){ + final boolean rev, final long offset, final long count) { return execute((client)->client.sortedSetOperations() .zRangeStore(rawKey(destKey), rawKey(key), start, end, by, rev, offset, count)); } @Override - public Long zRank(final String key, final String member){ + public Long zRank(final String key, final String member) { return execute((client)->client.sortedSetOperations().zRank(rawKey(key), member)); } @Override - public Long zRank(final byte[] key, final byte[] member){ + public Long zRank(final byte[] key, final byte[] member) { return execute((client)->client.sortedSetOperations().zRank(rawKey(key), member)); } @Override - public Long zRem(final String key, final String... members){ + public Long zRem(final String key, final String... members) { return execute((client)->client.sortedSetOperations().zRem(rawKey(key), members)); } @Override - public Long zRem(final byte[] key, final byte[]... members){ + public Long zRem(final byte[] key, final byte[]... members) { return execute((client)->client.sortedSetOperations().zRem(rawKey(key), members)); } @Override - public Long zRemRangeByLex(final String key, final double min, final double max){ + public Long zRemRangeByLex(final String key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRemRangeByLex(rawKey(key), min, max)); } @Override - public Long zRemRangeByLex(final byte[] key, final double min, final double max){ + public Long zRemRangeByLex(final byte[] key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRemRangeByLex(rawKey(key), min, max)); } + @Deprecated @Override - public Long zRemRangeByLex(final String key, final String min, final String max){ + public Long zRemRangeByLex(final String key, final String min, final String max) { return execute((client)->client.sortedSetOperations().zRemRangeByLex(rawKey(key), min, max)); } + @Deprecated @Override - public Long zRemRangeByLex(final byte[] key, final byte[] min, final byte[] max){ + public Long zRemRangeByLex(final byte[] key, final byte[] min, final byte[] max) { return execute((client)->client.sortedSetOperations().zRemRangeByLex(rawKey(key), min, max)); } @Override - public Long zRemRangeByScore(final String key, final double min, final double max){ + public Long zRemRangeByScore(final String key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRemRangeByScore(rawKey(key), min, max)); } @Override - public Long zRemRangeByScore(final byte[] key, final double min, final double max){ + public Long zRemRangeByScore(final byte[] key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRemRangeByScore(rawKey(key), min, max)); } + @Deprecated @Override - public Long zRemRangeByScore(final String key, final String min, final String max){ + public Long zRemRangeByScore(final String key, final String min, final String max) { return execute((client)->client.sortedSetOperations().zRemRangeByScore(rawKey(key), min, max)); } + @Deprecated @Override - public Long zRemRangeByScore(final byte[] key, final byte[] min, final byte[] max){ + public Long zRemRangeByScore(final byte[] key, final byte[] min, final byte[] max) { return execute((client)->client.sortedSetOperations().zRemRangeByScore(rawKey(key), min, max)); } @Override - public Long zRemRangeByRank(final String key, final long start, final long end){ + public Long zRemRangeByRank(final String key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRemRangeByRank(rawKey(key), start, end)); } @Override - public Long zRemRangeByRank(final byte[] key, final long start, final long end){ + public Long zRemRangeByRank(final byte[] key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRemRangeByRank(rawKey(key), start, end)); } @Override - public List zRevRange(final String key, final long start, final long end){ + public List zRevRange(final String key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRevRange(rawKey(key), start, end)); } @Override - public List zRevRange(final byte[] key, final long start, final long end){ + public List zRevRange(final byte[] key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRevRange(rawKey(key), start, end)); } @Override - public List zRevRangeWithScores(final String key, final long start, final long end){ + public List zRevRangeWithScores(final String key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRevRangeWithScores(rawKey(key), start, end)); } @Override - public List zRevRangeWithScores(final byte[] key, final long start, final long end){ + public List zRevRangeWithScores(final byte[] key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRevRangeWithScores(rawKey(key), start, end)); } @Override - public List zRevRangeByLex(final String key, final double min, final double max){ + public List zRevRangeByLex(final String key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(rawKey(key), min, max)); } @Override - public List zRevRangeByLex(final byte[] key, final double min, final double max){ + public List zRevRangeByLex(final byte[] key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(rawKey(key), min, max)); } + @Deprecated @Override - public List zRevRangeByLex(final String key, final String min, final String max){ + public List zRevRangeByLex(final String key, final String min, final String max) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(rawKey(key), min, max)); } + @Deprecated @Override - public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max){ + public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(rawKey(key), min, max)); } @Override public List zRevRangeByLex(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(rawKey(key), min, max, offset, count)); } @Override public List zRevRangeByLex(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(rawKey(key), min, max, offset, count)); } + @Deprecated @Override public List zRevRangeByLex(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(rawKey(key), min, max, offset, count)); } + @Deprecated @Override public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(rawKey(key), min, max, offset, count)); } @Override - public List zRevRangeByScore(final String key, final double min, final double max){ + public List zRevRangeByScore(final String key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(rawKey(key), min, max)); } @Override - public List zRevRangeByScore(final byte[] key, final double min, final double max){ + public List zRevRangeByScore(final byte[] key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(rawKey(key), min, max)); } + @Deprecated @Override - public List zRevRangeByScore(final String key, final String min, final String max){ + public List zRevRangeByScore(final String key, final String min, final String max) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(rawKey(key), min, max)); } + @Deprecated @Override - public List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max){ + public List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(rawKey(key), min, max)); } @Override public List zRevRangeByScore(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(rawKey(key), min, max, offset, count)); } @Override public List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(rawKey(key), min, max, offset, count)); } + @Deprecated @Override public List zRevRangeByScore(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(rawKey(key), min, max, offset, count)); } + @Deprecated @Override public List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(rawKey(key), min, max, offset, count)); } @Override - public List zRevRangeByScoreWithScores(final String key, final double min, final double max){ + public List zRevRangeByScoreWithScores(final String key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRevRangeByScoreWithScores(rawKey(key), min, max)); } @Override - public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max){ + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRevRangeByScoreWithScores(rawKey(key), min, max)); } + @Deprecated @Override - public List zRevRangeByScoreWithScores(final String key, final String min, final String max){ + public List zRevRangeByScoreWithScores(final String key, final String min, final String max) { return execute((client)->client.sortedSetOperations().zRevRangeByScoreWithScores(rawKey(key), min, max)); } + @Deprecated @Override - public List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max){ + public List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max) { return execute((client)->client.sortedSetOperations().zRevRangeByScoreWithScores(rawKey(key), min, max)); } @Override public List zRevRangeByScoreWithScores(final String key, final double min, final double max, - final long offset, final long count){ + final long offset, final long count) { return execute((client)->client.sortedSetOperations() .zRevRangeByScoreWithScores(rawKey(key), min, max, offset, count)); } @Override public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max, - final long offset, final long count){ + final long offset, final long count) { return execute((client)->client.sortedSetOperations() .zRevRangeByScoreWithScores(rawKey(key), min, max, offset, count)); } + @Deprecated @Override public List zRevRangeByScoreWithScores(final String key, final String min, final String max, - final long offset, final long count){ + final long offset, final long count) { return execute((client)->client.sortedSetOperations() .zRevRangeByScoreWithScores(rawKey(key), min, max, offset, count)); } + @Deprecated @Override public List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max, - final long offset, final long count){ + final long offset, final long count) { return execute((client)->client.sortedSetOperations() .zRevRangeByScoreWithScores(rawKey(key), min, max, offset, count)); } @Override - public Long zRevRank(final String key, final String member){ + public Long zRevRank(final String key, final String member) { return execute((client)->client.sortedSetOperations().zRevRank(rawKey(key), member)); } @Override - public Long zRevRank(final byte[] key, final byte[] member){ + public Long zRevRank(final byte[] key, final byte[] member) { return execute((client)->client.sortedSetOperations().zRevRank(rawKey(key), member)); } @Override - public ScanResult> zScan(final String key, final long cursor){ + public ScanResult> zScan(final String key, final long cursor) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor)); } @Override - public ScanResult> zScan(final byte[] key, final long cursor){ + public ScanResult> zScan(final byte[] key, final long cursor) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor)); } @Override - public ScanResult> zScan(final String key, final String cursor){ + public ScanResult> zScan(final String key, final String cursor) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor)); } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor){ + public ScanResult> zScan(final byte[] key, final byte[] cursor) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor)); } @Override - public ScanResult> zScan(final String key, final long cursor, final String pattern){ + public ScanResult> zScan(final String key, final long cursor, final String pattern) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern)); } @Override - public ScanResult> zScan(final byte[] key, final long cursor, final byte[] pattern){ + public ScanResult> zScan(final byte[] key, final long cursor, final byte[] pattern) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern)); } @Override - public ScanResult> zScan(final String key, final String cursor, final String pattern){ + public ScanResult> zScan(final String key, final String cursor, final String pattern) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern)); } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern){ + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern)); } @Override - public ScanResult> zScan(final String key, final long cursor, final long count){ + public ScanResult> zScan(final String key, final long cursor, final long count) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, count)); } @Override - public ScanResult> zScan(final byte[] key, final long cursor, final long count){ + public ScanResult> zScan(final byte[] key, final long cursor, final long count) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, count)); } @Override - public ScanResult> zScan(final String key, final String cursor, final long count){ + public ScanResult> zScan(final String key, final String cursor, final long count) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, count)); } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor, final long count){ + public ScanResult> zScan(final byte[] key, final byte[] cursor, final long count) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, count)); } @Override - public ScanResult> zScan(final String key, final long cursor, final String pattern, final long count){ + public ScanResult> zScan(final String key, final long cursor, final String pattern, final long count) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern, count)); } @Override - public ScanResult> zScan(final byte[] key, final long cursor, final byte[] pattern, final long count){ + public ScanResult> zScan(final byte[] key, final long cursor, final byte[] pattern, final long count) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern, count)); } @Override - public ScanResult> zScan(final String key, final String cursor, final String pattern, final long count){ + public ScanResult> zScan(final String key, final String cursor, final String pattern, + final long count) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern, count)); } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, final long count){ + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final long count) { return execute((client)->client.sortedSetOperations().zScan(rawKey(key), cursor, pattern, count)); } @Override - public Double zScore(final String key, final String member){ + public Double zScore(final String key, final String member) { return execute((client)->client.sortedSetOperations().zScore(rawKey(key), member)); } @Override - public Double zScore(final byte[] key, final byte[] member){ + public Double zScore(final byte[] key, final byte[] member) { return execute((client)->client.sortedSetOperations().zScore(rawKey(key), member)); } @Override - public Set zUnion(final String... keys){ + public List zUnion(final String... keys) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys))); } @Override - public Set zUnion(final byte[]... keys){ + public List zUnion(final byte[]... keys) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys))); } @Override - public Set zUnion(final String[] keys, final Aggregate aggregate){ + public List zUnion(final String[] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate)); } @Override - public Set zUnion(final byte[][] keys, final Aggregate aggregate){ + public List zUnion(final byte[][] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate)); } @Override - public Set zUnion(final String[] keys, final double... weights){ + public List zUnion(final String[] keys, final double... weights) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights)); } @Override - public Set zUnion(final byte[][] keys, final double... weights){ + public List zUnion(final byte[][] keys, final double... weights) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights)); } @Override - public Set zUnion(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zUnion(final String[] keys, final Aggregate aggregate, final double... weights) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights)); } @Override - public Set zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights)); } @Override - public Set zUnionWithScores(final String... keys){ + public List zUnionWithScores(final String... keys) { return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys))); } @Override - public Set zUnionWithScores(final byte[]... keys){ + public List zUnionWithScores(final byte[]... keys) { return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys))); } @Override - public Set zUnionWithScores(final String[] keys, final Aggregate aggregate){ + public List zUnionWithScores(final String[] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys), aggregate)); } @Override - public Set zUnionWithScores(final byte[][] keys, final Aggregate aggregate){ + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys), aggregate)); } @Override - public Set zUnionWithScores(final String[] keys, final double... weights){ + public List zUnionWithScores(final String[] keys, final double... weights) { return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys), weights)); } @Override - public Set zUnionWithScores(final byte[][] keys, final double... weights){ + public List zUnionWithScores(final byte[][] keys, final double... weights) { return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys), weights)); } @Override - public Set zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys), aggregate, weights)); } @Override - public Set zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { return execute((client)->client.sortedSetOperations().zUnionWithScores(rawKeys(keys), aggregate, weights)); } @Override - public Long zUnionStore(final String destKey, final String... keys){ + public Long zUnionStore(final String destKey, final String... keys) { return execute((client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys))); } @Override - public Long zUnionStore(final byte[] destKey, final byte[]... keys){ + public Long zUnionStore(final byte[] destKey, final byte[]... keys) { return execute((client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys))); } @Override - public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate){ + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys), aggregate)); } @Override - public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate){ + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys), aggregate)); } @Override - public Long zUnionStore(final String destKey, final String[] keys, final double... weights){ + public Long zUnionStore(final String destKey, final String[] keys, final double... weights) { return execute((client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys), weights)); } @Override - public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights){ + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights) { return execute((client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys), weights)); } @Override public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { return execute( (client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys), aggregate, weights)); } @Override public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { return execute( (client)->client.sortedSetOperations().zUnionStore(rawKey(destKey), rawKeys(keys), aggregate, weights)); } @Override - public Long xAck(final String key, final String groupName, final StreamEntryId... ids){ + public Long xAck(final String key, final String groupName, final StreamEntryId... ids) { return execute((client)->client.streamOperations().xAck(rawKey(key), groupName, ids)); } @Override - public Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId... ids){ + public Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId... ids) { return execute((client)->client.streamOperations().xAck(rawKey(key), groupName, ids)); } @Override - public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash){ + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash) { return execute((client)->client.streamOperations().xAdd(rawKey(key), id, hash)); } @Override - public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, Map hash){ + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, Map hash) { return execute((client)->client.streamOperations().xAdd(rawKey(key), id, hash)); } @Override public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash, - final XAddArgument xAddArgument){ + final XAddArgument xAddArgument) { return execute((client)->client.streamOperations().xAdd(rawKey(key), id, hash, xAddArgument)); } @Override public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash, - final XAddArgument xAddArgument){ + final XAddArgument xAddArgument) { return execute((client)->client.streamOperations().xAdd(rawKey(key), id, hash, xAddArgument)); } @Override public Map> xAutoClaim(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start){ + final StreamEntryId start) { return execute((client)->client.streamOperations() .xAutoClaim(rawKey(key), groupName, consumerName, minIdleTime, start)); } @@ -3616,7 +2829,7 @@ public Map> xAutoClaim(final String key, final @Override public Map> xAutoClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, - final StreamEntryId start){ + final StreamEntryId start) { return execute((client)->client.streamOperations() .xAutoClaim(rawKey(key), groupName, consumerName, minIdleTime, start)); } @@ -3624,7 +2837,7 @@ public Map> xAutoClaim(final byte[] key, final @Override public Map> xAutoClaim(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start, final long count){ + final StreamEntryId start, final long count) { return execute((client)->client.streamOperations() .xAutoClaim(rawKey(key), groupName, consumerName, minIdleTime, start, count)); } @@ -3632,7 +2845,7 @@ public Map> xAutoClaim(final String key, final @Override public Map> xAutoClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, - final StreamEntryId start, final long count){ + final StreamEntryId start, final long count) { return execute((client)->client.streamOperations() .xAutoClaim(rawKey(key), groupName, consumerName, minIdleTime, start, count)); } @@ -3640,7 +2853,7 @@ public Map> xAutoClaim(final byte[] key, final @Override public Map> xAutoClaimJustId(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start){ + final StreamEntryId start) { return execute((client)->client.streamOperations() .xAutoClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, start)); } @@ -3648,7 +2861,7 @@ public Map> xAutoClaimJustId(final String key @Override public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, - final StreamEntryId start){ + final StreamEntryId start) { return execute((client)->client.streamOperations() .xAutoClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, start)); } @@ -3656,7 +2869,7 @@ public Map> xAutoClaimJustId(final byte[] key @Override public Map> xAutoClaimJustId(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start, final long count){ + final StreamEntryId start, final long count) { return execute((client)->client.streamOperations() .xAutoClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, start, count)); } @@ -3664,21 +2877,21 @@ public Map> xAutoClaimJustId(final String key @Override public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, - final StreamEntryId start, final long count){ + final StreamEntryId start, final long count) { return execute((client)->client.streamOperations() .xAutoClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, start, count)); } @Override public List xClaim(final String key, final String groupName, final String consumerName, - final int minIdleTime, final StreamEntryId... ids){ + final int minIdleTime, final StreamEntryId... ids) { return execute( (client)->client.streamOperations().xClaim(rawKey(key), groupName, consumerName, minIdleTime, ids)); } @Override public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, - final int minIdleTime, final StreamEntryId... ids){ + final int minIdleTime, final StreamEntryId... ids) { return execute( (client)->client.streamOperations().xClaim(rawKey(key), groupName, consumerName, minIdleTime, ids)); } @@ -3686,7 +2899,7 @@ public List xClaim(final byte[] key, final byte[] groupName, final @Override public List xClaim(final String key, final String groupName, final String consumerName, final int minIdleTime, final StreamEntryId[] ids, - final XClaimArgument xClaimArgument){ + final XClaimArgument xClaimArgument) { return execute((client)->client.streamOperations() .xClaim(rawKey(key), groupName, consumerName, minIdleTime, ids, xClaimArgument)); } @@ -3694,21 +2907,21 @@ public List xClaim(final String key, final String groupName, final @Override public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, final StreamEntryId[] ids, - final XClaimArgument xClaimArgument){ + final XClaimArgument xClaimArgument) { return execute((client)->client.streamOperations() .xClaim(rawKey(key), groupName, consumerName, minIdleTime, ids, xClaimArgument)); } @Override public List xClaimJustId(final String key, final String groupName, final String consumerName, - final int minIdleTime, final StreamEntryId... ids){ + final int minIdleTime, final StreamEntryId... ids) { return execute((client)->client.streamOperations() .xClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, ids)); } @Override public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, - final int minIdleTime, final StreamEntryId... ids){ + final int minIdleTime, final StreamEntryId... ids) { return execute((client)->client.streamOperations() .xClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, ids)); } @@ -3716,7 +2929,7 @@ public List xClaimJustId(final byte[] key, final byte[] groupName @Override public List xClaimJustId(final String key, final String groupName, final String consumerName, final int minIdleTime, final StreamEntryId[] ids, - final XClaimArgument xClaimArgument){ + final XClaimArgument xClaimArgument) { return execute((client)->client.streamOperations() .xClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, ids, xClaimArgument)); } @@ -3724,211 +2937,211 @@ public List xClaimJustId(final String key, final String groupName @Override public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, final StreamEntryId[] ids, - final XClaimArgument xClaimArgument){ + final XClaimArgument xClaimArgument) { return execute((client)->client.streamOperations() .xClaimJustId(rawKey(key), groupName, consumerName, minIdleTime, ids, xClaimArgument)); } @Override - public Long xDel(final String key, final StreamEntryId... ids){ + public Long xDel(final String key, final StreamEntryId... ids) { return execute((client)->client.streamOperations().xDel(rawKey(key), ids)); } @Override - public Long xDel(final byte[] key, final StreamEntryId... ids){ + public Long xDel(final byte[] key, final StreamEntryId... ids) { return execute((client)->client.streamOperations().xDel(rawKey(key), ids)); } @Override public Status xGroupCreate(final String key, final String groupName, final StreamEntryId id, - final boolean makeStream){ + final boolean makeStream) { return execute((client)->client.streamOperations().xGroupCreate(rawKey(key), groupName, id, makeStream)); } @Override public Status xGroupCreate(final byte[] key, final byte[] groupName, final StreamEntryId id, - final boolean makeStream){ + final boolean makeStream) { return execute((client)->client.streamOperations().xGroupCreate(rawKey(key), groupName, id, makeStream)); } @Override - public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName){ + public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName) { return execute((client)->client.streamOperations().xGroupCreateConsumer(rawKey(key), groupName, consumerName)); } @Override - public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName){ + public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { return execute((client)->client.streamOperations().xGroupCreateConsumer(rawKey(key), groupName, consumerName)); } @Override - public Long xGroupDelConsumer(final String key, final String groupName, final String consumerName){ + public Long xGroupDelConsumer(final String key, final String groupName, final String consumerName) { return execute((client)->client.streamOperations().xGroupDelConsumer(rawKey(key), groupName, consumerName)); } @Override - public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName){ + public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { return execute((client)->client.streamOperations().xGroupDelConsumer(rawKey(key), groupName, consumerName)); } @Override - public Status xGroupDestroy(final String key, final String groupName){ + public Status xGroupDestroy(final String key, final String groupName) { return execute((client)->client.streamOperations().xGroupDestroy(rawKey(key), groupName)); } @Override - public Status xGroupDestroy(final byte[] key, final byte[] groupName){ + public Status xGroupDestroy(final byte[] key, final byte[] groupName) { return execute((client)->client.streamOperations().xGroupDestroy(rawKey(key), groupName)); } @Override - public Status xGroupSetId(final String key, final String groupName, final StreamEntryId id){ + public Status xGroupSetId(final String key, final String groupName, final StreamEntryId id) { return execute((client)->client.streamOperations().xGroupSetId(rawKey(key), groupName, id)); } @Override - public Status xGroupSetId(final byte[] key, final byte[] groupName, final StreamEntryId id){ + public Status xGroupSetId(final byte[] key, final byte[] groupName, final StreamEntryId id) { return execute((client)->client.streamOperations().xGroupSetId(rawKey(key), groupName, id)); } @Override - public List xInfoConsumers(final String key, final String groupName){ + public List xInfoConsumers(final String key, final String groupName) { return execute((client)->client.streamOperations().xInfoConsumers(rawKey(key), groupName)); } @Override - public List xInfoConsumers(final byte[] key, final byte[] groupName){ + public List xInfoConsumers(final byte[] key, final byte[] groupName) { return execute((client)->client.streamOperations().xInfoConsumers(rawKey(key), groupName)); } @Override - public List xInfoGroups(final String key){ + public List xInfoGroups(final String key) { return execute((client)->client.streamOperations().xInfoGroups(rawKey(key))); } @Override - public List xInfoGroups(final byte[] key){ + public List xInfoGroups(final byte[] key) { return execute((client)->client.streamOperations().xInfoGroups(rawKey(key))); } @Override - public Stream xInfoStream(final String key){ + public Stream xInfoStream(final String key) { return execute((client)->client.streamOperations().xInfoStream(rawKey(key))); } @Override - public Stream xInfoStream(final byte[] key){ + public Stream xInfoStream(final byte[] key) { return execute((client)->client.streamOperations().xInfoStream(rawKey(key))); } @Override - public StreamFull xInfoStream(final String key, final boolean full){ + public StreamFull xInfoStream(final String key, final boolean full) { return execute((client)->client.streamOperations().xInfoStream(rawKey(key), full)); } @Override - public StreamFull xInfoStream(final byte[] key, final boolean full){ + public StreamFull xInfoStream(final byte[] key, final boolean full) { return execute((client)->client.streamOperations().xInfoStream(rawKey(key), full)); } @Override - public StreamFull xInfoStream(final String key, final boolean full, final long count){ + public StreamFull xInfoStream(final String key, final boolean full, final long count) { return execute((client)->client.streamOperations().xInfoStream(rawKey(key), full, count)); } @Override - public StreamFull xInfoStream(final byte[] key, final boolean full, final long count){ + public StreamFull xInfoStream(final byte[] key, final boolean full, final long count) { return execute((client)->client.streamOperations().xInfoStream(rawKey(key), full, count)); } @Override - public Long xLen(final String key){ + public Long xLen(final String key) { return execute((client)->client.streamOperations().xLen(rawKey(key))); } @Override - public Long xLen(final byte[] key){ + public Long xLen(final byte[] key) { return execute((client)->client.streamOperations().xLen(rawKey(key))); } @Override - public StreamPendingSummary xPending(final String key, final String groupName){ + public StreamPendingSummary xPending(final String key, final String groupName) { return execute((client)->client.streamOperations().xPending(rawKey(key), groupName)); } @Override - public StreamPendingSummary xPending(final byte[] key, final byte[] groupName){ + public StreamPendingSummary xPending(final byte[] key, final byte[] groupName) { return execute((client)->client.streamOperations().xPending(rawKey(key), groupName)); } @Override - public List xPending(final String key, final String groupName, final long minIdleTime){ + public List xPending(final String key, final String groupName, final long minIdleTime) { return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, minIdleTime)); } @Override - public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime){ + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime) { return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, minIdleTime)); } @Override public List xPending(final String key, final String groupName, final StreamEntryId start, - final StreamEntryId end, final long count){ + final StreamEntryId end, final long count) { return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, start, end, count)); } @Override public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, - final StreamEntryId end, final long count){ + final StreamEntryId end, final long count) { return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, start, end, count)); } @Override - public List xPending(final String key, final String groupName, final String consumerName){ + public List xPending(final String key, final String groupName, final String consumerName) { return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, consumerName)); } @Override - public List xPending(final byte[] key, final byte[] groupName, final byte[] consumerName){ + public List xPending(final byte[] key, final byte[] groupName, final byte[] consumerName) { return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, consumerName)); } @Override public List xPending(final String key, final String groupName, final long minIdleTime, - final StreamEntryId start, final StreamEntryId end, final long count){ + final StreamEntryId start, final StreamEntryId end, final long count) { return execute( (client)->client.streamOperations().xPending(rawKey(key), groupName, minIdleTime, start, end, count)); } @Override public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, - final StreamEntryId start, final StreamEntryId end, final long count){ + final StreamEntryId start, final StreamEntryId end, final long count) { return execute( (client)->client.streamOperations().xPending(rawKey(key), groupName, minIdleTime, start, end, count)); } @Override public List xPending(final String key, final String groupName, final long minIdleTime, - final String consumerName){ + final String consumerName) { return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, minIdleTime, consumerName)); } @Override public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, - final byte[] consumerName){ + final byte[] consumerName) { return execute((client)->client.streamOperations().xPending(rawKey(key), groupName, minIdleTime, consumerName)); } @Override public List xPending(final String key, final String groupName, final StreamEntryId start, - final StreamEntryId end, final long count, final String consumerName){ + final StreamEntryId end, final long count, final String consumerName) { return execute( (client)->client.streamOperations().xPending(rawKey(key), groupName, start, end, count, consumerName)); } @Override public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, - final StreamEntryId end, final long count, final byte[] consumerName){ + final StreamEntryId end, final long count, final byte[] consumerName) { return execute( (client)->client.streamOperations().xPending(rawKey(key), groupName, start, end, count, consumerName)); } @@ -3936,7 +3149,7 @@ public List xPending(final byte[] key, final byte[] groupName, fi @Override public List xPending(final String key, final String groupName, final long minIdleTime, final StreamEntryId start, final StreamEntryId end, final long count, - final String consumerName){ + final String consumerName) { return execute((client)->client.streamOperations() .xPending(rawKey(key), groupName, minIdleTime, start, end, count, consumerName)); } @@ -3944,122 +3157,122 @@ public List xPending(final String key, final String groupName, fi @Override public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, final StreamEntryId start, final StreamEntryId end, final long count, - final byte[] consumerName){ + final byte[] consumerName) { return execute((client)->client.streamOperations() .xPending(rawKey(key), groupName, minIdleTime, start, end, count, consumerName)); } @Override - public List xRange(final String key, final StreamEntryId start, final StreamEntryId end){ + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end) { return execute((client)->client.streamOperations().xRange(rawKey(key), start, end)); } @Override - public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end){ + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end) { return execute((client)->client.streamOperations().xRange(rawKey(key), start, end)); } @Override public List xRange(final String key, final StreamEntryId start, final StreamEntryId end, - final long count){ + final long count) { return execute((client)->client.streamOperations().xRange(rawKey(key), start, end)); } @Override public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end, - final long count){ + final long count) { return execute((client)->client.streamOperations().xRange(rawKey(key), start, end)); } @Override - public List>> xRead(final Map streams){ + public List>> xRead(final Map streams) { return execute((client)->client.streamOperations().xRead(streams)); } @Override - public List>> xRead(final long count, final Map streams){ + public List>> xRead(final long count, final Map streams) { return execute((client)->client.streamOperations().xRead(count, streams)); } @Override - public List>> xRead(final int block, final Map streams){ + public List>> xRead(final int block, final Map streams) { return execute((client)->client.streamOperations().xRead(block, streams)); } @Override public List>> xRead(final long count, final int block, - final Map streams){ + final Map streams) { return execute((client)->client.streamOperations().xRead(count, block, streams)); } @Override public List>> xReadGroup(final String groupName, final String consumerName, - final Map streams){ + final Map streams) { return execute((client)->client.streamOperations().xReadGroup(groupName, consumerName, streams)); } @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, - final Map streams){ + final Map streams) { return execute((client)->client.streamOperations().xReadGroup(groupName, consumerName, streams)); } @Override public List>> xReadGroup(final String groupName, final String consumerName, - final long count, final Map streams){ + final long count, final Map streams) { return execute((client)->client.streamOperations().xReadGroup(groupName, consumerName, count, streams)); } @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, - final long count, final Map streams){ + final long count, final Map streams) { return execute((client)->client.streamOperations().xReadGroup(groupName, consumerName, count, streams)); } @Override public List>> xReadGroup(final String groupName, final String consumerName, - final int block, final Map streams){ + final int block, final Map streams) { return execute((client)->client.streamOperations().xReadGroup(groupName, consumerName, block, streams)); } @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, - final int block, final Map streams){ + final int block, final Map streams) { return execute((client)->client.streamOperations().xReadGroup(groupName, consumerName, block, streams)); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final boolean isNoAck, - final Map streams){ + final Map streams) { return execute((client)->client.streamOperations().xReadGroup(groupName, consumerName, isNoAck, streams)); } @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, final boolean isNoAck, - final Map streams){ + final Map streams) { return execute((client)->client.streamOperations().xReadGroup(groupName, consumerName, isNoAck, streams)); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final long count, final int block, - final Map streams){ + final Map streams) { return execute((client)->client.streamOperations().xReadGroup(groupName, consumerName, count, block, streams)); } @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, final long count, final int block, - final Map streams){ + final Map streams) { return execute((client)->client.streamOperations().xReadGroup(groupName, consumerName, count, block, streams)); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final long count, final boolean isNoAck, - final Map streams){ + final Map streams) { return execute( (client)->client.streamOperations().xReadGroup(groupName, consumerName, count, isNoAck, streams)); } @@ -4067,7 +3280,7 @@ public List>> xReadGroup(final String groupName, f @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, final long count, final boolean isNoAck, - final Map streams){ + final Map streams) { return execute( (client)->client.streamOperations().xReadGroup(groupName, consumerName, count, isNoAck, streams)); } @@ -4075,7 +3288,7 @@ public List>> xReadGroup(final byte[] groupName, f @Override public List>> xReadGroup(final String groupName, final String consumerName, final int block, final boolean isNoAck, - final Map streams){ + final Map streams) { return execute( (client)->client.streamOperations().xReadGroup(groupName, consumerName, block, isNoAck, streams)); } @@ -4083,7 +3296,7 @@ public List>> xReadGroup(final String groupName, f @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, final int block, final boolean isNoAck, - final Map streams){ + final Map streams) { return execute( (client)->client.streamOperations().xReadGroup(groupName, consumerName, block, isNoAck, streams)); } @@ -4091,7 +3304,7 @@ public List>> xReadGroup(final byte[] groupName, f @Override public List>> xReadGroup(final String groupName, final String consumerName, final long count, final int block, final boolean isNoAck, - final Map streams){ + final Map streams) { return execute((client)->client.streamOperations() .xReadGroup(groupName, consumerName, count, block, isNoAck, streams)); } @@ -4099,292 +3312,269 @@ public List>> xReadGroup(final String groupName, f @Override public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, final long count, final int block, final boolean isNoAck, - final Map streams){ + final Map streams) { return execute((client)->client.streamOperations() .xReadGroup(groupName, consumerName, count, block, isNoAck, streams)); } @Override - public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start){ + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start) { return execute((client)->client.streamOperations().xRevRange(rawKey(key), end, start)); } @Override - public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start){ + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start) { return execute((client)->client.streamOperations().xRevRange(rawKey(key), end, start)); } @Override public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start, - final long count){ + final long count) { return execute((client)->client.streamOperations().xRevRange(rawKey(key), end, start, count)); } @Override public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start, - final long count){ + final long count) { return execute((client)->client.streamOperations().xRevRange(rawKey(key), end, start, count)); } @Override - public Long xTrim(final String key, final XTrimArgument xTrimArgument){ + public Long xTrim(final String key, final XTrimArgument xTrimArgument) { return execute((client)->client.streamOperations().xTrim(rawKey(key), xTrimArgument)); } @Override - public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument){ + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument) { return execute((client)->client.streamOperations().xTrim(rawKey(key), xTrimArgument)); } @Override - public Long xTrim(final String key, final XTrimArgument xTrimArgument, final long limit){ + public Long xTrim(final String key, final XTrimArgument xTrimArgument, final long limit) { return execute((client)->client.streamOperations().xTrim(rawKey(key), xTrimArgument, limit)); } @Override - public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit){ + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit) { return execute((client)->client.streamOperations().xTrim(rawKey(key), xTrimArgument, limit)); } @Override - public Long append(final String key, final String value){ + public Long append(final String key, final String value) { return execute((client)->client.stringOperations().append(rawKey(key), value)); } @Override - public Long append(final byte[] key, final byte[] value){ + public Long append(final byte[] key, final byte[] value) { return execute((client)->client.stringOperations().append(rawKey(key), value)); } @Override - public Long incr(final String key){ + public Long incr(final String key) { return execute((client)->client.stringOperations().incr(rawKey(key))); } @Override - public Long incr(final byte[] key){ + public Long incr(final byte[] key) { return execute((client)->client.stringOperations().incr(rawKey(key))); } @Override - public Long incrBy(final String key, final long value){ + public Long incrBy(final String key, final long value) { return execute((client)->client.stringOperations().incrBy(rawKey(key), value)); } @Override - public Long incrBy(final byte[] key, final long value){ + public Long incrBy(final byte[] key, final long value) { return execute((client)->client.stringOperations().incrBy(rawKey(key), value)); } @Override - public Double incrByFloat(final String key, final double value){ + public Double incrByFloat(final String key, final double value) { return execute((client)->client.stringOperations().incrByFloat(rawKey(key), value)); } @Override - public Double incrByFloat(final byte[] key, final double value){ + public Double incrByFloat(final byte[] key, final double value) { return execute((client)->client.stringOperations().incrByFloat(rawKey(key), value)); } @Override - public Long decr(final String key){ + public Long decr(final String key) { return execute((client)->client.stringOperations().decr(rawKey(key))); } @Override - public Long decr(final byte[] key){ + public Long decr(final byte[] key) { return execute((client)->client.stringOperations().decr(rawKey(key))); } @Override - public Long decrBy(final String key, final long value){ + public Long decrBy(final String key, final long value) { return execute((client)->client.stringOperations().decrBy(rawKey(key), value)); } @Override - public Long decrBy(final byte[] key, final long value){ + public Long decrBy(final byte[] key, final long value) { return execute((client)->client.stringOperations().decrBy(rawKey(key), value)); } @Override - public String get(final String key){ + public String get(final String key) { return execute((client)->client.stringOperations().get(rawKey(key))); } @Override - public byte[] get(final byte[] key){ + public byte[] get(final byte[] key) { return execute((client)->client.stringOperations().get(rawKey(key))); } @Override - public String getEx(final String key, final GetExArgument getExArgument){ + public String getEx(final String key, final GetExArgument getExArgument) { return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument)); } @Override - public byte[] getEx(final byte[] key, final GetExArgument getExArgument){ + public byte[] getEx(final byte[] key, final GetExArgument getExArgument) { return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument)); } @Override - public String getSet(final String key, final String value){ + public String getSet(final String key, final String value) { return execute((client)->client.stringOperations().getSet(rawKey(key), value)); } @Override - public byte[] getSet(final byte[] key, final byte[] value){ + public byte[] getSet(final byte[] key, final byte[] value) { return execute((client)->client.stringOperations().getSet(rawKey(key), value)); } @Override - public String getDel(final String key){ + public String getDel(final String key) { return execute((client)->client.stringOperations().getDel(rawKey(key))); } @Override - public byte[] getDel(final byte[] key){ + public byte[] getDel(final byte[] key) { return execute((client)->client.stringOperations().getDel(rawKey(key))); } @Override - public List mGet(final String... keys){ + public List mGet(final String... keys) { return execute((client)->client.stringOperations().mGet(rawKeys(keys))); } @Override - public List mGet(final byte[]... keys){ + public List mGet(final byte[]... keys) { return execute((client)->client.stringOperations().mGet(rawKeys(keys))); } @Override - public Status mSet(final Map values){ + public Status mSet(final Map values) { final Map newValues = Maps.map(values, this::rawKey, (value)->value, new LinkedHashMap<>(values.size())); return execute((client)->client.stringOperations().mSet(newValues)); } @Override - public Status mSetNx(final Map values){ + public Status mSetNx(final Map values) { final Map newValues = Maps.map(values, this::rawKey, (value)->value, new LinkedHashMap<>(values.size())); return execute((client)->client.stringOperations().mSetNx(newValues)); } @Override - public Status pSetEx(final String key, String value, int lifetime){ + public Status pSetEx(final String key, String value, int lifetime) { return execute((client)->client.stringOperations().pSetEx(rawKey(key), value, lifetime)); } @Override - public Status pSetEx(final byte[] key, final byte[] value, final int lifetime){ + public Status pSetEx(final byte[] key, final byte[] value, final int lifetime) { return execute((client)->client.stringOperations().pSetEx(rawKey(key), value, lifetime)); } @Override - public Status set(final String key, final String value){ + public Status set(final String key, final String value) { return execute((client)->client.stringOperations().set(rawKey(key), value)); } @Override - public Status set(final byte[] key, final byte[] value){ + public Status set(final byte[] key, final byte[] value) { return execute((client)->client.stringOperations().set(rawKey(key), value)); } @Override - public Status set(final String key, final String value, final SetArgument setArgument){ + public Status set(final String key, final String value, final SetArgument setArgument) { return execute((client)->client.stringOperations().set(rawKey(key), value, setArgument)); } @Override - public Status set(final byte[] key, final byte[] value, final SetArgument setArgument){ + public Status set(final byte[] key, final byte[] value, final SetArgument setArgument) { return execute((client)->client.stringOperations().set(rawKey(key), value, setArgument)); } @Override - public Status setEx(final String key, final String value, final int lifetime){ + public Status setEx(final String key, final String value, final int lifetime) { return execute((client)->client.stringOperations().setEx(rawKey(key), value, lifetime)); } @Override - public Status setEx(final byte[] key, final byte[] value, final int lifetime){ + public Status setEx(final byte[] key, final byte[] value, final int lifetime) { return execute((client)->client.stringOperations().setEx(rawKey(key), value, lifetime)); } @Override - public Status setNx(final String key, final String value){ + public Status setNx(final String key, final String value) { return execute((client)->client.stringOperations().setNx(rawKey(key), value)); } @Override - public Status setNx(final byte[] key, final byte[] value){ + public Status setNx(final byte[] key, final byte[] value) { return execute((client)->client.stringOperations().setNx(rawKey(key), value)); } @Override - public Long setRange(final String key, final long offset, final String value){ + public Long setRange(final String key, final long offset, final String value) { return execute((client)->client.stringOperations().setRange(rawKey(key), offset, value)); } @Override - public Long setRange(final byte[] key, final long offset, final byte[] value){ + public Long setRange(final byte[] key, final long offset, final byte[] value) { return execute((client)->client.stringOperations().setRange(rawKey(key), offset, value)); } @Override - public String getRange(final String key, final long start, final long end){ + public String getRange(final String key, final long start, final long end) { return execute((client)->client.stringOperations().getRange(rawKey(key), start, end)); } @Override - public byte[] getRange(final byte[] key, final long start, final long end){ + public byte[] getRange(final byte[] key, final long start, final long end) { return execute((client)->client.stringOperations().getRange(rawKey(key), start, end)); } @Override - public Long strlen(final String key){ + public Long strlen(final String key) { return execute((client)->client.stringOperations().strlen(rawKey(key))); } @Override - public Long strlen(final byte[] key){ + public Long strlen(final byte[] key) { return execute((client)->client.stringOperations().strlen(rawKey(key))); } @Override - public String substr(final String key, final long start, final long end){ + public String substr(final String key, final long start, final long end) { return execute((client)->client.stringOperations().substr(rawKey(key), start, end)); } @Override - public byte[] substr(final byte[] key, final long start, final long end){ + public byte[] substr(final byte[] key, final long start, final long end) { return execute((client)->client.stringOperations().substr(rawKey(key), start, end)); } @Override - public Status multi(){ - return execute((client)->client.transactionOperations().multi()); - } - - @Override - public List exec(){ - return execute((client)->{ - RedisConnection connection = client.getConnection(); - - if(connection.isPipeline()){ - final Pipeline pipeline = connection.openPipeline(); - try{ - return pipeline.syncAndReturnAll(); - }finally{ - connection.closePipeline(); - } - }else{ - return client.getConnection().exec(); - } - }); - } - - @Override - public void discard(){ + public void discard() { execute((client)->{ client.getConnection().discard(); return null; @@ -4392,18 +3582,18 @@ public void discard(){ } @Override - public Status watch(final String... keys){ - return execute((client)->client.transactionOperations().watch(rawKeys(keys))); + public List exec() { + return execute((client)->client.getConnection().exec()); } @Override - public Status watch(final byte[]... keys){ + public Status watch(final String... keys) { return execute((client)->client.transactionOperations().watch(rawKeys(keys))); } @Override - public Status unwatch(){ - return execute((client)->client.transactionOperations().unwatch()); + public Status watch(final byte[]... keys) { + return execute((client)->client.transactionOperations().watch(rawKeys(keys))); } } diff --git a/buession-redis/src/main/java/com/buession/redis/RedisAccessor.java b/buession-redis/src/main/java/com/buession/redis/RedisAccessor.java index a58763c99..0bbae2348 100644 --- a/buession-redis/src/main/java/com/buession/redis/RedisAccessor.java +++ b/buession-redis/src/main/java/com/buession/redis/RedisAccessor.java @@ -19,13 +19,15 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis; import com.buession.core.utils.Assert; import com.buession.redis.client.RedisClient; +import com.buession.redis.client.connection.JedisConnectionFactory; +import com.buession.redis.client.connection.LettuceConnectionFactory; import com.buession.redis.client.connection.RedisConnection; import com.buession.redis.client.connection.RedisConnectionFactory; import com.buession.redis.client.connection.RedisConnectionUtils; @@ -33,9 +35,15 @@ import com.buession.redis.client.connection.datasource.jedis.JedisClusterDataSource; import com.buession.redis.client.connection.datasource.jedis.JedisDataSource; import com.buession.redis.client.connection.datasource.jedis.JedisSentinelDataSource; +import com.buession.redis.client.connection.datasource.lettuce.LettuceClusterDataSource; +import com.buession.redis.client.connection.datasource.lettuce.LettuceDataSource; +import com.buession.redis.client.connection.datasource.lettuce.LettuceSentinelDataSource; import com.buession.redis.client.jedis.JedisStandaloneClient; import com.buession.redis.client.jedis.JedisClusterClient; import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; import com.buession.redis.core.Command; import com.buession.redis.core.Options; import com.buession.redis.core.SessionCallback; @@ -53,6 +61,8 @@ import java.util.function.Function; /** + * Base class for {@link RedisTemplate} defining common properties. Not intended to be used directly. + * * @author Yong.Teng */ public abstract class RedisAccessor implements InitializingBean, AutoCloseable { @@ -77,6 +87,8 @@ public abstract class RedisAccessor implements InitializingBean, AutoCloseable { protected boolean enableTransactionSupport = false; + protected RedisClient redisClient; + protected final static ThreadLocal>> txConverters = new ThreadLocal<>(); protected final static ThreadLocal index = new ThreadLocal<>(); @@ -138,7 +150,15 @@ public void afterPropertiesSet() throws RedisException { } if(connectionFactory == null){ - connectionFactory = new RedisConnectionFactory(getDataSource()); + DataSource dataSource = getDataSource(); + + if(dataSource instanceof LettuceDataSource){ + connectionFactory = new LettuceConnectionFactory((LettuceDataSource) dataSource); + }else if(dataSource instanceof JedisDataSource){ + connectionFactory = new JedisConnectionFactory((JedisDataSource) dataSource); + }else{ + Assert.isNull(getDataSource(), "DataSource is required"); + } } } @@ -161,7 +181,7 @@ public Pipeline execute() throws RedisException { @Override public Pipeline run(final CommandArguments arguments) throws RedisException { - return client.getConnection().openPipeline(); + return execute(); } }); @@ -169,21 +189,18 @@ public Pipeline run(final CommandArguments arguments) throws RedisException { public R execute(final SessionCallback callback) throws RedisException { Assert.isNull(callback, "callback cloud not be null."); - checkInitialized(); - RedisConnection connection = fetchConnection(); + RedisConnection connection = fetchRequiredConnection(); RedisClient client = doGetRedisClient(); client.setConnection(connection); - if(isTransactionOrPipeline(connection)){ + if(isMulti(connection)){ index.set(index.get() + 1); } try{ return callback.execute(client); - }catch(Exception e){ - throw new RedisException(e.getMessage(), e); }finally{ RedisConnectionUtils.releaseConnection(connectionFactory, connection, enableTransactionSupport); } @@ -192,21 +209,18 @@ public R execute(final SessionCallback callback) throws RedisException { public TR execute(final SessionCallback callback, final Converter converter) throws RedisException { Assert.isNull(callback, "callback cloud not be null."); - checkInitialized(); - RedisConnection connection = fetchConnection(); + RedisConnection connection = fetchRequiredConnection(); RedisClient client = doGetRedisClient(); client.setConnection(connection); - if(isTransactionOrPipeline(connection)){ + if(isMulti(connection)){ index.set(index.get() + 1); } try{ return converter.convert(connection, callback.execute(client)); - }catch(Exception e){ - throw new RedisException(e.getMessage(), e); }finally{ RedisConnectionUtils.releaseConnection(connectionFactory, connection, enableTransactionSupport); } @@ -218,24 +232,36 @@ public void close() throws Exception { } protected RedisConnection fetchConnection() { - if(enableTransactionSupport){ - return RedisConnectionUtils.bindConnection(connectionFactory, true); - }else{ - return RedisConnectionUtils.getConnection(connectionFactory); - } + return RedisConnectionUtils.bindConnection(connectionFactory, enableTransactionSupport); + } + + protected RedisConnection fetchRequiredConnection() { + checkInitialized(); + return fetchConnection(); } protected RedisClient doGetRedisClient() throws RedisException { - DataSource dataSource = getDataSource(); - if(dataSource instanceof JedisDataSource){ - return new JedisStandaloneClient(); - }else if(dataSource instanceof JedisSentinelDataSource){ - return new JedisSentinelClient(); - }else if(dataSource instanceof JedisClusterDataSource){ - return new JedisClusterClient(); - }else{ - throw new RedisException("Cloud not initialize RedisClient for: " + dataSource); + if(redisClient == null){ + DataSource dataSource = getDataSource(); + + if(dataSource instanceof JedisDataSource){ + redisClient = new JedisStandaloneClient(); + }else if(dataSource instanceof JedisSentinelDataSource){ + redisClient = new JedisSentinelClient(); + }else if(dataSource instanceof JedisClusterDataSource){ + redisClient = new JedisClusterClient(); + }else if(dataSource instanceof LettuceDataSource){ + redisClient = new LettuceStandaloneClient(); + }else if(dataSource instanceof LettuceSentinelDataSource){ + redisClient = new LettuceSentinelClient(); + }else if(dataSource instanceof LettuceClusterDataSource){ + redisClient = new LettuceClusterClient(); + }else{ + throw new RedisException("Cloud not initialize RedisClient for: " + dataSource); + } } + + return redisClient; } protected final void checkInitialized() { @@ -251,7 +277,12 @@ protected boolean isPipeline(final RedisConnection connection) { return connection.isPipeline(); } + @Deprecated protected boolean isTransactionOrPipeline(final RedisConnection connection) { + return isMulti(connection); + } + + protected boolean isMulti(final RedisConnection connection) { return isTransaction(connection) || isPipeline(connection); } diff --git a/buession-redis/src/main/java/com/buession/redis/RedisTemplate.java b/buession-redis/src/main/java/com/buession/redis/RedisTemplate.java index 85cca3ee1..9c8e07cd0 100644 --- a/buession-redis/src/main/java/com/buession/redis/RedisTemplate.java +++ b/buession-redis/src/main/java/com/buession/redis/RedisTemplate.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis; @@ -45,20 +45,20 @@ import java.util.stream.Collectors; /** - * Redis 基本操作封装扩展,可序列化对象和反序列化为对象 + * Redis 命令操作封装扩展,可序列化对象和反序列化为对象 * * @author Yong.Teng * @see BaseRedisTemplate */ public class RedisTemplate extends BaseRedisTemplate implements BitMapOperations, ClusterOperations, - ConnectionOperations, GeoOperations, HashOperations, HyperLogLogOperations, KeyOperations, ListOperations, - PubSubOperations, ScriptingOperations, ServerOperations, SetOperations, SortedSetOperations, + ConnectionOperations, GenericOperations, GeoOperations, HashOperations, HyperLogLogOperations, KeyOperations, + ListOperations, PubSubOperations, ScriptingOperations, ServerOperations, SetOperations, SortedSetOperations, StreamOperations, StringOperations, TransactionOperations { /** * 构造函数 */ - public RedisTemplate(){ + public RedisTemplate() { super(); } @@ -68,120 +68,120 @@ public RedisTemplate(){ * @param dataSource * 数据源 */ - public RedisTemplate(DataSource dataSource){ + public RedisTemplate(DataSource dataSource) { super(dataSource); } @Override - public V hGetObject(final String key, final String field){ + public V hGetObject(final String key, final String field) { return execute((client)->client.hashOperations().hGet(rawKey(key), field), new Converter.SimpleStringConverter<>(this)); } @Override - public V hGetObject(final byte[] key, final byte[] field){ + public V hGetObject(final byte[] key, final byte[] field) { return execute((client)->client.hashOperations().hGet(rawKey(key), field), new Converter.SimpleBinaryConverter<>(this)); } @Override - public V hGetObject(final String key, final String field, final Class clazz){ + public V hGetObject(final String key, final String field, final Class clazz) { return execute((client)->client.hashOperations().hGet(rawKey(key), field), new Converter.ClazzStringConverter<>(this, clazz)); } @Override - public V hGetObject(final byte[] key, final byte[] field, final Class clazz){ + public V hGetObject(final byte[] key, final byte[] field, final Class clazz) { return execute((client)->client.hashOperations().hGet(rawKey(key), field), new Converter.ClazzBinaryConverter<>(this, clazz)); } @Override - public V hGetObject(final String key, final String field, final TypeReference type){ + public V hGetObject(final String key, final String field, final TypeReference type) { return execute((client)->client.hashOperations().hGet(rawKey(key), field), new Converter.TypeStringConverter<>(this, type)); } @Override - public V hGetObject(final byte[] key, final byte[] field, final TypeReference type){ + public V hGetObject(final byte[] key, final byte[] field, final TypeReference type) { return execute((client)->client.hashOperations().hGet(rawKey(key), field), new Converter.TypeBinaryConverter<>(this, type)); } @Override - public Map hGetAllObject(final String key){ + public Map hGetAllObject(final String key) { return execute((client)->client.hashOperations().hGetAll(rawKey(key)), new Converter.SimpleMapStringConverter<>(this)); } @Override - public Map hGetAllObject(final byte[] key){ + public Map hGetAllObject(final byte[] key) { return execute((client)->client.hashOperations().hGetAll(rawKey(key)), new Converter.SimpleMapBinaryConverter<>(this)); } @Override - public Map hGetAllObject(final String key, final Class clazz){ + public Map hGetAllObject(final String key, final Class clazz) { return execute((client)->client.hashOperations().hGetAll(rawKey(key)), new Converter.ClazzMapStringConverter<>(this, clazz)); } @Override - public Map hGetAllObject(final byte[] key, final Class clazz){ + public Map hGetAllObject(final byte[] key, final Class clazz) { return execute((client)->client.hashOperations().hGetAll(rawKey(key)), new Converter.ClazzMapBinaryConverter<>(this, clazz)); } @Override - public Map hGetAllObject(final String key, final TypeReference type){ + public Map hGetAllObject(final String key, final TypeReference type) { return execute((client)->client.hashOperations().hGetAll(rawKey(key)), new Converter.TypeMapStringConverter<>(this, type)); } @Override - public Map hGetAllObject(final byte[] key, final TypeReference type){ + public Map hGetAllObject(final byte[] key, final TypeReference type) { return execute((client)->client.hashOperations().hGetAll(rawKey(key)), new Converter.TypeMapBinaryConverter<>(this, type)); } @Override - public List hMGetObject(final String key, final String... fields){ + public List hMGetObject(final String key, final String... fields) { return execute((client)->client.hashOperations().hMGet(rawKey(key), fields), new Converter.SimpleListStringConverter<>(this)); } @Override - public List hMGetObject(final byte[] key, final byte[]... fields){ + public List hMGetObject(final byte[] key, final byte[]... fields) { return execute((client)->client.hashOperations().hMGet(rawKey(key), fields), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List hMGetObject(final String key, final String[] fields, final Class clazz){ + public List hMGetObject(final String key, final String[] fields, final Class clazz) { return execute((client)->client.hashOperations().hMGet(rawKey(key), fields), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List hMGetObject(final byte[] key, final byte[][] fields, final Class clazz){ + public List hMGetObject(final byte[] key, final byte[][] fields, final Class clazz) { return execute((client)->client.hashOperations().hMGet(rawKey(key), fields), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public List hMGetObject(final String key, final String[] fields, final TypeReference type){ + public List hMGetObject(final String key, final String[] fields, final TypeReference type) { return execute((client)->client.hashOperations().hMGet(rawKey(key), fields), new Converter.TypeListStringConverter<>(this, type)); } @Override - public List hMGetObject(final byte[] key, final byte[][] fields, final TypeReference type){ + public List hMGetObject(final byte[] key, final byte[][] fields, final TypeReference type) { return execute((client)->client.hashOperations().hMGet(rawKey(key), fields), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public Status hMSet(final String key, final List> data){ + public Status hMSet(final String key, final List> data) { Map temp = data.stream() .collect(Collectors.toMap(KeyValue::getKey, (e)->serializer.serialize(e.getValue()), (key1, key2)->key2, LinkedHashMap::new)); @@ -190,7 +190,7 @@ public Status hMSet(final String key, final List> data){ } @Override - public Status hMSet(final byte[] key, final List> data){ + public Status hMSet(final byte[] key, final List> data) { Map temp = data.stream() .collect(Collectors.toMap(KeyValue::getKey, (e)->serializer.serializeAsBytes(e.getValue()), (key1, key2)->key2, LinkedHashMap::new)); @@ -199,2880 +199,2888 @@ public Status hMSet(final byte[] key, final List> data){ } @Override - public Map hRandFieldWithValuesObject(final String key, final long count){ + public Map hRandFieldWithValuesObject(final String key, final long count) { return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count), new Converter.SimpleMapStringConverter<>(this)); } @Override - public Map hRandFieldWithValuesObject(final byte[] key, final long count){ + public Map hRandFieldWithValuesObject(final byte[] key, final long count) { return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count), new Converter.SimpleMapBinaryConverter<>(this)); } @Override - public Map hRandFieldWithValuesObject(final String key, long count, final Class clazz){ + public Map hRandFieldWithValuesObject(final String key, long count, final Class clazz) { return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count), new Converter.ClazzMapStringConverter<>(this, clazz)); } @Override - public Map hRandFieldWithValuesObject(final byte[] key, final long count, final Class clazz){ + public Map hRandFieldWithValuesObject(final byte[] key, final long count, final Class clazz) { return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count), new Converter.ClazzMapBinaryConverter<>(this, clazz)); } @Override public Map hRandFieldWithValuesObject(final String key, final long count, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count), new Converter.TypeMapStringConverter<>(this, type)); } @Override public Map hRandFieldWithValuesObject(final byte[] key, final long count, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.hashOperations().hRandFieldWithValues(rawKey(key), count), new Converter.TypeMapBinaryConverter<>(this, type)); } @Override - public ScanResult> hScanObject(final String key, final long cursor){ + public ScanResult> hScanObject(final String key, final long cursor) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), new Converter.SimpleScanResultMapStringConverter<>(this)); } @Override - public ScanResult> hScanObject(final byte[] key, final long cursor){ + public ScanResult> hScanObject(final byte[] key, final long cursor) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), new Converter.SimpleScanResultMapBinaryConverter<>(this)); } @Override - public ScanResult> hScanObject(final String key, final long cursor, final Class clazz){ + public ScanResult> hScanObject(final String key, final long cursor, final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); } @Override - public ScanResult> hScanObject(final byte[] key, final long cursor, final Class clazz){ + public ScanResult> hScanObject(final byte[] key, final long cursor, final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); } @Override - public ScanResult> hScanObject(final String key, final long cursor, final TypeReference type){ + public ScanResult> hScanObject(final String key, final long cursor, + final TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), new Converter.TypeScanResultMapStringConverter<>(this, type)); } @Override - public ScanResult> hScanObject(final byte[] key, final long cursor, final TypeReference type){ + public ScanResult> hScanObject(final byte[] key, final long cursor, + final TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), new Converter.TypeScanResultMapBinaryConverter<>(this, type)); } @Override - public ScanResult> hScanObject(final String key, final String cursor){ + public ScanResult> hScanObject(final String key, final String cursor) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), new Converter.SimpleScanResultMapStringConverter<>(this)); } @Override - public ScanResult> hScanObject(final byte[] key, final byte[] cursor){ + public ScanResult> hScanObject(final byte[] key, final byte[] cursor) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), new Converter.SimpleScanResultMapBinaryConverter<>(this)); } @Override - public ScanResult> hScanObject(final String key, final String cursor, final Class clazz){ + public ScanResult> hScanObject(final String key, final String cursor, final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); } @Override - public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final Class clazz){ + public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); } @Override public ScanResult> hScanObject(final String key, final String cursor, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), new Converter.TypeScanResultMapStringConverter<>(this, type)); } @Override public ScanResult> hScanObject(final byte[] key, final byte[] cursor, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor), new Converter.TypeScanResultMapBinaryConverter<>(this, type)); } @Override - public ScanResult> hScanObject(final String key, final long cursor, final String pattern){ + public ScanResult> hScanObject(final String key, final long cursor, final String pattern) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), new Converter.SimpleScanResultMapStringConverter<>(this)); } @Override - public ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern){ + public ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), new Converter.SimpleScanResultMapBinaryConverter<>(this)); } @Override public ScanResult> hScanObject(final String key, final long cursor, final String pattern, - final Class clazz){ + final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); } @Override public ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern, - final Class clazz){ + final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); } @Override public ScanResult> hScanObject(final String key, final long cursor, final String pattern, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), new Converter.TypeScanResultMapStringConverter<>(this, type)); } @Override public ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), new Converter.TypeScanResultMapBinaryConverter<>(this, type)); } @Override - public ScanResult> hScanObject(final String key, final String cursor, final String pattern){ + public ScanResult> hScanObject(final String key, final String cursor, final String pattern) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), new Converter.SimpleScanResultMapStringConverter<>(this)); } @Override - public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern){ + public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), new Converter.SimpleScanResultMapBinaryConverter<>(this)); } @Override public ScanResult> hScanObject(final String key, final String cursor, final String pattern, - final Class clazz){ + final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); } @Override public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, - final Class clazz){ + final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); } @Override public ScanResult> hScanObject(final String key, final String cursor, final String pattern, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), new Converter.TypeScanResultMapStringConverter<>(this, type)); } @Override public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern), new Converter.TypeScanResultMapBinaryConverter<>(this, type)); } @Override - public ScanResult> hScanObject(final String key, final long cursor, final long count){ + public ScanResult> hScanObject(final String key, final long cursor, final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), new Converter.SimpleScanResultMapStringConverter<>(this)); } @Override - public ScanResult> hScanObject(final byte[] key, final long cursor, final long count){ + public ScanResult> hScanObject(final byte[] key, final long cursor, final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), new Converter.SimpleScanResultMapBinaryConverter<>(this)); } @Override public ScanResult> hScanObject(final String key, final long cursor, final long count, - final Class clazz){ + final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); } @Override public ScanResult> hScanObject(final byte[] key, final long cursor, final long count, - final Class clazz){ + final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); } @Override public ScanResult> hScanObject(final String key, final long cursor, long count, - TypeReference type){ + TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), new Converter.TypeScanResultMapStringConverter<>(this, type)); } @Override public ScanResult> hScanObject(final byte[] key, final long cursor, final long count, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), new Converter.TypeScanResultMapBinaryConverter<>(this, type)); } @Override - public ScanResult> hScanObject(final String key, final String cursor, final long count){ + public ScanResult> hScanObject(final String key, final String cursor, final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), new Converter.SimpleScanResultMapStringConverter<>(this)); } @Override - public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final long count){ + public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), new Converter.SimpleScanResultMapBinaryConverter<>(this)); } @Override public ScanResult> hScanObject(final String key, final String cursor, final long count, - final Class clazz){ + final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); } @Override public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final long count, - final Class clazz){ + final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); } @Override public ScanResult> hScanObject(final String key, final String cursor, final long count, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), new Converter.TypeScanResultMapStringConverter<>(this, type)); } @Override public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final long count, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, count), new Converter.TypeScanResultMapBinaryConverter<>(this, type)); } @Override public ScanResult> hScanObject(final String key, final long cursor, final String pattern, - final long count){ + final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), new Converter.SimpleScanResultMapStringConverter<>(this)); } @Override public ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern, - final long count){ + final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), new Converter.SimpleScanResultMapBinaryConverter<>(this)); } @Override public ScanResult> hScanObject(final String key, final long cursor, final String pattern, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); } @Override public ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); } @Override public ScanResult> hScanObject(final String key, final long cursor, final String pattern, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), new Converter.TypeScanResultMapStringConverter<>(this, type)); } @Override public ScanResult> hScanObject(final byte[] key, final long cursor, final byte[] pattern, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), new Converter.TypeScanResultMapBinaryConverter<>(this, type)); } @Override public ScanResult> hScanObject(final String key, final String cursor, final String pattern, - final long count){ + final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), new Converter.SimpleScanResultMapStringConverter<>(this)); } @Override public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, - final long count){ + final long count) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), new Converter.SimpleScanResultMapBinaryConverter<>(this)); } @Override public ScanResult> hScanObject(final String key, final String cursor, final String pattern, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), new Converter.ClazzScanResultMapStringConverter<>(this, clazz)); } @Override public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), new Converter.ClazzScanResultMapBinaryConverter<>(this, clazz)); } @Override public ScanResult> hScanObject(final String key, final String cursor, final String pattern, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), new Converter.TypeScanResultMapStringConverter<>(this, type)); } @Override public ScanResult> hScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.hashOperations().hScan(rawKey(key), cursor, pattern, count), new Converter.TypeScanResultMapBinaryConverter<>(this, type)); } @Override - public Long hSet(final String key, final String field, final V value){ + public Long hSet(final String key, final String field, final V value) { return hSet(key, field, serializer.serialize(value)); } @Override - public Long hSet(final byte[] key, final byte[] field, final V value){ + public Long hSet(final byte[] key, final byte[] field, final V value) { return hSet(key, field, serializer.serializeAsBytes(value)); } @Override - public Status hSetNx(final String key, final String field, final V value){ + public Status hSetNx(final String key, final String field, final V value) { return hSetNx(key, field, serializer.serialize(value)); } @Override - public Status hSetNx(final byte[] key, final byte[] field, final V value){ + public Status hSetNx(final byte[] key, final byte[] field, final V value) { return hSetNx(key, field, serializer.serializeAsBytes(value)); } @Override - public List hValsObject(final String key){ + public List hValsObject(final String key) { return execute((client)->client.hashOperations().hVals(rawKey(key)), new Converter.SimpleListStringConverter<>(this)); } @Override - public List hValsObject(final byte[] key){ + public List hValsObject(final byte[] key) { return execute((client)->client.hashOperations().hVals(rawKey(key)), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List hValsObject(final String key, final Class clazz){ + public List hValsObject(final String key, final Class clazz) { return execute((client)->client.hashOperations().hVals(rawKey(key)), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List hValsObject(final byte[] key, final Class clazz){ + public List hValsObject(final byte[] key, final Class clazz) { return execute((client)->client.hashOperations().hVals(rawKey(key)), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public List hValsObject(final String key, final TypeReference type){ + public List hValsObject(final String key, final TypeReference type) { return execute((client)->client.hashOperations().hVals(rawKey(key)), new Converter.TypeListStringConverter<>(this, type)); } @Override - public List hValsObject(final byte[] key, final TypeReference type){ + public List hValsObject(final byte[] key, final TypeReference type) { return execute((client)->client.hashOperations().hVals(rawKey(key)), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public V lIndexObject(final String key, final long index){ + public V lIndexObject(final String key, final long index) { return execute((client)->client.listOperations().lIndex(rawKey(key), index), new Converter.SimpleStringConverter<>(this)); } @Override - public V lIndexObject(final byte[] key, final long index){ + public V lIndexObject(final byte[] key, final long index) { return execute((client)->client.listOperations().lIndex(rawKey(key), index), new Converter.SimpleBinaryConverter<>(this)); } @Override - public V lIndexObject(final String key, final long index, final Class clazz){ + public V lIndexObject(final String key, final long index, final Class clazz) { return execute((client)->client.listOperations().lIndex(rawKey(key), index), new Converter.ClazzStringConverter<>(this, clazz)); } @Override - public V lIndexObject(final byte[] key, final long index, final Class clazz){ + public V lIndexObject(final byte[] key, final long index, final Class clazz) { return execute((client)->client.listOperations().lIndex(rawKey(key), index), new Converter.ClazzBinaryConverter<>(this, clazz)); } @Override - public V lIndexObject(final String key, final long index, final TypeReference type){ + public V lIndexObject(final String key, final long index, final TypeReference type) { return execute((client)->client.listOperations().lIndex(rawKey(key), index), new Converter.TypeStringConverter<>(this, type)); } @Override - public V lIndexObject(final byte[] key, final long index, final TypeReference type){ + public V lIndexObject(final byte[] key, final long index, final TypeReference type) { return execute((client)->client.listOperations().lIndex(rawKey(key), index), new Converter.TypeBinaryConverter<>(this, type)); } @Override - public Long lInsert(final String key, final ListPosition position, final V pivot, final V value){ + public Long lInsert(final String key, final ListPosition position, final V pivot, final V value) { return lInsert(key, position, serializer.serialize(pivot), serializer.serialize(value)); } @Override - public Long lInsert(final byte[] key, final ListPosition position, final V pivot, final V value){ + public Long lInsert(final byte[] key, final ListPosition position, final V pivot, final V value) { return lInsert(key, position, serializer.serializeAsBytes(pivot), serializer.serializeAsBytes(value)); } @Override - public Status lSet(final String key, final long index, final V value){ + public Status lSet(final String key, final long index, final V value) { return lSet(key, index, serializer.serialize(value)); } @Override - public Status lSet(final byte[] key, final long index, final V value){ + public Status lSet(final byte[] key, final long index, final V value) { return lSet(key, index, serializer.serializeAsBytes(value)); } @Override - public List lRangeObject(final String key, final long start, final long end){ + public List lRangeObject(final String key, final long start, final long end) { return execute((client)->client.listOperations().lRange(rawKey(key), start, end), new Converter.SimpleListStringConverter<>(this)); } @Override - public List lRangeObject(final byte[] key, final long start, final long end){ + public List lRangeObject(final byte[] key, final long start, final long end) { return execute((client)->client.listOperations().lRange(rawKey(key), start, end), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List lRangeObject(final String key, final long start, final long end, final Class clazz){ + public List lRangeObject(final String key, final long start, final long end, final Class clazz) { return execute((client)->client.listOperations().lRange(rawKey(key), start, end), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List lRangeObject(final byte[] key, final long start, final long end, final Class clazz){ + public List lRangeObject(final byte[] key, final long start, final long end, final Class clazz) { return execute((client)->client.listOperations().lRange(rawKey(key), start, end), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public List lRangeObject(final String key, final long start, final long end, final TypeReference type){ + public List lRangeObject(final String key, final long start, final long end, final TypeReference type) { return execute((client)->client.listOperations().lRange(rawKey(key), start, end), new Converter.TypeListStringConverter<>(this, type)); } @Override - public List lRangeObject(final byte[] key, final long start, final long end, final TypeReference type){ + public List lRangeObject(final byte[] key, final long start, final long end, final TypeReference type) { return execute((client)->client.listOperations().lRange(rawKey(key), start, end), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public V lMoveObject(final String key, final String destKey, final Direction from, final Direction to){ + public V lMoveObject(final String key, final String destKey, final Direction from, final Direction to) { return execute((client)->client.listOperations().lMove(rawKey(destKey), rawKey(destKey), from, to), new Converter.SimpleStringConverter<>(this)); } @Override - public V lMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to){ + public V lMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { return execute((client)->client.listOperations().lMove(rawKey(destKey), rawKey(destKey), from, to), new Converter.SimpleBinaryConverter<>(this)); } @Override public V lMoveObject(final String key, final String destKey, final Direction from, final Direction to, - final Class clazz){ + final Class clazz) { return execute((client)->client.listOperations().lMove(rawKey(destKey), rawKey(destKey), from, to), new Converter.ClazzStringConverter<>(this, clazz)); } @Override public V lMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to, - final Class clazz){ + final Class clazz) { return execute((client)->client.listOperations().lMove(rawKey(destKey), rawKey(destKey), from, to), new Converter.ClazzBinaryConverter<>(this, clazz)); } @Override public V lMoveObject(final String key, final String destKey, final Direction from, final Direction to, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.listOperations().lMove(rawKey(destKey), rawKey(destKey), from, to), new Converter.TypeStringConverter<>(this, type)); } @Override public V lMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.listOperations().lMove(rawKey(destKey), rawKey(destKey), from, to), new Converter.TypeBinaryConverter<>(this, type)); } @Override public V blMoveObject(final String key, final String destKey, final Direction from, final Direction to, - final int timeout){ + final int timeout) { return execute((client)->client.listOperations().blMove(rawKey(destKey), rawKey(destKey), from, to, timeout), new Converter.SimpleStringConverter<>(this)); } @Override public V blMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to, - final int timeout){ + final int timeout) { return execute((client)->client.listOperations().blMove(rawKey(destKey), rawKey(destKey), from, to, timeout), new Converter.SimpleBinaryConverter<>(this)); } @Override public V blMoveObject(final String key, final String destKey, final Direction from, final Direction to, - final int timeout, final Class clazz){ + final int timeout, final Class clazz) { return execute((client)->client.listOperations().blMove(rawKey(destKey), rawKey(destKey), from, to, timeout), new Converter.ClazzStringConverter<>(this, clazz)); } @Override public V blMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to, - final int timeout, final Class clazz){ + final int timeout, final Class clazz) { return execute((client)->client.listOperations().blMove(rawKey(destKey), rawKey(destKey), from, to, timeout), new Converter.ClazzBinaryConverter<>(this, clazz)); } @Override public V blMoveObject(final String key, final String destKey, final Direction from, final Direction to, - final int timeout, final TypeReference type){ + final int timeout, final TypeReference type) { return execute((client)->client.listOperations().blMove(rawKey(destKey), rawKey(destKey), from, to, timeout), new Converter.TypeStringConverter<>(this, type)); } @Override public V blMoveObject(final byte[] key, final byte[] destKey, final Direction from, final Direction to, - final int timeout, final TypeReference type){ + final int timeout, final TypeReference type) { return execute((client)->client.listOperations().blMove(rawKey(destKey), rawKey(destKey), from, to, timeout), new Converter.TypeBinaryConverter<>(this, type)); } @Override - public List blPopObject(final String[] keys, final int timeout){ + public List blPopObject(final String[] keys, final int timeout) { return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout), new Converter.SimpleListStringConverter<>(this)); } @Override - public List blPopObject(final byte[][] keys, final int timeout){ + public List blPopObject(final byte[][] keys, final int timeout) { return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List blPopObject(final String[] keys, final int timeout, final Class clazz){ + public List blPopObject(final String[] keys, final int timeout, final Class clazz) { return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List blPopObject(final byte[][] keys, final int timeout, final Class clazz){ + public List blPopObject(final byte[][] keys, final int timeout, final Class clazz) { return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public List blPopObject(final String[] keys, final int timeout, final TypeReference type){ + public List blPopObject(final String[] keys, final int timeout, final TypeReference type) { return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout), new Converter.TypeListStringConverter<>(this, type)); } @Override - public List blPopObject(final byte[][] keys, final int timeout, final TypeReference type){ + public List blPopObject(final byte[][] keys, final int timeout, final TypeReference type) { return execute((client)->client.listOperations().blPop(rawKeys(keys), timeout), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public List brPopObject(final String[] keys, final int timeout){ + public List brPopObject(final String[] keys, final int timeout) { return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout), new Converter.SimpleListStringConverter<>(this)); } @Override - public List brPopObject(final byte[][] keys, final int timeout){ + public List brPopObject(final byte[][] keys, final int timeout) { return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List brPopObject(final String[] keys, final int timeout, final Class clazz){ + public List brPopObject(final String[] keys, final int timeout, final Class clazz) { return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List brPopObject(final byte[][] keys, final int timeout, final Class clazz){ + public List brPopObject(final byte[][] keys, final int timeout, final Class clazz) { return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public List brPopObject(final String[] keys, final int timeout, final TypeReference type){ + public List brPopObject(final String[] keys, final int timeout, final TypeReference type) { return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout), new Converter.TypeListStringConverter<>(this, type)); } @Override - public List brPopObject(final byte[][] keys, final int timeout, final TypeReference type){ + public List brPopObject(final byte[][] keys, final int timeout, final TypeReference type) { return execute((client)->client.listOperations().brPop(rawKeys(keys), timeout), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public V brPoplPushObject(final String key, final String destKey, final int timeout){ + public V brPoplPushObject(final String key, final String destKey, final int timeout) { return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout), new Converter.SimpleStringConverter<>(this)); } @Override - public V brPoplPushObject(final byte[] key, final byte[] destKey, final int timeout){ + public V brPoplPushObject(final byte[] key, final byte[] destKey, final int timeout) { return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout), new Converter.SimpleBinaryConverter<>(this)); } @Override - public V brPoplPushObject(final String key, final String destKey, final int timeout, final Class clazz){ + public V brPoplPushObject(final String key, final String destKey, final int timeout, final Class clazz) { return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout), new Converter.ClazzStringConverter<>(this, clazz)); } @Override - public V brPoplPushObject(final byte[] key, final byte[] destKey, final int timeout, final Class clazz){ + public V brPoplPushObject(final byte[] key, final byte[] destKey, final int timeout, final Class clazz) { return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout), new Converter.ClazzBinaryConverter<>(this, clazz)); } @Override public V brPoplPushObject(final String key, final String destKey, final int timeout, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout), new Converter.TypeStringConverter<>(this, type)); } @Override public V brPoplPushObject(final byte[] key, final byte[] destKey, final int timeout, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.listOperations().brPoplPush(rawKey(key), rawKey(destKey), timeout), new Converter.TypeBinaryConverter<>(this, type)); } @Override - public V lPopObject(final String key){ + public V lPopObject(final String key) { return execute((client)->client.listOperations().lPop(rawKey(key)), new Converter.SimpleStringConverter<>(this)); } @Override - public V lPopObject(final byte[] key){ + public V lPopObject(final byte[] key) { return execute((client)->client.listOperations().lPop(rawKey(key)), new Converter.SimpleBinaryConverter<>(this)); } @Override - public V lPopObject(final String key, final Class clazz){ + public V lPopObject(final String key, final Class clazz) { return execute((client)->client.listOperations().lPop(rawKey(key)), new Converter.ClazzStringConverter<>(this, clazz)); } @Override - public V lPopObject(final byte[] key, final Class clazz){ + public V lPopObject(final byte[] key, final Class clazz) { return execute((client)->client.listOperations().lPop(rawKey(key)), new Converter.ClazzBinaryConverter<>(this, clazz)); } @Override - public V lPopObject(final String key, final TypeReference type){ + public V lPopObject(final String key, final TypeReference type) { return execute((client)->client.listOperations().lPop(rawKey(key)), new Converter.TypeStringConverter<>(this, type)); } @Override - public V lPopObject(final byte[] key, final TypeReference type){ + public V lPopObject(final byte[] key, final TypeReference type) { return execute((client)->client.listOperations().lPop(rawKey(key)), new Converter.TypeBinaryConverter<>(this, type)); } @Override - public Long lPush(final String key, final V value){ + public Long lPush(final String key, final V value) { return lPush(key, serializer.serialize(value)); } @Override - public Long lPush(final byte[] key, final V value){ + public Long lPush(final byte[] key, final V value) { return lPush(key, serializer.serializeAsBytes(value)); } @Override - public Long lPush(final String key, final V... values){ + public Long lPush(final String key, final V... values) { return lPush(key, serializer.serialize(values)); } @Override - public Long lPush(final byte[] key, final V... values){ + public Long lPush(final byte[] key, final V... values) { return lPush(key, serializer.serializeAsBytes(values)); } @Override - public Long lPushX(final String key, final V value){ + public Long lPushX(final String key, final V value) { return lPushX(key, serializer.serialize(value)); } @Override - public Long lPushX(final byte[] key, final V value){ + public Long lPushX(final byte[] key, final V value) { return lPushX(key, serializer.serializeAsBytes(value)); } @Override - public Long lPushX(final String key, final V... values){ + public Long lPushX(final String key, final V... values) { return lPushX(key, serializer.serialize(values)); } @Override - public Long lPushX(final byte[] key, final V... values){ + public Long lPushX(final byte[] key, final V... values) { return lPushX(key, serializer.serializeAsBytes(values)); } @Override - public V rPopObject(final String key){ + public V rPopObject(final String key) { return execute((client)->client.listOperations().rPop(rawKey(key)), new Converter.SimpleStringConverter<>(this)); } @Override - public V rPopObject(final byte[] key){ + public V rPopObject(final byte[] key) { return execute((client)->client.listOperations().rPop(rawKey(key)), new Converter.SimpleBinaryConverter<>(this)); } @Override - public V rPopObject(final String key, final Class clazz){ + public V rPopObject(final String key, final Class clazz) { return execute((client)->client.listOperations().rPop(rawKey(key)), new Converter.ClazzStringConverter<>(this, clazz)); } @Override - public V rPopObject(final byte[] key, final Class clazz){ + public V rPopObject(final byte[] key, final Class clazz) { return execute((client)->client.listOperations().rPop(rawKey(key)), new Converter.ClazzBinaryConverter<>(this, clazz)); } @Override - public V rPopObject(final String key, final TypeReference type){ + public V rPopObject(final String key, final TypeReference type) { return execute((client)->client.listOperations().rPop(rawKey(key)), new Converter.TypeStringConverter<>(this, type)); } @Override - public V rPopObject(final byte[] key, final TypeReference type){ + public V rPopObject(final byte[] key, final TypeReference type) { return execute((client)->client.listOperations().rPop(rawKey(key)), new Converter.TypeBinaryConverter<>(this, type)); } @Override - public V rPoplPushObject(final String key, final String destKey){ + public V rPoplPushObject(final String key, final String destKey) { return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey)), new Converter.SimpleStringConverter<>(this)); } @Override - public V rPoplPushObject(final byte[] key, final byte[] destKey){ + public V rPoplPushObject(final byte[] key, final byte[] destKey) { return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey)), new Converter.SimpleBinaryConverter<>(this)); } @Override - public V rPoplPushObject(final String key, final String destKey, final Class clazz){ + public V rPoplPushObject(final String key, final String destKey, final Class clazz) { return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey)), new Converter.ClazzStringConverter<>(this, clazz)); } @Override - public V rPoplPushObject(final byte[] key, final byte[] destKey, final Class clazz){ + public V rPoplPushObject(final byte[] key, final byte[] destKey, final Class clazz) { return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey)), new Converter.ClazzBinaryConverter<>(this, clazz)); } @Override - public V rPoplPushObject(final String key, final String destKey, final TypeReference type){ + public V rPoplPushObject(final String key, final String destKey, final TypeReference type) { return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey)), new Converter.TypeStringConverter<>(this, type)); } @Override - public V rPoplPushObject(final byte[] key, final byte[] destKey, final TypeReference type){ + public V rPoplPushObject(final byte[] key, final byte[] destKey, final TypeReference type) { return execute((client)->client.listOperations().rPoplPush(rawKey(key), rawKey(destKey)), new Converter.TypeBinaryConverter<>(this, type)); } @Override - public Long rPush(final String key, final V value){ + public Long rPush(final String key, final V value) { return rPush(key, serializer.serialize(value)); } @Override - public Long rPush(final byte[] key, final V value){ + public Long rPush(final byte[] key, final V value) { return rPush(key, serializer.serializeAsBytes(value)); } @Override - public Long rPush(final String key, final V... values){ + public Long rPush(final String key, final V... values) { return rPush(key, serializer.serialize(values)); } @Override - public Long rPush(final byte[] key, final V... values){ + public Long rPush(final byte[] key, final V... values) { return rPush(key, serializer.serializeAsBytes(values)); } @Override - public Long rPushX(final String key, final V value){ + public Long rPushX(final String key, final V value) { return rPushX(key, serializer.serialize(value)); } @Override - public Long rPushX(final byte[] key, final V value){ + public Long rPushX(final byte[] key, final V value) { return rPushX(key, serializer.serializeAsBytes(value)); } @Override - public Long rPushX(final String key, final V... values){ + public Long rPushX(final String key, final V... values) { return rPushX(key, serializer.serialize(values)); } @Override - public Long rPushX(final byte[] key, final V... values){ + public Long rPushX(final byte[] key, final V... values) { return rPushX(key, serializer.serializeAsBytes(values)); } @Override - public Long sAdd(final String key, final V... members){ + public Long sAdd(final String key, final V... members) { return sAdd(key, serializer.serialize(members)); } @Override - public Long sAdd(final byte[] key, final V... members){ + public Long sAdd(final byte[] key, final V... members) { return sAdd(key, serializer.serializeAsBytes(members)); } @Override - public Set sDiffObject(final String[] keys){ + public Set sDiffObject(final String[] keys) { return execute((client)->client.setOperations().sDiff(rawKeys(keys)), new Converter.SimpleSetStringConverter<>(this)); } @Override - public Set sDiffObject(final byte[][] keys){ + public Set sDiffObject(final byte[][] keys) { return execute((client)->client.setOperations().sDiff(rawKeys(keys)), new Converter.SimpleSetBinaryConverter<>(this)); } @Override - public Set sDiffObject(final String[] keys, final Class clazz){ + public Set sDiffObject(final String[] keys, final Class clazz) { return execute((client)->client.setOperations().sDiff(rawKeys(keys)), new Converter.ClazzSetStringConverter<>(this, clazz)); } @Override - public Set sDiffObject(final byte[][] keys, final Class clazz){ + public Set sDiffObject(final byte[][] keys, final Class clazz) { return execute((client)->client.setOperations().sDiff(rawKeys(keys)), new Converter.ClazzSetBinaryConverter<>(this, clazz)); } @Override - public Set sDiffObject(final String[] keys, final TypeReference type){ + public Set sDiffObject(final String[] keys, final TypeReference type) { return execute((client)->client.setOperations().sDiff(rawKeys(keys)), new Converter.TypeSetStringConverter<>(this, type)); } @Override - public Set sDiffObject(final byte[][] keys, final TypeReference type){ + public Set sDiffObject(final byte[][] keys, final TypeReference type) { return execute((client)->client.setOperations().sDiff(rawKeys(keys)), new Converter.TypeSetBinaryConverter<>(this, type)); } @Override - public Set sInterObject(final String[] keys){ + public Set sInterObject(final String[] keys) { return execute((client)->client.setOperations().sInter(rawKeys(keys)), new Converter.SimpleSetStringConverter<>(this)); } @Override - public Set sInterObject(final byte[][] keys){ + public Set sInterObject(final byte[][] keys) { return execute((client)->client.setOperations().sInter(rawKeys(keys)), new Converter.SimpleSetBinaryConverter<>(this)); } @Override - public Set sInterObject(final String[] keys, final Class clazz){ + public Set sInterObject(final String[] keys, final Class clazz) { return execute((client)->client.setOperations().sInter(rawKeys(keys)), new Converter.ClazzSetStringConverter<>(this, clazz)); } @Override - public Set sInterObject(final byte[][] keys, final Class clazz){ + public Set sInterObject(final byte[][] keys, final Class clazz) { return execute((client)->client.setOperations().sInter(rawKeys(keys)), new Converter.ClazzSetBinaryConverter<>(this, clazz)); } @Override - public Set sInterObject(final String[] keys, final TypeReference type){ + public Set sInterObject(final String[] keys, final TypeReference type) { return execute((client)->client.setOperations().sInter(rawKeys(keys)), new Converter.TypeSetStringConverter<>(this, type)); } @Override - public Set sInterObject(final byte[][] keys, final TypeReference type){ + public Set sInterObject(final byte[][] keys, final TypeReference type) { return execute((client)->client.setOperations().sInter(rawKeys(keys)), new Converter.TypeSetBinaryConverter<>(this, type)); } @Override - public Set sMembersObject(final String key){ + public Set sMembersObject(final String key) { return execute((client)->client.setOperations().sMembers(rawKey(key)), new Converter.SimpleSetStringConverter<>(this)); } @Override - public Set sMembersObject(final byte[] key){ + public Set sMembersObject(final byte[] key) { return execute((client)->client.setOperations().sMembers(rawKey(key)), new Converter.SimpleSetBinaryConverter<>(this)); } @Override - public Set sMembersObject(final String key, final Class clazz){ + public Set sMembersObject(final String key, final Class clazz) { return execute((client)->client.setOperations().sMembers(rawKey(key)), new Converter.ClazzSetStringConverter<>(this, clazz)); } @Override - public Set sMembersObject(final byte[] key, final Class clazz){ + public Set sMembersObject(final byte[] key, final Class clazz) { return execute((client)->client.setOperations().sMembers(rawKey(key)), new Converter.ClazzSetBinaryConverter<>(this, clazz)); } @Override - public Set sMembersObject(final String key, final TypeReference type){ + public Set sMembersObject(final String key, final TypeReference type) { return execute((client)->client.setOperations().sMembers(rawKey(key)), new Converter.TypeSetStringConverter<>(this, type)); } @Override - public Set sMembersObject(final byte[] key, final TypeReference type){ + public Set sMembersObject(final byte[] key, final TypeReference type) { return execute((client)->client.setOperations().sMembers(rawKey(key)), new Converter.TypeSetBinaryConverter<>(this, type)); } @Override - public V sPopObject(final String key){ + public V sPopObject(final String key) { return execute((client)->client.setOperations().sPop(rawKey(key)), new Converter.SimpleStringConverter<>(this)); } @Override - public V sPopObject(final byte[] key){ + public V sPopObject(final byte[] key) { return execute((client)->client.setOperations().sPop(rawKey(key)), new Converter.SimpleBinaryConverter<>(this)); } @Override - public V sPopObject(final String key, final Class clazz){ + public V sPopObject(final String key, final Class clazz) { return execute((client)->client.setOperations().sPop(rawKey(key)), new Converter.ClazzStringConverter<>(this, clazz)); } @Override - public V sPopObject(final byte[] key, final Class clazz){ + public V sPopObject(final byte[] key, final Class clazz) { return execute((client)->client.setOperations().sPop(rawKey(key)), new Converter.ClazzBinaryConverter<>(this, clazz)); } @Override - public V sPopObject(final String key, final TypeReference type){ + public V sPopObject(final String key, final TypeReference type) { return execute((client)->client.setOperations().sPop(rawKey(key)), new Converter.TypeStringConverter<>(this, type)); } @Override - public V sPopObject(final byte[] key, final TypeReference type){ + public V sPopObject(final byte[] key, final TypeReference type) { return execute((client)->client.setOperations().sPop(rawKey(key)), new Converter.TypeBinaryConverter<>(this, type)); } @Override - public Set sPopObject(final String key, final long count){ + public Set sPopObject(final String key, final long count) { return execute((client)->client.setOperations().sPop(rawKey(key), count), new Converter.SimpleSetStringConverter<>(this)); } @Override - public Set sPopObject(final byte[] key, final long count){ + public Set sPopObject(final byte[] key, final long count) { return execute((client)->client.setOperations().sPop(rawKey(key), count), new Converter.SimpleSetBinaryConverter<>(this)); } @Override - public Set sPopObject(final String key, final long count, final Class clazz){ + public Set sPopObject(final String key, final long count, final Class clazz) { return execute((client)->client.setOperations().sPop(rawKey(key), count), new Converter.ClazzSetStringConverter<>(this, clazz)); } @Override - public Set sPopObject(final byte[] key, final long count, final Class clazz){ + public Set sPopObject(final byte[] key, final long count, final Class clazz) { return execute((client)->client.setOperations().sPop(rawKey(key), count), new Converter.ClazzSetBinaryConverter<>(this, clazz)); } @Override - public Set sPopObject(final String key, final long count, final TypeReference type){ + public Set sPopObject(final String key, final long count, final TypeReference type) { return execute((client)->client.setOperations().sPop(rawKey(key), count), new Converter.TypeSetStringConverter<>(this, type)); } @Override - public Set sPopObject(final byte[] key, final long count, final TypeReference type){ + public Set sPopObject(final byte[] key, final long count, final TypeReference type) { return execute((client)->client.setOperations().sPop(rawKey(key), count), new Converter.TypeSetBinaryConverter<>(this, type)); } @Override - public V sRandMemberObject(final String key){ + public V sRandMemberObject(final String key) { return execute((client)->client.setOperations().sRandMember(rawKey(key)), new Converter.SimpleStringConverter<>(this)); } @Override - public V sRandMemberObject(final byte[] key){ + public V sRandMemberObject(final byte[] key) { return execute((client)->client.setOperations().sRandMember(rawKey(key)), new Converter.SimpleBinaryConverter<>(this)); } @Override - public V sRandMemberObject(final String key, final Class clazz){ + public V sRandMemberObject(final String key, final Class clazz) { return execute((client)->client.setOperations().sRandMember(rawKey(key)), new Converter.ClazzStringConverter<>(this, clazz)); } @Override - public V sRandMemberObject(final byte[] key, final Class clazz){ + public V sRandMemberObject(final byte[] key, final Class clazz) { return execute((client)->client.setOperations().sRandMember(rawKey(key)), new Converter.ClazzBinaryConverter<>(this, clazz)); } @Override - public V sRandMemberObject(final String key, final TypeReference type){ + public V sRandMemberObject(final String key, final TypeReference type) { return execute((client)->client.setOperations().sRandMember(rawKey(key)), new Converter.TypeStringConverter<>(this, type)); } @Override - public V sRandMemberObject(final byte[] key, final TypeReference type){ + public V sRandMemberObject(final byte[] key, final TypeReference type) { return execute((client)->client.setOperations().sRandMember(rawKey(key)), new Converter.TypeBinaryConverter<>(this, type)); } @Override - public List sRandMemberObject(final String key, final long count){ + public List sRandMemberObject(final String key, final long count) { return execute((client)->client.setOperations().sRandMember(rawKey(key), count), new Converter.SimpleListStringConverter<>(this)); } @Override - public List sRandMemberObject(final byte[] key, final long count){ + public List sRandMemberObject(final byte[] key, final long count) { return execute((client)->client.setOperations().sRandMember(rawKey(key), count), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List sRandMemberObject(final String key, final long count, final Class clazz){ + public List sRandMemberObject(final String key, final long count, final Class clazz) { return execute((client)->client.setOperations().sRandMember(rawKey(key), count), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List sRandMemberObject(final byte[] key, final long count, final Class clazz){ + public List sRandMemberObject(final byte[] key, final long count, final Class clazz) { return execute((client)->client.setOperations().sRandMember(rawKey(key), count), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public List sRandMemberObject(final String key, final long count, final TypeReference type){ + public List sRandMemberObject(final String key, final long count, final TypeReference type) { return execute((client)->client.setOperations().sRandMember(rawKey(key), count), new Converter.TypeListStringConverter<>(this, type)); } @Override - public List sRandMemberObject(final byte[] key, final long count, final TypeReference type){ + public List sRandMemberObject(final byte[] key, final long count, final TypeReference type) { return execute((client)->client.setOperations().sRandMember(rawKey(key), count), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public Long sRem(final String key, final V member){ + public Long sRem(final String key, final V member) { return sRem(key, serializer.serialize(member)); } @Override - public Long sRem(final byte[] key, final V member){ + public Long sRem(final byte[] key, final V member) { return sRem(key, serializer.serializeAsBytes(member)); } @Override - public Long sRem(final String key, final V... members){ + public Long sRem(final String key, final V... members) { return sRem(key, serializer.serialize(members)); } @Override - public Long sRem(final byte[] key, final V... members){ + public Long sRem(final byte[] key, final V... members) { return sRem(key, serializer.serializeAsBytes(members)); } @Override - public ScanResult> sScanObject(final String key, final long cursor){ + public ScanResult> sScanObject(final String key, final long cursor) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor), new Converter.SimpleScanResultListStringConverter<>(this)); } @Override - public ScanResult> sScanObject(final byte[] key, final long cursor){ + public ScanResult> sScanObject(final byte[] key, final long cursor) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor), new Converter.SimpleScanResultListBinaryConverter<>(this)); } @Override - public ScanResult> sScanObject(final String key, final long cursor, final Class clazz){ + public ScanResult> sScanObject(final String key, final long cursor, final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor), new Converter.ClazzScanResultListStringConverter<>(this, clazz)); } @Override - public ScanResult> sScanObject(final byte[] key, final long cursor, final Class clazz){ + public ScanResult> sScanObject(final byte[] key, final long cursor, final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor), new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); } @Override - public ScanResult> sScanObject(final String key, final long cursor, final TypeReference type){ + public ScanResult> sScanObject(final String key, final long cursor, final TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor), new Converter.TypeScanResultListStringConverter<>(this, type)); } @Override - public ScanResult> sScanObject(final byte[] key, final long cursor, final TypeReference type){ + public ScanResult> sScanObject(final byte[] key, final long cursor, final TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor), new Converter.TypeScanResultListBinaryConverter<>(this, type)); } @Override - public ScanResult> sScanObject(final String key, final String cursor){ + public ScanResult> sScanObject(final String key, final String cursor) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor), new Converter.SimpleScanResultListStringConverter<>(this)); } @Override - public ScanResult> sScanObject(final byte[] key, final byte[] cursor){ + public ScanResult> sScanObject(final byte[] key, final byte[] cursor) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor), new Converter.SimpleScanResultListBinaryConverter<>(this)); } @Override - public ScanResult> sScanObject(final String key, final String cursor, final Class clazz){ + public ScanResult> sScanObject(final String key, final String cursor, final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor), new Converter.ClazzScanResultListStringConverter<>(this, clazz)); } @Override - public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final Class clazz){ + public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor), new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); } @Override public ScanResult> sScanObject(final String key, final String cursor, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor), new Converter.TypeScanResultListStringConverter<>(this, type)); } @Override public ScanResult> sScanObject(final byte[] key, final byte[] cursor, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor), new Converter.TypeScanResultListBinaryConverter<>(this, type)); } @Override - public ScanResult> sScanObject(final String key, final long cursor, final String pattern){ + public ScanResult> sScanObject(final String key, final long cursor, final String pattern) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), new Converter.SimpleScanResultListStringConverter<>(this)); } @Override - public ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern){ + public ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), new Converter.SimpleScanResultListBinaryConverter<>(this)); } @Override public ScanResult> sScanObject(final String key, final long cursor, final String pattern, - final Class clazz){ + final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), new Converter.ClazzScanResultListStringConverter<>(this, clazz)); } @Override public ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern, - final Class clazz){ + final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); } @Override public ScanResult> sScanObject(final String key, final long cursor, final String pattern, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), new Converter.TypeScanResultListStringConverter<>(this, type)); } @Override public ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), new Converter.TypeScanResultListBinaryConverter<>(this, type)); } @Override - public ScanResult> sScanObject(final String key, final String cursor, final String pattern){ + public ScanResult> sScanObject(final String key, final String cursor, final String pattern) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), new Converter.SimpleScanResultListStringConverter<>(this)); } @Override - public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern){ + public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), new Converter.SimpleScanResultListBinaryConverter<>(this)); } @Override public ScanResult> sScanObject(final String key, final String cursor, final String pattern, - final Class clazz){ + final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), new Converter.ClazzScanResultListStringConverter<>(this, clazz)); } @Override public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, - final Class clazz){ + final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); } @Override public ScanResult> sScanObject(final String key, final String cursor, final String pattern, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), new Converter.TypeScanResultListStringConverter<>(this, type)); } @Override public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern), new Converter.TypeScanResultListBinaryConverter<>(this, type)); } @Override - public ScanResult> sScanObject(final String key, final long cursor, final long count){ + public ScanResult> sScanObject(final String key, final long cursor, final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), new Converter.SimpleScanResultListStringConverter<>(this)); } @Override - public ScanResult> sScanObject(final byte[] key, final long cursor, final long count){ + public ScanResult> sScanObject(final byte[] key, final long cursor, final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), new Converter.SimpleScanResultListBinaryConverter<>(this)); } @Override public ScanResult> sScanObject(final String key, final long cursor, final long count, - final Class clazz){ + final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), new Converter.ClazzScanResultListStringConverter<>(this, clazz)); } @Override public ScanResult> sScanObject(final byte[] key, final long cursor, final long count, - final Class clazz){ + final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); } @Override public ScanResult> sScanObject(final String key, final long cursor, long count, - TypeReference type){ + TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), new Converter.TypeScanResultListStringConverter<>(this, type)); } @Override public ScanResult> sScanObject(final byte[] key, final long cursor, final long count, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), new Converter.TypeScanResultListBinaryConverter<>(this, type)); } @Override - public ScanResult> sScanObject(final String key, final String cursor, final long count){ + public ScanResult> sScanObject(final String key, final String cursor, final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), new Converter.SimpleScanResultListStringConverter<>(this)); } @Override - public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final long count){ + public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), new Converter.SimpleScanResultListBinaryConverter<>(this)); } @Override public ScanResult> sScanObject(final String key, final String cursor, final long count, - final Class clazz){ + final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), new Converter.ClazzScanResultListStringConverter<>(this, clazz)); } @Override public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final long count, - final Class clazz){ + final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); } @Override public ScanResult> sScanObject(final String key, final String cursor, final long count, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), new Converter.TypeScanResultListStringConverter<>(this, type)); } @Override public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final long count, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, count), new Converter.TypeScanResultListBinaryConverter<>(this, type)); } @Override public ScanResult> sScanObject(final String key, final long cursor, final String pattern, - final long count){ + final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), new Converter.SimpleScanResultListStringConverter<>(this)); } @Override public ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern, - final long count){ + final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), new Converter.SimpleScanResultListBinaryConverter<>(this)); } @Override public ScanResult> sScanObject(final String key, final long cursor, final String pattern, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), new Converter.ClazzScanResultListStringConverter<>(this, clazz)); } @Override public ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); } @Override public ScanResult> sScanObject(final String key, final long cursor, final String pattern, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), new Converter.TypeScanResultListStringConverter<>(this, type)); } @Override public ScanResult> sScanObject(final byte[] key, final long cursor, final byte[] pattern, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), new Converter.TypeScanResultListBinaryConverter<>(this, type)); } @Override public ScanResult> sScanObject(final String key, final String cursor, final String pattern, - final long count){ + final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), new Converter.SimpleScanResultListStringConverter<>(this)); } @Override public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, - final long count){ + final long count) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), new Converter.SimpleScanResultListBinaryConverter<>(this)); } @Override public ScanResult> sScanObject(final String key, final String cursor, final String pattern, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), new Converter.ClazzScanResultListStringConverter<>(this, clazz)); } @Override public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), new Converter.ClazzScanResultListBinaryConverter<>(this, clazz)); } @Override public ScanResult> sScanObject(final String key, final String cursor, final String pattern, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), new Converter.TypeScanResultListStringConverter<>(this, type)); } @Override public ScanResult> sScanObject(final byte[] key, final byte[] cursor, final byte[] pattern, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.setOperations().sScan(rawKey(key), cursor, pattern, count), new Converter.TypeScanResultListBinaryConverter<>(this, type)); } @Override - public Set sUnionObject(final String[] keys){ + public Set sUnionObject(final String[] keys) { return execute((client)->client.setOperations().sUnion(rawKeys(keys)), new Converter.SimpleSetStringConverter<>(this)); } @Override - public Set sUnionObject(final byte[][] keys){ + public Set sUnionObject(final byte[][] keys) { return execute((client)->client.setOperations().sUnion(rawKeys(keys)), new Converter.SimpleSetBinaryConverter<>(this)); } @Override - public Set sUnionObject(final String[] keys, final Class clazz){ + public Set sUnionObject(final String[] keys, final Class clazz) { return execute((client)->client.setOperations().sUnion(rawKeys(keys)), new Converter.ClazzSetStringConverter<>(this, clazz)); } @Override - public Set sUnionObject(final byte[][] keys, final Class clazz){ + public Set sUnionObject(final byte[][] keys, final Class clazz) { return execute((client)->client.setOperations().sUnion(rawKeys(keys)), new Converter.ClazzSetBinaryConverter<>(this, clazz)); } @Override - public Set sUnionObject(final String[] keys, final TypeReference type){ + public Set sUnionObject(final String[] keys, final TypeReference type) { return execute((client)->client.setOperations().sUnion(rawKeys(keys)), new Converter.TypeSetStringConverter<>(this, type)); } @Override - public Set sUnionObject(final byte[][] keys, final TypeReference type){ + public Set sUnionObject(final byte[][] keys, final TypeReference type) { return execute((client)->client.setOperations().sUnion(rawKeys(keys)), new Converter.TypeSetBinaryConverter<>(this, type)); } @Override - public Long zAdd(final String key, final double score, final V member){ + public Long zAdd(final String key, final double score, final V member) { return zAdd(key, score, serializer.serialize(member)); } @Override - public Long zAdd(final byte[] key, final double score, final V member){ + public Long zAdd(final byte[] key, final double score, final V member) { return zAdd(key, score, serializer.serialize(member)); } @Override - public Long zAdd(final String key, final double score, final V member, final NxXx nxXx){ + public Long zAdd(final String key, final double score, final V member, final NxXx nxXx) { return zAdd(key, score, serializer.serialize(member), nxXx); } @Override - public Long zAdd(final byte[] key, final double score, final V member, final NxXx nxXx){ + public Long zAdd(final byte[] key, final double score, final V member, final NxXx nxXx) { return zAdd(key, score, serializer.serialize(member), nxXx); } @Override - public Long zAdd(final String key, final double score, final V member, final GtLt gtLt){ + public Long zAdd(final String key, final double score, final V member, final GtLt gtLt) { return zAdd(key, score, serializer.serialize(member), gtLt); } @Override - public Long zAdd(final byte[] key, final double score, final V member, final GtLt gtLt){ + public Long zAdd(final byte[] key, final double score, final V member, final GtLt gtLt) { return zAdd(key, score, serializer.serialize(member), gtLt); } @Override - public Long zAdd(final String key, final double score, final V member, final boolean ch){ + public Long zAdd(final String key, final double score, final V member, final boolean ch) { return zAdd(key, score, serializer.serialize(member), ch); } @Override - public Long zAdd(final byte[] key, final double score, final V member, final boolean ch){ + public Long zAdd(final byte[] key, final double score, final V member, final boolean ch) { return zAdd(key, score, serializer.serialize(member), ch); } @Override - public Long zAdd(final String key, final double score, final V member, final NxXx nxXx, final GtLt gtLt){ + public Long zAdd(final String key, final double score, final V member, final NxXx nxXx, final GtLt gtLt) { return zAdd(key, score, serializer.serialize(member), nxXx, gtLt); } @Override - public Long zAdd(final byte[] key, final double score, final V member, final NxXx nxXx, final GtLt gtLt){ + public Long zAdd(final byte[] key, final double score, final V member, final NxXx nxXx, final GtLt gtLt) { return zAdd(key, score, serializer.serialize(member), nxXx, gtLt); } @Override - public Long zAdd(final String key, final double score, final V member, final NxXx nxXx, final boolean ch){ + public Long zAdd(final String key, final double score, final V member, final NxXx nxXx, final boolean ch) { return zAdd(key, score, serializer.serialize(member), nxXx, ch); } @Override - public Long zAdd(final byte[] key, final double score, final V member, final NxXx nxXx, final boolean ch){ + public Long zAdd(final byte[] key, final double score, final V member, final NxXx nxXx, final boolean ch) { return zAdd(key, score, serializer.serialize(member), nxXx, ch); } @Override - public Long zAdd(final String key, final double score, final V member, final GtLt gtLt, final boolean ch){ + public Long zAdd(final String key, final double score, final V member, final GtLt gtLt, final boolean ch) { return zAdd(key, score, serializer.serialize(member), gtLt, ch); } @Override - public Long zAdd(final byte[] key, final double score, final V member, final GtLt gtLt, final boolean ch){ + public Long zAdd(final byte[] key, final double score, final V member, final GtLt gtLt, final boolean ch) { return zAdd(key, score, serializer.serialize(member), gtLt, ch); } @Override public Long zAdd(final String key, final double score, final V member, final NxXx nxXx, final GtLt gtLt, - final boolean ch){ + final boolean ch) { return zAdd(key, score, serializer.serialize(member), nxXx, gtLt, ch); } @Override public Long zAdd(final byte[] key, final double score, final V member, final NxXx nxXx, final GtLt gtLt, - final boolean ch){ + final boolean ch) { return zAdd(key, score, serializer.serialize(member), nxXx, gtLt, ch); } @Override - public Set zDiffObject(final String[] keys){ + public List zDiffObject(final String[] keys) { return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys)), - new Converter.SimpleSetStringConverter<>(this)); + new Converter.SimpleListStringConverter<>(this)); } @Override - public Set zDiffObject(final byte[][] keys){ + public List zDiffObject(final byte[][] keys) { return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys)), - new Converter.SimpleSetBinaryConverter<>(this)); + new Converter.SimpleListBinaryConverter<>(this)); } @Override - public Set zDiffObject(final String[] keys, final Class clazz){ + public List zDiffObject(final String[] keys, final Class clazz) { return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys)), - new Converter.ClazzSetStringConverter<>(this, clazz)); + new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public Set zDiffObject(final byte[][] keys, final Class clazz){ + public List zDiffObject(final byte[][] keys, final Class clazz) { return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys)), - new Converter.ClazzSetBinaryConverter<>(this, clazz)); + new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public Set zDiffObject(final String[] keys, final TypeReference type){ + public List zDiffObject(final String[] keys, final TypeReference type) { return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys)), - new Converter.TypeSetStringConverter<>(this, type)); + new Converter.TypeListStringConverter<>(this, type)); } @Override - public Set zDiffObject(final byte[][] keys, final TypeReference type){ + public List zDiffObject(final byte[][] keys, final TypeReference type) { return execute((client)->client.sortedSetOperations().zDiff(rawKeys(keys)), - new Converter.TypeSetBinaryConverter<>(this, type)); + new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public Set zInterObject(final String[] keys){ + public List zInterObject(final String[] keys) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys)), - new Converter.SimpleSetStringConverter<>(this)); + new Converter.SimpleListStringConverter<>(this)); } @Override - public Set zInterObject(final byte[][] keys){ + public List zInterObject(final byte[][] keys) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys)), - new Converter.SimpleSetBinaryConverter<>(this)); + new Converter.SimpleListBinaryConverter<>(this)); } @Override - public Set zInterObject(final String[] keys, final Class clazz){ + public List zInterObject(final String[] keys, final Class clazz) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys)), - new Converter.ClazzSetStringConverter<>(this, clazz)); + new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public Set zInterObject(final byte[][] keys, final Class clazz){ + public List zInterObject(final byte[][] keys, final Class clazz) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys)), - new Converter.ClazzSetBinaryConverter<>(this, clazz)); + new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public Set zInterObject(final String[] keys, final TypeReference type){ + public List zInterObject(final String[] keys, final TypeReference type) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys)), - new Converter.TypeSetStringConverter<>(this, type)); + new Converter.TypeListStringConverter<>(this, type)); } @Override - public Set zInterObject(final byte[][] keys, final TypeReference type){ + public List zInterObject(final byte[][] keys, final TypeReference type) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys)), - new Converter.TypeSetBinaryConverter<>(this, type)); + new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public Set zInterObject(final String[] keys, final Aggregate aggregate){ + public List zInterObject(final String[] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate), - new Converter.SimpleSetStringConverter<>(this)); + new Converter.SimpleListStringConverter<>(this)); } @Override - public Set zInterObject(final byte[][] keys, final Aggregate aggregate){ + public List zInterObject(final byte[][] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate), - new Converter.SimpleSetBinaryConverter<>(this)); + new Converter.SimpleListBinaryConverter<>(this)); } @Override - public Set zInterObject(final String[] keys, final Aggregate aggregate, final Class clazz){ + public List zInterObject(final String[] keys, final Aggregate aggregate, final Class clazz) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate), - new Converter.ClazzSetStringConverter<>(this, clazz)); + new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public Set zInterObject(final byte[][] keys, final Aggregate aggregate, final Class clazz){ + public List zInterObject(final byte[][] keys, final Aggregate aggregate, final Class clazz) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate), - new Converter.ClazzSetBinaryConverter<>(this, clazz)); + new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public Set zInterObject(final String[] keys, final Aggregate aggregate, final TypeReference type){ + public List zInterObject(final String[] keys, final Aggregate aggregate, final TypeReference type) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate), - new Converter.TypeSetStringConverter<>(this, type)); + new Converter.TypeListStringConverter<>(this, type)); } @Override - public Set zInterObject(final byte[][] keys, final Aggregate aggregate, final TypeReference type){ + public List zInterObject(final byte[][] keys, final Aggregate aggregate, final TypeReference type) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate), - new Converter.TypeSetBinaryConverter<>(this, type)); + new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public Set zInterObject(final String[] keys, final double[] weights){ + public List zInterObject(final String[] keys, final double[] weights) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights), - new Converter.SimpleSetStringConverter<>(this)); + new Converter.SimpleListStringConverter<>(this)); } @Override - public Set zInterObject(final byte[][] keys, final double[] weights){ + public List zInterObject(final byte[][] keys, final double[] weights) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights), - new Converter.SimpleSetBinaryConverter<>(this)); + new Converter.SimpleListBinaryConverter<>(this)); } @Override - public Set zInterObject(final String[] keys, final double[] weights, final Class clazz){ + public List zInterObject(final String[] keys, final double[] weights, final Class clazz) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights), - new Converter.ClazzSetStringConverter<>(this, clazz)); + new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public Set zInterObject(final byte[][] keys, final double[] weights, final Class clazz){ + public List zInterObject(final byte[][] keys, final double[] weights, final Class clazz) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights), - new Converter.ClazzSetBinaryConverter<>(this, clazz)); + new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public Set zInterObject(final String[] keys, final double[] weights, final TypeReference type){ + public List zInterObject(final String[] keys, final double[] weights, final TypeReference type) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights), - new Converter.TypeSetStringConverter<>(this, type)); + new Converter.TypeListStringConverter<>(this, type)); } @Override - public Set zInterObject(final byte[][] keys, final double[] weights, final TypeReference type){ + public List zInterObject(final byte[][] keys, final double[] weights, final TypeReference type) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), weights), - new Converter.TypeSetBinaryConverter<>(this, type)); + new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public Set zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights){ + public List zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights), - new Converter.SimpleSetStringConverter<>(this)); + new Converter.SimpleListStringConverter<>(this)); } @Override - public Set zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights){ + public List zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights), - new Converter.SimpleSetBinaryConverter<>(this)); + new Converter.SimpleListBinaryConverter<>(this)); } @Override - public Set zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights, - final Class clazz){ + public List zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final Class clazz) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights), - new Converter.ClazzSetStringConverter<>(this, clazz)); + new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public Set zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, - final Class clazz){ + public List zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final Class clazz) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights), - new Converter.ClazzSetBinaryConverter<>(this, clazz)); + new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public Set zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights, - final TypeReference type){ + public List zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights), - new Converter.TypeSetStringConverter<>(this, type)); + new Converter.TypeListStringConverter<>(this, type)); } @Override - public Set zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, - final TypeReference type){ + public List zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type) { return execute((client)->client.sortedSetOperations().zInter(rawKeys(keys), aggregate, weights), - new Converter.TypeSetBinaryConverter<>(this, type)); + new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public V zRandMemberObject(final String key){ + public V zRandMemberObject(final String key) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key)), new Converter.SimpleStringConverter<>(this)); } @Override - public V zRandMemberObject(final byte[] key){ + public V zRandMemberObject(final byte[] key) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key)), new Converter.SimpleBinaryConverter<>(this)); } @Override - public V zRandMemberObject(final String key, final Class clazz){ + public V zRandMemberObject(final String key, final Class clazz) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key)), new Converter.ClazzStringConverter<>(this, clazz)); } @Override - public V zRandMemberObject(final byte[] key, final Class clazz){ + public V zRandMemberObject(final byte[] key, final Class clazz) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key)), new Converter.ClazzBinaryConverter<>(this, clazz)); } @Override - public V zRandMemberObject(final String key, final TypeReference type){ + public V zRandMemberObject(final String key, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key)), new Converter.TypeStringConverter<>(this, type)); } @Override - public V zRandMemberObject(final byte[] key, final TypeReference type){ + public V zRandMemberObject(final byte[] key, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key)), new Converter.TypeBinaryConverter<>(this, type)); } @Override - public List zRandMemberObject(final String key, final long count){ + public List zRandMemberObject(final String key, final long count) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count), new Converter.SimpleListStringConverter<>(this)); } @Override - public List zRandMemberObject(final byte[] key, final long count){ + public List zRandMemberObject(final byte[] key, final long count) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List zRandMemberObject(final String key, final long count, final Class clazz){ + public List zRandMemberObject(final String key, final long count, final Class clazz) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List zRandMemberObject(final byte[] key, final long count, final Class clazz){ + public List zRandMemberObject(final byte[] key, final long count, final Class clazz) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public List zRandMemberObject(final String key, final long count, final TypeReference type){ + public List zRandMemberObject(final String key, final long count, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count), new Converter.TypeListStringConverter<>(this, type)); } @Override - public List zRandMemberObject(final byte[] key, final long count, final TypeReference type){ + public List zRandMemberObject(final byte[] key, final long count, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRandMember(rawKey(key), count), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public List zRangeObject(final String key, final long start, final long end){ + public List zRangeObject(final String key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end), new Converter.SimpleListStringConverter<>(this)); } @Override - public List zRangeObject(final byte[] key, final long start, final long end){ + public List zRangeObject(final byte[] key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List zRangeObject(final String key, final long start, final long end, final Class clazz){ + public List zRangeObject(final String key, final long start, final long end, final Class clazz) { return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List zRangeObject(final byte[] key, final long start, final long end, final Class clazz){ + public List zRangeObject(final byte[] key, final long start, final long end, final Class clazz) { return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public List zRangeObject(final String key, final long start, final long end, final TypeReference type){ + public List zRangeObject(final String key, final long start, final long end, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end), new Converter.TypeListStringConverter<>(this, type)); } @Override - public List zRangeObject(final byte[] key, final long start, final long end, final TypeReference type){ + public List zRangeObject(final byte[] key, final long start, final long end, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRange(rawKey(key), start, end), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public List zRangeByLexObject(final String key, final double min, final double max){ + public List zRangeByLexObject(final String key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), new Converter.SimpleListStringConverter<>(this)); } @Override - public List zRangeByLexObject(final byte[] key, final double min, final double max){ + public List zRangeByLexObject(final byte[] key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List zRangeByLexObject(final String key, final double min, final double max, final Class clazz){ + public List zRangeByLexObject(final String key, final double min, final double max, final Class clazz) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List zRangeByLexObject(final byte[] key, final double min, final double max, final Class clazz){ + public List zRangeByLexObject(final byte[] key, final double min, final double max, final Class clazz) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override public List zRangeByLexObject(final String key, final double min, final double max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), new Converter.TypeListStringConverter<>(this, type)); } @Override public List zRangeByLexObject(final byte[] key, final double min, final double max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public List zRangeByLexObject(final String key, final String min, final String max){ + public List zRangeByLexObject(final String key, final String min, final String max) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), new Converter.SimpleListStringConverter<>(this)); } @Override - public List zRangeByLexObject(final byte[] key, final byte[] min, final byte[] max){ + public List zRangeByLexObject(final byte[] key, final byte[] min, final byte[] max) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List zRangeByLexObject(final String key, final String min, final String max, final Class clazz){ + public List zRangeByLexObject(final String key, final String min, final String max, final Class clazz) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List zRangeByLexObject(final byte[] key, final byte[] min, final byte[] max, final Class clazz){ + public List zRangeByLexObject(final byte[] key, final byte[] min, final byte[] max, final Class clazz) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override public List zRangeByLexObject(final String key, final String min, final String max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), new Converter.TypeListStringConverter<>(this, type)); } @Override public List zRangeByLexObject(final byte[] key, final byte[] min, final byte[] max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRangeByLex(rawKey(key), min, max), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public List zRangeByScoreObject(final String key, final double min, final double max){ + public List zRangeByScoreObject(final String key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), new Converter.SimpleListStringConverter<>(this)); } @Override - public List zRangeByScoreObject(final byte[] key, final double min, final double max){ + public List zRangeByScoreObject(final byte[] key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List zRangeByScoreObject(final String key, final double min, final double max, final Class clazz){ + public List zRangeByScoreObject(final String key, final double min, final double max, final Class clazz) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List zRangeByScoreObject(final byte[] key, final double min, final double max, final Class clazz){ + public List zRangeByScoreObject(final byte[] key, final double min, final double max, final Class clazz) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override public List zRangeByScoreObject(final String key, final double min, final double max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), new Converter.TypeListStringConverter<>(this, type)); } @Override public List zRangeByScoreObject(final byte[] key, final double min, final double max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public List zRangeByScoreObject(final String key, final String min, final String max){ + public List zRangeByScoreObject(final String key, final String min, final String max) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), new Converter.SimpleListStringConverter<>(this)); } @Override - public List zRangeByScoreObject(final byte[] key, final byte[] min, final byte[] max){ + public List zRangeByScoreObject(final byte[] key, final byte[] min, final byte[] max) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List zRangeByScoreObject(final String key, final String min, final String max, final Class clazz){ + public List zRangeByScoreObject(final String key, final String min, final String max, final Class clazz) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List zRangeByScoreObject(final byte[] key, final byte[] min, final byte[] max, final Class clazz){ + public List zRangeByScoreObject(final byte[] key, final byte[] min, final byte[] max, final Class clazz) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override public List zRangeByScoreObject(final String key, final String min, final String max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), new Converter.TypeListStringConverter<>(this, type)); } @Override public List zRangeByScoreObject(final byte[] key, final byte[] min, final byte[] max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max), new Converter.TypeListBinaryConverter<>(this, type)); } @Override public List zRangeByScoreObject(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), new Converter.SimpleListStringConverter<>(this)); } @Override public List zRangeByScoreObject(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), new Converter.SimpleListBinaryConverter<>(this)); } @Override public List zRangeByScoreObject(final String key, final double min, final double max, final long offset, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override public List zRangeByScoreObject(final byte[] key, final double min, final double max, final long offset, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override public List zRangeByScoreObject(final String key, final double min, final double max, final long offset, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), new Converter.TypeListStringConverter<>(this, type)); } @Override public List zRangeByScoreObject(final byte[] key, final double min, final double max, final long offset, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), new Converter.TypeListBinaryConverter<>(this, type)); } @Override public List zRangeByScoreObject(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), new Converter.SimpleListStringConverter<>(this)); } @Override public List zRangeByScoreObject(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), new Converter.SimpleListBinaryConverter<>(this)); } @Override public List zRangeByScoreObject(final String key, final String min, final String max, final long offset, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override public List zRangeByScoreObject(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override public List zRangeByScoreObject(final String key, final String min, final String max, final long offset, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), new Converter.TypeListStringConverter<>(this, type)); } @Override public List zRangeByScoreObject(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRangeByScore(key, min, max, offset, count), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public List zRevRangeObject(final String key, final long start, final long end){ + public List zRevRangeObject(final String key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRevRange(key, start, end), new Converter.SimpleListStringConverter<>(this)); } @Override - public List zRevRangeObject(final byte[] key, final long start, final long end){ + public List zRevRangeObject(final byte[] key, final long start, final long end) { return execute((client)->client.sortedSetOperations().zRevRange(key, start, end), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List zRevRangeObject(final String key, final long start, final long end, final Class clazz){ + public List zRevRangeObject(final String key, final long start, final long end, final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRange(key, start, end), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List zRevRangeObject(final byte[] key, final long start, final long end, final Class clazz){ + public List zRevRangeObject(final byte[] key, final long start, final long end, final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRange(key, start, end), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public List zRevRangeObject(final String key, final long start, final long end, final TypeReference type){ + public List zRevRangeObject(final String key, final long start, final long end, + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRange(key, start, end), new Converter.TypeListStringConverter<>(this, type)); } @Override - public List zRevRangeObject(final byte[] key, final long start, final long end, final TypeReference type){ + public List zRevRangeObject(final byte[] key, final long start, final long end, + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRange(key, start, end), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public List zRevRangeByLexObject(final String key, final double min, final double max){ + public List zRevRangeByLexObject(final String key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), new Converter.SimpleListStringConverter<>(this)); } @Override - public List zRevRangeByLexObject(final byte[] key, final double min, final double max){ + public List zRevRangeByLexObject(final byte[] key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List zRevRangeByLexObject(final String key, final double min, final double max, final Class clazz){ + public List zRevRangeByLexObject(final String key, final double min, final double max, + final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List zRevRangeByLexObject(final byte[] key, final double min, final double max, final Class clazz){ + public List zRevRangeByLexObject(final byte[] key, final double min, final double max, + final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override public List zRevRangeByLexObject(final String key, final double min, final double max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), new Converter.TypeListStringConverter<>(this, type)); } @Override public List zRevRangeByLexObject(final byte[] key, final double min, final double max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public List zRevRangeByLexObject(final String key, final String min, final String max){ + public List zRevRangeByLexObject(final String key, final String min, final String max) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), new Converter.SimpleListStringConverter<>(this)); } @Override - public List zRevRangeByLexObject(final byte[] key, final byte[] min, final byte[] max){ + public List zRevRangeByLexObject(final byte[] key, final byte[] min, final byte[] max) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List zRevRangeByLexObject(final String key, final String min, final String max, final Class clazz){ + public List zRevRangeByLexObject(final String key, final String min, final String max, + final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List zRevRangeByLexObject(final byte[] key, final byte[] min, final byte[] max, final Class clazz){ + public List zRevRangeByLexObject(final byte[] key, final byte[] min, final byte[] max, + final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override public List zRevRangeByLexObject(final String key, final String min, final String max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), new Converter.TypeListStringConverter<>(this, type)); } @Override public List zRevRangeByLexObject(final byte[] key, final byte[] min, final byte[] max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max), new Converter.TypeListBinaryConverter<>(this, type)); } @Override public List zRevRangeByLexObject(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), new Converter.SimpleListStringConverter<>(this)); } @Override public List zRevRangeByLexObject(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), new Converter.SimpleListBinaryConverter<>(this)); } @Override public List zRevRangeByLexObject(final String key, final double min, final double max, final long offset, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override public List zRevRangeByLexObject(final byte[] key, final double min, final double max, final long offset, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override public List zRevRangeByLexObject(final String key, final double min, final double max, final long offset, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), new Converter.TypeListStringConverter<>(this, type)); } @Override public List zRevRangeByLexObject(final byte[] key, final double min, final double max, final long offset, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), new Converter.TypeListBinaryConverter<>(this, type)); } @Override public List zRevRangeByLexObject(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), new Converter.SimpleListStringConverter<>(this)); } @Override public List zRevRangeByLexObject(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), new Converter.SimpleListBinaryConverter<>(this)); } @Override public List zRevRangeByLexObject(final String key, final String min, final String max, final long offset, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override public List zRevRangeByLexObject(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override public List zRevRangeByLexObject(final String key, final String min, final String max, final long offset, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), new Converter.TypeListStringConverter<>(this, type)); } @Override public List zRevRangeByLexObject(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByLex(key, min, max, offset, count), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public List zRevRangeByScoreObject(final String key, final double min, final double max){ + public List zRevRangeByScoreObject(final String key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), new Converter.SimpleListStringConverter<>(this)); } @Override - public List zRevRangeByScoreObject(final byte[] key, final double min, final double max){ + public List zRevRangeByScoreObject(final byte[] key, final double min, final double max) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), new Converter.SimpleListBinaryConverter<>(this)); } @Override public List zRevRangeByScoreObject(final String key, final double min, final double max, - final Class clazz){ + final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override public List zRevRangeByScoreObject(final byte[] key, final double min, final double max, - final Class clazz){ + final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override public List zRevRangeByScoreObject(final String key, final double min, final double max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), new Converter.TypeListStringConverter<>(this, type)); } @Override public List zRevRangeByScoreObject(final byte[] key, final double min, final double max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public List zRevRangeByScoreObject(final String key, final String min, final String max){ + public List zRevRangeByScoreObject(final String key, final String min, final String max) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), new Converter.SimpleListStringConverter<>(this)); } @Override - public List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byte[] max){ + public List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byte[] max) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), new Converter.SimpleListBinaryConverter<>(this)); } @Override public List zRevRangeByScoreObject(final String key, final String min, final String max, - final Class clazz){ + final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override public List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byte[] max, - final Class clazz){ + final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override public List zRevRangeByScoreObject(final String key, final String min, final String max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), new Converter.TypeListStringConverter<>(this, type)); } @Override public List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byte[] max, - final TypeReference type){ + final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max), new Converter.TypeListBinaryConverter<>(this, type)); } @Override public List zRevRangeByScoreObject(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), new Converter.SimpleListStringConverter<>(this)); } @Override public List zRevRangeByScoreObject(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), new Converter.SimpleListBinaryConverter<>(this)); } @Override public List zRevRangeByScoreObject(final String key, final double min, final double max, final long offset, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override public List zRevRangeByScoreObject(final byte[] key, final double min, final double max, final long offset, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override public List zRevRangeByScoreObject(final String key, final double min, final double max, final long offset, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), new Converter.TypeListStringConverter<>(this, type)); } @Override public List zRevRangeByScoreObject(final byte[] key, final double min, final double max, final long offset, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), new Converter.TypeListBinaryConverter<>(this, type)); } @Override public List zRevRangeByScoreObject(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), new Converter.SimpleListStringConverter<>(this)); } @Override public List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), new Converter.SimpleListBinaryConverter<>(this)); } @Override public List zRevRangeByScoreObject(final String key, final String min, final String max, final long offset, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override public List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count, final Class clazz){ + final long count, final Class clazz) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override public List zRevRangeByScoreObject(final String key, final String min, final String max, final long offset, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), new Converter.TypeListStringConverter<>(this, type)); } @Override public List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count, final TypeReference type){ + final long count, final TypeReference type) { return execute((client)->client.sortedSetOperations().zRevRangeByScore(key, min, max, offset, count), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public Set zUnionObject(final String[] keys){ + public List zUnionObject(final String[] keys) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys)), - new Converter.SimpleSetStringConverter<>(this)); + new Converter.SimpleListStringConverter<>(this)); } @Override - public Set zUnionObject(final byte[][] keys){ + public List zUnionObject(final byte[][] keys) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys)), - new Converter.SimpleSetBinaryConverter<>(this)); + new Converter.SimpleListBinaryConverter<>(this)); } @Override - public Set zUnionObject(final String[] keys, final Class clazz){ + public List zUnionObject(final String[] keys, final Class clazz) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys)), - new Converter.ClazzSetStringConverter<>(this, clazz)); + new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public Set zUnionObject(final byte[][] keys, final Class clazz){ + public List zUnionObject(final byte[][] keys, final Class clazz) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys)), - new Converter.ClazzSetBinaryConverter<>(this, clazz)); + new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public Set zUnionObject(final String[] keys, final TypeReference type){ + public List zUnionObject(final String[] keys, final TypeReference type) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys)), - new Converter.TypeSetStringConverter<>(this, type)); + new Converter.TypeListStringConverter<>(this, type)); } @Override - public Set zUnionObject(final byte[][] keys, final TypeReference type){ + public List zUnionObject(final byte[][] keys, final TypeReference type) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys)), - new Converter.TypeSetBinaryConverter<>(this, type)); + new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public Set zUnionObject(final String[] keys, final Aggregate aggregate){ + public List zUnionObject(final String[] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate), - new Converter.SimpleSetStringConverter<>(this)); + new Converter.SimpleListStringConverter<>(this)); } @Override - public Set zUnionObject(final byte[][] keys, final Aggregate aggregate){ + public List zUnionObject(final byte[][] keys, final Aggregate aggregate) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate), - new Converter.SimpleSetBinaryConverter<>(this)); + new Converter.SimpleListBinaryConverter<>(this)); } @Override - public Set zUnionObject(final String[] keys, final Aggregate aggregate, final Class clazz){ + public List zUnionObject(final String[] keys, final Aggregate aggregate, final Class clazz) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate), - new Converter.ClazzSetStringConverter<>(this, clazz)); + new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public Set zUnionObject(final byte[][] keys, final Aggregate aggregate, final Class clazz){ + public List zUnionObject(final byte[][] keys, final Aggregate aggregate, final Class clazz) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate), - new Converter.ClazzSetBinaryConverter<>(this, clazz)); + new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public Set zUnionObject(final String[] keys, final Aggregate aggregate, final TypeReference type){ + public List zUnionObject(final String[] keys, final Aggregate aggregate, final TypeReference type) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate), - new Converter.TypeSetStringConverter<>(this, type)); + new Converter.TypeListStringConverter<>(this, type)); } @Override - public Set zUnionObject(final byte[][] keys, final Aggregate aggregate, final TypeReference type){ + public List zUnionObject(final byte[][] keys, final Aggregate aggregate, final TypeReference type) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate), - new Converter.TypeSetBinaryConverter<>(this, type)); + new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public Set zUnionObject(final String[] keys, final double[] weights){ + public List zUnionObject(final String[] keys, final double[] weights) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights), - new Converter.SimpleSetStringConverter<>(this)); + new Converter.SimpleListStringConverter<>(this)); } @Override - public Set zUnionObject(final byte[][] keys, final double[] weights){ + public List zUnionObject(final byte[][] keys, final double[] weights) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights), - new Converter.SimpleSetBinaryConverter<>(this)); + new Converter.SimpleListBinaryConverter<>(this)); } @Override - public Set zUnionObject(final String[] keys, final double[] weights, final Class clazz){ + public List zUnionObject(final String[] keys, final double[] weights, final Class clazz) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights), - new Converter.ClazzSetStringConverter<>(this, clazz)); + new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public Set zUnionObject(final byte[][] keys, final double[] weights, final Class clazz){ + public List zUnionObject(final byte[][] keys, final double[] weights, final Class clazz) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights), - new Converter.ClazzSetBinaryConverter<>(this, clazz)); + new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public Set zUnionObject(final String[] keys, final double[] weights, final TypeReference type){ + public List zUnionObject(final String[] keys, final double[] weights, final TypeReference type) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights), - new Converter.TypeSetStringConverter<>(this, type)); + new Converter.TypeListStringConverter<>(this, type)); } @Override - public Set zUnionObject(final byte[][] keys, final double[] weights, final TypeReference type){ + public List zUnionObject(final byte[][] keys, final double[] weights, final TypeReference type) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), weights), - new Converter.TypeSetBinaryConverter<>(this, type)); + new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public Set zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights){ + public List zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights), - new Converter.SimpleSetStringConverter<>(this)); + new Converter.SimpleListStringConverter<>(this)); } @Override - public Set zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights){ + public List zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights), - new Converter.SimpleSetBinaryConverter<>(this)); + new Converter.SimpleListBinaryConverter<>(this)); } @Override - public Set zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights, - final Class clazz){ + public List zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final Class clazz) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights), - new Converter.ClazzSetStringConverter<>(this, clazz)); + new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public Set zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, - final Class clazz){ + public List zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final Class clazz) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights), - new Converter.ClazzSetBinaryConverter<>(this, clazz)); + new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public Set zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights, - final TypeReference type){ + public List zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights), - new Converter.TypeSetStringConverter<>(this, type)); + new Converter.TypeListStringConverter<>(this, type)); } @Override - public Set zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, - final TypeReference type){ + public List zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type) { return execute((client)->client.sortedSetOperations().zUnion(rawKeys(keys), aggregate, weights), - new Converter.TypeSetBinaryConverter<>(this, type)); + new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public V getObject(final String key){ + public V getObject(final String key) { return execute((client)->client.stringOperations().get(rawKey(key)), new Converter.SimpleStringConverter<>(this)); } @Override - public V getObject(final byte[] key){ + public V getObject(final byte[] key) { return execute((client)->client.stringOperations().get(rawKey(key)), new Converter.SimpleBinaryConverter<>(this)); } @Override - public V getObject(final String key, final Class clazz){ + public V getObject(final String key, final Class clazz) { return execute((client)->client.stringOperations().get(rawKey(key)), new Converter.ClazzStringConverter<>(this, clazz)); } @Override - public V getObject(final byte[] key, final Class clazz){ + public V getObject(final byte[] key, final Class clazz) { return execute((client)->client.stringOperations().get(rawKey(key)), new Converter.ClazzBinaryConverter<>(this, clazz)); } @Override - public V getObject(final String key, final TypeReference type){ + public V getObject(final String key, final TypeReference type) { return execute((client)->client.stringOperations().get(rawKey(key)), new Converter.TypeStringConverter<>(this, type)); } @Override - public V getObject(final byte[] key, final TypeReference type){ + public V getObject(final byte[] key, final TypeReference type) { return execute((client)->client.stringOperations().get(rawKey(key)), new Converter.TypeBinaryConverter<>(this, type)); } @Override - public V getExObject(final String key, final GetExArgument getExArgument){ + public V getExObject(final String key, final GetExArgument getExArgument) { return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument), new Converter.SimpleStringConverter<>(this)); } @Override - public V getExObject(final byte[] key, final GetExArgument getExArgument){ + public V getExObject(final byte[] key, final GetExArgument getExArgument) { return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument), new Converter.SimpleBinaryConverter<>(this)); } @Override - public V getExObject(final String key, final GetExArgument getExArgument, final Class clazz){ + public V getExObject(final String key, final GetExArgument getExArgument, final Class clazz) { return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument), new Converter.ClazzStringConverter<>(this, clazz)); } @Override - public V getExObject(final byte[] key, final GetExArgument getExArgument, final Class clazz){ + public V getExObject(final byte[] key, final GetExArgument getExArgument, final Class clazz) { return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument), new Converter.ClazzBinaryConverter<>(this, clazz)); } @Override - public V getExObject(final String key, final GetExArgument getExArgument, final TypeReference type){ + public V getExObject(final String key, final GetExArgument getExArgument, final TypeReference type) { return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument), new Converter.TypeStringConverter<>(this, type)); } @Override - public V getExObject(final byte[] key, final GetExArgument getExArgument, final TypeReference type){ + public V getExObject(final byte[] key, final GetExArgument getExArgument, final TypeReference type) { return execute((client)->client.stringOperations().getEx(rawKey(key), getExArgument), new Converter.TypeBinaryConverter<>(this, type)); } @Override - public V getSet(final String key, final V value){ + public V getSet(final String key, final V value) { return execute((client)->client.stringOperations().getSet(rawKey(key), serializer.serialize(value)), new Converter.SimpleStringConverter<>(this)); } @Override - public V getSet(final byte[] key, final V value){ + public V getSet(final byte[] key, final V value) { return execute((client)->client.stringOperations().getSet(rawKey(key), serializer.serializeAsBytes(value)), new Converter.SimpleBinaryConverter<>(this)); } @Override - public V getSet(final String key, final V value, final Class clazz){ + public V getSet(final String key, final V value, final Class clazz) { return execute((client)->client.stringOperations().getSet(rawKey(key), serializer.serialize(value)), new Converter.ClazzStringConverter<>(this, clazz)); } @Override - public V getSet(final byte[] key, final V value, final Class clazz){ + public V getSet(final byte[] key, final V value, final Class clazz) { return execute((client)->client.stringOperations().getSet(rawKey(key), serializer.serializeAsBytes(value)), new Converter.ClazzBinaryConverter<>(this, clazz)); } @Override - public V getSet(final String key, final V value, final TypeReference type){ + public V getSet(final String key, final V value, final TypeReference type) { return execute((client)->client.stringOperations().getSet(rawKey(key), serializer.serialize(value)), new Converter.TypeStringConverter<>(this, type)); } @Override - public V getSet(final byte[] key, final V value, final TypeReference type){ + public V getSet(final byte[] key, final V value, final TypeReference type) { return execute((client)->client.stringOperations().getSet(rawKey(key), serializer.serializeAsBytes(value)), new Converter.TypeBinaryConverter<>(this, type)); } @Override - public V getDelObject(final String key){ + public V getDelObject(final String key) { return execute((client)->client.stringOperations().getDel(rawKey(key)), new Converter.SimpleStringConverter<>(this)); } @Override - public V getDelObject(final byte[] key){ + public V getDelObject(final byte[] key) { return execute((client)->client.stringOperations().getDel(rawKey(key)), new Converter.SimpleBinaryConverter<>(this)); } @Override - public V getDelObject(final String key, final Class clazz){ + public V getDelObject(final String key, final Class clazz) { return execute((client)->client.stringOperations().getDel(rawKey(key)), new Converter.ClazzStringConverter<>(this, clazz)); } @Override - public V getDelObject(final byte[] key, final Class clazz){ + public V getDelObject(final byte[] key, final Class clazz) { return execute((client)->client.stringOperations().getDel(rawKey(key)), new Converter.ClazzBinaryConverter<>(this, clazz)); } @Override - public V getDelObject(final String key, final TypeReference type){ + public V getDelObject(final String key, final TypeReference type) { return execute((client)->client.stringOperations().getDel(rawKey(key)), new Converter.TypeStringConverter<>(this, type)); } @Override - public V getDelObject(final byte[] key, final TypeReference type){ + public V getDelObject(final byte[] key, final TypeReference type) { return execute((client)->client.stringOperations().getDel(rawKey(key)), new Converter.TypeBinaryConverter<>(this, type)); } @Override - public List mGetObject(final String... keys){ + public List mGetObject(final String... keys) { return execute((client)->client.stringOperations().mGet(rawKeys(keys)), new Converter.SimpleListStringConverter<>(this)); } @Override - public List mGetObject(final byte[]... keys){ + public List mGetObject(final byte[]... keys) { return execute((client)->client.stringOperations().mGet(rawKeys(keys)), new Converter.SimpleListBinaryConverter<>(this)); } @Override - public List mGetObject(final String[] keys, final Class clazz){ + public List mGetObject(final String[] keys, final Class clazz) { return execute((client)->client.stringOperations().mGet(rawKeys(keys)), new Converter.ClazzListStringConverter<>(this, clazz)); } @Override - public List mGetObject(final byte[][] keys, final Class clazz){ + public List mGetObject(final byte[][] keys, final Class clazz) { return execute((client)->client.stringOperations().mGet(rawKeys(keys)), new Converter.ClazzListBinaryConverter<>(this, clazz)); } @Override - public List mGetObject(final String[] keys, final TypeReference type){ + public List mGetObject(final String[] keys, final TypeReference type) { return execute((client)->client.stringOperations().mGet(rawKeys(keys)), new Converter.TypeListStringConverter<>(this, type)); } @Override - public List mGetObject(final byte[][] keys, final TypeReference type){ + public List mGetObject(final byte[][] keys, final TypeReference type) { return execute((client)->client.stringOperations().mGet(rawKeys(keys)), new Converter.TypeListBinaryConverter<>(this, type)); } @Override - public Status pSetEx(final String key, final V value, final int lifetime){ + public Status pSetEx(final String key, final V value, final int lifetime) { return pSetEx(key, serializer.serialize(value), lifetime); } @Override - public Status pSetEx(final byte[] key, final V value, final int lifetime){ + public Status pSetEx(final byte[] key, final V value, final int lifetime) { return pSetEx(key, serializer.serializeAsBytes(value), lifetime); } @Override - public Status set(final String key, final V value){ + public Status set(final String key, final V value) { return set(key, serializer.serialize(value)); } @Override - public Status set(final byte[] key, final V value){ + public Status set(final byte[] key, final V value) { return set(key, serializer.serializeAsBytes(value)); } @Override - public Status set(final String key, final V value, final SetArgument setArgument){ + public Status set(final String key, final V value, final SetArgument setArgument) { return set(key, serializer.serialize(value), setArgument); } @Override - public Status set(final byte[] key, final V value, final SetArgument setArgument){ + public Status set(final byte[] key, final V value, final SetArgument setArgument) { return set(key, serializer.serializeAsBytes(value), setArgument); } @Override - public Status setEx(final String key, final V value, final int lifetime){ + public Status setEx(final String key, final V value, final int lifetime) { return setEx(key, serializer.serialize(value), lifetime); } @Override - public Status setEx(final byte[] key, final V value, final int lifetime){ + public Status setEx(final byte[] key, final V value, final int lifetime) { return setEx(key, serializer.serializeAsBytes(value), lifetime); } @Override - public Status setNx(final String key, final V value){ + public Status setNx(final String key, final V value) { return setNx(key, serializer.serialize(value)); } @Override - public Status setNx(final byte[] key, final V value){ + public Status setNx(final byte[] key, final V value) { return setNx(key, serializer.serializeAsBytes(value)); } @Override - public void discard(){ + public void discard() { super.discard(); resetTransactionOrPipeline(); } @Override - public List exec(){ + public List exec() { List result = super.exec(); if(result != null){ diff --git a/buession-redis/src/main/java/com/buession/redis/client/AbstractRedisClient.java b/buession-redis/src/main/java/com/buession/redis/client/AbstractRedisClient.java index 38f1833d3..95288ab94 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/AbstractRedisClient.java +++ b/buession-redis/src/main/java/com/buession/redis/client/AbstractRedisClient.java @@ -19,16 +19,31 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client; -import com.buession.core.Executor; import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.client.operations.BitMapOperations; +import com.buession.redis.client.operations.ClusterOperations; +import com.buession.redis.client.operations.ConnectionOperations; +import com.buession.redis.client.operations.GenericOperations; +import com.buession.redis.client.operations.GeoOperations; +import com.buession.redis.client.operations.HashOperations; +import com.buession.redis.client.operations.HyperLogLogOperations; +import com.buession.redis.client.operations.KeyOperations; +import com.buession.redis.client.operations.ListOperations; +import com.buession.redis.client.operations.PubSubOperations; +import com.buession.redis.client.operations.ScriptingOperations; +import com.buession.redis.client.operations.ServerOperations; +import com.buession.redis.client.operations.SetOperations; +import com.buession.redis.client.operations.SortedSetOperations; +import com.buession.redis.client.operations.StreamOperations; +import com.buession.redis.client.operations.StringOperations; +import com.buession.redis.client.operations.TransactionOperations; import com.buession.redis.core.Command; import com.buession.redis.core.command.CommandArguments; -import com.buession.redis.core.command.ProtocolCommand; import com.buession.redis.exception.RedisException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,16 +51,111 @@ /** * Redis 客户端抽象类 * + * @param + * Redis 连接对象类型 {@link RedisConnection} + * * @author Yong.Teng */ -public abstract class AbstractRedisClient implements RedisClient { +public abstract class AbstractRedisClient implements RedisClient { + + /** + * Redis 连接对象 + */ + protected CONN connection; + + /** + * BitMap 命令操作 + */ + protected BitMapOperations bitMapOperations; + + /** + * 集群命令操作 + */ + protected ClusterOperations clusterOperations; + + /** + * 连接命令操作 + */ + protected ConnectionOperations connectionOperations; + + /** + * 一般命令 + * + * @since 3.0.0 + */ + protected GenericOperations genericOperations; + + /** + * 地理位置操作命令 + */ + protected GeoOperations geoOperations; + + /** + * 哈希表命令操作 + */ + protected HashOperations hashOperations; + + /** + * HyperLogLog 命令操作 + */ + protected HyperLogLogOperations hyperLogLogOperations; + + /** + * KEY 命令操作 + */ + protected KeyOperations keyOperations; + + /** + * 列表命令操作 + */ + protected ListOperations listOperations; + + /** + * 发布订阅命令操作 + */ + protected PubSubOperations pubSubOperations; + + /** + * Script 命令操作 + */ + protected ScriptingOperations scriptingOperations; + + /** + * 服务端操作命令 + */ + protected ServerOperations serverOperations; + + /** + * 集合命令操作 + */ + protected SetOperations setOperations; + + /** + * 有序集合命令操作 + */ + protected SortedSetOperations sortedSetOperations; + + /** + * Stream 命令操作 + */ + protected StreamOperations streamOperations; + + /** + * 字符串命令操作 + */ + protected StringOperations stringOperations; + + /** + * 事务命令操作 + */ + protected TransactionOperations transactionOperations; protected final Logger logger = LoggerFactory.getLogger(getClass()); /** * 构造函数 */ - public AbstractRedisClient(){ + public AbstractRedisClient() { super(); } @@ -55,17 +165,23 @@ public AbstractRedisClient(){ * @param connection * Redis 连接对象 {@link RedisConnection} */ - public AbstractRedisClient(final RedisConnection connection){ + public AbstractRedisClient(final CONN connection) { setConnection(connection); } @Override - public R execute(final Command command, final CommandArguments arguments){ - return doExecute((conn)->command.execute(), command.getCommand(), arguments); + public CONN getConnection() { + return connection; + } + + @SuppressWarnings({"unchecked"}) + @Override + public void setConnection(RedisConnection connection) { + this.connection = (CONN) connection; } - private R doExecute(final Executor executor, final ProtocolCommand command, - final CommandArguments arguments){ + @Override + public R execute(final Command command, final CommandArguments arguments) { long startTime = 0; if(logger.isDebugEnabled()){ startTime = System.nanoTime(); @@ -73,21 +189,21 @@ private R doExecute(final Executor executor, final Proto if(logger.isDebugEnabled()){ if(arguments != null){ - logger.debug("Execute command '{}' with arguments: {}", command, arguments); + logger.debug("Execute command: {} {}", command.getCommand(), arguments); }else{ - logger.debug("Execute command '{}'", command); + logger.debug("Execute command: {}", command.getCommand()); } } try{ - return getConnection().execute(executor); + return doExecute(command); }catch(RedisException e){ if(logger.isErrorEnabled()){ if(arguments != null){ - logger.error("Execute command '{}' with arguments: {}, failure: {}", command, - arguments, e.getMessage(), e); + logger.error("Execute command: {} {}, failure: {}", command.getCommand(), arguments, + e.getMessage(), e); }else{ - logger.error("Execute command '{}', failure: {}", command, e.getMessage(), e); + logger.error("Execute command: {}, failure: {}", command.getCommand(), e.getMessage(), e); } } throw e; @@ -99,4 +215,8 @@ private R doExecute(final Executor executor, final Proto } } + private R doExecute(final Command command) { + return getConnection().execute((conn)->command.execute()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/client/RedisClient.java b/buession-redis/src/main/java/com/buession/redis/client/RedisClient.java index 699357152..a8f43d490 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/RedisClient.java +++ b/buession-redis/src/main/java/com/buession/redis/client/RedisClient.java @@ -28,6 +28,7 @@ import com.buession.redis.client.operations.BitMapOperations; import com.buession.redis.client.operations.ClusterOperations; import com.buession.redis.client.operations.ConnectionOperations; +import com.buession.redis.client.operations.GenericOperations; import com.buession.redis.client.operations.GeoOperations; import com.buession.redis.client.operations.HashOperations; import com.buession.redis.client.operations.HyperLogLogOperations; @@ -88,6 +89,15 @@ public interface RedisClient { */ ConnectionOperations connectionOperations(); + /** + * 返回一般命令操作实例 + * + * @return 一般命令操作实例 + * + * @since 3.0.0 + */ + GenericOperations genericOperations(); + /** * 返回地理位置命令操作实例 * @@ -192,7 +202,7 @@ public interface RedisClient { * @throws RedisException * Redis Exception */ - default R execute(final Command command) throws RedisException{ + default R execute(final Command command) throws RedisException { return execute(command, null); } diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/AbstractConnectionFactory.java b/buession-redis/src/main/java/com/buession/redis/client/connection/AbstractConnectionFactory.java new file mode 100644 index 000000000..0160abfb6 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/AbstractConnectionFactory.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection; + +import com.buession.redis.client.connection.datasource.ClusterDataSource; +import com.buession.redis.client.connection.datasource.DataSource; +import com.buession.redis.client.connection.datasource.SentinelDataSource; + +/** + * Redis 连接工厂抽象类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractConnectionFactory implements RedisConnectionFactory { + + private final DS dataSource; + + private RedisConnection redisConnection; + + public AbstractConnectionFactory(final DS dataSource) { + this.dataSource = dataSource; + } + + public boolean isRedisSentinelAware() { + return dataSource instanceof SentinelDataSource; + } + + public boolean isRedisClusterAware() { + return dataSource instanceof ClusterDataSource; + } + + @Override + public RedisConnection getConnection() { + if(redisConnection == null){ + synchronized(this){ + if(isRedisClusterAware()){ + redisConnection = getClusterConnection(); + }else if(isRedisSentinelAware()){ + redisConnection = getSentinelConnection(); + }else{ + redisConnection = getStandaloneConnection(); + } + } + } + + return redisConnection; + } + + protected DS getDataSource() { + return dataSource; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/AbstractRedisConnection.java b/buession-redis/src/main/java/com/buession/redis/client/connection/AbstractRedisConnection.java index f20815e5a..864ef62ae 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/AbstractRedisConnection.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/AbstractRedisConnection.java @@ -19,19 +19,17 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.connection; -import com.buession.core.Executor; import com.buession.lang.Status; import com.buession.net.ssl.SslConfiguration; import com.buession.redis.core.Constants; import com.buession.redis.client.connection.datasource.DataSource; +import com.buession.redis.core.PoolConfig; import com.buession.redis.exception.RedisConnectionFailureException; -import com.buession.redis.exception.RedisException; -import com.buession.redis.exception.JedisRedisExceptionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,6 +47,13 @@ public abstract class AbstractRedisConnection implements RedisConnection { */ private DataSource dataSource; + /** + * 连接池配置 + * + * @since 3.0.0 + */ + private PoolConfig poolConfig; + /** * 连接超时(单位:毫秒) */ @@ -73,12 +78,12 @@ public abstract class AbstractRedisConnection implements RedisConnection { private volatile boolean initialized = false; - private final Logger logger = LoggerFactory.getLogger(getClass()); + protected final Logger logger = LoggerFactory.getLogger(getClass()); /** * 构造函数 */ - public AbstractRedisConnection(){ + public AbstractRedisConnection() { } /** @@ -87,7 +92,7 @@ public AbstractRedisConnection(){ * @param dataSource * Redis 数据源 */ - public AbstractRedisConnection(DataSource dataSource){ + public AbstractRedisConnection(DataSource dataSource) { this.dataSource = dataSource; } @@ -97,11 +102,11 @@ public AbstractRedisConnection(DataSource dataSource){ * @param dataSource * Redis 数据源 * @param connectTimeout - * 连接超时 + * 连接超时(单位:毫秒) * @param soTimeout - * 读取超时 + * 读取超时(单位:毫秒) */ - public AbstractRedisConnection(DataSource dataSource, int connectTimeout, int soTimeout){ + public AbstractRedisConnection(DataSource dataSource, int connectTimeout, int soTimeout) { this.dataSource = dataSource; this.connectTimeout = connectTimeout; this.soTimeout = soTimeout; @@ -122,7 +127,7 @@ public AbstractRedisConnection(DataSource dataSource, int connectTimeout, int so * @since 2.0.0 */ public AbstractRedisConnection(DataSource dataSource, int connectTimeout, int soTimeout, - int infiniteSoTimeout){ + int infiniteSoTimeout) { this(dataSource, connectTimeout, soTimeout); this.infiniteSoTimeout = infiniteSoTimeout; } @@ -135,7 +140,7 @@ public AbstractRedisConnection(DataSource dataSource, int connectTimeout, int so * @param sslConfiguration * SSL 配置 */ - public AbstractRedisConnection(DataSource dataSource, SslConfiguration sslConfiguration){ + public AbstractRedisConnection(DataSource dataSource, SslConfiguration sslConfiguration) { this.dataSource = dataSource; this.sslConfiguration = sslConfiguration; } @@ -153,7 +158,7 @@ public AbstractRedisConnection(DataSource dataSource, SslConfiguration sslConfig * SSL 配置 */ public AbstractRedisConnection(DataSource dataSource, int connectTimeout, int soTimeout, - SslConfiguration sslConfiguration){ + SslConfiguration sslConfiguration) { this(dataSource, connectTimeout, soTimeout); this.sslConfiguration = sslConfiguration; } @@ -175,68 +180,209 @@ public AbstractRedisConnection(DataSource dataSource, int connectTimeout, int so * @since 2.0.0 */ public AbstractRedisConnection(DataSource dataSource, int connectTimeout, int soTimeout, - int infiniteSoTimeout, SslConfiguration sslConfiguration){ + int infiniteSoTimeout, SslConfiguration sslConfiguration) { this(dataSource, connectTimeout, soTimeout, sslConfiguration); this.infiniteSoTimeout = infiniteSoTimeout; } + /** + * 构造函数 + * + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public AbstractRedisConnection(PoolConfig poolConfig) { + this.poolConfig = poolConfig; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public AbstractRedisConnection(DataSource dataSource, PoolConfig poolConfig) { + this(dataSource); + this.poolConfig = poolConfig; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public AbstractRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout) { + this(dataSource, connectTimeout, soTimeout); + this.poolConfig = poolConfig; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public AbstractRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + this(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.poolConfig = poolConfig; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public AbstractRedisConnection(DataSource dataSource, PoolConfig poolConfig, SslConfiguration sslConfiguration) { + this(dataSource, sslConfiguration); + this.poolConfig = poolConfig; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout(单位:毫秒) + * 连接超时 + * @param soTimeout(单位:毫秒) + * 读取超时 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public AbstractRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + this(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.poolConfig = poolConfig; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout(单位:毫秒) + * Infinite 读取超时 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public AbstractRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + this(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.poolConfig = poolConfig; + } + @Override - public DataSource getDataSource(){ + public DataSource getDataSource() { return dataSource; } @Override - public void setDataSource(DataSource dataSource){ + public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } @Override - public int getConnectTimeout(){ + public PoolConfig getPoolConfig() { + return poolConfig; + } + + @Override + public void setPoolConfig(PoolConfig poolConfig) { + this.poolConfig = poolConfig; + } + + @Override + public int getConnectTimeout() { return connectTimeout; } @Override - public void setConnectTimeout(int connectTimeout){ + public void setConnectTimeout(int connectTimeout) { this.connectTimeout = connectTimeout; } @Override - public int getSoTimeout(){ + public int getSoTimeout() { return soTimeout; } @Override - public void setSoTimeout(int soTimeout){ + public void setSoTimeout(int soTimeout) { this.soTimeout = soTimeout; } @Override - public int getInfiniteSoTimeout(){ + public int getInfiniteSoTimeout() { return infiniteSoTimeout; } @Override - public void setInfiniteSoTimeout(int infiniteSoTimeout){ + public void setInfiniteSoTimeout(int infiniteSoTimeout) { this.infiniteSoTimeout = infiniteSoTimeout; } @Override - public boolean isUseSsl(){ + public boolean isUseSsl() { return sslConfiguration != null; } @Override - public SslConfiguration getSslConfiguration(){ + public SslConfiguration getSslConfiguration() { return sslConfiguration; } @Override - public void setSslConfiguration(SslConfiguration sslConfiguration){ + public void setSslConfiguration(SslConfiguration sslConfiguration) { this.sslConfiguration = sslConfiguration; } @Override - public Status connect() throws RedisConnectionFailureException{ + public Status connect() throws RedisConnectionFailureException { logger.info("Connection redis server."); try{ @@ -251,28 +397,18 @@ public Status connect() throws RedisConnectionFailureException{ } @Override - public R execute(final Executor executor) throws RedisException{ - try{ - return executor.execute(this); - }catch(Exception e){ - logger.error("Redis execute command failure: {}", e.getMessage(), e); - throw JedisRedisExceptionUtils.convert(e); - } - } - - @Override - public void destroy() throws IOException{ + public void destroy() throws IOException { logger.info("Destroy redis server."); doDestroy(); } @Override - public void close() throws IOException{ + public void close() throws IOException { logger.info("Closing redis server."); doClose(); } - protected void initialized(){ + protected void initialized() { if(initialized == false){ synchronized(this){ if(initialized == false){ diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/JedisConnectionFactory.java b/buession-redis/src/main/java/com/buession/redis/client/connection/JedisConnectionFactory.java new file mode 100644 index 000000000..b0fc47fee --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/JedisConnectionFactory.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection; + +import com.buession.redis.client.connection.datasource.jedis.JedisClusterDataSource; +import com.buession.redis.client.connection.datasource.jedis.JedisDataSource; +import com.buession.redis.client.connection.datasource.jedis.JedisRedisDataSource; +import com.buession.redis.client.connection.datasource.jedis.JedisSentinelDataSource; +import com.buession.redis.client.connection.jedis.JedisClusterConnection; +import com.buession.redis.client.connection.jedis.JedisConnection; +import com.buession.redis.client.connection.jedis.JedisSentinelConnection; +import com.buession.redis.exception.RedisConnectionFailureException; + +/** + * Jedis Redis 连接工厂 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisConnectionFactory extends AbstractConnectionFactory { + + public JedisConnectionFactory(final JedisRedisDataSource dataSource) { + super(dataSource); + } + + @Override + public RedisStandaloneConnection getStandaloneConnection() { + final JedisDataSource dataSource = (JedisDataSource) getDataSource(); + + if(dataSource.getPoolConfig() == null){ + return new JedisConnection(dataSource, dataSource.getConnectTimeout(), dataSource.getSoTimeout(), + dataSource.getInfiniteSoTimeout(), dataSource.getSslConfiguration()); + }else{ + return new JedisConnection(dataSource, dataSource.getPoolConfig(), dataSource.getConnectTimeout(), + dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), dataSource.getSslConfiguration()); + } + } + + @Override + public RedisSentinelConnection getSentinelConnection() { + if(isRedisSentinelAware()){ + final JedisSentinelDataSource dataSource = (JedisSentinelDataSource) getDataSource(); + + if(dataSource.getPoolConfig() == null){ + return new JedisSentinelConnection(dataSource, dataSource.getConnectTimeout(), + dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), + dataSource.getSentinelConnectTimeout(), dataSource.getSentinelSoTimeout(), + dataSource.getSslConfiguration()); + }else{ + return new JedisSentinelConnection(dataSource, dataSource.getPoolConfig(), + dataSource.getConnectTimeout(), dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), + dataSource.getSentinelConnectTimeout(), dataSource.getSentinelSoTimeout(), + dataSource.getSslConfiguration()); + } + } + + throw new RedisConnectionFailureException("No Sentinels datasource"); + } + + @Override + public RedisClusterConnection getClusterConnection() { + if(isRedisClusterAware()){ + final JedisClusterDataSource dataSource = (JedisClusterDataSource) getDataSource(); + + if(dataSource.getPoolConfig() == null){ + return new JedisClusterConnection(dataSource, dataSource.getConnectTimeout(), + dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), dataSource.getMaxRedirects(), + dataSource.getMaxTotalRetriesDuration(), dataSource.getSslConfiguration()); + }else{ + return new JedisClusterConnection(dataSource, dataSource.getPoolConfig(), + dataSource.getConnectTimeout(), dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), + dataSource.getMaxRedirects(), dataSource.getMaxTotalRetriesDuration(), + dataSource.getSslConfiguration()); + } + } + + throw new RedisConnectionFailureException("No Cluster datasource"); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/LettuceConnectionFactory.java b/buession-redis/src/main/java/com/buession/redis/client/connection/LettuceConnectionFactory.java new file mode 100644 index 000000000..55e08a653 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/LettuceConnectionFactory.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection; + +import com.buession.redis.client.connection.datasource.jedis.JedisSentinelDataSource; +import com.buession.redis.client.connection.datasource.lettuce.LettuceClusterDataSource; +import com.buession.redis.client.connection.datasource.lettuce.LettuceDataSource; +import com.buession.redis.client.connection.datasource.lettuce.LettuceRedisDataSource; +import com.buession.redis.client.connection.jedis.JedisSentinelConnection; +import com.buession.redis.client.connection.lettuce.LettuceClusterConnection; +import com.buession.redis.client.connection.lettuce.LettuceConnection; +import com.buession.redis.exception.RedisConnectionFailureException; + +/** + * Lettuce Redis 连接工厂 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceConnectionFactory extends AbstractConnectionFactory { + + public LettuceConnectionFactory(final LettuceRedisDataSource dataSource) { + super(dataSource); + } + + @Override + public RedisStandaloneConnection getStandaloneConnection() { + final LettuceDataSource dataSource = (LettuceDataSource) getDataSource(); + + if(dataSource.getPoolConfig() == null){ + return new LettuceConnection(dataSource, dataSource.getConnectTimeout(), dataSource.getSoTimeout(), + dataSource.getInfiniteSoTimeout(), dataSource.getSslConfiguration()); + }else{ + return new LettuceConnection(dataSource, dataSource.getPoolConfig(), dataSource.getConnectTimeout(), + dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), dataSource.getSslConfiguration()); + } + } + + @Override + public RedisSentinelConnection getSentinelConnection() { + if(isRedisSentinelAware()){ + final JedisSentinelDataSource dataSource = (JedisSentinelDataSource) getDataSource(); + + if(dataSource.getPoolConfig() == null){ + return new JedisSentinelConnection(dataSource, dataSource.getConnectTimeout(), + dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), + dataSource.getSentinelConnectTimeout(), dataSource.getSentinelSoTimeout(), + dataSource.getSslConfiguration()); + }else{ + return new JedisSentinelConnection(dataSource, dataSource.getPoolConfig(), + dataSource.getConnectTimeout(), dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), + dataSource.getSentinelConnectTimeout(), dataSource.getSentinelSoTimeout(), + dataSource.getSslConfiguration()); + } + } + + throw new RedisConnectionFailureException("No Sentinels datasource"); + } + + @Override + public RedisClusterConnection getClusterConnection() { + if(isRedisClusterAware()){ + final LettuceClusterDataSource dataSource = (LettuceClusterDataSource) getDataSource(); + + if(dataSource.getPoolConfig() == null){ + return new LettuceClusterConnection(dataSource, dataSource.getConnectTimeout(), + dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), dataSource.getMaxRedirects(), + dataSource.getMaxTotalRetriesDuration(), dataSource.getSslConfiguration()); + }else{ + return new LettuceClusterConnection(dataSource, dataSource.getPoolConfig(), + dataSource.getConnectTimeout(), dataSource.getSoTimeout(), dataSource.getInfiniteSoTimeout(), + dataSource.getMaxRedirects(), dataSource.getMaxTotalRetriesDuration(), + dataSource.getSslConfiguration()); + } + } + + throw new RedisConnectionFailureException("No Cluster datasource"); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/RedisConnection.java b/buession-redis/src/main/java/com/buession/redis/client/connection/RedisConnection.java index 15eb56213..dc57cd3de 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/RedisConnection.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/RedisConnection.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.connection; @@ -29,13 +29,13 @@ import com.buession.lang.Status; import com.buession.net.ssl.SslConfiguration; import com.buession.redis.client.connection.datasource.DataSource; +import com.buession.redis.core.PoolConfig; import com.buession.redis.exception.RedisConnectionFailureException; import com.buession.redis.exception.RedisException; import com.buession.redis.pipeline.Pipeline; import com.buession.redis.transaction.Transaction; import java.io.Closeable; -import java.io.IOException; import java.util.List; /** @@ -60,6 +60,25 @@ public interface RedisConnection extends Destroyable, Closeable { */ void setDataSource(DataSource dataSource); + /** + * 返回连接池配置 + * + * @return 连接池配置 + * + * @since 3.0.0 + */ + PoolConfig getPoolConfig(); + + /** + * 连接池配置 + * + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + void setPoolConfig(PoolConfig poolConfig); + /** * 获取连接超时 * diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/RedisConnectionFactory.java b/buession-redis/src/main/java/com/buession/redis/client/connection/RedisConnectionFactory.java index b74eccfba..be8a7b6af 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/RedisConnectionFactory.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/RedisConnectionFactory.java @@ -19,42 +19,45 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.connection; -import com.buession.redis.client.connection.datasource.DataSource; - /** * Redis 连接工厂 * * @author Yong.Teng + * @since 3.0.0 */ -public class RedisConnectionFactory { +public interface RedisConnectionFactory { /** - * Redis 数据源 + * 返回 Redis 连接对象 + * + * @return Redis 连接对象 */ - private final DataSource dataSource; + RedisConnection getConnection(); /** - * 返回 Redis 数据源 + * 返回 Redis 单机连接对象 * - * @param dataSource - * Redis 数据源 + * @return Redis 单机连接对象 */ - public RedisConnectionFactory(final DataSource dataSource){ - this.dataSource = dataSource; - } + RedisStandaloneConnection getStandaloneConnection(); /** - * 返回 Redis 连接对象 + * 返回 Redis 哨兵连接对象 * - * @return Redis 连接对象 + * @return Redis 哨兵连接对象 + */ + RedisSentinelConnection getSentinelConnection(); + + /** + * 返回 Redis 集群连接对象 + * + * @return Redis 集群连接对象 */ - public RedisConnection getConnection(){ - return dataSource.getConnection(); - } + RedisClusterConnection getClusterConnection(); } diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/RedisConnectionUtils.java b/buession-redis/src/main/java/com/buession/redis/client/connection/RedisConnectionUtils.java index b63a763d4..d25948e56 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/RedisConnectionUtils.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/RedisConnectionUtils.java @@ -42,7 +42,7 @@ public final class RedisConnectionUtils { private final static Logger logger = LoggerFactory.getLogger(RedisConnectionUtils.class); - private RedisConnectionUtils(){ + private RedisConnectionUtils() { } /** @@ -53,7 +53,7 @@ private RedisConnectionUtils(){ * * @return Redis 模式 */ - public static RedisMode getRedisMode(final RedisConnection connection){ + public static RedisMode getRedisMode(final RedisConnection connection) { if(connection instanceof RedisSentinelConnection){ return RedisMode.SENTINEL; }else if(connection instanceof RedisClusterConnection){ @@ -63,33 +63,33 @@ public static RedisMode getRedisMode(final RedisConnection connection){ } } - public static RedisConnection bindConnection(final RedisConnectionFactory factory){ + public static RedisConnection bindConnection(final RedisConnectionFactory factory) { return bindConnection(factory, false); } public static RedisConnection bindConnection(final RedisConnectionFactory factory, - final boolean enableTransactionSupport){ + final boolean enableTransactionSupport) { return doGetConnection(factory, true, true, enableTransactionSupport); } - public static RedisConnection getConnection(final RedisConnectionFactory factory){ + public static RedisConnection getConnection(final RedisConnectionFactory factory) { return getConnection(factory, false); } public static RedisConnection getConnection(final RedisConnectionFactory factory, - final boolean enableTransactionSupport){ + final boolean enableTransactionSupport) { return doGetConnection(factory, true, false, enableTransactionSupport); } public static boolean isConnectionTransactional(final RedisConnectionFactory factory, - final RedisConnection connection){ + final RedisConnection connection) { Assert.isNull(factory, "No RedisConnectionFactory specified"); RedisConnectionHolder connHolder = TransactionUtils.getResource(factory); return (connHolder != null && connection == connHolder.getConnection()); } public static void releaseConnection(final RedisConnectionFactory factory, - final @Nullable RedisConnection connection, final boolean transactionSupport){ + final @Nullable RedisConnection connection, final boolean transactionSupport) { if(connection == null){ logger.error("Redis connection is null."); return; @@ -115,7 +115,7 @@ public static void releaseConnection(final RedisConnectionFactory factory, } } - public static void unbindConnection(final RedisConnectionFactory factory){ + public static void unbindConnection(final RedisConnectionFactory factory) { RedisConnectionHolder connectionHolder = TransactionUtils.unbindResourceIfPossible(factory); if(connectionHolder == null){ return; @@ -130,7 +130,7 @@ public static void unbindConnection(final RedisConnectionFactory factory){ } private static RedisConnection doGetConnection(final RedisConnectionFactory factory, final boolean allowCreate, - final boolean bind, final boolean enableTransactionSupport){ + final boolean bind, final boolean enableTransactionSupport) { Assert.isNull(factory, "No RedisConnectionFactory specified"); RedisConnectionHolder connectionHolder = TransactionUtils.getResource(factory); @@ -156,15 +156,17 @@ private static RedisConnection doGetConnection(final RedisConnectionFactory fact startTime = System.nanoTime(); } - try{ - connection.connect(); - }catch(RedisConnectionFailureException e){ - logger.error("Redis connection failure: {}", e.getMessage()); - throw e; - }finally{ - if(logger.isDebugEnabled()){ - long finishTime = System.nanoTime(); - logger.debug("Connection redis execution time: {}", finishTime - startTime); + if(connection.isConnect() == false){ + try{ + connection.connect(); + }catch(RedisConnectionFailureException e){ + logger.error("Redis connection failure: {}", e.getMessage()); + throw e; + }finally{ + if(logger.isDebugEnabled()){ + long finishTime = System.nanoTime(); + logger.debug("Connection redis execution time: {}", finishTime - startTime); + } } } @@ -190,7 +192,7 @@ private static RedisConnection doGetConnection(final RedisConnectionFactory fact } private static void potentiallyRegisterTransactionSynchronisation(final RedisConnectionFactory factory, - final RedisConnectionHolder connectionHolder){ + final RedisConnectionHolder connectionHolder) { if(TransactionUtils.isActualNonReadonlyTransactionActive() && connectionHolder.isTransactionSyncronisationActive() == false){ connectionHolder.setTransactionSyncronisationActive(true); @@ -204,7 +206,7 @@ private static void potentiallyRegisterTransactionSynchronisation(final RedisCon } private static RedisConnection createConnectionProxy(final RedisConnectionFactory factory, - final RedisConnection connection){ + final RedisConnection connection) { ProxyFactory proxyFactory = new ProxyFactory(connection); proxyFactory.addAdvice(new ConnectionSplittingInterceptor(factory)); @@ -212,7 +214,7 @@ private static RedisConnection createConnectionProxy(final RedisConnectionFactor return (RedisConnection) proxyFactory.getProxy(); } - private static void connectionClose(final RedisConnection connection){ + private static void connectionClose(final RedisConnection connection) { if(connection == null){ return; } diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/RedisSentinelConnection.java b/buession-redis/src/main/java/com/buession/redis/client/connection/RedisSentinelConnection.java index d54bfb288..ac06a874d 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/RedisSentinelConnection.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/RedisSentinelConnection.java @@ -38,6 +38,36 @@ */ public interface RedisSentinelConnection extends RedisConnection { + /** + * 返回哨兵节点连接超时 + * + * @return 哨兵节点连接超时(单位:毫秒) + */ + int getSentinelConnectTimeout(); + + /** + * 设置哨兵节点连接超时 + * + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + */ + void setSentinelConnectTimeout(int sentinelConnectTimeout); + + /** + * 返回哨兵节点读取超时 + * + * @return 哨兵节点读取超时(单位:毫秒) + */ + int getSentinelSoTimeout(); + + /** + * 设置哨兵节点读取超时 + * + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + */ + void setSentinelSoTimeout(int sentinelSoTimeout); + /** * 返回 Master 节点列表 * diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/AbstractDataSource.java b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/AbstractDataSource.java index 7ed9e7620..62cb61480 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/AbstractDataSource.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/AbstractDataSource.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.connection.datasource; @@ -87,7 +87,7 @@ public abstract class AbstractDataSource implements DataSource { * @return 用户名 */ @Override - public String getUsername(){ + public String getUsername() { return username; } @@ -98,7 +98,7 @@ public String getUsername(){ * 用户名 */ @Override - public void setUsername(String username){ + public void setUsername(String username) { this.username = username; } @@ -108,7 +108,7 @@ public void setUsername(String username){ * @return 密码 */ @Override - public String getPassword(){ + public String getPassword() { return password; } @@ -119,7 +119,7 @@ public String getPassword(){ * 密码 */ @Override - public void setPassword(String password){ + public void setPassword(String password) { this.password = password; } @@ -129,7 +129,7 @@ public void setPassword(String password){ * @return 客户端名称 */ @Override - public String getClientName(){ + public String getClientName() { return clientName; } @@ -140,66 +140,58 @@ public String getClientName(){ * 客户端名称 */ @Override - public void setClientName(String clientName){ + public void setClientName(String clientName) { this.clientName = clientName; } @Override - public int getConnectTimeout(){ + public int getConnectTimeout() { return connectTimeout; } @Override - public void setConnectTimeout(int connectTimeout){ + public void setConnectTimeout(int connectTimeout) { this.connectTimeout = connectTimeout; } @Override - public int getSoTimeout(){ + public int getSoTimeout() { return soTimeout; } @Override - public void setSoTimeout(int soTimeout){ + public void setSoTimeout(int soTimeout) { this.soTimeout = soTimeout; } @Override - public int getInfiniteSoTimeout(){ + public int getInfiniteSoTimeout() { return infiniteSoTimeout; } @Override - public void setInfiniteSoTimeout(int infiniteSoTimeout){ + public void setInfiniteSoTimeout(int infiniteSoTimeout) { this.infiniteSoTimeout = infiniteSoTimeout; } @Override - public PoolConfig getPoolConfig(){ + public PoolConfig getPoolConfig() { return poolConfig; } @Override - public void setPoolConfig(PoolConfig poolConfig){ + public void setPoolConfig(PoolConfig poolConfig) { this.poolConfig = poolConfig; } @Override - public SslConfiguration getSslConfiguration(){ + public SslConfiguration getSslConfiguration() { return sslConfiguration; } @Override - public void setSslConfiguration(SslConfiguration sslConfiguration){ + public void setSslConfiguration(SslConfiguration sslConfiguration) { this.sslConfiguration = sslConfiguration; } - protected boolean isUseSsl(){ - return sslConfiguration != null; - } - - protected boolean isUsePool(){ - return getPoolConfig() != null; - } - } diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/DataSource.java b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/DataSource.java index 2a77894e1..279322258 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/DataSource.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/DataSource.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.connection.datasource; @@ -170,6 +170,7 @@ public interface DataSource { * * @since 2.0.0 */ + @Deprecated RedisConnection getConnection(); } diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisClusterDataSource.java b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisClusterDataSource.java index d6f707a81..8097a6c53 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisClusterDataSource.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisClusterDataSource.java @@ -19,24 +19,16 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.connection.datasource.jedis; -import com.buession.redis.client.connection.RedisConnection; import com.buession.redis.client.connection.datasource.ClusterDataSource; import com.buession.redis.client.connection.jedis.JedisClusterConnection; import com.buession.redis.core.RedisNode; -import com.buession.redis.core.internal.jedis.JedisClientConfigBuilder; -import redis.clients.jedis.ConnectionPoolConfig; -import redis.clients.jedis.HostAndPort; -import redis.clients.jedis.JedisCluster; -import java.time.Duration; import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; /** * Jedis 集群模式数据源 @@ -61,11 +53,6 @@ public class JedisClusterDataSource extends AbstractJedisDataSource implements C */ private int maxTotalRetriesDuration = -1; - /** - * JedisCluster 对象 - */ - private JedisCluster cluster; - @Override public List getNodes() { return nodes; @@ -96,48 +83,16 @@ public void setMaxTotalRetriesDuration(int maxTotalRetriesDuration) { this.maxTotalRetriesDuration = maxTotalRetriesDuration; } + @Deprecated @Override - public RedisConnection getConnection() { - if(cluster == null){ - cluster = createJedisCluster(); - } - - return new JedisClusterConnection(this, cluster, getConnectTimeout(), getSoTimeout(), getInfiniteSoTimeout(), - getMaxRedirects(), getMaxTotalRetriesDuration(), getSslConfiguration()); - } - - protected JedisCluster createJedisCluster() { - int maxRedirects = getMaxRedirects() < 0 ? DEFAULT_MAX_REDIRECTS : getMaxRedirects(); - final JedisClientConfigBuilder builder = JedisClientConfigBuilder.create(this, getSslConfiguration()); - - if(isUsePool()){ - final ConnectionPoolConfig connectionPoolConfig = new ConnectionPoolConfig(); - - getPoolConfig().toGenericObjectPoolConfig(connectionPoolConfig); - - if(getMaxTotalRetriesDuration() > 0){ - cluster = new JedisCluster(createHostAndPorts(), builder.build(), maxRedirects, - Duration.ofMillis(getMaxTotalRetriesDuration()), connectionPoolConfig); - }else{ - cluster = new JedisCluster(createHostAndPorts(), builder.build(), maxRedirects, connectionPoolConfig); - } + public JedisClusterConnection getConnection() { + if(getPoolConfig() == null){ + return new JedisClusterConnection(this, getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getMaxRedirects(), getMaxTotalRetriesDuration(), getSslConfiguration()); }else{ - if(getMaxTotalRetriesDuration() > 0){ - cluster = new JedisCluster(createHostAndPorts(), builder.build(), maxRedirects, - Duration.ofMillis(getMaxTotalRetriesDuration())); - }else{ - cluster = new JedisCluster(createHostAndPorts(), builder.build(), maxRedirects); - } + return new JedisClusterConnection(this, getPoolConfig(), getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getMaxRedirects(), getMaxTotalRetriesDuration(), getSslConfiguration()); } - - return cluster; - } - - private Set createHostAndPorts() { - return getNodes().stream().map((node)->{ - int port = node.getPort() == 0 ? RedisNode.DEFAULT_PORT : node.getPort(); - return new HostAndPort(node.getHost(), port); - }).collect(Collectors.toSet()); } } \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisDataSource.java b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisDataSource.java index 955c934ad..c2184f2ce 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisDataSource.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisDataSource.java @@ -19,21 +19,14 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.connection.datasource.jedis; -import com.buession.lang.Constants; -import com.buession.net.ssl.SslConfiguration; -import com.buession.redis.client.connection.RedisConnection; import com.buession.redis.client.connection.datasource.StandaloneDataSource; import com.buession.redis.client.connection.jedis.JedisConnection; import com.buession.redis.core.RedisNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import redis.clients.jedis.JedisPool; -import redis.clients.jedis.JedisPoolConfig; /** * Jedis 单机模式数据源 @@ -57,10 +50,6 @@ public class JedisDataSource extends AbstractJedisDataSource implements Standalo */ private int database = RedisNode.DEFAULT_DATABASE; - private JedisPool pool; - - private final static Logger logger = LoggerFactory.getLogger(JedisDataSource.class); - @Override public String getHost() { return host; @@ -91,35 +80,15 @@ public void setDatabase(int database) { this.database = database; } + @Deprecated @Override - public RedisConnection getConnection() { - if(isUsePool()){ - if(pool == null){ - pool = createPool(); - } - } - - return new JedisConnection(this, pool, getConnectTimeout(), getSoTimeout(), getInfiniteSoTimeout(), - getSslConfiguration()); - } - - protected JedisPool createPool() { - final SslConfiguration sslConfiguration = getSslConfiguration(); - final JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); - - getPoolConfig().toGenericObjectPoolConfig(jedisPoolConfig); - - final String password = Constants.EMPTY_STRING.equals(getPassword()) ? null : getPassword(); - if(sslConfiguration == null){ - logger.debug("Create jedis pool."); - return new JedisPool(jedisPoolConfig, getHost(), getPort(), getConnectTimeout(), getSoTimeout(), - getUsername(), password, getDatabase(), getClientName(), isUseSsl()); + public JedisConnection getConnection() { + if(getPoolConfig() == null){ + return new JedisConnection(this, getConnectTimeout(), getSoTimeout(), getInfiniteSoTimeout(), + getSslConfiguration()); }else{ - logger.debug("Create jedis pool with ssl."); - return new JedisPool(jedisPoolConfig, getHost(), getPort(), getConnectTimeout(), getSoTimeout(), - getUsername(), password, getDatabase(), getClientName(), isUseSsl(), - sslConfiguration.getSslSocketFactory(), sslConfiguration.getSslParameters(), - sslConfiguration.getHostnameVerifier()); + return new JedisConnection(this, getPoolConfig(), getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getSslConfiguration()); } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisSentinelDataSource.java b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisSentinelDataSource.java index 9e4bf6f16..5f97c4672 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisSentinelDataSource.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/jedis/JedisSentinelDataSource.java @@ -19,28 +19,18 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.connection.datasource.jedis; -import com.buession.core.validator.Validate; -import com.buession.redis.client.connection.RedisConnection; import com.buession.redis.client.connection.datasource.SentinelDataSource; import com.buession.redis.client.connection.jedis.JedisSentinelConnection; import com.buession.redis.core.Constants; import com.buession.redis.core.RedisNode; -import com.buession.redis.core.internal.jedis.JedisClientConfigBuilder; -import redis.clients.jedis.HostAndPort; -import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.JedisSentinelPool; -import java.util.Collection; -import java.util.Collections; import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; /** * Jedis 哨兵模式数据源 @@ -142,42 +132,16 @@ public void setSentinels(List sentinels) { this.sentinels = sentinels; } + @Deprecated @Override - public RedisConnection getConnection() { - if(isUsePool()){ - if(pool == null){ - pool = createPool(); - } + public JedisSentinelConnection getConnection() { + if(getPoolConfig() == null){ + return new JedisSentinelConnection(this, getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getSentinelConnectTimeout(), getSentinelSoTimeout(), getSslConfiguration()); + }else{ + return new JedisSentinelConnection(this, getPoolConfig(), getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getSentinelConnectTimeout(), getSentinelSoTimeout(), getSslConfiguration()); } - - return new JedisSentinelConnection(this, pool, getConnectTimeout(), getSoTimeout(), - getInfiniteSoTimeout(), getSentinelConnectTimeout(), getSentinelSoTimeout(), getSslConfiguration()); - } - - protected JedisSentinelPool createPool() { - final Set sentinels = convertToJedisSentinelSet(getSentinels()); - final JedisClientConfigBuilder builder = JedisClientConfigBuilder.create(this, getSslConfiguration()); - final JedisClientConfigBuilder sentinelBuilder = JedisClientConfigBuilder.create(this, - getSslConfiguration()); - final JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); - - builder.database(getDatabase()); - - getPoolConfig().toGenericObjectPoolConfig(jedisPoolConfig); - - return new JedisSentinelPool(getMasterName(), sentinels, jedisPoolConfig, builder.build(), - sentinelBuilder.build()); - } - - private Set convertToJedisSentinelSet(Collection sentinelNodes) { - if(Validate.isEmpty(sentinelNodes)){ - return Collections.emptySet(); - } - - return sentinelNodes.stream().filter(Objects::nonNull).map(node->{ - int port = node.getPort() == 0 ? RedisNode.DEFAULT_SENTINEL_PORT : node.getPort(); - return new HostAndPort(node.getHost(), port); - }).collect(Collectors.toSet()); } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/AbstractLettuceDataSource.java b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/AbstractLettuceDataSource.java new file mode 100644 index 000000000..7b67f5abe --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/AbstractLettuceDataSource.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource.lettuce; + +import com.buession.redis.client.connection.datasource.AbstractDataSource; + +/** + * Lettuce 数据源抽象类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractLettuceDataSource extends AbstractDataSource implements LettuceRedisDataSource { + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/LettuceClusterDataSource.java b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/LettuceClusterDataSource.java new file mode 100644 index 000000000..530843818 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/LettuceClusterDataSource.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource.lettuce; + +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.client.connection.datasource.ClusterDataSource; +import com.buession.redis.client.connection.lettuce.LettuceClusterConnection; +import com.buession.redis.client.connection.lettuce.LettuceSentinelConnection; +import com.buession.redis.core.RedisNode; + +import java.util.List; + +/** + * Lettuce 集群模式数据源 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceClusterDataSource extends AbstractLettuceDataSource implements ClusterDataSource { + + /** + * 集群主机节点 + */ + private List nodes; + + /** + * 最大重定向次数 + */ + private int maxRedirects = DEFAULT_MAX_REDIRECTS; + + /** + * 最大重数时长(单位:秒) + */ + private int maxTotalRetriesDuration = -1; + + @Override + public List getNodes() { + return nodes; + } + + @Override + public void setNodes(List nodes) { + this.nodes = nodes; + } + + @Override + public int getMaxRedirects() { + return maxRedirects; + } + + @Override + public void setMaxRedirects(int maxRedirects) { + this.maxRedirects = maxRedirects; + } + + @Override + public int getMaxTotalRetriesDuration() { + return maxTotalRetriesDuration; + } + + @Override + public void setMaxTotalRetriesDuration(int maxTotalRetriesDuration) { + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + @Deprecated + @Override + public RedisConnection getConnection() { + if(getPoolConfig() == null){ + return new LettuceClusterConnection(this, getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getMaxRedirects(), getMaxTotalRetriesDuration(), getSslConfiguration()); + }else{ + return new LettuceClusterConnection(this, getPoolConfig(), getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getMaxRedirects(), getMaxTotalRetriesDuration(), getSslConfiguration()); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/LettuceDataSource.java b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/LettuceDataSource.java new file mode 100644 index 000000000..6d37786e8 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/LettuceDataSource.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource.lettuce; + +import com.buession.redis.client.connection.datasource.StandaloneDataSource; +import com.buession.redis.client.connection.lettuce.LettuceConnection; +import com.buession.redis.core.RedisNode; + +/** + * Lettuce 单机模式数据源 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceDataSource extends AbstractLettuceDataSource implements StandaloneDataSource { + + /** + * Redis 主机地址 + */ + private String host = RedisNode.DEFAULT_HOST; + + /** + * Redis 端口 + */ + private int port = RedisNode.DEFAULT_PORT; + + /** + * 数据库 + */ + private int database = RedisNode.DEFAULT_DATABASE; + + @Override + public String getHost() { + return host; + } + + @Override + public void setHost(String host) { + this.host = host; + } + + @Override + public int getPort() { + return port; + } + + @Override + public void setPort(int port) { + this.port = port; + } + + @Override + public int getDatabase() { + return database; + } + + @Override + public void setDatabase(int database) { + this.database = database; + } + + @Deprecated + @Override + public LettuceConnection getConnection() { + if(getPoolConfig() == null){ + return new LettuceConnection(this, getConnectTimeout(), getSoTimeout(), getInfiniteSoTimeout(), + getSslConfiguration()); + }else{ + return new LettuceConnection(this, getPoolConfig(), getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getSslConfiguration()); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/LettuceRedisDataSource.java b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/LettuceRedisDataSource.java new file mode 100644 index 000000000..a07272b04 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/LettuceRedisDataSource.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource.lettuce; + +import com.buession.redis.client.connection.datasource.DataSource; + +/** + * Lettuce 数据源 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface LettuceRedisDataSource extends DataSource { + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/LettuceSentinelDataSource.java b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/LettuceSentinelDataSource.java new file mode 100644 index 000000000..47d6879b6 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/LettuceSentinelDataSource.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.datasource.lettuce; + +import com.buession.redis.client.connection.datasource.SentinelDataSource; +import com.buession.redis.client.connection.lettuce.LettuceSentinelConnection; +import com.buession.redis.core.Constants; +import com.buession.redis.core.RedisNode; + +import java.util.List; + +/** + * Lettuce 哨兵模式数据源 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceSentinelDataSource extends AbstractLettuceDataSource implements SentinelDataSource { + + /** + * 数据库 + */ + private int database = RedisNode.DEFAULT_DATABASE; + + /** + * 哨兵节点连接超时(单位:毫秒) + */ + private int sentinelConnectTimeout = Constants.DEFAULT_CONNECT_TIMEOUT; + + /** + * 哨兵节点读取超时(单位:毫秒) + */ + private int sentinelSoTimeout = Constants.DEFAULT_SO_TIMEOUT; + + /** + * Sentinel Client Name + */ + private String sentinelClientName; + + /** + * Master 名称 + */ + private String masterName; + + /** + * 哨兵节点 + */ + private List sentinels; + + @Override + public int getDatabase() { + return database; + } + + @Override + public void setDatabase(int database) { + this.database = database; + } + + @Override + public int getSentinelConnectTimeout() { + return sentinelConnectTimeout; + } + + @Override + public void setSentinelConnectTimeout(int sentinelConnectTimeout) { + this.sentinelConnectTimeout = sentinelConnectTimeout; + } + + @Override + public int getSentinelSoTimeout() { + return sentinelSoTimeout; + } + + @Override + public void setSentinelSoTimeout(int sentinelSoTimeout) { + this.sentinelSoTimeout = sentinelSoTimeout; + } + + @Override + public String getSentinelClientName() { + return sentinelClientName; + } + + @Override + public void setSentinelClientName(String sentinelClientName) { + this.sentinelClientName = sentinelClientName; + } + + @Override + public String getMasterName() { + return masterName; + } + + @Override + public void setMasterName(String masterName) { + this.masterName = masterName; + } + + @Override + public List getSentinels() { + return sentinels; + } + + @Override + public void setSentinels(List sentinels) { + this.sentinels = sentinels; + } + + @Deprecated + @Override + public LettuceSentinelConnection getConnection() { + if(getPoolConfig() == null){ + return new LettuceSentinelConnection(this, getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getSentinelConnectTimeout(), getSentinelSoTimeout(), getSslConfiguration()); + }else{ + return new LettuceSentinelConnection(this, getPoolConfig(), getConnectTimeout(), getSoTimeout(), + getInfiniteSoTimeout(), getSentinelConnectTimeout(), getSentinelSoTimeout(), getSslConfiguration()); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/package-info.java b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/package-info.java new file mode 100644 index 000000000..6c094cc10 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/lettuce/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.client.connection.datasource.lettuce; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/package-info.java b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/package-info.java index 716f05235..9edb1b0af 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/package-info.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/datasource/package-info.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ /** diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/AbstractJedisRedisConnection.java b/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/AbstractJedisRedisConnection.java index 15378d321..2ef81eb23 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/AbstractJedisRedisConnection.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/AbstractJedisRedisConnection.java @@ -24,13 +24,17 @@ */ package com.buession.redis.client.connection.jedis; -import com.buession.core.validator.Validate; +import com.buession.core.Executor; import com.buession.redis.client.connection.AbstractRedisConnection; import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.client.connection.datasource.DataSource; import com.buession.redis.client.connection.datasource.jedis.JedisRedisDataSource; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.exception.JedisRedisExceptionUtils; +import com.buession.redis.exception.RedisException; import com.buession.redis.pipeline.Pipeline; import com.buession.redis.transaction.Transaction; -import redis.clients.jedis.DefaultJedisClientConfig; import java.io.IOException; @@ -151,6 +155,133 @@ public AbstractJedisRedisConnection(JedisRedisDataSource dataSource, int connect super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); } + /** + * 构造函数 + * + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public AbstractJedisRedisConnection(PoolConfig poolConfig) { + super(poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public AbstractJedisRedisConnection(DataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public AbstractJedisRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public AbstractJedisRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public AbstractJedisRedisConnection(DataSource dataSource, PoolConfig poolConfig, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout(单位:毫秒) + * 连接超时 + * @param soTimeout(单位:毫秒) + * 读取超时 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public AbstractJedisRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout(单位:毫秒) + * Infinite 读取超时 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public AbstractJedisRedisConnection(DataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + @Override public boolean isPipeline() { return pipeline != null; @@ -161,27 +292,14 @@ public boolean isTransaction() { return transaction != null; } - protected DefaultJedisClientConfig.Builder createJedisClientConfigBuilder(final JedisRedisDataSource dataSource, - final int connectTimeout, - final int soTimeout, - final int infiniteSoTimeout) { - final DefaultJedisClientConfig.Builder builder = DefaultJedisClientConfig.builder() - .connectionTimeoutMillis(connectTimeout) - .socketTimeoutMillis(soTimeout) - .blockingSocketTimeoutMillis(infiniteSoTimeout) - .ssl(isUseSsl()); - - if(Validate.hasText(dataSource.getClientName())){ - builder.clientName(dataSource.getClientName()); - } - - if(getSslConfiguration() != null){ - builder.sslSocketFactory(getSslConfiguration().getSslSocketFactory()) - .sslParameters(getSslConfiguration().getSslParameters()) - .hostnameVerifier(getSslConfiguration().getHostnameVerifier()); + @Override + public R execute(final Executor executor) throws RedisException { + try{ + return executor.execute(this); + }catch(Exception e){ + logger.error("Redis execute command failure: {}", e.getMessage(), e); + throw JedisRedisExceptionUtils.convert(e); } - - return builder; } @Override diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisClusterConnection.java b/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisClusterConnection.java index b333f0cf9..d8e1dd2f5 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisClusterConnection.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisClusterConnection.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.connection.jedis; @@ -27,12 +27,30 @@ import com.buession.net.ssl.SslConfiguration; import com.buession.redis.client.connection.RedisClusterConnection; import com.buession.redis.client.connection.datasource.jedis.JedisClusterDataSource; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.core.RedisNode; +import com.buession.redis.core.internal.jedis.JedisClientConfigBuilder; import com.buession.redis.exception.RedisConnectionFailureException; +import com.buession.redis.exception.RedisException; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.pipeline.jedis.JedisClusterPipeline; +import com.buession.redis.pipeline.jedis.JedisPipelineProxy; +import com.buession.redis.transaction.Transaction; +import com.buession.redis.transaction.jedis.JedisTransaction; +import com.buession.redis.transaction.jedis.JedisTransactionProxy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import redis.clients.jedis.ConnectionPoolConfig; +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.JedisClientConfig; import redis.clients.jedis.JedisCluster; +import redis.clients.jedis.providers.ClusterConnectionProvider; import java.io.IOException; +import java.time.Duration; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; /** * Jedis 集群模式连接器 @@ -52,6 +70,13 @@ public class JedisClusterConnection extends AbstractJedisRedisConnection impleme */ private int maxTotalRetriesDuration; + /** + * 连接提供者 + * + * @since 3.0.0 + */ + private ClusterConnectionProvider connectionProvider; + /** * JedisCluster 对象 */ @@ -197,6 +222,54 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTime super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); } + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param sslConfiguration + * SSL 配置 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int maxRedirects, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + /** * 构造函数 * @@ -205,6 +278,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, int connectTime * @param cluster * {@link JedisCluster} */ + @Deprecated public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster) { super(dataSource); this.cluster = cluster; @@ -222,6 +296,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * @param soTimeout * 读取超时(单位:毫秒) */ + @Deprecated public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, int soTimeout) { super(dataSource, connectTimeout, soTimeout); @@ -242,6 +317,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * @param infiniteSoTimeout * Infinite 读取超时(单位:毫秒) */ + @Deprecated public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, int soTimeout, int infiniteSoTimeout) { super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); @@ -258,6 +334,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * @param sslConfiguration * SSL 配置 */ + @Deprecated public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, SslConfiguration sslConfiguration) { super(dataSource, sslConfiguration); @@ -278,6 +355,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * @param sslConfiguration * SSL 配置 */ + @Deprecated public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, int soTimeout, SslConfiguration sslConfiguration) { super(dataSource, connectTimeout, soTimeout, sslConfiguration); @@ -300,6 +378,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * @param sslConfiguration * SSL 配置 */ + @Deprecated public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); @@ -345,6 +424,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, int maxRedirect * @param maxRedirects * 最大重试次数 */ + @Deprecated public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int maxRedirects) { this(dataSource, cluster); this.maxRedirects = maxRedirects; @@ -362,6 +442,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * @param sslConfiguration * SSL 配置 */ + @Deprecated public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int maxRedirects, SslConfiguration sslConfiguration) { this(dataSource, cluster, sslConfiguration); @@ -384,6 +465,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * @param maxTotalRetriesDuration * 最大重试时长(单位:毫秒) */ + @Deprecated public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, int soTimeout, int maxRedirects, int maxTotalRetriesDuration) { this(dataSource, cluster, connectTimeout, soTimeout); @@ -409,6 +491,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * @param sslConfiguration * SSL 配置 */ + @Deprecated public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, int soTimeout, int maxRedirects, int maxTotalRetriesDuration, SslConfiguration sslConfiguration) { @@ -435,6 +518,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * @param maxTotalRetriesDuration * 最大重试时长(单位:毫秒) */ + @Deprecated public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, int soTimeout, int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration) { this(dataSource, cluster, connectTimeout, soTimeout, infiniteSoTimeout); @@ -462,6 +546,7 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl * @param sslConfiguration * SSL 配置 */ + @Deprecated public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cluster, int connectTimeout, int soTimeout, int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration, SslConfiguration sslConfiguration) { @@ -470,6 +555,280 @@ public JedisClusterConnection(JedisClusterDataSource dataSource, JedisCluster cl this.maxTotalRetriesDuration = maxTotalRetriesDuration; } + /** + * 构造函数 + * + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(PoolConfig poolConfig) { + super(poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param maxRedirects + * 最大重试次数 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int maxRedirects) { + super(dataSource, poolConfig); + this.maxRedirects = maxRedirects; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param maxRedirects + * 最大重试次数 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int maxRedirects, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + this.maxRedirects = maxRedirects; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数(单位:毫秒) + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int maxRedirects, int maxTotalRetriesDuration) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int maxRedirects, int maxTotalRetriesDuration, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisClusterConnection(JedisClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + @Override public int getMaxRedirects() { return maxRedirects; @@ -495,14 +854,47 @@ public JedisCluster getCluster() { } @Override - protected void internalInit() { - if(cluster == null){ - throw new IllegalStateException("JedisCluster cloud not be initialized."); + public Pipeline openPipeline() { + if(pipeline == null){ + final redis.clients.jedis.ClusterPipeline pipelineObject = cluster.pipelined(); + pipeline = new JedisPipelineProxy<>(new JedisClusterPipeline(pipelineObject), pipelineObject); } + + return pipeline; } @Override - protected void doConnect() throws RedisConnectionFailureException { + public Transaction multi() { + if(transaction == null){ + final redis.clients.jedis.Transaction tran = cluster.multi(); + transaction = new JedisTransactionProxy(new JedisTransaction(tran), tran); + } + + return transaction; + } + + @Override + public List exec() throws RedisException { + if(transaction != null){ + final List result = transaction.exec(); + + transaction.close(); + transaction = null; + + return result; + }else{ + throw new RedisException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + @Override + public void discard() throws RedisException { + if(transaction != null){ + transaction.discard(); + transaction = null; + }else{ + throw new RedisException("ERR DISCARD without MULTI. Did you forget to call multi?"); + } } @Override @@ -515,6 +907,43 @@ public boolean isClosed() { return cluster == null; } + @Override + protected void internalInit() { + if(cluster == null){ + connectionProvider = createConnectionProvider(); + } + } + + protected boolean isUsePool() { + return getPoolConfig() != null; + } + + @Override + protected void doConnect() throws RedisConnectionFailureException { + cluster = new JedisCluster(connectionProvider, getMaxRedirects(), + Duration.ofMillis(getMaxTotalRetriesDuration())); + } + + protected ClusterConnectionProvider createConnectionProvider() { + final JedisClusterDataSource dataSource = (JedisClusterDataSource) getDataSource(); + final JedisClientConfig clientConfig = JedisClientConfigBuilder.create(dataSource, getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .build(); + final Set nodes = createHostAndPorts(dataSource); + + if(isUsePool()){ + final ConnectionPoolConfig connectionPoolConfig = new ConnectionPoolConfig(); + + getPoolConfig().toGenericObjectPoolConfig(connectionPoolConfig); + + return new ClusterConnectionProvider(nodes, clientConfig, connectionPoolConfig); + }else{ + return new ClusterConnectionProvider(nodes, clientConfig); + } + } + @Override protected void doDestroy() throws IOException { super.doDestroy(); @@ -531,4 +960,11 @@ protected void doClose() throws IOException { } } + private static Set createHostAndPorts(final JedisClusterDataSource clusterDataSource) { + return clusterDataSource.getNodes().stream().map((node)->{ + int port = node.getPort() == 0 ? RedisNode.DEFAULT_PORT : node.getPort(); + return new HostAndPort(node.getHost(), port); + }).collect(Collectors.toSet()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisConnection.java b/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisConnection.java index 927c88cda..3618b16f0 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisConnection.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisConnection.java @@ -27,18 +27,24 @@ import com.buession.redis.client.connection.RedisStandaloneConnection; import com.buession.net.ssl.SslConfiguration; import com.buession.redis.client.connection.datasource.jedis.JedisDataSource; +import com.buession.redis.core.PoolConfig; import com.buession.redis.core.internal.jedis.JedisClientConfigBuilder; import com.buession.redis.exception.RedisConnectionFailureException; import com.buession.redis.exception.RedisException; import com.buession.redis.exception.JedisRedisExceptionUtils; import com.buession.redis.pipeline.Pipeline; import com.buession.redis.pipeline.jedis.JedisPipeline; +import com.buession.redis.pipeline.jedis.JedisPipelineProxy; import com.buession.redis.transaction.Transaction; import com.buession.redis.transaction.jedis.JedisTransaction; +import com.buession.redis.transaction.jedis.JedisTransactionProxy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import redis.clients.jedis.DefaultJedisClientConfig; +import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; import java.io.IOException; import java.util.List; @@ -169,6 +175,7 @@ public JedisConnection(JedisDataSource dataSource, int connectTimeout, int soTim * @param pool * 连接池 */ + @Deprecated public JedisConnection(JedisDataSource dataSource, JedisPool pool) { super(dataSource); this.pool = pool; @@ -186,6 +193,7 @@ public JedisConnection(JedisDataSource dataSource, JedisPool pool) { * @param soTimeout * 读取超时(单位:毫秒) */ + @Deprecated public JedisConnection(JedisDataSource dataSource, JedisPool pool, int connectTimeout, int soTimeout) { super(dataSource, connectTimeout, soTimeout); this.pool = pool; @@ -205,6 +213,7 @@ public JedisConnection(JedisDataSource dataSource, JedisPool pool, int connectTi * @param infiniteSoTimeout * Infinite 读取超时(单位:毫秒) */ + @Deprecated public JedisConnection(JedisDataSource dataSource, JedisPool pool, int connectTimeout, int soTimeout, int infiniteSoTimeout) { super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); @@ -221,6 +230,7 @@ public JedisConnection(JedisDataSource dataSource, JedisPool pool, int connectTi * @param sslConfiguration * SSL 配置 */ + @Deprecated public JedisConnection(JedisDataSource dataSource, JedisPool pool, SslConfiguration sslConfiguration) { super(dataSource, sslConfiguration); this.pool = pool; @@ -240,6 +250,7 @@ public JedisConnection(JedisDataSource dataSource, JedisPool pool, SslConfigurat * @param sslConfiguration * SSL 配置 */ + @Deprecated public JedisConnection(JedisDataSource dataSource, JedisPool pool, int connectTimeout, int soTimeout, SslConfiguration sslConfiguration) { super(dataSource, connectTimeout, soTimeout, sslConfiguration); @@ -262,12 +273,138 @@ public JedisConnection(JedisDataSource dataSource, JedisPool pool, int connectTi * @param sslConfiguration * SSL 配置 */ + @Deprecated public JedisConnection(JedisDataSource dataSource, JedisPool pool, int connectTimeout, int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); this.pool = pool; } + /** + * 构造函数 + * + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public JedisConnection(PoolConfig poolConfig) { + super(poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public JedisConnection(JedisDataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisConnection(JedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisConnection(JedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisConnection(JedisDataSource dataSource, PoolConfig poolConfig, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisConnection(JedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisConnection(JedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + public Jedis getJedis() { return jedis; } @@ -275,7 +412,8 @@ public Jedis getJedis() { @Override public Pipeline openPipeline() { if(pipeline == null){ - pipeline = new JedisPipeline(jedis.pipelined()); + final redis.clients.jedis.Pipeline pipelineObject = jedis.pipelined(); + pipeline = new JedisPipelineProxy<>(new JedisPipeline(pipelineObject), pipelineObject); } return pipeline; @@ -289,8 +427,10 @@ public void closePipeline() { @Override public Transaction multi() { + System.out.println("transaction: " + (transaction == null ? "false" : "true")); if(transaction == null){ - transaction = new JedisTransaction(jedis.multi()); + final redis.clients.jedis.Transaction tran = jedis.multi(); + transaction = new JedisTransactionProxy(new JedisTransaction(tran), tran); } return transaction; @@ -298,7 +438,14 @@ public Transaction multi() { @Override public List exec() throws RedisException { - if(transaction != null){ + if(pipeline != null){ + final List result = pipeline.syncAndReturnAll(); + + pipeline.close(); + pipeline = null; + + return result; + }else if(transaction != null){ final List result = transaction.exec(); transaction.close(); @@ -332,6 +479,9 @@ public boolean isClosed() { @Override protected void internalInit() { + if(pool == null && getPoolConfig() != null){ + pool = createPool(); + } } protected boolean isUsePool() { @@ -356,12 +506,39 @@ protected void doConnect() throws RedisConnectionFailureException { } }else{ final JedisDataSource dataSource = (JedisDataSource) getDataSource(); - final JedisClientConfigBuilder builder = JedisClientConfigBuilder.create(dataSource, getSslConfiguration()); - - builder.database(dataSource.getDatabase()); + final DefaultJedisClientConfig clientConfig = JedisClientConfigBuilder.create(dataSource, + getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .database(dataSource.getDatabase()) + .build(); + + jedis = new Jedis(dataSource.getHost(), dataSource.getPort(), clientConfig); + } + } - jedis = new Jedis(dataSource.getHost(), dataSource.getPort(), builder.build()); + protected JedisPool createPool() { + final JedisDataSource dataSource = (JedisDataSource) getDataSource(); + final JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); + final HostAndPort hostAndPort = new HostAndPort(dataSource.getHost(), dataSource.getPort()); + final DefaultJedisClientConfig clientConfig = JedisClientConfigBuilder.create(dataSource, + getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .database(dataSource.getDatabase()) + .build(); + + getPoolConfig().toGenericObjectPoolConfig(jedisPoolConfig); + + if(getSslConfiguration() == null){ + logger.debug("Create JedisPool."); + }else{ + logger.debug("Create JedisPool with ssl."); } + + return new JedisPool(jedisPoolConfig, hostAndPort, clientConfig); } @Override @@ -395,17 +572,11 @@ protected void doClose() throws IOException { jedis.close(); } }else{ - logger.info("Jedis quit and disconnect."); + logger.info("Jedis disconnect."); if(jedis != null){ Exception ex = null; - try{ - jedis.quit(); - }catch(Exception e){ - ex = e; - } - try{ jedis.disconnect(); }catch(Exception e){ diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisRedisConnection.java b/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisRedisConnection.java index 3ea8b1bca..9eeeeeb10 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisRedisConnection.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisRedisConnection.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.connection.jedis; diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisSentinelConnection.java b/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisSentinelConnection.java index f99563bcf..cc4622061 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisSentinelConnection.java +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/jedis/JedisSentinelConnection.java @@ -31,6 +31,7 @@ import com.buession.redis.client.connection.datasource.DataSource; import com.buession.redis.client.connection.datasource.jedis.JedisSentinelDataSource; import com.buession.redis.core.Constants; +import com.buession.redis.core.PoolConfig; import com.buession.redis.core.RedisNamedNode; import com.buession.redis.core.RedisNode; import com.buession.redis.core.RedisSentinelNode; @@ -42,27 +43,29 @@ import com.buession.redis.exception.JedisRedisExceptionUtils; import com.buession.redis.pipeline.Pipeline; import com.buession.redis.pipeline.jedis.JedisPipeline; +import com.buession.redis.pipeline.jedis.JedisPipelineProxy; import com.buession.redis.transaction.Transaction; import com.buession.redis.transaction.jedis.JedisTransaction; +import com.buession.redis.transaction.jedis.JedisTransactionProxy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import redis.clients.jedis.DefaultJedisClientConfig; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisClientConfig; +import redis.clients.jedis.JedisPoolConfig; import redis.clients.jedis.JedisSentinelPool; import redis.clients.jedis.exceptions.JedisException; import java.io.IOException; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Properties; import java.util.Set; +import java.util.stream.Collectors; /** * Jedis 哨兵模式连接器 @@ -123,6 +126,8 @@ public JedisSentinelConnection(JedisSentinelDataSource dataSource) { */ public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTimeout, int soTimeout) { super(dataSource, connectTimeout, soTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; } /** @@ -142,6 +147,8 @@ public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTi public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTimeout, int soTimeout, int infiniteSoTimeout) { super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; } /** @@ -171,6 +178,8 @@ public JedisSentinelConnection(JedisSentinelDataSource dataSource, SslConfigurat public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTimeout, int soTimeout, SslConfiguration sslConfiguration) { super(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; } /** @@ -192,6 +201,8 @@ public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTi public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTimeout, int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; } /** @@ -202,6 +213,7 @@ public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTi * @param pool * 连接池 */ + @Deprecated public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool) { super(dataSource); this.pool = pool; @@ -219,9 +231,12 @@ public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinel * @param soTimeout * 读取超时(单位:毫秒) */ + @Deprecated public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, int soTimeout) { super(dataSource, connectTimeout, soTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; this.pool = pool; } @@ -239,9 +254,12 @@ public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinel * @param infiniteSoTimeout * Infinite 读取超时(单位:毫秒) */ + @Deprecated public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, int soTimeout, int infiniteSoTimeout) { super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; this.pool = pool; } @@ -255,6 +273,7 @@ public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinel * @param sslConfiguration * SSL 配置 */ + @Deprecated public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, SslConfiguration sslConfiguration) { super(dataSource, sslConfiguration); @@ -275,9 +294,12 @@ public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinel * @param sslConfiguration * SSL 配置 */ + @Deprecated public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, int soTimeout, SslConfiguration sslConfiguration) { super(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; this.pool = pool; } @@ -297,9 +319,12 @@ public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinel * @param sslConfiguration * SSL 配置 */ + @Deprecated public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; this.pool = pool; } @@ -413,6 +438,7 @@ public JedisSentinelConnection(JedisSentinelDataSource dataSource, int connectTi * @param sentinelSoTimeout * 哨兵节点读取超时(单位:毫秒) */ + @Deprecated public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, int soTimeout, int sentinelConnectTimeout, int sentinelSoTimeout) { this(dataSource, pool, connectTimeout, soTimeout); @@ -438,6 +464,7 @@ public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinel * @param sentinelSoTimeout * 哨兵节点读取超时(单位:毫秒) */ + @Deprecated public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, int soTimeout, int infiniteSoTimeout, int sentinelConnectTimeout, int sentinelSoTimeout) { @@ -464,6 +491,7 @@ public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinel * @param sslConfiguration * SSL 配置 */ + @Deprecated public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, int soTimeout, int sentinelConnectTimeout, int sentinelSoTimeout, SslConfiguration sslConfiguration) { @@ -492,6 +520,7 @@ public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinel * @param sslConfiguration * SSL 配置 */ + @Deprecated public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinelPool pool, int connectTimeout, int soTimeout, int infiniteSoTimeout, int sentinelConnectTimeout, int sentinelSoTimeout, SslConfiguration sslConfiguration) { @@ -501,39 +530,267 @@ public JedisSentinelConnection(JedisSentinelDataSource dataSource, JedisSentinel } /** - * 返回哨兵节点连接超时 + * 构造函数 + * + * @param poolConfig + * 连接池配置 * - * @return 哨兵节点连接超时(单位:毫秒) + * @since 3.0.0 */ - public int getSentinelConnectTimeout() { - return sentinelConnectTimeout; + public JedisSentinelConnection(PoolConfig poolConfig) { + super(poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; } /** - * 设置哨兵节点连接超时 + * 构造函数 * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) * @param sentinelConnectTimeout * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * + * @since 3.0.0 */ - public void setSentinelConnectTimeout(int sentinelConnectTimeout) { + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int sentinelConnectTimeout, int sentinelSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; } /** - * 返回哨兵节点读取超时 + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) * - * @return 哨兵节点读取超时(单位:毫秒) + * @since 3.0.0 */ - public int getSentinelSoTimeout() { - return sentinelSoTimeout; + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int sentinelConnectTimeout, + int sentinelSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 + */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int sentinelConnectTimeout, int sentinelSoTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; } /** - * 设置哨兵节点读取超时 + * 构造函数 * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) * @param sentinelSoTimeout * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + * + * @since 3.0.0 */ + public JedisSentinelConnection(JedisSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int sentinelConnectTimeout, + int sentinelSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + @Override + public int getSentinelConnectTimeout() { + return sentinelConnectTimeout; + } + + @Override + public void setSentinelConnectTimeout(int sentinelConnectTimeout) { + this.sentinelConnectTimeout = sentinelConnectTimeout; + } + + @Override + public int getSentinelSoTimeout() { + return sentinelSoTimeout; + } + + @Override public void setSentinelSoTimeout(int sentinelSoTimeout) { this.sentinelSoTimeout = sentinelSoTimeout; } @@ -547,27 +804,7 @@ public List masters() { final List> masterNodes = Objects.requireNonNull(createSentinelJedis( (JedisSentinelDataSource) dataSource)).sentinelMasters(); - if(masterNodes == null){ - return null; - } - - final List result = new ArrayList<>(masterNodes.size()); - RedisServer redisServer; - Properties properties; - - for(Map masterNode : masterNodes){ - properties = new Properties(); - properties.putAll(masterNode); - - redisServer = new RedisServer(masterNode.get("ip"), Integer.parseInt(masterNode.get("port")), - properties); - redisServer.setName(masterNode.get("name")); - redisServer.setRole(Role.MASTER); - - result.add(redisServer); - } - - return result; + return parseRedisServer(masterNodes, Role.MASTER); } @Override @@ -587,27 +824,7 @@ public List slaves(String masterName) { final List> slaveNodes = Objects.requireNonNull(createSentinelJedis( (JedisSentinelDataSource) dataSource)).sentinelSlaves(masterName); - if(slaveNodes == null){ - return null; - } - - final List result = new ArrayList<>(slaveNodes.size()); - RedisServer redisServer; - Properties properties; - - for(Map slaveNode : slaveNodes){ - properties = new Properties(); - properties.putAll(slaveNode); - - redisServer = new RedisServer(slaveNode.get("ip"), Integer.parseInt(slaveNode.get("port")), - properties); - redisServer.setName(slaveNode.get("name")); - redisServer.setRole(Role.SLAVE); - - result.add(redisServer); - } - - return result; + return parseRedisServer(slaveNodes, Role.SLAVE); } @Override @@ -646,7 +863,8 @@ public Jedis getJedis() { @Override public Pipeline openPipeline() { if(pipeline == null){ - pipeline = new JedisPipeline(jedis.pipelined()); + final redis.clients.jedis.Pipeline pipelineObject = jedis.pipelined(); + pipeline = new JedisPipelineProxy<>(new JedisPipeline(pipelineObject), pipelineObject); } return pipeline; @@ -661,7 +879,8 @@ public void closePipeline() { @Override public Transaction multi() { if(transaction == null){ - transaction = new JedisTransaction(jedis.multi()); + final redis.clients.jedis.Transaction tran = jedis.multi(); + transaction = new JedisTransactionProxy(new JedisTransaction(tran), tran); } return transaction; @@ -715,15 +934,22 @@ public boolean isClosed() { @Override protected void internalInit() { + if(pool == null && getPoolConfig() != null){ + pool = createPool(); + } + } + + protected boolean isUsePool() { + return pool != null; } private Jedis createSentinelJedis(final JedisSentinelDataSource dataSource) { - final Set sentinels = convertToJedisSentinelSet(dataSource.getSentinels()); - final JedisClientConfigBuilder builder = JedisClientConfigBuilder.create(dataSource, getSslConfiguration()); - final JedisClientConfig clientConfig = builder.build(); + final JedisClientConfig sentinelClientConfig = createSentinelJedisClientConfig(dataSource); - for(HostAndPort sentinel : sentinels){ - try(Jedis jedis = new Jedis(sentinel, clientConfig)){ + for(RedisNode node : dataSource.getSentinels()){ + int port = node.getPort() == 0 ? RedisNode.DEFAULT_SENTINEL_PORT : node.getPort(); + HostAndPort sentinel = new HostAndPort(node.getHost(), port); + try(Jedis jedis = new Jedis(sentinel, sentinelClientConfig)){ return jedis; }catch(JedisException e){ logger.warn("Cannot get master address from sentinel running @ {}. Reason: {}. Trying next one.", @@ -734,35 +960,22 @@ private Jedis createSentinelJedis(final JedisSentinelDataSource dataSource) { return null; } - protected boolean isUsePool() { - return pool != null; - } - - private Set convertToJedisSentinelSet(Collection sentinelNodes) { - if(Validate.isEmpty(sentinelNodes)){ - return Collections.emptySet(); - } - - Set convertedNodes = new LinkedHashSet<>(sentinelNodes.size()); - - for(RedisNode node : sentinelNodes){ - if(node != null){ - int port = node.getPort() == 0 ? RedisNode.DEFAULT_SENTINEL_PORT : node.getPort(); - convertedNodes.add(new HostAndPort(node.getHost(), port)); - } - } - - return convertedNodes; - } - - protected Jedis createJedis(final JedisSentinelDataSource dataSource) { - final DefaultJedisClientConfig clientConfig = createJedisClientConfigBuilder(dataSource, - getSentinelConnectTimeout(), getSentinelSoTimeout(), getInfiniteSoTimeout()).build(); + protected Jedis createJedis() { + final JedisSentinelDataSource dataSource = (JedisSentinelDataSource) getDataSource(); + final JedisClientConfig sentinelClientConfig = createSentinelJedisClientConfig(dataSource); + final DefaultJedisClientConfig clientConfig = JedisClientConfigBuilder.create(dataSource, + getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .database(dataSource.getDatabase()) + .build(); boolean sentinelAvailable = false; for(RedisNode node : dataSource.getSentinels()){ int port = node.getPort() == 0 ? RedisNode.DEFAULT_SENTINEL_PORT : node.getPort(); - try(Jedis jedis = new Jedis(new HostAndPort(node.getHost(), port), clientConfig)){ + HostAndPort sentinel = new HostAndPort(node.getHost(), port); + try(Jedis jedis = new Jedis(sentinel, sentinelClientConfig)){ List masterAddr = jedis.sentinelGetMasterAddrByName(dataSource.getMasterName()); sentinelAvailable = true; @@ -772,13 +985,8 @@ protected Jedis createJedis(final JedisSentinelDataSource dataSource) { continue; } - final JedisClientConfigBuilder builder = JedisClientConfigBuilder.create(dataSource, - getSslConfiguration()); - - builder.database(dataSource.getDatabase()); - return new Jedis(new HostAndPort(masterAddr.get(0), Integer.parseInt(masterAddr.get(1))), - builder.build()); + clientConfig); } } @@ -808,11 +1016,34 @@ protected void doConnect() throws RedisConnectionFailureException { throw JedisRedisExceptionUtils.convert(e); } }else{ - final JedisSentinelDataSource dataSource = (JedisSentinelDataSource) getDataSource(); - jedis = createJedis(dataSource); + jedis = createJedis(); } } + protected JedisSentinelPool createPool() { + final JedisSentinelDataSource dataSource = (JedisSentinelDataSource) getDataSource(); + final JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); + final Set sentinels = createSentinelHosts(dataSource.getSentinels()); + final JedisClientConfig clientConfig = JedisClientConfigBuilder.create(dataSource, getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .database(dataSource.getDatabase()) + .build(); + final JedisClientConfig sentinelClientConfig = createSentinelJedisClientConfig(dataSource); + + getPoolConfig().toGenericObjectPoolConfig(jedisPoolConfig); + + if(getSslConfiguration() == null){ + logger.debug("Create JedisSentinelPool."); + }else{ + logger.debug("Create JedisSentinelPool with ssl."); + } + + return new JedisSentinelPool(dataSource.getMasterName(), sentinels, jedisPoolConfig, clientConfig, + sentinelClientConfig); + } + @Override protected void doDestroy() throws IOException { super.doDestroy(); @@ -844,17 +1075,11 @@ protected void doClose() throws IOException { jedis.close(); } }else{ - logger.info("Jedis quit and disconnect."); + logger.info("Jedis disconnect."); if(jedis != null){ Exception ex = null; - try{ - jedis.quit(); - }catch(Exception e){ - ex = e; - } - try{ jedis.disconnect(); }catch(Exception e){ @@ -868,4 +1093,41 @@ protected void doClose() throws IOException { } } + protected JedisClientConfig createSentinelJedisClientConfig(final JedisSentinelDataSource dataSource) { + return JedisClientConfigBuilder.create(dataSource, getSslConfiguration()) + .connectTimeout(getSentinelConnectTimeout()) + .socketTimeout(getSentinelSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .clientName(dataSource.getSentinelClientName()) + .build(); + } + + protected Set createSentinelHosts(final Collection sentinelNodes) { + if(Validate.isEmpty(sentinelNodes)){ + return Collections.emptySet(); + } + + return sentinelNodes.stream().filter(Objects::nonNull).map(node->{ + int port = node.getPort() == 0 ? RedisNode.DEFAULT_SENTINEL_PORT : node.getPort(); + return new HostAndPort(node.getHost(), port); + }).collect(Collectors.toSet()); + } + + protected List parseRedisServer(final List> nodes, final Role role) { + if(nodes == null){ + return null; + } + + return nodes.stream().map((node)->{ + Properties properties = new Properties(); + properties.putAll(node); + + RedisServer redisServer = new RedisServer(node.get("ip"), Integer.parseInt(node.get("port")), properties); + redisServer.setName(node.get("name")); + redisServer.setRole(role); + + return redisServer; + }).collect(Collectors.toList()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/AbstractLettuceRedisConnection.java b/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/AbstractLettuceRedisConnection.java new file mode 100644 index 000000000..70241b8cc --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/AbstractLettuceRedisConnection.java @@ -0,0 +1,303 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.lettuce; + +import com.buession.core.Executor; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.AbstractRedisConnection; +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.client.connection.datasource.lettuce.LettuceRedisDataSource; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.exception.LettuceRedisExceptionUtils; +import com.buession.redis.exception.RedisException; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.transaction.Transaction; + +import java.io.IOException; + +/** + * Lettuce Redis 连接对象抽象类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractLettuceRedisConnection extends AbstractRedisConnection implements LettuceRedisConnection { + + /** + * 事务 + */ + protected Transaction transaction; + + /** + * 管道 + */ + protected volatile Pipeline pipeline; + + /** + * 构造函数 + */ + public AbstractLettuceRedisConnection() { + super(); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource) { + super(dataSource); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, int connectTimeout, int soTimeout) { + super(dataSource, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param sslConfiguration + * SSL 配置 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, SslConfiguration sslConfiguration) { + super(dataSource, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param poolConfig + * 连接池配置 + */ + public AbstractLettuceRedisConnection(PoolConfig poolConfig) { + super(poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, PoolConfig poolConfig, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public AbstractLettuceRedisConnection(LettuceRedisDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + @Override + public boolean isPipeline() { + return pipeline != null; + } + + @Override + public boolean isTransaction() { + return transaction != null; + } + + @Override + public R execute(final Executor executor) throws RedisException { + try{ + return executor.execute(this); + }catch(Exception e){ + logger.error("Redis execute command failure: {}", e.getMessage(), e); + throw LettuceRedisExceptionUtils.convert(e); + } + } + + @Override + protected void doDestroy() throws IOException { + if(pipeline != null){ + pipeline.close(); + pipeline = null; + } + } + + @Override + protected void doClose() throws IOException { + if(pipeline != null){ + pipeline.close(); + pipeline = null; + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/LettuceClusterConnection.java b/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/LettuceClusterConnection.java new file mode 100644 index 000000000..b1bf2f3e3 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/LettuceClusterConnection.java @@ -0,0 +1,707 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.lettuce; + +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.validator.Validate; +import com.buession.net.HostAndPort; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.RedisClusterConnection; +import com.buession.redis.client.connection.datasource.lettuce.LettuceClusterDataSource; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.core.RedisNode; +import com.buession.redis.core.internal.lettuce.LettuceClientConfigBuilder; +import com.buession.redis.exception.LettuceRedisExceptionUtils; +import com.buession.redis.exception.RedisConnectionFailureException; +import com.buession.redis.exception.RedisException; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.pipeline.lettuce.LettucePipeline; +import com.buession.redis.pipeline.lettuce.LettucePipelineProxy; +import com.buession.redis.transaction.Transaction; +import io.lettuce.core.LettuceClientConfig; +import io.lettuce.core.LettuceClusterPool; +import io.lettuce.core.LettucePoolConfig; +import io.lettuce.core.RedisCredentialsProvider; +import io.lettuce.core.RedisURI; +import io.lettuce.core.StaticCredentialsProvider; +import io.lettuce.core.api.PipeliningFlushPolicy; +import io.lettuce.core.api.PipeliningFlushState; +import io.lettuce.core.cluster.RedisClusterClient; +import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; +import io.lettuce.core.codec.ByteArrayCodec; +import io.lettuce.core.codec.RedisCodec; +import io.lettuce.core.support.ConnectionPoolUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.time.Duration; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Lettuce 集群模式连接器 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceClusterConnection extends AbstractLettuceRedisConnection implements RedisClusterConnection { + + /** + * 最大重定向次数 + */ + private int maxRedirects; + + /** + * 最大重数时长(单位:毫秒) + */ + private int maxTotalRetriesDuration; + + /** + * 连接池 + */ + private LettuceClusterPool pool; + + /** + * {@link StatefulRedisClusterConnection} 实例 + */ + private StatefulRedisClusterConnection delegate; + + private final PipeliningFlushPolicy pipeliningFlushPolicy = PipeliningFlushPolicy.flushEachCommand(); + + private final static Logger logger = LoggerFactory.getLogger(LettuceClusterConnection.class); + + /** + * 构造函数 + */ + public LettuceClusterConnection() { + super(); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource) { + super(dataSource); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout) { + super(dataSource, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, SslConfiguration sslConfiguration) { + super(dataSource, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout, + int maxRedirects, int maxTotalRetriesDuration) { + super(dataSource, connectTimeout, soTimeout); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout, + int maxRedirects, int maxTotalRetriesDuration, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int maxRedirects, int maxTotalRetriesDuration) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int maxRedirects, + int maxTotalRetriesDuration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int maxRedirects, int maxTotalRetriesDuration, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param maxRedirects + * 最大重定向次数 + * @param maxTotalRetriesDuration + * 最大重试时长(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceClusterConnection(LettuceClusterDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int maxRedirects, int maxTotalRetriesDuration, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.maxRedirects = maxRedirects; + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + @Override + public int getMaxRedirects() { + return maxRedirects; + } + + @Override + public void setMaxRedirects(int maxRedirects) { + this.maxRedirects = maxRedirects; + } + + @Override + public int getMaxTotalRetriesDuration() { + return maxTotalRetriesDuration; + } + + @Override + public void setMaxTotalRetriesDuration(int maxTotalRetriesDuration) { + this.maxTotalRetriesDuration = maxTotalRetriesDuration; + } + + public StatefulRedisClusterConnection getStatefulRedisClusterConnection() { + return delegate; + } + + @Override + public Pipeline openPipeline() { + if(pipeline == null){ + final PipeliningFlushState flushState = pipeliningFlushPolicy.newPipeline(); + final LettucePipelineProxy lettucePipelineProxy = + new LettucePipelineProxy<>(flushState); + + lettucePipelineProxy.setTarget( + new LettucePipeline(delegate, flushState, lettucePipelineProxy.getTxResults())); + pipeline = lettucePipelineProxy; + } + + return pipeline; + } + + @Override + public void closePipeline() { + pipeline.close(); + pipeline = null; + } + + @Override + public Transaction multi() { + if(transaction == null){ + //final RedisSentinelCommands commands = delegate.sync(); + //transaction = new LettuceTransactionProxy(new LettuceTransaction(commands), commands); + } + + return transaction; + } + + @Override + public List exec() throws RedisException { + if(pipeline != null){ + final List result = pipeline.syncAndReturnAll(); + + pipeline.close(); + pipeline = null; + + return result; + }else if(transaction != null){ + final List result = transaction.exec(); + + transaction.close(); + transaction = null; + + return result; + }else{ + throw new RedisException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + @Override + public void discard() throws RedisException { + if(transaction != null){ + transaction.discard(); + transaction = null; + }else{ + throw new RedisException("ERR DISCARD without MULTI. Did you forget to call multi?"); + } + } + + @Override + public boolean isConnect() { + return delegate != null && delegate.isOpen(); + } + + @Override + public boolean isClosed() { + return delegate == null || delegate.isOpen() == false; + } + + @Override + protected void internalInit() { + if(pool == null && getPoolConfig() != null){ + pool = createPool(); + } + } + + protected boolean isUsePool() { + return pool != null; + } + + protected StatefulRedisClusterConnection createStatefulRedisClusterConnection( + final RedisCodec codec) { + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); + final LettuceClusterDataSource dataSource = (LettuceClusterDataSource) getDataSource(); + final RedisCredentialsProvider redisCredentialsProvider = Validate.hasText(dataSource.getPassword()) ? + new StaticCredentialsProvider(Validate.hasText(dataSource.getUsername()) ? dataSource.getUsername() : + null, dataSource.getPassword().toCharArray()) : null; + final Set redisURIs = dataSource.getNodes().stream().map((node)->{ + int port = node.getPort() == 0 ? RedisNode.DEFAULT_PORT : node.getPort(); + final RedisURI redisURI = RedisURI.create(node.getHost(), port); + + propertyMapper.from(redisCredentialsProvider).to(redisURI::setCredentialsProvider); + propertyMapper.from(dataSource.getClientName()).to(redisURI::setClientName); + + if(dataSource.getConnectTimeout() > 0){ + redisURI.setTimeout(Duration.ofMillis(dataSource.getConnectTimeout())); + } + + redisURI.setSsl(dataSource.getSslConfiguration() != null); + + return redisURI; + }).collect(Collectors.toSet()); + + return RedisClusterClient.create(redisURIs).connect(codec); + } + + @Override + protected void doConnect() throws RedisConnectionFailureException { + if(isUsePool()){ + try{ + delegate = pool.getResource(); + + if(logger.isInfoEnabled()){ + logger.info("StatefulRedisClusterConnection initialized with pool success."); + } + }catch(Exception e){ + if(logger.isErrorEnabled()){ + logger.error("StatefulRedisClusterConnection initialized with pool failure: {}", e.getMessage(), + e); + } + + throw LettuceRedisExceptionUtils.convert(e); + } + }else{ + delegate = createStatefulRedisClusterConnection(new ByteArrayCodec()); + } + } + + protected LettuceClusterPool createPool() { + final LettuceClusterDataSource dataSource = (LettuceClusterDataSource) getDataSource(); + final LettucePoolConfig> lettucePoolConfig = new LettucePoolConfig<>(); + final LettuceClientConfig clientConfig = LettuceClientConfigBuilder.create(dataSource, + getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .build(); + final Set nodes = createHostAndPorts(dataSource); + + getPoolConfig().toGenericObjectPoolConfig(lettucePoolConfig); + + if(getSslConfiguration() == null){ + logger.debug("Create LettuceClusterPool."); + }else{ + logger.debug("Create LettuceClusterPool with ssl."); + } + + return ConnectionPoolUtils.createLettuceClusterPool(lettucePoolConfig, nodes, clientConfig); + } + + @Override + protected void doDestroy() throws IOException { + super.doDestroy(); + + logger.info("Lettuce destroy."); + if(pool != null){ + if(logger.isInfoEnabled()){ + logger.info("Lettuce cluster pool for {} destroy.", pool.getClass().getName()); + } + + try{ + pool.destroy(); + }catch(Exception ex){ + logger.warn("Cannot properly close Lettuce cluster pool.", ex); + } + + pool = null; + } + } + + @Override + protected void doClose() throws IOException { + super.doClose(); + + logger.info("Lettuce close."); + + if(delegate != null){ + delegate.close(); + } + } + + private static Set createHostAndPorts(final LettuceClusterDataSource clusterDataSource) { + return clusterDataSource.getNodes().stream().map((node)->{ + int port = node.getPort() == 0 ? RedisNode.DEFAULT_PORT : node.getPort(); + return new HostAndPort(node.getHost(), port); + }).collect(Collectors.toSet()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/LettuceConnection.java b/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/LettuceConnection.java new file mode 100644 index 000000000..8c193a883 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/LettuceConnection.java @@ -0,0 +1,480 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.lettuce; + +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.validator.Validate; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.RedisStandaloneConnection; +import com.buession.redis.client.connection.datasource.lettuce.LettuceDataSource; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.core.internal.lettuce.LettuceClientConfigBuilder; +import com.buession.redis.exception.LettuceRedisExceptionUtils; +import com.buession.redis.exception.RedisConnectionFailureException; +import com.buession.redis.exception.RedisException; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.pipeline.lettuce.LettucePipeline; +import com.buession.redis.pipeline.lettuce.LettucePipelineProxy; +import com.buession.redis.transaction.Transaction; +import com.buession.redis.transaction.lettuce.LettuceTransaction; +import com.buession.redis.transaction.lettuce.LettuceTransactionProxy; +import io.lettuce.core.LettuceClientConfig; +import io.lettuce.core.LettucePool; +import io.lettuce.core.LettucePoolConfig; +import io.lettuce.core.RedisClient; +import io.lettuce.core.RedisCredentialsProvider; +import io.lettuce.core.RedisURI; +import io.lettuce.core.StaticCredentialsProvider; +import io.lettuce.core.api.PipeliningFlushPolicy; +import io.lettuce.core.api.PipeliningFlushState; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.core.codec.ByteArrayCodec; +import io.lettuce.core.codec.RedisCodec; +import io.lettuce.core.support.ConnectionPoolUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.time.Duration; +import java.util.List; + +/** + * Lettuce 单机模式连接器 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceConnection extends AbstractLettuceRedisConnection implements RedisStandaloneConnection { + + /** + * 连接池 + */ + private LettucePool pool; + + /** + * {@link StatefulRedisConnection} 实例 + */ + private StatefulRedisConnection delegate; + + private final PipeliningFlushPolicy pipeliningFlushPolicy = PipeliningFlushPolicy.flushEachCommand(); + + private final static Logger logger = LoggerFactory.getLogger(LettuceConnection.class); + + /** + * 构造函数 + */ + public LettuceConnection() { + super(); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + */ + public LettuceConnection(LettuceDataSource dataSource) { + super(dataSource); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public LettuceConnection(LettuceDataSource dataSource, int connectTimeout, int soTimeout) { + super(dataSource, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public LettuceConnection(LettuceDataSource dataSource, int connectTimeout, int soTimeout, int infiniteSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param sslConfiguration + * SSL 配置 + */ + public LettuceConnection(LettuceDataSource dataSource, SslConfiguration sslConfiguration) { + super(dataSource, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceConnection(LettuceDataSource dataSource, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceConnection(LettuceDataSource dataSource, int connectTimeout, int soTimeout, int infiniteSoTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param poolConfig + * 连接池配置 + */ + public LettuceConnection(PoolConfig poolConfig) { + super(poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + */ + public LettuceConnection(LettuceDataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public LettuceConnection(LettuceDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public LettuceConnection(LettuceDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + */ + public LettuceConnection(LettuceDataSource dataSource, PoolConfig poolConfig, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceConnection(LettuceDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceConnection(LettuceDataSource dataSource, PoolConfig poolConfig, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + } + + public StatefulRedisConnection getStatefulConnection() { + return delegate; + } + + @Override + public Pipeline openPipeline() { + if(pipeline == null){ + final PipeliningFlushState flushState = pipeliningFlushPolicy.newPipeline(); + final LettucePipelineProxy lettucePipelineProxy = + new LettucePipelineProxy<>(flushState); + + lettucePipelineProxy.setTarget( + new LettucePipeline(delegate, flushState, lettucePipelineProxy.getTxResults())); + pipeline = lettucePipelineProxy; + } + + return pipeline; + } + + @Override + public void closePipeline() { + pipeline.close(); + pipeline = null; + } + + @Override + public Transaction multi() { + System.out.println("transaction: " + (transaction == null ? "false" : "true")); + if(transaction == null){ + final RedisCommands commands = delegate.sync(); + commands.multi(); + transaction = new LettuceTransactionProxy(new LettuceTransaction(commands), commands); + } + + return transaction; + } + + @Override + public List exec() throws RedisException { + if(pipeline != null){ + final List result = pipeline.syncAndReturnAll(); + + pipeline.close(); + pipeline = null; + + return result; + }else if(transaction != null){ + final List result = transaction.exec(); + + transaction.close(); + transaction = null; + + return result; + }else{ + throw new RedisException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + @Override + public void discard() throws RedisException { + if(transaction != null){ + transaction.discard(); + transaction = null; + }else{ + throw new RedisException("ERR DISCARD without MULTI. Did you forget to call multi?"); + } + } + + @Override + public boolean isConnect() { + return delegate != null && delegate.isOpen(); + } + + @Override + public boolean isClosed() { + return delegate == null || delegate.isOpen() == false; + } + + @Override + protected void internalInit() { + if(pool == null && getPoolConfig() != null){ + pool = createPool(); + } + } + + protected boolean isUsePool() { + return pool != null; + } + + @Override + protected void doConnect() throws RedisConnectionFailureException { + if(isUsePool()){ + try{ + delegate = pool.getResource(); + + if(logger.isInfoEnabled()){ + logger.info("StatefulConnection initialized with pool success."); + } + }catch(Exception e){ + if(logger.isErrorEnabled()){ + logger.error("StatefulConnection initialized with pool failure: {}", e.getMessage(), e); + } + + throw LettuceRedisExceptionUtils.convert(e); + } + }else{ + delegate = createStatefulRedisConnection(new ByteArrayCodec()); + } + } + + protected StatefulRedisConnection createStatefulRedisConnection(final RedisCodec codec) { + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); + final LettuceDataSource dataSource = (LettuceDataSource) getDataSource(); + final RedisURI redisURI = RedisURI.create(dataSource.getHost(), dataSource.getPort()); + final RedisCredentialsProvider redisCredentialsProvider = Validate.hasText(dataSource.getPassword()) ? + new StaticCredentialsProvider(Validate.hasText(dataSource.getUsername()) ? dataSource.getUsername() : + null, dataSource.getPassword().toCharArray()) : null; + + if(dataSource.getDatabase() >= 0){ + redisURI.setDatabase(dataSource.getDatabase()); + } + + propertyMapper.from(redisCredentialsProvider).to(redisURI::setCredentialsProvider); + propertyMapper.from(dataSource.getClientName()).to(redisURI::setClientName); + + if(dataSource.getConnectTimeout() > 0){ + redisURI.setTimeout(Duration.ofMillis(dataSource.getConnectTimeout())); + } + + redisURI.setSsl(dataSource.getSslConfiguration() != null); + + return RedisClient.create(redisURI).connect(codec); + } + + protected LettucePool createPool() { + final LettuceDataSource dataSource = (LettuceDataSource) getDataSource(); + final LettucePoolConfig> lettucePoolConfig = new LettucePoolConfig<>(); + final LettuceClientConfig clientConfig = LettuceClientConfigBuilder.create(dataSource, + getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .database(dataSource.getDatabase()) + .build(); + + getPoolConfig().toGenericObjectPoolConfig(lettucePoolConfig); + + if(getSslConfiguration() == null){ + logger.debug("Create LettucePool."); + }else{ + logger.debug("Create LettucePool with ssl."); + } + + return ConnectionPoolUtils.createLettucePool(lettucePoolConfig, dataSource.getHost(), dataSource.getPort(), + clientConfig); + } + + @Override + protected void doDestroy() throws IOException { + super.doDestroy(); + + logger.info("Lettuce destroy."); + if(pool != null){ + if(logger.isInfoEnabled()){ + logger.info("Lettuce pool for {} destroy.", pool.getClass().getName()); + } + + try{ + pool.destroy(); + }catch(Exception ex){ + logger.warn("Cannot properly close Lettuce pool.", ex); + } + + pool = null; + } + } + + @Override + protected void doClose() throws IOException { + super.doClose(); + + logger.info("Lettuce close."); + + if(delegate != null){ + delegate.close(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/LettuceRedisConnection.java b/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/LettuceRedisConnection.java new file mode 100644 index 000000000..9b3d7ca13 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/LettuceRedisConnection.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.lettuce; + +import com.buession.redis.client.connection.RedisConnection; + +/** + * Lettuce Redis 连接对象 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface LettuceRedisConnection extends RedisConnection { + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/LettuceSentinelConnection.java b/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/LettuceSentinelConnection.java new file mode 100644 index 000000000..3241814d6 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/LettuceSentinelConnection.java @@ -0,0 +1,869 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.connection.lettuce; + +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.utils.Assert; +import com.buession.core.validator.Validate; +import com.buession.net.HostAndPort; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.RedisSentinelConnection; +import com.buession.redis.client.connection.datasource.DataSource; +import com.buession.redis.client.connection.datasource.lettuce.LettuceSentinelDataSource; +import com.buession.redis.core.Constants; +import com.buession.redis.core.PoolConfig; +import com.buession.redis.core.RedisNamedNode; +import com.buession.redis.core.RedisNode; +import com.buession.redis.core.RedisSentinelNode; +import com.buession.redis.core.RedisServer; +import com.buession.redis.core.Role; +import com.buession.redis.core.internal.lettuce.LettuceClientConfigBuilder; +import com.buession.redis.exception.LettuceRedisExceptionUtils; +import com.buession.redis.exception.RedisConnectionFailureException; +import com.buession.redis.exception.RedisException; +import com.buession.redis.pipeline.Pipeline; +import com.buession.redis.pipeline.lettuce.LettucePipeline; +import com.buession.redis.pipeline.lettuce.LettucePipelineProxy; +import com.buession.redis.transaction.Transaction; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.LettuceClientConfig; +import io.lettuce.core.LettucePoolConfig; +import io.lettuce.core.LettuceSentinelPool; +import io.lettuce.core.RedisClient; +import io.lettuce.core.RedisCredentialsProvider; +import io.lettuce.core.RedisURI; +import io.lettuce.core.StaticCredentialsProvider; +import io.lettuce.core.api.PipeliningFlushPolicy; +import io.lettuce.core.api.PipeliningFlushState; +import io.lettuce.core.codec.ByteArrayCodec; +import io.lettuce.core.codec.RedisCodec; +import io.lettuce.core.sentinel.api.StatefulRedisSentinelConnection; +import io.lettuce.core.sentinel.api.sync.RedisSentinelCommands; +import io.lettuce.core.support.ConnectionPoolUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.time.Duration; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Lettuce 哨兵模式连接器 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceSentinelConnection extends AbstractLettuceRedisConnection implements RedisSentinelConnection { + + /** + * 哨兵节点连接超时(单位:毫秒) + */ + private int sentinelConnectTimeout = Constants.DEFAULT_CONNECT_TIMEOUT; + + /** + * 哨兵节点读取超时(单位:毫秒) + */ + private int sentinelSoTimeout = Constants.DEFAULT_SO_TIMEOUT; + + /** + * 连接池 + */ + private LettuceSentinelPool pool; + + /** + * {@link StatefulRedisSentinelConnection} 实例 + */ + private StatefulRedisSentinelConnection delegate; + + private final PipeliningFlushPolicy pipeliningFlushPolicy = PipeliningFlushPolicy.flushEachCommand(); + + private final static Logger logger = LoggerFactory.getLogger(LettuceSentinelConnection.class); + + /** + * 构造函数 + */ + public LettuceSentinelConnection() { + super(); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource) { + super(dataSource); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout) { + super(dataSource, connectTimeout, soTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, SslConfiguration sslConfiguration) { + super(dataSource, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int sentinelConnectTimeout, int sentinelSoTimeout) { + super(dataSource, connectTimeout, soTimeout); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int sentinelConnectTimeout, int sentinelSoTimeout) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int sentinelConnectTimeout, int sentinelSoTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, int connectTimeout, int soTimeout, + int infiniteSoTimeout, int sentinelConnectTimeout, int sentinelSoTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param poolConfig + * 连接池配置 + */ + public LettuceSentinelConnection(PoolConfig poolConfig) { + super(poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig) { + super(dataSource, poolConfig); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, sslConfiguration); + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = connectTimeout; + this.sentinelSoTimeout = soTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int sentinelConnectTimeout, int sentinelSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int sentinelConnectTimeout, + int sentinelSoTimeout) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int sentinelConnectTimeout, int sentinelSoTimeout, + SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + /** + * 构造函数 + * + * @param dataSource + * Redis 数据源 + * @param poolConfig + * 连接池配置 + * @param connectTimeout + * 连接超时(单位:毫秒) + * @param soTimeout + * 读取超时(单位:毫秒) + * @param infiniteSoTimeout + * Infinite 读取超时 + * @param sentinelConnectTimeout + * 哨兵节点连接超时(单位:毫秒) + * @param sentinelSoTimeout + * 哨兵节点读取超时(单位:毫秒) + * @param sslConfiguration + * SSL 配置 + */ + public LettuceSentinelConnection(LettuceSentinelDataSource dataSource, PoolConfig poolConfig, int connectTimeout, + int soTimeout, int infiniteSoTimeout, int sentinelConnectTimeout, + int sentinelSoTimeout, SslConfiguration sslConfiguration) { + super(dataSource, poolConfig, connectTimeout, soTimeout, infiniteSoTimeout, sslConfiguration); + this.sentinelConnectTimeout = sentinelConnectTimeout; + this.sentinelSoTimeout = sentinelSoTimeout; + } + + @Override + public int getSentinelConnectTimeout() { + return sentinelConnectTimeout; + } + + @Override + public void setSentinelConnectTimeout(int sentinelConnectTimeout) { + this.sentinelConnectTimeout = sentinelConnectTimeout; + } + + @Override + public int getSentinelSoTimeout() { + return sentinelSoTimeout; + } + + @Override + public void setSentinelSoTimeout(int sentinelSoTimeout) { + this.sentinelSoTimeout = sentinelSoTimeout; + } + + @Override + public List masters() { + DataSource dataSource = getDataSource(); + if(dataSource == null){ + return null; + } + + final List> masterNodes = getSentinelCommands( + (LettuceSentinelDataSource) dataSource).masters(); + return parseRedisServer(masterNodes, Role.MASTER); + } + + @Override + public List slaves(RedisNamedNode master) { + Assert.isNull(master, "Redis master node cloud not be 'null' for loading slaves."); + return slaves(master.getName()); + } + + @Override + public List slaves(String masterName) { + Assert.isBlank(masterName, "Redis master name cloud not be 'null' or empty for loading slaves."); + + DataSource dataSource = getDataSource(); + if(dataSource == null){ + return null; + } + + final List> slaveNodes = getSentinelCommands( + (LettuceSentinelDataSource) dataSource).slaves(SafeEncoder.encode(masterName)); + return parseRedisServer(slaveNodes, Role.SLAVE); + } + + @Override + public void failover(RedisNamedNode namedNode) { + Assert.isNull(namedNode, "Redis master node cloud not be 'null' for failover."); + Assert.isBlank(namedNode.getName(), "Redis master name cloud not be 'null' or empty for failover."); + + DataSource dataSource = getDataSource(); + if(dataSource == null){ + return; + } + + Objects.requireNonNull(getSentinelCommands((LettuceSentinelDataSource) dataSource)) + .failover(SafeEncoder.encode(namedNode.getName())); + } + + @Override + public void monitor(RedisSentinelNode server) { + Assert.isNull(server, "Cannot monitor 'null' server."); + Assert.isBlank(server.getName(), "Name of server to monitor must not be 'null' or empty."); + Assert.isBlank(server.getHost(), "Host must not be 'null' for server to monitor."); + + DataSource dataSource = getDataSource(); + if(dataSource == null){ + return; + } + + Objects.requireNonNull(getSentinelCommands((LettuceSentinelDataSource) dataSource)) + .monitor(SafeEncoder.encode(server.getName()), server.getHost(), server.getPort(), server.getQuorum()); + } + + public StatefulRedisSentinelConnection getStatefulRedisSentinelConnection() { + return delegate; + } + + @Override + public Pipeline openPipeline() { + if(pipeline == null){ + final PipeliningFlushState flushState = pipeliningFlushPolicy.newPipeline(); + final LettucePipelineProxy lettucePipelineProxy = + new LettucePipelineProxy<>(flushState); + + lettucePipelineProxy.setTarget( + new LettucePipeline(delegate, flushState, lettucePipelineProxy.getTxResults())); + pipeline = lettucePipelineProxy; + } + + return pipeline; + } + + @Override + public void closePipeline() { + pipeline.close(); + pipeline = null; + } + + @Override + public Transaction multi() { + if(transaction == null){ + final RedisSentinelCommands commands = delegate.sync(); + //transaction = new LettuceTransactionProxy(new LettuceTransaction(commands), commands); + } + + return transaction; + } + + @Override + public List exec() throws RedisException { + if(pipeline != null){ + final List result = pipeline.syncAndReturnAll(); + + pipeline.close(); + pipeline = null; + + return result; + }else if(transaction != null){ + final List result = transaction.exec(); + + transaction.close(); + transaction = null; + + return result; + }else{ + throw new RedisException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + @Override + public void discard() throws RedisException { + if(transaction != null){ + transaction.discard(); + transaction = null; + }else{ + throw new RedisException("ERR DISCARD without MULTI. Did you forget to call multi?"); + } + } + + @Override + public void remove(RedisNamedNode master) { + Assert.isNull(master, "Master node cloud be 'null' when trying to remove."); + remove(master.getName()); + } + + @Override + public void remove(String masterName) { + Assert.isBlank(masterName, "Redis master name cloud be 'null' or empty when trying to remove."); + delegate.async().remove(SafeEncoder.encode(masterName)); + } + + @Override + public boolean isConnect() { + return delegate != null && delegate.isOpen(); + } + + @Override + public boolean isClosed() { + return delegate == null || delegate.isOpen() == false; + } + + @Override + protected void internalInit() { + if(pool == null && getPoolConfig() != null){ + pool = createPool(); + } + } + + private RedisSentinelCommands getSentinelCommands(final LettuceSentinelDataSource dataSource) { + return delegate.sync(); + } + + protected boolean isUsePool() { + return pool != null; + } + + protected StatefulRedisSentinelConnection createStatefulRedisSentinelConnection( + final RedisCodec codec) { + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); + final LettuceSentinelDataSource dataSource = (LettuceSentinelDataSource) getDataSource(); + final RedisURI.Builder redisURIBuilder = RedisURI.builder(); + final RedisCredentialsProvider redisCredentialsProvider = Validate.hasText(dataSource.getPassword()) ? + new StaticCredentialsProvider(Validate.hasText(dataSource.getUsername()) ? dataSource.getUsername() : + null, dataSource.getPassword().toCharArray()) : null; + + if(dataSource.getDatabase() >= 0){ + redisURIBuilder.withDatabase(dataSource.getDatabase()); + } + + propertyMapper.from(redisCredentialsProvider).to(redisURIBuilder::withAuthentication); + propertyMapper.from(dataSource.getClientName()).to(redisURIBuilder::withClientName); + + if(dataSource.getConnectTimeout() > 0){ + redisURIBuilder.withTimeout(Duration.ofMillis(dataSource.getConnectTimeout())); + } + + redisURIBuilder.withSsl(dataSource.getSslConfiguration() != null); + + return RedisClient.create(redisURIBuilder.build()).connectSentinel(codec); + } + + @Override + protected void doConnect() throws RedisConnectionFailureException { + if(isUsePool()){ + try{ + delegate = pool.getResource(); + + if(logger.isInfoEnabled()){ + logger.info("StatefulRedisSentinelConnection initialized with pool success."); + } + }catch(Exception e){ + if(logger.isErrorEnabled()){ + logger.error("StatefulRedisSentinelConnection initialized with pool failure: {}", e.getMessage(), + e); + } + + throw LettuceRedisExceptionUtils.convert(e); + } + }else{ + delegate = createStatefulRedisSentinelConnection(new ByteArrayCodec()); + } + } + + protected LettuceSentinelPool createPool() { + final LettuceSentinelDataSource dataSource = (LettuceSentinelDataSource) getDataSource(); + final LettucePoolConfig> lettucePoolConfig = new LettucePoolConfig<>(); + final Set sentinels = createSentinelHosts(dataSource.getSentinels()); + final LettuceClientConfig clientConfig = LettuceClientConfigBuilder.create(dataSource, + getSslConfiguration()) + .connectTimeout(getConnectTimeout()) + .socketTimeout(getSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .database(dataSource.getDatabase()) + .build(); + final LettuceClientConfig sentinelClientConfig = createSentinelLettuceClientConfig(dataSource); + + getPoolConfig().toGenericObjectPoolConfig(lettucePoolConfig); + + if(getSslConfiguration() == null){ + logger.debug("Create LettuceSentinelPool."); + }else{ + logger.debug("Create LettuceSentinelPool with ssl."); + } + + return ConnectionPoolUtils.createLettuceSentinelPool(dataSource.getMasterName(), lettucePoolConfig, + sentinels, clientConfig, sentinelClientConfig); + } + + @Override + protected void doDestroy() throws IOException { + super.doDestroy(); + + logger.info("Lettuce destroy."); + if(pool != null){ + if(logger.isInfoEnabled()){ + logger.info("Lettuce sentinel pool for {} destroy.", pool.getClass().getName()); + } + + try{ + pool.destroy(); + }catch(Exception ex){ + logger.warn("Cannot properly close Lettuce sentinel pool.", ex); + } + + pool = null; + } + } + + @Override + protected void doClose() throws IOException { + super.doClose(); + + logger.info("Lettuce close."); + + if(delegate != null){ + delegate.close(); + } + } + + protected LettuceClientConfig createSentinelLettuceClientConfig(final LettuceSentinelDataSource dataSource) { + return LettuceClientConfigBuilder.create(dataSource, getSslConfiguration()) + .connectTimeout(getSentinelConnectTimeout()) + .socketTimeout(getSentinelSoTimeout()) + .infiniteSoTimeout(getInfiniteSoTimeout()) + .clientName(dataSource.getSentinelClientName()) + .build(); + } + + protected Set createSentinelHosts(final Collection sentinelNodes) { + if(Validate.isEmpty(sentinelNodes)){ + return Collections.emptySet(); + } + + return sentinelNodes.stream().filter(Objects::nonNull).map(node->{ + int port = node.getPort() == 0 ? RedisNode.DEFAULT_SENTINEL_PORT : node.getPort(); + return new HostAndPort(node.getHost(), port); + }).collect(Collectors.toSet()); + } + + protected List parseRedisServer(final List> nodes, final Role role) { + if(nodes == null){ + return null; + } + + return nodes.stream().map((node)->{ + if(node == null){ + return null; + }else{ + final Map sNodes = new HashMap<>(node.size()); + final Properties properties = new Properties(); + + node.forEach((key, value)->{ + sNodes.put(SafeEncoder.encode(key), SafeEncoder.encode(value)); + }); + + properties.putAll(sNodes); + + final RedisServer redisServer = new RedisServer(sNodes.get("ip"), + Integer.parseInt(sNodes.get("port")), properties); + redisServer.setName(sNodes.get("name")); + redisServer.setRole(role); + + return redisServer; + } + }).collect(Collectors.toList()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/package-info.java b/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/package-info.java new file mode 100644 index 000000000..0175f8b94 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/connection/lettuce/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.client.connection.lettuce; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/AbstractJedisRedisClient.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/AbstractJedisRedisClient.java index 601f8c909..f4d260879 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/AbstractJedisRedisClient.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/AbstractJedisRedisClient.java @@ -19,32 +19,29 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis; import com.buession.redis.client.AbstractRedisClient; import com.buession.redis.client.connection.jedis.JedisRedisConnection; -import com.buession.redis.core.FutureResult; -import redis.clients.jedis.Response; - -import java.util.LinkedList; -import java.util.Queue; /** * Jedis Redis 客户端抽象类 * + * @param + * Jedis Redis 连接对象类型 {@link JedisRedisConnection} + * * @author Yong.Teng */ -public abstract class AbstractJedisRedisClient extends AbstractRedisClient implements JedisRedisClient { - - private Queue, Object, Object>> txResults = new LinkedList<>(); +public abstract class AbstractJedisRedisClient extends AbstractRedisClient + implements JedisRedisClient { /** * 构造函数 */ - public AbstractJedisRedisClient(){ + public AbstractJedisRedisClient() { super(); } @@ -54,13 +51,8 @@ public AbstractJedisRedisClient(){ * @param connection * Jedis Redis 连接对象 {@link JedisRedisConnection} */ - public AbstractJedisRedisClient(final JedisRedisConnection connection){ + public AbstractJedisRedisClient(final CONN connection) { super(connection); } - @Override - public Queue, Object, Object>> getTxResults(){ - return txResults; - } - } \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisClusterClient.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisClusterClient.java index dde08bc4a..3d34ccf88 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisClusterClient.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisClusterClient.java @@ -19,17 +19,17 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis; import com.buession.redis.client.RedisClusterClient; -import com.buession.redis.client.connection.RedisConnection; import com.buession.redis.client.connection.jedis.JedisClusterConnection; import com.buession.redis.client.jedis.operations.JedisClusterBitMapOperations; import com.buession.redis.client.jedis.operations.JedisClusterClusterOperations; import com.buession.redis.client.jedis.operations.JedisClusterConnectionOperations; +import com.buession.redis.client.jedis.operations.JedisClusterGenericOperations; import com.buession.redis.client.jedis.operations.JedisClusterGeoOperations; import com.buession.redis.client.jedis.operations.JedisClusterHashOperations; import com.buession.redis.client.jedis.operations.JedisClusterHyperLogLogOperations; @@ -43,6 +43,7 @@ import com.buession.redis.client.jedis.operations.JedisClusterStreamOperations; import com.buession.redis.client.jedis.operations.JedisClusterStringOperations; import com.buession.redis.client.jedis.operations.JedisClusterTransactionOperations; +import com.buession.redis.client.operations.*; /** * jedis 集群模式客户端 @@ -50,14 +51,12 @@ * @author Yong.Teng * @since 2.0.0 */ -public class JedisClusterClient extends AbstractJedisRedisClient implements RedisClusterClient { - - private JedisClusterConnection connection; +public class JedisClusterClient extends AbstractJedisRedisClient implements RedisClusterClient { /** * 构造函数 */ - public JedisClusterClient(){ + public JedisClusterClient() { super(); } @@ -67,98 +66,161 @@ public JedisClusterClient(){ * @param connection * Jedis Redis 集群连接对象 {@link JedisClusterConnection} */ - public JedisClusterClient(final JedisClusterConnection connection){ + public JedisClusterClient(final JedisClusterConnection connection) { super(connection); } @Override - public JedisClusterConnection getConnection(){ - return connection; - } + public BitMapOperations bitMapOperations() { + if(bitMapOperations == null){ + bitMapOperations = new JedisClusterBitMapOperations(this); + } - @Override - public void setConnection(RedisConnection connection){ - this.connection = (JedisClusterConnection) connection; + return bitMapOperations; } @Override - public JedisClusterBitMapOperations bitMapOperations(){ - return new JedisClusterBitMapOperations(this); + public ClusterOperations clusterOperations() { + if(clusterOperations == null){ + clusterOperations = new JedisClusterClusterOperations(this); + } + + return clusterOperations; } @Override - public JedisClusterClusterOperations clusterOperations(){ - return new JedisClusterClusterOperations(this); + public ConnectionOperations connectionOperations() { + if(connectionOperations == null){ + connectionOperations = new JedisClusterConnectionOperations(this); + } + + return connectionOperations; } @Override - public JedisClusterConnectionOperations connectionOperations(){ - return new JedisClusterConnectionOperations(this); + public GenericOperations genericOperations() { + if(genericOperations == null){ + genericOperations = new JedisClusterGenericOperations(this); + } + + return genericOperations; } @Override - public JedisClusterGeoOperations geoOperations(){ - return new JedisClusterGeoOperations(this); + public GeoOperations geoOperations() { + if(geoOperations == null){ + geoOperations = new JedisClusterGeoOperations(this); + } + + return geoOperations; } @Override - public JedisClusterHashOperations hashOperations(){ - return new JedisClusterHashOperations(this); + public HashOperations hashOperations() { + if(hashOperations == null){ + hashOperations = new JedisClusterHashOperations(this); + } + + return hashOperations; } @Override - public JedisClusterHyperLogLogOperations hyperLogLogOperations(){ - return new JedisClusterHyperLogLogOperations(this); + public HyperLogLogOperations hyperLogLogOperations() { + if(hyperLogLogOperations == null){ + hyperLogLogOperations = new JedisClusterHyperLogLogOperations(this); + } + + return hyperLogLogOperations; } @Override - public JedisClusterKeyOperations keyOperations(){ - return new JedisClusterKeyOperations(this); + public KeyOperations keyOperations() { + if(keyOperations == null){ + keyOperations = new JedisClusterKeyOperations(this); + } + + return keyOperations; } @Override - public JedisClusterListOperations listOperations(){ - return new JedisClusterListOperations(this); + public ListOperations listOperations() { + if(listOperations == null){ + listOperations = new JedisClusterListOperations(this); + } + + return listOperations; } @Override - public JedisClusterPubSubOperations pubSubOperations(){ - return new JedisClusterPubSubOperations(this); + public PubSubOperations pubSubOperations() { + if(pubSubOperations == null){ + pubSubOperations = new JedisClusterPubSubOperations(this); + } + + return pubSubOperations; } @Override - public JedisClusterScriptingOperations scriptingOperations(){ - return new JedisClusterScriptingOperations(this); + public ScriptingOperations scriptingOperations() { + if(scriptingOperations == null){ + scriptingOperations = new JedisClusterScriptingOperations(this); + } + + return scriptingOperations; } @Override - public JedisClusterServerOperations serverOperations(){ - return new JedisClusterServerOperations(this); + public ServerOperations serverOperations() { + if(serverOperations == null){ + serverOperations = new JedisClusterServerOperations(this); + } + + return serverOperations; } @Override - public JedisClusterSetOperations setOperations(){ - return new JedisClusterSetOperations(this); + public SetOperations setOperations() { + if(setOperations == null){ + setOperations = new JedisClusterSetOperations(this); + } + + return setOperations; } @Override - public JedisClusterSortedSetOperations sortedSetOperations(){ - return new JedisClusterSortedSetOperations(this); + public SortedSetOperations sortedSetOperations() { + if(sortedSetOperations == null){ + sortedSetOperations = new JedisClusterSortedSetOperations(this); + } + + return sortedSetOperations; } @Override - public JedisClusterStreamOperations streamOperations(){ - return new JedisClusterStreamOperations(this); + public StreamOperations streamOperations() { + if(streamOperations == null){ + streamOperations = new JedisClusterStreamOperations(this); + } + + return streamOperations; } @Override - public JedisClusterStringOperations stringOperations(){ - return new JedisClusterStringOperations(this); + public StringOperations stringOperations() { + if(stringOperations == null){ + stringOperations = new JedisClusterStringOperations(this); + } + + return stringOperations; } @Override - public JedisClusterTransactionOperations transactionOperations(){ - return new JedisClusterTransactionOperations(this); + public TransactionOperations transactionOperations() { + if(transactionOperations == null){ + transactionOperations = new JedisClusterTransactionOperations(this); + } + + return transactionOperations; } } \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisRedisClient.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisRedisClient.java index d7f3a198c..826879b95 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisRedisClient.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisRedisClient.java @@ -19,16 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis; import com.buession.redis.client.RedisClient; -import com.buession.redis.core.FutureResult; -import redis.clients.jedis.Response; - -import java.util.Queue; /** * Jedis Redis 客户端 @@ -37,6 +33,4 @@ */ public interface JedisRedisClient extends RedisClient { - Queue, Object, Object>> getTxResults(); - } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisSentinelClient.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisSentinelClient.java index af4db20c1..c9735e5cb 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisSentinelClient.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisSentinelClient.java @@ -19,17 +19,17 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis; import com.buession.redis.client.RedisSentinelClient; -import com.buession.redis.client.connection.RedisConnection; import com.buession.redis.client.connection.jedis.JedisSentinelConnection; import com.buession.redis.client.jedis.operations.JedisSentinelBitMapOperations; import com.buession.redis.client.jedis.operations.JedisSentinelClusterOperations; import com.buession.redis.client.jedis.operations.JedisSentinelConnectionOperations; +import com.buession.redis.client.jedis.operations.JedisSentinelGenericOperations; import com.buession.redis.client.jedis.operations.JedisSentinelGeoOperations; import com.buession.redis.client.jedis.operations.JedisSentinelHashOperations; import com.buession.redis.client.jedis.operations.JedisSentinelHyperLogLogOperations; @@ -43,6 +43,7 @@ import com.buession.redis.client.jedis.operations.JedisSentinelStreamOperations; import com.buession.redis.client.jedis.operations.JedisSentinelStringOperations; import com.buession.redis.client.jedis.operations.JedisSentinelTransactionOperations; +import com.buession.redis.client.operations.*; /** * jedis 哨兵模式客户端 @@ -50,14 +51,13 @@ * @author Yong.Teng * @since 2.0.0 */ -public class JedisSentinelClient extends AbstractJedisRedisClient implements RedisSentinelClient { - - private JedisSentinelConnection connection; +public class JedisSentinelClient extends AbstractJedisRedisClient + implements RedisSentinelClient { /** * 构造函数 */ - public JedisSentinelClient(){ + public JedisSentinelClient() { super(); } @@ -67,98 +67,161 @@ public JedisSentinelClient(){ * @param connection * Jedis Redis 哨兵连接对象 {@link JedisSentinelConnection} */ - public JedisSentinelClient(final JedisSentinelConnection connection){ + public JedisSentinelClient(final JedisSentinelConnection connection) { super(connection); } @Override - public JedisSentinelConnection getConnection(){ - return connection; - } + public BitMapOperations bitMapOperations() { + if(bitMapOperations == null){ + bitMapOperations = new JedisSentinelBitMapOperations(this); + } - @Override - public void setConnection(RedisConnection connection){ - this.connection = (JedisSentinelConnection) connection; + return bitMapOperations; } @Override - public JedisSentinelBitMapOperations bitMapOperations(){ - return new JedisSentinelBitMapOperations(this); + public ClusterOperations clusterOperations() { + if(clusterOperations == null){ + clusterOperations = new JedisSentinelClusterOperations(this); + } + + return clusterOperations; } @Override - public JedisSentinelClusterOperations clusterOperations(){ - return new JedisSentinelClusterOperations(this); + public ConnectionOperations connectionOperations() { + if(connectionOperations == null){ + connectionOperations = new JedisSentinelConnectionOperations(this); + } + + return connectionOperations; } @Override - public JedisSentinelConnectionOperations connectionOperations(){ - return new JedisSentinelConnectionOperations(this); + public GenericOperations genericOperations() { + if(genericOperations == null){ + genericOperations = new JedisSentinelGenericOperations(this); + } + + return genericOperations; } @Override - public JedisSentinelGeoOperations geoOperations(){ - return new JedisSentinelGeoOperations(this); + public GeoOperations geoOperations() { + if(geoOperations == null){ + geoOperations = new JedisSentinelGeoOperations(this); + } + + return geoOperations; } @Override - public JedisSentinelHashOperations hashOperations(){ - return new JedisSentinelHashOperations(this); + public HashOperations hashOperations() { + if(hashOperations == null){ + hashOperations = new JedisSentinelHashOperations(this); + } + + return hashOperations; } @Override - public JedisSentinelHyperLogLogOperations hyperLogLogOperations(){ - return new JedisSentinelHyperLogLogOperations(this); + public HyperLogLogOperations hyperLogLogOperations() { + if(hyperLogLogOperations == null){ + hyperLogLogOperations = new JedisSentinelHyperLogLogOperations(this); + } + + return hyperLogLogOperations; } @Override - public JedisSentinelKeyOperations keyOperations(){ - return new JedisSentinelKeyOperations(this); + public KeyOperations keyOperations() { + if(keyOperations == null){ + keyOperations = new JedisSentinelKeyOperations(this); + } + + return keyOperations; } @Override - public JedisSentinelListOperations listOperations(){ - return new JedisSentinelListOperations(this); + public ListOperations listOperations() { + if(listOperations == null){ + listOperations = new JedisSentinelListOperations(this); + } + + return listOperations; } @Override - public JedisSentinelPubSubOperations pubSubOperations(){ - return new JedisSentinelPubSubOperations(this); + public PubSubOperations pubSubOperations() { + if(pubSubOperations == null){ + pubSubOperations = new JedisSentinelPubSubOperations(this); + } + + return pubSubOperations; } @Override - public JedisSentinelScriptingOperations scriptingOperations(){ - return new JedisSentinelScriptingOperations(this); + public ScriptingOperations scriptingOperations() { + if(scriptingOperations == null){ + scriptingOperations = new JedisSentinelScriptingOperations(this); + } + + return scriptingOperations; } @Override - public JedisSentinelServerOperations serverOperations(){ - return new JedisSentinelServerOperations(this); + public ServerOperations serverOperations() { + if(serverOperations == null){ + serverOperations = new JedisSentinelServerOperations(this); + } + + return serverOperations; } @Override - public JedisSentinelSetOperations setOperations(){ - return new JedisSentinelSetOperations(this); + public SetOperations setOperations() { + if(setOperations == null){ + setOperations = new JedisSentinelSetOperations(this); + } + + return setOperations; } @Override - public JedisSentinelSortedSetOperations sortedSetOperations(){ - return new JedisSentinelSortedSetOperations(this); + public SortedSetOperations sortedSetOperations() { + if(sortedSetOperations == null){ + sortedSetOperations = new JedisSentinelSortedSetOperations(this); + } + + return sortedSetOperations; } @Override - public JedisSentinelStreamOperations streamOperations(){ - return new JedisSentinelStreamOperations(this); + public StreamOperations streamOperations() { + if(streamOperations == null){ + streamOperations = new JedisSentinelStreamOperations(this); + } + + return streamOperations; } @Override - public JedisSentinelStringOperations stringOperations(){ - return new JedisSentinelStringOperations(this); + public StringOperations stringOperations() { + if(stringOperations == null){ + stringOperations = new JedisSentinelStringOperations(this); + } + + return stringOperations; } @Override - public JedisSentinelTransactionOperations transactionOperations(){ - return new JedisSentinelTransactionOperations(this); + public TransactionOperations transactionOperations() { + if(transactionOperations == null){ + transactionOperations = new JedisSentinelTransactionOperations(this); + } + + return transactionOperations; } } \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisStandaloneClient.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisStandaloneClient.java index 3edc15407..844445a6f 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisStandaloneClient.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/JedisStandaloneClient.java @@ -19,17 +19,17 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis; import com.buession.redis.client.RedisStandaloneClient; -import com.buession.redis.client.connection.RedisConnection; import com.buession.redis.client.connection.jedis.JedisConnection; import com.buession.redis.client.jedis.operations.JedisBitMapOperations; import com.buession.redis.client.jedis.operations.JedisClusterOperations; import com.buession.redis.client.jedis.operations.JedisConnectionOperations; +import com.buession.redis.client.jedis.operations.JedisGenericOperations; import com.buession.redis.client.jedis.operations.JedisGeoOperations; import com.buession.redis.client.jedis.operations.JedisHashOperations; import com.buession.redis.client.jedis.operations.JedisHyperLogLogOperations; @@ -43,20 +43,19 @@ import com.buession.redis.client.jedis.operations.JedisStreamOperations; import com.buession.redis.client.jedis.operations.JedisStringOperations; import com.buession.redis.client.jedis.operations.JedisTransactionOperations; +import com.buession.redis.client.operations.*; /** * Jedis 单机模式客户端 * * @author Yong.Teng */ -public class JedisStandaloneClient extends AbstractJedisRedisClient implements RedisStandaloneClient { - - private JedisConnection connection; +public class JedisStandaloneClient extends AbstractJedisRedisClient implements RedisStandaloneClient { /** * 构造函数 */ - public JedisStandaloneClient(){ + public JedisStandaloneClient() { super(); } @@ -66,98 +65,161 @@ public JedisStandaloneClient(){ * @param connection * Jedis Redis 单机连接对象 {@link JedisConnection} */ - public JedisStandaloneClient(final JedisConnection connection){ + public JedisStandaloneClient(final JedisConnection connection) { super(connection); } @Override - public JedisConnection getConnection(){ - return connection; - } + public BitMapOperations bitMapOperations() { + if(bitMapOperations == null){ + bitMapOperations = new JedisBitMapOperations(this); + } - @Override - public void setConnection(RedisConnection connection){ - this.connection = (JedisConnection) connection; + return bitMapOperations; } @Override - public JedisBitMapOperations bitMapOperations(){ - return new JedisBitMapOperations(this); + public ClusterOperations clusterOperations() { + if(clusterOperations == null){ + clusterOperations = new JedisClusterOperations(this); + } + + return clusterOperations; } @Override - public JedisClusterOperations clusterOperations(){ - return new JedisClusterOperations(this); + public ConnectionOperations connectionOperations() { + if(connectionOperations == null){ + connectionOperations = new JedisConnectionOperations(this); + } + + return connectionOperations; } @Override - public JedisConnectionOperations connectionOperations(){ - return new JedisConnectionOperations(this); + public GenericOperations genericOperations() { + if(genericOperations == null){ + genericOperations = new JedisGenericOperations(this); + } + + return genericOperations; } @Override - public JedisGeoOperations geoOperations(){ - return new JedisGeoOperations(this); + public GeoOperations geoOperations() { + if(geoOperations == null){ + geoOperations = new JedisGeoOperations(this); + } + + return geoOperations; } @Override - public JedisHashOperations hashOperations(){ - return new JedisHashOperations(this); + public HashOperations hashOperations() { + if(hashOperations == null){ + hashOperations = new JedisHashOperations(this); + } + + return hashOperations; } @Override - public JedisHyperLogLogOperations hyperLogLogOperations(){ - return new JedisHyperLogLogOperations(this); + public HyperLogLogOperations hyperLogLogOperations() { + if(hyperLogLogOperations == null){ + hyperLogLogOperations = new JedisHyperLogLogOperations(this); + } + + return hyperLogLogOperations; } @Override - public JedisKeyOperations keyOperations(){ - return new JedisKeyOperations(this); + public KeyOperations keyOperations() { + if(keyOperations == null){ + keyOperations = new JedisKeyOperations(this); + } + + return keyOperations; } @Override - public JedisListOperations listOperations(){ - return new JedisListOperations(this); + public ListOperations listOperations() { + if(listOperations == null){ + listOperations = new JedisListOperations(this); + } + + return listOperations; } @Override - public JedisPubSubOperations pubSubOperations(){ - return new JedisPubSubOperations(this); + public PubSubOperations pubSubOperations() { + if(pubSubOperations == null){ + pubSubOperations = new JedisPubSubOperations(this); + } + + return pubSubOperations; } @Override - public JedisScriptingOperations scriptingOperations(){ - return new JedisScriptingOperations(this); + public ScriptingOperations scriptingOperations() { + if(scriptingOperations == null){ + scriptingOperations = new JedisScriptingOperations(this); + } + + return scriptingOperations; } @Override - public JedisServerOperations serverOperations(){ - return new JedisServerOperations(this); + public ServerOperations serverOperations() { + if(serverOperations == null){ + serverOperations = new JedisServerOperations(this); + } + + return serverOperations; } @Override - public JedisSetOperations setOperations(){ - return new JedisSetOperations(this); + public SetOperations setOperations() { + if(setOperations == null){ + setOperations = new JedisSetOperations(this); + } + + return setOperations; } @Override - public JedisSortedSetOperations sortedSetOperations(){ - return new JedisSortedSetOperations(this); + public SortedSetOperations sortedSetOperations() { + if(sortedSetOperations == null){ + sortedSetOperations = new JedisSortedSetOperations(this); + } + + return sortedSetOperations; } @Override - public JedisStreamOperations streamOperations(){ - return new JedisStreamOperations(this); + public StreamOperations streamOperations() { + if(streamOperations == null){ + streamOperations = new JedisStreamOperations(this); + } + + return streamOperations; } @Override - public JedisStringOperations stringOperations(){ - return new JedisStringOperations(this); + public StringOperations stringOperations() { + if(stringOperations == null){ + stringOperations = new JedisStringOperations(this); + } + + return stringOperations; } @Override - public JedisTransactionOperations transactionOperations(){ - return new JedisTransactionOperations(this); + public TransactionOperations transactionOperations() { + if(transactionOperations == null){ + transactionOperations = new JedisTransactionOperations(this); + } + + return transactionOperations; } } \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractBitMapOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractBitMapOperations.java index 4cd92dfa0..920ea2a85 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractBitMapOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractBitMapOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -39,7 +39,7 @@ public abstract class AbstractBitMapOperations extends AbstractJedisRedisOperations implements BitMapOperations { - public AbstractBitMapOperations(final C client){ + public AbstractBitMapOperations(final C client) { super(client); } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractClusterOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractClusterOperations.java index 8631017a3..af03a5c27 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractClusterOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractClusterOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -46,42 +46,47 @@ public abstract class AbstractClusterOperations extends AbstractJedisRedisOperations implements ClusterOperations { - public AbstractClusterOperations(final C client){ + public AbstractClusterOperations(final C client) { super(client); } @Override - public Status clusterForget(final byte[] nodeId){ + public Integer clusterCountFailureReports(final byte[] nodeId) { + return clusterCountFailureReports(SafeEncoder.encode(nodeId)); + } + + @Override + public Status clusterForget(final byte[] nodeId) { return clusterForget(SafeEncoder.encode(nodeId)); } @Override - public Long clusterKeySlot(final byte[] key){ + public Long clusterKeySlot(final byte[] key) { return clusterKeySlot(SafeEncoder.encode(key)); } @Override - public List clusterSlaves(final byte[] nodeId){ + public List clusterSlaves(final byte[] nodeId) { return clusterSlaves(SafeEncoder.encode(nodeId)); } @Override - public List clusterReplicas(final byte[] nodeId){ + public List clusterReplicas(final byte[] nodeId) { return clusterReplicas(SafeEncoder.encode(nodeId)); } @Override - public Status clusterReplicate(final byte[] nodeId){ + public Status clusterReplicate(final byte[] nodeId) { return clusterReplicate(SafeEncoder.encode(nodeId)); } @Override - public Status clusterReset(){ + public Status clusterReset() { return clusterReset(ClusterResetOption.SOFT); } @Override - public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final byte[] nodeId){ + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final byte[] nodeId) { return clusterSetSlot(slot, setSlotOption, SafeEncoder.encode(nodeId)); } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractConnectionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractConnectionOperations.java index 24b01b5cd..49609c7df 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractConnectionOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractConnectionOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractGenericOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractGenericOperations.java new file mode 100644 index 000000000..c38c1cb52 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractGenericOperations.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.operations.GenericOperations; + +/** + * Jedis 一般命令操作抽象类 + * + * @param + * Redis Client {@link JedisRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractGenericOperations extends AbstractJedisRedisOperations + implements GenericOperations { + + public AbstractGenericOperations(final C client) { + super(client); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractGeoOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractGeoOperations.java index fe30c2e2b..1a6c8832d 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractGeoOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractGeoOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -36,10 +36,10 @@ * @author Yong.Teng * @since 2.0.0 */ -public abstract class AbstractGeoOperations - extends AbstractJedisRedisOperations implements GeoOperations { +public abstract class AbstractGeoOperations extends AbstractJedisRedisOperations + implements GeoOperations { - public AbstractGeoOperations(final C client){ + public AbstractGeoOperations(final C client) { super(client); } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractHashOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractHashOperations.java index fc7da9946..370b22df2 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractHashOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractHashOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractHyperLogLogOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractHyperLogLogOperations.java index 343f04206..b18e16f59 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractHyperLogLogOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractHyperLogLogOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractJedisRedisOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractJedisRedisOperations.java index 70cb7a0bb..5feabcbfe 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractJedisRedisOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractJedisRedisOperations.java @@ -19,13 +19,18 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.redis.client.jedis.JedisClusterClient; import com.buession.redis.client.jedis.JedisRedisClient; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.client.jedis.JedisStandaloneClient; import com.buession.redis.client.operations.AbstractRedisOperations; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; /** * Jedis Redis 命令操作抽象类 @@ -39,10 +44,50 @@ public abstract class AbstractJedisRedisOperations extends AbstractRedisOperations implements JedisRedisOperations { - protected C client; + public AbstractJedisRedisOperations(final C client) { + super(client); + } + + protected T notCommand(final JedisStandaloneClient client, final ProtocolCommand command, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand(client, command) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, command) + .run(args); + }else{ + return new JedisCommand(client, command) + .run(args); + } + } + + protected T notCommand(final JedisSentinelClient client, final ProtocolCommand command, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, command) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, command) + .run(args); + }else{ + return new JedisSentinelCommand(client, command) + .run(args); + } + } - public AbstractJedisRedisOperations(final C client){ - this.client = client; + protected T notCommand(final JedisClusterClient client, final ProtocolCommand command, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, command) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, command) + .run(args); + }else{ + return new JedisClusterCommand(client, command) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractKeyOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractKeyOperations.java index 0803df5ba..b3bd6ca1a 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractKeyOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractKeyOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractListOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractListOperations.java index 6d73452ab..515475265 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractListOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractListOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractPubSubOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractPubSubOperations.java index 437f04324..6042cec1d 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractPubSubOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractPubSubOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractScriptingOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractScriptingOperations.java index 28adec811..2d8568811 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractScriptingOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractScriptingOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractServerOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractServerOperations.java index 6a783ae3d..cc38065d9 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractServerOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractServerOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractSetOperations.java index ff373bd16..9f767580c 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractSetOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractSetOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractSortedSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractSortedSetOperations.java index 8fa3f3141..76e5db807 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractSortedSetOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractSortedSetOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractStreamOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractStreamOperations.java index a7055950c..36540e18a 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractStreamOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractStreamOperations.java @@ -19,12 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; import com.buession.core.collect.Maps; +import com.buession.core.converter.ListConverter; import com.buession.core.converter.MapConverter; import com.buession.lang.Status; import com.buession.redis.client.jedis.JedisRedisClient; @@ -42,7 +43,6 @@ import java.util.List; import java.util.Map; -import java.util.stream.Collectors; /** * Jedis Stream 命令操作抽象类 @@ -67,24 +67,23 @@ public Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId.. @Override public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash) { - return xAdd(SafeEncoder.encode(key), id, - Converters.BINARY_MAP_TO_STRING_MAP_CONVERTER.convert(hash)); + return xAdd(SafeEncoder.encode(key), id, Converters.mapBinaryToString().convert(hash)); } @Override public Map> xAutoClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, - final StreamEntryId start, final long count) { + final StreamEntryId start) { return xAutoClaim(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), - minIdleTime, start, count); + minIdleTime, start); } @Override public Map> xAutoClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, final int minIdleTime, - final StreamEntryId start) { + final StreamEntryId start, final long count) { return xAutoClaim(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), - minIdleTime, start); + minIdleTime, start, count); } @Override @@ -364,9 +363,9 @@ protected static List>> afterBianryXReadGroup( if(data == null){ return null; }else{ - final MapConverter, byte[], List> converter = new MapConverter<>( - SafeEncoder::encode, (value)->value); - return data.stream().map(converter::convert).collect(Collectors.toList()); + final ListConverter>, Map>> converter = + new ListConverter<>(new MapConverter<>(SafeEncoder::encode, (v)->v)); + return converter.convert(data); } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractStringOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractStringOperations.java index b0b82c34c..f8a47e79a 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractStringOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractStringOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractTransactionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractTransactionOperations.java index dd1da2fbb..4dc979947 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractTransactionOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/AbstractTransactionOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisBitMapOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisBitMapOperations.java index 0ce1d0acb..473c623b4 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisBitMapOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisBitMapOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -46,246 +46,378 @@ */ public final class JedisBitMapOperations extends AbstractBitMapOperations { - public JedisBitMapOperations(final JedisStandaloneClient client){ + public JedisBitMapOperations(final JedisStandaloneClient client) { super(client); } @Override - public Long bitCount(final String key){ + public Long bitCount(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key)) - .pipeline((cmd)->cmd.bitcount(key)) - .transaction((cmd)->cmd.bitcount(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } } @Override - public Long bitCount(final byte[] key){ + public Long bitCount(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key)) - .pipeline((cmd)->cmd.bitcount(key)) - .transaction((cmd)->cmd.bitcount(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } } @Override - public Long bitCount(final String key, final long start, final long end){ + public Long bitCount(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key, start, end)) - .pipeline((cmd)->cmd.bitcount(key, start, end)) - .transaction((cmd)->cmd.bitcount(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + } } @Override - public Long bitCount(final byte[] key, final long start, final long end){ + public Long bitCount(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key, start, end)) - .pipeline((cmd)->cmd.bitcount(key, start, end)) - .transaction((cmd)->cmd.bitcount(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + } } @Override - public Long bitCount(final String key, final long start, final long end, final BitCountOption bitCountOption){ + public Long bitCount(final String key, final long start, final long end, final BitCountOption bitCountOption) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end) .put("bitCountOption", bitCountOption); - final redis.clients.jedis.args.BitCountOption option = BitCountOptionConverter.INSTANCE.convert( + final redis.clients.jedis.args.BitCountOption option = (new BitCountOptionConverter()).convert( bitCountOption); - return new JedisCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key, start, end, option)) - .pipeline((cmd)->cmd.bitcount(key, start, end, option)) - .transaction((cmd)->cmd.bitcount(key, start, end, option)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end, option), + (v)->v) + .run(args); + } } @Override - public Long bitCount(final byte[] key, final long start, final long end, final BitCountOption bitCountOption){ + public Long bitCount(final byte[] key, final long start, final long end, final BitCountOption bitCountOption) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end) .put("bitCountOption", bitCountOption); - final redis.clients.jedis.args.BitCountOption option = BitCountOptionConverter.INSTANCE.convert( + final redis.clients.jedis.args.BitCountOption option = (new BitCountOptionConverter()).convert( bitCountOption); - return new JedisCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key, start, end, option)) - .pipeline((cmd)->cmd.bitcount(key, start, end, option)) - .transaction((cmd)->cmd.bitcount(key, start, end, option)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end, option), + (v)->v) + .run(args); + } } @Override - public List bitField(final String key, final BitFieldArgument argument){ + public List bitField(final String key, final BitFieldArgument argument) { final CommandArguments args = CommandArguments.create("key", key).put("arguments", argument); - final String[] arguments = BitFieldArgumentConverter.INSTANCE.convert(argument); - return new JedisCommand>(client, ProtocolCommand.BITFIELD) - .general((cmd)->cmd.bitfield(key, arguments)) - .pipeline((cmd)->cmd.bitfield(key, arguments)) - .transaction((cmd)->cmd.bitfield(key, arguments)) - .run(args); + final String[] arguments = (new BitFieldArgumentConverter()).convert(argument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITFIELD, (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + } } @Override - public List bitField(final byte[] key, final BitFieldArgument argument){ + public List bitField(final byte[] key, final BitFieldArgument argument) { final CommandArguments args = CommandArguments.create("key", key).put("arguments", argument); - final byte[][] arguments = SafeEncoder.encode(BitFieldArgumentConverter.INSTANCE.convert(argument)); - return new JedisCommand>(client, ProtocolCommand.BITFIELD) - .general((cmd)->cmd.bitfield(key, arguments)) - .pipeline((cmd)->cmd.bitfield(key, arguments)) - .transaction((cmd)->cmd.bitfield(key, arguments)) - .run(args); - } + final byte[][] arguments = SafeEncoder.encode((new BitFieldArgumentConverter()).convert(argument)); - @Deprecated - @Override - public List bitField(final String key, final String... arguments){ - final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); - return new JedisCommand>(client, ProtocolCommand.BITFIELD) - .general((cmd)->cmd.bitfield(key, arguments)) - .pipeline((cmd)->cmd.bitfield(key, arguments)) - .transaction((cmd)->cmd.bitfield(key, arguments)) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITFIELD, (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + } } - @Deprecated @Override - public List bitField(final byte[] key, final byte[]... arguments){ + public List bitFieldRo(final String key, final String... arguments) { final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); - return new JedisCommand>(client, ProtocolCommand.BITFIELD) - .general((cmd)->cmd.bitfield(key, arguments)) - .pipeline((cmd)->cmd.bitfield(key, arguments)) - .transaction((cmd)->cmd.bitfield(key, arguments)) - .run(args); - } - @Override - public List bitFieldRo(final String key, final String... arguments){ - final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); - return new JedisCommand>(client, ProtocolCommand.BITFIELD_RO) - .general((cmd)->cmd.bitfieldReadonly(key, arguments)) - .pipeline((cmd)->cmd.bitfieldReadonly(key, arguments)) - .transaction((cmd)->cmd.bitfieldReadonly(key, arguments)) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key, arguments), + (v)->v) + .run(args); + } } @Override - public List bitFieldRo(final byte[] key, final byte[]... arguments){ + public List bitFieldRo(final byte[] key, final byte[]... arguments) { final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); - return new JedisCommand>(client, ProtocolCommand.BITFIELD_RO) - .general((cmd)->cmd.bitfieldReadonly(key, arguments)) - .pipeline((cmd)->cmd.bitfieldReadonly(key, arguments)) - .transaction((cmd)->cmd.bitfieldReadonly(key, arguments)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITFIELD_RO, (cmd)->cmd.bitfieldReadonly(key, arguments), + (v)->v) + .run(args); + } } @Override - public Long bitOp(final BitOperation operation, final String destKey, final String... keys){ + public Long bitOp(final BitOperation operation, final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("operation", operation).put("destKey", destKey) .put("keys", (Object[]) keys); - final BitOP bitOP = BitOperationConverter.INSTANCE.convert(operation); - return new JedisCommand(client, ProtocolCommand.BITOP) - .general((cmd)->cmd.bitop(bitOP, destKey, keys)) - .pipeline((cmd)->cmd.bitop(bitOP, destKey, keys)) - .transaction((cmd)->cmd.bitop(bitOP, destKey, keys)) - .run(args); + final BitOP bitOP = (new BitOperationConverter()).convert(operation); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + } } @Override - public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys){ + public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("operation", operation).put("destKey", destKey) .put("keys", (Object[]) keys); - final BitOP bitOP = BitOperationConverter.INSTANCE.convert(operation); - return new JedisCommand(client, ProtocolCommand.BITOP) - .general((cmd)->cmd.bitop(bitOP, destKey, keys)) - .pipeline((cmd)->cmd.bitop(bitOP, destKey, keys)) - .transaction((cmd)->cmd.bitop(bitOP, destKey, keys)) - .run(args); + final BitOP bitOP = (new BitOperationConverter()).convert(operation); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + } } @Override - public Long bitPos(final String key, final boolean value){ + public Long bitPos(final String key, final boolean value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.BITPOS) - .general((cmd)->cmd.bitpos(key, value)) - .pipeline((cmd)->cmd.bitpos(key, value)) - .transaction((cmd)->cmd.bitpos(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } } @Override - public Long bitPos(final byte[] key, final boolean value){ + public Long bitPos(final byte[] key, final boolean value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.BITPOS) - .general((cmd)->cmd.bitpos(key, value)) - .pipeline((cmd)->cmd.bitpos(key, value)) - .transaction((cmd)->cmd.bitpos(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } } @Override - public Long bitPos(final String key, final boolean value, final long start, final long end){ + public Long bitPos(final String key, final boolean value, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("start", start) .put("end", end); - final BitPosParams params = new BitPosParams(start, end); - return new JedisCommand(client, ProtocolCommand.BITPOS) - .general((cmd)->cmd.bitpos(key, value, params)) - .pipeline((cmd)->cmd.bitpos(key, value, params)) - .transaction((cmd)->cmd.bitpos(key, value, params)) - .run(args); + final BitPosParams bitPosParams = new BitPosParams(start, end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value, bitPosParams), + (v)->v) + .run(args); + } } @Override - public Long bitPos(final byte[] key, final boolean value, final long start, final long end){ + public Long bitPos(final byte[] key, final boolean value, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("start", start) .put("end", end); - final BitPosParams params = new BitPosParams(start, end); - return new JedisCommand(client, ProtocolCommand.BITPOS) - .general((cmd)->cmd.bitpos(key, value, params)) - .pipeline((cmd)->cmd.bitpos(key, value, params)) - .transaction((cmd)->cmd.bitpos(key, value, params)) - .run(args); + final BitPosParams bitPosParams = new BitPosParams(start, end); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value, bitPosParams), + (v)->v) + .run(args); + } } @Override - public Boolean getBit(final String key, final long offset){ + public Boolean getBit(final String key, final long offset) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset); - return new JedisCommand(client, ProtocolCommand.GETBIT) - .general((cmd)->cmd.getbit(key, offset)) - .pipeline((cmd)->cmd.getbit(key, offset)) - .transaction((cmd)->cmd.getbit(key, offset)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + } } @Override - public Boolean getBit(final byte[] key, final long offset){ + public Boolean getBit(final byte[] key, final long offset) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset); - return new JedisCommand(client, ProtocolCommand.GETBIT) - .general((cmd)->cmd.getbit(key, offset)) - .pipeline((cmd)->cmd.getbit(key, offset)) - .transaction((cmd)->cmd.getbit(key, offset)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + } } @Override - public Boolean setBit(final String key, final long offset, final boolean value){ + public Boolean setBit(final String key, final long offset, final boolean value) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); - return new JedisCommand(client, ProtocolCommand.SETBIT) - .general((cmd)->cmd.setbit(key, offset, value)) - .pipeline((cmd)->cmd.setbit(key, offset, value)) - .transaction((cmd)->cmd.setbit(key, offset, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SETBIT, (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + } } @Override - public Boolean setBit(final byte[] key, final long offset, final boolean value){ + public Boolean setBit(final byte[] key, final long offset, final boolean value) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); - return new JedisCommand(client, ProtocolCommand.SETBIT) - .general((cmd)->cmd.setbit(key, offset, value)) - .pipeline((cmd)->cmd.setbit(key, offset, value)) - .transaction((cmd)->cmd.setbit(key, offset, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SETBIT, (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterBitMapOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterBitMapOperations.java index 84c691649..114710163 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterBitMapOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterBitMapOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -46,246 +46,401 @@ */ public final class JedisClusterBitMapOperations extends AbstractBitMapOperations { - public JedisClusterBitMapOperations(final JedisClusterClient client){ + public JedisClusterBitMapOperations(final JedisClusterClient client) { super(client); } @Override - public Long bitCount(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key)) - .pipeline((cmd)->cmd.bitcount(key)) - .transaction((cmd)->cmd.bitcount(key)) - .run(args); + public Long bitCount(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } } @Override - public Long bitCount(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key)) - .pipeline((cmd)->cmd.bitcount(key)) - .transaction((cmd)->cmd.bitcount(key)) - .run(args); + public Long bitCount(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } } @Override - public Long bitCount(final String key, final long start, final long end){ + public Long bitCount(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key, start, end)) - .pipeline((cmd)->cmd.bitcount(key, start, end)) - .transaction((cmd)->cmd.bitcount(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + } } @Override - public Long bitCount(final byte[] key, final long start, final long end){ + public Long bitCount(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key, start, end)) - .pipeline((cmd)->cmd.bitcount(key, start, end)) - .transaction((cmd)->cmd.bitcount(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + } } @Override - public Long bitCount(final String key, final long start, final long end, final BitCountOption bitCountOption){ + public Long bitCount(final String key, final long start, final long end, final BitCountOption bitCountOption) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end) .put("bitCountOption", bitCountOption); - final redis.clients.jedis.args.BitCountOption option = BitCountOptionConverter.INSTANCE.convert( + final redis.clients.jedis.args.BitCountOption option = (new BitCountOptionConverter()).convert( bitCountOption); - return new JedisClusterCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key, start, end, option)) - .pipeline((cmd)->cmd.bitcount(key, start, end, option)) - .transaction((cmd)->cmd.bitcount(key, start, end, option)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), + (v)->v) + .run(args); + } } @Override - public Long bitCount(final byte[] key, final long start, final long end, final BitCountOption bitCountOption){ + public Long bitCount(final byte[] key, final long start, final long end, final BitCountOption bitCountOption) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end) .put("bitCountOption", bitCountOption); - final redis.clients.jedis.args.BitCountOption option = BitCountOptionConverter.INSTANCE.convert( + final redis.clients.jedis.args.BitCountOption option = (new BitCountOptionConverter()).convert( bitCountOption); - return new JedisClusterCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key, start, end, option)) - .pipeline((cmd)->cmd.bitcount(key, start, end, option)) - .transaction((cmd)->cmd.bitcount(key, start, end, option)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), + (v)->v) + .run(args); + } } @Override - public List bitField(final String key, final BitFieldArgument argument){ + public List bitField(final String key, final BitFieldArgument argument) { final CommandArguments args = CommandArguments.create("key", key).put("arguments", argument); - final String[] arguments = BitFieldArgumentConverter.INSTANCE.convert(argument); - return new JedisClusterCommand>(client, ProtocolCommand.BITFIELD) - .general((cmd)->cmd.bitfield(key, arguments)) - .pipeline((cmd)->cmd.bitfield(key, arguments)) - .transaction((cmd)->cmd.bitfield(key, arguments)) - .run(args); + final String[] arguments = (new BitFieldArgumentConverter()).convert(argument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITFIELD, + (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITFIELD, + (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + } } @Override - public List bitField(final byte[] key, final BitFieldArgument argument){ + public List bitField(final byte[] key, final BitFieldArgument argument) { final CommandArguments args = CommandArguments.create("key", key).put("arguments", argument); - final byte[][] arguments = SafeEncoder.encode(BitFieldArgumentConverter.INSTANCE.convert(argument)); - return new JedisClusterCommand>(client, ProtocolCommand.BITFIELD) - .general((cmd)->cmd.bitfield(key, arguments)) - .pipeline((cmd)->cmd.bitfield(key, arguments)) - .transaction((cmd)->cmd.bitfield(key, arguments)) - .run(args); - } + final byte[][] arguments = SafeEncoder.encode((new BitFieldArgumentConverter()).convert(argument)); - @Deprecated - @Override - public List bitField(final String key, final String... arguments){ - final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); - return new JedisClusterCommand>(client, ProtocolCommand.BITFIELD) - .general((cmd)->cmd.bitfield(key, arguments)) - .pipeline((cmd)->cmd.bitfield(key, arguments)) - .transaction((cmd)->cmd.bitfield(key, arguments)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITFIELD, + (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITFIELD, + (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + } } - @Deprecated @Override - public List bitField(final byte[] key, final byte[]... arguments){ + public List bitFieldRo(final String key, final String... arguments) { final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); - return new JedisClusterCommand>(client, ProtocolCommand.BITFIELD) - .general((cmd)->cmd.bitfield(key, arguments)) - .pipeline((cmd)->cmd.bitfield(key, arguments)) - .transaction((cmd)->cmd.bitfield(key, arguments)) - .run(args); - } - @Override - public List bitFieldRo(final String key, final String... arguments){ - final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); - return new JedisClusterCommand>(client, ProtocolCommand.BITFIELD_RO) - .general((cmd)->cmd.bitfieldReadonly(key, arguments)) - .pipeline((cmd)->cmd.bitfieldReadonly(key, arguments)) - .transaction((cmd)->cmd.bitfieldReadonly(key, arguments)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), + (v)->v) + .run(args); + } } @Override - public List bitFieldRo(final byte[] key, final byte[]... arguments){ + public List bitFieldRo(final byte[] key, final byte[]... arguments) { final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); - return new JedisClusterCommand>(client, ProtocolCommand.BITFIELD_RO) - .general((cmd)->cmd.bitfieldReadonly(key, arguments)) - .pipeline((cmd)->cmd.bitfieldReadonly(key, arguments)) - .transaction((cmd)->cmd.bitfieldReadonly(key, arguments)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), + (v)->v) + .run(args); + } } @Override - public Long bitOp(final BitOperation operation, final String destKey, final String... keys){ + public Long bitOp(final BitOperation operation, final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("operation", operation).put("destKey", destKey) .put("keys", (Object[]) keys); - final BitOP bitOP = BitOperationConverter.INSTANCE.convert(operation); - return new JedisClusterCommand(client, ProtocolCommand.BITOP) - .general((cmd)->cmd.bitop(bitOP, destKey, keys)) - .pipeline((cmd)->cmd.bitop(bitOP, destKey, keys)) - .transaction((cmd)->cmd.bitop(bitOP, destKey, keys)) - .run(args); + final BitOP bitOP = (new BitOperationConverter()).convert(operation); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITOP, + (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITOP, + (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys){ + public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("operation", operation).put("destKey", destKey) .put("keys", (Object[]) keys); - final BitOP bitOP = BitOperationConverter.INSTANCE.convert(operation); - return new JedisClusterCommand(client, ProtocolCommand.BITOP) - .general((cmd)->cmd.bitop(bitOP, destKey, keys)) - .pipeline((cmd)->cmd.bitop(bitOP, destKey, keys)) - .transaction((cmd)->cmd.bitop(bitOP, destKey, keys)) - .run(args); + final BitOP bitOP = (new BitOperationConverter()).convert(operation); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITOP, + (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITOP, + (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long bitPos(final String key, final boolean value){ + public Long bitPos(final String key, final boolean value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.BITPOS) - .general((cmd)->cmd.bitpos(key, value)) - .pipeline((cmd)->cmd.bitpos(key, value)) - .transaction((cmd)->cmd.bitpos(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } } @Override - public Long bitPos(final byte[] key, final boolean value){ + public Long bitPos(final byte[] key, final boolean value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.BITPOS) - .general((cmd)->cmd.bitpos(key, value)) - .pipeline((cmd)->cmd.bitpos(key, value)) - .transaction((cmd)->cmd.bitpos(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } } @Override - public Long bitPos(final String key, final boolean value, final long start, final long end){ + public Long bitPos(final String key, final boolean value, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("start", start) .put("end", end); - final BitPosParams params = new BitPosParams(start, end); - return new JedisClusterCommand(client, ProtocolCommand.BITPOS) - .general((cmd)->cmd.bitpos(key, value, params)) - .pipeline((cmd)->cmd.bitpos(key, value, params)) - .transaction((cmd)->cmd.bitpos(key, value, params)) - .run(args); + final BitPosParams bitPosParams = new BitPosParams(start, end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), + (v)->v) + .run(args); + } } @Override - public Long bitPos(final byte[] key, final boolean value, final long start, final long end){ + public Long bitPos(final byte[] key, final boolean value, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("start", start) .put("end", end); - final BitPosParams params = new BitPosParams(start, end); - return new JedisClusterCommand(client, ProtocolCommand.BITPOS) - .general((cmd)->cmd.bitpos(key, value, params)) - .pipeline((cmd)->cmd.bitpos(key, value, params)) - .transaction((cmd)->cmd.bitpos(key, value, params)) - .run(args); + final BitPosParams bitPosParams = new BitPosParams(start, end); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + } } @Override - public Boolean getBit(final String key, final long offset){ + public Boolean getBit(final String key, final long offset) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset); - return new JedisClusterCommand(client, ProtocolCommand.GETBIT) - .general((cmd)->cmd.getbit(key, offset)) - .pipeline((cmd)->cmd.getbit(key, offset)) - .transaction((cmd)->cmd.getbit(key, offset)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + } } @Override - public Boolean getBit(final byte[] key, final long offset){ + public Boolean getBit(final byte[] key, final long offset) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset); - return new JedisClusterCommand(client, ProtocolCommand.GETBIT) - .general((cmd)->cmd.getbit(key, offset)) - .pipeline((cmd)->cmd.getbit(key, offset)) - .transaction((cmd)->cmd.getbit(key, offset)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + } } @Override - public Boolean setBit(final String key, final long offset, final boolean value){ + public Boolean setBit(final String key, final long offset, final boolean value) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.SETBIT) - .general((cmd)->cmd.setbit(key, offset, value)) - .pipeline((cmd)->cmd.setbit(key, offset, value)) - .transaction((cmd)->cmd.setbit(key, offset, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SETBIT, + (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SETBIT, + (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + } } @Override - public Boolean setBit(final byte[] key, final long offset, final boolean value){ + public Boolean setBit(final byte[] key, final long offset, final boolean value) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.SETBIT) - .general((cmd)->cmd.setbit(key, offset, value)) - .pipeline((cmd)->cmd.setbit(key, offset, value)) - .transaction((cmd)->cmd.setbit(key, offset, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SETBIT, + (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SETBIT, + (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterClusterOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterClusterOperations.java index 9329e4c4c..058097b31 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterClusterOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterClusterOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -47,180 +47,408 @@ */ public final class JedisClusterClusterOperations extends AbstractClusterOperations { - public JedisClusterClusterOperations(final JedisClusterClient client){ + public JedisClusterClusterOperations(final JedisClusterClient client) { super(client); } @Override - public String clusterMyId(){ - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_MY_ID) - .run(); + public String clusterMyId() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLUSTER_MY_ID) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLUSTER_MY_ID) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_MY_ID) + .run(); + } } @Override - public Status clusterAddSlots(final int... slots){ + public Status clusterAddSlots(final int... slots) { final CommandArguments args = CommandArguments.create("slots", slots); - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_ADDSLOTS) - .run(args); - } - @Override - public List clusterSlots(){ - return new JedisClusterCommand>(client, ProtocolCommand.CLUSTER_SLOTS) - .run(); + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLUSTER_ADDSLOTS) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLUSTER_ADDSLOTS) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_ADDSLOTS) + .run(args); + } } @Override - public Integer clusterCountFailureReports(final String nodeId){ - final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) - .run(args); + public List clusterSlots() { + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_SLOTS) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_SLOTS) + .run(); + }else{ + return new JedisClusterCommand, List>(client, + ProtocolCommand.CLUSTER_SLOTS) + .run(); + } } @Override - public Integer clusterCountFailureReports(final byte[] nodeId){ + public Integer clusterCountFailureReports(final String nodeId) { final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, + ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, + ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) + .run(args); + } } @Override - public Long clusterCountKeysInSlot(final int slot){ + public Long clusterCountKeysInSlot(final int slot) { final CommandArguments args = CommandArguments.create("slot", slot); - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT) + .run(args); + } } @Override - public Status clusterDelSlots(final int... slots){ + public Status clusterDelSlots(final int... slots) { final CommandArguments args = CommandArguments.create("slots", slots); - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_DELSLOTS).run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLUSTER_DELSLOTS) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLUSTER_DELSLOTS) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_DELSLOTS) + .run(args); + } } @Override - public Status clusterFlushSlots(){ - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_FLUSHSLOTS) - .run(); + public Status clusterFlushSlots() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLUSTER_FLUSHSLOTS) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLUSTER_FLUSHSLOTS) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_FLUSHSLOTS) + .run(); + } } @Override - public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption){ + public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption) { final CommandArguments args = CommandArguments.create("clusterFailoverOption", clusterFailoverOption); - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_FAILOVER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLUSTER_FAILOVER) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLUSTER_FAILOVER) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_FAILOVER) + .run(args); + } } @Override - public Status clusterForget(final String nodeId){ + public Status clusterForget(final String nodeId) { final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_FORGET) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLUSTER_FORGET) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLUSTER_FORGET) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_FORGET) + .run(args); + } } @Override - public List clusterGetKeysInSlot(final int slot, final long count){ + public List clusterGetKeysInSlot(final int slot, final long count) { final CommandArguments args = CommandArguments.create("slot", slot).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else{ + return new JedisClusterCommand, List>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + } } @Override - public Long clusterKeySlot(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) - .run(args); + public Long clusterKeySlot(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + } } @Override - public ClusterInfo clusterInfo(){ - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_INFO) - .run(); + public ClusterInfo clusterInfo() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLUSTER_INFO) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLUSTER_INFO) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_INFO) + .run(); + } } @Override - public Status clusterMeet(final String ip, final int port){ + public Status clusterMeet(final String ip, final int port) { final CommandArguments args = CommandArguments.create("ip", ip).put("port", port); - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_MEET) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLUSTER_MEET) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLUSTER_MEET) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_MEET) + .run(args); + } } @Override - public List clusterNodes(){ - return new JedisClusterCommand>(client, ProtocolCommand.CLUSTER_NODES) - .run(); + public List clusterNodes() { + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_NODES) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_NODES) + .run(); + }else{ + return new JedisClusterCommand, List>(client, + ProtocolCommand.CLUSTER_NODES) + .run(); + } } @Override - public List clusterSlaves(final String nodeId){ + public List clusterSlaves(final String nodeId) { final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisClusterCommand>(client, ProtocolCommand.CLUSTER_SLAVES) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_SLAVES) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_SLAVES) + .run(args); + }else{ + return new JedisClusterCommand, List>(client, + ProtocolCommand.CLUSTER_SLAVES) + .run(args); + } } @Override - public List clusterReplicas(final String nodeId){ + public List clusterReplicas(final String nodeId) { final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisClusterCommand>(client, ProtocolCommand.CLUSTER_REPLICAS) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_REPLICAS) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_REPLICAS) + .run(args); + }else{ + return new JedisClusterCommand, List>(client, + ProtocolCommand.CLUSTER_REPLICAS) + .run(args); + } } @Override - public Status clusterReplicate(final String nodeId){ + public Status clusterReplicate(final String nodeId) { final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_REPLICATE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLUSTER_REPLICATE) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLUSTER_REPLICATE) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_REPLICATE) + .run(args); + } } @Override - public Status clusterReset(final ClusterResetOption clusterResetOption){ + public Status clusterReset(final ClusterResetOption clusterResetOption) { final CommandArguments args = CommandArguments.create("clusterResetOption", clusterResetOption); - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_RESET) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLUSTER_RESET) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLUSTER_RESET) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_RESET) + .run(args); + } } @Override - public Status clusterSaveConfig(){ - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_SAVECONFIG) - .run(); + public Status clusterSaveConfig() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLUSTER_SAVECONFIG) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLUSTER_SAVECONFIG) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_SAVECONFIG) + .run(); + } } @Override - public Status clusterSetConfigEpoch(final long configEpoch){ + public Status clusterSetConfigEpoch(final long configEpoch) { final CommandArguments args = CommandArguments.create("configEpoch", configEpoch); - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH) + .run(args); + } } @Override - public KeyValue clusterBumpEpoch(){ - return new JedisClusterCommand>(client, ProtocolCommand.CLUSTER_BUMPEPOCH) - .run(); + public KeyValue clusterBumpEpoch() { + if(isPipeline()){ + return new JedisClusterPipelineCommand, KeyValue>(client, + ProtocolCommand.CLUSTER_BUMPEPOCH) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, KeyValue>( + client, ProtocolCommand.CLUSTER_BUMPEPOCH) + .run(); + }else{ + return new JedisClusterCommand, KeyValue>( + client, ProtocolCommand.CLUSTER_BUMPEPOCH) + .run(); + } } @Override - public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId){ + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId) { final CommandArguments args = CommandArguments.create("slot", slot).put("setSlotOption", setSlotOption) .put("nodeId", nodeId); - return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_SETSLOT) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLUSTER_SETSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLUSTER_SETSLOT) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLUSTER_SETSLOT) + .run(args); + } } @Override - public Status asking(){ - return new JedisClusterCommand(client, ProtocolCommand.ASKING) - .run(); + public Status asking() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.ASKING) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.ASKING) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.ASKING) + .run(); + } } @Override - public Status readWrite(){ - return new JedisClusterCommand(client, ProtocolCommand.READWRITE) - .run(); + public Status readWrite() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.READWRITE) + .run(); + }else if(isTransaction()){ + return new JedisClusterCommand(client, ProtocolCommand.READWRITE) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.READWRITE) + .run(); + } } @Override - public Status readOnly(){ - return new JedisClusterCommand(client, ProtocolCommand.READONLY) - .run(); + public Status readOnly() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.READONLY) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.READONLY) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.READONLY) + .run(); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterConnectionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterConnectionOperations.java index d68586ea3..2fc1f4d21 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterConnectionOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterConnectionOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -32,6 +32,7 @@ import com.buession.redis.core.ClientUnblockType; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.response.PingResultConverter; import java.util.List; @@ -48,147 +49,325 @@ public JedisClusterConnectionOperations(final JedisClusterClient client) { @Override public Status auth(final String user, final String password) { final CommandArguments args = CommandArguments.create("user", user).put("password", password); - return new JedisClusterCommand(client, ProtocolCommand.AUTH) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.AUTH) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.AUTH) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.AUTH) + .run(args); + } } @Override public Status auth(final String password) { - final CommandArguments args = CommandArguments.create("password", password); - return new JedisClusterCommand(client, ProtocolCommand.AUTH) - .run(args); + final CommandArguments args = CommandArguments.create(password); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.AUTH) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.AUTH) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.AUTH) + .run(args); + } } @Override public String echo(final String str) { - final CommandArguments args = CommandArguments.create("str", str); - return new JedisClusterCommand(client, ProtocolCommand.ECHO) - .run(args); + final CommandArguments args = CommandArguments.create(str); + return echo(args); } @Override public byte[] echo(final byte[] str) { - final CommandArguments args = CommandArguments.create("str", str); - return new JedisClusterCommand(client, ProtocolCommand.ECHO) - .run(args); + final CommandArguments args = CommandArguments.create(str); + return echo(args); } @Override public Status ping() { - return new JedisClusterCommand(client, ProtocolCommand.PING) - .run(); + final PingResultConverter pingResultConverter = new PingResultConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.PING) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.PING) + .run(); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PING, (cmd)->cmd.ping(), pingResultConverter) + .run(); + } } @Override public Status reset() { - return new JedisClusterCommand(client, ProtocolCommand.RESET) - .run(); + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.RESET) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.RESET) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.RESET) + .run(); + } } @Override public Status quit() { - return new JedisClusterCommand(client, ProtocolCommand.QUIT) - .run(); + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.QUIT) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.QUIT) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.QUIT) + .run(); + } } @Override public Status select(final int db) { - final CommandArguments args = CommandArguments.create("db", db); - return new JedisClusterCommand(client, ProtocolCommand.SELECT) - .run(args); + final CommandArguments args = CommandArguments.create(db); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.SELECT) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.SELECT) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.SELECT) + .run(args); + } } @Override public Status clientCaching(final boolean isYes) { - final CommandArguments args = CommandArguments.create("isYes", isYes); - return new JedisClusterCommand(client, ProtocolCommand.CLIENT_CACHING) - .run(args); + final CommandArguments args = CommandArguments.create(isYes); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + } } @Override public Long clientId() { - return new JedisClusterCommand(client, ProtocolCommand.CLIENT_ID) - .run(); + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLIENT_ID) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLIENT_ID) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLIENT_ID) + .run(); + } } @Override public Status clientSetName(final String name) { - final CommandArguments args = CommandArguments.create("name", name); - return new JedisClusterCommand(client, ProtocolCommand.CLIENT_SETNAME) - .run(args); + final CommandArguments args = CommandArguments.create(name); + return clientSetName(args); } @Override public Status clientSetName(final byte[] name) { - final CommandArguments args = CommandArguments.create("name", name); - return new JedisClusterCommand(client, ProtocolCommand.CLIENT_SETNAME) - .run(args); + final CommandArguments args = CommandArguments.create(name); + return clientSetName(args); } @Override public String clientGetName() { - return new JedisClusterCommand(client, ProtocolCommand.CLIENT_GETNAME) - .run(); + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLIENT_GETNAME) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLIENT_GETNAME) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLIENT_GETNAME) + .run(); + } } @Override public Integer clientGetRedir() { - return new JedisClusterCommand(client, ProtocolCommand.CLIENT_GETREDIR) - .run(); + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + } } @Override public List clientList() { - return new JedisClusterCommand>(client, ProtocolCommand.CLIENT_LIST) - .run(); + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, ProtocolCommand.CLIENT_LIST) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, ProtocolCommand.CLIENT_LIST) + .run(); + }else{ + return new JedisClusterCommand, List>(client, ProtocolCommand.CLIENT_LIST) + .run(); + } } @Override public List clientList(final ClientType clientType) { final CommandArguments args = CommandArguments.create("clientType", clientType); - return new JedisClusterCommand>(client, ProtocolCommand.CLIENT_LIST) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, ProtocolCommand.CLIENT_LIST) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, ProtocolCommand.CLIENT_LIST) + .run(args); + }else{ + return new JedisClusterCommand, List>(client, ProtocolCommand.CLIENT_LIST) + .run(args); + } } @Override public Client clientInfo() { - return new JedisClusterCommand(client, ProtocolCommand.CLIENT_INFO) - .run(); + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLIENT_LIST) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLIENT_LIST) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLIENT_LIST) + .run(); + } } @Override public Status clientPause(final int timeout) { final CommandArguments args = CommandArguments.create("timeout", timeout); - return new JedisClusterCommand(client, ProtocolCommand.CLIENT_PAUSE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLIENT_PAUSE) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLIENT_PAUSE) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLIENT_PAUSE) + .run(args); + } } @Override public Status clientReply(final ClientReply option) { - final CommandArguments args = CommandArguments.create("option", option); - return new JedisClusterCommand(client, ProtocolCommand.CLIENT_REPLY) - .run(args); + final CommandArguments args = CommandArguments.create(option); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + } } @Override public Status clientKill(final String host, final int port) { final CommandArguments args = CommandArguments.create("host", host).put("port", port); - return new JedisClusterCommand(client, ProtocolCommand.CLIENT_PAUSE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLIENT_KILL) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLIENT_KILL) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLIENT_KILL) + .run(args); + } } @Override public Status clientUnblock(final int clientId) { final CommandArguments args = CommandArguments.create("clientId", clientId); - return new JedisClusterCommand(client, ProtocolCommand.CLIENT_UNBLOCK) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLIENT_UNBLOCK) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLIENT_UNBLOCK) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLIENT_UNBLOCK) + .run(args); + } } @Override public Status clientUnblock(final int clientId, final ClientUnblockType type) { final CommandArguments args = CommandArguments.create("clientId", clientId).put("type", type); - return new JedisClusterCommand(client, ProtocolCommand.CLIENT_UNBLOCK) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLIENT_UNBLOCK) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLIENT_UNBLOCK) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLIENT_UNBLOCK) + .run(args); + } + } + + private V echo(final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.ECHO) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.ECHO) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.ECHO) + .run(args); + } + } + + private Status clientSetName(final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CLIENT_SETNAME) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CLIENT_SETNAME) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CLIENT_SETNAME) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterGenericOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterGenericOperations.java new file mode 100644 index 000000000..ac43d4efd --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterGenericOperations.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.KeyValue; +import com.buession.redis.client.jedis.JedisClusterClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.jedis.response.KeyValueConverter; + +/** + * Jedis 集群模式一般命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisClusterGenericOperations extends AbstractGenericOperations { + + public JedisClusterGenericOperations(final JedisClusterClient client) { + super(client); + } + + @Override + public Long wait(final int replicas, final int timeout) { + final CommandArguments args = CommandArguments.create(replicas).add(timeout); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.WAIT, + (cmd)->cmd.waitReplicas(replicas, timeout), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.WAIT, + (cmd)->cmd.waitReplicas(replicas, timeout), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.WAIT, + (cmd)->cmd.waitReplicas((String) null, replicas, timeout), (v)->v) + .run(args); + } + } + + @Override + public KeyValue waitOf(final int locals, final int replicas, final int timeout) { + final CommandArguments args = CommandArguments.create(locals).add(replicas).add(timeout); + final KeyValueConverter keyValueConverter = new KeyValueConverter<>((k)->k, (v)->v); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.WAITOF, + (cmd)->cmd.waitAOF((String) null, locals, replicas, timeout), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.WAITOF, + (cmd)->cmd.waitAOF((String) null, locals, replicas, timeout), keyValueConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.WAITOF, + (cmd)->cmd.waitAOF((String) null, locals, replicas, timeout), keyValueConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterGeoOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterGeoOperations.java index 99d16fe1f..0a84dbfc0 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterGeoOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterGeoOperations.java @@ -19,11 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.core.converter.ListConverter; import com.buession.lang.Geo; import com.buession.redis.client.jedis.JedisClusterClient; import com.buession.redis.core.GeoRadius; @@ -31,12 +32,13 @@ import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; import com.buession.redis.core.internal.convert.jedis.params.GeoConverter; -import com.buession.redis.core.internal.convert.jedis.params.GeoRadiusArgumentConverter; import com.buession.redis.core.internal.convert.jedis.params.GeoUnitConverter; import com.buession.redis.core.internal.convert.jedis.response.GeoCoordinateConverter; import com.buession.redis.core.internal.convert.jedis.response.GeoRadiusResponseConverter; +import com.buession.redis.core.internal.jedis.JedisGeoRadiusParam; import redis.clients.jedis.GeoCoordinate; import redis.clients.jedis.params.GeoRadiusParam; +import redis.clients.jedis.resps.GeoRadiusResponse; import java.util.List; import java.util.Map; @@ -57,132 +59,240 @@ public JedisClusterGeoOperations(final JedisClusterClient client) { public Long geoAdd(final String key, final String member, final double longitude, final double latitude) { final CommandArguments args = CommandArguments.create("key", key).put("member", member) .put("longitude", longitude).put("latitude", latitude); - return new JedisClusterCommand(client, ProtocolCommand.GEOADD) - .general((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .pipeline((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .transaction((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, longitude, latitude, + member), (v)->v) + .run(args); + } } @Override public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude) { final CommandArguments args = CommandArguments.create("key", key).put("member", member) .put("longitude", longitude).put("latitude", latitude); - return new JedisClusterCommand(client, ProtocolCommand.GEOADD) - .general((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .pipeline((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .transaction((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, longitude, latitude, + member), (v)->v) + .run(args); + } } @Override public Long geoAdd(final String key, final Map memberCoordinates) { final CommandArguments args = CommandArguments.create("key", key).put("memberCoordinates", memberCoordinates); - final Map geoCoordinates = GeoConverter.STRING_MAP_CONVERTER.convert( + final Map geoCoordinates = GeoConverter.mapConverter().convert( memberCoordinates); - return new JedisClusterCommand(client, ProtocolCommand.GEOADD) - .general((cmd)->cmd.geoadd(key, geoCoordinates)) - .pipeline((cmd)->cmd.geoadd(key, geoCoordinates)) - .transaction((cmd)->cmd.geoadd(key, geoCoordinates)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, geoCoordinates), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, geoCoordinates), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + } } @Override public Long geoAdd(final byte[] key, final Map memberCoordinates) { final CommandArguments args = CommandArguments.create("key", key).put("memberCoordinates", memberCoordinates); - final Map geoCoordinates = GeoConverter.BINARY_MAP_CONVERTER.convert( + final Map geoCoordinates = GeoConverter.mapConverter().convert( memberCoordinates); - return new JedisClusterCommand(client, ProtocolCommand.GEOADD) - .general((cmd)->cmd.geoadd(key, geoCoordinates)) - .pipeline((cmd)->cmd.geoadd(key, geoCoordinates)) - .transaction((cmd)->cmd.geoadd(key, geoCoordinates)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, geoCoordinates), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, geoCoordinates), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + } } @Override public List geoHash(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisClusterCommand>(client, ProtocolCommand.GEOHASH) - .general((cmd)->cmd.geohash(key, members)) - .pipeline((cmd)->cmd.geohash(key, members)) - .transaction((cmd)->cmd.geohash(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEOHASH, + (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + } } @Override public List geoHash(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisClusterCommand>(client, ProtocolCommand.GEOHASH) - .general((cmd)->cmd.geohash(key, members)) - .pipeline((cmd)->cmd.geohash(key, members)) - .transaction((cmd)->cmd.geohash(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEOHASH, + (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + } } @Override public List geoPos(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisClusterCommand>(client, ProtocolCommand.GEOPOS) - .general((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .run(args); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } } @Override public List geoPos(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisClusterCommand>(client, ProtocolCommand.GEOPOS) - .general((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .run(args); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } } @Override public Double geoDist(final String key, final String member1, final String member2) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2); - return new JedisClusterCommand(client, ProtocolCommand.GEODIST) - .general((cmd)->cmd.geodist(key, member1, member2)) - .pipeline((cmd)->cmd.geodist(key, member1, member2)) - .transaction((cmd)->cmd.geodist(key, member1, member2)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEODIST, (cmd)->cmd.geodist(key, member1, member2), + (v)->v) + .run(args); + } } @Override public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2); - return new JedisClusterCommand(client, ProtocolCommand.GEODIST) - .general((cmd)->cmd.geodist(key, member1, member2)) - .pipeline((cmd)->cmd.geodist(key, member1, member2)) - .transaction((cmd)->cmd.geodist(key, member1, member2)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEODIST, (cmd)->cmd.geodist(key, member1, member2), + (v)->v) + .run(args); + } } @Override public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisClusterCommand(client, ProtocolCommand.GEODIST) - .general((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .pipeline((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .transaction((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + } } @Override public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisClusterCommand(client, ProtocolCommand.GEODIST) - .general((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .pipeline((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .transaction((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + } } @Override @@ -190,15 +300,23 @@ public List geoRadius(final String key, final double longitude, final final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUS) - .general((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override @@ -206,15 +324,23 @@ public List geoRadius(final byte[] key, final double longitude, final final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUS) - .general((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override @@ -224,16 +350,27 @@ public List geoRadius(final String key, final double longitude, final final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUS) - .general((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override @@ -243,16 +380,27 @@ public List geoRadius(final byte[] key, final double longitude, final final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUS) - .general((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override @@ -260,15 +408,26 @@ public List geoRadiusRo(final String key, final double longitude, fin final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUS_RO) - .general((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + } } @Override @@ -276,15 +435,26 @@ public List geoRadiusRo(final byte[] key, final double longitude, fin final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUS_RO) - .general((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + } } @Override @@ -294,16 +464,27 @@ public List geoRadiusRo(final String key, final double longitude, fin final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUS_RO) - .general((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override @@ -313,16 +494,27 @@ public List geoRadiusRo(final byte[] key, final double longitude, fin final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUS_RO) - .general((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override @@ -330,15 +522,23 @@ public List geoRadiusByMember(final String key, final String member, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override @@ -346,15 +546,23 @@ public List geoRadiusByMember(final byte[] key, final byte[] member, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override @@ -362,16 +570,27 @@ public List geoRadiusByMember(final String key, final String member, final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override @@ -379,16 +598,27 @@ public List geoRadiusByMember(final byte[] key, final byte[] member, final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override @@ -396,15 +626,23 @@ public List geoRadiusByMemberRo(final String key, final String member final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override @@ -412,15 +650,23 @@ public List geoRadiusByMemberRo(final byte[] key, final byte[] member final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override @@ -428,16 +674,27 @@ public List geoRadiusByMemberRo(final String key, final String member final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override @@ -445,16 +702,27 @@ public List geoRadiusByMemberRo(final byte[] key, final byte[] member final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisClusterCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterHashOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterHashOperations.java index b97cb75e5..929347d19 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterHashOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterHashOperations.java @@ -19,20 +19,20 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.core.converter.ListMapEntryMapConverter; import com.buession.lang.Status; import com.buession.redis.client.jedis.JedisClusterClient; import com.buession.redis.core.ScanResult; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; import com.buession.redis.core.internal.jedis.JedisScanParams; +import redis.clients.jedis.params.ScanParams; import java.util.List; import java.util.Map; @@ -46,461 +46,751 @@ */ public final class JedisClusterHashOperations extends AbstractHashOperations { - public JedisClusterHashOperations(final JedisClusterClient client){ + public JedisClusterHashOperations(final JedisClusterClient client) { super(client); } @Override - public Long hDel(final String key, final String... fields){ - final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); - return new JedisClusterCommand(client, ProtocolCommand.HDEL) - .general((cmd)->cmd.hdel(key, fields)) - .pipeline((cmd)->cmd.hdel(key, fields)) - .transaction((cmd)->cmd.hdel(key, fields)) - .run(args); - } + public Long hDel(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); - @Override - public Long hDel(final byte[] key, final byte[]... fields){ - final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); - return new JedisClusterCommand(client, ProtocolCommand.HDEL) - .general((cmd)->cmd.hdel(key, fields)) - .pipeline((cmd)->cmd.hdel(key, fields)) - .transaction((cmd)->cmd.hdel(key, fields)) - .run(args); - } + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } + } + + @Override + public Long hDel(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create(key).add(fields); - @Override - public Boolean hExists(final String key, final String field){ - final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisClusterCommand(client, ProtocolCommand.HEXISTS) - .general((cmd)->cmd.hexists(key, field)) - .pipeline((cmd)->cmd.hexists(key, field)) - .transaction((cmd)->cmd.hexists(key, field)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } + } + + @Override + public Boolean hExists(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } } @Override - public Boolean hExists(final byte[] key, final byte[] field){ - final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisClusterCommand(client, ProtocolCommand.HEXISTS) - .general((cmd)->cmd.hexists(key, field)) - .pipeline((cmd)->cmd.hexists(key, field)) - .transaction((cmd)->cmd.hexists(key, field)) - .run(args); - } + public Boolean hExists(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); - @Override - public String hGet(final String key, final String field){ - final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisClusterCommand(client, ProtocolCommand.HGET) - .general((cmd)->cmd.hget(key, field)) - .pipeline((cmd)->cmd.hget(key, field)) - .transaction((cmd)->cmd.hget(key, field)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } } @Override - public byte[] hGet(final byte[] key, final byte[] field){ - final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisClusterCommand(client, ProtocolCommand.HGET) - .general((cmd)->cmd.hget(key, field)) - .pipeline((cmd)->cmd.hget(key, field)) - .transaction((cmd)->cmd.hget(key, field)) - .run(args); - } + public String hGet(final String key, final String field) { + final CommandArguments args = CommandArguments.create(key).add(field); - @Override - public Map hGetAll(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand>(client, ProtocolCommand.HGETALL) - .general((cmd)->cmd.hgetAll(key)) - .pipeline((cmd)->cmd.hgetAll(key)) - .transaction((cmd)->cmd.hgetAll(key)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + } } @Override - public Map hGetAll(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand>(client, ProtocolCommand.HGETALL) - .general((cmd)->cmd.hgetAll(key)) - .pipeline((cmd)->cmd.hgetAll(key)) - .transaction((cmd)->cmd.hgetAll(key)) - .run(args); - } + public byte[] hGet(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create(key).add(field); - @Override - public Long hIncrBy(final String key, final String field, final long value){ + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + } + } + + @Override + public Map hGetAll(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + } + } + + @Override + public Map hGetAll(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + } + } + + @Override + public Long hIncrBy(final String key, final String field, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.HINCRBY) - .general((cmd)->cmd.hincrBy(key, field, value)) - .pipeline((cmd)->cmd.hincrBy(key, field, value)) - .transaction((cmd)->cmd.hincrBy(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HINCRBY, + (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HINCRBY, + (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + } } @Override - public Long hIncrBy(final byte[] key, final byte[] field, final long value){ + public Long hIncrBy(final byte[] key, final byte[] field, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.HINCRBY) - .general((cmd)->cmd.hincrBy(key, field, value)) - .pipeline((cmd)->cmd.hincrBy(key, field, value)) - .transaction((cmd)->cmd.hincrBy(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HINCRBY, + (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HINCRBY, + (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + } } @Override - public Double hIncrByFloat(final String key, final String field, final double value){ + public Double hIncrByFloat(final String key, final String field, final double value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.HINCRBYFLOAT) - .general((cmd)->cmd.hincrByFloat(key, field, value)) - .pipeline((cmd)->cmd.hincrByFloat(key, field, value)) - .transaction((cmd)->cmd.hincrByFloat(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + } } @Override - public Double hIncrByFloat(final byte[] key, final byte[] field, final double value){ + public Double hIncrByFloat(final byte[] key, final byte[] field, final double value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.HINCRBYFLOAT) - .general((cmd)->cmd.hincrByFloat(key, field, value)) - .pipeline((cmd)->cmd.hincrByFloat(key, field, value)) - .transaction((cmd)->cmd.hincrByFloat(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + } } @Override - public Set hKeys(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand>(client, ProtocolCommand.HKEYS) - .general((cmd)->cmd.hkeys(key)) - .pipeline((cmd)->cmd.hkeys(key)) - .transaction((cmd)->cmd.hkeys(key)) - .run(args); + public Set hKeys(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + } } @Override - public Set hKeys(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand>(client, ProtocolCommand.HKEYS) - .general((cmd)->cmd.hkeys(key)) - .pipeline((cmd)->cmd.hkeys(key)) - .transaction((cmd)->cmd.hkeys(key)) - .run(args); + public Set hKeys(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + } } @Override - public Long hLen(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.HLEN) - .general((cmd)->cmd.hlen(key)) - .pipeline((cmd)->cmd.hlen(key)) - .transaction((cmd)->cmd.hlen(key)) - .run(args); + public Long hLen(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } } @Override - public Long hLen(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.HLEN) - .general((cmd)->cmd.hlen(key)) - .pipeline((cmd)->cmd.hlen(key)) - .transaction((cmd)->cmd.hlen(key)) - .run(args); + public Long hLen(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } } @Override - public List hMGet(final String key, final String... fields){ + public List hMGet(final String key, final String... fields) { final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); - return new JedisClusterCommand>(client, ProtocolCommand.HMGET) - .general((cmd)->cmd.hmget(key, fields)) - .pipeline((cmd)->cmd.hmget(key, fields)) - .transaction((cmd)->cmd.hmget(key, fields)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + } } @Override - public List hMGet(final byte[] key, final byte[]... fields){ + public List hMGet(final byte[] key, final byte[]... fields) { final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); - return new JedisClusterCommand>(client, ProtocolCommand.HMGET) - .general((cmd)->cmd.hmget(key, fields)) - .pipeline((cmd)->cmd.hmget(key, fields)) - .transaction((cmd)->cmd.hmget(key, fields)) - .run(args); - } - @Override - public Status hMSet(final String key, final Map data){ - final CommandArguments args = CommandArguments.create("key", key).put("data", data); - return new JedisClusterCommand(client, ProtocolCommand.HMGET) - .general((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + } } @Override - public Status hMSet(final byte[] key, final Map data){ + public Status hMSet(final String key, final Map data) { final CommandArguments args = CommandArguments.create("key", key).put("data", data); - return new JedisClusterCommand(client, ProtocolCommand.HMGET) - .general((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .run(args); - } - @Override - public String hRandField(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfield(key)) - .pipeline((cmd)->cmd.hrandfield(key)) - .transaction((cmd)->cmd.hrandfield(key)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + } } @Override - public byte[] hRandField(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfield(key)) - .pipeline((cmd)->cmd.hrandfield(key)) - .transaction((cmd)->cmd.hrandfield(key)) - .run(args); - } + public Status hMSet(final byte[] key, final Map data) { + final CommandArguments args = CommandArguments.create("key", key).put("data", data); - @Override - public List hRandField(final String key, final long count){ + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + } + } + + @Override + public String hRandField(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] hRandField(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + } + } + + @Override + public List hRandField(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfield(key, count)) - .pipeline((cmd)->cmd.hrandfield(key, count)) - .transaction((cmd)->cmd.hrandfield(key, count)) - .run(args); - } - @Override - public List hRandField(final byte[] key, final long count){ - final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfield(key, count)) - .pipeline((cmd)->cmd.hrandfield(key, count)) - .transaction((cmd)->cmd.hrandfield(key, count)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + } } @Override - public Map hRandFieldWithValues(final String key, final long count){ + public List hRandField(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfieldWithValues(key, count)) - .pipeline((cmd)->cmd.hrandfieldWithValues(key, count)) - .transaction((cmd)->cmd.hrandfieldWithValues(key, count)) - .run(args); - } - @Override - public Map hRandFieldWithValues(final byte[] key, final long count){ - final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfieldWithValues(key, count)) - .pipeline((cmd)->cmd.hrandfieldWithValues(key, count)) - .transaction((cmd)->cmd.hrandfieldWithValues(key, count)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + } } @Override - public ScanResult> hScan(final String key, final String cursor){ + public Map hRandFieldWithValues(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListMapEntryMapConverter converter = + new ListMapEntryMapConverter<>((k)->k, (v)->v); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + } + } + + @Override + public Map hRandFieldWithValues(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListMapEntryMapConverter converter = + new ListMapEntryMapConverter<>((k)->k, (v)->v); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final String key, final String cursor) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisClusterCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .run(args); - } - - @Override - public ScanResult> hScan(final byte[] key, final byte[] cursor){ + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisClusterCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .run(args); - } - - @Override - public ScanResult> hScan(final String key, final String cursor, final String pattern){ + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final String key, final String cursor, final String pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisClusterCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return hScan(key, cursor, scanParams, args); } @Override - public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern){ + public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisClusterCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return hScan(key, cursor, scanParams, args); } @Override - public ScanResult> hScan(final String key, final String cursor, final long count){ + public ScanResult> hScan(final String key, final String cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisClusterCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return hScan(key, cursor, scanParams, args); } @Override - public ScanResult> hScan(final byte[] key, final byte[] cursor, final long count){ + public ScanResult> hScan(final byte[] key, final byte[] cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisClusterCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return hScan(key, cursor, scanParams, args); } @Override public ScanResult> hScan(final String key, final String cursor, final String pattern, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisClusterCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return hScan(key, cursor, scanParams, args); } @Override public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisClusterCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return hScan(key, cursor, scanParams, args); } @Override - public Long hSet(final String key, final String field, final String value){ + public Long hSet(final String key, final String field, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.HSET) - .general((cmd)->cmd.hset(key, field, value)) - .pipeline((cmd)->cmd.hset(key, field, value)) - .transaction((cmd)->cmd.hset(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HSET, + (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + } } @Override - public Long hSet(final byte[] key, final byte[] field, final byte[] value){ + public Long hSet(final byte[] key, final byte[] field, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.HSET) - .general((cmd)->cmd.hset(key, field, value)) - .pipeline((cmd)->cmd.hset(key, field, value)) - .transaction((cmd)->cmd.hset(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HSET, + (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + } } @Override - public Status hSetNx(final String key, final String field, final String value){ + public Status hSetNx(final String key, final String field, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.HSETNX) - .general((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HSETNX, + (cmd)->cmd.hsetnx(key, field, value), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HSETNX, + (cmd)->cmd.hsetnx(key, field, value), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + } } @Override - public Status hSetNx(final byte[] key, final byte[] field, final byte[] value){ + public Status hSetNx(final byte[] key, final byte[] field, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.HSETNX) - .general((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HSETNX, + (cmd)->cmd.hsetnx(key, field, value), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HSETNX, + (cmd)->cmd.hsetnx(key, field, value), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + } } @Override - public Long hStrLen(final String key, final String field){ + public Long hStrLen(final String key, final String field) { final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisClusterCommand(client, ProtocolCommand.HSTRLEN) - .general((cmd)->cmd.hstrlen(key, field)) - .pipeline((cmd)->cmd.hstrlen(key, field)) - .transaction((cmd)->cmd.hstrlen(key, field)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } } @Override - public Long hStrLen(final byte[] key, final byte[] field){ + public Long hStrLen(final byte[] key, final byte[] field) { final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisClusterCommand(client, ProtocolCommand.HSTRLEN) - .general((cmd)->cmd.hstrlen(key, field)) - .pipeline((cmd)->cmd.hstrlen(key, field)) - .transaction((cmd)->cmd.hstrlen(key, field)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } } @Override - public List hVals(final String key){ + public List hVals(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand>(client, ProtocolCommand.HVALS) - .general((cmd)->cmd.hvals(key)) - .pipeline((cmd)->cmd.hvals(key)) - .transaction((cmd)->cmd.hvals(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + } } @Override - public List hVals(final byte[] key){ + public List hVals(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand>(client, ProtocolCommand.HVALS) - .general((cmd)->cmd.hvals(key)) - .pipeline((cmd)->cmd.hvals(key)) - .transaction((cmd)->cmd.hvals(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + } + } + + private ScanResult> hScan(final String key, final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanParams), mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanParams), mapScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + } + } + + private ScanResult> hScan(final byte[] key, final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanParams), mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanParams), mapScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterHyperLogLogOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterHyperLogLogOperations.java index 741994fc7..5c647e5c0 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterHyperLogLogOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterHyperLogLogOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -28,8 +28,6 @@ import com.buession.redis.client.jedis.JedisClusterClient; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; /** * Jedis 集群模式 HyperLogLog 命令操作 @@ -39,68 +37,118 @@ */ public final class JedisClusterHyperLogLogOperations extends AbstractHyperLogLogOperations { - public JedisClusterHyperLogLogOperations(final JedisClusterClient client){ + public JedisClusterHyperLogLogOperations(final JedisClusterClient client) { super(client); } @Override - public Status pfAdd(final String key, final String... elements){ - final CommandArguments args = CommandArguments.create("key", key).put("elements", (Object[]) elements); - return new JedisClusterCommand(client, ProtocolCommand.PFADD) - .general((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .run(args); + public Status pfAdd(final String key, final String... elements) { + final CommandArguments args = CommandArguments.create(key).add(elements); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + } } @Override - public Status pfAdd(final byte[] key, final byte[]... elements){ - final CommandArguments args = CommandArguments.create("key", key).put("elements", (Object[]) elements); - return new JedisClusterCommand(client, ProtocolCommand.PFADD) - .general((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .run(args); + public Status pfAdd(final byte[] key, final byte[]... elements) { + final CommandArguments args = CommandArguments.create(key).add(elements); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + } } @Override - public Status pfMerge(final String destKey, final String... keys){ + public Status pfMerge(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.PFMERGE) - .general((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PFMERGE, + (cmd)->cmd.pfmerge(destKey, keys), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + } } @Override - public Status pfMerge(final byte[] destKey, final byte[]... keys){ + public Status pfMerge(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.PFMERGE) - .general((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PFMERGE, + (cmd)->cmd.pfmerge(destKey, keys), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + } } @Override - public Long pfCount(final String... keys){ + public Long pfCount(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.PFCOUNT) - .general((cmd)->cmd.pfcount(keys)) - .pipeline((cmd)->cmd.pfcount(keys)) - .transaction((cmd)->cmd.pfcount(keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } } @Override - public Long pfCount(final byte[]... keys){ + public Long pfCount(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.PFCOUNT) - .general((cmd)->cmd.pfcount(keys)) - .pipeline((cmd)->cmd.pfcount(keys)) - .transaction((cmd)->cmd.pfcount(keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterKeyOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterKeyOperations.java index c1d0e626a..ace1759ba 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterKeyOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterKeyOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -33,15 +33,20 @@ import com.buession.redis.core.Type; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; import com.buession.redis.core.internal.convert.jedis.params.ExpireOptionConverter; -import com.buession.redis.core.internal.convert.jedis.params.RestoreArgumentConverter; -import com.buession.redis.core.internal.convert.jedis.params.SortArgumentConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import com.buession.redis.core.internal.convert.response.BinaryObjectEncodingConverter; +import com.buession.redis.core.internal.convert.response.ObjectEncodingConverter; import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; +import com.buession.redis.core.internal.convert.response.TypeConverter; +import com.buession.redis.core.internal.jedis.JedisMigrateParams; +import com.buession.redis.core.internal.jedis.JedisRestoreParams; import com.buession.redis.core.internal.jedis.JedisScanParams; +import com.buession.redis.core.internal.jedis.JedisSortingParams; +import com.buession.redis.utils.SafeEncoder; import redis.clients.jedis.args.ExpiryOption; +import redis.clients.jedis.params.MigrateParams; import redis.clients.jedis.params.RestoreParams; +import redis.clients.jedis.params.ScanParams; import redis.clients.jedis.params.SortingParams; import java.util.List; @@ -55,910 +60,1475 @@ */ public final class JedisClusterKeyOperations extends AbstractKeyOperations { - public JedisClusterKeyOperations(final JedisClusterClient client){ + public JedisClusterKeyOperations(final JedisClusterClient client) { super(client); } @Override - public Long del(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.DEL) - .general((cmd)->cmd.del(keys)) - .pipeline((cmd)->cmd.del(keys)) - .transaction((cmd)->cmd.del(keys)) - .run(args); + public Long del(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } } @Override - public Long del(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.DEL) - .general((cmd)->cmd.del(keys)) - .pipeline((cmd)->cmd.del(keys)) - .transaction((cmd)->cmd.del(keys)) - .run(args); + public Long del(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } } @Override - public String dump(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.DUMP) - .general((cmd)->cmd.dump(key), Converters.BINARY_TO_STRING_CONVERTER) - .pipeline((cmd)->cmd.dump(key), Converters.BINARY_TO_STRING_CONVERTER) - .transaction((cmd)->cmd.dump(key), Converters.BINARY_TO_STRING_CONVERTER) - .run(args); + public String dump(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), + SafeEncoder::encode) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), + SafeEncoder::encode) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), SafeEncoder::encode) + .run(args); + } } @Override - public byte[] dump(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.DUMP) - .general((cmd)->cmd.dump(key)) - .pipeline((cmd)->cmd.dump(key)) - .transaction((cmd)->cmd.dump(key)) - .run(args); + public byte[] dump(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + } } @Override - public Boolean exists(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.EXISTS) - .general((cmd)->cmd.exists(key)) - .pipeline((cmd)->cmd.exists(key)) - .transaction((cmd)->cmd.exists(key)) - .run(args); + public Boolean exists(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + } } @Override - public Boolean exists(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.EXISTS) - .general((cmd)->cmd.exists(key)) - .pipeline((cmd)->cmd.exists(key)) - .transaction((cmd)->cmd.exists(key)) - .run(args); + public Boolean exists(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + } } @Override - public Long exists(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.EXISTS) - .general((cmd)->cmd.exists(keys)) - .pipeline((cmd)->cmd.exists(keys)) - .transaction((cmd)->cmd.exists(keys)) - .run(args); + public Long exists(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } } @Override - public Long exists(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.EXISTS) - .general((cmd)->cmd.exists(keys)) - .pipeline((cmd)->cmd.exists(keys)) - .transaction((cmd)->cmd.exists(keys)) - .run(args); + public Long exists(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } } @Override - public Status expire(final String key, final int lifetime){ + public Status expire(final String key, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); - return new JedisClusterCommand(client, ProtocolCommand.EXPIRE) - .general((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + } } @Override - public Status expire(final byte[] key, final int lifetime){ + public Status expire(final byte[] key, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); - return new JedisClusterCommand(client, ProtocolCommand.EXPIRE) - .general((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + } } @Override - public Status expire(final String key, final int lifetime, final ExpireOption expireOption){ + public Status expire(final String key, final int lifetime, final ExpireOption expireOption) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime) .put("expireOption", expireOption); - final ExpiryOption expiryOption = ExpireOptionConverter.INSTANCE.convert(expireOption); - return new JedisClusterCommand(client, ProtocolCommand.EXPIRE) - .general((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .run(args); - } - - @Override - public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption){ + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime) .put("expireOption", expireOption); - final ExpiryOption expiryOption = ExpireOptionConverter.INSTANCE.convert(expireOption); - return new JedisClusterCommand(client, ProtocolCommand.EXPIRE) - .general((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .run(args); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + } } @Override - public Status expireAt(final String key, final long unixTimestamp){ + public Status expireAt(final String key, final long unixTimestamp) { final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); - return new JedisClusterCommand(client, ProtocolCommand.EXPIREAT) - .general((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } } @Override - public Status expireAt(final byte[] key, final long unixTimestamp){ + public Status expireAt(final byte[] key, final long unixTimestamp) { final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); - return new JedisClusterCommand(client, ProtocolCommand.EXPIREAT) - .general((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } } @Override - public Status pExpire(final String key, final int lifetime){ + public Status pExpire(final String key, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); - return new JedisClusterCommand(client, ProtocolCommand.PEXPIRE) - .general((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + } } @Override - public Status pExpire(final byte[] key, final int lifetime){ + public Status pExpire(final byte[] key, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); - return new JedisClusterCommand(client, ProtocolCommand.PEXPIRE) - .general((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + } } @Override - public Status pExpireAt(final String key, final long unixTimestamp){ + public Status pExpireAt(final String key, final long unixTimestamp) { final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); - return new JedisClusterCommand(client, ProtocolCommand.PEXPIREAT) - .general((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } } @Override - public Status pExpireAt(final byte[] key, final long unixTimestamp){ + public Status pExpireAt(final byte[] key, final long unixTimestamp) { final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); - return new JedisClusterCommand(client, ProtocolCommand.PEXPIREAT) - .general((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } } @Override - public Status persist(final String key){ + public Status persist(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.PERSIST) - .general((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + } } @Override - public Status persist(final byte[] key){ + public Status persist(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.PERSIST) - .general((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + } } @Override - public Long ttl(final String key){ + public Long ttl(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.TTL) - .general((cmd)->cmd.ttl(key)) - .pipeline((cmd)->cmd.ttl(key)) - .transaction((cmd)->cmd.ttl(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } } @Override - public Long ttl(final byte[] key){ + public Long ttl(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.TTL) - .general((cmd)->cmd.ttl(key)) - .pipeline((cmd)->cmd.ttl(key)) - .transaction((cmd)->cmd.ttl(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } } @Override - public Long pTtl(final String key){ + public Long pTtl(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.PTTL) - .general((cmd)->cmd.pttl(key)) - .pipeline((cmd)->cmd.pttl(key)) - .transaction((cmd)->cmd.pttl(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } } @Override - public Long pTtl(final byte[] key){ + public Long pTtl(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.PTTL) - .general((cmd)->cmd.pttl(key)) - .pipeline((cmd)->cmd.pttl(key)) - .transaction((cmd)->cmd.pttl(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } } @Override - public Status copy(final String key, final String destKey){ + public Status copy(final String key, final String destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisClusterCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, false, args); } @Override - public Status copy(final byte[] key, final byte[] destKey){ + public Status copy(final byte[] key, final byte[] destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisClusterCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, false, args); } @Override - public Status copy(final String key, final String destKey, final int db){ + public Status copy(final String key, final String destKey, final int db) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("db", db); - return new JedisClusterCommand(client, ProtocolCommand.COPY) - .run(args); + return copy(key, destKey, db, false, args); } @Override - public Status copy(final byte[] key, final byte[] destKey, final int db){ - final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) - .put("db", db); - return new JedisClusterCommand(client, ProtocolCommand.COPY) - .run(args); + public Status copy(final byte[] key, final byte[] destKey, final int db) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("db", db); + return copy(key, destKey, db, false, args); } @Override - public Status copy(final String key, final String destKey, final boolean replace){ + public Status copy(final String key, final String destKey, final boolean replace) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("replace", replace); - return new JedisClusterCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, replace, args); } @Override - public Status copy(final byte[] key, final byte[] destKey, final boolean replace){ + public Status copy(final byte[] key, final byte[] destKey, final boolean replace) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("replace", replace); - return new JedisClusterCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, replace, args); } @Override - public Status copy(final String key, final String destKey, final int db, final boolean replace){ + public Status copy(final String key, final String destKey, final int db, final boolean replace) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("db", db) .put("replace", replace); - return new JedisClusterCommand(client, ProtocolCommand.COPY) - .run(args); + return copy(key, destKey, db, replace, args); } @Override - public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace){ + public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("db", db) .put("replace", replace); - return new JedisClusterCommand(client, ProtocolCommand.COPY) - .run(args); + return copy(key, destKey, db, replace, args); } @Override - public Status move(final String key, final int db){ + public Status move(final String key, final int db) { final CommandArguments args = CommandArguments.create("key", key).put("db", db); - return new JedisClusterCommand(client, ProtocolCommand.MOVE) - .run(args); + return move(args); } @Override - public Status move(final byte[] key, final int db){ + public Status move(final byte[] key, final int db) { final CommandArguments args = CommandArguments.create("key", key).put("db", db); - return new JedisClusterCommand(client, ProtocolCommand.MOVE) - .run(args); + return move(args); } @Override - public Status migrate(final String host, final int port, final int db, final int timeout, final String... keys){ + public Status migrate(final String host, final int port, final int db, final int timeout, final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("timeout", timeout).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.MIGRATE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override - public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... keys){ + public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("timeout", timeout).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.MIGRATE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final int timeout, - final MigrateOperation operation, final String... keys){ + final MigrateOperation operation, final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("timeout", timeout).put("operation", operation).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.MIGRATE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final int timeout, - final MigrateOperation operation, final byte[]... keys){ + final MigrateOperation operation, final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("timeout", timeout).put("operation", operation).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.MIGRATE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final String password, final int timeout, - final String... keys){ + final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("password", password).put("timeout", timeout).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.MIGRATE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final byte[] password, final int timeout, - final byte[]... keys){ + final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("password", password).put("timeout", timeout).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.MIGRATE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final String password, final int timeout, - final MigrateOperation operation, final String... keys){ + final MigrateOperation operation, final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("password", password).put("timeout", timeout).put("operation", operation) .put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.MIGRATE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final byte[] password, final int timeout, - final MigrateOperation operation, final byte[]... keys){ + final MigrateOperation operation, final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("password", password).put("timeout", timeout).put("operation", operation) .put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.MIGRATE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final String user, final String password, - final int timeout, final String... keys){ + final int timeout, final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("user", user).put("password", password).put("timeout", timeout).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.MIGRATE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(user, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final byte[] user, final byte[] password, - final int timeout, final byte[]... keys){ + final int timeout, final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("user", user).put("password", password).put("timeout", timeout).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.MIGRATE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(user, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final String user, final String password, - final int timeout, final MigrateOperation operation, final String... keys){ + final int timeout, final MigrateOperation operation, final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("user", user).put("password", password).put("timeout", timeout).put("operation", operation) .put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.MIGRATE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation, user, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final byte[] user, final byte[] password, - final int timeout, final MigrateOperation operation, final byte[]... keys){ + final int timeout, final MigrateOperation operation, final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("user", user).put("password", password).put("timeout", timeout).put("operation", operation) .put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.MIGRATE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation, user, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override - public Set keys(final String pattern){ + public Set keys(final String pattern) { final CommandArguments args = CommandArguments.create("pattern", pattern); - return new JedisClusterCommand>(client, ProtocolCommand.KEYS) - .general((cmd)->cmd.keys(pattern)) - .pipeline((cmd)->cmd.keys(pattern)) - .transaction((cmd)->cmd.keys(pattern)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + } } @Override - public Set keys(final byte[] pattern){ + public Set keys(final byte[] pattern) { final CommandArguments args = CommandArguments.create("pattern", pattern); - return new JedisClusterCommand>(client, ProtocolCommand.KEYS) - .general((cmd)->cmd.keys(pattern)) - .pipeline((cmd)->cmd.keys(pattern)) - .transaction((cmd)->cmd.keys(pattern)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + } } @Override - public String randomKey(){ - return new JedisClusterCommand(client, ProtocolCommand.RANDOMKEY) - .general((cmd)->cmd.randomKey()) - .pipeline((cmd)->cmd.randomKey()) - .transaction((cmd)->cmd.randomKey()) - .run(); + public String randomKey() { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RANDOMKEY, (cmd)->cmd.randomKey(), (v)->v) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RANDOMKEY, (cmd)->cmd.randomKey(), + (v)->v) + .run(); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RANDOMKEY, (cmd)->cmd.randomKey(), (v)->v) + .run(); + } } @Override - public Status rename(final String key, final String newKey){ + public Status rename(final String key, final String newKey) { final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); - return new JedisClusterCommand(client, ProtocolCommand.RENAME) - .general((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + } } @Override - public Status rename(final byte[] key, final byte[] newKey){ + public Status rename(final byte[] key, final byte[] newKey) { final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); - return new JedisClusterCommand(client, ProtocolCommand.RENAME) - .general((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + } } @Override - public Status renameNx(final String key, final String newKey){ + public Status renameNx(final String key, final String newKey) { final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); - return new JedisClusterCommand(client, ProtocolCommand.RENAME) - .general((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RENAMENX, + (cmd)->cmd.renamenx(key, newKey), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + } } @Override - public Status renameNx(final byte[] key, final byte[] newKey){ + public Status renameNx(final byte[] key, final byte[] newKey) { final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); - return new JedisClusterCommand(client, ProtocolCommand.RENAME) - .general((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RENAMENX, + (cmd)->cmd.renamenx(key, newKey), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + } } @Override - public Status restore(final String key, final byte[] serializedValue, final int ttl){ + public Status restore(final String key, final byte[] serializedValue, final int ttl) { final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) .put("ttl", ttl); - return new JedisClusterCommand(client, ProtocolCommand.RESTORE) - .general((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + } } @Override - public Status restore(final byte[] key, final byte[] serializedValue, final int ttl){ + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl) { final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) .put("ttl", ttl); - return new JedisClusterCommand(client, ProtocolCommand.RESTORE) - .general((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + } } @Override public Status restore(final String key, final byte[] serializedValue, final int ttl, - final RestoreArgument argument){ + final RestoreArgument argument) { final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) .put("ttl", ttl).put("argument", argument); - final RestoreParams params = RestoreArgumentConverter.INSTANCE.convert(argument); - return new JedisClusterCommand(client, ProtocolCommand.RESTORE) - .general((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .run(args); + final RestoreParams restoreParams = JedisRestoreParams.from(argument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + } } @Override public Status restore(final byte[] key, final byte[] serializedValue, final int ttl, - final RestoreArgument argument){ + final RestoreArgument argument) { final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) .put("ttl", ttl).put("argument", argument); - final RestoreParams params = RestoreArgumentConverter.INSTANCE.convert(argument); - return new JedisClusterCommand(client, ProtocolCommand.RESTORE) - .general((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .run(args); - } + final RestoreParams restoreParams = JedisRestoreParams.from(argument); - @Override - public ScanResult> scan(final String cursor){ - final CommandArguments args = CommandArguments.create("cursor", cursor); - return new JedisClusterCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor), ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor), ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + } } @Override - public ScanResult> scan(final byte[] cursor){ + public ScanResult> scan(final String cursor) { final CommandArguments args = CommandArguments.create("cursor", cursor); - return new JedisClusterCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor), ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor), ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); - } - - @Override - public ScanResult> scan(final String cursor, final String pattern){ + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final byte[] cursor) { + final CommandArguments args = CommandArguments.create("cursor", cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final String cursor, final String pattern) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisClusterCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return scan(cursor, scanParams, args); } @Override - public ScanResult> scan(final byte[] cursor, final byte[] pattern){ + public ScanResult> scan(final byte[] cursor, final byte[] pattern) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisClusterCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return scan(cursor, scanParams, args); } @Override - public ScanResult> scan(final String cursor, final long count){ + public ScanResult> scan(final String cursor, final long count) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisClusterCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return scan(cursor, scanParams, args); } @Override - public ScanResult> scan(final byte[] cursor, final long count){ + public ScanResult> scan(final byte[] cursor, final long count) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisClusterCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return scan(cursor, scanParams, args); } @Override - public ScanResult> scan(final String cursor, final String pattern, final long count){ + public ScanResult> scan(final String cursor, final String pattern, final long count) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisClusterCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return scan(cursor, scanParams, args); } @Override - public ScanResult> scan(final byte[] cursor, final byte[] pattern, final long count){ + public ScanResult> scan(final byte[] cursor, final byte[] pattern, final long count) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisClusterCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return scan(cursor, scanParams, args); } @Override - public List sort(final String key){ + public List sort(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand>(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key)) - .pipeline((cmd)->cmd.sort(key)) - .transaction((cmd)->cmd.sort(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + } } @Override - public List sort(final byte[] key){ + public List sort(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand>(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key)) - .pipeline((cmd)->cmd.sort(key)) - .transaction((cmd)->cmd.sort(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + } } @Override - public List sort(final String key, final SortArgument sortArgument){ + public List sort(final String key, final SortArgument sortArgument) { final CommandArguments args = CommandArguments.create("key", key).put("sortArgument", sortArgument); - final SortingParams params = SortArgumentConverter.INSTANCE.convert(sortArgument); - return new JedisClusterCommand>(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, params)) - .pipeline((cmd)->cmd.sort(key, params)) - .transaction((cmd)->cmd.sort(key, params)) - .run(args); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + } } @Override - public List sort(final byte[] key, final SortArgument sortArgument){ + public List sort(final byte[] key, final SortArgument sortArgument) { final CommandArguments args = CommandArguments.create("key", key).put("sortArgument", sortArgument); - final SortingParams params = SortArgumentConverter.INSTANCE.convert(sortArgument); - return new JedisClusterCommand>(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, params)) - .pipeline((cmd)->cmd.sort(key, params)) - .transaction((cmd)->cmd.sort(key, params)) - .run(args); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + } } @Override - public Long sort(final String key, final String destKey){ + public Long sort(final String key, final String destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisClusterCommand(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, destKey)) - .pipeline((cmd)->cmd.sort(key, destKey)) - .transaction((cmd)->cmd.sort(key, destKey)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + } } @Override - public Long sort(final byte[] key, final byte[] destKey){ + public Long sort(final byte[] key, final byte[] destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisClusterCommand(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, destKey)) - .pipeline((cmd)->cmd.sort(key, destKey)) - .transaction((cmd)->cmd.sort(key, destKey)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + } } @Override - public Long sort(final String key, final String destKey, final SortArgument sortArgument){ + public Long sort(final String key, final String destKey, final SortArgument sortArgument) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("sortArgument", sortArgument); - final SortingParams params = SortArgumentConverter.INSTANCE.convert(sortArgument); - return new JedisClusterCommand(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, params, destKey)) - .pipeline((cmd)->cmd.sort(key, params, destKey)) - .transaction((cmd)->cmd.sort(key, params, destKey)) - .run(args); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), + (v)->v) + .run(args); + } } @Override - public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument){ + public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("sortArgument", sortArgument); - final SortingParams params = SortArgumentConverter.INSTANCE.convert(sortArgument); - return new JedisClusterCommand(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, params, destKey)) - .pipeline((cmd)->cmd.sort(key, params, destKey)) - .transaction((cmd)->cmd.sort(key, params, destKey)) - .run(args); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), + (v)->v) + .run(args); + } } @Override - public Long touch(final String... keys){ + public Long touch(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.TOUCH) - .general((cmd)->cmd.touch(keys)) - .pipeline((cmd)->cmd.touch(keys)) - .transaction((cmd)->cmd.touch(keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } } @Override - public Long touch(final byte[]... keys){ + public Long touch(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.TOUCH) - .general((cmd)->cmd.touch(keys)) - .pipeline((cmd)->cmd.touch(keys)) - .transaction((cmd)->cmd.touch(keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } } @Override - public Type type(final String key){ + public Type type(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.TYPE) - .general((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .pipeline((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .transaction((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .run(args); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), + typeConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } } @Override - public Type type(final byte[] key){ + public Type type(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.TYPE) - .general((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .pipeline((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .transaction((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .run(args); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), + typeConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } } @Override - public Long unlink(final String... keys){ + public Long unlink(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.UNLINK) - .general((cmd)->cmd.unlink(keys)) - .pipeline((cmd)->cmd.unlink(keys)) - .transaction((cmd)->cmd.unlink(keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } } @Override - public Long unlink(final byte[]... keys){ + public Long unlink(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.UNLINK) - .general((cmd)->cmd.unlink(keys)) - .pipeline((cmd)->cmd.unlink(keys)) - .transaction((cmd)->cmd.unlink(keys)) - .run(args); - } - @Override - public Long wait(final int replicas, final int timeout){ - final CommandArguments args = CommandArguments.create("replicas", replicas).put("timeout", timeout); - return new JedisClusterCommand(client, ProtocolCommand.WAIT) - .general((cmd)->cmd.waitReplicas((String) null, replicas, timeout)) - .pipeline((cmd)->cmd.waitReplicas(replicas, timeout)) - .transaction((cmd)->cmd.waitReplicas(replicas, timeout)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } } @Override - public ObjectEncoding objectEncoding(final String key){ + public ObjectEncoding objectEncoding(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.OBJECT_ENCODING) - .general((cmd)->cmd.objectEncoding(key), Converters.STRING_OBJECT_ENCODING_RESULT_CONVERTER) - .pipeline((cmd)->cmd.objectEncoding(key), Converters.STRING_OBJECT_ENCODING_RESULT_CONVERTER) - .transaction((cmd)->cmd.objectEncoding(key), Converters.STRING_OBJECT_ENCODING_RESULT_CONVERTER) - .run(args); + final ObjectEncodingConverter objectEncodingConverter = new ObjectEncodingConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.OBJECT_ENCODING, (cmd)->cmd.objectEncoding(key), + objectEncodingConverter) + .run(args); + } } @Override - public ObjectEncoding objectEncoding(final byte[] key){ + public ObjectEncoding objectEncoding(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.OBJECT_ENCODING) - .general((cmd)->cmd.objectEncoding(key), Converters.BINARY_OBJECT_ENCODING_RESULT_CONVERTER) - .pipeline((cmd)->cmd.objectEncoding(key), Converters.BINARY_OBJECT_ENCODING_RESULT_CONVERTER) - .transaction((cmd)->cmd.objectEncoding(key), Converters.BINARY_OBJECT_ENCODING_RESULT_CONVERTER) - .run(args); + final BinaryObjectEncodingConverter binaryObjectEncodingConverter = new BinaryObjectEncodingConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), binaryObjectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), binaryObjectEncodingConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.OBJECT_ENCODING, (cmd)->cmd.objectEncoding(key), + binaryObjectEncodingConverter) + .run(args); + } } @Override - public Long objectFreq(final String key){ + public Long objectFreq(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.OBJECT_REFQ) - .general((cmd)->cmd.objectFreq(key)) - .pipeline((cmd)->cmd.objectFreq(key)) - .transaction((cmd)->cmd.objectFreq(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + } } @Override - public Long objectFreq(final byte[] key){ + public Long objectFreq(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.OBJECT_REFQ) - .general((cmd)->cmd.objectFreq(key)) - .pipeline((cmd)->cmd.objectFreq(key)) - .transaction((cmd)->cmd.objectFreq(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + } } @Override - public Long objectIdleTime(final String key){ + public Long objectIdleTime(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.OBJECT_IDLETIME) - .general((cmd)->cmd.objectIdletime(key)) - .pipeline((cmd)->cmd.objectIdletime(key)) - .transaction((cmd)->cmd.objectIdletime(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, (cmd)->cmd.objectIdletime(key), + (v)->v) + .run(args); + } } @Override - public Long objectIdleTime(final byte[] key){ + public Long objectIdleTime(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.OBJECT_IDLETIME) - .general((cmd)->cmd.objectIdletime(key)) - .pipeline((cmd)->cmd.objectIdletime(key)) - .transaction((cmd)->cmd.objectIdletime(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, (cmd)->cmd.objectIdletime(key), + (v)->v) + .run(args); + } } @Override - public Long objectRefcount(final String key){ + public Long objectRefcount(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.OBJECT_REFCOUNT) - .general((cmd)->cmd.objectRefcount(key)) - .pipeline((cmd)->cmd.objectRefcount(key)) - .transaction((cmd)->cmd.objectRefcount(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, (cmd)->cmd.objectRefcount(key), + (v)->v) + .run(args); + } } @Override - public Long objectRefcount(final byte[] key){ + public Long objectRefcount(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.OBJECT_REFCOUNT) - .general((cmd)->cmd.objectRefcount(key)) - .pipeline((cmd)->cmd.objectRefcount(key)) - .transaction((cmd)->cmd.objectRefcount(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, (cmd)->cmd.objectRefcount(key), + (v)->v) + .run(args); + } + } + + private Status copy(final String key, final String destKey, final boolean replace, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final byte[] key, final byte[] destKey, final boolean replace, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final String key, final String destKey, final int db, final boolean replace, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status move(final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.MOVE) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.MOVE) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.MOVE) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, final String[] keys, + final MigrateParams migrateParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, final byte[][] keys, + final MigrateParams migrateParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + } + } + + private ScanResult> scan(final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SCAN, + (cmd)->cmd.scan(cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + + private ScanResult> scan(final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SCAN, + (cmd)->cmd.scan(cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterListOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterListOperations.java index 2d52e980f..4a41c7ff4 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterListOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterListOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -31,9 +31,8 @@ import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; import com.buession.redis.core.internal.convert.jedis.params.DirectionConverter; -import com.buession.redis.core.internal.convert.jedis.params.LPosArgumentConverter; import com.buession.redis.core.internal.convert.jedis.params.ListPositionConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import com.buession.redis.core.internal.jedis.JedisLPosParams; import redis.clients.jedis.args.ListDirection; import redis.clients.jedis.params.LPosParams; @@ -47,474 +46,836 @@ */ public final class JedisClusterListOperations extends AbstractListOperations { - public JedisClusterListOperations(final JedisClusterClient client){ + public JedisClusterListOperations(final JedisClusterClient client) { super(client); } @Override - public String lIndex(final String key, final long index){ + public String lIndex(final String key, final long index) { final CommandArguments args = CommandArguments.create("key", key).put("index", index); - return new JedisClusterCommand(client, ProtocolCommand.LINDEX) - .general((cmd)->cmd.lindex(key, index)) - .pipeline((cmd)->cmd.lindex(key, index)) - .transaction((cmd)->cmd.lindex(key, index)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + } } @Override - public byte[] lIndex(final byte[] key, final long index){ + public byte[] lIndex(final byte[] key, final long index) { final CommandArguments args = CommandArguments.create("key", key).put("index", index); - return new JedisClusterCommand(client, ProtocolCommand.LINDEX) - .general((cmd)->cmd.lindex(key, index)) - .pipeline((cmd)->cmd.lindex(key, index)) - .transaction((cmd)->cmd.lindex(key, index)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + } } @Override - public Long lInsert(final String key, final ListPosition position, final String pivot, final String value){ + public Long lInsert(final String key, final ListPosition position, final String pivot, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) .put("value", value); - final redis.clients.jedis.args.ListPosition pos = ListPositionConverter.INSTANCE.convert(position); - return new JedisClusterCommand(client, ProtocolCommand.LINSERT) - .general((cmd)->cmd.linsert(key, pos, pivot, value)) - .pipeline((cmd)->cmd.linsert(key, pos, pivot, value)) - .transaction((cmd)->cmd.linsert(key, pos, pivot, value)) - .run(args); + final redis.clients.jedis.args.ListPosition listPosition = (new ListPositionConverter()).convert(position); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + } } @Override - public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value){ + public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) .put("value", value); - final redis.clients.jedis.args.ListPosition pos = ListPositionConverter.INSTANCE.convert(position); - return new JedisClusterCommand(client, ProtocolCommand.LINSERT) - .general((cmd)->cmd.linsert(key, pos, pivot, value)) - .pipeline((cmd)->cmd.linsert(key, pos, pivot, value)) - .transaction((cmd)->cmd.linsert(key, pos, pivot, value)) - .run(args); + final redis.clients.jedis.args.ListPosition listPosition = (new ListPositionConverter()).convert(position); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + } } @Override - public Status lSet(final String key, final long index, final String value){ + public Status lSet(final String key, final long index, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.LINSERT) - .general((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } } @Override - public Status lSet(final byte[] key, final long index, final byte[] value){ + public Status lSet(final byte[] key, final long index, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.LINSERT) - .general((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } } @Override - public Long lLen(final String key){ + public Long lLen(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.LLEN) - .general((cmd)->cmd.llen(key)) - .pipeline((cmd)->cmd.llen(key)) - .transaction((cmd)->cmd.llen(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } } @Override - public Long lLen(final byte[] key){ + public Long lLen(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.LLEN) - .general((cmd)->cmd.llen(key)) - .pipeline((cmd)->cmd.llen(key)) - .transaction((cmd)->cmd.llen(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } } @Override - public List lRange(final String key, final long start, final long end){ + public List lRange(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand>(client, ProtocolCommand.LRANGE) - .general((cmd)->cmd.lrange(key, start, end)) - .pipeline((cmd)->cmd.lrange(key, start, end)) - .transaction((cmd)->cmd.lrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LRANGE, + (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + } } @Override - public List lRange(final byte[] key, final long start, final long end){ + public List lRange(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand>(client, ProtocolCommand.LRANGE) - .general((cmd)->cmd.lrange(key, start, end)) - .pipeline((cmd)->cmd.lrange(key, start, end)) - .transaction((cmd)->cmd.lrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LRANGE, + (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + } } @Override - public Long lPos(final String key, final String element){ + public Long lPos(final String key, final String element) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element)) - .pipeline((cmd)->cmd.lpos(key, element)) - .transaction((cmd)->cmd.lpos(key, element)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } } @Override - public Long lPos(final byte[] key, final byte[] element){ + public Long lPos(final byte[] key, final byte[] element) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element)) - .pipeline((cmd)->cmd.lpos(key, element)) - .transaction((cmd)->cmd.lpos(key, element)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } } @Override - public Long lPos(final String key, final String element, final LPosArgument lPosArgument){ + public Long lPos(final String key, final String element, final LPosArgument lPosArgument) { final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); - final LPosParams params = LPosArgumentConverter.INSTANCE.convert(lPosArgument); - return new JedisClusterCommand(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element, params)) - .pipeline((cmd)->cmd.lpos(key, element, params)) - .transaction((cmd)->cmd.lpos(key, element, params)) - .run(args); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), + (v)->v) + .run(args); + } } @Override - public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument){ + public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument) { final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); - final LPosParams params = LPosArgumentConverter.INSTANCE.convert(lPosArgument); - return new JedisClusterCommand(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element, params)) - .pipeline((cmd)->cmd.lpos(key, element, params)) - .transaction((cmd)->cmd.lpos(key, element, params)) - .run(args); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), + (v)->v) + .run(args); + } } @Override - public List lPos(final String key, final String element, final LPosArgument lPosArgument, final long count){ + public List lPos(final String key, final String element, final LPosArgument lPosArgument, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) .put("count", count); - final LPosParams params = LPosArgumentConverter.INSTANCE.convert(lPosArgument); - return new JedisClusterCommand>(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element, params, count)) - .pipeline((cmd)->cmd.lpos(key, element, params, count)) - .transaction((cmd)->cmd.lpos(key, element, params, count)) - .run(args); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + } } @Override - public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final long count){ + public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) .put("count", count); - final LPosParams params = LPosArgumentConverter.INSTANCE.convert(lPosArgument); - return new JedisClusterCommand>(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element, params, count)) - .pipeline((cmd)->cmd.lpos(key, element, params, count)) - .transaction((cmd)->cmd.lpos(key, element, params, count)) - .run(args); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + } } @Override - public Long lRem(final String key, final String value, final long count){ + public Long lRem(final String key, final String value, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); - return new JedisClusterCommand(client, ProtocolCommand.LREM) - .general((cmd)->cmd.lrem(key, count, value)) - .pipeline((cmd)->cmd.lrem(key, count, value)) - .transaction((cmd)->cmd.lrem(key, count, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LREM, + (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } } @Override - public Long lRem(final byte[] key, final byte[] value, final long count){ + public Long lRem(final byte[] key, final byte[] value, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); - return new JedisClusterCommand(client, ProtocolCommand.LREM) - .general((cmd)->cmd.lrem(key, count, value)) - .pipeline((cmd)->cmd.lrem(key, count, value)) - .transaction((cmd)->cmd.lrem(key, count, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LREM, + (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } } @Override - public Status lTrim(final String key, final long start, final long end){ + public Status lTrim(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand(client, ProtocolCommand.LTRIM) - .general((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LTRIM, + (cmd)->cmd.ltrim(key, start, end), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } } @Override - public Status lTrim(final byte[] key, final long start, final long end){ + public Status lTrim(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand(client, ProtocolCommand.LTRIM) - .general((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LTRIM, + (cmd)->cmd.ltrim(key, start, end), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } } @Override - public String lMove(final String key, final String destKey, final Direction from, final Direction to){ + public String lMove(final String key, final String destKey, final Direction from, final Direction to) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) .put("to", to); - final ListDirection fromDirection = DirectionConverter.INSTANCE.convert(from); - final ListDirection toDirection = DirectionConverter.INSTANCE.convert(to); - return new JedisClusterCommand(client, ProtocolCommand.LMOVE) - .general((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .pipeline((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .transaction((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .run(args); - } - - @Override - public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to){ + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + } + } + + @Override + public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) .put("to", to); - final ListDirection fromDirection = DirectionConverter.INSTANCE.convert(from); - final ListDirection toDirection = DirectionConverter.INSTANCE.convert(to); - return new JedisClusterCommand(client, ProtocolCommand.LMOVE) - .general((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .pipeline((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .transaction((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .run(args); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + } } @Override public String blMove(final String key, final String destKey, final Direction from, final Direction to, - final int timeout){ + final int timeout) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) .put("to", to).put("timeout", timeout); - final ListDirection fromDirection = DirectionConverter.INSTANCE.convert(from); - final ListDirection toDirection = DirectionConverter.INSTANCE.convert(to); - return new JedisClusterCommand(client, ProtocolCommand.BLMOVE) - .general((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .pipeline((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .transaction((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .run(args); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + } } @Override public byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, - final int timeout){ + final int timeout) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) .put("to", to).put("timeout", timeout); - final ListDirection fromDirection = DirectionConverter.INSTANCE.convert(from); - final ListDirection toDirection = DirectionConverter.INSTANCE.convert(to); - return new JedisClusterCommand(client, ProtocolCommand.BLMOVE) - .general((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .pipeline((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .transaction((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .run(args); - } - - @Override - public List blPop(final String[] keys, final int timeout){ + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + } + } + + @Override + public List blPop(final String[] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisClusterCommand>(client, ProtocolCommand.BLPOP) - .general((cmd)->cmd.blpop(timeout, keys)) - .pipeline((cmd)->cmd.blpop(timeout, keys)) - .transaction((cmd)->cmd.blpop(timeout, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + } } @Override - public List blPop(final byte[][] keys, final int timeout){ + public List blPop(final byte[][] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisClusterCommand>(client, ProtocolCommand.BLPOP) - .general((cmd)->cmd.blpop(timeout, keys)) - .pipeline((cmd)->cmd.blpop(timeout, keys)) - .transaction((cmd)->cmd.blpop(timeout, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + } } @Override - public List brPop(final String[] keys, final int timeout){ + public List brPop(final String[] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisClusterCommand>(client, ProtocolCommand.BRPOP) - .general((cmd)->cmd.brpop(timeout, keys)) - .pipeline((cmd)->cmd.brpop(timeout, keys)) - .transaction((cmd)->cmd.brpop(timeout, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + } } @Override - public List brPop(final byte[][] keys, final int timeout){ + public List brPop(final byte[][] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisClusterCommand>(client, ProtocolCommand.BRPOP) - .general((cmd)->cmd.brpop(timeout, keys)) - .pipeline((cmd)->cmd.brpop(timeout, keys)) - .transaction((cmd)->cmd.brpop(timeout, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + } } @Override - public String brPoplPush(final String key, final String destKey, final int timeout){ + public String brPoplPush(final String key, final String destKey, final int timeout) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("timeout", timeout); - return new JedisClusterCommand(client, ProtocolCommand.BRPOPLPUSH) - .general((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .pipeline((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .transaction((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + } } @Override - public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout){ + public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("timeout", timeout); - return new JedisClusterCommand(client, ProtocolCommand.BRPOPLPUSH) - .general((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .pipeline((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .transaction((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + } } @Override - public String lPop(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.LPOP) - .general((cmd)->cmd.lpop(key)) - .pipeline((cmd)->cmd.lpop(key)) - .transaction((cmd)->cmd.lpop(key)) - .run(args); + public String lPop(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + } } @Override - public byte[] lPop(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.LPOP) - .general((cmd)->cmd.lpop(key)) - .pipeline((cmd)->cmd.lpop(key)) - .transaction((cmd)->cmd.lpop(key)) - .run(args); + public byte[] lPop(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + } } @Override - public Long lPush(final String key, final String... values){ + public Long lPush(final String key, final String... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisClusterCommand(client, ProtocolCommand.LPUSH) - .general((cmd)->cmd.lpush(key, values)) - .pipeline((cmd)->cmd.lpush(key, values)) - .transaction((cmd)->cmd.lpush(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } } @Override - public Long lPush(final byte[] key, final byte[]... values){ + public Long lPush(final byte[] key, final byte[]... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisClusterCommand(client, ProtocolCommand.LPUSH) - .general((cmd)->cmd.lpush(key, values)) - .pipeline((cmd)->cmd.lpush(key, values)) - .transaction((cmd)->cmd.lpush(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } } @Override - public Long lPushX(final String key, final String... values){ + public Long lPushX(final String key, final String... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisClusterCommand(client, ProtocolCommand.LPUSHX) - .general((cmd)->cmd.lpushx(key, values)) - .pipeline((cmd)->cmd.lpushx(key, values)) - .transaction((cmd)->cmd.lpushx(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } } @Override - public Long lPushX(final byte[] key, final byte[]... values){ + public Long lPushX(final byte[] key, final byte[]... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisClusterCommand(client, ProtocolCommand.LPUSHX) - .general((cmd)->cmd.lpushx(key, values)) - .pipeline((cmd)->cmd.lpushx(key, values)) - .transaction((cmd)->cmd.lpushx(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } } @Override - public String rPop(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.RPOP) - .general((cmd)->cmd.rpop(key)) - .pipeline((cmd)->cmd.rpop(key)) - .transaction((cmd)->cmd.rpop(key)) - .run(args); + public String rPop(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + } } @Override - public byte[] rPop(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.RPOP) - .general((cmd)->cmd.rpop(key)) - .pipeline((cmd)->cmd.rpop(key)) - .transaction((cmd)->cmd.rpop(key)) - .run(args); + public byte[] rPop(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + } } @Override - public String rPoplPush(final String key, final String destKey){ + public String rPoplPush(final String key, final String destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisClusterCommand(client, ProtocolCommand.RPOPLPUSH) - .general((cmd)->cmd.rpoplpush(key, destKey)) - .pipeline((cmd)->cmd.rpoplpush(key, destKey)) - .transaction((cmd)->cmd.rpoplpush(key, destKey)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + } } @Override - public byte[] rPoplPush(final byte[] key, final byte[] destKey){ + public byte[] rPoplPush(final byte[] key, final byte[] destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisClusterCommand(client, ProtocolCommand.RPOPLPUSH) - .general((cmd)->cmd.rpoplpush(key, destKey)) - .pipeline((cmd)->cmd.rpoplpush(key, destKey)) - .transaction((cmd)->cmd.rpoplpush(key, destKey)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + } } @Override - public Long rPush(final String key, final String... values){ + public Long rPush(final String key, final String... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisClusterCommand(client, ProtocolCommand.RPUSH) - .general((cmd)->cmd.rpush(key, values)) - .pipeline((cmd)->cmd.rpush(key, values)) - .transaction((cmd)->cmd.rpush(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } } @Override - public Long rPush(final byte[] key, final byte[]... values){ + public Long rPush(final byte[] key, final byte[]... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisClusterCommand(client, ProtocolCommand.RPUSH) - .general((cmd)->cmd.rpush(key, values)) - .pipeline((cmd)->cmd.rpush(key, values)) - .transaction((cmd)->cmd.rpush(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } } @Override - public Long rPushX(final String key, final String... values){ + public Long rPushX(final String key, final String... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisClusterCommand(client, ProtocolCommand.RPUSHX) - .general((cmd)->cmd.rpushx(key, values)) - .pipeline((cmd)->cmd.rpushx(key, values)) - .transaction((cmd)->cmd.rpushx(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } } @Override - public Long rPushX(final byte[] key, final byte[]... values){ + public Long rPushX(final byte[] key, final byte[]... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisClusterCommand(client, ProtocolCommand.RPUSHX) - .general((cmd)->cmd.rpushx(key, values)) - .pipeline((cmd)->cmd.rpushx(key, values)) - .transaction((cmd)->cmd.rpushx(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterOperations.java index 3df551d69..1cff53ee3 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterOperations.java @@ -19,11 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.core.converter.ListConverter; import com.buession.lang.KeyValue; import com.buession.lang.Status; import com.buession.redis.client.jedis.JedisStandaloneClient; @@ -44,7 +45,7 @@ import com.buession.redis.core.internal.convert.jedis.response.ClusterResetOptionConverter; import com.buession.redis.core.internal.convert.response.ClusterNodeConverter; import com.buession.redis.core.internal.convert.response.ClusterSlotConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import redis.clients.jedis.args.ClusterResetType; import java.util.List; @@ -56,221 +57,446 @@ */ public final class JedisClusterOperations extends AbstractClusterOperations { - public JedisClusterOperations(final JedisStandaloneClient client){ + public JedisClusterOperations(final JedisStandaloneClient client) { super(client); } @Override - public String clusterMyId(){ - return new JedisCommand(client, ProtocolCommand.CLUSTER_MY_ID) - .general((cmd)->cmd.clusterMyId()) - .run(); + public String clusterMyId() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_MY_ID) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_MY_ID) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_MY_ID, (cmd)->cmd.clusterMyId(), (v)->v) + .run(); + } } @Override - public Status clusterAddSlots(final int... slots){ + public Status clusterAddSlots(final int... slots) { final CommandArguments args = CommandArguments.create("slots", slots); - return new JedisCommand(client, ProtocolCommand.CLUSTER_ADDSLOTS) - .general((cmd)->cmd.clusterAddSlots(slots), OkStatusConverter.INSTANCE) - .run(args); - } - @Override - public List clusterSlots(){ - return new JedisCommand>(client, ProtocolCommand.CLUSTER_SLOTS) - .general((cmd)->cmd.clusterSlots(), ClusterSlotConverter.LIST_CONVERTER) - .run(); + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_ADDSLOTS) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_ADDSLOTS) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_ADDSLOTS, (cmd)->cmd.clusterAddSlots(slots), + okStatusConverter) + .run(args); + } } @Override - public Integer clusterCountFailureReports(final String nodeId){ - final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisCommand(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) - .run(args); + public List clusterSlots() { + final ListConverter listClusterSlotConverter = ClusterSlotConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.CLUSTER_SLOTS) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_SLOTS) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_SLOTS, (cmd)->cmd.clusterSlots(), + listClusterSlotConverter) + .run(); + } } @Override - public Integer clusterCountFailureReports(final byte[] nodeId){ + public Integer clusterCountFailureReports(final String nodeId) { final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisCommand(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS, + (cmd)->cmd.clusterCountFailureReports(nodeId), Long::intValue) + .run(args); + } } @Override - public Long clusterCountKeysInSlot(final int slot){ + public Long clusterCountKeysInSlot(final int slot) { final CommandArguments args = CommandArguments.create("slot", slot); - return new JedisCommand(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT) - .general((cmd)->cmd.clusterCountKeysInSlot(slot)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + } } @Override - public Status clusterDelSlots(final int... slots){ + public Status clusterDelSlots(final int... slots) { final CommandArguments args = CommandArguments.create("slots", slots); - return new JedisCommand(client, ProtocolCommand.CLUSTER_DELSLOTS) - .general((cmd)->cmd.clusterDelSlots(slots), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_DELSLOTS) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_DELSLOTS) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_DELSLOTS, (cmd)->cmd.clusterDelSlots(slots), + okStatusConverter) + .run(args); + } } @Override - public Status clusterFlushSlots(){ - return new JedisCommand(client, ProtocolCommand.CLUSTER_FLUSHSLOTS) - .general((cmd)->cmd.clusterFlushSlots(), OkStatusConverter.INSTANCE) - .run(); + public Status clusterFlushSlots() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_FLUSHSLOTS) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_FLUSHSLOTS) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_FLUSHSLOTS, (cmd)->cmd.clusterFlushSlots(), + okStatusConverter) + .run(); + } } @Override - public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption){ + public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption) { final CommandArguments args = CommandArguments.create("clusterFailoverOption", clusterFailoverOption); - return new JedisCommand(client, ProtocolCommand.CLUSTER_FAILOVER) - .general((cmd)->cmd.clusterFailover( - ClusterFailoverOptionConverter.INSTANCE.convert(clusterFailoverOption)), - OkStatusConverter.INSTANCE) - .run(args); + final redis.clients.jedis.args.ClusterFailoverOption failoverOption = + (new ClusterFailoverOptionConverter()).convert(clusterFailoverOption); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_FAILOVER) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_FAILOVER) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_FAILOVER, + (cmd)->cmd.clusterFailover(failoverOption), okStatusConverter) + .run(args); + } } @Override - public Status clusterForget(final String nodeId){ + public Status clusterForget(final String nodeId) { final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisCommand(client, ProtocolCommand.CLUSTER_FORGET) - .general((cmd)->cmd.clusterForget(nodeId), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_FORGET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_FORGET) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_FORGET, (cmd)->cmd.clusterForget(nodeId), + okStatusConverter) + .run(args); + } } @Override - public List clusterGetKeysInSlot(final int slot, final long count){ + public List clusterGetKeysInSlot(final int slot, final long count) { final CommandArguments args = CommandArguments.create("slot", slot).put("count", count); - return new JedisCommand>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) - .general((cmd)->cmd.clusterGetKeysInSlot(slot, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, (int) count), (v)->v) + .run(args); + } } @Override - public Long clusterKeySlot(final String key){ + public Long clusterKeySlot(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) - .general((cmd)->cmd.clusterKeySlot(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, (cmd)->cmd.clusterKeySlot(key), + (v)->v) + .run(args); + } } @Override - public ClusterInfo clusterInfo(){ - return new JedisCommand(client, ProtocolCommand.CLUSTER_INFO) - .general((cmd)->cmd.clusterInfo(), ClusterInfoConverter.INSTANCE) - .run(); + public ClusterInfo clusterInfo() { + final ClusterInfoConverter clusterInfoConverter = new ClusterInfoConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_INFO) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_INFO) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_INFO, (cmd)->cmd.clusterInfo(), + clusterInfoConverter) + .run(); + } } @Override - public Status clusterMeet(final String ip, final int port){ + public Status clusterMeet(final String ip, final int port) { final CommandArguments args = CommandArguments.create("ip", ip).put("port", port); - return new JedisCommand(client, ProtocolCommand.CLUSTER_MEET) - .general((cmd)->cmd.clusterMeet(ip, port), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_MEET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_MEET) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_MEET, (cmd)->cmd.clusterMeet(ip, port), + okStatusConverter) + .run(args); + } } @Override - public List clusterNodes(){ - return new JedisCommand>(client, ProtocolCommand.CLUSTER_NODES) - .general((cmd)->cmd.clusterNodes(), ClusterNodesConverter.INSTANCE) - .run(); + public List clusterNodes() { + final ClusterNodesConverter clusterNodesConverter = new ClusterNodesConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_NODES) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_NODES) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_NODES, (cmd)->cmd.clusterNodes(), + clusterNodesConverter) + .run(); + } } @Override - public List clusterSlaves(final String nodeId){ + public List clusterSlaves(final String nodeId) { final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisCommand>(client, ProtocolCommand.CLUSTER_SLAVES) - .general((cmd)->cmd.clusterSlaves(nodeId), ClusterNodeConverter.LIST_CONVERTER) - .run(args); + final ListConverter listClusterNodeConverter = ClusterNodeConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_SLAVES) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_SLAVES) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_SLAVES, (cmd)->cmd.clusterSlaves(nodeId), + listClusterNodeConverter) + .run(args); + } } @Override - public List clusterReplicas(final String nodeId){ + public List clusterReplicas(final String nodeId) { final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisCommand>(client, ProtocolCommand.CLUSTER_REPLICAS) - .general((cmd)->cmd.clusterReplicas(nodeId), ClusterReplicasConverter.LIST_CONVERTER) - .run(args); + final ListConverter listClusterReplicasConverter = ClusterReplicasConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_REPLICAS) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_REPLICAS) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_REPLICAS, (cmd)->cmd.clusterReplicas(nodeId), + listClusterReplicasConverter) + .run(args); + } } @Override - public Status clusterReplicate(final String nodeId){ + public Status clusterReplicate(final String nodeId) { final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisCommand(client, ProtocolCommand.CLUSTER_REPLICATE) - .general((cmd)->cmd.clusterReplicate(nodeId), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_REPLICATE) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_REPLICATE) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_REPLICATE, (cmd)->cmd.clusterReplicate(nodeId), + okStatusConverter) + .run(args); + } } @Override - public Status clusterReset(final ClusterResetOption clusterResetOption){ + public Status clusterReset(final ClusterResetOption clusterResetOption) { final CommandArguments args = CommandArguments.create("clusterResetOption", clusterResetOption); - return new JedisCommand(client, ProtocolCommand.CLUSTER_RESET) - .general((cmd)->cmd.clusterReset(ClusterResetOptionConverter.INSTANCE.convert(clusterResetOption)), - OkStatusConverter.INSTANCE) - .run(args); + final ClusterResetType clusterResetType = (new ClusterResetOptionConverter()).convert(clusterResetOption); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_RESET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_RESET) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_RESET, + (cmd)->cmd.clusterReset(clusterResetType), okStatusConverter) + .run(args); + } } @Override - public Status clusterSaveConfig(){ - return new JedisCommand(client, ProtocolCommand.CLUSTER_SAVECONFIG) - .general((cmd)->cmd.clusterSaveConfig(), OkStatusConverter.INSTANCE) - .run(); + public Status clusterSaveConfig() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_SAVECONFIG) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_SAVECONFIG) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_SAVECONFIG, (cmd)->cmd.clusterSaveConfig(), + okStatusConverter) + .run(); + } } @Override - public Status clusterSetConfigEpoch(final long configEpoch){ + public Status clusterSetConfigEpoch(final long configEpoch) { final CommandArguments args = CommandArguments.create("configEpoch", configEpoch); - return new JedisCommand(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH) - .general((cmd)->cmd.clusterSetConfigEpoch(configEpoch), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + } } @Override - public KeyValue clusterBumpEpoch(){ - return new JedisCommand>(client, ProtocolCommand.CLUSTER_BUMPEPOCH) - .general((cmd)->cmd.clusterBumpEpoch(), BumpEpochConverter.INSTANCE) - .run(); + public KeyValue clusterBumpEpoch() { + final BumpEpochConverter bumpEpochConverter = new BumpEpochConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, KeyValue>(client, + ProtocolCommand.CLUSTER_BUMPEPOCH) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, KeyValue>(client, + ProtocolCommand.CLUSTER_BUMPEPOCH) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_BUMPEPOCH, (cmd)->cmd.clusterBumpEpoch(), + bumpEpochConverter) + .run(); + } } @Override - public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId){ + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId) { final CommandArguments args = CommandArguments.create("slot", slot).put("setSlotOption", setSlotOption) .put("nodeId", nodeId); - return new JedisCommand(client, ProtocolCommand.CLUSTER_SETSLOT) - .general((cmd)->{ - switch(setSlotOption){ - case IMPORTING: - return cmd.clusterSetSlotImporting(slot, nodeId); - case MIGRATING: - return cmd.clusterSetSlotMigrating(slot, nodeId); - case STABLE: - return cmd.clusterSetSlotStable(slot); - case NODE: - return cmd.clusterSetSlotNode(slot, nodeId); - default: - return null; - } - }, OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLUSTER_SETSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLUSTER_SETSLOT) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + } } @Override - public Status asking(){ - return new JedisCommand(client, ProtocolCommand.ASKING) - .general((cmd)->cmd.asking(), OkStatusConverter.INSTANCE) - .run(); + public Status asking() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.ASKING) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.ASKING) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ASKING, (cmd)->cmd.asking(), okStatusConverter) + .run(); + } } @Override - public Status readWrite(){ - return new JedisCommand(client, ProtocolCommand.READWRITE) - .general((cmd)->cmd.readwrite(), OkStatusConverter.INSTANCE) - .run(); + public Status readWrite() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.READWRITE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.READWRITE) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.READWRITE, (cmd)->cmd.readwrite(), + okStatusConverter) + .run(); + } } @Override - public Status readOnly(){ - return new JedisCommand(client, ProtocolCommand.READONLY) - .general((cmd)->cmd.readonly(), OkStatusConverter.INSTANCE) - .run(); + public Status readOnly() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.READONLY) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.READONLY) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.READONLY, (cmd)->cmd.readonly(), okStatusConverter) + .run(); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterPubSubOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterPubSubOperations.java index d1f1acf77..5fcecf884 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterPubSubOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterPubSubOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -42,156 +42,282 @@ */ public class JedisClusterPubSubOperations extends AbstractPubSubOperations { - public JedisClusterPubSubOperations(final JedisClusterClient client){ + public JedisClusterPubSubOperations(final JedisClusterClient client) { super(client); } @Override - public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener){ + public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener) { final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) .put("pubSubListener", pubSubListener); - new JedisClusterCommand(client, ProtocolCommand.PSUBSCRIBE) - .general((cmd)->{ - cmd.psubscribe(new DefaultJedisPubSub(pubSubListener), patterns); - return null; - }) - .run(args); + + if(isPipeline()){ + new JedisClusterPipelineCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisClusterTransactionCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else{ + new JedisClusterCommand<>(client, ProtocolCommand.PSUBSCRIBE, (cmd)->{ + cmd.psubscribe(new DefaultJedisPubSub(pubSubListener), patterns); + return null; + }, (v)->v) + .run(args); + } } @Override - public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener){ + public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener) { final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) .put("pubSubListener", pubSubListener); - new JedisClusterCommand(client, ProtocolCommand.PSUBSCRIBE) - .general((cmd)->{ - cmd.psubscribe(new DefaultBinaryJedisPubSub(pubSubListener), patterns); - return null; - }) - .run(args); + + if(isPipeline()){ + new JedisClusterPipelineCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisClusterTransactionCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else{ + new JedisClusterCommand<>(client, ProtocolCommand.PSUBSCRIBE, (cmd)->{ + cmd.psubscribe(new DefaultBinaryJedisPubSub(pubSubListener), patterns); + return null; + }, (v)->v) + .run(args); + } } @Override - public Long publish(final String channel, final String message){ + public Long publish(final String channel, final String message) { final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); - return new JedisClusterCommand(client, ProtocolCommand.PUBLISH) - .general((cmd)->cmd.publish(channel, message)) - .pipeline((cmd)->cmd.publish(channel, message)) - .transaction((cmd)->cmd.publish(channel, message)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PUBLISH, + (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.PUBLISH) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + } } @Override - public Long publish(final byte[] channel, final byte[] message){ + public Long publish(final byte[] channel, final byte[] message) { final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); - return new JedisClusterCommand(client, ProtocolCommand.PUBLISH) - .general((cmd)->cmd.publish(channel, message)) - .pipeline((cmd)->cmd.publish(channel, message)) - .transaction((cmd)->cmd.publish(channel, message)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PUBLISH, + (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.PUBLISH) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + } } @Override - public List pubsubChannels(){ - return new JedisClusterCommand>(client, ProtocolCommand.PUBSUB_CHANNELS) - .run(); + public List pubsubChannels() { + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, + ProtocolCommand.PUBSUB_CHANNELS) + .run(); + }else{ + return new JedisClusterCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(); + } } @Override - public List pubsubChannels(final String pattern){ + public List pubsubChannels(final String pattern) { final CommandArguments args = CommandArguments.create("pattern", pattern); - return new JedisClusterCommand>(client, ProtocolCommand.PUBSUB_CHANNELS) - .run(args); + return pubsubChannels(args); } @Override - public List pubsubChannels(final byte[] pattern){ + public List pubsubChannels(final byte[] pattern) { final CommandArguments args = CommandArguments.create("pattern", pattern); - return new JedisClusterCommand>(client, ProtocolCommand.PUBSUB_CHANNELS) - .run(args); + return pubsubChannels(args); } @Override - public Long pubsubNumPat(){ - return new JedisClusterCommand(client, ProtocolCommand.PUBSUB_NUMPAT) - .run(); + public Long pubsubNumPat() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.PUBSUB_NUMPAT) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.PUBSUB_NUMPAT) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.PUBSUB_NUMPAT) + .run(); + } } @Override - public Map pubsubNumSub(final String... channels){ + public Map pubsubNumSub(final String... channels) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); - return new JedisClusterCommand>(client, ProtocolCommand.PUBSUB_NUMSUB) - .run(args); + return pubsubNumSub(args); } @Override - public Map pubsubNumSub(final byte[]... channels){ + public Map pubsubNumSub(final byte[]... channels) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); - return new JedisClusterCommand>(client, ProtocolCommand.PUBSUB_NUMSUB) - .run(args); + return pubsubNumSub(args); } @Override - public Object pUnSubscribe(){ - return new JedisClusterCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) - .run(); + public Object pUnSubscribe() { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + } } @Override - public Object pUnSubscribe(final String... patterns){ + public Object pUnSubscribe(final String... patterns) { final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); - return new JedisClusterCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) - .run(args); + return pUnSubscribe(args); } @Override - public Object pUnSubscribe(final byte[]... patterns){ + public Object pUnSubscribe(final byte[]... patterns) { final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); - return new JedisClusterCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) - .run(args); + return pUnSubscribe(args); } @Override - public void subscribe(final String[] channels, final PubSubListener pubSubListener){ + public void subscribe(final String[] channels, final PubSubListener pubSubListener) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) .put("pubSubListener", pubSubListener); - new JedisClusterCommand(client, ProtocolCommand.PUBLISH) - .general((cmd)->{ - cmd.subscribe(new DefaultJedisPubSub(pubSubListener), channels); - return null; - }) - .run(args); + + if(isPipeline()){ + new JedisClusterPipelineCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisClusterTransactionCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else{ + new JedisClusterCommand<>(client, ProtocolCommand.SUBSCRIBE, (cmd)->{ + cmd.subscribe(new DefaultJedisPubSub(pubSubListener), channels); + return null; + }, (v)->v) + .run(args); + } } @Override - public void subscribe(final byte[][] channels, final PubSubListener pubSubListener){ + public void subscribe(final byte[][] channels, final PubSubListener pubSubListener) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) .put("pubSubListener", pubSubListener); - new JedisClusterCommand(client, ProtocolCommand.PUBLISH) - .general((cmd)->{ - cmd.subscribe(new DefaultBinaryJedisPubSub(pubSubListener), channels); - return null; - }) - .run(args); + + if(isPipeline()){ + new JedisClusterPipelineCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisClusterTransactionCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else{ + new JedisClusterCommand<>(client, ProtocolCommand.SUBSCRIBE, (cmd)->{ + cmd.subscribe(new DefaultBinaryJedisPubSub(pubSubListener), channels); + return null; + }, (v)->v) + .run(args); + } } @Override - public Object unSubscribe(){ - return new JedisClusterCommand<>(client, ProtocolCommand.UNSUBSCRIBE) - .run(); + public Object unSubscribe() { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + } } @Override - public Object unSubscribe(final String... channels){ + public Object unSubscribe(final String... channels) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); - return new JedisClusterCommand<>(client, ProtocolCommand.UNSUBSCRIBE) - .run(args); + return unSubscribe(args); } @Override - public Object unSubscribe(final byte[]... channels){ + public Object unSubscribe(final byte[]... channels) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); - return new JedisClusterCommand<>(client, ProtocolCommand.UNSUBSCRIBE) - .run(args); + return unSubscribe(args); + } + + private List pubsubChannels(final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(args); + }else{ + return new JedisClusterCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(); + } + } + + private Map pubsubNumSub(final CommandArguments args) { + + if(isPipeline()){ + return new JedisClusterPipelineCommand, Map>(client, ProtocolCommand.PUBSUB_NUMSUB) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, Map>(client, ProtocolCommand.PUBSUB_NUMSUB) + .run(args); + }else{ + return new JedisClusterCommand, Map>(client, ProtocolCommand.PUBSUB_NUMSUB) + .run(args); + } + } + + private Object pUnSubscribe(final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + } + } + + private Object unSubscribe(final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterScriptingOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterScriptingOperations.java index 083ff4c55..6b1134c25 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterScriptingOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterScriptingOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -30,7 +30,7 @@ import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; import com.buession.redis.core.internal.convert.jedis.params.FlushModeConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import com.buession.redis.utils.SafeEncoder; import java.util.Arrays; import java.util.List; @@ -43,205 +43,373 @@ */ public final class JedisClusterScriptingOperations extends AbstractScriptingOperations { - public JedisClusterScriptingOperations(final JedisClusterClient client){ + public JedisClusterScriptingOperations(final JedisClusterClient client) { super(client); } @Override - public Object eval(final String script){ - final CommandArguments args = CommandArguments.create("script", script); - return new JedisClusterCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script)) - .pipeline((cmd)->cmd.eval(script)) - .transaction((cmd)->cmd.eval(script)) - .run(args); + public Object eval(final String script) { + final CommandArguments args = CommandArguments.create(script); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + } } @Override - public Object eval(final byte[] script){ - final CommandArguments args = CommandArguments.create("script", script); - return new JedisClusterCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script)) - .pipeline((cmd)->cmd.eval(script)) - .transaction((cmd)->cmd.eval(script)) - .run(args); + public Object eval(final byte[] script) { + final CommandArguments args = CommandArguments.create(script); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + } } @Override - public Object eval(final String script, final String... params){ - final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + public Object eval(final String script, final String... params) { + final CommandArguments args = CommandArguments.create(script).add(params); final int paramsSize = params == null ? 0 : params.length; - return new JedisClusterCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script, paramsSize, params)) - .pipeline((cmd)->cmd.eval(script, paramsSize, params)) - .transaction((cmd)->cmd.eval(script, paramsSize, params)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script, paramsSize, params), + (v)->v) + .run(args); + } } @Override - public Object eval(final byte[] script, final byte[]... params){ - final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + public Object eval(final byte[] script, final byte[]... params) { + final CommandArguments args = CommandArguments.create(script).add(params); final int paramsSize = params == null ? 0 : params.length; - return new JedisClusterCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script, paramsSize, params)) - .pipeline((cmd)->cmd.eval(script, paramsSize, params)) - .transaction((cmd)->cmd.eval(script, paramsSize, params)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script, paramsSize, params), + (v)->v) + .run(args); + } } @Override - public Object eval(final String script, final String[] keys, final String[] arguments){ + public Object eval(final String script, final String[] keys, final String[] arguments) { final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) .put("arguments", (Object[]) arguments); - return new JedisClusterCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .pipeline((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .transaction((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .run(args); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + } } @Override - public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments){ + public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments) { final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) .put("arguments", (Object[]) arguments); - return new JedisClusterCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .pipeline((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .transaction((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .run(args); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + } } @Override - public Object evalSha(final String digest){ + public Object evalSha(final String digest) { final CommandArguments args = CommandArguments.create("digest", digest); - return new JedisClusterCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest)) - .pipeline((cmd)->cmd.evalsha(digest)) - .transaction((cmd)->cmd.evalsha(digest)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + } } @Override - public Object evalSha(final byte[] digest){ + public Object evalSha(final byte[] digest) { final CommandArguments args = CommandArguments.create("digest", digest); - return new JedisClusterCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest)) - .pipeline((cmd)->cmd.evalsha(digest)) - .transaction((cmd)->cmd.evalsha(digest)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + } } @Override - public Object evalSha(final String digest, final String... params){ + public Object evalSha(final String digest, final String... params) { final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); final int paramsSize = params == null ? 0 : params.length; - return new JedisClusterCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest, paramsSize, params)) - .pipeline((cmd)->cmd.evalsha(digest, paramsSize, params)) - .transaction((cmd)->cmd.evalsha(digest, paramsSize, params)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + } } @Override - public Object evalSha(final byte[] digest, final byte[]... params){ + public Object evalSha(final byte[] digest, final byte[]... params) { final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); final int paramsSize = params == null ? 0 : params.length; - return new JedisClusterCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest, paramsSize, params)) - .pipeline((cmd)->cmd.evalsha(digest, paramsSize, params)) - .transaction((cmd)->cmd.evalsha(digest, paramsSize, params)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + } } @Override - public Object evalSha(final String digest, final String[] keys, final String[] arguments){ + public Object evalSha(final String digest, final String[] keys, final String[] arguments) { final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) .put("arguments", (Object[]) arguments); - return new JedisClusterCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .pipeline((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .transaction((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .run(args); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + } } @Override - public Object evalSha(final byte[] digest, final byte[][] keys, final byte[][] arguments){ + public Object evalSha(final byte[] digest, final byte[][] keys, final byte[][] arguments) { final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) .put("arguments", (Object[]) arguments); - return new JedisClusterCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .pipeline((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .transaction((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .run(args); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + } } @Override - public List scriptExists(final String... sha1){ - final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); - return new JedisClusterCommand>(client, ProtocolCommand.SCRIPT_EXISTS) - .general((cmd)->cmd.scriptExists(null, sha1)) - .pipeline((cmd)->cmd.scriptExists(null, sha1)) - .transaction((cmd)->cmd.scriptExists(null, sha1)) - .run(args); + public List scriptExists(final String... sha1) { + final CommandArguments args = CommandArguments.create(sha1); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + } } @Override - public List scriptExists(final byte[]... sha1){ - final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); - return new JedisClusterCommand>(client, ProtocolCommand.SCRIPT_EXISTS) - .general((cmd)->cmd.scriptExists(null, sha1)) - .pipeline((cmd)->cmd.scriptExists(null, sha1)) - .transaction((cmd)->cmd.scriptExists(null, sha1)) - .run(args); + public List scriptExists(final byte[]... sha1) { + final CommandArguments args = CommandArguments.create(sha1); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + } } @Override - public Status scriptFlush(){ - return new JedisClusterCommand(client, ProtocolCommand.SCRIPT_FLUSH) - .general((cmd)->cmd.scriptFlush((String) null), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.scriptFlush((String) null), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.scriptFlush((String) null), OkStatusConverter.INSTANCE) - .run(); + public Status scriptFlush() { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null), okStatusConverter) + .run(); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(); + } } @Override - public Status scriptFlush(final FlushMode mode){ + public Status scriptFlush(final FlushMode mode) { final CommandArguments args = CommandArguments.create("mode", mode); - final redis.clients.jedis.args.FlushMode flushMode = FlushModeConverter.INSTANCE.convert(mode); - return new JedisClusterCommand(client, ProtocolCommand.SCRIPT_FLUSH) - .general((cmd)->cmd.scriptFlush((String) null, flushMode), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.scriptFlush((String) null, flushMode), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.scriptFlush((String) null, flushMode), OkStatusConverter.INSTANCE) - .run(args); + final redis.clients.jedis.args.FlushMode flushMode = (new FlushModeConverter()).convert(mode); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null, flushMode), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null, flushMode), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null, flushMode), okStatusConverter) + .run(args); + } } @Override - public String scriptLoad(final String script){ + public String scriptLoad(final String script) { final CommandArguments args = CommandArguments.create("script", script); - return new JedisClusterCommand(client, ProtocolCommand.SCRIPT_LOAD) - .general((cmd)->cmd.scriptLoad(script, null)) - .pipeline((cmd)->cmd.scriptLoad(script, null)) - .transaction((cmd)->cmd.scriptLoad(script, null)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), (v)->v) + .run(args); + } } @Override - public byte[] scriptLoad(final byte[] script){ + public byte[] scriptLoad(final byte[] script) { final CommandArguments args = CommandArguments.create("script", script); - return new JedisClusterCommand(client, ProtocolCommand.SCRIPT_LOAD) - .general((cmd)->cmd.scriptLoad(script, null)) - .pipeline((cmd)->cmd.scriptLoad(script, null)) - .transaction((cmd)->cmd.scriptLoad(script, null)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(SafeEncoder.encode(script)), SafeEncoder::encode) + .run(args); + } } @Override - public Status scriptKill(){ - return new JedisClusterCommand(client, ProtocolCommand.SCRIPT_KILL) - .general((cmd)->cmd.scriptKill((String) null), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.scriptKill((String) null), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.scriptKill((String) null), OkStatusConverter.INSTANCE) - .run(); + public Status scriptKill() { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SCRIPT_KILL, + (cmd)->cmd.scriptKill((String) null), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SCRIPT_KILL, + (cmd)->cmd.scriptKill((String) null), okStatusConverter) + .run(); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterServerOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterServerOperations.java index 007ad76cb..ce706152a 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterServerOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterServerOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -38,8 +38,11 @@ import com.buession.redis.core.SlowLog; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.utils.SafeEncoder; +import redis.clients.jedis.args.SaveMode; import java.util.List; +import java.util.Map; /** * Jedis 集群模式服务端命令操作 @@ -49,451 +52,959 @@ */ public final class JedisClusterServerOperations extends AbstractServerOperations { - public JedisClusterServerOperations(final JedisClusterClient client){ + public JedisClusterServerOperations(final JedisClusterClient client) { super(client); } @Override - public List aclCat(){ - return new JedisClusterCommand>(client, ProtocolCommand.ACL_CAT) - .run(); + public List aclCat() { + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else{ + return new JedisClusterCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + } } @Override - public List aclCat(final String categoryName){ + public List aclCat(final String categoryName) { final CommandArguments args = CommandArguments.create("categoryName", categoryName); - return new JedisClusterCommand>(client, ProtocolCommand.ACL_CAT) - .run(args); + return aclCat(args); } @Override - public List aclCat(final byte[] categoryName){ + public List aclCat(final byte[] categoryName) { final CommandArguments args = CommandArguments.create("categoryName", categoryName); - return new JedisClusterCommand>(client, ProtocolCommand.ACL_CAT) - .run(args); + return aclCat(args); } @Override - public Status aclSetUser(final String username, final String... rules){ + public Status aclSetUser(final String username, final String... rules) { final CommandArguments args = CommandArguments.create("username", username).put("rules", (Object[]) rules); - return new JedisClusterCommand(client, ProtocolCommand.ACL_SETUSER) - .run(args); + return aclSetUser(args); } @Override - public Status aclSetUser(final byte[] username, final byte[]... rules){ + public Status aclSetUser(final byte[] username, final byte[]... rules) { final CommandArguments args = CommandArguments.create("username", username).put("rules", (Object[]) rules); - return new JedisClusterCommand(client, ProtocolCommand.ACL_SETUSER) - .run(args); + return aclSetUser(args); } @Override - public AclUser aclGetUser(final String username){ + public AclUser aclGetUser(final String username) { final CommandArguments args = CommandArguments.create("username", username); - return new JedisClusterCommand(client, ProtocolCommand.ACL_GETUSER) - .run(args); + return aclGetUser(args); } @Override - public AclUser aclGetUser(final byte[] username){ + public AclUser aclGetUser(final byte[] username) { final CommandArguments args = CommandArguments.create("username", username); - return new JedisClusterCommand(client, ProtocolCommand.ACL_GETUSER) - .run(args); + return aclGetUser(args); } @Override - public List aclUsers(){ - return new JedisClusterCommand>(client, ProtocolCommand.ACL_USERS) - .run(); + public List aclUsers() { + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + }else{ + return new JedisClusterCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + } } @Override - public String aclWhoAmI(){ - return new JedisClusterCommand(client, ProtocolCommand.ACL_WHOAMI) - .run(); + public String aclWhoAmI() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + } } @Override - public Long aclDelUser(final String... usernames){ + public Long aclDelUser(final String... usernames) { final CommandArguments args = CommandArguments.create("usernames", (Object[]) usernames); - return new JedisClusterCommand(client, ProtocolCommand.ACL_DELUSER) - .run(args); + return aclDelUser(args); } @Override - public Long aclDelUser(final byte[]... usernames){ + public Long aclDelUser(final byte[]... usernames) { final CommandArguments args = CommandArguments.create("usernames", (Object[]) usernames); - return new JedisClusterCommand(client, ProtocolCommand.ACL_DELUSER) - .run(args); + return aclDelUser(args); } @Override - public String aclGenPass(){ - return new JedisClusterCommand(client, ProtocolCommand.ACL_GENPASS) - .run(); + public String aclGenPass() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + } } @Override - public List aclList(){ - return new JedisClusterCommand>(client, ProtocolCommand.ACL_LIST) - .run(); + public List aclList() { + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + }else{ + return new JedisClusterCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + } } @Override - public Status aclLoad(){ - return new JedisClusterCommand(client, ProtocolCommand.ACL_LOAD) - .run(); + public Status aclLoad() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + } } @Override - public List aclLog(){ - return new JedisClusterCommand>(client, ProtocolCommand.ACL_LOG) - .run(); + public List aclLog() { + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + }else{ + return new JedisClusterCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + } } @Override - public List aclLog(final long count){ + public List aclLog(final long count) { final CommandArguments args = CommandArguments.create("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ACL_LOG) - .run(args); - } - - @Override - public Status aclLogReset(){ - return new JedisClusterCommand(client, ProtocolCommand.ACL_LOGREST) - .run(); - } - - @Override - public Status aclLogSave(){ - return new JedisClusterCommand(client, ProtocolCommand.ACL_LOGSAVE) - .run(); - } - - @Override - public String bgRewriteAof(){ - return new JedisClusterCommand(client, ProtocolCommand.BGREWRITEAOF) - .run(); - } - @Override - public String bgSave(){ - return new JedisClusterCommand(client, ProtocolCommand.BGREWRITEAOF) - .run(); - } - - @Override - public Status configSet(final String parameter, final String value){ + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + }else{ + return new JedisClusterCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + } + } + + @Override + public Status aclLogReset() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + } + } + + @Override + public Status aclLogSave() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + } + } + + @Override + public String bgRewriteAof() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + } + } + + @Override + public String bgSave() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.BGSAVE) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.BGSAVE) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.BGSAVE) + .run(); + } + } + + @Override + public Status configSet(final String parameter, final String value) { final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.CONFIG_SET) - .run(args); + return configSet(parameter, value, args); } @Override - public Status configSet(final byte[] parameter, final byte[] value){ + public Status configSet(final byte[] parameter, final byte[] value) { final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.CONFIG_SET) - .run(args); - } - - @Override - public List configGet(final String parameter){ - final CommandArguments args = CommandArguments.create("parameter", parameter); - return new JedisClusterCommand>(client, ProtocolCommand.CONFIG_GET) - .run(args); - } - - @Override - public List configGet(final byte[] parameter){ - final CommandArguments args = CommandArguments.create("parameter", parameter); - return new JedisClusterCommand>(client, ProtocolCommand.CONFIG_GET) - .run(args); - } - - @Override - public Status configResetStat(){ - return new JedisClusterCommand(client, ProtocolCommand.CONFIG_RESETSTAT) - .run(); - } - - @Override - public Status configRewrite(){ - return new JedisClusterCommand(client, ProtocolCommand.CONFIG_REWRITE) - .run(); - } - - @Override - public Long dbSize(){ - return new JedisClusterCommand(client, ProtocolCommand.DBSIZE) - .general((cmd)->cmd.dbSize()) - .pipeline((cmd)->cmd.dbSize()) - .run(); - } - - @Override - public Status failover(){ - return new JedisClusterCommand(client, ProtocolCommand.FAILOVER) - .run(); - } - - @Override - public Status failover(final String host, final int port){ + final String sParameter = SafeEncoder.encode(parameter); + final String sValue = SafeEncoder.encode(value); + + return configSet(sParameter, sValue, args); + } + + @Override + public Status configSet(final Map configs) { + final CommandArguments args = CommandArguments.create("configs", configs); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.CONFIG_SET, (cmd)->{ + configs.forEach(cmd::configSet); + return Status.SUCCESS; + }, (v)->v) + .run(args); + } + } + + @Override + public Map configGet(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + + if(isPipeline()){ + return new JedisClusterPipelineCommand, Map>(client, + ProtocolCommand.CONFIG_GET) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, Map>(client, + ProtocolCommand.CONFIG_GET) + .run(args); + }else{ + return new JedisClusterCommand, Map>(client, ProtocolCommand.CONFIG_GET) + .run(args); + } + } + + @Override + public Map configGet(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + + if(isPipeline()){ + return new JedisClusterPipelineCommand, Map>(client, + ProtocolCommand.CONFIG_GET) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, Map>(client, + ProtocolCommand.CONFIG_GET) + .run(args); + }else{ + return new JedisClusterCommand, Map>(client, ProtocolCommand.CONFIG_GET) + .run(args); + } + } + + @Override + public Status configResetStat() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CONFIG_RESETSTAT) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CONFIG_RESETSTAT) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CONFIG_RESETSTAT) + .run(); + } + } + + @Override + public Status configRewrite() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CONFIG_REWRITE) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CONFIG_REWRITE) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.CONFIG_REWRITE) + .run(); + } + } + + @Override + public Long dbSize() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.DBSIZE) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.DBSIZE) + .run(); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.DBSIZE, (cmd)->cmd.dbSize(), (v)->v) + .run(); + } + } + + @Override + public Status failover() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.FAILOVER) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.FAILOVER) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.FAILOVER) + .run(); + } + } + + @Override + public Status failover(final String host, final int port) { final CommandArguments args = CommandArguments.create("host", host).put("port", port); - return new JedisClusterCommand(client, ProtocolCommand.FAILOVER) - .run(args); + return failover(args); } @Override - public Status failover(final String host, final int port, final int timeout){ + public Status failover(final String host, final int port, final int timeout) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("timeout", timeout); - return new JedisClusterCommand(client, ProtocolCommand.FAILOVER) - .run(args); + return failover(args); } @Override - public Status failover(final String host, final int port, final boolean isForce, final int timeout){ + public Status failover(final String host, final int port, final boolean isForce, final int timeout) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("isForce", isForce) .put("timeout", timeout); - return new JedisClusterCommand(client, ProtocolCommand.FAILOVER) - .run(args); + return failover(args); } @Override - public Status failover(final int timeout){ + public Status failover(final int timeout) { final CommandArguments args = CommandArguments.create("timeout", timeout); - return new JedisClusterCommand(client, ProtocolCommand.FAILOVER) - .run(args); + return failover(args); } @Override - public Status flushAll(){ - return new JedisClusterCommand(client, ProtocolCommand.FLUSHALL) - .run(); + public Status flushAll() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.FLUSHALL) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.FLUSHALL) + .run(); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.FLUSHALL, (cmd)->cmd.flushAll(), okStatusConverter) + .run(); + } } @Override - public Status flushAll(final FlushMode mode){ + public Status flushAll(final FlushMode mode) { final CommandArguments args = CommandArguments.create("mode", mode); - return new JedisClusterCommand(client, ProtocolCommand.FLUSHALL) - .run(args); - } - @Override - public Status flushDb(){ - return new JedisClusterCommand(client, ProtocolCommand.FLUSHDB) - .run(); + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.FLUSHALL) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.FLUSHALL) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.FLUSHALL, (cmd)->cmd.flushAll(), + okStatusConverter) + .run(args); + } } @Override - public Status flushDb(final FlushMode mode){ - final CommandArguments args = CommandArguments.create("mode", mode); - return new JedisClusterCommand(client, ProtocolCommand.FLUSHDB) - .run(args); + public Status flushDb() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.FLUSHDB) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.FLUSHDB) + .run(); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.flushDB(), okStatusConverter) + .run(); + } } @Override - public Info info(){ - return new JedisClusterCommand(client, ProtocolCommand.INFO) - .run(); - } - - @Override - public Info info(final Info.Section section){ - final CommandArguments args = CommandArguments.create("section", section); - return new JedisClusterCommand(client, ProtocolCommand.INFO) - .run(args); - } + public Status flushDb(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); - @Override - public Long lastSave(){ - return new JedisClusterCommand(client, ProtocolCommand.LASTSAVE) - .run(); + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.FLUSHDB) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.FLUSHDB) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.flushDB(), + okStatusConverter) + .run(args); + } } @Override - public String memoryDoctor(){ - return new JedisClusterCommand(client, ProtocolCommand.MEMORY_DOCTOR) - .run(); + public Info info() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.INFO) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.INFO) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.INFO) + .run(); + } } @Override - public Status memoryPurge(){ - return new JedisClusterCommand(client, ProtocolCommand.MEMORY_PURGE) - .run(); - } + public Info info(final Info.Section section) { + final CommandArguments args = CommandArguments.create("section", section); + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.INFO) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.INFO) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.INFO) + .run(args); + } + } + + @Override + public Long lastSave() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.LASTSAVE) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.LASTSAVE) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.LASTSAVE) + .run(); + } + } + + @Override + public String memoryDoctor() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + } + } + + @Override + public Status memoryPurge() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + } + } + + @Override + public MemoryStats memoryStats() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + } + } + + @Override + public Long memoryUsage(final String key) { + final CommandArguments args = CommandArguments.create("key", key); - @Override - public MemoryStats memoryStats(){ - return new JedisClusterCommand(client, ProtocolCommand.MEMORY_STATS) - .run(); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } } @Override - public Long memoryUsage(final String key){ + public Long memoryUsage(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.MEMORY_USAGE) - .general((cmd)->cmd.memoryUsage(key)) - .pipeline((cmd)->cmd.memoryUsage(key)) - .transaction((cmd)->cmd.memoryUsage(key)) - .run(args); - } - @Override - public Long memoryUsage(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.MEMORY_USAGE) - .general((cmd)->cmd.memoryUsage(key)) - .pipeline((cmd)->cmd.memoryUsage(key)) - .transaction((cmd)->cmd.memoryUsage(key)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } } @Override - public Long memoryUsage(final String key, final int samples){ + public Long memoryUsage(final String key, final int samples) { final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); - return new JedisClusterCommand(client, ProtocolCommand.MEMORY_USAGE) - .general((cmd)->cmd.memoryUsage(key, samples)) - .pipeline((cmd)->cmd.memoryUsage(key, samples)) - .transaction((cmd)->cmd.memoryUsage(key, samples)) - .run(args); - } - @Override - public Long memoryUsage(final byte[] key, final int samples){ - final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); - return new JedisClusterCommand(client, ProtocolCommand.MEMORY_USAGE) - .general((cmd)->cmd.memoryUsage(key, samples)) - .pipeline((cmd)->cmd.memoryUsage(key, samples)) - .transaction((cmd)->cmd.memoryUsage(key, samples)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key, samples), + (v)->v) + .run(args); + } } @Override - public List moduleList(){ - return new JedisClusterCommand>(client, ProtocolCommand.MODULE_LIST) - .run(); - } + public Long memoryUsage(final byte[] key, final int samples) { + final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); - @Override - public Status moduleLoad(final String path, final String... arguments){ + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key, samples), + (v)->v) + .run(args); + } + } + + @Override + public List moduleList() { + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, ProtocolCommand.MODULE_LIST) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, ProtocolCommand.MODULE_LIST) + .run(); + }else{ + return new JedisClusterCommand, List>(client, ProtocolCommand.MODULE_LIST) + .run(); + } + } + + @Override + public Status moduleLoad(final String path, final String... arguments) { final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); - return new JedisClusterCommand(client, ProtocolCommand.MODULE_LOAD) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + } } @Override - public Status moduleUnLoad(final String name){ + public Status moduleUnLoad(final String name) { final CommandArguments args = CommandArguments.create("name", name); - return new JedisClusterCommand(client, ProtocolCommand.MODULE_UNLOAD) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + } } @Override - public void monitor(final RedisMonitor redisMonitor){ + public void monitor(final RedisMonitor redisMonitor) { final CommandArguments args = CommandArguments.create("redisMonitor", redisMonitor); - new JedisClusterCommand(client, ProtocolCommand.MONITOR) - .run(args); - } - @Override - public Object pSync(final String replicationId, final long offset){ - final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); - return new JedisClusterCommand<>(client, ProtocolCommand.PSYNC) - .run(args); + if(isPipeline()){ + new JedisClusterPipelineCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + }else if(isTransaction()){ + new JedisClusterTransactionCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + }else{ + new JedisClusterCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + } } @Override - public Object pSync(final byte[] replicationId, final long offset){ + public Object pSync(final String replicationId, final long offset) { final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); - return new JedisClusterCommand<>(client, ProtocolCommand.PSYNC) - .run(args); + return pSync(args); } @Override - public void sync(){ - new JedisClusterCommand(client, ProtocolCommand.SYNC) - .pipeline((cmd)->{ - cmd.sync(); - return null; - }) - .run(); + public Object pSync(final byte[] replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return pSync(args); } @Override - public Status replicaOf(final String host, final int port){ - final CommandArguments args = CommandArguments.create("host", host).put("port", port); - return new JedisClusterCommand(client, ProtocolCommand.REPLICAOF) - .run(args); + public void sync() { + if(isPipeline()){ + new JedisClusterPipelineCommand<>(client, ProtocolCommand.SYNC, (cmd)->{ + cmd.sync(); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new JedisClusterTransactionCommand<>(client, ProtocolCommand.SYNC) + .run(); + }else{ + new JedisClusterCommand<>(client, ProtocolCommand.SYNC) + .run(); + } } @Override - public Status slaveOf(final String host, final int port){ + public Status replicaOf(final String host, final int port) { final CommandArguments args = CommandArguments.create("host", host).put("port", port); - return new JedisClusterCommand(client, ProtocolCommand.SLAVEOF) - .run(args); - } - - @Override - public List role(){ - return new JedisClusterCommand>(client, ProtocolCommand.ROLE) - .run(); - } - - @Override - public Status save(){ - return new JedisClusterCommand(client, ProtocolCommand.SAVE) - .run(); - } - @Override - public void shutdown(){ - new JedisClusterCommand(client, ProtocolCommand.SHUTDOWN) - .run(); + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + } } @Override - public void shutdown(final boolean save){ - final CommandArguments args = CommandArguments.create("save", save); - new JedisClusterCommand(client, ProtocolCommand.SHUTDOWN) - .run(args); - } - - @Override - public List slowLogGet(){ - return new JedisClusterCommand>(client, ProtocolCommand.SLOWLOG_GET) - .run(); - } + public Status slaveOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); - @Override - public List slowLogGet(final long count){ + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.SLAVEOF) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.SLAVEOF) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.SLAVEOF) + .run(args); + } + } + + @Override + public Role role() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.ROLE) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.ROLE) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.ROLE) + .run(); + } + } + + @Override + public Status save() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.SAVE) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.SAVE) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.SAVE) + .run(); + } + } + + @Override + public void shutdown() { + if(isPipeline()){ + new JedisClusterPipelineCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + }else if(isTransaction()){ + new JedisClusterTransactionCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + }else{ + new JedisClusterCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + } + } + + @Override + public void shutdown(final boolean save) { + if(isPipeline()){ + new JedisClusterPipelineCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + }else if(isTransaction()){ + new JedisClusterTransactionCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + }else{ + new JedisClusterCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + } + } + + @Override + public List slowLogGet() { + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(); + }else{ + return new JedisClusterCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(); + } + } + + @Override + public List slowLogGet(final long count) { final CommandArguments args = CommandArguments.create("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.SLOWLOG_GET) - .run(args); - } - - @Override - public Long slowLogLen(){ - return new JedisClusterCommand(client, ProtocolCommand.SLOWLOG_LEN) - .run(); - } - @Override - public Status slowLogReset(){ - return new JedisClusterCommand(client, ProtocolCommand.SLOWLOG_RESET) - .run(); - } - - @Override - public Status swapdb(final int db1, final int db2){ + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(args); + }else{ + return new JedisClusterCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(args); + } + } + + @Override + public Long slowLogLen() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.SLOWLOG_LEN) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.SLOWLOG_LEN) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.SLOWLOG_LEN) + .run(); + } + } + + @Override + public Status slowLogReset() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.SLOWLOG_RESET) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.SLOWLOG_RESET) + .run(); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + } + } + + @Override + public Status swapdb(final int db1, final int db2) { final CommandArguments args = CommandArguments.create("db1", db1).put("db2", db2); - return new JedisClusterCommand(client, ProtocolCommand.SWAPDB) - .run(args); - } - @Override - public RedisServerTime time(){ - return new JedisClusterCommand(client, ProtocolCommand.TIME) - .run(); + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.SWAPDB) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.SWAPDB) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.SWAPDB) + .run(args); + } + } + + @Override + public RedisServerTime time() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.TIME) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.TIME) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.TIME) + .run(); + } + } + + private List aclCat(final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else{ + return new JedisClusterCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(args); + } + } + + private Status aclSetUser(final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + } + } + + private AclUser aclGetUser(final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + } + } + + private Long aclDelUser(final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.ACL_DELUSER) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.ACL_DELUSER) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.ACL_DELUSER) + .run(args); + } + } + + private Status configSet(final String parameter, final String value, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.CONFIG_SET, (cmd)->cmd.configSet(parameter, value), + okStatusConverter) + .run(args); + } + } + + private Status failover(final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.FAILOVER) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand(client, ProtocolCommand.FAILOVER) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.FAILOVER) + .run(args); + } + } + + private Object pSync(final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterSetOperations.java index 5f0fa40b3..5703090b1 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterSetOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterSetOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -29,9 +29,9 @@ import com.buession.redis.core.ScanResult; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; import com.buession.redis.core.internal.jedis.JedisScanParams; +import redis.clients.jedis.params.ScanParams; import java.util.List; import java.util.Set; @@ -44,458 +44,744 @@ */ public final class JedisClusterSetOperations extends AbstractSetOperations { - public JedisClusterSetOperations(final JedisClusterClient client){ + public JedisClusterSetOperations(final JedisClusterClient client) { super(client); } @Override - public Long sAdd(final String key, final String... members){ + public Long sAdd(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisClusterCommand(client, ProtocolCommand.SADD) - .general((cmd)->cmd.sadd(key, members)) - .pipeline((cmd)->cmd.sadd(key, members)) - .transaction((cmd)->cmd.sadd(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } } @Override - public Long sAdd(final byte[] key, final byte[]... members){ + public Long sAdd(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisClusterCommand(client, ProtocolCommand.SADD) - .general((cmd)->cmd.sadd(key, members)) - .pipeline((cmd)->cmd.sadd(key, members)) - .transaction((cmd)->cmd.sadd(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } } @Override - public Long sCard(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.SCARD) - .general((cmd)->cmd.scard(key)) - .pipeline((cmd)->cmd.scard(key)) - .transaction((cmd)->cmd.scard(key)) - .run(args); + public Long sCard(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } } @Override - public Long sCard(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.SCARD) - .general((cmd)->cmd.scard(key)) - .pipeline((cmd)->cmd.scard(key)) - .transaction((cmd)->cmd.scard(key)) - .run(args); + public Long sCard(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } } @Override - public Set sDiff(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand>(client, ProtocolCommand.SDIFF) - .general((cmd)->cmd.sdiff(keys)) - .pipeline((cmd)->cmd.sdiff(keys)) - .transaction((cmd)->cmd.sdiff(keys)) - .run(args); + public Set sDiff(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + } } @Override - public Set sDiff(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand>(client, ProtocolCommand.SDIFF) - .general((cmd)->cmd.sdiff(keys)) - .pipeline((cmd)->cmd.sdiff(keys)) - .transaction((cmd)->cmd.sdiff(keys)) - .run(args); + public Set sDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + } } @Override - public Long sDiffStore(final String destKey, final String... keys){ + public Long sDiffStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.SDIFFSTORE) - .general((cmd)->cmd.sdiffstore(destKey, keys)) - .pipeline((cmd)->cmd.sdiffstore(destKey, keys)) - .transaction((cmd)->cmd.sdiffstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long sDiffStore(final byte[] destKey, final byte[]... keys){ + public Long sDiffStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.SDIFFSTORE) - .general((cmd)->cmd.sdiffstore(destKey, keys)) - .pipeline((cmd)->cmd.sdiffstore(destKey, keys)) - .transaction((cmd)->cmd.sdiffstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Set sInter(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand>(client, ProtocolCommand.SINTER) - .general((cmd)->cmd.sinter(keys)) - .pipeline((cmd)->cmd.sinter(keys)) - .transaction((cmd)->cmd.sinter(keys)) - .run(args); + public Set sInter(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + } } @Override - public Set sInter(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand>(client, ProtocolCommand.SINTER) - .general((cmd)->cmd.sinter(keys)) - .pipeline((cmd)->cmd.sinter(keys)) - .transaction((cmd)->cmd.sinter(keys)) - .run(args); + public Set sInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + } } @Override - public Long sInterStore(final String destKey, final String... keys){ + public Long sInterStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.SINTERSTORE) - .general((cmd)->cmd.sinterstore(destKey, keys)) - .pipeline((cmd)->cmd.sinterstore(destKey, keys)) - .transaction((cmd)->cmd.sinterstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SINTERSTORE, (cmd)->cmd.sinterstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long sInterStore(final byte[] destKey, final byte[]... keys){ + public Long sInterStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.SINTERSTORE) - .general((cmd)->cmd.sinterstore(destKey, keys)) - .pipeline((cmd)->cmd.sinterstore(destKey, keys)) - .transaction((cmd)->cmd.sinterstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SINTERSTORE, (cmd)->cmd.sinterstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Boolean sIsMember(final String key, final String member){ + public Boolean sIsMember(final String key, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisClusterCommand(client, ProtocolCommand.SISMEMBER) - .general((cmd)->cmd.sismember(key, member)) - .pipeline((cmd)->cmd.sismember(key, member)) - .transaction((cmd)->cmd.sismember(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + } } @Override - public Boolean sIsMember(final byte[] key, final byte[] member){ + public Boolean sIsMember(final byte[] key, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisClusterCommand(client, ProtocolCommand.SISMEMBER) - .general((cmd)->cmd.sismember(key, member)) - .pipeline((cmd)->cmd.sismember(key, member)) - .transaction((cmd)->cmd.sismember(key, member)) - .run(args); - } - @Override - public List smIsMember(final String key, final String... members){ - final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisClusterCommand>(client, ProtocolCommand.SMISMEMBER) - .general((cmd)->cmd.smismember(key, members)) - .pipeline((cmd)->cmd.smismember(key, members)) - .transaction((cmd)->cmd.smismember(key, members)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + } } @Override - public List smIsMember(final byte[] key, final byte[]... members){ + public List smIsMember(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisClusterCommand>(client, ProtocolCommand.SMISMEMBER) - .general((cmd)->cmd.smismember(key, members)) - .pipeline((cmd)->cmd.smismember(key, members)) - .transaction((cmd)->cmd.smismember(key, members)) - .run(args); - } - @Override - public Set sMembers(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand>(client, ProtocolCommand.SMEMBERS) - .general((cmd)->cmd.smembers(key)) - .pipeline((cmd)->cmd.smembers(key)) - .transaction((cmd)->cmd.smembers(key)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SMISMEMBER, (cmd)->cmd.smismember(key, members), + (v)->v) + .run(args); + } } @Override - public Set sMembers(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand>(client, ProtocolCommand.SMEMBERS) - .general((cmd)->cmd.smembers(key)) - .pipeline((cmd)->cmd.smembers(key)) - .transaction((cmd)->cmd.smembers(key)) - .run(args); - } + public List smIsMember(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - @Override - public Status sMove(final String key, final String destKey, final String member){ + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SMISMEMBER, (cmd)->cmd.smismember(key, members), + (v)->v) + .run(args); + } + } + + @Override + public Set sMembers(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + } + } + + @Override + public Set sMembers(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + } + } + + @Override + public Status sMove(final String key, final String destKey, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); - return new JedisClusterCommand(client, ProtocolCommand.SMOVE) - .general((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + } } @Override - public Status sMove(final byte[] key, final byte[] destKey, final byte[] member){ + public Status sMove(final byte[] key, final byte[] destKey, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); - return new JedisClusterCommand(client, ProtocolCommand.SMOVE) - .general((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + } } @Override - public String sPop(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.SPOP) - .general((cmd)->cmd.spop(key)) - .pipeline((cmd)->cmd.spop(key)) - .transaction((cmd)->cmd.spop(key)) - .run(args); + public String sPop(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + } } @Override - public byte[] sPop(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.SPOP) - .general((cmd)->cmd.spop(key)) - .pipeline((cmd)->cmd.spop(key)) - .transaction((cmd)->cmd.spop(key)) - .run(args); + public byte[] sPop(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + } } @Override - public Set sPop(final String key, final long count){ + public Set sPop(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.SPOP) - .general((cmd)->cmd.spop(key, count)) - .pipeline((cmd)->cmd.spop(key, count)) - .transaction((cmd)->cmd.spop(key, count)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + } } @Override - public Set sPop(final byte[] key, final long count){ + public Set sPop(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.SPOP) - .general((cmd)->cmd.spop(key, count)) - .pipeline((cmd)->cmd.spop(key, count)) - .transaction((cmd)->cmd.spop(key, count)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + } } @Override - public String sRandMember(final String key){ + public String sRandMember(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.SRANDMEMBER) - .general((cmd)->cmd.srandmember(key)) - .pipeline((cmd)->cmd.srandmember(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + } } @Override - public byte[] sRandMember(final byte[] key){ + public byte[] sRandMember(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.SRANDMEMBER) - .general((cmd)->cmd.srandmember(key)) - .pipeline((cmd)->cmd.srandmember(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + } } @Override - public List sRandMember(final String key, final long count){ + public List sRandMember(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.SRANDMEMBER) - .general((cmd)->cmd.srandmember(key, (int) count)) - .pipeline((cmd)->cmd.srandmember(key, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + } } @Override - public List sRandMember(final byte[] key, final long count){ + public List sRandMember(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.SRANDMEMBER) - .general((cmd)->cmd.srandmember(key, (int) count)) - .pipeline((cmd)->cmd.srandmember(key, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + } } @Override - public Long sRem(final String key, final String... members){ + public Long sRem(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisClusterCommand(client, ProtocolCommand.SREM) - .general((cmd)->cmd.srem(key, members)) - .pipeline((cmd)->cmd.srem(key, members)) - .transaction((cmd)->cmd.srem(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } } @Override - public Long sRem(final byte[] key, final byte[]... members){ + public Long sRem(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisClusterCommand(client, ProtocolCommand.SREM) - .general((cmd)->cmd.srem(key, members)) - .pipeline((cmd)->cmd.srem(key, members)) - .transaction((cmd)->cmd.srem(key, members)) - .run(args); - } - @Override - public ScanResult> sScan(final String key, final String cursor){ - final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisClusterCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } } @Override - public ScanResult> sScan(final byte[] key, final byte[] cursor){ + public ScanResult> sScan(final String key, final String cursor) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisClusterCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); - } - - @Override - public ScanResult> sScan(final String key, final String cursor, final String pattern){ + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisClusterCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return sScan(key, cursor, scanParams, args); } @Override - public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern){ + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisClusterCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return sScan(key, cursor, scanParams, args); } @Override - public ScanResult> sScan(final String key, final String cursor, final long count){ + public ScanResult> sScan(final String key, final String cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisClusterCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return sScan(key, cursor, scanParams, args); } @Override - public ScanResult> sScan(final byte[] key, final byte[] cursor, final long count){ + public ScanResult> sScan(final byte[] key, final byte[] cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisClusterCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return sScan(key, cursor, scanParams, args); } @Override public ScanResult> sScan(final String key, final String cursor, final String pattern, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisClusterCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return sScan(key, cursor, scanParams, args); } @Override public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisClusterCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return sScan(key, cursor, scanParams, args); } @Override - public Set sUnion(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand>(client, ProtocolCommand.SUNION) - .general((cmd)->cmd.sunion(keys)) - .pipeline((cmd)->cmd.sunion(keys)) - .transaction((cmd)->cmd.sunion(keys)) - .run(args); + public Set sUnion(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + } } @Override - public Set sUnion(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand>(client, ProtocolCommand.SUNION) - .general((cmd)->cmd.sunion(keys)) - .pipeline((cmd)->cmd.sunion(keys)) - .transaction((cmd)->cmd.sunion(keys)) - .run(args); + public Set sUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + } } @Override - public Long sUnionStore(final String destKey, final String... keys){ + public Long sUnionStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.SUNIONSTORE) - .general((cmd)->cmd.sunionstore(destKey, keys)) - .pipeline((cmd)->cmd.sunionstore(destKey, keys)) - .transaction((cmd)->cmd.sunionstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SUNIONSTORE, (cmd)->cmd.sunionstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long sUnionStore(final byte[] destKey, final byte[]... keys){ + public Long sUnionStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.SUNIONSTORE) - .general((cmd)->cmd.sunionstore(destKey, keys)) - .pipeline((cmd)->cmd.sunionstore(destKey, keys)) - .transaction((cmd)->cmd.sunionstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SUNIONSTORE, (cmd)->cmd.sunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + private ScanResult> sScan(final String key, final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterSortedSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterSortedSetOperations.java index e6d0449b9..76f42b06e 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterSortedSetOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterSortedSetOperations.java @@ -19,30 +19,34 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.core.converter.ListConverter; import com.buession.core.utils.NumberUtils; +import com.buession.lang.KeyValue; import com.buession.redis.client.jedis.JedisClusterClient; import com.buession.redis.core.Aggregate; import com.buession.redis.core.GtLt; -import com.buession.redis.core.KeyedZSetElement; import com.buession.redis.core.NxXx; import com.buession.redis.core.ScanResult; import com.buession.redis.core.Tuple; import com.buession.redis.core.ZRangeBy; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.jedis.response.KeyedZSetElementConverter; +import com.buession.redis.core.internal.convert.jedis.response.KeyValueConverter; import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; import com.buession.redis.core.internal.convert.jedis.response.TupleConverter; import com.buession.redis.core.internal.jedis.JedisScanParams; import com.buession.redis.core.internal.jedis.JedisZAddParams; import com.buession.redis.core.internal.jedis.JedisZParams; import com.buession.redis.core.internal.jedis.JedisZRangeParams; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.params.ZAddParams; import redis.clients.jedis.params.ZParams; +import redis.clients.jedis.params.ZRangeParams; import java.util.List; import java.util.Map; @@ -56,2192 +60,3240 @@ */ public final class JedisClusterSortedSetOperations extends AbstractSortedSetOperations { - public JedisClusterSortedSetOperations(final JedisClusterClient client){ + public JedisClusterSortedSetOperations(final JedisClusterClient client) { super(client); } @Override - public Tuple zPopMin(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.ZPOPMIN) - .general((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .pipeline((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .transaction((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .run(args); - } + public Tuple zPopMin(final String key) { + final CommandArguments args = CommandArguments.create(key); + final TupleConverter tupleConverter = new TupleConverter(); - @Override - public Tuple zPopMin(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.ZPOPMIN) - .general((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .pipeline((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .transaction((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + } } @Override - public List zPopMin(final String key, final long count){ - final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZPOPMIN) - .general((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .run(args); + public Tuple zPopMin(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + } } @Override - public List zPopMin(final byte[] key, final long count){ + public List zPopMin(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZPOPMIN) - .general((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .run(args); - } + final ListConverter listTupleConverter = TupleConverter.listConverter(); - @Override - public Tuple zPopMax(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.ZPOPMAX) - .general((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .pipeline((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .transaction((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + } } @Override - public Tuple zPopMax(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.ZPOPMAX) - .general((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .pipeline((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .transaction((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .run(args); - } - - @Override - public List zPopMax(final String key, final long count){ + public List zPopMin(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + } + } + + @Override + public Tuple zPopMax(final String key) { + final CommandArguments args = CommandArguments.create(key); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + } + } + + @Override + public Tuple zPopMax(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + } + } + + @Override + public List zPopMax(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZPOPMAX) - .general((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + } } @Override - public List zPopMax(final byte[] key, final long count){ + public List zPopMax(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZPOPMAX) - .general((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .run(args); - } + final ListConverter listTupleConverter = TupleConverter.listConverter(); - @Override - public KeyedZSetElement bzPopMin(final String[] keys, final int timeout){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisClusterCommand(client, ProtocolCommand.BZPOPMIN) - .general((cmd)->cmd.bzpopmin(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .pipeline((cmd)->cmd.bzpopmin(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .transaction((cmd)->cmd.bzpopmin(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + } } @Override - public KeyedZSetElement bzPopMin(final byte[][] keys, final int timeout){ + public KeyValue bzPopMin(final String[] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisClusterCommand(client, ProtocolCommand.BZPOPMIN) - .general((cmd)->cmd.bzpopmin(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .pipeline((cmd)->cmd.bzpopmin(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .transaction((cmd)->cmd.bzpopmin(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .run(args); - } - - @Override - public KeyedZSetElement bzPopMax(final String[] keys, final int timeout){ + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMin(final byte[][] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisClusterCommand(client, ProtocolCommand.BZPOPMAX) - .general((cmd)->cmd.bzpopmax(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .pipeline((cmd)->cmd.bzpopmax(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .transaction((cmd)->cmd.bzpopmax(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .run(args); - } - - @Override - public KeyedZSetElement bzPopMax(final byte[][] keys, final int timeout){ + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final String[] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisClusterCommand(client, ProtocolCommand.BZPOPMIN) - .general((cmd)->cmd.bzpopmax(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .pipeline((cmd)->cmd.bzpopmax(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .transaction((cmd)->cmd.bzpopmax(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .run(args); - } - - @Override - public Long zAdd(final String key, final Map members){ + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public Long zAdd(final String key, final Map members) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members)) - .pipeline((cmd)->cmd.zadd(key, members)) - .transaction((cmd)->cmd.zadd(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + } } @Override - public Long zAdd(final byte[] key, final Map members){ + public Long zAdd(final byte[] key, final Map members) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members)) - .pipeline((cmd)->cmd.zadd(key, members)) - .transaction((cmd)->cmd.zadd(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + } } @Override - public Long zAdd(final String key, final Map members, final NxXx nxXx){ + public Long zAdd(final String key, final Map members, final NxXx nxXx) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); - final JedisZAddParams params = new JedisZAddParams(nxXx); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final NxXx nxXx){ + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); - final JedisZAddParams params = new JedisZAddParams(nxXx); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final String key, final Map members, final GtLt gtLt){ + public Long zAdd(final String key, final Map members, final GtLt gtLt) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); - final JedisZAddParams params = new JedisZAddParams(gtLt); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(gtLt); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final GtLt gtLt){ + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); - final JedisZAddParams params = new JedisZAddParams(gtLt); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(gtLt); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final String key, final Map members, final boolean ch){ + public Long zAdd(final String key, final Map members, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(ch); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final boolean ch){ + public Long zAdd(final byte[] key, final Map members, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(ch); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt){ + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("gtLt", gtLt); - final JedisZAddParams params = new JedisZAddParams(nxXx, gtLt); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt){ + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("gtLt", gtLt); - final JedisZAddParams params = new JedisZAddParams(nxXx, gtLt); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch){ + public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(nxXx, ch); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch){ + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(nxXx, ch); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch){ + public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) .put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(gtLt, ch); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(gtLt, ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch){ + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) .put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(gtLt, ch); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(gtLt, ch); + + return zAdd(key, members, zAddParams, args); } @Override public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt, - final boolean ch){ + final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("gtLt", gtLt).put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(nxXx, gtLt, ch); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt, ch); + + return zAdd(key, members, zAddParams, args); } @Override public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt, - final boolean ch){ + final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("gtLt", gtLt).put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(nxXx, gtLt, ch); - return new JedisClusterCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); - } + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt, ch); - @Override - public Long zCard(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.ZCARD) - .general((cmd)->cmd.zcard(key)) - .pipeline((cmd)->cmd.zcard(key)) - .transaction((cmd)->cmd.zcard(key)) - .run(args); + return zAdd(key, members, zAddParams, args); } @Override - public Long zCard(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.ZCARD) - .general((cmd)->cmd.zcard(key)). - pipeline((cmd)->cmd.zcard(key)) - .transaction((cmd)->cmd.zcard(key)) - .run(args); - } + public Long zCard(final String key) { + final CommandArguments args = CommandArguments.create(key); - @Override - public Long zCount(final String key, final double min, final double max){ - final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand(client, ProtocolCommand.ZCOUNT) - .general((cmd)->cmd.zcount(key, min, max)) - .pipeline((cmd)->cmd.zcount(key, min, max)) - .transaction((cmd)->cmd.zcount(key, min, max)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } } @Override - public Long zCount(final byte[] key, final double min, final double max){ - final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand(client, ProtocolCommand.ZCOUNT) - .general((cmd)->cmd.zcount(key, min, max)) - .pipeline((cmd)->cmd.zcount(key, min, max)) - .transaction((cmd)->cmd.zcount(key, min, max)) - .run(args); + public Long zCard(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } } @Override - public Long zCount(final String key, final String min, final String max){ + public Long zCount(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand(client, ProtocolCommand.ZCOUNT) - .general((cmd)->cmd.zcount(key, min, max)) - .pipeline((cmd)->cmd.zcount(key, min, max)) - .transaction((cmd)->cmd.zcount(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZCOUNT, + (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } } @Override - public Long zCount(final byte[] key, final byte[] min, final byte[] max){ + public Long zCount(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand(client, ProtocolCommand.ZCOUNT) - .general((cmd)->cmd.zcount(key, min, max)) - .pipeline((cmd)->cmd.zcount(key, min, max)) - .transaction((cmd)->cmd.zcount(key, min, max)) - .run(args); - } - @Override - public Set zDiff(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand>(client, ProtocolCommand.ZDIFF) - .general((cmd)->cmd.zdiff(keys)) - .pipeline((cmd)->cmd.zdiff(keys)) - .transaction((cmd)->cmd.zdiff(keys)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZCOUNT, + (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public Set zDiff(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand>(client, ProtocolCommand.ZDIFF) - .general((cmd)->cmd.zdiff(keys)) - .pipeline((cmd)->cmd.zdiff(keys)) - .transaction((cmd)->cmd.zdiff(keys)) - .run(args); - } + public Long zCount(final String key, final String min, final String max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - @Override - public Set zDiffWithScores(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand>(client, ProtocolCommand.ZDIFF) - .general((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZCOUNT, + (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public Set zDiffWithScores(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand>(client, ProtocolCommand.ZDIFF) - .general((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .run(args); - } + public Long zCount(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - @Override - public Long zDiffStore(final String destKey, final String... keys){ + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZCOUNT, + (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } + } + + @Override + public List zDiff(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + } + } + + @Override + public List zDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + } + } + + @Override + public List zDiffWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + } + } + + @Override + public List zDiffWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + } + } + + @Override + public Long zDiffStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.ZDIFFSTORE) - .general((cmd)->cmd.zdiffStore(destKey, keys)) - .pipeline((cmd)->cmd.zdiffStore(destKey, keys)) - .transaction((cmd)->cmd.zdiffStore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long zDiffStore(final byte[] destKey, final byte[]... keys){ + public Long zDiffStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.ZDIFFSTORE) - .general((cmd)->cmd.zdiffStore(destKey, keys)) - .pipeline((cmd)->cmd.zdiffStore(destKey, keys)) - .transaction((cmd)->cmd.zdiffStore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Double zIncrBy(final String key, final double increment, final String member){ + public Double zIncrBy(final String key, final double increment, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) .put("member", member); - return new JedisClusterCommand(client, ProtocolCommand.ZINCRBY) - .general((cmd)->cmd.zincrby(key, increment, member)) - .pipeline((cmd)->cmd.zincrby(key, increment, member)) - .transaction((cmd)->cmd.zincrby(key, increment, member)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + } } @Override - public Double zIncrBy(final byte[] key, final double increment, final byte[] member){ + public Double zIncrBy(final byte[] key, final double increment, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) .put("member", member); - return new JedisClusterCommand(client, ProtocolCommand.ZINCRBY) - .general((cmd)->cmd.zincrby(key, increment, member)) - .pipeline((cmd)->cmd.zincrby(key, increment, member)) - .transaction((cmd)->cmd.zincrby(key, increment, member)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + } } @Override - public Set zInter(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final ZParams params = new JedisZParams(); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + public List zInter(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + final ZParams zParams = new JedisZParams(); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final ZParams params = new JedisZParams(); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + public List zInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + final ZParams zParams = new JedisZParams(); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final String[] keys, final Aggregate aggregate){ + public List zInter(final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final ZParams params = new JedisZParams(aggregate); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final byte[][] keys, final Aggregate aggregate){ + public List zInter(final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final ZParams params = new JedisZParams(aggregate); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final String[] keys, final double... weights){ + public List zInter(final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final ZParams params = new JedisZParams(weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final byte[][] keys, final double... weights){ + public List zInter(final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final ZParams params = new JedisZParams(weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zInter(final String[] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final ZParams params = new JedisZParams(aggregate, weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final ZParams params = new JedisZParams(aggregate, weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInter(keys, zParams, args); } @Override - public Set zInterWithScores(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final ZParams params = new JedisZParams(); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + public List zInterWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + final ZParams zParams = new JedisZParams(); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final ZParams params = new JedisZParams(); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + public List zInterWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + final ZParams zParams = new JedisZParams(); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final String[] keys, final Aggregate aggregate){ + public List zInterWithScores(final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final ZParams params = new JedisZParams(aggregate); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final byte[][] keys, final Aggregate aggregate){ + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final ZParams params = new JedisZParams(aggregate); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final String[] keys, final double... weights){ + public List zInterWithScores(final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final ZParams params = new JedisZParams(weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final byte[][] keys, final double... weights){ + public List zInterWithScores(final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final ZParams params = new JedisZParams(weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final ZParams params = new JedisZParams(aggregate, weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final ZParams params = new JedisZParams(aggregate, weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterWithScores(keys, zParams, args); } @Override - public Long zInterStore(final String destKey, final String... keys){ + public Long zInterStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZINTERSTORE, (cmd)->cmd.zinterstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long zInterStore(final byte[] destKey, final byte[]... keys){ + public Long zInterStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZINTERSTORE, (cmd)->cmd.zinterstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate){ + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisClusterCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterStore(destKey, keys, zParams, args); } @Override - public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate){ + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisClusterCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterStore(destKey, keys, zParams, args); } @Override - public Long zInterStore(final String destKey, final String[] keys, final double... weights){ + public Long zInterStore(final String destKey, final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisClusterCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInterStore(destKey, keys, zParams, args); } @Override - public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights){ + public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisClusterCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInterStore(destKey, keys, zParams, args); } @Override public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate).put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisClusterCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterStore(destKey, keys, zParams, args); } @Override public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate).put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisClusterCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterStore(destKey, keys, zParams, args); } @Override - public Long zLexCount(final String key, final double min, final double max){ + public Long zLexCount(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand(client, ProtocolCommand.ZLEXCOUNT) - .general((cmd)->cmd.zlexcount(key, Double.toString(min), Double.toString(max))) - .pipeline((cmd)->cmd.zlexcount(key, Double.toString(min), Double.toString(max))) - .transaction((cmd)->cmd.zlexcount(key, Double.toString(min), Double.toString(max))) - .run(args); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zLexCount(key, sMin, sMax, args); } @Override - public Long zLexCount(final byte[] key, final double min, final double max){ + public Long zLexCount(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand(client, ProtocolCommand.ZLEXCOUNT) - .general((cmd)->cmd.zlexcount(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .pipeline((cmd)->cmd.zlexcount(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .transaction((cmd)->cmd.zlexcount(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .run(args); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zLexCount(key, bMin, bMax, args); } + @Deprecated @Override - public Long zLexCount(final String key, final String min, final String max){ + public Long zLexCount(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand(client, ProtocolCommand.ZLEXCOUNT) - .general((cmd)->cmd.zlexcount(key, min, max)) - .pipeline((cmd)->cmd.zlexcount(key, min, max)) - .transaction((cmd)->cmd.zlexcount(key, min, max)) - .run(args); + return zLexCount(key, min, max, args); } + @Deprecated @Override - public Long zLexCount(final byte[] key, final byte[] min, final byte[] max){ + public Long zLexCount(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand(client, ProtocolCommand.ZLEXCOUNT) - .general((cmd)->cmd.zlexcount(key, min, max)) - .pipeline((cmd)->cmd.zlexcount(key, min, max)) - .transaction((cmd)->cmd.zlexcount(key, min, max)) - .run(args); + return zLexCount(key, min, max, args); } @Override - public List zMScore(final String key, final String... members){ + public List zMScore(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisClusterCommand>(client, ProtocolCommand.ZMSCORE) - .general((cmd)->cmd.zmscore(key, members)) - .pipeline((cmd)->cmd.zmscore(key, members)) - .transaction((cmd)->cmd.zmscore(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZMSCORE, (cmd)->cmd.zmscore(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZMSCORE, + (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + } } @Override - public List zMScore(final byte[] key, final byte[]... members){ + public List zMScore(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisClusterCommand>(client, ProtocolCommand.ZMSCORE) - .general((cmd)->cmd.zmscore(key, members)) - .pipeline((cmd)->cmd.zmscore(key, members)) - .transaction((cmd)->cmd.zmscore(key, members)) - .run(args); - } - @Override - public String zRandMember(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmember(key)) - .pipeline((cmd)->cmd.zrandmember(key)) - .transaction((cmd)->cmd.zrandmember(key)) - .run(args); - } + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZMSCORE, (cmd)->cmd.zmscore(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZMSCORE, + (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + } + } + + @Override + public String zRandMember(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + } + } + + @Override + public byte[] zRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + } + } + + @Override + public List zRandMember(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); - @Override - public byte[] zRandMember(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmember(key)) - .pipeline((cmd)->cmd.zrandmember(key)) - .transaction((cmd)->cmd.zrandmember(key)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), + (v)->v) + .run(args); + } } @Override - public List zRandMember(final String key, final long count){ + public List zRandMember(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmember(key, count)) - .pipeline((cmd)->cmd.zrandmember(key, count)) - .transaction((cmd)->cmd.zrandmember(key, count)) - .run(args); - } - @Override - public List zRandMember(final byte[] key, final long count){ - final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmember(key, count)) - .pipeline((cmd)->cmd.zrandmember(key, count)) - .transaction((cmd)->cmd.zrandmember(key, count)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), + (v)->v) + .run(args); + } } @Override - public List zRandMemberWithScores(final String key, final long count){ + public List zRandMemberWithScores(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + } } @Override - public List zRandMemberWithScores(final byte[] key, final long count){ + public List zRandMemberWithScores(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + } } @Override - public List zRange(final String key, final long start, final long end){ + public List zRange(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGE) - .general((cmd)->cmd.zrange(key, start, end)) - .pipeline((cmd)->cmd.zrange(key, start, end)) - .transaction((cmd)->cmd.zrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + } } @Override - public List zRange(final byte[] key, final long start, final long end){ + public List zRange(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGE) - .general((cmd)->cmd.zrange(key, start, end)) - .pipeline((cmd)->cmd.zrange(key, start, end)) - .transaction((cmd)->cmd.zrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + } } @Override - public List zRangeWithScores(final String key, final long start, final long end){ + public List zRangeWithScores(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGE) - .general((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } } @Override - public List zRangeWithScores(final byte[] key, final long start, final long end){ + public List zRangeWithScores(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGE) - .general((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } } @Override - public List zRangeByLex(final String key, final double min, final double max){ + public List zRangeByLex(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max))) - .pipeline((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max))) - .transaction((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max))) - .run(args); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zRangeByLex(key, sMin, sMax, args); } @Override - public List zRangeByLex(final byte[] key, final double min, final double max){ + public List zRangeByLex(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .pipeline((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .transaction((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .run(args); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, args); } + @Deprecated @Override - public List zRangeByLex(final String key, final String min, final String max){ + public List zRangeByLex(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zrangeByLex(key, min, max)) - .run(args); + return zRangeByLex(key, min, max, args); } + @Deprecated @Override - public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max){ + public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zrangeByLex(key, min, max)) - .run(args); + return zRangeByLex(key, min, max, args); } @Override public List zRangeByLex(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max), (int) offset, - (int) count)) - .pipeline((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max), (int) offset, - (int) count)) - .transaction((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max), (int) offset, - (int) count)) - .run(args); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zRangeByLex(key, sMin, sMax, offset, count, args); } @Override public List zRangeByLex(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max), - (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max), - (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max), - (int) offset, (int) count)) - .run(args); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, offset, count, args); } + @Deprecated @Override public List zRangeByLex(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .run(args); + return zRangeByLex(key, min, max, offset, count, args); } + @Deprecated @Override public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .run(args); + return zRangeByLex(key, min, max, offset, count, args); } @Override - public List zRangeByScore(final String key, final double min, final double max){ + public List zRangeByScore(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override - public List zRangeByScore(final byte[] key, final double min, final double max){ + public List zRangeByScore(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public List zRangeByScore(final String key, final String min, final String max){ + public List zRangeByScore(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public List zRangeByScore(final byte[] key, final byte[] min, final byte[] max){ + public List zRangeByScore(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override public List zRangeByScore(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } @Override public List zRangeByScore(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRangeByScore(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRangeByScore(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); - } - @Override - public List zRangeByScoreWithScores(final String key, final double min, final double max){ - final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } @Override - public List zRangeByScoreWithScores(final byte[] key, final double min, final double max){ + public List zRangeByScoreWithScores(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); - } + final ListConverter listTupleConverter = TupleConverter.listConverter(); - @Override - public List zRangeByScoreWithScores(final String key, final String min, final String max){ - final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } } @Override - public List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max){ + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Deprecated + @Override + public List zRangeByScoreWithScores(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Deprecated + @Override + public List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } } @Override public List zRangeByScoreWithScores(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } @Override public List zRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } + @Deprecated @Override public List zRangeByScoreWithScores(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } + @Deprecated @Override public List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } @Override - public Long zRangeStore(final String destKey, final String key, final long start, final long end){ + public Long zRangeStore(final String destKey, final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end); - final JedisZRangeParams params = new JedisZRangeParams(start, end); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override - public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end){ + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end); - final JedisZRangeParams params = new JedisZRangeParams(start, end); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, - final ZRangeBy by){ + final ZRangeBy by) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, - final ZRangeBy by){ + final ZRangeBy by) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, - final boolean rev){ + final boolean rev) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("rev", rev); - final JedisZRangeParams params = new JedisZRangeParams(start, end, rev); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, - final boolean rev){ + final boolean rev) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("rev", rev); - final JedisZRangeParams params = new JedisZRangeParams(start, end, rev); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(start, end, offset, count); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(start, end, offset, count); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, - final ZRangeBy by, final boolean rev){ + final ZRangeBy by, final boolean rev) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("rev", rev); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, rev); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, - final ZRangeBy by, final boolean rev){ + final ZRangeBy by, final boolean rev) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("rev", rev); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, rev); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, - final ZRangeBy by, final long offset, final long count){ + final ZRangeBy by, final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, offset, count); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, - final ZRangeBy by, final long offset, final long count){ + final ZRangeBy by, final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, offset, count); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("rev", rev).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(start, end, rev, offset, count); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("rev", rev).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(start, end, rev, offset, count); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, - final boolean rev, final long offset, final long count){ + final boolean rev, final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, rev, offset, count); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, - final boolean rev, final long offset, final long count){ + final boolean rev, final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, rev, offset, count); - return new JedisClusterCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override - public Long zRank(final String key, final String member){ + public Long zRank(final String key, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisClusterCommand(client, ProtocolCommand.ZRANK) - .general((cmd)->cmd.zrank(key, member)) - .pipeline((cmd)->cmd.zrank(key, member)) - .transaction((cmd)->cmd.zrank(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } } @Override - public Long zRank(final byte[] key, final byte[] member){ + public Long zRank(final byte[] key, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisClusterCommand(client, ProtocolCommand.ZRANK) - .general((cmd)->cmd.zrank(key, member)) - .pipeline((cmd)->cmd.zrank(key, member)) - .transaction((cmd)->cmd.zrank(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } } @Override - public Long zRem(final String key, final String... members){ + public Long zRem(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisClusterCommand(client, ProtocolCommand.ZREM) - .general((cmd)->cmd.zrem(key, members)) - .pipeline((cmd)->cmd.zrem(key, members)) - .transaction((cmd)->cmd.zrem(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } } @Override - public Long zRem(final byte[] key, final byte[]... members){ + public Long zRem(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisClusterCommand(client, ProtocolCommand.ZREM) - .general((cmd)->cmd.zrem(key, members)) - .pipeline((cmd)->cmd.zrem(key, members)) - .transaction((cmd)->cmd.zrem(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } } + @Deprecated @Override - public Long zRemRangeByLex(final String key, final String min, final String max){ + public Long zRemRangeByLex(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand(client, ProtocolCommand.ZREMRANGEBYLEX) - .general((cmd)->cmd.zremrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zremrangeByLex(key, min, max)) - .run(args); - } - @Override - public Long zRemRangeByLex(final byte[] key, final byte[] min, final byte[] max){ + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), + (v)->v) + .run(args); + } + } + + @Deprecated + @Override + public Long zRemRangeByLex(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand(client, ProtocolCommand.ZREMRANGEBYLEX) - .general((cmd)->cmd.zremrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zremrangeByLex(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), + (v)->v) + .run(args); + } } @Override - public Long zRemRangeByScore(final String key, final double min, final double max){ + public Long zRemRangeByScore(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand(client, ProtocolCommand.ZREMRANGEBYSCORE) - .general((cmd)->cmd.zremrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zremrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override - public Long zRemRangeByScore(final byte[] key, final double min, final double max){ + public Long zRemRangeByScore(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand(client, ProtocolCommand.ZREMRANGEBYSCORE) - .general((cmd)->cmd.zremrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zremrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public Long zRemRangeByScore(final String key, final String min, final String max){ + public Long zRemRangeByScore(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand(client, ProtocolCommand.ZREMRANGEBYSCORE) - .general((cmd)->cmd.zremrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zremrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public Long zRemRangeByScore(final byte[] key, final byte[] min, final byte[] max){ + public Long zRemRangeByScore(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand(client, ProtocolCommand.ZREMRANGEBYSCORE) - .general((cmd)->cmd.zremrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zremrangeByScore(key, min, max)) - .run(args); - } - @Override - public Long zRemRangeByRank(final String key, final long start, final long end){ - final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand(client, ProtocolCommand.ZREMRANGEBYRANK) - .general((cmd)->cmd.zremrangeByRank(key, start, end)) - .pipeline((cmd)->cmd.zremrangeByRank(key, start, end)) - .transaction((cmd)->cmd.zremrangeByRank(key, start, end)) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override - public Long zRemRangeByRank(final byte[] key, final long start, final long end){ + public Long zRemRangeByRank(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand(client, ProtocolCommand.ZREMRANGEBYRANK) - .general((cmd)->cmd.zremrangeByRank(key, start, end)) - .pipeline((cmd)->cmd.zremrangeByRank(key, start, end)) - .transaction((cmd)->cmd.zremrangeByRank(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + } } @Override - public List zRevRange(final String key, final long start, final long end){ + public Long zRemRangeByRank(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGE) - .general((cmd)->cmd.zrevrange(key, start, end)) - .pipeline((cmd)->cmd.zrevrange(key, start, end)) - .transaction((cmd)->cmd.zrevrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + } } @Override - public List zRevRange(final byte[] key, final long start, final long end){ + public List zRevRange(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGE) - .general((cmd)->cmd.zrevrange(key, start, end)) - .pipeline((cmd)->cmd.zrevrange(key, start, end)) - .transaction((cmd)->cmd.zrevrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), + (v)->v) + .run(args); + } } @Override - public List zRevRangeWithScores(final String key, final long start, final long end){ + public List zRevRange(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGE) - .general((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), + (v)->v) + .run(args); + } } @Override - public List zRevRangeWithScores(final byte[] key, final long start, final long end){ + public List zRevRangeWithScores(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGE) - .general((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } } @Override - public List zRevRangeByLex(final String key, final String min, final String max){ + public List zRevRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } + } + + @Deprecated + @Override + public List zRevRangeByLex(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYLEX) - .general((cmd)->cmd.zrevrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByLex(key, min, max)) - .run(args); - } - @Override - public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max){ + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), + (v)->v) + .run(args); + } + } + + @Deprecated + @Override + public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYLEX) - .general((cmd)->cmd.zrevrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByLex(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), + (v)->v) + .run(args); + } } + @Deprecated @Override public List zRevRangeByLex(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYLEX) - .general((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYLEX) - .general((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } @Override - public List zRevRangeByScore(final String key, final double min, final double max){ + public List zRevRangeByScore(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override - public List zRevRangeByScore(final byte[] key, final double min, final double max){ + public List zRevRangeByScore(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public List zRevRangeByScore(final String key, final String min, final String max){ + public List zRevRangeByScore(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max){ + public List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override public List zRevRangeByScore(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } @Override public List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRevRangeByScore(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); - } - @Override - public List zRevRangeByScoreWithScores(final String key, final double min, final double max){ - final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } @Override - public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max){ + public List zRevRangeByScoreWithScores(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); - } + final ListConverter listTupleConverter = TupleConverter.listConverter(); - @Override - public List zRevRangeByScoreWithScores(final String key, final String min, final String max){ - final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } } @Override - public List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max){ + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Deprecated + @Override + public List zRevRangeByScoreWithScores(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Deprecated + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } } @Override public List zRevRangeByScoreWithScores(final String key, final double min, final double max, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } @Override public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } + @Deprecated @Override public List zRevRangeByScoreWithScores(final String key, final String min, final String max, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } + @Deprecated @Override public List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisClusterCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } @Override - public Long zRevRank(final String key, final String member){ + public Long zRevRank(final String key, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisClusterCommand(client, ProtocolCommand.ZREVRANK) - .general((cmd)->cmd.zrevrank(key, member)) - .pipeline((cmd)->cmd.zrevrank(key, member)) - .transaction((cmd)->cmd.zrevrank(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + } } @Override - public Long zRevRank(final byte[] key, final byte[] member){ + public Long zRevRank(final byte[] key, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisClusterCommand(client, ProtocolCommand.ZREVRANK) - .general((cmd)->cmd.zrevrank(key, member)) - .pipeline((cmd)->cmd.zrevrank(key, member)) - .transaction((cmd)->cmd.zrevrank(key, member)) - .run(args); - } - @Override - public ScanResult> zScan(final String key, final String cursor){ - final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisClusterCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + } } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor){ + public ScanResult> zScan(final String key, final String cursor) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisClusterCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); - } - - @Override - public ScanResult> zScan(final String key, final String cursor, final String pattern){ + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisClusterCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return zScan(key, cursor, scanParams, args); } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern){ + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisClusterCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return zScan(key, cursor, scanParams, args); } @Override - public ScanResult> zScan(final String key, final String cursor, final long count){ + public ScanResult> zScan(final String key, final String cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisClusterCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return zScan(key, cursor, scanParams, args); } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor, final long count){ + public ScanResult> zScan(final byte[] key, final byte[] cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisClusterCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return zScan(key, cursor, scanParams, args); } @Override - public ScanResult> zScan(final String key, final String cursor, final String pattern, final long count){ + public ScanResult> zScan(final String key, final String cursor, final String pattern, + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisClusterCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return zScan(key, cursor, scanParams, args); } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, final long count){ + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisClusterCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return zScan(key, cursor, scanParams, args); } @Override - public Double zScore(final String key, final String member){ + public Double zScore(final String key, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisClusterCommand(client, ProtocolCommand.ZSCORE) - .general((cmd)->cmd.zscore(key, member)) - .pipeline((cmd)->cmd.zscore(key, member)) - .transaction((cmd)->cmd.zscore(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } } @Override - public Double zScore(final byte[] key, final byte[] member){ + public Double zScore(final byte[] key, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisClusterCommand(client, ProtocolCommand.ZSCORE) - .general((cmd)->cmd.zscore(key, member)) - .pipeline((cmd)->cmd.zscore(key, member)) - .transaction((cmd)->cmd.zscore(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } } @Override - public Set zUnion(final String... keys){ + public List zUnion(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final JedisZParams params = new JedisZParams(); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final byte[]... keys){ + public List zUnion(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final JedisZParams params = new JedisZParams(); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final String[] keys, final Aggregate aggregate){ + public List zUnion(final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final byte[][] keys, final Aggregate aggregate){ + public List zUnion(final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final String[] keys, final double... weights){ + public List zUnion(final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final byte[][] keys, final double... weights){ + public List zUnion(final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zUnion(final String[] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnion(keys, zParams, args); } @Override - public Set zUnionWithScores(final String... keys){ + public List zUnionWithScores(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final JedisZParams params = new JedisZParams(); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final byte[]... keys){ + public List zUnionWithScores(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final JedisZParams params = new JedisZParams(); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final String[] keys, final Aggregate aggregate){ + public List zUnionWithScores(final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final byte[][] keys, final Aggregate aggregate){ + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final String[] keys, final double... weights){ + public List zUnionWithScores(final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final byte[][] keys, final double... weights){ + public List zUnionWithScores(final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisClusterCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionWithScores(keys, zParams, args); } @Override - public Long zUnionStore(final String destKey, final String... keys){ + public Long zUnionStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZUNIONSTORE, (cmd)->cmd.zunionstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long zUnionStore(final byte[] destKey, final byte[]... keys){ + public Long zUnionStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZUNIONSTORE, (cmd)->cmd.zunionstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate){ + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisClusterCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionStore(destKey, keys, zParams, args); } @Override - public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate){ + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisClusterCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionStore(destKey, keys, zParams, args); } @Override - public Long zUnionStore(final String destKey, final String[] keys, final double... weights){ + public Long zUnionStore(final String destKey, final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisClusterCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnionStore(destKey, keys, zParams, args); } @Override - public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights){ + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisClusterCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnionStore(destKey, keys, zParams, args); } @Override public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate).put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisClusterCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionStore(destKey, keys, zParams, args); } @Override public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate).put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisClusterCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionStore(destKey, keys, zParams, args); + } + + private Long zAdd(final String key, final Map members, final ZAddParams zAddParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), + (v)->v) + .run(args); + } + } + + private Long zAdd(final byte[] key, final Map members, final ZAddParams zAddParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), + (v)->v) + .run(args); + } + } + + private List zInter(final String[] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinter(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + } + } + + private List zInter(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinter(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + } + } + + private List zInterWithScores(final String[] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinterWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private List zInterWithScores(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinterWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private Long zInterStore(final String destKey, final String[] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zInterStore(final byte[] destKey, final byte[][] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zLexCount(final String key, final String min, final String max, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + } + } + + private Long zLexCount(final byte[] key, final byte[] min, final byte[] max, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + } + } + + private List zRangeByLex(final String key, final String min, final String max, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYLEX, (cmd)->cmd.zrangeByLex(key, min, max), + (v)->v) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYLEX, (cmd)->cmd.zrangeByLex(key, min, max), + (v)->v) + .run(args); + } + } + + private List zRangeByLex(final String key, final String min, final String max, final long offset, + final long count, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + private Long zRangeStore(final String destKey, final String key, final ZRangeParams zRangeParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + } + } + + private Long zRangeStore(final byte[] destKey, final byte[] key, final ZRangeParams zRangeParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + } + } + + private ScanResult> zScan(final String key, final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + } + } + + private List zUnion(final String[] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunion(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + } + } + + private List zUnion(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunion(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + } + } + + private List zUnionWithScores(final String[] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunionWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private List zUnionWithScores(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunionWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private Long zUnionStore(final String destKey, final String[] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zUnionStore(final byte[] destKey, final byte[][] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterStreamOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterStreamOperations.java index f12e95c47..19fdba602 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterStreamOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterStreamOperations.java @@ -19,11 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapEntryMapConverter; import com.buession.lang.Status; import com.buession.redis.client.jedis.JedisClusterClient; import com.buession.redis.core.Stream; @@ -36,11 +38,7 @@ import com.buession.redis.core.StreamPendingSummary; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; import com.buession.redis.core.internal.convert.jedis.params.StreamEntryIdConverter; -import com.buession.redis.core.internal.convert.jedis.params.XAddArgumentConverter; -import com.buession.redis.core.internal.convert.jedis.params.XClaimArgumentConverter; -import com.buession.redis.core.internal.convert.jedis.params.XTrimArgumentConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamConsumersInfoConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamEntryConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamEntryIDConverter; @@ -49,15 +47,25 @@ import com.buession.redis.core.internal.convert.jedis.response.StreamInfoConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamPendingEntryConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamPendingSummaryConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import com.buession.redis.core.internal.jedis.JedisStreamEntryID; +import com.buession.redis.core.internal.jedis.JedisXAddParams; import com.buession.redis.core.internal.jedis.JedisXAutoClaimParams; +import com.buession.redis.core.internal.jedis.JedisXClaimParams; import com.buession.redis.core.internal.jedis.JedisXPendingParams; import com.buession.redis.core.internal.jedis.JedisXReadGroupParams; import com.buession.redis.core.internal.jedis.JedisXReadParams; +import com.buession.redis.core.internal.jedis.JedisXTrimParams; import redis.clients.jedis.StreamEntryID; import redis.clients.jedis.params.XAddParams; +import redis.clients.jedis.params.XAutoClaimParams; import redis.clients.jedis.params.XClaimParams; +import redis.clients.jedis.params.XPendingParams; +import redis.clients.jedis.params.XReadGroupParams; +import redis.clients.jedis.params.XReadParams; import redis.clients.jedis.params.XTrimParams; +import redis.clients.jedis.resps.StreamConsumersInfo; +import redis.clients.jedis.resps.StreamGroupInfo; +import redis.clients.jedis.resps.StreamPendingEntry; import java.util.List; import java.util.Map; @@ -70,815 +78,1040 @@ */ public final class JedisClusterStreamOperations extends AbstractStreamOperations { - public JedisClusterStreamOperations(final JedisClusterClient client){ + public JedisClusterStreamOperations(final JedisClusterClient client) { super(client); } @Override - public Long xAck(final String key, final String groupName, final StreamEntryId... ids){ - final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) - .put("ids", (Object[]) ids); - final StreamEntryID[] streamEntryIDS = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisClusterCommand(client, ProtocolCommand.XACK) - .general((cmd)->cmd.xack(key, groupName, streamEntryIDS)) - .pipeline((cmd)->cmd.xack(key, groupName, streamEntryIDS)) - .transaction((cmd)->cmd.xack(key, groupName, streamEntryIDS)) - .run(args); + public Long xAck(final String key, final String groupName, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create(key).add(groupName).add(ids); + final StreamEntryID[] streamEntryIDS = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + } } @Override - public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash){ + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash) { final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(id); - return new JedisClusterCommand(client, ProtocolCommand.XADD) - .general((cmd)->cmd.xadd(key, streamEntryID, hash), StreamEntryIDConverter.INSTANCE) - .pipeline((cmd)->cmd.xadd(key, streamEntryID, hash), StreamEntryIDConverter.INSTANCE) - .transaction((cmd)->cmd.xadd(key, streamEntryID, hash), StreamEntryIDConverter.INSTANCE) - .run(args); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XADD, + (cmd)->cmd.xadd(key, streamEntryID, hash), streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XADD, + (cmd)->cmd.xadd(key, streamEntryID, hash), streamEntryIDConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, streamEntryID, hash), + streamEntryIDConverter) + .run(args); + } } @Override public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash, - final XAddArgument xAddArgument){ + final XAddArgument xAddArgument) { final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) .put("xAddArgument", xAddArgument); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(id); - final XAddParams params = XAddArgumentConverter.INSTANCE.convert(xAddArgument).id(streamEntryID); - return new JedisClusterCommand(client, ProtocolCommand.XADD) - .general((cmd)->cmd.xadd(key, hash, params), StreamEntryIDConverter.INSTANCE) - .pipeline((cmd)->cmd.xadd(key, hash, params), StreamEntryIDConverter.INSTANCE) - .transaction((cmd)->cmd.xadd(key, hash, params), StreamEntryIDConverter.INSTANCE) - .run(args); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + final XAddParams xAddParams = JedisXAddParams.from(xAddArgument).id(streamEntryID); + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), streamEntryIDConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + streamEntryIDConverter) + .run(args); + } } @Override public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash, - final XAddArgument xAddArgument){ + final XAddArgument xAddArgument) { final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) .put("xAddArgument", xAddArgument); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(id); - final XAddParams params = XAddArgumentConverter.INSTANCE.convert(xAddArgument).id(streamEntryID); - return new JedisClusterCommand(client, ProtocolCommand.XADD) - .general((cmd)->cmd.xadd(key, hash, params), - StreamEntryIDConverter.BinaryStreamEntryIdConverter.INSTANCE) - .pipeline((cmd)->cmd.xadd(key, hash, params), - StreamEntryIDConverter.BinaryStreamEntryIdConverter.INSTANCE) - .transaction((cmd)->cmd.xadd(key, hash, params), - StreamEntryIDConverter.BinaryStreamEntryIdConverter.INSTANCE) - .run(args); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + final XAddParams xAddParams = JedisXAddParams.from(xAddArgument).id(streamEntryID); + final StreamEntryIDConverter.BinaryStreamEntryIdConverter binaryStreamEntryIdConverter = + new StreamEntryIDConverter.BinaryStreamEntryIdConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), binaryStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), binaryStreamEntryIdConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + binaryStreamEntryIdConverter) + .run(args); + } } @Override public Map> xAutoClaim(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start){ + final StreamEntryId start) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final JedisXAutoClaimParams params = new JedisXAutoClaimParams(); - return new JedisClusterCommand>>(client, ProtocolCommand.XAUTOCLAIM) - .general((cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .transaction( - (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .run(args); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); } @Override public Map> xAutoClaim(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start, final long count){ + final StreamEntryId start, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) .put("count", count); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final JedisXAutoClaimParams params = new JedisXAutoClaimParams(count); - return new JedisClusterCommand>>(client, ProtocolCommand.XAUTOCLAIM) - .general((cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .transaction( - (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .run(args); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(count); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); } @Override public Map> xAutoClaimJustId(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start){ + final StreamEntryId start) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) .put("count"); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final JedisXAutoClaimParams params = new JedisXAutoClaimParams(); - return new JedisClusterCommand>>(client, ProtocolCommand.XAUTOCLAIM) - .general((cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .pipeline((cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .transaction( - (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .run(args); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); } @Override public Map> xAutoClaimJustId(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start, final long count){ + final StreamEntryId start, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) .put("count", count); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final JedisXAutoClaimParams params = new JedisXAutoClaimParams(count); - return new JedisClusterCommand>>(client, ProtocolCommand.XAUTOCLAIM) - .general((cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .pipeline((cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .transaction( - (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .run(args); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); } @Override public List xClaim(final String key, final String groupName, final String consumerName, - final int minIdleTime, final StreamEntryId... ids){ + final int minIdleTime, final StreamEntryId... ids) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); - final XClaimParams params = new XClaimParams(); - final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisClusterCommand>(client, ProtocolCommand.XCLAIM) - .general((cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .transaction( - (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .run(args); + final XClaimParams xClaimParams = new JedisXClaimParams(); + + return xClaim(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); } @Override public List xClaim(final String key, final String groupName, final String consumerName, final int minIdleTime, final StreamEntryId[] ids, - final XClaimArgument xClaimArgument){ + final XClaimArgument xClaimArgument) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) .put("xClaimArgument", xClaimArgument); - final XClaimParams params = XClaimArgumentConverter.INSTANCE.convert(xClaimArgument); - final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisClusterCommand>(client, ProtocolCommand.XCLAIM) - .general((cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .transaction( - (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .run(args); + final XClaimParams xClaimParams = JedisXClaimParams.from(xClaimArgument); + + return xClaim(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); } @Override public List xClaimJustId(final String key, final String groupName, final String consumerName, - final int minIdleTime, final StreamEntryId... ids){ + final int minIdleTime, final StreamEntryId... ids) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); - final XClaimParams params = new XClaimParams(); - final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisClusterCommand>(client, ProtocolCommand.XCLAIM) - .general((cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .transaction( - (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .run(args); + final XClaimParams xClaimParams = new JedisXClaimParams(); + + return xClaimJustId(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); } @Override public List xClaimJustId(final String key, final String groupName, final String consumerName, final int minIdleTime, final StreamEntryId[] ids, - final XClaimArgument xClaimArgument){ + final XClaimArgument xClaimArgument) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) .put("xClaimArgument", xClaimArgument); - final XClaimParams params = XClaimArgumentConverter.INSTANCE.convert(xClaimArgument); - final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisClusterCommand>(client, ProtocolCommand.XCLAIM) - .general((cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .transaction( - (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .run(args); + final XClaimParams xClaimParams = JedisXClaimParams.from(xClaimArgument); + + return xClaimJustId(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); } @Override - public Long xDel(final String key, final StreamEntryId... ids){ + public Long xDel(final String key, final StreamEntryId... ids) { final CommandArguments args = CommandArguments.create("key", key).put("ids", (Object[]) ids); - final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisClusterCommand(client, ProtocolCommand.XDEL) - .general((cmd)->cmd.xdel(key, streamEntryIDs)) - .pipeline((cmd)->cmd.xdel(key, streamEntryIDs)) - .transaction((cmd)->cmd.xdel(key, streamEntryIDs)) - .run(args); + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XDEL, (cmd)->cmd.xdel(key, streamEntryIDs), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XDEL, + (cmd)->cmd.xdel(key, streamEntryIDs), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XDEL, (cmd)->cmd.xdel(key, streamEntryIDs), (v)->v) + .run(args); + } } @Override public Status xGroupCreate(final String key, final String groupName, final StreamEntryId id, - final boolean makeStream){ + final boolean makeStream) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("id", id); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(id); - return new JedisClusterCommand(client, ProtocolCommand.XGROUP_CREATE) - .general((cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), - OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), - OkStatusConverter.INSTANCE) - .run(args); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + } } @Override - public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName){ + public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - return new JedisClusterCommand(client, ProtocolCommand.XGROUP_CREATECONSUMER) - .general((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + } } @Override - public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName){ + public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - return new JedisClusterCommand(client, - ProtocolCommand.XGROUP_CREATECONSUMER) - .general((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + } } @Override - public Long xGroupDelConsumer(final String key, final String groupName, final String consumerName){ + public Long xGroupDelConsumer(final String key, final String groupName, final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - return new JedisClusterCommand(client, ProtocolCommand.XGROUP_DELCONSUMER) - .general((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .pipeline((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .transaction((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + } } @Override - public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName){ + public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - return new JedisClusterCommand(client, ProtocolCommand.XGROUP_DELCONSUMER) - .general((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .pipeline((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .transaction((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + } } @Override - public Status xGroupDestroy(final String key, final String groupName){ + public Status xGroupDestroy(final String key, final String groupName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); - return new JedisClusterCommand(client, ProtocolCommand.XGROUP_DESTROY) - .general((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + } } @Override - public Status xGroupDestroy(final byte[] key, final byte[] groupName){ + public Status xGroupDestroy(final byte[] key, final byte[] groupName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); - return new JedisClusterCommand(client, ProtocolCommand.XGROUP_DESTROY) - .general((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + } } @Override - public Status xGroupSetId(final String key, final String groupName, final StreamEntryId id){ + public Status xGroupSetId(final String key, final String groupName, final StreamEntryId id) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName).put("id", id); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(id); - return new JedisClusterCommand(client, ProtocolCommand.XGROUP_SETID) - .general((cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), OkStatusConverter.INSTANCE) - .run(args); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + } } @Override - public List xInfoConsumers(final String key, final String groupName){ + public List xInfoConsumers(final String key, final String groupName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); - return new JedisClusterCommand>(client, ProtocolCommand.XINFO_CONSUMERS) - .general((cmd)->cmd.xinfoConsumers(key, groupName), StreamConsumersInfoConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xinfoConsumers(key, groupName), StreamConsumersInfoConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xinfoConsumers(key, groupName), StreamConsumersInfoConverter.LIST_CONVERTER) - .run(args); + final ListConverter listStreamConsumersInfoConverter = + StreamConsumersInfoConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + } } @Override - public List xInfoGroups(final String key){ + public List xInfoGroups(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand>(client, ProtocolCommand.XINFO_GROUPS) - .general((cmd)->cmd.xinfoGroups(key), StreamGroupInfoConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xinfoGroups(key), StreamGroupInfoConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xinfoGroups(key), StreamGroupInfoConverter.LIST_CONVERTER) - .run(args); + final ListConverter listStreamGroupInfoConverter = + StreamGroupInfoConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XINFO_GROUPS, + (cmd)->cmd.xinfoGroups(key), listStreamGroupInfoConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + } } @Override - public Stream xInfoStream(final String key){ + public Stream xInfoStream(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.XINFO_STREAM) - .general((cmd)->cmd.xinfoStream(key), StreamInfoConverter.INSTANCE) - .pipeline((cmd)->cmd.xinfoStream(key), StreamInfoConverter.INSTANCE) - .transaction((cmd)->cmd.xinfoStream(key), StreamInfoConverter.INSTANCE) - .run(args); + final StreamInfoConverter streamInfoConverter = new StreamInfoConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStream(key), streamInfoConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamInfoConverter) + .run(args); + } } @Override - public StreamFull xInfoStream(final String key, final boolean full){ + public StreamFull xInfoStream(final String key, final boolean full) { final CommandArguments args = CommandArguments.create("key", key).put("full", full); - return new JedisClusterCommand(client, ProtocolCommand.XINFO_STREAM) - .general((cmd)->cmd.xinfoStreamFull(key), StreamFullInfoConverter.INSTANCE) - .pipeline((cmd)->cmd.xinfoStreamFull(key), StreamFullInfoConverter.INSTANCE) - .transaction((cmd)->cmd.xinfoStreamFull(key), StreamFullInfoConverter.INSTANCE) - .run(args); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key), streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key), streamFullInfoConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStreamFull(key), + streamFullInfoConverter) + .run(args); + } } @Override - public StreamFull xInfoStream(final String key, final boolean full, final long count){ + public StreamFull xInfoStream(final String key, final boolean full, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("full", full).put("count", count); - return new JedisClusterCommand(client, ProtocolCommand.XINFO_STREAM) - .general((cmd)->cmd.xinfoStreamFull(key, (int) count), StreamFullInfoConverter.INSTANCE) - .pipeline((cmd)->cmd.xinfoStreamFull(key, (int) count), StreamFullInfoConverter.INSTANCE) - .transaction((cmd)->cmd.xinfoStreamFull(key, (int) count), StreamFullInfoConverter.INSTANCE) - .run(args); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + } } @Override - public Long xLen(final String key){ + public Long xLen(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.XLEN) - .general((cmd)->cmd.xlen(key)) - .pipeline((cmd)->cmd.xlen(key)) - .transaction((cmd)->cmd.xlen(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } } @Override - public Long xLen(final byte[] key){ + public Long xLen(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.XLEN) - .general((cmd)->cmd.xlen(key)) - .pipeline((cmd)->cmd.xlen(key)) - .transaction((cmd)->cmd.xlen(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } } @Override - public StreamPendingSummary xPending(final String key, final String groupName){ + public StreamPendingSummary xPending(final String key, final String groupName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); - return new JedisClusterCommand(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName), StreamPendingSummaryConverter.INSTANCE) - .pipeline((cmd)->cmd.xpending(key, groupName), StreamPendingSummaryConverter.INSTANCE) - .transaction((cmd)->cmd.xpending(key, groupName), StreamPendingSummaryConverter.INSTANCE) - .run(args); + final StreamPendingSummaryConverter streamPendingSummaryConverter = new StreamPendingSummaryConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName), streamPendingSummaryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName), streamPendingSummaryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XPENDING, (cmd)->cmd.xpending(key, groupName), + streamPendingSummaryConverter) + .run(args); + } } @Override - public List xPending(final String key, final String groupName, final long minIdleTime){ + public List xPending(final String key, final String groupName, final long minIdleTime) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("minIdleTime", minIdleTime); - final JedisXPendingParams params = new JedisXPendingParams(minIdleTime); - return new JedisClusterCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime); + + return xPending(key, groupName, xPendingParams, args); } @Override public List xPending(final String key, final String groupName, final StreamEntryId start, - final StreamEntryId end, final long count){ + final StreamEntryId end, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("start", start).put("end", end).put("count", count); - final JedisXPendingParams params = new JedisXPendingParams(start, end, count); - return new JedisClusterCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count); + + return xPending(key, groupName, xPendingParams, args); } @Override - public List xPending(final String key, final String groupName, final String consumerName){ + public List xPending(final String key, final String groupName, final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - final JedisXPendingParams params = new JedisXPendingParams(consumerName); - return new JedisClusterCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(consumerName); + + return xPending(key, groupName, xPendingParams, args); } @Override public List xPending(final String key, final String groupName, final long minIdleTime, - final StreamEntryId start, final StreamEntryId end, final long count){ + final StreamEntryId start, final StreamEntryId end, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("minIdleTime", minIdleTime).put("start", start).put("end", end).put("count", count); - final JedisXPendingParams params = new JedisXPendingParams(minIdleTime, start, end, count); - return new JedisClusterCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime, start, end, count); + + return xPending(key, groupName, xPendingParams, args); } @Override public List xPending(final String key, final String groupName, final long minIdleTime, - final String consumerName){ + final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("minIdleTime", minIdleTime).put("consumerName", consumerName); - final JedisXPendingParams params = new JedisXPendingParams(minIdleTime, consumerName); - return new JedisClusterCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime, consumerName); + + return xPending(key, groupName, xPendingParams, args); } @Override public List xPending(final String key, final String groupName, final StreamEntryId start, - final StreamEntryId end, final long count, final String consumerName){ + final StreamEntryId end, final long count, final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - final JedisXPendingParams params = new JedisXPendingParams(start, end, count, consumerName); - return new JedisClusterCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count, consumerName); + + return xPending(key, groupName, xPendingParams, args); } @Override public List xPending(final String key, final String groupName, final long minIdleTime, final StreamEntryId start, final StreamEntryId end, final long count, - final String consumerName){ + final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("minIdleTime", minIdleTime).put("consumerName", consumerName); - final JedisXPendingParams params = new JedisXPendingParams(minIdleTime, start, end, count, consumerName); - return new JedisClusterCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime, start, end, count, consumerName); + + return xPending(key, groupName, xPendingParams, args); } @Override - public List xRange(final String key, final StreamEntryId start, final StreamEntryId end){ + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - final StreamEntryID startStreamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final StreamEntryID endStreamEntryID = StreamEntryIdConverter.INSTANCE.convert(end); - return new JedisClusterCommand>(client, ProtocolCommand.XRANGE) - .general((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), - StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), - StreamEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), - StreamEntryConverter.LIST_CONVERTER) - .run(args); + final StreamEntryID startStreamEntryID = JedisStreamEntryID.from(start); + final StreamEntryID endStreamEntryID = JedisStreamEntryID.from(end); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), listStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), listStreamEntryConverter) + .run(args); + } } @Override public List xRange(final String key, final StreamEntryId start, final StreamEntryId end, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - final StreamEntryID startStreamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final StreamEntryID endStreamEntryID = StreamEntryIdConverter.INSTANCE.convert(end); - return new JedisClusterCommand>(client, ProtocolCommand.XRANGE) - .general((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), - StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), - StreamEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), - StreamEntryConverter.LIST_CONVERTER) - .run(args); + final StreamEntryID startStreamEntryID = JedisStreamEntryID.from(start); + final StreamEntryID endStreamEntryID = JedisStreamEntryID.from(end); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), listStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), listStreamEntryConverter) + .run(args); + } } @Override - public List>> xRead(final Map streams){ + public List>> xRead(final Map streams) { final CommandArguments args = CommandArguments.create("streams", streams); - final JedisXReadParams params = new JedisXReadParams(); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisClusterCommand>>>(client, ProtocolCommand.XREAD) - .general((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadParams xReadParams = new JedisXReadParams(); + + return xRead(streams, xReadParams, args); } @Override - public List>> xRead(final long count, final Map streams){ + public List>> xRead(final long count, final Map streams) { final CommandArguments args = CommandArguments.create("count", count).put("streams", streams); - final JedisXReadParams params = new JedisXReadParams(count); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisClusterCommand>>>(client, ProtocolCommand.XREAD) - .general((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadParams xReadParams = new JedisXReadParams(count); + + return xRead(streams, xReadParams, args); } @Override - public List>> xRead(final int block, final Map streams){ + public List>> xRead(final int block, final Map streams) { final CommandArguments args = CommandArguments.create("block", block).put("streams", streams); - final JedisXReadParams params = new JedisXReadParams(block); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisClusterCommand>>>( - client, ProtocolCommand.XREAD) - .general((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadParams xReadParams = new JedisXReadParams(block); + + return xRead(streams, xReadParams, args); } @Override public List>> xRead(final long count, final int block, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("count", count).put("block", block) .put("streams", streams); - final JedisXReadParams params = new JedisXReadParams(count, block); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisClusterCommand>>>(client, ProtocolCommand.XREAD) - .general((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadParams xReadParams = new JedisXReadParams(count, block); + + return xRead(streams, xReadParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisClusterCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, - final long count, final Map streams){ + final long count, final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("count", count).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(count); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisClusterCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(count); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, - final int block, final Map streams){ + final int block, final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("block", block).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(block); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisClusterCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(block); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final boolean isNoAck, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("isNoAck", isNoAck).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(isNoAck); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisClusterCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final long count, final int block, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("count", count).put("block", block).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(count, block); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisClusterCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(count, block); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final long count, final boolean isNoAck, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("count", count).put("isNoAck", isNoAck).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(count, isNoAck); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisClusterCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(count, isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final int block, final boolean isNoAck, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("block", block).put("isNoAck", isNoAck).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(block, isNoAck); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisClusterCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(block, isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final long count, final int block, final boolean isNoAck, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("count", count).put("block", block).put("isNoAck", isNoAck).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(count, block, isNoAck); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisClusterCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(count, block, isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override - public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start){ + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start) { final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start); - final StreamEntryID endID = StreamEntryIdConverter.INSTANCE.convert(end); - final StreamEntryID startID = StreamEntryIdConverter.INSTANCE.convert(start); - return new JedisClusterCommand>(client, ProtocolCommand.XREVRANGE) - .general((cmd)->cmd.xrevrange(key, endID, startID), StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xrevrange(key, endID, startID), StreamEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xrevrange(key, endID, startID), StreamEntryConverter.LIST_CONVERTER) - .run(args); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), listStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), listStreamEntryConverter) + .run(args); + } } @Override public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start) .put("count", count); - final StreamEntryID endID = StreamEntryIdConverter.INSTANCE.convert(end); - final StreamEntryID startID = StreamEntryIdConverter.INSTANCE.convert(start); - return new JedisClusterCommand>(client, ProtocolCommand.XREVRANGE) - .general((cmd)->cmd.xrevrange(key, endID, startID, (int) count), StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xrevrange(key, endID, startID, (int) count), StreamEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xrevrange(key, endID, startID, (int) count), - StreamEntryConverter.LIST_CONVERTER) - .run(args); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + } } @Override - public Long xTrim(final String key, final XTrimArgument xTrimArgument){ + public Long xTrim(final String key, final XTrimArgument xTrimArgument) { final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); - final XTrimParams params = XTrimArgumentConverter.INSTANCE.convert(xTrimArgument); - return new JedisClusterCommand(client, ProtocolCommand.XTRIM) - .general((cmd)->cmd.xtrim(key, params)) - .pipeline((cmd)->cmd.xtrim(key, params)) - .transaction((cmd)->cmd.xtrim(key, params)) - .run(args); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument); + + return xTrim(key, xTrimParams, args); } @Override - public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument){ + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument) { final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); - final XTrimParams params = XTrimArgumentConverter.INSTANCE.convert(xTrimArgument); - return new JedisClusterCommand(client, ProtocolCommand.XTRIM) - .general((cmd)->cmd.xtrim(key, params)) - .pipeline((cmd)->cmd.xtrim(key, params)) - .transaction((cmd)->cmd.xtrim(key, params)) - .run(args); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument); + + return xTrim(key, xTrimParams, args); } @Override - public Long xTrim(final String key, final XTrimArgument xTrimArgument, final long limit){ + public Long xTrim(final String key, final XTrimArgument xTrimArgument, final long limit) { final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) .put("limit", limit); - final XTrimParams params = XTrimArgumentConverter.INSTANCE.convert(xTrimArgument).limit(limit); - return new JedisClusterCommand(client, ProtocolCommand.XTRIM) - .general((cmd)->cmd.xtrim(key, params)) - .pipeline((cmd)->cmd.xtrim(key, params)) - .transaction((cmd)->cmd.xtrim(key, params)) - .run(args); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument).limit(limit); + + return xTrim(key, xTrimParams, args); } @Override - public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit){ + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit) { final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) .put("limit", limit); - final XTrimParams params = XTrimArgumentConverter.INSTANCE.convert(xTrimArgument).limit(limit); - return new JedisClusterCommand(client, ProtocolCommand.XTRIM) - .general((cmd)->cmd.xtrim(key, params)) - .pipeline((cmd)->cmd.xtrim(key, params)) - .transaction((cmd)->cmd.xtrim(key, params)) - .run(args); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument).limit(limit); + + return xTrim(key, xTrimParams, args); + } + + private Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, + final XAutoClaimParams xAutoClaimParams, + final CommandArguments args) { + final StreamEntryID startStreamEntryID = JedisStreamEntryID.from(start); + final StreamEntryConverter.MapEntryStreamEntryConverter mapEntryStreamEntryConverter = + new StreamEntryConverter.MapEntryStreamEntryConverter<>(new StreamEntryIDConverter()); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryConverter) + .run(args); + } + } + + private Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, + final XAutoClaimParams xAutoClaimParams, + final CommandArguments args) { + final StreamEntryID startStreamEntryID = JedisStreamEntryID.from(start); + final MapEntryMapConverter, StreamEntryId, List> mapEntryStreamEntryIdConverter = StreamEntryIDConverter.mapEntryMapConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryIdConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryIdConverter) + .run(args); + } + } + + private List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, final XClaimParams xClaimParams, + final CommandArguments args) { + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + } + } + + private List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimParams xClaimParams, final CommandArguments args) { + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter listStreamEntryIDConverter = StreamEntryIDConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + } + } + + private List xPending(final String key, final String groupName, + final XPendingParams xPendingParams, final CommandArguments args) { + final ListConverter listStreamPendingEntryConverter = + StreamPendingEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + } + } + + private List>> xRead(final Map streams, + final XReadParams xReadParams, final CommandArguments args) { + final Map stringStreamEntryIDMap = StreamEntryIdConverter.mapConverter().convert( + streams); + final StreamEntryConverter.ListMapEntryStreamEntryConverter listMapEntryStreamEntryConverter = + new StreamEntryConverter.ListMapEntryStreamEntryConverter<>((k)->k); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadGroupParams xReadGroupParams, + final CommandArguments args) { + final Map stringStreamEntryIDMap = StreamEntryIdConverter.mapConverter().convert( + streams); + final StreamEntryConverter.ListMapEntryStreamEntryConverter listMapEntryStreamEntryConverter = + new StreamEntryConverter.ListMapEntryStreamEntryConverter<>((k)->k); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + } + } + + private Long xTrim(final String key, final XTrimParams xTrimParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XTRIM, + (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + } + } + + private Long xTrim(final byte[] key, final XTrimParams xTrimParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.XTRIM, + (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterStringOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterStringOperations.java index 3ce1dfd35..b81e26514 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterStringOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterStringOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -28,10 +28,8 @@ import com.buession.redis.client.jedis.JedisClusterClient; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; -import com.buession.redis.core.internal.convert.jedis.params.GetExArgumentConverter; -import com.buession.redis.core.internal.convert.jedis.params.SetArgumentConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import com.buession.redis.core.internal.jedis.JedisGetExParams; +import com.buession.redis.core.internal.jedis.JedisSetParams; import redis.clients.jedis.params.GetExParams; import redis.clients.jedis.params.SetParams; @@ -47,234 +45,392 @@ */ public final class JedisClusterStringOperations extends AbstractStringOperations { - public JedisClusterStringOperations(final JedisClusterClient client){ + public JedisClusterStringOperations(final JedisClusterClient client) { super(client); } @Override - public Long append(final String key, final String value){ + public Long append(final String key, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.APPEND) - .general((cmd)->cmd.append(key, value)) - .pipeline((cmd)->cmd.append(key, value)) - .transaction((cmd)->cmd.append(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } } @Override - public Long append(final byte[] key, final byte[] value){ + public Long append(final byte[] key, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.APPEND) - .general((cmd)->cmd.append(key, value)) - .pipeline((cmd)->cmd.append(key, value)) - .transaction((cmd)->cmd.append(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } } @Override - public Long incr(final String key){ + public Long incr(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.INCR) - .general((cmd)->cmd.incr(key)) - .pipeline((cmd)->cmd.incr(key)) - .transaction((cmd)->cmd.incr(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } } @Override - public Long incr(final byte[] key){ + public Long incr(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.INCR) - .general((cmd)->cmd.incr(key)) - .pipeline((cmd)->cmd.incr(key)) - .transaction((cmd)->cmd.incr(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } } @Override - public Long incrBy(final String key, final long value){ + public Long incrBy(final String key, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.INCRBY) - .general((cmd)->cmd.incrBy(key, value)) - .pipeline((cmd)->cmd.incrBy(key, value)) - .transaction((cmd)->cmd.incrBy(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + } } @Override - public Long incrBy(final byte[] key, final long value){ + public Long incrBy(final byte[] key, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.INCRBY) - .general((cmd)->cmd.incrBy(key, value)) - .pipeline((cmd)->cmd.incrBy(key, value)) - .transaction((cmd)->cmd.incrBy(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + } } @Override - public Double incrByFloat(final String key, final double value){ + public Double incrByFloat(final String key, final double value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.INCRBYFLOAT) - .general((cmd)->cmd.incrByFloat(key, value)) - .pipeline((cmd)->cmd.incrByFloat(key, value)) - .transaction((cmd)->cmd.incrByFloat(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), + (v)->v) + .run(args); + } } @Override - public Double incrByFloat(final byte[] key, final double value){ + public Double incrByFloat(final byte[] key, final double value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.INCRBYFLOAT) - .general((cmd)->cmd.incrByFloat(key, value)) - .pipeline((cmd)->cmd.incrByFloat(key, value)) - .transaction((cmd)->cmd.incrByFloat(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), + (v)->v) + .run(args); + } } @Override - public Long decr(final String key){ + public Long decr(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.DECR) - .general((cmd)->cmd.decr(key)) - .pipeline((cmd)->cmd.decr(key)) - .transaction((cmd)->cmd.decr(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } } @Override - public Long decr(final byte[] key){ + public Long decr(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.DECR) - .general((cmd)->cmd.decr(key)) - .pipeline((cmd)->cmd.decr(key)) - .transaction((cmd)->cmd.decr(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } } @Override - public Long decrBy(final String key, final long value){ + public Long decrBy(final String key, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.DECRBY) - .general((cmd)->cmd.decrBy(key, value)) - .pipeline((cmd)->cmd.decrBy(key, value)) - .transaction((cmd)->cmd.decrBy(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + } } @Override - public Long decrBy(final byte[] key, final long value){ + public Long decrBy(final byte[] key, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.DECRBY) - .general((cmd)->cmd.decrBy(key, value)) - .pipeline((cmd)->cmd.decrBy(key, value)) - .transaction((cmd)->cmd.decrBy(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + } } @Override - public String get(final String key){ + public String get(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.GET) - .general((cmd)->cmd.get(key)) - .pipeline((cmd)->cmd.get(key)) - .transaction((cmd)->cmd.get(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + } } @Override - public byte[] get(final byte[] key){ + public byte[] get(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.GET) - .general((cmd)->cmd.get(key)) - .pipeline((cmd)->cmd.get(key)) - .transaction((cmd)->cmd.get(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + } } @Override - public String getEx(final String key, final GetExArgument getExArgument){ + public String getEx(final String key, final GetExArgument getExArgument) { final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); - final GetExParams params = GetExArgumentConverter.INSTANCE.convert(getExArgument); - return new JedisClusterCommand(client, ProtocolCommand.GETEX) - .general((cmd)->cmd.getEx(key, params)) - .pipeline((cmd)->cmd.getEx(key, params)) - .transaction((cmd)->cmd.getEx(key, params)) - .run(args); + final GetExParams getExParams = JedisGetExParams.from(getExArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GETEX, (cmd)->cmd.getEx(key, getExParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GETEX, + (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + } } @Override - public byte[] getEx(final byte[] key, final GetExArgument getExArgument){ + public byte[] getEx(final byte[] key, final GetExArgument getExArgument) { final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); - final GetExParams params = GetExArgumentConverter.INSTANCE.convert(getExArgument); - return new JedisClusterCommand(client, ProtocolCommand.GETEX) - .general((cmd)->cmd.getEx(key, params)) - .pipeline((cmd)->cmd.getEx(key, params)) - .transaction((cmd)->cmd.getEx(key, params)) - .run(args); + final GetExParams getExParams = JedisGetExParams.from(getExArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GETEX, (cmd)->cmd.getEx(key, getExParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GETEX, + (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + } } @Override - public String getSet(final String key, final String value){ + public String getSet(final String key, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.GETSET) - .general((cmd)->cmd.getSet(key, value)) - .pipeline((cmd)->cmd.getSet(key, value)) - .transaction((cmd)->cmd.getSet(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + } } @Override - public byte[] getSet(final byte[] key, final byte[] value){ + public byte[] getSet(final byte[] key, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.GETSET) - .general((cmd)->cmd.getSet(key, value)) - .pipeline((cmd)->cmd.getSet(key, value)) - .transaction((cmd)->cmd.getSet(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + } } @Override - public String getDel(final String key){ + public String getDel(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.GETDEL) - .general((cmd)->cmd.getDel(key)) - .pipeline((cmd)->cmd.getDel(key)) - .transaction((cmd)->cmd.getDel(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + } } @Override - public byte[] getDel(final byte[] key){ + public byte[] getDel(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.GETDEL) - .general((cmd)->cmd.getDel(key)) - .pipeline((cmd)->cmd.getDel(key)) - .transaction((cmd)->cmd.getDel(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + } } @Override - public List mGet(final String... keys){ + public List mGet(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand>(client, ProtocolCommand.MGET) - .general((cmd)->cmd.mget(keys)) - .pipeline((cmd)->cmd.mget(keys)) - .transaction((cmd)->cmd.mget(keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + } } @Override - public List mGet(final byte[]... keys){ + public List mGet(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand>(client, ProtocolCommand.MGET) - .general((cmd)->cmd.mget(keys)) - .pipeline((cmd)->cmd.mget(keys)) - .transaction((cmd)->cmd.mget(keys)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + } } @Override - public Status mSet(final Map values){ + public Status mSet(final Map values) { final CommandArguments args = CommandArguments.create("values", values); final List temp = new ArrayList<>(values.size() * 2); @@ -284,15 +440,24 @@ public Status mSet(final Map values){ }); final String[] keysValues = temp.toArray(new String[0]); - return new JedisClusterCommand(client, ProtocolCommand.MSET) - .general((cmd)->cmd.mset(keysValues), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.mset(keysValues), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.mset(keysValues), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + } } @Override - public Status mSetNx(final Map values){ + public Status mSetNx(final Map values) { final CommandArguments args = CommandArguments.create("values", values); final List temp = new ArrayList<>(values.size() * 2); @@ -302,191 +467,356 @@ public Status mSetNx(final Map values){ }); final String[] keysValues = temp.toArray(new String[0]); - return new JedisClusterCommand(client, ProtocolCommand.MSETNX) - .general((cmd)->cmd.msetnx(keysValues), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.msetnx(keysValues), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.msetnx(keysValues), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + } } @Override - public Status pSetEx(final String key, final String value, final int lifetime){ + public Status pSetEx(final String key, final String value, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); - return new JedisClusterCommand(client, ProtocolCommand.PSETEX) - .general((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } } @Override - public Status pSetEx(final byte[] key, final byte[] value, final int lifetime){ + public Status pSetEx(final byte[] key, final byte[] value, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); - return new JedisClusterCommand(client, ProtocolCommand.PSETEX) - .general((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } } @Override - public Status set(final String key, final String value){ + public Status set(final String key, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.SET) - .general((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), okStatusConverter) + .run(args); + } } @Override - public Status set(final byte[] key, final byte[] value){ + public Status set(final byte[] key, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.SET) - .general((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), okStatusConverter) + .run(args); + } } @Override - public Status set(final String key, final String value, final SetArgument setArgument){ + public Status set(final String key, final String value, final SetArgument setArgument) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - final SetParams params = SetArgumentConverter.INSTANCE.convert(setArgument); - return new JedisClusterCommand(client, ProtocolCommand.SET) - .general((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .run(args); + final SetParams setParams = JedisSetParams.from(setArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SET, + (cmd)->cmd.set(key, value, setParams), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + } } @Override - public Status set(final byte[] key, final byte[] value, final SetArgument setArgument){ + public Status set(final byte[] key, final byte[] value, final SetArgument setArgument) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - final SetParams params = SetArgumentConverter.INSTANCE.convert(setArgument); - return new JedisClusterCommand(client, ProtocolCommand.SET) - .general((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .run(args); + final SetParams setParams = JedisSetParams.from(setArgument); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SET, + (cmd)->cmd.set(key, value, setParams), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + } } @Override - public Status setEx(final String key, final String value, final int lifetime){ + public Status setEx(final String key, final String value, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); - return new JedisClusterCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } } @Override - public Status setEx(final byte[] key, final byte[] value, final int lifetime){ + public Status setEx(final byte[] key, final byte[] value, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); - return new JedisClusterCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } } @Override - public Status setNx(final String key, final String value){ + public Status setNx(final String key, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + } } @Override - public Status setNx(final byte[] key, final byte[] value){ + public Status setNx(final byte[] key, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + } } @Override - public Long setRange(final String key, final long offset, final String value){ + public Long setRange(final String key, final long offset, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setrange(key, offset, value)) - .pipeline((cmd)->cmd.setrange(key, offset, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SETRANGE, (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + } } @Override - public Long setRange(final byte[] key, final long offset, final byte[] value){ + public Long setRange(final byte[] key, final long offset, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); - return new JedisClusterCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setrange(key, offset, value)) - .pipeline((cmd)->cmd.setrange(key, offset, value)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SETRANGE, (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + } } @Override - public String getRange(final String key, final long start, final long end){ + public String getRange(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand(client, ProtocolCommand.GETRANGE) - .general((cmd)->cmd.getrange(key, start, end)) - .pipeline((cmd)->cmd.getrange(key, start, end)) - .transaction((cmd)->cmd.getrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + } } @Override - public byte[] getRange(final byte[] key, final long start, final long end){ + public byte[] getRange(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand(client, ProtocolCommand.GETRANGE) - .general((cmd)->cmd.getrange(key, start, end)) - .pipeline((cmd)->cmd.getrange(key, start, end)) - .transaction((cmd)->cmd.getrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + } } @Override - public Long strlen(final String key){ + public Long strlen(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.STRLEN) - .general((cmd)->cmd.strlen(key)) - .pipeline((cmd)->cmd.strlen(key)) - .transaction((cmd)->cmd.strlen(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } } @Override - public Long strlen(final byte[] key){ + public Long strlen(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisClusterCommand(client, ProtocolCommand.STRLEN) - .general((cmd)->cmd.strlen(key)) - .pipeline((cmd)->cmd.strlen(key)) - .transaction((cmd)->cmd.strlen(key)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } } @Override - public String substr(final String key, final long start, final long end){ + public String substr(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand(client, ProtocolCommand.SUBSTR) - .general((cmd)->cmd.substr(key, (int) start, (int) end)) - .pipeline((cmd)->cmd.substr(key, (int) start, (int) end)) - .transaction((cmd)->cmd.substr(key, (int) start, (int) end)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + } } @Override - public byte[] substr(final byte[] key, final long start, final long end){ + public byte[] substr(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisClusterCommand(client, ProtocolCommand.SUBSTR) - .general((cmd)->cmd.substr(key, (int) start, (int) end)) - .pipeline((cmd)->cmd.substr(key, (int) start, (int) end)) - .transaction((cmd)->cmd.substr(key, (int) start, (int) end)) - .run(args); + + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterTransactionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterTransactionOperations.java index 308a4dd3b..4b240f56b 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterTransactionOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisClusterTransactionOperations.java @@ -19,19 +19,16 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; -import com.buession.core.validator.Validate; import com.buession.lang.Status; import com.buession.redis.client.connection.RedisConnection; import com.buession.redis.client.jedis.JedisClusterClient; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.TransactionResultConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; import redis.clients.jedis.Builder; import redis.clients.jedis.Response; @@ -45,109 +42,194 @@ */ public final class JedisClusterTransactionOperations extends AbstractTransactionOperations { - public JedisClusterTransactionOperations(final JedisClusterClient client){ + public JedisClusterTransactionOperations(final JedisClusterClient client) { super(client); } @Override - public Status multi(){ - return new JedisClusterCommand(client, ProtocolCommand.MULTI) - .general((cmd)->{ - RedisConnection connection = client.getConnection(); - connection.multi(); + public void discard() { + if(isPipeline()){ + new JedisClusterPipelineCommand<>(client, ProtocolCommand.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new JedisClusterTransactionCommand<>(client, ProtocolCommand.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + }else{ + new JedisClusterCommand<>(client, ProtocolCommand.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + } + } - return Status.SUCCESS; - }).transaction((cmd)->{ - RedisConnection connection = client.getConnection(); - connection.multi(); + @Override + public List exec() { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); - return new Response<>(new Builder() { + return new Response<>(new Builder>() { - @Override - public Status build(Object data){ - return Status.SUCCESS; - } + @Override + public List build(Object data) { + return connection.exec(); + } + + }); + }, (v)->v).run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); + + return new Response<>(new Builder>() { - }); - }) - .run(); + @Override + public List build(Object data) { + return connection.exec(); + } + + }); + }, (v)->v).run(); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); + return connection.exec(); + }, (v)->v).run(); + } } @Override - public List exec(){ - return new JedisClusterCommand>(client, - ProtocolCommand.EXEC) - .transaction((cmd)->{ - RedisConnection connection = client.getConnection(); - List results = connection.exec(); + public Status multi() { + if(isPipeline()){ + return new JedisClusterPipelineCommand<>(client, ProtocolCommand.MULTI, (cmd)->{ + RedisConnection connection = client.getConnection(); - return new Response<>(new Builder>() { + return new Response<>(new Builder() { - @Override - public List build(Object data){ - return Validate.isEmpty(results) ? results : new TransactionResultConverter<>( - client.getTxResults()).convert( - results); + @Override + public Status build(Object data) { + try{ + connection.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; } + } - }); - }) - .run(); - } + }); + }, (v)->v) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.MULTI, (cmd)->{ + RedisConnection connection = client.getConnection(); - @Override - public void discard(){ - new JedisClusterCommand<>(client, ProtocolCommand.DISCARD) - .transaction((cmd)->{ - RedisConnection connection = client.getConnection(); - connection.discard(); - return null; - }) - .run(); + return new Response<>(new Builder() { + + @Override + public Status build(Object data) { + try{ + connection.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; + } + } + + }); + }, (v)->v) + .run(); + }else{ + return new JedisClusterCommand<>(client, ProtocolCommand.MULTI, (cmd)->{ + RedisConnection connection = client.getConnection(); + try{ + connection.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; + } + }, (v)->v) + .run(); + } } @Override - public Status watch(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.WATCH) - .transaction((cmd)->new Response<>(new Builder() { + public Status unwatch() { + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.UNWATCH) + .run(); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.UNWATCH, + (cmd)->new Response<>(new Builder() { - @Override - public String build(Object data){ - return cmd.watch(keys); - } + @Override + public String build(Object data) { + return cmd.unwatch(); + } - }), OkStatusConverter.INSTANCE) - .run(args); + }), okStatusConverter) + .run(); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.UNWATCH) + .run(); + } } @Override - public Status watch(final byte[]... keys){ + public Status watch(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisClusterCommand(client, ProtocolCommand.WATCH) - .transaction((cmd)->new Response<>(new Builder() { - @Override - public String build(Object data){ - return cmd.watch(keys); - } + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.WATCH) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.WATCH, + (cmd)->new Response<>(new Builder() { + + @Override + public String build(Object data) { + return cmd.watch(keys); + } - }), OkStatusConverter.INSTANCE) - .run(args); + }), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.WATCH) + .run(args); + } } @Override - public Status unwatch(){ - return new JedisClusterCommand(client, ProtocolCommand.UNWATCH) - .transaction((cmd)->new Response<>(new Builder() { + public Status watch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - @Override - public String build(Object data){ - return cmd.unwatch(); - } + if(isPipeline()){ + return new JedisClusterPipelineCommand(client, ProtocolCommand.WATCH) + .run(args); + }else if(isTransaction()){ + return new JedisClusterTransactionCommand<>(client, ProtocolCommand.WATCH, + (cmd)->new Response<>(new Builder() { + + @Override + public String build(Object data) { + return cmd.watch(keys); + } - }), OkStatusConverter.INSTANCE) - .run(); + }), okStatusConverter) + .run(args); + }else{ + return new JedisClusterCommand(client, ProtocolCommand.WATCH) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisConnectionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisConnectionOperations.java index 213cc0834..89b6785bb 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisConnectionOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisConnectionOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -32,12 +32,11 @@ import com.buession.redis.core.ClientUnblockType; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; import com.buession.redis.core.internal.convert.jedis.params.ClientTypeConverter; import com.buession.redis.core.internal.convert.jedis.params.ClientUnblockTypeConverter; import com.buession.redis.core.internal.convert.response.ClientConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; import com.buession.redis.core.internal.convert.response.PingResultConverter; +import redis.clients.jedis.args.UnblockType; import java.util.List; @@ -49,175 +48,366 @@ */ public final class JedisConnectionOperations extends AbstractConnectionOperations { - public JedisConnectionOperations(final JedisStandaloneClient client){ + public JedisConnectionOperations(final JedisStandaloneClient client) { super(client); } @Override - public Status auth(final String user, final String password){ + public Status auth(final String user, final String password) { final CommandArguments args = CommandArguments.create("user", user).put("password", password); - return new JedisCommand(client, ProtocolCommand.AUTH) - .general((cmd)->cmd.auth(user, password), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.AUTH) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.AUTH) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.AUTH, (cmd)->cmd.auth(user, password), + okStatusConverter) + .run(args); + } } @Override - public Status auth(final String password){ + public Status auth(final String password) { final CommandArguments args = CommandArguments.create("password", password); - return new JedisCommand(client, ProtocolCommand.AUTH) - .general((cmd)->cmd.auth(password), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.AUTH) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.AUTH) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.AUTH, (cmd)->cmd.auth(password), + okStatusConverter) + .run(args); + } } @Override - public String echo(final String str){ + public String echo(final String str) { final CommandArguments args = CommandArguments.create("str", str); - return new JedisCommand(client, ProtocolCommand.ECHO) - .general((cmd)->cmd.echo(str)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.ECHO) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.ECHO) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.echo(str), (v)->v) + .run(args); + } } @Override - public byte[] echo(final byte[] str){ + public byte[] echo(final byte[] str) { final CommandArguments args = CommandArguments.create("str", str); - return new JedisCommand(client, ProtocolCommand.ECHO) - .general((cmd)->cmd.echo(str)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.ECHO) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.ECHO) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.echo(str), (v)->v) + .run(args); + } } @Override - public Status ping(){ - return new JedisCommand(client, ProtocolCommand.PING) - .general((cmd)->cmd.ping(), PingResultConverter.INSTANCE) - .run(); + public Status ping() { + final PingResultConverter pingResultConverter = new PingResultConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.PING) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.PING) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PING, (cmd)->cmd.ping(), pingResultConverter) + .run(); + } } @Override - public Status reset(){ - return new JedisCommand(client, ProtocolCommand.RESET) - .run(); + public Status reset() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.RESET) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.RESET) + .run(); + }else{ + return new JedisCommand(client, ProtocolCommand.RESET) + .run(); + } } @Override - public Status quit(){ - return new JedisCommand(client, ProtocolCommand.QUIT) - .general((cmd)->cmd.quit(), OkStatusConverter.INSTANCE) - .run(); + public Status quit() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.QUIT) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.QUIT) + .run(); + }else{ + return new JedisCommand(client, ProtocolCommand.QUIT) + .run(); + } } @Override - public Status select(final int db){ + public Status select(final int db) { final CommandArguments args = CommandArguments.create("db", db); - return new JedisCommand(client, ProtocolCommand.SELECT) - .general((cmd)->cmd.select(db), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.select(db), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SELECT, (cmd)->cmd.select(db), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.SELECT) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SELECT, (cmd)->cmd.select(db), okStatusConverter) + .run(args); + } } @Override - public Status clientCaching(final boolean isYes){ + public Status clientCaching(final boolean isYes) { final CommandArguments args = CommandArguments.create("isYes", isYes); - return new JedisCommand(client, ProtocolCommand.CLIENT_CACHING) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + }else{ + return new JedisCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + } } @Override - public Long clientId(){ - return new JedisCommand(client, ProtocolCommand.CLIENT_ID) - .general((cmd)->cmd.clientId()) - .run(); + public Long clientId() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLIENT_ID) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLIENT_ID) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLIENT_ID, (cmd)->cmd.clientId(), (v)->v) + .run(); + } } @Override - public Status clientSetName(final String name){ + public Status clientSetName(final String name) { final CommandArguments args = CommandArguments.create("name", name); - return new JedisCommand(client, ProtocolCommand.CLIENT_SETNAME) - .general((cmd)->cmd.clientSetname(name), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLIENT_SETNAME) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLIENT_SETNAME) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + } } @Override - public Status clientSetName(final byte[] name){ + public Status clientSetName(final byte[] name) { final CommandArguments args = CommandArguments.create("name", name); - return new JedisCommand(client, ProtocolCommand.CLIENT_SETNAME) - .general((cmd)->cmd.clientSetname(name), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLIENT_SETNAME) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLIENT_SETNAME) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + } } @Override - public String clientGetName(){ - return new JedisCommand(client, ProtocolCommand.CLIENT_GETNAME) - .general((cmd)->cmd.clientGetname()) - .run(); + public String clientGetName() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLIENT_GETNAME) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLIENT_GETNAME) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLIENT_GETNAME, + (cmd)->cmd.clientGetname(), (v)->v) + .run(); + } } @Override - public Integer clientGetRedir(){ - return new JedisCommand(client, ProtocolCommand.CLIENT_GETREDIR) - .run(); + public Integer clientGetRedir() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + }else{ + return new JedisCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + } } @Override - public List clientList(){ - return new JedisCommand>(client, ProtocolCommand.CLIENT_LIST) - .general((cmd)->cmd.clientList(), ClientConverter.ClientListConverter.INSTANCE) - .run(); + public List clientList() { + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.CLIENT_LIST) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, ProtocolCommand.CLIENT_LIST) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), clientListConverter) + .run(); + } } @Override - public List clientList(final ClientType clientType){ + public List clientList(final ClientType clientType) { final CommandArguments args = CommandArguments.create("clientType", clientType); - return new JedisCommand>(client, ProtocolCommand.CLIENT_LIST) - .general((cmd)->cmd.clientList(ClientTypeConverter.INSTANCE.convert(clientType)), - ClientConverter.ClientListConverter.INSTANCE) - .run(args); + final redis.clients.jedis.args.ClientType jClientType = (new ClientTypeConverter()).convert(clientType); + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.CLIENT_LIST) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, ProtocolCommand.CLIENT_LIST) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(jClientType), + clientListConverter) + .run(args); + } } @Override - public Client clientInfo(){ - return new JedisCommand(client, ProtocolCommand.CLIENT_INFO) - .general((cmd)->cmd.clientInfo(), ClientConverter.INSTANCE) - .run(); + public Client clientInfo() { + final ClientConverter clientConverter = new ClientConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLIENT_LIST) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLIENT_LIST) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientInfo(), + clientConverter) + .run(); + } } @Override - public Status clientPause(final int timeout){ + public Status clientPause(final int timeout) { final CommandArguments args = CommandArguments.create("timeout", timeout); - return new JedisCommand(client, ProtocolCommand.CLIENT_PAUSE) - .general((cmd)->cmd.clientPause(timeout), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLIENT_PAUSE) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLIENT_PAUSE) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLIENT_PAUSE, (cmd)->cmd.clientInfo(), + okStatusConverter) + .run(args); + } } @Override - public Status clientReply(final ClientReply option){ + public Status clientReply(final ClientReply option) { final CommandArguments args = CommandArguments.create("option", option); - return new JedisCommand(client, ProtocolCommand.CLIENT_REPLY) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + }else{ + return new JedisCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + } } @Override - public Status clientKill(final String host, final int port){ + public Status clientKill(final String host, final int port) { final CommandArguments args = CommandArguments.create("host", host).put("port", port); - return new JedisCommand(client, ProtocolCommand.CLIENT_PAUSE) - .general((cmd)->cmd.clientKill(host + ":" + port), OkStatusConverter.INSTANCE) - .run(args); + final String addr = host + ':' + port; + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLIENT_KILL) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLIENT_KILL) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLIENT_KILL, (cmd)->cmd.clientKill(addr), + okStatusConverter) + .run(args); + } } @Override - public Status clientUnblock(final int clientId){ + public Status clientUnblock(final int clientId) { final CommandArguments args = CommandArguments.create("clientId", clientId); - return new JedisCommand(client, ProtocolCommand.CLIENT_UNBLOCK) - .general((cmd)->cmd.clientUnblock(clientId, null), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLIENT_UNBLOCK) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLIENT_UNBLOCK) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLIENT_UNBLOCK, (cmd)->cmd.clientUnblock(clientId), + oneStatusConverter) + .run(args); + } } @Override - public Status clientUnblock(final int clientId, final ClientUnblockType type){ + public Status clientUnblock(final int clientId, final ClientUnblockType type) { final CommandArguments args = CommandArguments.create("clientId", clientId).put("type", type); - return new JedisCommand(client, ProtocolCommand.CLIENT_UNBLOCK) - .general((cmd)->cmd.clientUnblock(clientId, ClientUnblockTypeConverter.INSTANCE.convert(type)), - Converters.ONE_STATUS_CONVERTER) - .run(args); + final UnblockType unblockType = (new ClientUnblockTypeConverter()).convert(type); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CLIENT_UNBLOCK) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CLIENT_UNBLOCK) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CLIENT_UNBLOCK, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisGenericOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisGenericOperations.java new file mode 100644 index 000000000..7f0a8ccd5 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisGenericOperations.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.KeyValue; +import com.buession.redis.client.jedis.JedisStandaloneClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.jedis.response.KeyValueConverter; + +/** + * Jedis 单机模式一般命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisGenericOperations extends AbstractGenericOperations { + + public JedisGenericOperations(final JedisStandaloneClient client) { + super(client); + } + + @Override + public Long wait(final int replicas, final int timeout) { + final CommandArguments args = CommandArguments.create(replicas).add(timeout); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.WAIT, (cmd)->cmd.waitReplicas(replicas, timeout), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.WAIT, + (cmd)->cmd.waitReplicas(replicas, timeout), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.WAIT, (cmd)->cmd.waitReplicas(replicas, timeout), (v)->v) + .run(args); + } + } + + @Override + public KeyValue waitOf(final int locals, final int replicas, final int timeout) { + final CommandArguments args = CommandArguments.create(locals).add(replicas).add(timeout); + final KeyValueConverter keyValueConverter = new KeyValueConverter<>((k)->k, (v)->v); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.WAITOF, + (cmd)->cmd.waitAOF((String) null, locals, replicas, timeout), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.WAITOF, + (cmd)->cmd.waitAOF((String) null, locals, replicas, timeout), keyValueConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.WAITOF, (cmd)->cmd.waitAOF(locals, replicas, timeout), + keyValueConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisGeoOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisGeoOperations.java index ce7518bb8..8407b2ae0 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisGeoOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisGeoOperations.java @@ -19,11 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.core.converter.ListConverter; import com.buession.lang.Geo; import com.buession.redis.client.jedis.JedisStandaloneClient; import com.buession.redis.core.GeoRadius; @@ -31,12 +32,13 @@ import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; import com.buession.redis.core.internal.convert.jedis.params.GeoConverter; -import com.buession.redis.core.internal.convert.jedis.params.GeoRadiusArgumentConverter; import com.buession.redis.core.internal.convert.jedis.params.GeoUnitConverter; import com.buession.redis.core.internal.convert.jedis.response.GeoCoordinateConverter; import com.buession.redis.core.internal.convert.jedis.response.GeoRadiusResponseConverter; +import com.buession.redis.core.internal.jedis.JedisGeoRadiusParam; import redis.clients.jedis.GeoCoordinate; import redis.clients.jedis.params.GeoRadiusParam; +import redis.clients.jedis.resps.GeoRadiusResponse; import java.util.List; import java.util.Map; @@ -49,410 +51,674 @@ */ public final class JedisGeoOperations extends AbstractGeoOperations { - public JedisGeoOperations(final JedisStandaloneClient client){ + public JedisGeoOperations(final JedisStandaloneClient client) { super(client); } @Override - public Long geoAdd(final String key, final String member, final double longitude, final double latitude){ + public Long geoAdd(final String key, final String member, final double longitude, final double latitude) { final CommandArguments args = CommandArguments.create("key", key).put("member", member) .put("longitude", longitude).put("latitude", latitude); - return new JedisCommand(client, ProtocolCommand.GEOADD) - .general((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .pipeline((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .transaction((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, longitude, latitude, + member), (v)->v) + .run(args); + } } @Override - public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude){ + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude) { final CommandArguments args = CommandArguments.create("key", key).put("member", member) .put("longitude", longitude).put("latitude", latitude); - return new JedisCommand(client, ProtocolCommand.GEOADD) - .general((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .pipeline((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .transaction((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, longitude, latitude, + member), (v)->v) + .run(args); + } } @Override - public Long geoAdd(final String key, final Map memberCoordinates){ + public Long geoAdd(final String key, final Map memberCoordinates) { final CommandArguments args = CommandArguments.create("key", key).put("memberCoordinates", memberCoordinates); - final Map geoCoordinates = GeoConverter.STRING_MAP_CONVERTER.convert(memberCoordinates); - return new JedisCommand(client, ProtocolCommand.GEOADD) - .general((cmd)->cmd.geoadd(key, geoCoordinates)) - .pipeline((cmd)->cmd.geoadd(key, geoCoordinates)) - .transaction((cmd)->cmd.geoadd(key, geoCoordinates)) - .run(args); + final Map geoCoordinates = GeoConverter.mapConverter().convert( + memberCoordinates); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), (v)->v) + .run(args); + } } @Override - public Long geoAdd(final byte[] key, final Map memberCoordinates){ + public Long geoAdd(final byte[] key, final Map memberCoordinates) { final CommandArguments args = CommandArguments.create("key", key).put("memberCoordinates", memberCoordinates); - final Map geoCoordinates = GeoConverter.BINARY_MAP_CONVERTER.convert(memberCoordinates); - return new JedisCommand(client, ProtocolCommand.GEOADD) - .general((cmd)->cmd.geoadd(key, geoCoordinates)) - .pipeline((cmd)->cmd.geoadd(key, geoCoordinates)) - .transaction((cmd)->cmd.geoadd(key, geoCoordinates)) - .run(args); + final Map geoCoordinates = GeoConverter.mapConverter().convert( + memberCoordinates); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), (v)->v) + .run(args); + } } @Override - public List geoHash(final String key, final String... members){ + public List geoHash(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisCommand>(client, ProtocolCommand.GEOHASH) - .general((cmd)->cmd.geohash(key, members)) - .pipeline((cmd)->cmd.geohash(key, members)) - .transaction((cmd)->cmd.geohash(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + } } @Override - public List geoHash(final byte[] key, final byte[]... members){ + public List geoHash(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisCommand>(client, ProtocolCommand.GEOHASH) - .general((cmd)->cmd.geohash(key, members)) - .pipeline((cmd)->cmd.geohash(key, members)) - .transaction((cmd)->cmd.geohash(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + } } @Override - public List geoPos(final String key, final String... members){ + public List geoPos(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisCommand>(client, ProtocolCommand.GEOPOS) - .general((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .run(args); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } } @Override - public List geoPos(final byte[] key, final byte[]... members){ + public List geoPos(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisCommand>(client, ProtocolCommand.GEOPOS) - .general((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .run(args); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } } @Override - public Double geoDist(final String key, final String member1, final String member2){ + public Double geoDist(final String key, final String member1, final String member2) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2); - return new JedisCommand(client, ProtocolCommand.GEODIST) - .general((cmd)->cmd.geodist(key, member1, member2)) - .pipeline((cmd)->cmd.geodist(key, member1, member2)) - .transaction((cmd)->cmd.geodist(key, member1, member2)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEODIST, (cmd)->cmd.geodist(key, member1, member2), + (v)->v) + .run(args); + } } @Override - public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2){ + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2); - return new JedisCommand(client, ProtocolCommand.GEODIST) - .general((cmd)->cmd.geodist(key, member1, member2)) - .pipeline((cmd)->cmd.geodist(key, member1, member2)) - .transaction((cmd)->cmd.geodist(key, member1, member2)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEODIST, (cmd)->cmd.geodist(key, member1, member2), + (v)->v) + .run(args); + } } @Override - public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit){ + public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisCommand(client, ProtocolCommand.GEODIST) - .general((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .pipeline((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .transaction((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + } } @Override - public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit){ + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisCommand(client, ProtocolCommand.GEODIST) - .general((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .pipeline((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .transaction((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + } } @Override public List geoRadius(final String key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisCommand>(client, ProtocolCommand.GEORADIUS) - .general((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadius(final byte[] key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisCommand>(client, ProtocolCommand.GEORADIUS) - .general((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadius(final String key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisCommand>(client, ProtocolCommand.GEORADIUS) - .general((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadius(final byte[] key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisCommand>(client, ProtocolCommand.GEORADIUS) - .general((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusRo(final String key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisCommand>(client, ProtocolCommand.GEORADIUS_RO) - .general((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisCommand>(client, ProtocolCommand.GEORADIUS_RO) - .general((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusRo(final String key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisCommand>(client, ProtocolCommand.GEORADIUS_RO) - .general((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisCommand>(client, ProtocolCommand.GEORADIUS_RO) - .general((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMember(final String key, final String member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMember(final String key, final String member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMemberRo(final String key, final String member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMemberRo(final String key, final String member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisHashOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisHashOperations.java index 98e2f5d62..99bbae589 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisHashOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisHashOperations.java @@ -19,20 +19,20 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.core.converter.ListMapEntryMapConverter; import com.buession.lang.Status; import com.buession.redis.client.jedis.JedisStandaloneClient; import com.buession.redis.core.ScanResult; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; import com.buession.redis.core.internal.jedis.JedisScanParams; +import redis.clients.jedis.params.ScanParams; import java.util.List; import java.util.Map; @@ -46,459 +46,728 @@ */ public final class JedisHashOperations extends AbstractHashOperations { - public JedisHashOperations(final JedisStandaloneClient client){ + public JedisHashOperations(final JedisStandaloneClient client) { super(client); } @Override - public Long hDel(final String key, final String... fields){ + public Long hDel(final String key, final String... fields) { final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); - return new JedisCommand(client, ProtocolCommand.HDEL) - .general((cmd)->cmd.hdel(key, fields)) - .pipeline((cmd)->cmd.hdel(key, fields)) - .transaction((cmd)->cmd.hdel(key, fields)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } } @Override - public Long hDel(final byte[] key, final byte[]... fields){ + public Long hDel(final byte[] key, final byte[]... fields) { final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); - return new JedisCommand(client, ProtocolCommand.HDEL) - .general((cmd)->cmd.hdel(key, fields)) - .pipeline((cmd)->cmd.hdel(key, fields)) - .transaction((cmd)->cmd.hdel(key, fields)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } } @Override - public Boolean hExists(final String key, final String field){ + public Boolean hExists(final String key, final String field) { final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisCommand(client, ProtocolCommand.HEXISTS) - .general((cmd)->cmd.hexists(key, field)) - .pipeline((cmd)->cmd.hexists(key, field)) - .transaction((cmd)->cmd.hexists(key, field)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } } @Override - public Boolean hExists(final byte[] key, final byte[] field){ + public Boolean hExists(final byte[] key, final byte[] field) { final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisCommand(client, ProtocolCommand.HEXISTS) - .general((cmd)->cmd.hexists(key, field)) - .pipeline((cmd)->cmd.hexists(key, field)) - .transaction((cmd)->cmd.hexists(key, field)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } } @Override - public String hGet(final String key, final String field){ + public String hGet(final String key, final String field) { final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisCommand(client, ProtocolCommand.HGET) - .general((cmd)->cmd.hget(key, field)) - .pipeline((cmd)->cmd.hget(key, field)) - .transaction((cmd)->cmd.hget(key, field)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + } } @Override - public byte[] hGet(final byte[] key, final byte[] field){ + public byte[] hGet(final byte[] key, final byte[] field) { final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisCommand(client, ProtocolCommand.HGET) - .general((cmd)->cmd.hget(key, field)) - .pipeline((cmd)->cmd.hget(key, field)) - .transaction((cmd)->cmd.hget(key, field)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + } } @Override - public Map hGetAll(final String key){ + public Map hGetAll(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand>(client, ProtocolCommand.HGETALL) - .general((cmd)->cmd.hgetAll(key)) - .pipeline((cmd)->cmd.hgetAll(key)) - .transaction((cmd)->cmd.hgetAll(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + } } @Override - public Map hGetAll(final byte[] key){ + public Map hGetAll(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand>(client, ProtocolCommand.HGETALL) - .general((cmd)->cmd.hgetAll(key)) - .pipeline((cmd)->cmd.hgetAll(key)) - .transaction((cmd)->cmd.hgetAll(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + } } @Override - public Long hIncrBy(final String key, final String field, final long value){ + public Long hIncrBy(final String key, final String field, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisCommand(client, ProtocolCommand.HINCRBY) - .general((cmd)->cmd.hincrBy(key, field, value)) - .pipeline((cmd)->cmd.hincrBy(key, field, value)) - .transaction((cmd)->cmd.hincrBy(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + } } @Override - public Long hIncrBy(final byte[] key, final byte[] field, final long value){ + public Long hIncrBy(final byte[] key, final byte[] field, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisCommand(client, ProtocolCommand.HINCRBY) - .general((cmd)->cmd.hincrBy(key, field, value)) - .pipeline((cmd)->cmd.hincrBy(key, field, value)) - .transaction((cmd)->cmd.hincrBy(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + } } @Override - public Double hIncrByFloat(final String key, final String field, final double value){ + public Double hIncrByFloat(final String key, final String field, final double value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisCommand(client, ProtocolCommand.HINCRBYFLOAT) - .general((cmd)->cmd.hincrByFloat(key, field, value)) - .pipeline((cmd)->cmd.hincrByFloat(key, field, value)) - .transaction((cmd)->cmd.hincrByFloat(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + } } @Override - public Double hIncrByFloat(final byte[] key, final byte[] field, final double value){ + public Double hIncrByFloat(final byte[] key, final byte[] field, final double value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisCommand(client, ProtocolCommand.HINCRBYFLOAT) - .general((cmd)->cmd.hincrByFloat(key, field, value)) - .pipeline((cmd)->cmd.hincrByFloat(key, field, value)) - .transaction((cmd)->cmd.hincrByFloat(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + } } @Override - public Set hKeys(final String key){ + public Set hKeys(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand>(client, ProtocolCommand.HKEYS) - .general((cmd)->cmd.hkeys(key)) - .pipeline((cmd)->cmd.hkeys(key)) - .transaction((cmd)->cmd.hkeys(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + } } @Override - public Set hKeys(final byte[] key){ + public Set hKeys(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand>(client, ProtocolCommand.HKEYS) - .general((cmd)->cmd.hkeys(key)) - .pipeline((cmd)->cmd.hkeys(key)) - .transaction((cmd)->cmd.hkeys(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + } } @Override - public Long hLen(final String key){ + public Long hLen(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.HLEN) - .general((cmd)->cmd.hlen(key)) - .pipeline((cmd)->cmd.hlen(key)) - .transaction((cmd)->cmd.hlen(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } } @Override - public Long hLen(final byte[] key){ + public Long hLen(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.HLEN) - .general((cmd)->cmd.hlen(key)) - .pipeline((cmd)->cmd.hlen(key)) - .transaction((cmd)->cmd.hlen(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } } @Override - public List hMGet(final String key, final String... fields){ + public List hMGet(final String key, final String... fields) { final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); - return new JedisCommand>(client, ProtocolCommand.HMGET) - .general((cmd)->cmd.hmget(key, fields)) - .pipeline((cmd)->cmd.hmget(key, fields)) - .transaction((cmd)->cmd.hmget(key, fields)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + } } @Override - public List hMGet(final byte[] key, final byte[]... fields){ + public List hMGet(final byte[] key, final byte[]... fields) { final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); - return new JedisCommand>(client, ProtocolCommand.HMGET) - .general((cmd)->cmd.hmget(key, fields)) - .pipeline((cmd)->cmd.hmget(key, fields)) - .transaction((cmd)->cmd.hmget(key, fields)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + } } @Override - public Status hMSet(final String key, final Map data){ + public Status hMSet(final String key, final Map data) { final CommandArguments args = CommandArguments.create("key", key).put("data", data); - return new JedisCommand(client, ProtocolCommand.HMGET) - .general((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + } } @Override - public Status hMSet(final byte[] key, final Map data){ + public Status hMSet(final byte[] key, final Map data) { final CommandArguments args = CommandArguments.create("key", key).put("data", data); - return new JedisCommand(client, ProtocolCommand.HMGET) - .general((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), okStatusConverter) + .run(args); + } } @Override - public String hRandField(final String key){ + public String hRandField(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfield(key)) - .pipeline((cmd)->cmd.hrandfield(key)) - .transaction((cmd)->cmd.hrandfield(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + } } @Override - public byte[] hRandField(final byte[] key){ + public byte[] hRandField(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfield(key)) - .pipeline((cmd)->cmd.hrandfield(key)) - .transaction((cmd)->cmd.hrandfield(key)) - .run(args); - } - @Override - public List hRandField(final String key, final long count){ - final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfield(key, count)) - .pipeline((cmd)->cmd.hrandfield(key, count)) - .transaction((cmd)->cmd.hrandfield(key, count)) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + } } @Override - public List hRandField(final byte[] key, final long count){ + public List hRandField(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfield(key, count)) - .pipeline((cmd)->cmd.hrandfield(key, count)) - .transaction((cmd)->cmd.hrandfield(key, count)) - .run(args); - } - @Override - public Map hRandFieldWithValues(final String key, final long count){ - final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfieldWithValues(key, count)) - .pipeline((cmd)->cmd.hrandfieldWithValues(key, count)) - .transaction((cmd)->cmd.hrandfieldWithValues(key, count)) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + } } @Override - public Map hRandFieldWithValues(final byte[] key, final long count){ + public List hRandField(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfieldWithValues(key, count)) - .pipeline((cmd)->cmd.hrandfieldWithValues(key, count)) - .transaction((cmd)->cmd.hrandfieldWithValues(key, count)) - .run(args); - } - @Override - public ScanResult> hScan(final String key, final String cursor){ - final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor), ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + } } @Override - public ScanResult> hScan(final byte[] key, final byte[] cursor){ + public Map hRandFieldWithValues(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListMapEntryMapConverter converter = + new ListMapEntryMapConverter<>((k)->k, (v)->v); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + } + } + + @Override + public Map hRandFieldWithValues(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListMapEntryMapConverter converter = + new ListMapEntryMapConverter<>((k)->k, (v)->v); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final String key, final String cursor) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor), ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .run(args); - } - - @Override - public ScanResult> hScan(final String key, final String cursor, final String pattern){ + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final String key, final String cursor, final String pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return hScan(key, cursor, scanParams, args); } @Override - public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern){ + public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return hScan(key, cursor, scanParams, args); } @Override - public ScanResult> hScan(final String key, final String cursor, final long count){ + public ScanResult> hScan(final String key, final String cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return hScan(key, cursor, scanParams, args); } @Override - public ScanResult> hScan(final byte[] key, final byte[] cursor, final long count){ + public ScanResult> hScan(final byte[] key, final byte[] cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return hScan(key, cursor, scanParams, args); } @Override public ScanResult> hScan(final String key, final String cursor, final String pattern, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return hScan(key, cursor, scanParams, args); } @Override public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return hScan(key, cursor, scanParams, args); } @Override - public Long hSet(final String key, final String field, final String value){ + public Long hSet(final String key, final String field, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisCommand(client, ProtocolCommand.HSET) - .general((cmd)->cmd.hset(key, field, value)) - .pipeline((cmd)->cmd.hset(key, field, value)) - .transaction((cmd)->cmd.hset(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + } } @Override - public Long hSet(final byte[] key, final byte[] field, final byte[] value){ + public Long hSet(final byte[] key, final byte[] field, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisCommand(client, ProtocolCommand.HSET) - .general((cmd)->cmd.hset(key, field, value)) - .pipeline((cmd)->cmd.hset(key, field, value)) - .transaction((cmd)->cmd.hset(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + } } @Override - public Status hSetNx(final String key, final String field, final String value){ + public Status hSetNx(final String key, final String field, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisCommand(client, ProtocolCommand.HSETNX) - .general((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + } } @Override - public Status hSetNx(final byte[] key, final byte[] field, final byte[] value){ + public Status hSetNx(final byte[] key, final byte[] field, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisCommand(client, ProtocolCommand.HSETNX) - .general((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + } } @Override - public Long hStrLen(final String key, final String field){ + public Long hStrLen(final String key, final String field) { final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisCommand(client, ProtocolCommand.HSTRLEN) - .general((cmd)->cmd.hstrlen(key, field)) - .pipeline((cmd)->cmd.hstrlen(key, field)) - .transaction((cmd)->cmd.hstrlen(key, field)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } } @Override - public Long hStrLen(final byte[] key, final byte[] field){ + public Long hStrLen(final byte[] key, final byte[] field) { final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisCommand(client, ProtocolCommand.HSTRLEN) - .general((cmd)->cmd.hstrlen(key, field)) - .pipeline((cmd)->cmd.hstrlen(key, field)) - .transaction((cmd)->cmd.hstrlen(key, field)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } } @Override - public List hVals(final String key){ + public List hVals(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand>(client, ProtocolCommand.HVALS) - .general((cmd)->cmd.hvals(key)) - .pipeline((cmd)->cmd.hvals(key)) - .transaction((cmd)->cmd.hvals(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + } } @Override - public List hVals(final byte[] key){ + public List hVals(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand>(client, ProtocolCommand.HVALS) - .general((cmd)->cmd.hvals(key)) - .pipeline((cmd)->cmd.hvals(key)) - .transaction((cmd)->cmd.hvals(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + } + } + + private ScanResult> hScan(final String key, final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanParams), mapScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + } + } + + private ScanResult> hScan(final byte[] key, final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanParams), mapScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisHyperLogLogOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisHyperLogLogOperations.java index ab61807c5..f7dc62cbd 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisHyperLogLogOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisHyperLogLogOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -28,8 +28,6 @@ import com.buession.redis.client.jedis.JedisStandaloneClient; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; /** * Jedis 单机模式 HyperLogLog 命令操作 @@ -39,68 +37,116 @@ */ public final class JedisHyperLogLogOperations extends AbstractHyperLogLogOperations { - public JedisHyperLogLogOperations(final JedisStandaloneClient client){ + public JedisHyperLogLogOperations(final JedisStandaloneClient client) { super(client); } @Override - public Status pfAdd(final String key, final String... elements){ + public Status pfAdd(final String key, final String... elements) { final CommandArguments args = CommandArguments.create("key", key).put("elements", (Object[]) elements); - return new JedisCommand(client, ProtocolCommand.PFADD) - .general((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + } } @Override - public Status pfAdd(final byte[] key, final byte[]... elements){ + public Status pfAdd(final byte[] key, final byte[]... elements) { final CommandArguments args = CommandArguments.create("key", key).put("elements", (Object[]) elements); - return new JedisCommand(client, ProtocolCommand.PFADD) - .general((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + } } @Override - public Status pfMerge(final String destKey, final String... keys){ + public Status pfMerge(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.PFMERGE) - .general((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + } } @Override - public Status pfMerge(final byte[] destKey, final byte[]... keys){ + public Status pfMerge(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.PFMERGE) - .general((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + } } @Override - public Long pfCount(final String... keys){ + public Long pfCount(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.PFCOUNT) - .general((cmd)->cmd.pfcount(keys)) - .pipeline((cmd)->cmd.pfcount(keys)) - .transaction((cmd)->cmd.pfcount(keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } } @Override - public Long pfCount(final byte[]... keys){ + public Long pfCount(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.PFCOUNT) - .general((cmd)->cmd.pfcount(keys)) - .pipeline((cmd)->cmd.pfcount(keys)) - .transaction((cmd)->cmd.pfcount(keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisKeyOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisKeyOperations.java index 94a9697fd..ac07547d0 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisKeyOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisKeyOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -33,16 +33,20 @@ import com.buession.redis.core.Type; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; import com.buession.redis.core.internal.convert.jedis.params.ExpireOptionConverter; -import com.buession.redis.core.internal.convert.jedis.params.RestoreArgumentConverter; -import com.buession.redis.core.internal.convert.jedis.params.SortArgumentConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import com.buession.redis.core.internal.convert.response.BinaryObjectEncodingConverter; +import com.buession.redis.core.internal.convert.response.ObjectEncodingConverter; import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; +import com.buession.redis.core.internal.convert.response.TypeConverter; import com.buession.redis.core.internal.jedis.JedisMigrateParams; +import com.buession.redis.core.internal.jedis.JedisRestoreParams; import com.buession.redis.core.internal.jedis.JedisScanParams; +import com.buession.redis.core.internal.jedis.JedisSortingParams; +import com.buession.redis.utils.SafeEncoder; import redis.clients.jedis.args.ExpiryOption; +import redis.clients.jedis.params.MigrateParams; import redis.clients.jedis.params.RestoreParams; +import redis.clients.jedis.params.ScanParams; import redis.clients.jedis.params.SortingParams; import java.util.List; @@ -56,958 +60,1460 @@ */ public final class JedisKeyOperations extends AbstractKeyOperations { - public JedisKeyOperations(final JedisStandaloneClient client){ + public JedisKeyOperations(final JedisStandaloneClient client) { super(client); } @Override - public Long del(final String... keys){ + public Long del(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.DEL) - .general((cmd)->cmd.del(keys)) - .pipeline((cmd)->cmd.del(keys)) - .transaction((cmd)->cmd.del(keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } } @Override - public Long del(final byte[]... keys){ + public Long del(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.DEL) - .general((cmd)->cmd.del(keys)) - .pipeline((cmd)->cmd.del(keys)) - .transaction((cmd)->cmd.del(keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } } @Override - public String dump(final String key){ + public String dump(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.DUMP) - .general((cmd)->cmd.dump(key), Converters.BINARY_TO_STRING_CONVERTER) - .pipeline((cmd)->cmd.dump(key), Converters.BINARY_TO_STRING_CONVERTER) - .transaction((cmd)->cmd.dump(key), Converters.BINARY_TO_STRING_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), SafeEncoder::encode) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), + SafeEncoder::encode) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), SafeEncoder::encode) + .run(args); + } } @Override - public byte[] dump(final byte[] key){ + public byte[] dump(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.DUMP) - .general((cmd)->cmd.dump(key)) - .pipeline((cmd)->cmd.dump(key)) - .transaction((cmd)->cmd.dump(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + } } @Override - public Boolean exists(final String key){ + public Boolean exists(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.EXISTS) - .general((cmd)->cmd.exists(key)) - .pipeline((cmd)->cmd.exists(key)) - .transaction((cmd)->cmd.exists(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + } } @Override - public Boolean exists(final byte[] key){ + public Boolean exists(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.EXISTS) - .general((cmd)->cmd.exists(key)) - .pipeline((cmd)->cmd.exists(key)) - .transaction((cmd)->cmd.exists(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + } } @Override - public Long exists(final String... keys){ + public Long exists(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.EXISTS) - .general((cmd)->cmd.exists(keys)) - .pipeline((cmd)->cmd.exists(keys)) - .transaction((cmd)->cmd.exists(keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } } @Override - public Long exists(final byte[]... keys){ + public Long exists(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.EXISTS) - .general((cmd)->cmd.exists(keys)) - .pipeline((cmd)->cmd.exists(keys)) - .transaction((cmd)->cmd.exists(keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } } @Override - public Status expire(final String key, final int lifetime){ + public Status expire(final String key, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); - return new JedisCommand(client, ProtocolCommand.EXPIRE) - .general((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + } } @Override - public Status expire(final byte[] key, final int lifetime){ + public Status expire(final byte[] key, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); - return new JedisCommand(client, ProtocolCommand.EXPIRE) - .general((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + } } @Override - public Status expire(final String key, final int lifetime, final ExpireOption expireOption){ + public Status expire(final String key, final int lifetime, final ExpireOption expireOption) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime) .put("expireOption", expireOption); - final ExpiryOption expiryOption = ExpireOptionConverter.INSTANCE.convert(expireOption); - return new JedisCommand(client, ProtocolCommand.EXPIRE) - .general((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .run(args); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + } } @Override - public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption){ + public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime) .put("expireOption", expireOption); - final ExpiryOption expiryOption = ExpireOptionConverter.INSTANCE.convert(expireOption); - return new JedisCommand(client, ProtocolCommand.EXPIRE) - .general((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .run(args); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime, expiryOption), + oneStatusConverter) + .run(args); + } } @Override - public Status expireAt(final String key, final long unixTimestamp){ + public Status expireAt(final String key, final long unixTimestamp) { final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); - return new JedisCommand(client, ProtocolCommand.EXPIREAT) - .general((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } } @Override - public Status expireAt(final byte[] key, final long unixTimestamp){ + public Status expireAt(final byte[] key, final long unixTimestamp) { final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); - return new JedisCommand(client, ProtocolCommand.EXPIREAT) - .general((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } } @Override - public Status pExpire(final String key, final int lifetime){ + public Status pExpire(final String key, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); - return new JedisCommand(client, ProtocolCommand.PEXPIRE) - .general((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + } } @Override - public Status pExpire(final byte[] key, final int lifetime){ + public Status pExpire(final byte[] key, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); - return new JedisCommand(client, ProtocolCommand.PEXPIRE) - .general((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + } } @Override - public Status pExpireAt(final String key, final long unixTimestamp){ + public Status pExpireAt(final String key, final long unixTimestamp) { final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); - return new JedisCommand(client, ProtocolCommand.PEXPIREAT) - .general((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PEXPIREAT, (cmd)->cmd.pexpireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } } @Override - public Status pExpireAt(final byte[] key, final long unixTimestamp){ + public Status pExpireAt(final byte[] key, final long unixTimestamp) { final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); - return new JedisCommand(client, ProtocolCommand.PEXPIREAT) - .general((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PEXPIREAT, (cmd)->cmd.pexpireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } } @Override - public Status persist(final String key){ + public Status persist(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.PERSIST) - .general((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), oneStatusConverter) + .run(args); + } } @Override - public Status persist(final byte[] key){ + public Status persist(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.PERSIST) - .general((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), oneStatusConverter) + .run(args); + } } @Override - public Long ttl(final String key){ + public Long ttl(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.TTL) - .general((cmd)->cmd.ttl(key)) - .pipeline((cmd)->cmd.ttl(key)) - .transaction((cmd)->cmd.ttl(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } } @Override - public Long ttl(final byte[] key){ + public Long ttl(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.TTL) - .general((cmd)->cmd.ttl(key)) - .pipeline((cmd)->cmd.ttl(key)) - .transaction((cmd)->cmd.ttl(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } } @Override - public Long pTtl(final String key){ + public Long pTtl(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.PTTL) - .general((cmd)->cmd.pttl(key)) - .pipeline((cmd)->cmd.pttl(key)) - .transaction((cmd)->cmd.pttl(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } } @Override - public Long pTtl(final byte[] key){ + public Long pTtl(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.PTTL) - .general((cmd)->cmd.pttl(key)) - .pipeline((cmd)->cmd.pttl(key)) - .transaction((cmd)->cmd.pttl(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } } @Override - public Status copy(final String key, final String destKey){ + public Status copy(final String key, final String destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, false, args); } @Override - public Status copy(final byte[] key, final byte[] destKey){ + public Status copy(final byte[] key, final byte[] destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, false, args); } @Override - public Status copy(final String key, final String destKey, final int db){ + public Status copy(final String key, final String destKey, final int db) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("db", db); - return new JedisCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, db, false), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, db, false), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, db, false, args); } @Override - public Status copy(final byte[] key, final byte[] destKey, final int db){ - final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) - .put("db", db); - return new JedisCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, db, false), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, db, false), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + public Status copy(final byte[] key, final byte[] destKey, final int db) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("db", db); + return copy(key, destKey, db, false, args); } @Override - public Status copy(final String key, final String destKey, final boolean replace){ + public Status copy(final String key, final String destKey, final boolean replace) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("replace", replace); - return new JedisCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, replace, args); } @Override - public Status copy(final byte[] key, final byte[] destKey, final boolean replace){ + public Status copy(final byte[] key, final byte[] destKey, final boolean replace) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("replace", replace); - return new JedisCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, replace, args); } @Override - public Status copy(final String key, final String destKey, final int db, final boolean replace){ + public Status copy(final String key, final String destKey, final int db, final boolean replace) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("db", db) .put("replace", replace); - return new JedisCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, db, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, db, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, db, replace, args); } @Override - public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace){ + public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("db", db) .put("replace", replace); - return new JedisCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, db, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, db, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, db, replace, args); } @Override - public Status move(final String key, final int db){ + public Status move(final String key, final int db) { final CommandArguments args = CommandArguments.create("key", key).put("db", db); - return new JedisCommand(client, ProtocolCommand.MOVE) - .general((cmd)->cmd.move(key, db), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.move(key, db), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.MOVE, (cmd)->cmd.move(key, db), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.MOVE) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MOVE, (cmd)->cmd.move(key, db), oneStatusConverter) + .run(args); + } } @Override - public Status move(final byte[] key, final int db){ + public Status move(final byte[] key, final int db) { final CommandArguments args = CommandArguments.create("key", key).put("db", db); - return new JedisCommand(client, ProtocolCommand.MOVE) - .general((cmd)->cmd.move(key, db), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.move(key, db), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.MOVE, (cmd)->cmd.move(key, db), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.MOVE) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MOVE, (cmd)->cmd.move(key, db), oneStatusConverter) + .run(args); + } } @Override - public Status migrate(final String host, final int port, final int db, final int timeout, final String... keys){ + public Status migrate(final String host, final int port, final int db, final int timeout, final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("timeout", timeout).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(); - return new JedisCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override - public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... keys){ + public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("timeout", timeout).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(); - return new JedisCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final int timeout, - final MigrateOperation operation, final String... keys){ + final MigrateOperation operation, final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("timeout", timeout).put("operation", operation).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(operation); - return new JedisCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final int timeout, - final MigrateOperation operation, final byte[]... keys){ + final MigrateOperation operation, final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("timeout", timeout).put("operation", operation).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(operation); - return new JedisCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final String password, final int timeout, - final String... keys){ + final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("password", password).put("timeout", timeout).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(password); - return new JedisCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final byte[] password, final int timeout, - final byte[]... keys){ + final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("password", password).put("timeout", timeout).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(password); - return new JedisCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final String password, final int timeout, - final MigrateOperation operation, final String... keys){ + final MigrateOperation operation, final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("password", password).put("timeout", timeout).put("operation", operation) .put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(operation, password); - return new JedisCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final byte[] password, final int timeout, - final MigrateOperation operation, final byte[]... keys){ + final MigrateOperation operation, final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("password", password).put("timeout", timeout).put("operation", operation) .put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(operation, password); - return new JedisCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final String user, final String password, - final int timeout, final String... keys){ + final int timeout, final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("user", user).put("password", password).put("timeout", timeout).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(user, password); - return new JedisCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(user, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final byte[] user, final byte[] password, - final int timeout, final byte[]... keys){ + final int timeout, final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("user", user).put("password", password).put("timeout", timeout).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(user, password); - return new JedisCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(user, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final String user, final String password, - final int timeout, final MigrateOperation operation, final String... keys){ + final int timeout, final MigrateOperation operation, final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("user", user).put("password", password).put("timeout", timeout).put("operation", operation) .put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(operation, user, password); - return new JedisCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation, user, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final byte[] user, final byte[] password, - final int timeout, final MigrateOperation operation, final byte[]... keys){ + final int timeout, final MigrateOperation operation, final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("user", user).put("password", password).put("timeout", timeout).put("operation", operation) .put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(operation, user, password); - return new JedisCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation, user, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override - public Set keys(final String pattern){ + public Set keys(final String pattern) { final CommandArguments args = CommandArguments.create("pattern", pattern); - return new JedisCommand>(client, ProtocolCommand.KEYS) - .general((cmd)->cmd.keys(pattern)) - .pipeline((cmd)->cmd.keys(pattern)) - .transaction((cmd)->cmd.keys(pattern)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + } } @Override - public Set keys(final byte[] pattern){ + public Set keys(final byte[] pattern) { final CommandArguments args = CommandArguments.create("pattern", pattern); - return new JedisCommand>(client, ProtocolCommand.KEYS) - .general((cmd)->cmd.keys(pattern)) - .pipeline((cmd)->cmd.keys(pattern)) - .transaction((cmd)->cmd.keys(pattern)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + } } @Override - public String randomKey(){ - return new JedisCommand(client, ProtocolCommand.RANDOMKEY) - .general((cmd)->cmd.randomKey()) - .pipeline((cmd)->cmd.randomKey()) - .transaction((cmd)->cmd.randomKey()) - .run(); + public String randomKey() { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RANDOMKEY, (cmd)->cmd.randomKey(), (v)->v) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RANDOMKEY, (cmd)->cmd.randomKey(), (v)->v) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RANDOMKEY, (cmd)->cmd.randomKey(), (v)->v) + .run(); + } } @Override - public Status rename(final String key, final String newKey){ + public Status rename(final String key, final String newKey) { final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); - return new JedisCommand(client, ProtocolCommand.RENAME) - .general((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), okStatusConverter) + .run(args); + } } @Override - public Status rename(final byte[] key, final byte[] newKey){ + public Status rename(final byte[] key, final byte[] newKey) { final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); - return new JedisCommand(client, ProtocolCommand.RENAME) - .general((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), okStatusConverter) + .run(args); + } } @Override - public Status renameNx(final String key, final String newKey){ + public Status renameNx(final String key, final String newKey) { final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); - return new JedisCommand(client, ProtocolCommand.RENAMENX) - .general((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + } } @Override - public Status renameNx(final byte[] key, final byte[] newKey){ + public Status renameNx(final byte[] key, final byte[] newKey) { final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); - return new JedisCommand(client, ProtocolCommand.RENAMENX) - .general((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + } } @Override - public Status restore(final String key, final byte[] serializedValue, final int ttl){ + public Status restore(final String key, final byte[] serializedValue, final int ttl) { final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) .put("ttl", ttl); - return new JedisCommand(client, ProtocolCommand.RESTORE) - .general((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RESTORE, (cmd)->cmd.restore(key, ttl, serializedValue), + okStatusConverter) + .run(args); + } } @Override - public Status restore(final byte[] key, final byte[] serializedValue, final int ttl){ + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl) { final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) .put("ttl", ttl); - return new JedisCommand(client, ProtocolCommand.RESTORE) - .general((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RESTORE, (cmd)->cmd.restore(key, ttl, serializedValue), + okStatusConverter) + .run(args); + } } @Override public Status restore(final String key, final byte[] serializedValue, final int ttl, - final RestoreArgument argument){ + final RestoreArgument argument) { final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) .put("ttl", ttl).put("argument", argument); - final RestoreParams params = RestoreArgumentConverter.INSTANCE.convert(argument); - return new JedisCommand(client, ProtocolCommand.RESTORE) - .general((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .run(args); + final RestoreParams restoreParams = JedisRestoreParams.from(argument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + } } @Override public Status restore(final byte[] key, final byte[] serializedValue, final int ttl, - final RestoreArgument argument){ + final RestoreArgument argument) { final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) .put("ttl", ttl).put("argument", argument); - final RestoreParams params = RestoreArgumentConverter.INSTANCE.convert(argument); - return new JedisCommand(client, ProtocolCommand.RESTORE) - .general((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .run(args); + final RestoreParams restoreParams = JedisRestoreParams.from(argument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + } } @Override - public ScanResult> scan(final String cursor){ + public ScanResult> scan(final String cursor) { final CommandArguments args = CommandArguments.create("cursor", cursor); - return new JedisCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor), ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor), ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), listScanResultConverter) + .run(args); + } } @Override - public ScanResult> scan(final byte[] cursor){ + public ScanResult> scan(final byte[] cursor) { final CommandArguments args = CommandArguments.create("cursor", cursor); - return new JedisCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor), ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor), ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), listScanResultConverter) + .run(args); + } } @Override - public ScanResult> scan(final String cursor, final String pattern){ + public ScanResult> scan(final String cursor, final String pattern) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return scan(cursor, scanParams, args); } @Override - public ScanResult> scan(final byte[] cursor, final byte[] pattern){ + public ScanResult> scan(final byte[] cursor, final byte[] pattern) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return scan(cursor, scanParams, args); } @Override - public ScanResult> scan(final String cursor, final long count){ + public ScanResult> scan(final String cursor, final long count) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return scan(cursor, scanParams, args); } @Override - public ScanResult> scan(final byte[] cursor, final long count){ + public ScanResult> scan(final byte[] cursor, final long count) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return scan(cursor, scanParams, args); } @Override - public ScanResult> scan(final String cursor, final String pattern, final long count){ + public ScanResult> scan(final String cursor, final String pattern, final long count) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return scan(cursor, scanParams, args); } @Override - public ScanResult> scan(final byte[] cursor, final byte[] pattern, final long count){ + public ScanResult> scan(final byte[] cursor, final byte[] pattern, final long count) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return scan(cursor, scanParams, args); } @Override - public List sort(final String key){ + public List sort(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand>(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key)) - .pipeline((cmd)->cmd.sort(key)) - .transaction((cmd)->cmd.sort(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + } } @Override - public List sort(final byte[] key){ + public List sort(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand>(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key)) - .pipeline((cmd)->cmd.sort(key)) - .transaction((cmd)->cmd.sort(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + } } @Override - public List sort(final String key, final SortArgument sortArgument){ + public List sort(final String key, final SortArgument sortArgument) { final CommandArguments args = CommandArguments.create("key", key).put("sortArgument", sortArgument); - final SortingParams params = SortArgumentConverter.INSTANCE.convert(sortArgument); - return new JedisCommand>(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, params)) - .pipeline((cmd)->cmd.sort(key, params)) - .transaction((cmd)->cmd.sort(key, params)) - .run(args); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + } } @Override - public List sort(final byte[] key, final SortArgument sortArgument){ + public List sort(final byte[] key, final SortArgument sortArgument) { final CommandArguments args = CommandArguments.create("key", key).put("sortArgument", sortArgument); - final SortingParams params = SortArgumentConverter.INSTANCE.convert(sortArgument); - return new JedisCommand>(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, params)) - .pipeline((cmd)->cmd.sort(key, params)) - .transaction((cmd)->cmd.sort(key, params)) - .run(args); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + } } @Override - public Long sort(final String key, final String destKey){ + public Long sort(final String key, final String destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisCommand(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, destKey)) - .pipeline((cmd)->cmd.sort(key, destKey)) - .transaction((cmd)->cmd.sort(key, destKey)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + } } @Override - public Long sort(final byte[] key, final byte[] destKey){ + public Long sort(final byte[] key, final byte[] destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisCommand(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, destKey)) - .pipeline((cmd)->cmd.sort(key, destKey)) - .transaction((cmd)->cmd.sort(key, destKey)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + } } @Override - public Long sort(final String key, final String destKey, final SortArgument sortArgument){ + public Long sort(final String key, final String destKey, final SortArgument sortArgument) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("sortArgument", sortArgument); - final SortingParams params = SortArgumentConverter.INSTANCE.convert(sortArgument); - return new JedisCommand(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, params, destKey)) - .pipeline((cmd)->cmd.sort(key, params, destKey)) - .transaction((cmd)->cmd.sort(key, params, destKey)) - .run(args); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), + (v)->v) + .run(args); + } } @Override - public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument){ + public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("sortArgument", sortArgument); - final SortingParams params = SortArgumentConverter.INSTANCE.convert(sortArgument); - return new JedisCommand(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, params, destKey)) - .pipeline((cmd)->cmd.sort(key, params, destKey)) - .transaction((cmd)->cmd.sort(key, params, destKey)) - .run(args); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams, destKey), + (v)->v) + .run(args); + } } @Override - public Long touch(final String... keys){ + public Long touch(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.TOUCH) - .general((cmd)->cmd.touch(keys)) - .pipeline((cmd)->cmd.touch(keys)) - .transaction((cmd)->cmd.touch(keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } } @Override - public Long touch(final byte[]... keys){ + public Long touch(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.TOUCH) - .general((cmd)->cmd.touch(keys)) - .pipeline((cmd)->cmd.touch(keys)) - .transaction((cmd)->cmd.touch(keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } } @Override - public Type type(final String key){ + public Type type(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.TYPE) - .general((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .pipeline((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .transaction((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .run(args); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } } @Override - public Type type(final byte[] key){ + public Type type(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.TYPE) - .general((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .pipeline((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .transaction((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .run(args); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } } @Override - public Long unlink(final String... keys){ + public Long unlink(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.UNLINK) - .general((cmd)->cmd.unlink(keys)) - .pipeline((cmd)->cmd.unlink(keys)) - .transaction((cmd)->cmd.unlink(keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } } @Override - public Long unlink(final byte[]... keys){ + public Long unlink(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.UNLINK) - .general((cmd)->cmd.unlink(keys)) - .pipeline((cmd)->cmd.unlink(keys)) - .transaction((cmd)->cmd.unlink(keys)) - .run(args); - } - @Override - public Long wait(final int replicas, final int timeout){ - final CommandArguments args = CommandArguments.create("replicas", replicas).put("timeout", timeout); - return new JedisCommand(client, ProtocolCommand.WAIT) - .general((cmd)->cmd.waitReplicas(replicas, timeout)) - .pipeline((cmd)->cmd.waitReplicas(replicas, timeout)) - .transaction((cmd)->cmd.waitReplicas(replicas, timeout)) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } } @Override - public ObjectEncoding objectEncoding(final String key){ + public ObjectEncoding objectEncoding(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.OBJECT_ENCODING) - .general((cmd)->cmd.objectEncoding(key), Converters.STRING_OBJECT_ENCODING_RESULT_CONVERTER) - .pipeline((cmd)->cmd.objectEncoding(key), Converters.STRING_OBJECT_ENCODING_RESULT_CONVERTER) - .transaction((cmd)->cmd.objectEncoding(key), Converters.STRING_OBJECT_ENCODING_RESULT_CONVERTER) - .run(args); - } - - @Override - public ObjectEncoding objectEncoding(final byte[] key){ + final ObjectEncodingConverter objectEncodingConverter = new ObjectEncodingConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.OBJECT_ENCODING, (cmd)->cmd.objectEncoding(key), + objectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), + objectEncodingConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.OBJECT_ENCODING, (cmd)->cmd.objectEncoding(key), + objectEncodingConverter) + .run(args); + } + } + + @Override + public ObjectEncoding objectEncoding(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.OBJECT_ENCODING) - .general((cmd)->cmd.objectEncoding(key), Converters.BINARY_OBJECT_ENCODING_RESULT_CONVERTER) - .pipeline((cmd)->cmd.objectEncoding(key), Converters.BINARY_OBJECT_ENCODING_RESULT_CONVERTER) - .transaction((cmd)->cmd.objectEncoding(key), Converters.BINARY_OBJECT_ENCODING_RESULT_CONVERTER) - .run(args); + final BinaryObjectEncodingConverter binaryObjectEncodingConverter = new BinaryObjectEncodingConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.OBJECT_ENCODING, (cmd)->cmd.objectEncoding(key), + binaryObjectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), binaryObjectEncodingConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.OBJECT_ENCODING, (cmd)->cmd.objectEncoding(key), + binaryObjectEncodingConverter) + .run(args); + } } @Override - public Long objectFreq(final String key){ + public Long objectFreq(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.OBJECT_REFQ) - .general((cmd)->cmd.objectFreq(key)) - .pipeline((cmd)->cmd.objectFreq(key)) - .transaction((cmd)->cmd.objectFreq(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + } } @Override - public Long objectFreq(final byte[] key){ + public Long objectFreq(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.OBJECT_REFQ) - .general((cmd)->cmd.objectFreq(key)) - .pipeline((cmd)->cmd.objectFreq(key)) - .transaction((cmd)->cmd.objectFreq(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + } } @Override - public Long objectIdleTime(final String key){ + public Long objectIdleTime(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.OBJECT_IDLETIME) - .general((cmd)->cmd.objectIdletime(key)) - .pipeline((cmd)->cmd.objectIdletime(key)) - .transaction((cmd)->cmd.objectIdletime(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, (cmd)->cmd.objectIdletime(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + } } @Override - public Long objectIdleTime(final byte[] key){ + public Long objectIdleTime(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.OBJECT_IDLETIME) - .general((cmd)->cmd.objectIdletime(key)). - pipeline((cmd)->cmd.objectIdletime(key)) - .transaction((cmd)->cmd.objectIdletime(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, (cmd)->cmd.objectIdletime(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + } } @Override - public Long objectRefcount(final String key){ + public Long objectRefcount(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.OBJECT_REFCOUNT) - .general((cmd)->cmd.objectRefcount(key)) - .pipeline((cmd)->cmd.objectRefcount(key)) - .transaction((cmd)->cmd.objectRefcount(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, (cmd)->cmd.objectRefcount(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + } } @Override - public Long objectRefcount(final byte[] key){ + public Long objectRefcount(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.OBJECT_REFCOUNT) - .general((cmd)->cmd.objectRefcount(key)) - .pipeline((cmd)->cmd.objectRefcount(key)) - .transaction((cmd)->cmd.objectRefcount(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, (cmd)->cmd.objectRefcount(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + } + } + + private Status copy(final String key, final String destKey, final boolean replace, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final byte[] key, final byte[] destKey, final boolean replace, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final String key, final String destKey, final int db, final boolean replace, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, db, replace), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, db, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, db, replace), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, db, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, final String[] keys, + final MigrateParams migrateParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, final byte[][] keys, + final MigrateParams migrateParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + } + } + + private ScanResult> scan(final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + + private ScanResult> scan(final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisListOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisListOperations.java index a8d49a629..92d6b0ef9 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisListOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisListOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -31,9 +31,8 @@ import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; import com.buession.redis.core.internal.convert.jedis.params.DirectionConverter; -import com.buession.redis.core.internal.convert.jedis.params.LPosArgumentConverter; import com.buession.redis.core.internal.convert.jedis.params.ListPositionConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import com.buession.redis.core.internal.jedis.JedisLPosParams; import redis.clients.jedis.args.ListDirection; import redis.clients.jedis.params.LPosParams; @@ -47,474 +46,800 @@ */ public final class JedisListOperations extends AbstractListOperations { - public JedisListOperations(final JedisStandaloneClient client){ + public JedisListOperations(final JedisStandaloneClient client) { super(client); } @Override - public String lIndex(final String key, final long index){ + public String lIndex(final String key, final long index) { final CommandArguments args = CommandArguments.create("key", key).put("index", index); - return new JedisCommand(client, ProtocolCommand.LINDEX) - .general((cmd)->cmd.lindex(key, index)) - .pipeline((cmd)->cmd.lindex(key, index)) - .transaction((cmd)->cmd.lindex(key, index)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + } } @Override - public byte[] lIndex(final byte[] key, final long index){ + public byte[] lIndex(final byte[] key, final long index) { final CommandArguments args = CommandArguments.create("key", key).put("index", index); - return new JedisCommand(client, ProtocolCommand.LINDEX) - .general((cmd)->cmd.lindex(key, index)) - .pipeline((cmd)->cmd.lindex(key, index)) - .transaction((cmd)->cmd.lindex(key, index)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + } } @Override - public Long lInsert(final String key, final ListPosition position, final String pivot, final String value){ + public Long lInsert(final String key, final ListPosition position, final String pivot, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) .put("value", value); - final redis.clients.jedis.args.ListPosition pos = ListPositionConverter.INSTANCE.convert(position); - return new JedisCommand(client, ProtocolCommand.LINSERT) - .general((cmd)->cmd.linsert(key, pos, pivot, value)) - .pipeline((cmd)->cmd.linsert(key, pos, pivot, value)) - .transaction((cmd)->cmd.linsert(key, pos, pivot, value)) - .run(args); - } - - @Override - public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value){ + final redis.clients.jedis.args.ListPosition listPosition = (new ListPositionConverter()).convert(position); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), + (v)->v) + .run(args); + } + } + + @Override + public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) .put("value", value); - final redis.clients.jedis.args.ListPosition pos = ListPositionConverter.INSTANCE.convert(position); - return new JedisCommand(client, ProtocolCommand.LINSERT) - .general((cmd)->cmd.linsert(key, pos, pivot, value)) - .pipeline((cmd)->cmd.linsert(key, pos, pivot, value)) - .transaction((cmd)->cmd.linsert(key, pos, pivot, value)) - .run(args); - } - - @Override - public Status lSet(final String key, final long index, final String value){ + final redis.clients.jedis.args.ListPosition listPosition = (new ListPositionConverter()).convert(position); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), + (v)->v) + .run(args); + } + } + + @Override + public Status lSet(final String key, final long index, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); - return new JedisCommand(client, ProtocolCommand.LINSERT) - .general((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } } @Override - public Status lSet(final byte[] key, final long index, final byte[] value){ + public Status lSet(final byte[] key, final long index, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); - return new JedisCommand(client, ProtocolCommand.LINSERT) - .general((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } } @Override - public Long lLen(final String key){ + public Long lLen(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.LLEN) - .general((cmd)->cmd.llen(key)) - .pipeline((cmd)->cmd.llen(key)) - .transaction((cmd)->cmd.llen(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } } @Override - public Long lLen(final byte[] key){ + public Long lLen(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.LLEN) - .general((cmd)->cmd.llen(key)) - .pipeline((cmd)->cmd.llen(key)) - .transaction((cmd)->cmd.llen(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } } @Override - public List lRange(final String key, final long start, final long end){ + public List lRange(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand>(client, ProtocolCommand.LRANGE) - .general((cmd)->cmd.lrange(key, start, end)) - .pipeline((cmd)->cmd.lrange(key, start, end)) - .transaction((cmd)->cmd.lrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + } } @Override - public List lRange(final byte[] key, final long start, final long end){ + public List lRange(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand>(client, ProtocolCommand.LRANGE) - .general((cmd)->cmd.lrange(key, start, end)) - .pipeline((cmd)->cmd.lrange(key, start, end)) - .transaction((cmd)->cmd.lrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + } } @Override - public Long lPos(final String key, final String element){ + public Long lPos(final String key, final String element) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element)) - .pipeline((cmd)->cmd.lpos(key, element)) - .transaction((cmd)->cmd.lpos(key, element)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } } @Override - public Long lPos(final byte[] key, final byte[] element){ + public Long lPos(final byte[] key, final byte[] element) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element)) - .pipeline((cmd)->cmd.lpos(key, element)) - .transaction((cmd)->cmd.lpos(key, element)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } } @Override - public Long lPos(final String key, final String element, final LPosArgument lPosArgument){ + public Long lPos(final String key, final String element, final LPosArgument lPosArgument) { final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); - final LPosParams params = LPosArgumentConverter.INSTANCE.convert(lPosArgument); - return new JedisCommand(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element, params)) - .pipeline((cmd)->cmd.lpos(key, element, params)) - .transaction((cmd)->cmd.lpos(key, element, params)) - .run(args); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + } } @Override - public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument){ + public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument) { final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); - final LPosParams params = LPosArgumentConverter.INSTANCE.convert(lPosArgument); - return new JedisCommand(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element, params)) - .pipeline((cmd)->cmd.lpos(key, element, params)) - .transaction((cmd)->cmd.lpos(key, element, params)) - .run(args); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + } } @Override - public List lPos(final String key, final String element, final LPosArgument lPosArgument, final long count){ + public List lPos(final String key, final String element, final LPosArgument lPosArgument, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) .put("count", count); - final LPosParams params = LPosArgumentConverter.INSTANCE.convert(lPosArgument); - return new JedisCommand>(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element, params, count)) - .pipeline((cmd)->cmd.lpos(key, element, params, count)) - .transaction((cmd)->cmd.lpos(key, element, params, count)) - .run(args); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element, lPosParams, count), + (v)->v) + .run(args); + } } @Override - public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final long count){ + public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) .put("count", count); - final LPosParams params = LPosArgumentConverter.INSTANCE.convert(lPosArgument); - return new JedisCommand>(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element, params, count)) - .pipeline((cmd)->cmd.lpos(key, element, params, count)) - .transaction((cmd)->cmd.lpos(key, element, params, count)) - .run(args); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element, lPosParams, count), + (v)->v) + .run(args); + } } @Override - public Long lRem(final String key, final String value, final long count){ + public Long lRem(final String key, final String value, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); - return new JedisCommand(client, ProtocolCommand.LREM) - .general((cmd)->cmd.lrem(key, count, value)) - .pipeline((cmd)->cmd.lrem(key, count, value)) - .transaction((cmd)->cmd.lrem(key, count, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } } @Override - public Long lRem(final byte[] key, final byte[] value, final long count){ + public Long lRem(final byte[] key, final byte[] value, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); - return new JedisCommand(client, ProtocolCommand.LREM) - .general((cmd)->cmd.lrem(key, count, value)) - .pipeline((cmd)->cmd.lrem(key, count, value)) - .transaction((cmd)->cmd.lrem(key, count, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } } @Override - public Status lTrim(final String key, final long start, final long end){ + public Status lTrim(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand(client, ProtocolCommand.LTRIM) - .general((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } } @Override - public Status lTrim(final byte[] key, final long start, final long end){ + public Status lTrim(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand(client, ProtocolCommand.LTRIM) - .general((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } } @Override - public String lMove(final String key, final String destKey, final Direction from, final Direction to){ + public String lMove(final String key, final String destKey, final Direction from, final Direction to) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) .put("to", to); - final ListDirection fromDirection = DirectionConverter.INSTANCE.convert(from); - final ListDirection toDirection = DirectionConverter.INSTANCE.convert(to); - return new JedisCommand(client, ProtocolCommand.LMOVE) - .general((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .pipeline((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .transaction((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .run(args); - } - - @Override - public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to){ + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LMOVE, (cmd)->cmd.lmove(key, destKey, fromDirection, + toDirection), (v)->v) + .run(args); + } + } + + @Override + public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) .put("to", to); - final ListDirection fromDirection = DirectionConverter.INSTANCE.convert(from); - final ListDirection toDirection = DirectionConverter.INSTANCE.convert(to); - return new JedisCommand(client, ProtocolCommand.LMOVE) - .general((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .pipeline((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .transaction((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .run(args); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LMOVE, (cmd)->cmd.lmove(key, destKey, fromDirection, + toDirection), (v)->v) + .run(args); + } } @Override public String blMove(final String key, final String destKey, final Direction from, final Direction to, - final int timeout){ + final int timeout) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) .put("to", to).put("timeout", timeout); - final ListDirection fromDirection = DirectionConverter.INSTANCE.convert(from); - final ListDirection toDirection = DirectionConverter.INSTANCE.convert(to); - return new JedisCommand(client, ProtocolCommand.BLMOVE) - .general((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .pipeline((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .transaction((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .run(args); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + } } @Override public byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, - final int timeout){ + final int timeout) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) .put("to", to).put("timeout", timeout); - final ListDirection fromDirection = DirectionConverter.INSTANCE.convert(from); - final ListDirection toDirection = DirectionConverter.INSTANCE.convert(to); - return new JedisCommand(client, ProtocolCommand.BLMOVE) - .general((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .pipeline((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .transaction((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .run(args); - } - - @Override - public List blPop(final String[] keys, final int timeout){ + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + } + } + + @Override + public List blPop(final String[] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisCommand>(client, ProtocolCommand.BLPOP) - .general((cmd)->cmd.blpop(timeout, keys)) - .pipeline((cmd)->cmd.blpop(timeout, keys)) - .transaction((cmd)->cmd.blpop(timeout, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + } } @Override - public List blPop(final byte[][] keys, final int timeout){ + public List blPop(final byte[][] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisCommand>(client, ProtocolCommand.BLPOP) - .general((cmd)->cmd.blpop(timeout, keys)) - .pipeline((cmd)->cmd.blpop(timeout, keys)) - .transaction((cmd)->cmd.blpop(timeout, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + } } @Override - public List brPop(final String[] keys, final int timeout){ + public List brPop(final String[] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisCommand>(client, ProtocolCommand.BRPOP) - .general((cmd)->cmd.brpop(timeout, keys)) - .pipeline((cmd)->cmd.brpop(timeout, keys)) - .transaction((cmd)->cmd.brpop(timeout, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + } } @Override - public List brPop(final byte[][] keys, final int timeout){ + public List brPop(final byte[][] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisCommand>(client, ProtocolCommand.BRPOP) - .general((cmd)->cmd.brpop(timeout, keys)) - .pipeline((cmd)->cmd.brpop(timeout, keys)) - .transaction((cmd)->cmd.brpop(timeout, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + } } @Override - public String brPoplPush(final String key, final String destKey, final int timeout){ + public String brPoplPush(final String key, final String destKey, final int timeout) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("timeout", timeout); - return new JedisCommand(client, ProtocolCommand.BRPOPLPUSH) - .general((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .pipeline((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .transaction((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BRPOPLPUSH, (cmd)->cmd.brpoplpush(key, destKey, timeout), + (v)->v) + .run(args); + } } @Override - public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout){ + public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("timeout", timeout); - return new JedisCommand(client, ProtocolCommand.BRPOPLPUSH) - .general((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .pipeline((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .transaction((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BRPOPLPUSH, (cmd)->cmd.brpoplpush(key, destKey, timeout), + (v)->v) + .run(args); + } } @Override - public String lPop(final String key){ + public String lPop(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.LPOP) - .general((cmd)->cmd.lpop(key)) - .pipeline((cmd)->cmd.lpop(key)) - .transaction((cmd)->cmd.lpop(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + } } @Override - public byte[] lPop(final byte[] key){ + public byte[] lPop(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.LPOP) - .general((cmd)->cmd.lpop(key)) - .pipeline((cmd)->cmd.lpop(key)) - .transaction((cmd)->cmd.lpop(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + } } @Override - public Long lPush(final String key, final String... values){ + public Long lPush(final String key, final String... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisCommand(client, ProtocolCommand.LPUSH) - .general((cmd)->cmd.lpush(key, values)) - .pipeline((cmd)->cmd.lpush(key, values)) - .transaction((cmd)->cmd.lpush(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } } @Override - public Long lPush(final byte[] key, final byte[]... values){ + public Long lPush(final byte[] key, final byte[]... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisCommand(client, ProtocolCommand.LPUSH) - .general((cmd)->cmd.lpush(key, values)) - .pipeline((cmd)->cmd.lpush(key, values)) - .transaction((cmd)->cmd.lpush(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } } @Override - public Long lPushX(final String key, final String... values){ + public Long lPushX(final String key, final String... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisCommand(client, ProtocolCommand.LPUSHX) - .general((cmd)->cmd.lpushx(key, values)) - .pipeline((cmd)->cmd.lpushx(key, values)) - .transaction((cmd)->cmd.lpushx(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } } @Override - public Long lPushX(final byte[] key, final byte[]... values){ + public Long lPushX(final byte[] key, final byte[]... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisCommand(client, ProtocolCommand.LPUSHX) - .general((cmd)->cmd.lpushx(key, values)) - .pipeline((cmd)->cmd.lpushx(key, values)) - .transaction((cmd)->cmd.lpushx(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } } @Override - public String rPop(final String key){ + public String rPop(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.RPOP) - .general((cmd)->cmd.rpop(key)) - .pipeline((cmd)->cmd.rpop(key)) - .transaction((cmd)->cmd.rpop(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + } } @Override - public byte[] rPop(final byte[] key){ + public byte[] rPop(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.RPOP) - .general((cmd)->cmd.rpop(key)) - .pipeline((cmd)->cmd.rpop(key)) - .transaction((cmd)->cmd.rpop(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + } } @Override - public String rPoplPush(final String key, final String destKey){ + public String rPoplPush(final String key, final String destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisCommand(client, ProtocolCommand.RPOPLPUSH) - .general((cmd)->cmd.rpoplpush(key, destKey)) - .pipeline((cmd)->cmd.rpoplpush(key, destKey)) - .transaction((cmd)->cmd.rpoplpush(key, destKey)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + } } @Override - public byte[] rPoplPush(final byte[] key, final byte[] destKey){ + public byte[] rPoplPush(final byte[] key, final byte[] destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisCommand(client, ProtocolCommand.RPOPLPUSH) - .general((cmd)->cmd.rpoplpush(key, destKey)) - .pipeline((cmd)->cmd.rpoplpush(key, destKey)) - .transaction((cmd)->cmd.rpoplpush(key, destKey)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + } } @Override - public Long rPush(final String key, final String... values){ + public Long rPush(final String key, final String... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisCommand(client, ProtocolCommand.RPUSH) - .general((cmd)->cmd.rpush(key, values)) - .pipeline((cmd)->cmd.rpush(key, values)) - .transaction((cmd)->cmd.rpush(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } } @Override - public Long rPush(final byte[] key, final byte[]... values){ + public Long rPush(final byte[] key, final byte[]... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisCommand(client, ProtocolCommand.RPUSH) - .general((cmd)->cmd.rpush(key, values)) - .pipeline((cmd)->cmd.rpush(key, values)) - .transaction((cmd)->cmd.rpush(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } } @Override - public Long rPushX(final String key, final String... values){ + public Long rPushX(final String key, final String... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisCommand(client, ProtocolCommand.RPUSHX) - .general((cmd)->cmd.rpushx(key, values)) - .pipeline((cmd)->cmd.rpushx(key, values)) - .transaction((cmd)->cmd.rpushx(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } } @Override - public Long rPushX(final byte[] key, final byte[]... values){ + public Long rPushX(final byte[] key, final byte[]... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisCommand(client, ProtocolCommand.RPUSHX) - .general((cmd)->cmd.rpushx(key, values)) - .pipeline((cmd)->cmd.rpushx(key, values)) - .transaction((cmd)->cmd.rpushx(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisPubSubOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisPubSubOperations.java index f9694e166..c02d0842b 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisPubSubOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisPubSubOperations.java @@ -19,12 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; -import com.buession.core.collect.Maps; +import com.buession.core.converter.Converter; +import com.buession.core.converter.MapConverter; import com.buession.redis.client.jedis.JedisStandaloneClient; import com.buession.redis.core.PubSubListener; import com.buession.redis.core.command.CommandArguments; @@ -45,167 +46,292 @@ */ public final class JedisPubSubOperations extends AbstractPubSubOperations { - public JedisPubSubOperations(final JedisStandaloneClient client){ + public JedisPubSubOperations(final JedisStandaloneClient client) { super(client); } @Override - public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener){ + public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener) { final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) .put("pubSubListener", pubSubListener); - new JedisCommand(client, ProtocolCommand.PSUBSCRIBE) - .general((cmd)->{ - cmd.psubscribe(new DefaultJedisPubSub(pubSubListener), patterns); - return null; - }) - .run(args); + + if(isPipeline()){ + new JedisPipelineCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else{ + new JedisCommand<>(client, ProtocolCommand.PSUBSCRIBE, (cmd)->{ + cmd.psubscribe(new DefaultJedisPubSub(pubSubListener), patterns); + return null; + }, (v)->v) + .run(args); + } } @Override - public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener){ + public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener) { final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) .put("pubSubListener", pubSubListener); - new JedisCommand(client, ProtocolCommand.PSUBSCRIBE) - .general((cmd)->{ - cmd.psubscribe(new DefaultBinaryJedisPubSub(pubSubListener), patterns); - return null; - }) - .run(args); + + if(isPipeline()){ + new JedisPipelineCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else{ + new JedisCommand<>(client, ProtocolCommand.PSUBSCRIBE, (cmd)->{ + cmd.psubscribe(new DefaultBinaryJedisPubSub(pubSubListener), patterns); + return null; + }, (v)->v) + .run(args); + } } @Override - public Long publish(final String channel, final String message){ + public Long publish(final String channel, final String message) { final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); - return new JedisCommand(client, ProtocolCommand.PUBLISH) - .general((cmd)->cmd.publish(channel, message)) - .pipeline((cmd)->cmd.publish(channel, message)) - .transaction((cmd)->cmd.publish(channel, message)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.PUBLISH) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PUBLISH, (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + } } @Override - public Long publish(final byte[] channel, final byte[] message){ + public Long publish(final byte[] channel, final byte[] message) { final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); - return new JedisCommand(client, ProtocolCommand.PUBLISH) - .general((cmd)->cmd.publish(channel, message)) - .pipeline((cmd)->cmd.publish(channel, message)) - .transaction((cmd)->cmd.publish(channel, message)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.PUBLISH) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PUBLISH, (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + } } @Override - public List pubsubChannels(){ - return new JedisCommand>(client, ProtocolCommand.PUBSUB_CHANNELS) - .general((cmd)->cmd.pubsubChannels()) - .run(); + public List pubsubChannels() { + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(), (v)->v) + .run(); + } } @Override - public List pubsubChannels(final String pattern){ + public List pubsubChannels(final String pattern) { final CommandArguments args = CommandArguments.create("pattern", pattern); - return new JedisCommand>(client, ProtocolCommand.PUBSUB_CHANNELS) - .general((cmd)->cmd.pubsubChannels(pattern)) - .run(args); + return pubsubChannels(pattern, (v)->v, args); } @Override - public List pubsubChannels(final byte[] pattern){ + public List pubsubChannels(final byte[] pattern) { final CommandArguments args = CommandArguments.create("pattern", pattern); - return new JedisCommand>(client, ProtocolCommand.PUBSUB_CHANNELS) - .general((cmd)->cmd.pubsubChannels(SafeEncoder.encode(pattern)), - Converters.STRING_LIST_TO_BINARY_LIST_CONVERTER) - .run(args); + final String sPattern = SafeEncoder.encode(pattern); + final com.buession.core.converter.ListConverter stringToBinaryListConverter = + Converters.listStringToBinary(); + + return pubsubChannels(sPattern, stringToBinaryListConverter, args); } @Override - public Long pubsubNumPat(){ - return new JedisCommand(client, ProtocolCommand.PUBSUB_NUMPAT) - .general((cmd)->cmd.pubsubNumPat()) - .run(); + public Long pubsubNumPat() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.PUBSUB_NUMPAT) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.PUBSUB_NUMPAT) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PUBSUB_NUMPAT, (cmd)->cmd.pubsubNumPat(), (v)->v) + .run(); + } } @Override - public Map pubsubNumSub(final String... channels){ + public Map pubsubNumSub(final String... channels) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); - return new JedisCommand>(client, ProtocolCommand.PUBSUB_NUMSUB) - .general((cmd)->cmd.pubsubNumSub(channels)) - .run(args); + return pubsubNumSub(channels, (v)->v, args); } @Override - public Map pubsubNumSub(final byte[]... channels){ + public Map pubsubNumSub(final byte[]... channels) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); - return new JedisCommand>(client, ProtocolCommand.PUBSUB_NUMSUB) - .general((cmd)->{ - final Map temp = cmd.pubsubNumSub( - Converters.BINARY_ARRAY_TO_STRING_ARRAY_CONVERTER.convert(channels)); - return Maps.map(temp, SafeEncoder::encode, (value)->value); - }) - .run(args); + final String[] sChannels = SafeEncoder.encode(channels); + final MapConverter stringToBinaryKeyPrimitiveValueMapConverter = + new MapConverter<>(SafeEncoder::encode, (v)->v); + + return pubsubNumSub(sChannels, stringToBinaryKeyPrimitiveValueMapConverter, args); } @Override - public Object pUnSubscribe(){ - return new JedisCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) - .run(); + public Object pUnSubscribe() { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + } } @Override - public Object pUnSubscribe(final String... patterns){ + public Object pUnSubscribe(final String... patterns) { final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); - return new JedisCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) - .run(args); + return pUnSubscribe(args); } @Override - public Object pUnSubscribe(final byte[]... patterns){ + public Object pUnSubscribe(final byte[]... patterns) { final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); - return new JedisCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) - .run(args); + return pUnSubscribe(args); } @Override - public void subscribe(final String[] channels, final PubSubListener pubSubListener){ + public void subscribe(final String[] channels, final PubSubListener pubSubListener) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) .put("pubSubListener", pubSubListener); - new JedisCommand(client, ProtocolCommand.PUBLISH) - .general((cmd)->{ - cmd.subscribe(new DefaultJedisPubSub(pubSubListener), channels); - return null; - }) - .run(args); + + if(isPipeline()){ + new JedisPipelineCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else{ + new JedisCommand<>(client, ProtocolCommand.SUBSCRIBE, (cmd)->{ + cmd.subscribe(new DefaultJedisPubSub(pubSubListener), channels); + return null; + }, (v)->v) + .run(args); + } } @Override - public void subscribe(final byte[][] channels, final PubSubListener pubSubListener){ + public void subscribe(final byte[][] channels, final PubSubListener pubSubListener) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) .put("pubSubListener", pubSubListener); - new JedisCommand(client, ProtocolCommand.PUBLISH) - .general((cmd)->{ - cmd.subscribe(new DefaultBinaryJedisPubSub(pubSubListener), channels); - return null; - }) - .run(args); + + if(isPipeline()){ + new JedisPipelineCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else{ + new JedisCommand<>(client, ProtocolCommand.SUBSCRIBE, (cmd)->{ + cmd.subscribe(new DefaultBinaryJedisPubSub(pubSubListener), channels); + return null; + }, (v)->v) + .run(args); + } } @Override - public Object unSubscribe(){ - return new JedisCommand<>(client, ProtocolCommand.UNSUBSCRIBE) - .run(); + public Object unSubscribe() { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + } } @Override - public Object unSubscribe(final String... channels){ + public Object unSubscribe(final String... channels) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); - return new JedisCommand<>(client, ProtocolCommand.UNSUBSCRIBE) - .run(args); + return unSubscribe(args); } @Override - public Object unSubscribe(final byte[]... channels){ + public Object unSubscribe(final byte[]... channels) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); - return new JedisCommand<>(client, ProtocolCommand.UNSUBSCRIBE) - .run(args); + return unSubscribe(args); + } + + private List pubsubChannels(final String pattern, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(pattern), + converter) + .run(); + } + } + + private Map pubsubNumSub(final String[] channels, + final Converter, Map> converter, + final CommandArguments args) { + + if(isPipeline()){ + return new JedisPipelineCommand, Map>(client, ProtocolCommand.PUBSUB_NUMSUB) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, Map>(client, ProtocolCommand.PUBSUB_NUMSUB) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PUBSUB_NUMSUB, (cmd)->cmd.pubsubNumSub(channels), + converter) + .run(args); + } + } + + private Object pUnSubscribe(final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + } + } + + private Object unSubscribe(final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisRedisOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisRedisOperations.java index f780adb39..cacf29b62 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisRedisOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisRedisOperations.java @@ -19,32 +19,28 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; -import com.buession.core.Executor; import com.buession.core.converter.Converter; -import com.buession.redis.client.connection.RedisConnectionUtils; import com.buession.redis.client.connection.jedis.JedisClusterConnection; import com.buession.redis.client.connection.jedis.JedisConnection; -import com.buession.redis.client.connection.jedis.JedisRedisConnection; import com.buession.redis.client.connection.jedis.JedisSentinelConnection; import com.buession.redis.client.jedis.JedisClusterClient; -import com.buession.redis.client.jedis.JedisRedisClient; import com.buession.redis.client.jedis.JedisSentinelClient; import com.buession.redis.client.jedis.JedisStandaloneClient; import com.buession.redis.client.operations.RedisOperations; +import com.buession.redis.core.Command; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.AbstractRedisOperationsCommand; import com.buession.redis.core.internal.jedis.JedisResult; -import com.buession.redis.exception.NotSupportedCommandException; -import com.buession.redis.exception.NotSupportedPipelineCommandException; -import com.buession.redis.exception.NotSupportedTransactionCommandException; import com.buession.redis.exception.RedisException; -import com.buession.redis.pipeline.jedis.JedisPipeline; -import com.buession.redis.transaction.jedis.JedisTransaction; +import com.buession.redis.exception.RedisPipelineException; +import com.buession.redis.exception.RedisTransactionException; +import com.buession.redis.pipeline.PipelineProxy; +import com.buession.redis.transaction.TransactionProxy; +import redis.clients.jedis.ClusterPipeline; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisCluster; import redis.clients.jedis.Pipeline; @@ -58,290 +54,316 @@ */ public interface JedisRedisOperations extends RedisOperations { - abstract class AbstractJedisCommand - extends AbstractRedisOperationsCommand { + class JedisCommand extends + AbstractStandaloneCommand { - protected AbstractJedisCommand(final CLIENT client, final ProtocolCommand command) { + public JedisCommand(final JedisStandaloneClient client, final ProtocolCommand command) { super(client, command); } + public JedisCommand(final JedisStandaloneClient client, final ProtocolCommand command, + final Executor executor, final Converter converter) { + super(client, command, executor, converter); + } + @Override - public R execute() throws RedisException { - if(connection.isPipeline()){ - if(pipelineRunner == null){ - throw new NotSupportedPipelineCommandException( - RedisConnectionUtils.getRedisMode(client.getConnection()), getCommand()); - }else{ - try{ - client.getTxResults().add(pipelineRunner.run()); - }catch(Exception e){ - throw new RedisException(e.getMessage(), e); - } - } - }else if(connection.isTransaction()){ - if(transactionRunner == null){ - throw new NotSupportedTransactionCommandException( - RedisConnectionUtils.getRedisMode(client.getConnection()), getCommand()); - }else{ - try{ - client.getTxResults().add(transactionRunner.run()); - }catch(Exception e){ - throw new RedisException(e.getMessage(), e); - } - } - }else{ - if(runner == null){ - throw new NotSupportedCommandException( - RedisConnectionUtils.getRedisMode(client.getConnection()), - NotSupportedCommandException.Type.NORMAL, getCommand()); - }else{ - try{ - return runner.run(); - }catch(Exception e){ - throw new RedisException(e.getMessage(), e); - } - } - } - return null; + protected R doExecute() throws RedisException { + final SR result = executor.execute(connection.getJedis()); + return result == null ? null : converter.convert(result); } - protected Runner createPipelineRunner(final Executor> executor) { - return new Runner() { + } - @SuppressWarnings({"unchecked"}) - @Override - public JedisResult run() throws Exception { - final redis.clients.jedis.Pipeline jedisPipeline = ((JedisPipeline) pipeline()).primitive(); - return newJedisResult(executor.execute(jedisPipeline)); - } + class JedisPipelineCommand extends + AbstractStandaloneCommand, SR, R> { - }; + public JedisPipelineCommand(final JedisStandaloneClient client, final ProtocolCommand command) { + super(client, command); } - protected Runner createPipelineRunner(final Executor> executor, - final Converter converter) { - return new Runner() { + public JedisPipelineCommand(final JedisStandaloneClient client, final ProtocolCommand command, + final Executor> executor, final Converter converter) { + super(client, command, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.pipeline.Pipeline pipeline = pipeline(); - @SuppressWarnings({"unchecked"}) - @Override - public JedisResult run() throws Exception { - final redis.clients.jedis.Pipeline jedisPipeline = ((JedisPipeline) pipeline()).primitive(); - return newJedisResult(executor.execute(jedisPipeline), converter); - } + if(pipeline instanceof PipelineProxy){ + final PipelineProxy> pipelineFactory = + (PipelineProxy>) pipeline; + final Runner runner = new PipelineRunner<>(executor, pipelineFactory, converter); - }; + pipelineFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisPipelineException("ERR EXEC without pipeline. Did you forget to call openPipeline?"); + } } - protected Runner createTransactionRunner(final Executor> executor) { - return new Runner() { + } - @SuppressWarnings({"unchecked"}) - @Override - public JedisResult run() throws Exception { - final redis.clients.jedis.Transaction transaction = ((JedisTransaction) transaction()).primitive(); - return newJedisResult(executor.execute(transaction)); - } + class JedisTransactionCommand extends + AbstractStandaloneCommand, SR, R> { - }; + public JedisTransactionCommand(final JedisStandaloneClient client, final ProtocolCommand command) { + super(client, command); } - protected Runner createTransactionRunner(final Executor> executor, - final Converter converter) { - return new Runner() { + public JedisTransactionCommand(final JedisStandaloneClient client, final ProtocolCommand command, + final Executor> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.transaction.Transaction transaction = transaction(); + + if(transaction instanceof TransactionProxy){ + final TransactionProxy> transactionFactory = + (TransactionProxy>) transaction; + final Runner runner = new TransactionRunner<>(executor, transactionFactory, converter); - @SuppressWarnings({"unchecked"}) - @Override - public JedisResult run() throws Exception { - final redis.clients.jedis.Transaction transaction = ((JedisTransaction) transaction()).primitive(); - return newJedisResult(executor.execute(transaction), converter); - } + transactionFactory.getTxResults().add(runner.run()); - }; + return null; + }else{ + throw new RedisTransactionException("ERR EXEC without multi. Did you forget to call multi?"); + } } - protected JedisResult newJedisResult(final Response response) { - return JedisResult.Builder.fromResponse(response).build(); + } + + class JedisSentinelCommand extends + AbstractSentinelCommand { + + public JedisSentinelCommand(final JedisSentinelClient client, final ProtocolCommand command) { + super(client, command); + } + + public JedisSentinelCommand(final JedisSentinelClient client, final ProtocolCommand command, + final Executor executor, final Converter converter) { + super(client, command, executor, converter); } - protected JedisResult newJedisResult(final Response response, - final Converter converter) { - return JedisResult.Builder.fromResponse(response).mappedWith(converter).build(); + @Override + protected R doExecute() throws RedisException { + final SR result = executor.execute(connection.getJedis()); + return result == null ? null : converter.convert(result); } } - class JedisCommand extends AbstractJedisCommand { + class JedisSentinelPipelineCommand extends + AbstractSentinelCommand, SR, R> { - public JedisCommand(final JedisStandaloneClient client, final ProtocolCommand command) { + public JedisSentinelPipelineCommand(final JedisSentinelClient client, final ProtocolCommand command) { super(client, command); } - public JedisCommand general(final Executor executor) { - this.runner = new Runner() { + public JedisSentinelPipelineCommand(final JedisSentinelClient client, final ProtocolCommand command, + final Executor> executor, + final Converter converter) { + super(client, command, executor, converter); + } - @SuppressWarnings({"unchecked"}) - @Override - public R run() throws Exception { - return executor.execute(connection.getJedis()); - } + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.pipeline.Pipeline pipeline = pipeline(); - }; + if(pipeline instanceof PipelineProxy){ + final PipelineProxy> pipelineFactory = (PipelineProxy>) pipeline; + final Runner runner = new PipelineRunner<>(executor, pipelineFactory, converter); - return this; + pipelineFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisPipelineException("ERR EXEC without pipeline. Did you forget to call openPipeline?"); + } } - public JedisCommand general(final Executor executor, final Converter converter) { - this.runner = new Runner() { + } - @SuppressWarnings({"unchecked"}) - @Override - public R run() throws Exception { - return converter.convert(executor.execute(connection.getJedis())); - } + class JedisSentinelTransactionCommand extends + AbstractSentinelCommand, SR, R> { - }; + public JedisSentinelTransactionCommand(final JedisSentinelClient client, final ProtocolCommand command) { + super(client, command); + } - return this; + public JedisSentinelTransactionCommand(final JedisSentinelClient client, final ProtocolCommand command, + final Executor> executor, + final Converter converter) { + super(client, command, executor, converter); } - public JedisCommand pipeline(final Executor> executor) { - this.pipelineRunner = createPipelineRunner(executor); - return this; + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.transaction.Transaction transaction = transaction(); + + if(transaction instanceof TransactionProxy){ + final TransactionProxy> transactionFactory = + (TransactionProxy>) transaction; + final Runner runner = new TransactionRunner<>(executor, transactionFactory, converter); + + transactionFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisTransactionException("ERR EXEC without multi. Did you forget to call multi?"); + } } - public JedisCommand pipeline(final Executor> executor, - final Converter converter) { - this.pipelineRunner = createPipelineRunner(executor, converter); - return this; + } + + class JedisClusterCommand extends + AbstractClusterCommand { + + public JedisClusterCommand(final JedisClusterClient client, final ProtocolCommand command) { + super(client, command); } - public JedisCommand transaction(final Executor> executor) { - this.transactionRunner = createTransactionRunner(executor); - return this; + public JedisClusterCommand(final JedisClusterClient client, final ProtocolCommand command, + final Executor executor, final Converter converter) { + super(client, command, executor, converter); } - public JedisCommand transaction(final Executor> executor, - final Converter converter) { - this.transactionRunner = createTransactionRunner(executor, converter); - return this; + @Override + protected R doExecute() throws RedisException { + final SR result = executor.execute(connection.getCluster()); + return result == null ? null : converter.convert(result); } } - class JedisSentinelCommand extends AbstractJedisCommand { + class JedisClusterPipelineCommand extends + AbstractClusterCommand, SR, R> { - protected JedisSentinelCommand(final JedisSentinelClient client, final ProtocolCommand command) { + public JedisClusterPipelineCommand(final JedisClusterClient client, final ProtocolCommand command) { super(client, command); } - public JedisSentinelCommand general(Executor executor) { - this.runner = new Runner() { + public JedisClusterPipelineCommand(final JedisClusterClient client, final ProtocolCommand command, + final Executor> executor, + final Converter converter) { + super(client, command, executor, converter); + } - @SuppressWarnings({"unchecked"}) - @Override - public R run() throws Exception { - return executor.execute(connection.getJedis()); - } + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.pipeline.Pipeline pipeline = pipeline(); - }; + if(pipeline instanceof PipelineProxy){ + final PipelineProxy> pipelineFactory = (PipelineProxy>) pipeline; + final Runner runner = new PipelineRunner<>(executor, pipelineFactory, converter); - return this; - } + pipelineFactory.getTxResults().add(runner.run()); - public JedisSentinelCommand general(final Executor executor, - final Converter converter) { - this.runner = new Runner() { + return null; + }else{ + throw new RedisPipelineException("ERR EXEC without pipeline. Did you forget to call openPipeline?"); + } + } - @SuppressWarnings({"unchecked"}) - @Override - public R run() throws Exception { - return converter.convert(executor.execute(connection.getJedis())); - } + } - }; + class JedisClusterTransactionCommand extends + AbstractClusterCommand, SR, R> { - return this; + public JedisClusterTransactionCommand(final JedisClusterClient client, final ProtocolCommand command) { + super(client, command); } - public JedisSentinelCommand pipeline(final Executor> executor) { - this.pipelineRunner = createPipelineRunner(executor); - return this; + public JedisClusterTransactionCommand(final JedisClusterClient client, final ProtocolCommand command, + final Executor> executor, + final Converter converter) { + super(client, command, executor, converter); } - public JedisSentinelCommand pipeline(final Executor> executor, - final Converter converter) { - this.pipelineRunner = createPipelineRunner(executor, converter); - return this; - } + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.transaction.Transaction transaction = transaction(); - public JedisSentinelCommand transaction(final Executor> executor) { - this.transactionRunner = createTransactionRunner(executor); - return this; - } + if(transaction instanceof TransactionProxy){ + final TransactionProxy> transactionFactory = + (TransactionProxy>) transaction; + final Runner runner = new TransactionRunner<>(executor, transactionFactory, converter); + + transactionFactory.getTxResults().add(runner.run()); - public JedisSentinelCommand transaction(final Executor> executor, - final Converter converter) { - this.transactionRunner = createTransactionRunner(executor, converter); - return this; + return null; + }else{ + throw new RedisTransactionException("ERR EXEC without multi. Did you forget to call multi?"); + } } } - class JedisClusterCommand extends AbstractJedisCommand { + abstract class PtRunner implements Command.Runner { - protected JedisClusterCommand(final JedisClusterClient client, final ProtocolCommand command) { - super(client, command); - } + protected final Command.Executor> executor; - public JedisClusterCommand general(Executor executor) { - this.runner = new Runner() { + protected final Converter converter; - @SuppressWarnings({"unchecked"}) - @Override - public R run() throws Exception { - return executor.execute(connection.getCluster()); - } + public PtRunner(final Command.Executor> executor, final Converter converter) { + this.executor = executor; + this.converter = converter; + } - }; + protected JedisResult newJedisResult(final Response response) { + return JedisResult.Builder.fromResponse(response).build(); + } - return this; + protected JedisResult newJedisResult(final Response response, final Converter converter) { + return JedisResult.Builder.fromResponse(response).mappedWith(converter).build(); } - public JedisClusterCommand general(final Executor executor, - final Converter converter) { - this.runner = new Runner() { + } - @SuppressWarnings({"unchecked"}) - @Override - public R run() throws Exception { - return converter.convert(executor.execute(connection.getCluster())); - } + final class PipelineRunner extends PtRunner { - }; + private final PipelineProxy> pipelineFactory; - return this; + public PipelineRunner(final Command.Executor> executor, + final PipelineProxy> pipelineFactory, + final Converter converter) { + super(executor, converter); + this.pipelineFactory = pipelineFactory; } - public JedisClusterCommand pipeline(final Executor> executor) { - this.pipelineRunner = createPipelineRunner(executor); - return this; + @SuppressWarnings({"unchecked"}) + @Override + public JedisResult run() throws RedisException { + final Response response = executor.execute(pipelineFactory.getObject()); + return converter == null ? newJedisResult(response) : newJedisResult(response, converter); } - public JedisClusterCommand pipeline(final Executor> executor, - final Converter converter) { - this.pipelineRunner = createPipelineRunner(executor, converter); - return this; - } + } + + final class TransactionRunner extends PtRunner { - public JedisClusterCommand transaction(final Executor> executor) { - this.transactionRunner = createTransactionRunner(executor); - return this; + private final TransactionProxy> transactionFactory; + + public TransactionRunner(final Command.Executor> executor, + final TransactionProxy> transactionFactory, + final Converter converter) { + super(executor, converter); + this.transactionFactory = transactionFactory; } - public JedisClusterCommand transaction(final Executor> executor, - final Converter converter) { - this.transactionRunner = createTransactionRunner(executor, converter); - return this; + @SuppressWarnings({"unchecked"}) + @Override + public JedisResult run() throws RedisException { + final Response response = executor.execute(transactionFactory.getObject()); + return converter == null ? newJedisResult(response) : newJedisResult(response, converter); } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisScriptingOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisScriptingOperations.java index 41bc5283a..d8e1db832 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisScriptingOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisScriptingOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -30,7 +30,6 @@ import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; import com.buession.redis.core.internal.convert.jedis.params.FlushModeConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; import java.util.Arrays; import java.util.List; @@ -43,205 +42,363 @@ */ public final class JedisScriptingOperations extends AbstractScriptingOperations { - public JedisScriptingOperations(final JedisStandaloneClient client){ + public JedisScriptingOperations(final JedisStandaloneClient client) { super(client); } @Override - public Object eval(final String script){ + public Object eval(final String script) { final CommandArguments args = CommandArguments.create("script", script); - return new JedisCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script)) - .pipeline((cmd)->cmd.eval(script)) - .transaction((cmd)->cmd.eval(script)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + } } @Override - public Object eval(final byte[] script){ + public Object eval(final byte[] script) { final CommandArguments args = CommandArguments.create("script", script); - return new JedisCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script)) - .pipeline((cmd)->cmd.eval(script)) - .transaction((cmd)->cmd.eval(script)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + } } @Override - public Object eval(final String script, final String... params){ + public Object eval(final String script, final String... params) { final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); final int paramsSize = params == null ? 0 : params.length; - return new JedisCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script, paramsSize, params)) - .pipeline((cmd)->cmd.eval(script, paramsSize, params)) - .transaction((cmd)->cmd.eval(script, paramsSize, params)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script, paramsSize, params), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + } } @Override - public Object eval(final byte[] script, final byte[]... params){ + public Object eval(final byte[] script, final byte[]... params) { final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); final int paramsSize = params == null ? 0 : params.length; - return new JedisCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script, paramsSize, params)) - .pipeline((cmd)->cmd.eval(script, paramsSize, params)) - .transaction((cmd)->cmd.eval(script, paramsSize, params)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script, paramsSize, params), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + } } @Override - public Object eval(final String script, final String[] keys, final String[] arguments){ + public Object eval(final String script, final String[] keys, final String[] arguments) { final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) .put("arguments", (Object[]) arguments); - return new JedisCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .pipeline((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .transaction((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .run(args); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script, keysList, argumentsList), + (v)->v) + .run(args); + } } @Override - public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments){ + public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments) { final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) .put("arguments", (Object[]) arguments); - return new JedisCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .pipeline((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .transaction((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .run(args); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script, keysList, argumentsList), + (v)->v) + .run(args); + } } @Override - public Object evalSha(final String digest){ + public Object evalSha(final String digest) { final CommandArguments args = CommandArguments.create("digest", digest); - return new JedisCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest)) - .pipeline((cmd)->cmd.evalsha(digest)) - .transaction((cmd)->cmd.evalsha(digest)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + } } @Override - public Object evalSha(final byte[] digest){ + public Object evalSha(final byte[] digest) { final CommandArguments args = CommandArguments.create("digest", digest); - return new JedisCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest)) - .pipeline((cmd)->cmd.evalsha(digest)) - .transaction((cmd)->cmd.evalsha(digest)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + } } @Override - public Object evalSha(final String digest, final String... params){ + public Object evalSha(final String digest, final String... params) { final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); final int paramsSize = params == null ? 0 : params.length; - return new JedisCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest, paramsSize, params)) - .pipeline((cmd)->cmd.evalsha(digest, paramsSize, params)) - .transaction((cmd)->cmd.evalsha(digest, paramsSize, params)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest, paramsSize, params), + (v)->v) + .run(args); + } } @Override - public Object evalSha(final byte[] digest, final byte[]... params){ + public Object evalSha(final byte[] digest, final byte[]... params) { final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); final int paramsSize = params == null ? 0 : params.length; - return new JedisCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest, paramsSize, params)) - .pipeline((cmd)->cmd.evalsha(digest, paramsSize, params)) - .transaction((cmd)->cmd.evalsha(digest, paramsSize, params)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest, paramsSize, params), + (v)->v) + .run(args); + } } @Override - public Object evalSha(final String digest, final String[] keys, final String[] arguments){ + public Object evalSha(final String digest, final String[] keys, final String[] arguments) { final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) .put("arguments", (Object[]) arguments); - return new JedisCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .pipeline((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .transaction((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .run(args); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.eval(digest, keysList, argumentsList), + (v)->v) + .run(args); + } } @Override - public Object evalSha(final byte[] digest, final byte[][] keys, final byte[][] arguments){ + public Object evalSha(final byte[] digest, final byte[][] keys, final byte[][] arguments) { final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) .put("arguments", (Object[]) arguments); - return new JedisCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .pipeline((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .transaction((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .run(args); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.eval(digest, keysList, argumentsList), + (v)->v) + .run(args); + } } @Override - public List scriptExists(final String... sha1){ + public List scriptExists(final String... sha1) { final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); - return new JedisCommand>(client, ProtocolCommand.SCRIPT_EXISTS) - .general((cmd)->cmd.scriptExists(sha1)) - .pipeline((cmd)->cmd.scriptExists(null, sha1)) - .transaction((cmd)->cmd.scriptExists(null, sha1)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(null, + sha1), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(null, + sha1), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), (v)->v) + .run(args); + } } @Override - public List scriptExists(final byte[]... sha1){ + public List scriptExists(final byte[]... sha1) { final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); - return new JedisCommand>(client, ProtocolCommand.SCRIPT_EXISTS) - .general((cmd)->cmd.scriptExists(sha1)) - .pipeline((cmd)->cmd.scriptExists(null, sha1)) - .transaction((cmd)->cmd.scriptExists(null, sha1)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(null, + sha1), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(null, + sha1), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), (v)->v) + .run(args); + } } @Override - public Status scriptFlush(){ - return new JedisCommand(client, ProtocolCommand.SCRIPT_FLUSH) - .general((cmd)->cmd.scriptFlush(), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.scriptFlush((String) null), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.scriptFlush((String) null), OkStatusConverter.INSTANCE) - .run(); + public Status scriptFlush() { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null), okStatusConverter) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), okStatusConverter) + .run(); + } } @Override - public Status scriptFlush(final FlushMode mode){ + public Status scriptFlush(final FlushMode mode) { final CommandArguments args = CommandArguments.create("mode", mode); - final redis.clients.jedis.args.FlushMode flushMode = FlushModeConverter.INSTANCE.convert(mode); - return new JedisCommand(client, ProtocolCommand.SCRIPT_FLUSH) - .general((cmd)->cmd.scriptFlush(flushMode), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.scriptFlush((String) null, flushMode), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.scriptFlush((String) null, flushMode), OkStatusConverter.INSTANCE) - .run(args); + final redis.clients.jedis.args.FlushMode flushMode = (new FlushModeConverter()).convert(mode); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null, flushMode), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null, flushMode), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(flushMode), + okStatusConverter) + .run(args); + } } @Override - public String scriptLoad(final String script){ + public String scriptLoad(final String script) { final CommandArguments args = CommandArguments.create("script", script); - return new JedisCommand(client, ProtocolCommand.SCRIPT_LOAD) - .general((cmd)->cmd.scriptLoad(script)) - .pipeline((cmd)->cmd.scriptLoad(script, null)) - .transaction((cmd)->cmd.scriptLoad(script, null)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), (v)->v) + .run(args); + } } @Override - public byte[] scriptLoad(final byte[] script){ + public byte[] scriptLoad(final byte[] script) { final CommandArguments args = CommandArguments.create("script", script); - return new JedisCommand(client, ProtocolCommand.SCRIPT_LOAD) - .general((cmd)->cmd.scriptLoad(script)) - .pipeline((cmd)->cmd.scriptLoad(script, null)) - .transaction((cmd)->cmd.scriptLoad(script, null)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), (v)->v) + .run(args); + } } @Override - public Status scriptKill(){ - return new JedisCommand(client, ProtocolCommand.SCRIPT_KILL) - .general((cmd)->cmd.scriptKill(), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.scriptKill((String) null), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.scriptKill((String) null), OkStatusConverter.INSTANCE) - .run(); + public Status scriptKill() { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SCRIPT_KILL, (cmd)->cmd.scriptKill((String) null), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SCRIPT_KILL, + (cmd)->cmd.scriptKill((String) null), + okStatusConverter) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SCRIPT_KILL, (cmd)->cmd.scriptKill(), okStatusConverter) + .run(); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelBitMapOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelBitMapOperations.java index 187d2c5a9..f4c3762dd 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelBitMapOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelBitMapOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -46,247 +46,398 @@ */ public final class JedisSentinelBitMapOperations extends AbstractBitMapOperations { - public JedisSentinelBitMapOperations(final JedisSentinelClient client){ + public JedisSentinelBitMapOperations(final JedisSentinelClient client) { super(client); } @Override - public Long bitCount(final String key){ + public Long bitCount(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key)) - .pipeline((cmd)->cmd.bitcount(key)) - .transaction((cmd)->cmd.bitcount(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } } @Override - - public Long bitCount(final byte[] key){ + public Long bitCount(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key)) - .pipeline((cmd)->cmd.bitcount(key)) - .transaction((cmd)->cmd.bitcount(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } } @Override - public Long bitCount(final String key, final long start, final long end){ + public Long bitCount(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key, start, end)) - .pipeline((cmd)->cmd.bitcount(key, start, end)) - .transaction((cmd)->cmd.bitcount(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + } } @Override - public Long bitCount(final byte[] key, final long start, final long end){ + public Long bitCount(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key, start, end)) - .pipeline((cmd)->cmd.bitcount(key, start, end)) - .transaction((cmd)->cmd.bitcount(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + } } @Override - public Long bitCount(final String key, final long start, final long end, final BitCountOption bitCountOption){ + public Long bitCount(final String key, final long start, final long end, final BitCountOption bitCountOption) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end) .put("bitCountOption", bitCountOption); - final redis.clients.jedis.args.BitCountOption option = BitCountOptionConverter.INSTANCE.convert( + final redis.clients.jedis.args.BitCountOption option = (new BitCountOptionConverter()).convert( bitCountOption); - return new JedisSentinelCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key, start, end, option)) - .pipeline((cmd)->cmd.bitcount(key, start, end, option)) - .transaction((cmd)->cmd.bitcount(key, start, end, option)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + } } @Override - public Long bitCount(final byte[] key, final long start, final long end, final BitCountOption bitCountOption){ + public Long bitCount(final byte[] key, final long start, final long end, final BitCountOption bitCountOption) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end) .put("bitCountOption", bitCountOption); - final redis.clients.jedis.args.BitCountOption option = BitCountOptionConverter.INSTANCE.convert( + final redis.clients.jedis.args.BitCountOption option = (new BitCountOptionConverter()).convert( bitCountOption); - return new JedisSentinelCommand(client, ProtocolCommand.BITCOUNT) - .general((cmd)->cmd.bitcount(key, start, end, option)) - .pipeline((cmd)->cmd.bitcount(key, start, end, option)) - .transaction((cmd)->cmd.bitcount(key, start, end, option)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end, option), (v)->v) + .run(args); + } } @Override - public List bitField(final String key, final BitFieldArgument argument){ + public List bitField(final String key, final BitFieldArgument argument) { final CommandArguments args = CommandArguments.create("key", key).put("arguments", argument); - final String[] arguments = BitFieldArgumentConverter.INSTANCE.convert(argument); - return new JedisSentinelCommand>(client, ProtocolCommand.BITFIELD) - .general((cmd)->cmd.bitfield(key, arguments)) - .pipeline((cmd)->cmd.bitfield(key, arguments)) - .transaction((cmd)->cmd.bitfield(key, arguments)) - .run(args); + final String[] arguments = (new BitFieldArgumentConverter()).convert(argument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITFIELD, + (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITFIELD, + (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + } } @Override - public List bitField(final byte[] key, final BitFieldArgument argument){ + public List bitField(final byte[] key, final BitFieldArgument argument) { final CommandArguments args = CommandArguments.create("key", key).put("arguments", argument); - final byte[][] arguments = SafeEncoder.encode(BitFieldArgumentConverter.INSTANCE.convert(argument)); - return new JedisSentinelCommand>(client, ProtocolCommand.BITFIELD) - .general((cmd)->cmd.bitfield(key, arguments)) - .pipeline((cmd)->cmd.bitfield(key, arguments)) - .transaction((cmd)->cmd.bitfield(key, arguments)) - .run(args); - } + final byte[][] arguments = SafeEncoder.encode((new BitFieldArgumentConverter()).convert(argument)); - @Deprecated - @Override - public List bitField(final String key, final String... arguments){ - final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); - return new JedisSentinelCommand>(client, ProtocolCommand.BITFIELD) - .general((cmd)->cmd.bitfield(key, arguments)) - .pipeline((cmd)->cmd.bitfield(key, arguments)) - .transaction((cmd)->cmd.bitfield(key, arguments)) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITFIELD, + (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITFIELD, + (cmd)->cmd.bitfield(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITFIELD, (cmd)->cmd.bitfield(key, arguments), + (v)->v) + .run(args); + } } - @Deprecated @Override - public List bitField(final byte[] key, final byte[]... arguments){ + public List bitFieldRo(final String key, final String... arguments) { final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); - return new JedisSentinelCommand>(client, ProtocolCommand.BITFIELD) - .general((cmd)->cmd.bitfield(key, arguments)) - .pipeline((cmd)->cmd.bitfield(key, arguments)) - .transaction((cmd)->cmd.bitfield(key, arguments)) - .run(args); - } - @Override - public List bitFieldRo(final String key, final String... arguments){ - final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); - return new JedisSentinelCommand>(client, ProtocolCommand.BITFIELD_RO) - .general((cmd)->cmd.bitfieldReadonly(key, arguments)) - .pipeline((cmd)->cmd.bitfieldReadonly(key, arguments)) - .transaction((cmd)->cmd.bitfieldReadonly(key, arguments)) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + } } @Override - public List bitFieldRo(final byte[] key, final byte[]... arguments){ + public List bitFieldRo(final byte[] key, final byte[]... arguments) { final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); - return new JedisSentinelCommand>(client, ProtocolCommand.BITFIELD_RO) - .general((cmd)->cmd.bitfieldReadonly(key, arguments)) - .pipeline((cmd)->cmd.bitfieldReadonly(key, arguments)) - .transaction((cmd)->cmd.bitfieldReadonly(key, arguments)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITFIELD_RO, + (cmd)->cmd.bitfieldReadonly(key, arguments), (v)->v) + .run(args); + } } @Override - public Long bitOp(final BitOperation operation, final String destKey, final String... keys){ + public Long bitOp(final BitOperation operation, final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("operation", operation).put("destKey", destKey) .put("keys", (Object[]) keys); - final BitOP bitOP = BitOperationConverter.INSTANCE.convert(operation); - return new JedisSentinelCommand(client, ProtocolCommand.BITOP) - .general((cmd)->cmd.bitop(bitOP, destKey, keys)) - .pipeline((cmd)->cmd.bitop(bitOP, destKey, keys)) - .transaction((cmd)->cmd.bitop(bitOP, destKey, keys)) - .run(args); + final BitOP bitOP = (new BitOperationConverter()).convert(operation); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITOP, + (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITOP, + (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys){ + public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("operation", operation).put("destKey", destKey) .put("keys", (Object[]) keys); - final BitOP bitOP = BitOperationConverter.INSTANCE.convert(operation); - return new JedisSentinelCommand(client, ProtocolCommand.BITOP) - .general((cmd)->cmd.bitop(bitOP, destKey, keys)) - .pipeline((cmd)->cmd.bitop(bitOP, destKey, keys)) - .transaction((cmd)->cmd.bitop(bitOP, destKey, keys)) - .run(args); + final BitOP bitOP = (new BitOperationConverter()).convert(operation); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITOP, + (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITOP, + (cmd)->cmd.bitop(bitOP, destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITOP, (cmd)->cmd.bitop(bitOP, destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long bitPos(final String key, final boolean value){ + public Long bitPos(final String key, final boolean value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.BITPOS) - .general((cmd)->cmd.bitpos(key, value)) - .pipeline((cmd)->cmd.bitpos(key, value)) - .transaction((cmd)->cmd.bitpos(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } } @Override - public Long bitPos(final byte[] key, final boolean value){ + public Long bitPos(final byte[] key, final boolean value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.BITPOS) - .general((cmd)->cmd.bitpos(key, value)) - .pipeline((cmd)->cmd.bitpos(key, value)) - .transaction((cmd)->cmd.bitpos(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } } @Override - public Long bitPos(final String key, final boolean value, final long start, final long end){ + public Long bitPos(final String key, final boolean value, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("start", start) .put("end", end); - final BitPosParams params = new BitPosParams(start, end); - return new JedisSentinelCommand(client, ProtocolCommand.BITPOS) - .general((cmd)->cmd.bitpos(key, value, params)) - .pipeline((cmd)->cmd.bitpos(key, value, params)) - .transaction((cmd)->cmd.bitpos(key, value, params)) - .run(args); + final BitPosParams bitPosParams = new BitPosParams(start, end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + } } @Override - public Long bitPos(final byte[] key, final boolean value, final long start, final long end){ + public Long bitPos(final byte[] key, final boolean value, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("start", start) .put("end", end); - final BitPosParams params = new BitPosParams(start, end); - return new JedisSentinelCommand(client, ProtocolCommand.BITPOS) - .general((cmd)->cmd.bitpos(key, value, params)) - .pipeline((cmd)->cmd.bitpos(key, value, params)) - .transaction((cmd)->cmd.bitpos(key, value, params)) - .run(args); + final BitPosParams bitPosParams = new BitPosParams(start, end); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, bitPosParams), (v)->v) + .run(args); + } } @Override - public Boolean getBit(final String key, final long offset){ + public Boolean getBit(final String key, final long offset) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset); - return new JedisSentinelCommand(client, ProtocolCommand.GETBIT) - .general((cmd)->cmd.getbit(key, offset)) - .pipeline((cmd)->cmd.getbit(key, offset)) - .transaction((cmd)->cmd.getbit(key, offset)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + } } @Override - public Boolean getBit(final byte[] key, final long offset){ + public Boolean getBit(final byte[] key, final long offset) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset); - return new JedisSentinelCommand(client, ProtocolCommand.GETBIT) - .general((cmd)->cmd.getbit(key, offset)) - .pipeline((cmd)->cmd.getbit(key, offset)) - .transaction((cmd)->cmd.getbit(key, offset)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), (v)->v) + .run(args); + } } @Override - public Boolean setBit(final String key, final long offset, final boolean value){ + public Boolean setBit(final String key, final long offset, final boolean value) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.SETBIT) - .general((cmd)->cmd.setbit(key, offset, value)) - .pipeline((cmd)->cmd.setbit(key, offset, value)) - .transaction((cmd)->cmd.setbit(key, offset, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SETBIT, + (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SETBIT, + (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + } } @Override - public Boolean setBit(final byte[] key, final long offset, final boolean value){ + public Boolean setBit(final byte[] key, final long offset, final boolean value) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.SETBIT) - .general((cmd)->cmd.setbit(key, offset, value)) - .pipeline((cmd)->cmd.setbit(key, offset, value)) - .transaction((cmd)->cmd.setbit(key, offset, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SETBIT, + (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SETBIT, + (cmd)->cmd.setbit(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SETBIT, (cmd)->cmd.setbit(key, offset, value), + (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelClusterOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelClusterOperations.java index f0cd858a1..e7d7f3608 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelClusterOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelClusterOperations.java @@ -19,11 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.core.converter.ListConverter; import com.buession.lang.KeyValue; import com.buession.lang.Status; import com.buession.redis.client.jedis.JedisSentinelClient; @@ -44,7 +45,7 @@ import com.buession.redis.core.internal.convert.jedis.response.ClusterResetOptionConverter; import com.buession.redis.core.internal.convert.response.ClusterNodeConverter; import com.buession.redis.core.internal.convert.response.ClusterSlotConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import redis.clients.jedis.args.ClusterResetType; import java.util.List; @@ -56,221 +57,452 @@ */ public final class JedisSentinelClusterOperations extends AbstractClusterOperations { - public JedisSentinelClusterOperations(final JedisSentinelClient client){ + public JedisSentinelClusterOperations(final JedisSentinelClient client) { super(client); } @Override - public String clusterMyId(){ - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_MY_ID) - .general((cmd)->cmd.clusterMyId()) - .run(); + public String clusterMyId() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_MY_ID) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_MY_ID) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_MY_ID, (cmd)->cmd.clusterMyId(), (v)->v) + .run(); + } } @Override - public Status clusterAddSlots(final int... slots){ + public Status clusterAddSlots(final int... slots) { final CommandArguments args = CommandArguments.create("slots", slots); - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_ADDSLOTS) - .general((cmd)->cmd.clusterAddSlots(slots), OkStatusConverter.INSTANCE) - .run(args); - } - @Override - public List clusterSlots(){ - return new JedisSentinelCommand>(client, ProtocolCommand.CLUSTER_SLOTS) - .general((cmd)->cmd.clusterSlots(), ClusterSlotConverter.LIST_CONVERTER) - .run(); + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_ADDSLOTS) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_ADDSLOTS) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_ADDSLOTS, + (cmd)->cmd.clusterAddSlots(slots), okStatusConverter) + .run(args); + } } @Override - public Integer clusterCountFailureReports(final String nodeId){ - final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) - .run(args); + public List clusterSlots() { + final ListConverter listClusterSlotConverter = ClusterSlotConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_SLOTS) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_SLOTS) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_SLOTS, (cmd)->cmd.clusterSlots(), + listClusterSlotConverter) + .run(); + } } @Override - public Integer clusterCountFailureReports(final byte[] nodeId){ + public Integer clusterCountFailureReports(final String nodeId) { final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, + ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, + ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS, + (cmd)->cmd.clusterCountFailureReports(nodeId), Long::intValue) + .run(args); + } } @Override - public Long clusterCountKeysInSlot(final int slot){ - final CommandArguments args = CommandArguments.create("slot", slot); - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT) - .general((cmd)->cmd.clusterCountKeysInSlot(slot)) - .run(args); + public Long clusterCountKeysInSlot(final int slot) { + final CommandArguments args = CommandArguments.create(slot); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + } } @Override - public Status clusterDelSlots(final int... slots){ - final CommandArguments args = CommandArguments.create("slots", slots); - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_DELSLOTS) - .general((cmd)->cmd.clusterDelSlots(slots), OkStatusConverter.INSTANCE) - .run(args); + public Status clusterDelSlots(final int... slots) { + final CommandArguments args = CommandArguments.create(slots); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_DELSLOTS) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_DELSLOTS) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_DELSLOTS, + (cmd)->cmd.clusterDelSlots(slots), okStatusConverter) + .run(args); + } } @Override - public Status clusterFlushSlots(){ - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_FLUSHSLOTS) - .general((cmd)->cmd.clusterFlushSlots(), OkStatusConverter.INSTANCE) - .run(); + public Status clusterFlushSlots() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_FLUSHSLOTS) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_FLUSHSLOTS) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_FLUSHSLOTS, + (cmd)->cmd.clusterFlushSlots(), okStatusConverter) + .run(); + } } @Override - public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption){ + public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption) { final CommandArguments args = CommandArguments.create("clusterFailoverOption", clusterFailoverOption); - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_FAILOVER) - .general((cmd)->cmd.clusterFailover( - ClusterFailoverOptionConverter.INSTANCE.convert(clusterFailoverOption)), - OkStatusConverter.INSTANCE) - .run(args); + final redis.clients.jedis.args.ClusterFailoverOption failoverOption = + (new ClusterFailoverOptionConverter()).convert(clusterFailoverOption); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_FAILOVER) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_FAILOVER) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_FAILOVER, + (cmd)->cmd.clusterFailover(failoverOption), okStatusConverter) + .run(args); + } } @Override - public Status clusterForget(final String nodeId){ + public Status clusterForget(final String nodeId) { final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_FORGET) - .general((cmd)->cmd.clusterForget(nodeId), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_FORGET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_FORGET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_FORGET, (cmd)->cmd.clusterForget(nodeId), + okStatusConverter) + .run(args); + } } @Override - public List clusterGetKeysInSlot(final int slot, final long count){ + public List clusterGetKeysInSlot(final int slot, final long count) { final CommandArguments args = CommandArguments.create("slot", slot).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) - .general((cmd)->cmd.clusterGetKeysInSlot(slot, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, (int) count), (v)->v) + .run(args); + } } @Override - public Long clusterKeySlot(final String key){ + public Long clusterKeySlot(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) - .general((cmd)->cmd.clusterKeySlot(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterKeySlot(key), (v)->v) + .run(args); + } } @Override - public ClusterInfo clusterInfo(){ - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_INFO) - .general((cmd)->cmd.clusterInfo(), ClusterInfoConverter.INSTANCE) - .run(); + public ClusterInfo clusterInfo() { + final ClusterInfoConverter clusterInfoConverter = new ClusterInfoConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_INFO) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_INFO) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_INFO, (cmd)->cmd.clusterInfo(), + clusterInfoConverter) + .run(); + } } @Override - public Status clusterMeet(final String ip, final int port){ + public Status clusterMeet(final String ip, final int port) { final CommandArguments args = CommandArguments.create("ip", ip).put("port", port); - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_MEET) - .general((cmd)->cmd.clusterMeet(ip, port), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_MEET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_MEET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_MEET, (cmd)->cmd.clusterMeet(ip, port), + okStatusConverter) + .run(args); + } } @Override - public List clusterNodes(){ - return new JedisSentinelCommand>(client, ProtocolCommand.CLUSTER_NODES) - .general((cmd)->cmd.clusterNodes(), ClusterNodesConverter.INSTANCE) - .run(); + public List clusterNodes() { + final ClusterNodesConverter clusterNodesConverter = new ClusterNodesConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_NODES) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_NODES) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_NODES, (cmd)->cmd.clusterNodes(), + clusterNodesConverter) + .run(); + } } @Override - public List clusterSlaves(final String nodeId){ + public List clusterSlaves(final String nodeId) { final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisSentinelCommand>(client, ProtocolCommand.CLUSTER_SLAVES) - .general((cmd)->cmd.clusterSlaves(nodeId), ClusterNodeConverter.LIST_CONVERTER) - .run(args); + final ListConverter listClusterNodeConverter = ClusterNodeConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_SLAVES) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_SLAVES) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_SLAVES, (cmd)->cmd.clusterSlaves(nodeId), + listClusterNodeConverter) + .run(args); + } } @Override - public List clusterReplicas(final String nodeId){ + public List clusterReplicas(final String nodeId) { final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisSentinelCommand>(client, ProtocolCommand.CLUSTER_REPLICAS) - .general((cmd)->cmd.clusterReplicas(nodeId), ClusterReplicasConverter.LIST_CONVERTER) - .run(args); + final ListConverter listClusterReplicasConverter = ClusterReplicasConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_REPLICAS) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_REPLICAS) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_REPLICAS, + (cmd)->cmd.clusterReplicas(nodeId), listClusterReplicasConverter) + .run(args); + } } @Override - public Status clusterReplicate(final String nodeId){ + public Status clusterReplicate(final String nodeId) { final CommandArguments args = CommandArguments.create("nodeId", nodeId); - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_REPLICATE) - .general((cmd)->cmd.clusterReplicate(nodeId), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_REPLICATE) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_REPLICATE) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_REPLICATE, + (cmd)->cmd.clusterReplicate(nodeId), okStatusConverter) + .run(args); + } } @Override - public Status clusterReset(final ClusterResetOption clusterResetOption){ + public Status clusterReset(final ClusterResetOption clusterResetOption) { final CommandArguments args = CommandArguments.create("clusterResetOption", clusterResetOption); - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_RESET) - .general((cmd)->cmd.clusterReset(ClusterResetOptionConverter.INSTANCE.convert(clusterResetOption)), - OkStatusConverter.INSTANCE) - .run(args); + final ClusterResetType clusterResetType = (new ClusterResetOptionConverter()).convert(clusterResetOption); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_RESET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_RESET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_RESET, + (cmd)->cmd.clusterReset(clusterResetType), okStatusConverter) + .run(args); + } } @Override - public Status clusterSaveConfig(){ - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_SAVECONFIG) - .general((cmd)->cmd.clusterSaveConfig(), OkStatusConverter.INSTANCE) - .run(); + public Status clusterSaveConfig() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_SAVECONFIG) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_SAVECONFIG) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_SAVECONFIG, + (cmd)->cmd.clusterSaveConfig(), okStatusConverter) + .run(); + } } @Override - public Status clusterSetConfigEpoch(final long configEpoch){ + public Status clusterSetConfigEpoch(final long configEpoch) { final CommandArguments args = CommandArguments.create("configEpoch", configEpoch); - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH) - .general((cmd)->cmd.clusterSetConfigEpoch(configEpoch), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + } } @Override - public KeyValue clusterBumpEpoch(){ - return new JedisSentinelCommand>(client, ProtocolCommand.CLUSTER_BUMPEPOCH) - .general((cmd)->cmd.clusterBumpEpoch(), BumpEpochConverter.INSTANCE) - .run(); + public KeyValue clusterBumpEpoch() { + final BumpEpochConverter bumpEpochConverter = new BumpEpochConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, KeyValue>(client, + ProtocolCommand.CLUSTER_BUMPEPOCH) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, KeyValue>( + client, + ProtocolCommand.CLUSTER_BUMPEPOCH) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_BUMPEPOCH, (cmd)->cmd.clusterBumpEpoch(), + bumpEpochConverter) + .run(); + } } @Override - public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId){ + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId) { final CommandArguments args = CommandArguments.create("slot", slot).put("setSlotOption", setSlotOption) .put("nodeId", nodeId); - return new JedisSentinelCommand(client, ProtocolCommand.CLUSTER_SETSLOT) - .general((cmd)->{ - switch(setSlotOption){ - case IMPORTING: - return cmd.clusterSetSlotImporting(slot, nodeId); - case MIGRATING: - return cmd.clusterSetSlotMigrating(slot, nodeId); - case STABLE: - return cmd.clusterSetSlotStable(slot); - case NODE: - return cmd.clusterSetSlotNode(slot, nodeId); - default: - return null; - } - }, OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_SETSLOT) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_SETSLOT) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + } } @Override - public Status asking(){ - return new JedisSentinelCommand(client, ProtocolCommand.ASKING) - .general((cmd)->cmd.asking(), OkStatusConverter.INSTANCE) - .run(); + public Status asking() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.ASKING) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.ASKING) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ASKING, (cmd)->cmd.asking(), okStatusConverter) + .run(); + } } @Override - public Status readWrite(){ - return new JedisSentinelCommand(client, ProtocolCommand.ASKING) - .general((cmd)->cmd.readwrite(), OkStatusConverter.INSTANCE) - .run(); + public Status readWrite() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.READWRITE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.READWRITE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.READWRITE, (cmd)->cmd.readwrite(), + okStatusConverter) + .run(); + } } @Override - public Status readOnly(){ - return new JedisSentinelCommand(client, ProtocolCommand.ASKING) - .general((cmd)->cmd.readonly(), OkStatusConverter.INSTANCE) - .run(); + public Status readOnly() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.READONLY) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.READONLY) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.READONLY, (cmd)->cmd.readonly(), + okStatusConverter) + .run(); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelConnectionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelConnectionOperations.java index 5defe80ee..15ea79806 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelConnectionOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelConnectionOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -32,12 +32,11 @@ import com.buession.redis.core.ClientUnblockType; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; import com.buession.redis.core.internal.convert.jedis.params.ClientTypeConverter; import com.buession.redis.core.internal.convert.jedis.params.ClientUnblockTypeConverter; import com.buession.redis.core.internal.convert.response.ClientConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; import com.buession.redis.core.internal.convert.response.PingResultConverter; +import redis.clients.jedis.args.UnblockType; import java.util.List; @@ -49,175 +48,368 @@ */ public final class JedisSentinelConnectionOperations extends AbstractConnectionOperations { - public JedisSentinelConnectionOperations(final JedisSentinelClient client){ + public JedisSentinelConnectionOperations(final JedisSentinelClient client) { super(client); } @Override - public Status auth(final String user, final String password){ + public Status auth(final String user, final String password) { final CommandArguments args = CommandArguments.create("user", user).put("password", password); - return new JedisSentinelCommand(client, ProtocolCommand.AUTH) - .general((cmd)->cmd.auth(user, password), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.AUTH) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.AUTH) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.AUTH, (cmd)->cmd.auth(user, password), + okStatusConverter) + .run(args); + } } @Override - public Status auth(final String password){ + public Status auth(final String password) { final CommandArguments args = CommandArguments.create("password", password); - return new JedisSentinelCommand(client, ProtocolCommand.AUTH) - .general((cmd)->cmd.auth(password), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.AUTH) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.AUTH) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.AUTH, (cmd)->cmd.auth(password), + okStatusConverter) + .run(args); + } } @Override - public String echo(final String str){ + public String echo(final String str) { final CommandArguments args = CommandArguments.create("str", str); - return new JedisSentinelCommand(client, ProtocolCommand.ECHO) - .general((cmd)->cmd.echo(str)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.ECHO) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.ECHO) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.echo(str), (v)->v) + .run(args); + } } @Override - public byte[] echo(final byte[] str){ + public byte[] echo(final byte[] str) { final CommandArguments args = CommandArguments.create("str", str); - return new JedisSentinelCommand(client, ProtocolCommand.ECHO) - .general((cmd)->cmd.echo(str)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.ECHO) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.ECHO) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.echo(str), (v)->v) + .run(args); + } } @Override - public Status ping(){ - return new JedisSentinelCommand(client, ProtocolCommand.PING) - .general((cmd)->cmd.ping(), PingResultConverter.INSTANCE) - .run(); + public Status ping() { + final PingResultConverter pingResultConverter = new PingResultConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.PING) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.PING) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PING, (cmd)->cmd.ping(), pingResultConverter) + .run(); + } } @Override - public Status reset(){ - return new JedisSentinelCommand(client, ProtocolCommand.RESET) - .run(); + public Status reset() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.RESET) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.RESET) + .run(); + }else{ + return new JedisSentinelCommand(client, ProtocolCommand.RESET) + .run(); + } } @Override - public Status quit(){ - return new JedisSentinelCommand(client, ProtocolCommand.QUIT) - .general((cmd)->cmd.quit(), OkStatusConverter.INSTANCE) - .run(); + public Status quit() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.QUIT) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.QUIT) + .run(); + }else{ + return new JedisSentinelCommand(client, ProtocolCommand.QUIT) + .run(); + } } @Override - public Status select(final int db){ + public Status select(final int db) { final CommandArguments args = CommandArguments.create("db", db); - return new JedisSentinelCommand(client, ProtocolCommand.SELECT) - .general((cmd)->cmd.select(db), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.select(db), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SELECT, (cmd)->cmd.select(db), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.SELECT) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SELECT, (cmd)->cmd.select(db), okStatusConverter) + .run(args); + } } @Override - public Status clientCaching(final boolean isYes){ + public Status clientCaching(final boolean isYes) { final CommandArguments args = CommandArguments.create("isYes", isYes); - return new JedisSentinelCommand(client, ProtocolCommand.CLIENT_CACHING) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + }else{ + return new JedisSentinelCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + } } @Override - public Long clientId(){ - return new JedisSentinelCommand(client, ProtocolCommand.CLIENT_ID) - .general((cmd)->cmd.clientId()) - .run(); + public Long clientId() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLIENT_ID) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLIENT_ID) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLIENT_ID, (cmd)->cmd.clientId(), (v)->v) + .run(); + } } @Override - public Status clientSetName(final String name){ + public Status clientSetName(final String name) { final CommandArguments args = CommandArguments.create("name", name); - return new JedisSentinelCommand(client, ProtocolCommand.CLIENT_SETNAME) - .general((cmd)->cmd.clientSetname(name), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLIENT_SETNAME) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLIENT_SETNAME) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + } } @Override - public Status clientSetName(final byte[] name){ + public Status clientSetName(final byte[] name) { final CommandArguments args = CommandArguments.create("name", name); - return new JedisSentinelCommand(client, ProtocolCommand.CLIENT_SETNAME) - .general((cmd)->cmd.clientSetname(name), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLIENT_SETNAME) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLIENT_SETNAME) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + } } @Override - public String clientGetName(){ - return new JedisSentinelCommand(client, ProtocolCommand.CLIENT_GETNAME) - .general((cmd)->cmd.clientGetname()) - .run(); + public String clientGetName() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLIENT_GETNAME) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLIENT_GETNAME) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLIENT_GETNAME, (cmd)->cmd.clientGetname(), + (v)->v) + .run(); + } } @Override - public Integer clientGetRedir(){ - return new JedisSentinelCommand(client, ProtocolCommand.CLIENT_GETREDIR) - .run(); + public Integer clientGetRedir() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + }else{ + return new JedisSentinelCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + } } @Override - public List clientList(){ - return new JedisSentinelCommand>(client, ProtocolCommand.CLIENT_LIST) - .general((cmd)->cmd.clientList(), ClientConverter.ClientListConverter.INSTANCE) - .run(); + public List clientList() { + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, ProtocolCommand.CLIENT_LIST) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, ProtocolCommand.CLIENT_LIST) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + } } @Override - public List clientList(final ClientType clientType){ + public List clientList(final ClientType clientType) { final CommandArguments args = CommandArguments.create("clientType", clientType); - return new JedisSentinelCommand>(client, ProtocolCommand.CLIENT_LIST) - .general((cmd)->cmd.clientList(ClientTypeConverter.INSTANCE.convert(clientType)), - ClientConverter.ClientListConverter.INSTANCE) - .run(args); + final redis.clients.jedis.args.ClientType jClientType = (new ClientTypeConverter()).convert(clientType); + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, ProtocolCommand.CLIENT_LIST) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, ProtocolCommand.CLIENT_LIST) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(jClientType), + clientListConverter) + .run(args); + } } @Override - public Client clientInfo(){ - return new JedisSentinelCommand(client, ProtocolCommand.CLIENT_INFO) - .general((cmd)->cmd.clientInfo(), ClientConverter.INSTANCE) - .run(); + public Client clientInfo() { + final ClientConverter clientConverter = new ClientConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLIENT_LIST) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLIENT_LIST) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientInfo(), + clientConverter) + .run(); + } } @Override - public Status clientPause(final int timeout){ + public Status clientPause(final int timeout) { final CommandArguments args = CommandArguments.create("timeout", timeout); - return new JedisSentinelCommand(client, ProtocolCommand.CLIENT_PAUSE) - .general((cmd)->cmd.clientPause(timeout), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLIENT_PAUSE) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLIENT_PAUSE) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLIENT_PAUSE, (cmd)->cmd.clientInfo(), + okStatusConverter) + .run(args); + } } @Override - public Status clientReply(final ClientReply option){ + public Status clientReply(final ClientReply option) { final CommandArguments args = CommandArguments.create("option", option); - return new JedisSentinelCommand(client, ProtocolCommand.CLIENT_REPLY) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + }else{ + return new JedisSentinelCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + } } @Override - public Status clientKill(final String host, final int port){ + public Status clientKill(final String host, final int port) { final CommandArguments args = CommandArguments.create("host", host).put("port", port); - return new JedisSentinelCommand(client, ProtocolCommand.CLIENT_PAUSE) - .general((cmd)->cmd.clientKill(host + ":" + port), OkStatusConverter.INSTANCE) - .run(args); + final String addr = host + ':' + port; + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLIENT_KILL) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLIENT_KILL) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLIENT_KILL, (cmd)->cmd.clientKill(addr), + okStatusConverter) + .run(args); + } } @Override - public Status clientUnblock(final int clientId){ + public Status clientUnblock(final int clientId) { final CommandArguments args = CommandArguments.create("clientId", clientId); - return new JedisSentinelCommand(client, ProtocolCommand.CLIENT_UNBLOCK) - .general((cmd)->cmd.clientUnblock(clientId, null), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLIENT_UNBLOCK) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLIENT_UNBLOCK) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLIENT_UNBLOCK, + (cmd)->cmd.clientUnblock(clientId), + oneStatusConverter) + .run(args); + } } @Override - public Status clientUnblock(final int clientId, final ClientUnblockType type){ + public Status clientUnblock(final int clientId, final ClientUnblockType type) { final CommandArguments args = CommandArguments.create("clientId", clientId).put("type", type); - return new JedisSentinelCommand(client, ProtocolCommand.CLIENT_UNBLOCK) - .general((cmd)->cmd.clientUnblock(clientId, ClientUnblockTypeConverter.INSTANCE.convert(type)), - Converters.ONE_STATUS_CONVERTER) - .run(args); + final UnblockType unblockType = (new ClientUnblockTypeConverter()).convert(type); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CLIENT_UNBLOCK) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CLIENT_UNBLOCK) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CLIENT_UNBLOCK, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelGenericOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelGenericOperations.java new file mode 100644 index 000000000..b182c1b57 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelGenericOperations.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.jedis.operations; + +import com.buession.lang.KeyValue; +import com.buession.redis.client.jedis.JedisSentinelClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.jedis.response.KeyValueConverter; + +/** + * Jedis 哨兵模式一般命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisSentinelGenericOperations extends AbstractGenericOperations { + + public JedisSentinelGenericOperations(final JedisSentinelClient client) { + super(client); + } + + @Override + public Long wait(final int replicas, final int timeout) { + final CommandArguments args = CommandArguments.create(replicas).add(timeout); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.WAIT, + (cmd)->cmd.waitReplicas(replicas, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.WAIT, + (cmd)->cmd.waitReplicas(replicas, timeout), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.WAIT, (cmd)->cmd.waitReplicas(replicas, timeout), + (v)->v) + .run(args); + } + } + + @Override + public KeyValue waitOf(final int locals, final int replicas, final int timeout) { + final CommandArguments args = CommandArguments.create(locals).add(replicas).add(timeout); + final KeyValueConverter keyValueConverter = new KeyValueConverter<>((k)->k, (v)->v); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.WAITOF, + (cmd)->cmd.waitAOF((String) null, locals, replicas, timeout), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.WAITOF, + (cmd)->cmd.waitAOF((String) null, locals, replicas, timeout), keyValueConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.WAITOF, + (cmd)->cmd.waitAOF(locals, replicas, timeout), keyValueConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelGeoOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelGeoOperations.java index edf8cb136..9d023bc7e 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelGeoOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelGeoOperations.java @@ -19,11 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.core.converter.ListConverter; import com.buession.lang.Geo; import com.buession.redis.client.jedis.JedisSentinelClient; import com.buession.redis.core.GeoRadius; @@ -31,12 +32,13 @@ import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; import com.buession.redis.core.internal.convert.jedis.params.GeoConverter; -import com.buession.redis.core.internal.convert.jedis.params.GeoRadiusArgumentConverter; import com.buession.redis.core.internal.convert.jedis.params.GeoUnitConverter; import com.buession.redis.core.internal.convert.jedis.response.GeoCoordinateConverter; import com.buession.redis.core.internal.convert.jedis.response.GeoRadiusResponseConverter; +import com.buession.redis.core.internal.jedis.JedisGeoRadiusParam; import redis.clients.jedis.GeoCoordinate; import redis.clients.jedis.params.GeoRadiusParam; +import redis.clients.jedis.resps.GeoRadiusResponse; import java.util.List; import java.util.Map; @@ -49,410 +51,678 @@ */ public final class JedisSentinelGeoOperations extends AbstractGeoOperations { - public JedisSentinelGeoOperations(final JedisSentinelClient client){ + public JedisSentinelGeoOperations(final JedisSentinelClient client) { super(client); } @Override - public Long geoAdd(final String key, final String member, final double longitude, final double latitude){ + public Long geoAdd(final String key, final String member, final double longitude, final double latitude) { final CommandArguments args = CommandArguments.create("key", key).put("member", member) .put("longitude", longitude).put("latitude", latitude); - return new JedisSentinelCommand(client, ProtocolCommand.GEOADD) - .general((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .pipeline((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .transaction((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + } } @Override - public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude){ + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude) { final CommandArguments args = CommandArguments.create("key", key).put("member", member) .put("longitude", longitude).put("latitude", latitude); - return new JedisSentinelCommand(client, ProtocolCommand.GEOADD) - .general((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .pipeline((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .transaction((cmd)->cmd.geoadd(key, longitude, latitude, member)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + } } @Override - public Long geoAdd(final String key, final Map memberCoordinates){ + public Long geoAdd(final String key, final Map memberCoordinates) { final CommandArguments args = CommandArguments.create("key", key).put("memberCoordinates", memberCoordinates); - final Map geoCoordinates = GeoConverter.STRING_MAP_CONVERTER.convert(memberCoordinates); - return new JedisSentinelCommand(client, ProtocolCommand.GEOADD) - .general((cmd)->cmd.geoadd(key, geoCoordinates)) - .pipeline((cmd)->cmd.geoadd(key, geoCoordinates)) - .transaction((cmd)->cmd.geoadd(key, geoCoordinates)) - .run(args); + final Map geoCoordinates = GeoConverter.mapConverter().convert( + memberCoordinates); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, geoCoordinates), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, geoCoordinates), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + } } @Override - public Long geoAdd(final byte[] key, final Map memberCoordinates){ + public Long geoAdd(final byte[] key, final Map memberCoordinates) { final CommandArguments args = CommandArguments.create("key", key).put("memberCoordinates", memberCoordinates); - final Map geoCoordinates = GeoConverter.BINARY_MAP_CONVERTER.convert(memberCoordinates); - return new JedisSentinelCommand(client, ProtocolCommand.GEOADD) - .general((cmd)->cmd.geoadd(key, geoCoordinates)) - .pipeline((cmd)->cmd.geoadd(key, geoCoordinates)) - .transaction((cmd)->cmd.geoadd(key, geoCoordinates)) - .run(args); + final Map geoCoordinates = GeoConverter.mapConverter() + .convert(memberCoordinates); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, geoCoordinates), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, geoCoordinates), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, geoCoordinates), + (v)->v) + .run(args); + } } @Override - public List geoHash(final String key, final String... members){ + public List geoHash(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisSentinelCommand>(client, ProtocolCommand.GEOHASH) - .general((cmd)->cmd.geohash(key, members)) - .pipeline((cmd)->cmd.geohash(key, members)) - .transaction((cmd)->cmd.geohash(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEOHASH, + (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + } } @Override - public List geoHash(final byte[] key, final byte[]... members){ + public List geoHash(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisSentinelCommand>(client, ProtocolCommand.GEOHASH) - .general((cmd)->cmd.geohash(key, members)) - .pipeline((cmd)->cmd.geohash(key, members)) - .transaction((cmd)->cmd.geohash(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEOHASH, + (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), (v)->v) + .run(args); + } } @Override - public List geoPos(final String key, final String... members){ + public List geoPos(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisSentinelCommand>(client, ProtocolCommand.GEOPOS) - .general((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .run(args); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEOPOS, + (cmd)->cmd.geopos(key, members), listGeoCoordinateConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } } @Override - public List geoPos(final byte[] key, final byte[]... members){ + public List geoPos(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisSentinelCommand>(client, ProtocolCommand.GEOPOS) - .general((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.geopos(key, members), GeoCoordinateConverter.LIST_CONVERTER) - .run(args); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEOPOS, + (cmd)->cmd.geopos(key, members), listGeoCoordinateConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } } @Override - public Double geoDist(final String key, final String member1, final String member2){ + public Double geoDist(final String key, final String member1, final String member2) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2); - return new JedisSentinelCommand(client, ProtocolCommand.GEODIST) - .general((cmd)->cmd.geodist(key, member1, member2)) - .pipeline((cmd)->cmd.geodist(key, member1, member2)) - .transaction((cmd)->cmd.geodist(key, member1, member2)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + } } @Override - public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2){ + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2); - return new JedisSentinelCommand(client, ProtocolCommand.GEODIST) - .general((cmd)->cmd.geodist(key, member1, member2)) - .pipeline((cmd)->cmd.geodist(key, member1, member2)) - .transaction((cmd)->cmd.geodist(key, member1, member2)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2), (v)->v) + .run(args); + } } @Override - public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit){ + public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisSentinelCommand(client, ProtocolCommand.GEODIST) - .general((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .pipeline((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .transaction((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + } } @Override - public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit){ + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) .put("member2", member2).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisSentinelCommand(client, ProtocolCommand.GEODIST) - .general((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .pipeline((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .transaction((cmd)->cmd.geodist(key, member1, member2, geoUnit)) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, geoUnit), (v)->v) + .run(args); + } } @Override public List geoRadius(final String key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUS) - .general((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadius(final byte[] key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUS) - .general((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadius(final String key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUS) - .general((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadius(final byte[] key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUS) - .general((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusRo(final String key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUS_RO) - .general((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, - final double radius, final GeoUnit unit){ + final double radius, final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUS_RO) - .general((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusRo(final String key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUS_RO) - .general((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, final double radius, final GeoUnit unit, - final GeoRadiusArgument geoRadiusArgument){ + final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) .put("latitude", latitude).put("radius", radius).put("unit", unit) .put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUS_RO) - .general((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUS_RO, + (cmd)->cmd.georadiusReadonly(key, longitude, latitude, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMember(final String key, final String member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMember(final String key, final String member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusByMember(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMemberRo(final String key, final String member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit){ + final GeoUnit unit) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit), listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMemberRo(final String key, final String member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } @Override public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, - final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument){ + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); - final redis.clients.jedis.args.GeoUnit geoUnit = GeoUnitConverter.INSTANCE.convert(unit); - final GeoRadiusParam param = GeoRadiusArgumentConverter.INSTANCE.convert(geoRadiusArgument); - return new JedisSentinelCommand>(client, ProtocolCommand.GEORADIUSBYMEMBER) - .general((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, param), - GeoRadiusResponseConverter.LIST_CONVERTER) - .run(args); + final redis.clients.jedis.args.GeoUnit geoUnit = (new GeoUnitConverter()).convert(unit); + final GeoRadiusParam geoRadiusParam = JedisGeoRadiusParam.from(geoRadiusArgument); + final ListConverter listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO, + (cmd)->cmd.georadiusByMemberReadonly(key, member, radius, geoUnit, geoRadiusParam), + listGeoRadiusResponseConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelHashOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelHashOperations.java index e8a8a7e09..e71895be5 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelHashOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelHashOperations.java @@ -19,20 +19,20 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.core.converter.ListMapEntryMapConverter; import com.buession.lang.Status; import com.buession.redis.client.jedis.JedisSentinelClient; import com.buession.redis.core.ScanResult; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; import com.buession.redis.core.internal.jedis.JedisScanParams; +import redis.clients.jedis.params.ScanParams; import java.util.List; import java.util.Map; @@ -46,459 +46,753 @@ */ public final class JedisSentinelHashOperations extends AbstractHashOperations { - public JedisSentinelHashOperations(final JedisSentinelClient client){ + public JedisSentinelHashOperations(final JedisSentinelClient client) { super(client); } @Override - public Long hDel(final String key, final String... fields){ + public Long hDel(final String key, final String... fields) { final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); - return new JedisSentinelCommand(client, ProtocolCommand.HDEL) - .general((cmd)->cmd.hdel(key, fields)) - .pipeline((cmd)->cmd.hdel(key, fields)) - .transaction((cmd)->cmd.hdel(key, fields)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } } @Override - public Long hDel(final byte[] key, final byte[]... fields){ + public Long hDel(final byte[] key, final byte[]... fields) { final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); - return new JedisSentinelCommand(client, ProtocolCommand.HDEL) - .general((cmd)->cmd.hdel(key, fields)) - .pipeline((cmd)->cmd.hdel(key, fields)) - .transaction((cmd)->cmd.hdel(key, fields)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } } @Override - public Boolean hExists(final String key, final String field){ + public Boolean hExists(final String key, final String field) { final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisSentinelCommand(client, ProtocolCommand.HEXISTS) - .general((cmd)->cmd.hexists(key, field)) - .pipeline((cmd)->cmd.hexists(key, field)) - .transaction((cmd)->cmd.hexists(key, field)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HEXISTS, + (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } } @Override - public Boolean hExists(final byte[] key, final byte[] field){ + public Boolean hExists(final byte[] key, final byte[] field) { final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisSentinelCommand(client, ProtocolCommand.HEXISTS) - .general((cmd)->cmd.hexists(key, field)) - .pipeline((cmd)->cmd.hexists(key, field)) - .transaction((cmd)->cmd.hexists(key, field)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HEXISTS, + (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } } @Override - public String hGet(final String key, final String field){ + public String hGet(final String key, final String field) { final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisSentinelCommand(client, ProtocolCommand.HGET) - .general((cmd)->cmd.hget(key, field)) - .pipeline((cmd)->cmd.hget(key, field)) - .transaction((cmd)->cmd.hget(key, field)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + } } @Override - public byte[] hGet(final byte[] key, final byte[] field){ + public byte[] hGet(final byte[] key, final byte[] field) { final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisSentinelCommand(client, ProtocolCommand.HGET) - .general((cmd)->cmd.hget(key, field)) - .pipeline((cmd)->cmd.hget(key, field)) - .transaction((cmd)->cmd.hget(key, field)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), (v)->v) + .run(args); + } } @Override - public Map hGetAll(final String key){ + public Map hGetAll(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand>(client, ProtocolCommand.HGETALL) - .general((cmd)->cmd.hgetAll(key)) - .pipeline((cmd)->cmd.hgetAll(key)) - .transaction((cmd)->cmd.hgetAll(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + } } @Override - public Map hGetAll(final byte[] key){ + public Map hGetAll(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand>(client, ProtocolCommand.HGETALL) - .general((cmd)->cmd.hgetAll(key)) - .pipeline((cmd)->cmd.hgetAll(key)) - .transaction((cmd)->cmd.hgetAll(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetAll(key), (v)->v) + .run(args); + } } @Override - public Long hIncrBy(final String key, final String field, final long value){ + public Long hIncrBy(final String key, final String field, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.HINCRBY) - .general((cmd)->cmd.hincrBy(key, field, value)) - .pipeline((cmd)->cmd.hincrBy(key, field, value)) - .transaction((cmd)->cmd.hincrBy(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HINCRBY, + (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HINCRBY, + (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + } } @Override - public Long hIncrBy(final byte[] key, final byte[] field, final long value){ + public Long hIncrBy(final byte[] key, final byte[] field, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.HINCRBY) - .general((cmd)->cmd.hincrBy(key, field, value)) - .pipeline((cmd)->cmd.hincrBy(key, field, value)) - .transaction((cmd)->cmd.hincrBy(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HINCRBY, + (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HINCRBY, + (cmd)->cmd.hincrBy(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HINCRBY, (cmd)->cmd.hincrBy(key, field, value), + (v)->v) + .run(args); + } } @Override - public Double hIncrByFloat(final String key, final String field, final double value){ + public Double hIncrByFloat(final String key, final String field, final double value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.HINCRBYFLOAT) - .general((cmd)->cmd.hincrByFloat(key, field, value)) - .pipeline((cmd)->cmd.hincrByFloat(key, field, value)) - .transaction((cmd)->cmd.hincrByFloat(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + } } @Override - public Double hIncrByFloat(final byte[] key, final byte[] field, final double value){ + public Double hIncrByFloat(final byte[] key, final byte[] field, final double value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.HINCRBYFLOAT) - .general((cmd)->cmd.hincrByFloat(key, field, value)) - .pipeline((cmd)->cmd.hincrByFloat(key, field, value)) - .transaction((cmd)->cmd.hincrByFloat(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrByFloat(key, field, value), (v)->v) + .run(args); + } } @Override - public Set hKeys(final String key){ + public Set hKeys(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand>(client, ProtocolCommand.HKEYS) - .general((cmd)->cmd.hkeys(key)) - .pipeline((cmd)->cmd.hkeys(key)) - .transaction((cmd)->cmd.hkeys(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + } } @Override - public Set hKeys(final byte[] key){ + public Set hKeys(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand>(client, ProtocolCommand.HKEYS) - .general((cmd)->cmd.hkeys(key)) - .pipeline((cmd)->cmd.hkeys(key)) - .transaction((cmd)->cmd.hkeys(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), (v)->v) + .run(args); + } } @Override - public Long hLen(final String key){ + public Long hLen(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.HLEN) - .general((cmd)->cmd.hlen(key)) - .pipeline((cmd)->cmd.hlen(key)) - .transaction((cmd)->cmd.hlen(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } } @Override - public Long hLen(final byte[] key){ + public Long hLen(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.HLEN) - .general((cmd)->cmd.hlen(key)) - .pipeline((cmd)->cmd.hlen(key)) - .transaction((cmd)->cmd.hlen(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } } @Override - public List hMGet(final String key, final String... fields){ + public List hMGet(final String key, final String... fields) { final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); - return new JedisSentinelCommand>(client, ProtocolCommand.HMGET) - .general((cmd)->cmd.hmget(key, fields)) - .pipeline((cmd)->cmd.hmget(key, fields)) - .transaction((cmd)->cmd.hmget(key, fields)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + } } @Override - public List hMGet(final byte[] key, final byte[]... fields){ + public List hMGet(final byte[] key, final byte[]... fields) { final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); - return new JedisSentinelCommand>(client, ProtocolCommand.HMGET) - .general((cmd)->cmd.hmget(key, fields)) - .pipeline((cmd)->cmd.hmget(key, fields)) - .transaction((cmd)->cmd.hmget(key, fields)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), (v)->v) + .run(args); + } } @Override - public Status hMSet(final String key, final Map data){ + public Status hMSet(final String key, final Map data) { final CommandArguments args = CommandArguments.create("key", key).put("data", data); - return new JedisSentinelCommand(client, ProtocolCommand.HMGET) - .general((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + } } @Override - public Status hMSet(final byte[] key, final Map data){ + public Status hMSet(final byte[] key, final Map data) { final CommandArguments args = CommandArguments.create("key", key).put("data", data); - return new JedisSentinelCommand(client, ProtocolCommand.HMGET) - .general((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.hmset(key, data), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + } } @Override - public String hRandField(final String key){ + public String hRandField(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfield(key)) - .pipeline((cmd)->cmd.hrandfield(key)) - .transaction((cmd)->cmd.hrandfield(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + } } @Override - public byte[] hRandField(final byte[] key){ + public byte[] hRandField(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfield(key)) - .pipeline((cmd)->cmd.hrandfield(key)) - .transaction((cmd)->cmd.hrandfield(key)) - .run(args); - } - @Override - public List hRandField(final String key, final long count){ - final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfield(key, count)) - .pipeline((cmd)->cmd.hrandfield(key, count)) - .transaction((cmd)->cmd.hrandfield(key, count)) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key), (v)->v) + .run(args); + } } @Override - public List hRandField(final byte[] key, final long count){ + public List hRandField(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfield(key, count)) - .pipeline((cmd)->cmd.hrandfield(key, count)) - .transaction((cmd)->cmd.hrandfield(key, count)) - .run(args); - } - @Override - public Map hRandFieldWithValues(final String key, final long count){ - final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfieldWithValues(key, count)) - .pipeline((cmd)->cmd.hrandfieldWithValues(key, count)) - .transaction((cmd)->cmd.hrandfieldWithValues(key, count)) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + } } @Override - public Map hRandFieldWithValues(final byte[] key, final long count){ + public List hRandField(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.HRANDFIELD) - .general((cmd)->cmd.hrandfieldWithValues(key, count)) - .pipeline((cmd)->cmd.hrandfieldWithValues(key, count)) - .transaction((cmd)->cmd.hrandfieldWithValues(key, count)) - .run(args); - } - @Override - public ScanResult> hScan(final String key, final String cursor){ - final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisSentinelCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor), ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfield(key, count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HRANDFIELD, (cmd)->cmd.hrandfield(key, count), + (v)->v) + .run(args); + } } @Override - public ScanResult> hScan(final byte[] key, final byte[] cursor){ + public Map hRandFieldWithValues(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListMapEntryMapConverter converter = + new ListMapEntryMapConverter<>((k)->k, (v)->v); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + } + } + + @Override + public Map hRandFieldWithValues(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListMapEntryMapConverter converter = + new ListMapEntryMapConverter<>((k)->k, (v)->v); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HRANDFIELD, + (cmd)->cmd.hrandfieldWithValues(key, count), converter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final String key, final String cursor) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisSentinelCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor), ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .run(args); - } - - @Override - public ScanResult> hScan(final String key, final String cursor, final String pattern){ + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + mapScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> hScan(final String key, final String cursor, final String pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisSentinelCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return hScan(key, cursor, scanParams, args); } @Override - public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern){ + public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisSentinelCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return hScan(key, cursor, scanParams, args); } @Override - public ScanResult> hScan(final String key, final String cursor, final long count){ + public ScanResult> hScan(final String key, final String cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisSentinelCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return hScan(key, cursor, scanParams, args); } @Override - public ScanResult> hScan(final byte[] key, final byte[] cursor, final long count){ + public ScanResult> hScan(final byte[] key, final byte[] cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisSentinelCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return hScan(key, cursor, scanParams, args); } @Override public ScanResult> hScan(final String key, final String cursor, final String pattern, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisSentinelCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.STRING_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return hScan(key, cursor, scanParams, args); } @Override public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisSentinelCommand>>(client, ProtocolCommand.HSCAN) - .general((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .pipeline((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .transaction((cmd)->cmd.hscan(key, cursor, params), - ScanResultConverter.MapScanResultConverter.BINARY_MAP_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return hScan(key, cursor, scanParams, args); } @Override - public Long hSet(final String key, final String field, final String value){ + public Long hSet(final String key, final String field, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.HSET) - .general((cmd)->cmd.hset(key, field, value)) - .pipeline((cmd)->cmd.hset(key, field, value)) - .transaction((cmd)->cmd.hset(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HSET, + (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + } } @Override - public Long hSet(final byte[] key, final byte[] field, final byte[] value){ + public Long hSet(final byte[] key, final byte[] field, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.HSET) - .general((cmd)->cmd.hset(key, field, value)) - .pipeline((cmd)->cmd.hset(key, field, value)) - .transaction((cmd)->cmd.hset(key, field, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HSET, + (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), (v)->v) + .run(args); + } } @Override - public Status hSetNx(final String key, final String field, final String value){ + public Status hSetNx(final String key, final String field, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.HSETNX) - .general((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HSETNX, + (cmd)->cmd.hsetnx(key, field, value), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HSETNX, + (cmd)->cmd.hsetnx(key, field, value), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + } } @Override - public Status hSetNx(final byte[] key, final byte[] field, final byte[] value){ + public Status hSetNx(final byte[] key, final byte[] field, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.HSETNX) - .general((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.hsetnx(key, field, value), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HSETNX, + (cmd)->cmd.hsetnx(key, field, value), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HSETNX, + (cmd)->cmd.hsetnx(key, field, value), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + oneStatusConverter) + .run(args); + } } @Override - public Long hStrLen(final String key, final String field){ + public Long hStrLen(final String key, final String field) { final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisSentinelCommand(client, ProtocolCommand.HSTRLEN) - .general((cmd)->cmd.hstrlen(key, field)) - .pipeline((cmd)->cmd.hstrlen(key, field)) - .transaction((cmd)->cmd.hstrlen(key, field)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HSTRLEN, + (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } } @Override - public Long hStrLen(final byte[] key, final byte[] field){ + public Long hStrLen(final byte[] key, final byte[] field) { final CommandArguments args = CommandArguments.create("key", key).put("field", field); - return new JedisSentinelCommand(client, ProtocolCommand.HSTRLEN) - .general((cmd)->cmd.hstrlen(key, field)) - .pipeline((cmd)->cmd.hstrlen(key, field)) - .transaction((cmd)->cmd.hstrlen(key, field)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HSTRLEN, + (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HSTRLEN, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } } @Override - public List hVals(final String key){ + public List hVals(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand>(client, ProtocolCommand.HVALS) - .general((cmd)->cmd.hvals(key)) - .pipeline((cmd)->cmd.hvals(key)) - .transaction((cmd)->cmd.hvals(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + } } @Override - public List hVals(final byte[] key){ + public List hVals(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand>(client, ProtocolCommand.HVALS) - .general((cmd)->cmd.hvals(key)) - .pipeline((cmd)->cmd.hvals(key)) - .transaction((cmd)->cmd.hvals(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), (v)->v) + .run(args); + } + } + + private ScanResult> hScan(final String key, final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanParams), mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanParams), mapScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + } + } + + private ScanResult> hScan(final byte[] key, final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.MapScanResultConverter mapScanResultConverter = + new ScanResultConverter.MapScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanParams), mapScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanParams), mapScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor, scanParams), + mapScanResultConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelHyperLogLogOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelHyperLogLogOperations.java index 3c05eac07..b6c4cd3f7 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelHyperLogLogOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelHyperLogLogOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -28,8 +28,6 @@ import com.buession.redis.client.jedis.JedisSentinelClient; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; /** * Jedis 哨兵模式 HyperLogLog 命令操作 @@ -39,68 +37,118 @@ */ public final class JedisSentinelHyperLogLogOperations extends AbstractHyperLogLogOperations { - public JedisSentinelHyperLogLogOperations(final JedisSentinelClient client){ + public JedisSentinelHyperLogLogOperations(final JedisSentinelClient client) { super(client); } @Override - public Status pfAdd(final String key, final String... elements){ + public Status pfAdd(final String key, final String... elements) { final CommandArguments args = CommandArguments.create("key", key).put("elements", (Object[]) elements); - return new JedisSentinelCommand(client, ProtocolCommand.PFADD) - .general((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + } } @Override - public Status pfAdd(final byte[] key, final byte[]... elements){ + public Status pfAdd(final byte[] key, final byte[]... elements) { final CommandArguments args = CommandArguments.create("key", key).put("elements", (Object[]) elements); - return new JedisSentinelCommand(client, ProtocolCommand.PFADD) - .general((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pfadd(key, elements), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + } } @Override - public Status pfMerge(final String destKey, final String... keys){ + public Status pfMerge(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.PFMERGE) - .general((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PFMERGE, + (cmd)->cmd.pfmerge(destKey, keys), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PFMERGE, + (cmd)->cmd.pfmerge(destKey, keys), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + } } @Override - public Status pfMerge(final byte[] destKey, final byte[]... keys){ + public Status pfMerge(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.PFMERGE) - .general((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.pfmerge(destKey, keys), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PFMERGE, + (cmd)->cmd.pfmerge(destKey, keys), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PFMERGE, + (cmd)->cmd.pfmerge(destKey, keys), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + } } @Override - public Long pfCount(final String... keys){ + public Long pfCount(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.PFCOUNT) - .general((cmd)->cmd.pfcount(keys)) - .pipeline((cmd)->cmd.pfcount(keys)) - .transaction((cmd)->cmd.pfcount(keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } } @Override - public Long pfCount(final byte[]... keys){ + public Long pfCount(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.PFCOUNT) - .general((cmd)->cmd.pfcount(keys)) - .pipeline((cmd)->cmd.pfcount(keys)) - .transaction((cmd)->cmd.pfcount(keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PFCOUNT, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelKeyOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelKeyOperations.java index 9e10ef373..13d3a25f0 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelKeyOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelKeyOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -33,16 +33,20 @@ import com.buession.redis.core.Type; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; import com.buession.redis.core.internal.convert.jedis.params.ExpireOptionConverter; -import com.buession.redis.core.internal.convert.jedis.params.RestoreArgumentConverter; -import com.buession.redis.core.internal.convert.jedis.params.SortArgumentConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import com.buession.redis.core.internal.convert.response.BinaryObjectEncodingConverter; +import com.buession.redis.core.internal.convert.response.ObjectEncodingConverter; import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; +import com.buession.redis.core.internal.convert.response.TypeConverter; import com.buession.redis.core.internal.jedis.JedisMigrateParams; +import com.buession.redis.core.internal.jedis.JedisRestoreParams; import com.buession.redis.core.internal.jedis.JedisScanParams; +import com.buession.redis.core.internal.jedis.JedisSortingParams; +import com.buession.redis.utils.SafeEncoder; import redis.clients.jedis.args.ExpiryOption; +import redis.clients.jedis.params.MigrateParams; import redis.clients.jedis.params.RestoreParams; +import redis.clients.jedis.params.ScanParams; import redis.clients.jedis.params.SortingParams; import java.util.List; @@ -56,952 +60,1488 @@ */ public final class JedisSentinelKeyOperations extends AbstractKeyOperations { - public JedisSentinelKeyOperations(final JedisSentinelClient client){ + public JedisSentinelKeyOperations(final JedisSentinelClient client) { super(client); } @Override - public Long del(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.DEL) - .general((cmd)->cmd.del(keys)) - .pipeline((cmd)->cmd.del(keys)) - .transaction((cmd)->cmd.del(keys)) - .run(args); + public Long del(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } } @Override - public Long del(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.DEL) - .general((cmd)->cmd.del(keys)) - .pipeline((cmd)->cmd.del(keys)) - .transaction((cmd)->cmd.del(keys)) - .run(args); + public Long del(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } } @Override - public String dump(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.DUMP) - .general((cmd)->cmd.dump(key), Converters.BINARY_TO_STRING_CONVERTER) - .pipeline((cmd)->cmd.dump(key), Converters.BINARY_TO_STRING_CONVERTER) - .transaction((cmd)->cmd.dump(key), Converters.BINARY_TO_STRING_CONVERTER) - .run(args); + public String dump(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), + SafeEncoder::encode) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), + SafeEncoder::encode) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), SafeEncoder::encode) + .run(args); + } } @Override - public byte[] dump(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.DUMP) - .general((cmd)->cmd.dump(key)) - .pipeline((cmd)->cmd.dump(key)) - .transaction((cmd)->cmd.dump(key)) - .run(args); + public byte[] dump(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + } } @Override - public Boolean exists(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.EXISTS) - .general((cmd)->cmd.exists(key)) - .pipeline((cmd)->cmd.exists(key)) - .transaction((cmd)->cmd.exists(key)) - .run(args); + public Boolean exists(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + } } @Override - public Boolean exists(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.EXISTS) - .general((cmd)->cmd.exists(key)) - .pipeline((cmd)->cmd.exists(key)) - .transaction((cmd)->cmd.exists(key)) - .run(args); + public Boolean exists(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v) + .run(args); + } } @Override - public Long exists(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.EXISTS) - .general((cmd)->cmd.exists(keys)) - .pipeline((cmd)->cmd.exists(keys)) - .transaction((cmd)->cmd.exists(keys)) - .run(args); + public Long exists(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } } @Override - public Long exists(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.EXISTS) - .general((cmd)->cmd.exists(keys)) - .pipeline((cmd)->cmd.exists(keys)) - .transaction((cmd)->cmd.exists(keys)) - .run(args); + public Long exists(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } } @Override - public Status expire(final String key, final int lifetime){ + public Status expire(final String key, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); - return new JedisSentinelCommand(client, ProtocolCommand.EXPIRE) - .general((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + } } @Override - public Status expire(final byte[] key, final int lifetime){ + public Status expire(final byte[] key, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); - return new JedisSentinelCommand(client, ProtocolCommand.EXPIRE) - .general((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + oneStatusConverter) + .run(args); + } } @Override - public Status expire(final String key, final int lifetime, final ExpireOption expireOption){ + public Status expire(final String key, final int lifetime, final ExpireOption expireOption) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime) .put("expireOption", expireOption); - final ExpiryOption expiryOption = ExpireOptionConverter.INSTANCE.convert(expireOption); - return new JedisSentinelCommand(client, ProtocolCommand.EXPIRE) - .general((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .run(args); + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + } } @Override - public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption){ + public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption) { final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime) .put("expireOption", expireOption); - final ExpiryOption expiryOption = ExpireOptionConverter.INSTANCE.convert(expireOption); - return new JedisSentinelCommand(client, ProtocolCommand.EXPIRE) - .general((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expire(key, lifetime, expiryOption), Converters.ONE_STATUS_CONVERTER) - .run(args); - } + final ExpiryOption expiryOption = (new ExpireOptionConverter()).convert(expireOption); - @Override - public Status expireAt(final String key, final long unixTimestamp){ - final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); - return new JedisSentinelCommand(client, ProtocolCommand.EXPIREAT) - .general((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime, expiryOption), oneStatusConverter) + .run(args); + } } @Override - public Status expireAt(final byte[] key, final long unixTimestamp){ + public Status expireAt(final String key, final long unixTimestamp) { final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); - return new JedisSentinelCommand(client, ProtocolCommand.EXPIREAT) - .general((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.expireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .run(args); - } - @Override - public Status pExpire(final String key, final int lifetime){ - final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); - return new JedisSentinelCommand(client, ProtocolCommand.PEXPIRE) - .general((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .run(args); - } - - @Override - public Status pExpire(final byte[] key, final int lifetime){ - final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); - return new JedisSentinelCommand(client, ProtocolCommand.PEXPIRE) - .general((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pexpire(key, lifetime), Converters.ONE_STATUS_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } } @Override - public Status pExpireAt(final String key, final long unixTimestamp){ + public Status expireAt(final byte[] key, final long unixTimestamp) { final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); - return new JedisSentinelCommand(client, ProtocolCommand.PEXPIREAT) - .general((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .run(args); - } - @Override - public Status pExpireAt(final byte[] key, final long unixTimestamp){ - final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); - return new JedisSentinelCommand(client, ProtocolCommand.PEXPIREAT) - .general((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.pexpireAt(key, unixTimestamp), Converters.ONE_STATUS_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.expireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EXPIREAT, (cmd)->cmd.expireAt(key, unixTimestamp), + oneStatusConverter) + .run(args); + } } @Override - public Status persist(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.PERSIST) - .general((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .run(args); - } + public Status pExpire(final String key, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); - @Override - public Status persist(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.PERSIST) - .general((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.persist(key), Converters.ONE_STATUS_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + } } @Override - public Long ttl(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.TTL) - .general((cmd)->cmd.ttl(key)) - .pipeline((cmd)->cmd.ttl(key)) - .transaction((cmd)->cmd.ttl(key)) - .run(args); - } + public Status pExpire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); - @Override - public Long ttl(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.TTL) - .general((cmd)->cmd.ttl(key)) - .pipeline((cmd)->cmd.ttl(key)) - .transaction((cmd)->cmd.ttl(key)) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + oneStatusConverter) + .run(args); + } } @Override - public Long pTtl(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.PTTL) - .general((cmd)->cmd.pttl(key)) - .pipeline((cmd)->cmd.pttl(key)) - .transaction((cmd)->cmd.pttl(key)) - .run(args); - } + public Status pExpireAt(final String key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); - @Override - public Long pTtl(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.PTTL) - .general((cmd)->cmd.pttl(key)) - .pipeline((cmd)->cmd.pttl(key)) - .transaction((cmd)->cmd.pttl(key)) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + } } @Override - public Status copy(final String key, final String destKey){ + public Status pExpireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PEXPIREAT, + (cmd)->cmd.pexpireAt(key, unixTimestamp), oneStatusConverter) + .run(args); + } + } + + @Override + public Status persist(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status persist(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + oneStatusConverter) + .run(args); + } + } + + @Override + public Long ttl(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } + } + + @Override + public Long ttl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } + } + + @Override + public Long pTtl(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } + } + + @Override + public Long pTtl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } + } + + @Override + public Status copy(final String key, final String destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisSentinelCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, false, args); } @Override - public Status copy(final byte[] key, final byte[] destKey){ + public Status copy(final byte[] key, final byte[] destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisSentinelCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.copy(key, destKey, false), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, false, args); } @Override - public Status copy(final String key, final String destKey, final int db){ + public Status copy(final String key, final String destKey, final int db) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("db", db); - return new JedisSentinelCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, db, false), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, db, false), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, db, false, args); } @Override - public Status copy(final byte[] key, final byte[] destKey, final int db){ - final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) - .put("db", db); - return new JedisSentinelCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, db, false), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, db, false), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + public Status copy(final byte[] key, final byte[] destKey, final int db) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("db", db); + return copy(key, destKey, db, false, args); } @Override - public Status copy(final String key, final String destKey, final boolean replace){ + public Status copy(final String key, final String destKey, final boolean replace) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("replace", replace); - return new JedisSentinelCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, replace, args); } @Override - public Status copy(final byte[] key, final byte[] destKey, final boolean replace){ + public Status copy(final byte[] key, final byte[] destKey, final boolean replace) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("replace", replace); - return new JedisSentinelCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.copy(key, destKey, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, replace, args); } @Override - public Status copy(final String key, final String destKey, final int db, final boolean replace){ + public Status copy(final String key, final String destKey, final int db, final boolean replace) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("db", db) .put("replace", replace); - return new JedisSentinelCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, db, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, db, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, db, replace, args); } @Override - public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace){ + public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("db", db) .put("replace", replace); - return new JedisSentinelCommand(client, ProtocolCommand.COPY) - .general((cmd)->cmd.copy(key, destKey, db, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.copy(key, destKey, db, replace), Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + return copy(key, destKey, db, replace, args); } @Override - public Status move(final String key, final int db){ + public Status move(final String key, final int db) { final CommandArguments args = CommandArguments.create("key", key).put("db", db); - return new JedisSentinelCommand(client, ProtocolCommand.MOVE) - .general((cmd)->cmd.move(key, db), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.move(key, db), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.MOVE, (cmd)->cmd.move(key, db), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.MOVE) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MOVE, (cmd)->cmd.move(key, db), + oneStatusConverter) + .run(args); + } } @Override - public Status move(final byte[] key, final int db){ + public Status move(final byte[] key, final int db) { final CommandArguments args = CommandArguments.create("key", key).put("db", db); - return new JedisSentinelCommand(client, ProtocolCommand.MOVE) - .general((cmd)->cmd.move(key, db), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.move(key, db), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.MOVE, (cmd)->cmd.move(key, db), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.MOVE) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MOVE, (cmd)->cmd.move(key, db), + oneStatusConverter) + .run(args); + } } @Override - public Status migrate(final String host, final int port, final int db, final int timeout, final String... keys){ + public Status migrate(final String host, final int port, final int db, final int timeout, final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("timeout", timeout).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(); - return new JedisSentinelCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override - public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... keys){ + public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("timeout", timeout).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(); - return new JedisSentinelCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final int timeout, - final MigrateOperation operation, final String... keys){ + final MigrateOperation operation, final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("timeout", timeout).put("operation", operation).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(operation); - return new JedisSentinelCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final int timeout, - final MigrateOperation operation, final byte[]... keys){ + final MigrateOperation operation, final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("timeout", timeout).put("operation", operation).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(operation); - return new JedisSentinelCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final String password, final int timeout, - final String... keys){ + final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("password", password).put("timeout", timeout).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(password); - return new JedisSentinelCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final byte[] password, final int timeout, - final byte[]... keys){ + final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("password", password).put("timeout", timeout).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(password); - return new JedisSentinelCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final String password, final int timeout, - final MigrateOperation operation, final String... keys){ + final MigrateOperation operation, final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("password", password).put("timeout", timeout).put("operation", operation) .put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(operation, password); - return new JedisSentinelCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final byte[] password, final int timeout, - final MigrateOperation operation, final byte[]... keys){ + final MigrateOperation operation, final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("password", password).put("timeout", timeout).put("operation", operation) .put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(operation, password); - return new JedisSentinelCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final String user, final String password, - final int timeout, final String... keys){ + final int timeout, final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("user", user).put("password", password).put("timeout", timeout).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(user, password); - return new JedisSentinelCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(user, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final byte[] user, final byte[] password, - final int timeout, final byte[]... keys){ + final int timeout, final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("user", user).put("password", password).put("timeout", timeout).put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(user, password); - return new JedisSentinelCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(user, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final String user, final String password, - final int timeout, final MigrateOperation operation, final String... keys){ + final int timeout, final MigrateOperation operation, final String... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("user", user).put("password", password).put("timeout", timeout).put("operation", operation) .put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(operation, user, password); - return new JedisSentinelCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation, user, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override public Status migrate(final String host, final int port, final int db, final byte[] user, final byte[] password, - final int timeout, final MigrateOperation operation, final byte[]... keys){ + final int timeout, final MigrateOperation operation, final byte[]... keys) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) .put("user", user).put("password", password).put("timeout", timeout).put("operation", operation) .put("keys", (Object[]) keys); - final JedisMigrateParams params = new JedisMigrateParams(operation, user, password); - return new JedisSentinelCommand(client, ProtocolCommand.MIGRATE) - .general((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.migrate(host, port, db, timeout, params, keys), OkStatusConverter.INSTANCE) - .run(args); + final MigrateParams migrateParams = new JedisMigrateParams(operation, user, password); + + return migrate(host, port, db, timeout, keys, migrateParams, args); } @Override - public Set keys(final String pattern){ + public Set keys(final String pattern) { final CommandArguments args = CommandArguments.create("pattern", pattern); - return new JedisSentinelCommand>(client, ProtocolCommand.KEYS) - .general((cmd)->cmd.keys(pattern)).pipeline((cmd)->cmd.keys(pattern)) - .transaction((cmd)->cmd.keys(pattern)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + } } @Override - public Set keys(final byte[] pattern){ + public Set keys(final byte[] pattern) { final CommandArguments args = CommandArguments.create("pattern", pattern); - return new JedisSentinelCommand>(client, ProtocolCommand.KEYS) - .general((cmd)->cmd.keys(pattern)).pipeline((cmd)->cmd.keys(pattern)) - .transaction((cmd)->cmd.keys(pattern)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), (v)->v) + .run(args); + } } @Override - public String randomKey(){ - return new JedisSentinelCommand(client, ProtocolCommand.RANDOMKEY) - .general((cmd)->cmd.randomKey()) - .pipeline((cmd)->cmd.randomKey()) - .transaction((cmd)->cmd.randomKey()) - .run(); + public String randomKey() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RANDOMKEY, (cmd)->cmd.randomKey(), (v)->v) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RANDOMKEY, (cmd)->cmd.randomKey(), + (v)->v) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RANDOMKEY, (cmd)->cmd.randomKey(), (v)->v) + .run(); + } } @Override - public Status rename(final String key, final String newKey){ + public Status rename(final String key, final String newKey) { final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); - return new JedisSentinelCommand(client, ProtocolCommand.RENAME) - .general((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + } } @Override - public Status rename(final byte[] key, final byte[] newKey){ + public Status rename(final byte[] key, final byte[] newKey) { final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); - return new JedisSentinelCommand(client, ProtocolCommand.RENAME) - .general((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.rename(key, newKey), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + } } @Override - public Status renameNx(final String key, final String newKey){ + public Status renameNx(final String key, final String newKey) { final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); - return new JedisSentinelCommand(client, ProtocolCommand.RENAME) - .general((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RENAMENX, + (cmd)->cmd.renamenx(key, newKey), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RENAMENX, + (cmd)->cmd.renamenx(key, newKey), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + } } @Override - public Status renameNx(final byte[] key, final byte[] newKey){ + public Status renameNx(final byte[] key, final byte[] newKey) { final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); - return new JedisSentinelCommand(client, ProtocolCommand.RENAME) - .general((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.renamenx(key, newKey), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RENAMENX, + (cmd)->cmd.renamenx(key, newKey), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RENAMENX, + (cmd)->cmd.renamenx(key, newKey), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + oneStatusConverter) + .run(args); + } } @Override - public Status restore(final String key, final byte[] serializedValue, final int ttl){ + public Status restore(final String key, final byte[] serializedValue, final int ttl) { final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) .put("ttl", ttl); - return new JedisSentinelCommand(client, ProtocolCommand.RESTORE) - .general((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + } } @Override - public Status restore(final byte[] key, final byte[] serializedValue, final int ttl){ + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl) { final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) .put("ttl", ttl); - return new JedisSentinelCommand(client, ProtocolCommand.RESTORE) - .general((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.restore(key, ttl, serializedValue), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + } } @Override public Status restore(final String key, final byte[] serializedValue, final int ttl, - final RestoreArgument argument){ + final RestoreArgument argument) { final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) .put("ttl", ttl).put("argument", argument); - final RestoreParams params = RestoreArgumentConverter.INSTANCE.convert(argument); - return new JedisSentinelCommand(client, ProtocolCommand.RESTORE) - .general((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .run(args); + final RestoreParams restoreParams = JedisRestoreParams.from(argument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + } } @Override public Status restore(final byte[] key, final byte[] serializedValue, final int ttl, - final RestoreArgument argument){ + final RestoreArgument argument) { final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) .put("ttl", ttl).put("argument", argument); - final RestoreParams params = RestoreArgumentConverter.INSTANCE.convert(argument); - return new JedisSentinelCommand(client, ProtocolCommand.RESTORE) - .general((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.restore(key, ttl, serializedValue, params), OkStatusConverter.INSTANCE) - .run(args); - } + final RestoreParams restoreParams = JedisRestoreParams.from(argument); - @Override - public ScanResult> scan(final String cursor){ - final CommandArguments args = CommandArguments.create("cursor", cursor); - return new JedisSentinelCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor), ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor), ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue, restoreParams), okStatusConverter) + .run(args); + } } @Override - public ScanResult> scan(final byte[] cursor){ + public ScanResult> scan(final String cursor) { final CommandArguments args = CommandArguments.create("cursor", cursor); - return new JedisSentinelCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor), ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor), ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); - } - - @Override - public ScanResult> scan(final String cursor, final String pattern){ + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final byte[] cursor) { + final CommandArguments args = CommandArguments.create("cursor", cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final String cursor, final String pattern) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisSentinelCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return scan(cursor, scanParams, args); } @Override - public ScanResult> scan(final byte[] cursor, final byte[] pattern){ + public ScanResult> scan(final byte[] cursor, final byte[] pattern) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisSentinelCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return scan(cursor, scanParams, args); } @Override - public ScanResult> scan(final String cursor, final long count){ + public ScanResult> scan(final String cursor, final long count) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisSentinelCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return scan(cursor, scanParams, args); } @Override - public ScanResult> scan(final byte[] cursor, final long count){ + public ScanResult> scan(final byte[] cursor, final long count) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisSentinelCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return scan(cursor, scanParams, args); } @Override - public ScanResult> scan(final String cursor, final String pattern, final long count){ + public ScanResult> scan(final String cursor, final String pattern, final long count) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisSentinelCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return scan(cursor, scanParams, args); } @Override - public ScanResult> scan(final byte[] cursor, final byte[] pattern, final long count){ + public ScanResult> scan(final byte[] cursor, final byte[] pattern, final long count) { final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisSentinelCommand>>(client, ProtocolCommand.SCAN) - .general((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.scan(cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return scan(cursor, scanParams, args); } @Override - public List sort(final String key){ + public List sort(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand>(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key)) - .pipeline((cmd)->cmd.sort(key)) - .transaction((cmd)->cmd.sort(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + } } @Override - public List sort(final byte[] key){ + public List sort(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand>(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key)) - .pipeline((cmd)->cmd.sort(key)) - .transaction((cmd)->cmd.sort(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), (v)->v) + .run(args); + } } @Override - public List sort(final String key, final SortArgument sortArgument){ + public List sort(final String key, final SortArgument sortArgument) { final CommandArguments args = CommandArguments.create("key", key).put("sortArgument", sortArgument); - final SortingParams params = SortArgumentConverter.INSTANCE.convert(sortArgument); - return new JedisSentinelCommand>(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, params)).pipeline((cmd)->cmd.sort(key, params)) - .transaction((cmd)->cmd.sort(key, params)) - .run(args); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + } } @Override - public List sort(final byte[] key, final SortArgument sortArgument){ + public List sort(final byte[] key, final SortArgument sortArgument) { final CommandArguments args = CommandArguments.create("key", key).put("sortArgument", sortArgument); - final SortingParams params = SortArgumentConverter.INSTANCE.convert(sortArgument); - return new JedisSentinelCommand>(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, params)).pipeline((cmd)->cmd.sort(key, params)) - .transaction((cmd)->cmd.sort(key, params)) - .run(args); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortingParams), (v)->v) + .run(args); + } } @Override - public Long sort(final String key, final String destKey){ + public Long sort(final String key, final String destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisSentinelCommand(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, destKey)) - .pipeline((cmd)->cmd.sort(key, destKey)) - .transaction((cmd)->cmd.sort(key, destKey)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + } } @Override - public Long sort(final byte[] key, final byte[] destKey){ + public Long sort(final byte[] key, final byte[] destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisSentinelCommand(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, destKey)) - .pipeline((cmd)->cmd.sort(key, destKey)) - .transaction((cmd)->cmd.sort(key, destKey)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, destKey), (v)->v) + .run(args); + } } @Override - public Long sort(final String key, final String destKey, final SortArgument sortArgument){ + public Long sort(final String key, final String destKey, final SortArgument sortArgument) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("sortArgument", sortArgument); - final SortingParams params = SortArgumentConverter.INSTANCE.convert(sortArgument); - return new JedisSentinelCommand(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, params, destKey)) - .pipeline((cmd)->cmd.sort(key, params, destKey)) - .transaction((cmd)->cmd.sort(key, params, destKey)) - .run(args); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + } } @Override - public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument){ + public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("sortArgument", sortArgument); - final SortingParams params = SortArgumentConverter.INSTANCE.convert(sortArgument); - return new JedisSentinelCommand(client, ProtocolCommand.SORT) - .general((cmd)->cmd.sort(key, params, destKey)) - .pipeline((cmd)->cmd.sort(key, params, destKey)) - .transaction((cmd)->cmd.sort(key, params, destKey)) - .run(args); + final SortingParams sortingParams = JedisSortingParams.from(sortArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sort(key, sortingParams, destKey), (v)->v) + .run(args); + } } @Override - public Long touch(final String... keys){ + public Long touch(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.TOUCH) - .general((cmd)->cmd.touch(keys)) - .pipeline((cmd)->cmd.touch(keys)) - .transaction((cmd)->cmd.touch(keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } } @Override - public Long touch(final byte[]... keys){ + public Long touch(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.TOUCH) - .general((cmd)->cmd.touch(keys)) - .pipeline((cmd)->cmd.touch(keys)) - .transaction((cmd)->cmd.touch(keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } } @Override - public Type type(final String key){ + public Type type(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.TYPE) - .general((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .pipeline((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .transaction((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .run(args); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), + typeConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } } @Override - public Type type(final byte[] key){ + public Type type(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.TYPE) - .general((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .pipeline((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .transaction((cmd)->cmd.type(key), Converters.TYPE_RESULT_CONVERTER) - .run(args); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), + typeConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } } @Override - public Long unlink(final String... keys){ + public Long unlink(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.UNLINK) - .general((cmd)->cmd.unlink(keys)).pipeline((cmd)->cmd.unlink(keys)) - .transaction((cmd)->cmd.unlink(keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } } @Override - public Long unlink(final byte[]... keys){ + public Long unlink(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.UNLINK) - .general((cmd)->cmd.unlink(keys)).pipeline((cmd)->cmd.unlink(keys)) - .transaction((cmd)->cmd.unlink(keys)) - .run(args); - } - @Override - public Long wait(final int replicas, final int timeout){ - final CommandArguments args = CommandArguments.create("replicas", replicas).put("timeout", timeout); - return new JedisSentinelCommand(client, ProtocolCommand.WAIT) - .general((cmd)->cmd.waitReplicas(replicas, timeout)) - .pipeline((cmd)->cmd.waitReplicas(replicas, timeout)) - .transaction((cmd)->cmd.waitReplicas(replicas, timeout)) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } } @Override - public ObjectEncoding objectEncoding(final String key){ + public ObjectEncoding objectEncoding(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.OBJECT_ENCODING) - .general((cmd)->cmd.objectEncoding(key), Converters.STRING_OBJECT_ENCODING_RESULT_CONVERTER) - .pipeline((cmd)->cmd.objectEncoding(key), Converters.STRING_OBJECT_ENCODING_RESULT_CONVERTER) - .transaction((cmd)->cmd.objectEncoding(key), Converters.STRING_OBJECT_ENCODING_RESULT_CONVERTER) - .run(args); + final ObjectEncodingConverter objectEncodingConverter = new ObjectEncodingConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.OBJECT_ENCODING, (cmd)->cmd.objectEncoding(key), + objectEncodingConverter) + .run(args); + } } @Override - public ObjectEncoding objectEncoding(final byte[] key){ + public ObjectEncoding objectEncoding(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.OBJECT_ENCODING) - .general((cmd)->cmd.objectEncoding(key), Converters.BINARY_OBJECT_ENCODING_RESULT_CONVERTER) - .pipeline((cmd)->cmd.objectEncoding(key), Converters.BINARY_OBJECT_ENCODING_RESULT_CONVERTER) - .transaction((cmd)->cmd.objectEncoding(key), Converters.BINARY_OBJECT_ENCODING_RESULT_CONVERTER) - .run(args); + final BinaryObjectEncodingConverter binaryObjectEncodingConverter = new BinaryObjectEncodingConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), binaryObjectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), binaryObjectEncodingConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.OBJECT_ENCODING, (cmd)->cmd.objectEncoding(key), + binaryObjectEncodingConverter) + .run(args); + } } @Override - public Long objectFreq(final String key){ + public Long objectFreq(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.OBJECT_REFQ) - .general((cmd)->cmd.objectFreq(key)) - .pipeline((cmd)->cmd.objectFreq(key)) - .transaction((cmd)->cmd.objectFreq(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + } } @Override - public Long objectFreq(final byte[] key){ + public Long objectFreq(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.OBJECT_REFQ) - .general((cmd)->cmd.objectFreq(key)) - .pipeline((cmd)->cmd.objectFreq(key)) - .transaction((cmd)->cmd.objectFreq(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.OBJECT_REFQ, + (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.OBJECT_REFQ, (cmd)->cmd.objectFreq(key), (v)->v) + .run(args); + } } @Override - public Long objectIdleTime(final String key){ + public Long objectIdleTime(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.OBJECT_IDLETIME) - .general((cmd)->cmd.objectIdletime(key)) - .pipeline((cmd)->cmd.objectIdletime(key)) - .transaction((cmd)->cmd.objectIdletime(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, (cmd)->cmd.objectIdletime(key), + (v)->v) + .run(args); + } } @Override - public Long objectIdleTime(final byte[] key){ + public Long objectIdleTime(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.OBJECT_IDLETIME) - .general((cmd)->cmd.objectIdletime(key)) - .pipeline((cmd)->cmd.objectIdletime(key)) - .transaction((cmd)->cmd.objectIdletime(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, (cmd)->cmd.objectIdletime(key), + (v)->v) + .run(args); + } } @Override - public Long objectRefcount(final String key){ + public Long objectRefcount(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.OBJECT_REFCOUNT) - .general((cmd)->cmd.objectRefcount(key)) - .pipeline((cmd)->cmd.objectRefcount(key)) - .transaction((cmd)->cmd.objectRefcount(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, (cmd)->cmd.objectRefcount(key), + (v)->v) + .run(args); + } } @Override - public Long objectRefcount(final byte[] key){ + public Long objectRefcount(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.OBJECT_REFCOUNT) - .general((cmd)->cmd.objectRefcount(key)) - .pipeline((cmd)->cmd.objectRefcount(key)) - .transaction((cmd)->cmd.objectRefcount(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, (cmd)->cmd.objectRefcount(key), + (v)->v) + .run(args); + } + } + + private Status copy(final String key, final String destKey, final boolean replace, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final byte[] key, final byte[] destKey, final boolean replace, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final String key, final String destKey, final int db, final boolean replace, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, db, replace), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, db, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, db, replace), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.COPY, + (cmd)->cmd.copy(key, destKey, replace), booleanStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.COPY, (cmd)->cmd.copy(key, destKey, db, replace), + booleanStatusConverter) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, final String[] keys, + final MigrateParams migrateParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, final byte[][] keys, + final MigrateParams migrateParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, timeout, migrateParams, keys), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateParams, keys), okStatusConverter) + .run(args); + } + } + + private ScanResult> scan(final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SCAN, + (cmd)->cmd.scan(cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + + private ScanResult> scan(final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SCAN, + (cmd)->cmd.scan(cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanParams), + listScanResultConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelListOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelListOperations.java index 55c6f22d2..39be47003 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelListOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelListOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -31,9 +31,8 @@ import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; import com.buession.redis.core.internal.convert.jedis.params.DirectionConverter; -import com.buession.redis.core.internal.convert.jedis.params.LPosArgumentConverter; import com.buession.redis.core.internal.convert.jedis.params.ListPositionConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import com.buession.redis.core.internal.jedis.JedisLPosParams; import redis.clients.jedis.args.ListDirection; import redis.clients.jedis.params.LPosParams; @@ -47,474 +46,838 @@ */ public final class JedisSentinelListOperations extends AbstractListOperations { - public JedisSentinelListOperations(final JedisSentinelClient client){ + public JedisSentinelListOperations(final JedisSentinelClient client) { super(client); } @Override - public String lIndex(final String key, final long index){ + public String lIndex(final String key, final long index) { final CommandArguments args = CommandArguments.create("key", key).put("index", index); - return new JedisSentinelCommand(client, ProtocolCommand.LINDEX) - .general((cmd)->cmd.lindex(key, index)) - .pipeline((cmd)->cmd.lindex(key, index)) - .transaction((cmd)->cmd.lindex(key, index)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + } } @Override - public byte[] lIndex(final byte[] key, final long index){ + public byte[] lIndex(final byte[] key, final long index) { final CommandArguments args = CommandArguments.create("key", key).put("index", index); - return new JedisSentinelCommand(client, ProtocolCommand.LINDEX) - .general((cmd)->cmd.lindex(key, index)) - .pipeline((cmd)->cmd.lindex(key, index)) - .transaction((cmd)->cmd.lindex(key, index)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), (v)->v) + .run(args); + } } @Override - public Long lInsert(final String key, final ListPosition position, final String pivot, final String value){ + public Long lInsert(final String key, final ListPosition position, final String pivot, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) .put("value", value); - final redis.clients.jedis.args.ListPosition pos = ListPositionConverter.INSTANCE.convert(position); - return new JedisSentinelCommand(client, ProtocolCommand.LINSERT) - .general((cmd)->cmd.linsert(key, pos, pivot, value)) - .pipeline((cmd)->cmd.linsert(key, pos, pivot, value)) - .transaction((cmd)->cmd.linsert(key, pos, pivot, value)) - .run(args); + final redis.clients.jedis.args.ListPosition listPosition = (new ListPositionConverter()).convert(position); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + } } @Override - public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value){ + public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) .put("value", value); - final redis.clients.jedis.args.ListPosition pos = ListPositionConverter.INSTANCE.convert(position); - return new JedisSentinelCommand(client, ProtocolCommand.LINSERT) - .general((cmd)->cmd.linsert(key, pos, pivot, value)) - .pipeline((cmd)->cmd.linsert(key, pos, pivot, value)) - .transaction((cmd)->cmd.linsert(key, pos, pivot, value)) - .run(args); + final redis.clients.jedis.args.ListPosition listPosition = (new ListPositionConverter()).convert(position); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, listPosition, pivot, value), (v)->v) + .run(args); + } } @Override - public Status lSet(final String key, final long index, final String value){ + public Status lSet(final String key, final long index, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.LINSERT) - .general((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } } @Override - public Status lSet(final byte[] key, final long index, final byte[] value){ + public Status lSet(final byte[] key, final long index, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.LINSERT) - .general((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.lset(key, index, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LINSERT, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } } @Override - public Long lLen(final String key){ + public Long lLen(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.LLEN) - .general((cmd)->cmd.llen(key)) - .pipeline((cmd)->cmd.llen(key)) - .transaction((cmd)->cmd.llen(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } } @Override - public Long lLen(final byte[] key){ + public Long lLen(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.LLEN) - .general((cmd)->cmd.llen(key)) - .pipeline((cmd)->cmd.llen(key)) - .transaction((cmd)->cmd.llen(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } } @Override - public List lRange(final String key, final long start, final long end){ + public List lRange(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand>(client, ProtocolCommand.LRANGE) - .general((cmd)->cmd.lrange(key, start, end)) - .pipeline((cmd)->cmd.lrange(key, start, end)) - .transaction((cmd)->cmd.lrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LRANGE, + (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LRANGE, + (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + } } @Override - public List lRange(final byte[] key, final long start, final long end){ + public List lRange(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand>(client, ProtocolCommand.LRANGE) - .general((cmd)->cmd.lrange(key, start, end)) - .pipeline((cmd)->cmd.lrange(key, start, end)) - .transaction((cmd)->cmd.lrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LRANGE, + (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LRANGE, + (cmd)->cmd.lrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), + (v)->v) + .run(args); + } } @Override - public Long lPos(final String key, final String element){ + public Long lPos(final String key, final String element) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element)) - .pipeline((cmd)->cmd.lpos(key, element)) - .transaction((cmd)->cmd.lpos(key, element)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } } @Override - public Long lPos(final byte[] key, final byte[] element){ + public Long lPos(final byte[] key, final byte[] element) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element)) - .pipeline((cmd)->cmd.lpos(key, element)) - .transaction((cmd)->cmd.lpos(key, element)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } } @Override - public Long lPos(final String key, final String element, final LPosArgument lPosArgument){ + public Long lPos(final String key, final String element, final LPosArgument lPosArgument) { final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); - final LPosParams params = LPosArgumentConverter.INSTANCE.convert(lPosArgument); - return new JedisSentinelCommand(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element, params)) - .pipeline((cmd)->cmd.lpos(key, element, params)) - .transaction((cmd)->cmd.lpos(key, element, params)) - .run(args); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), + (v)->v) + .run(args); + } } @Override - public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument){ + public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument) { final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); - final LPosParams params = LPosArgumentConverter.INSTANCE.convert(lPosArgument); - return new JedisSentinelCommand(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element, params)) - .pipeline((cmd)->cmd.lpos(key, element, params)) - .transaction((cmd)->cmd.lpos(key, element, params)) - .run(args); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element, lPosParams), + (v)->v) + .run(args); + } } @Override - public List lPos(final String key, final String element, final LPosArgument lPosArgument, final long count){ + public List lPos(final String key, final String element, final LPosArgument lPosArgument, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) .put("count", count); - final LPosParams params = LPosArgumentConverter.INSTANCE.convert(lPosArgument); - return new JedisSentinelCommand>(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element, params, count)) - .pipeline((cmd)->cmd.lpos(key, element, params, count)) - .transaction((cmd)->cmd.lpos(key, element, params, count)) - .run(args); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + } } @Override - public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final long count){ + public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) .put("count", count); - final LPosParams params = LPosArgumentConverter.INSTANCE.convert(lPosArgument); - return new JedisSentinelCommand>(client, ProtocolCommand.LPOS) - .general((cmd)->cmd.lpos(key, element, params, count)) - .pipeline((cmd)->cmd.lpos(key, element, params, count)) - .transaction((cmd)->cmd.lpos(key, element, params, count)) - .run(args); + final LPosParams lPosParams = JedisLPosParams.from(lPosArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosParams, count), (v)->v) + .run(args); + } } @Override - public Long lRem(final String key, final String value, final long count){ + public Long lRem(final String key, final String value, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); - return new JedisSentinelCommand(client, ProtocolCommand.LREM) - .general((cmd)->cmd.lrem(key, count, value)) - .pipeline((cmd)->cmd.lrem(key, count, value)) - .transaction((cmd)->cmd.lrem(key, count, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LREM, + (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } } @Override - public Long lRem(final byte[] key, final byte[] value, final long count){ + public Long lRem(final byte[] key, final byte[] value, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); - return new JedisSentinelCommand(client, ProtocolCommand.LREM) - .general((cmd)->cmd.lrem(key, count, value)) - .pipeline((cmd)->cmd.lrem(key, count, value)) - .transaction((cmd)->cmd.lrem(key, count, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LREM, + (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } } @Override - public Status lTrim(final String key, final long start, final long end){ + public Status lTrim(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand(client, ProtocolCommand.LTRIM) - .general((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LTRIM, + (cmd)->cmd.ltrim(key, start, end), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } } @Override - public Status lTrim(final byte[] key, final long start, final long end){ + public Status lTrim(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand(client, ProtocolCommand.LTRIM) - .general((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.ltrim(key, start, end), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LTRIM, + (cmd)->cmd.ltrim(key, start, end), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } } @Override - public String lMove(final String key, final String destKey, final Direction from, final Direction to){ + public String lMove(final String key, final String destKey, final Direction from, final Direction to) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) .put("to", to); - final ListDirection fromDirection = DirectionConverter.INSTANCE.convert(from); - final ListDirection toDirection = DirectionConverter.INSTANCE.convert(to); - return new JedisSentinelCommand(client, ProtocolCommand.LMOVE) - .general((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .pipeline((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .transaction((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .run(args); - } - - @Override - public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to){ + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + } + } + + @Override + public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) .put("to", to); - final ListDirection fromDirection = DirectionConverter.INSTANCE.convert(from); - final ListDirection toDirection = DirectionConverter.INSTANCE.convert(to); - return new JedisSentinelCommand(client, ProtocolCommand.LMOVE) - .general((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .pipeline((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .transaction((cmd)->cmd.lmove(key, destKey, fromDirection, toDirection)) - .run(args); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LMOVE, + (cmd)->cmd.lmove(key, destKey, fromDirection, toDirection), (v)->v) + .run(args); + } } @Override public String blMove(final String key, final String destKey, final Direction from, final Direction to, - final int timeout){ + final int timeout) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) .put("to", to).put("timeout", timeout); - final ListDirection fromDirection = DirectionConverter.INSTANCE.convert(from); - final ListDirection toDirection = DirectionConverter.INSTANCE.convert(to); - return new JedisSentinelCommand(client, ProtocolCommand.BLMOVE) - .general((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .pipeline((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .transaction((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .run(args); + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + } } @Override public byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, - final int timeout){ + final int timeout) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) .put("to", to).put("timeout", timeout); - final ListDirection fromDirection = DirectionConverter.INSTANCE.convert(from); - final ListDirection toDirection = DirectionConverter.INSTANCE.convert(to); - return new JedisSentinelCommand(client, ProtocolCommand.BLMOVE) - .general((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .pipeline((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .transaction((cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout)) - .run(args); - } - - @Override - public List blPop(final String[] keys, final int timeout){ + final DirectionConverter directionConverter = new DirectionConverter(); + final ListDirection fromDirection = directionConverter.convert(from); + final ListDirection toDirection = directionConverter.convert(to); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BLMOVE, + (cmd)->cmd.blmove(key, destKey, fromDirection, toDirection, timeout), (v)->v) + .run(args); + } + } + + @Override + public List blPop(final String[] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisSentinelCommand>(client, ProtocolCommand.BLPOP) - .general((cmd)->cmd.blpop(timeout, keys)) - .pipeline((cmd)->cmd.blpop(timeout, keys)) - .transaction((cmd)->cmd.blpop(timeout, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + } } @Override - public List blPop(final byte[][] keys, final int timeout){ + public List blPop(final byte[][] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisSentinelCommand>(client, ProtocolCommand.BLPOP) - .general((cmd)->cmd.blpop(timeout, keys)) - .pipeline((cmd)->cmd.blpop(timeout, keys)) - .transaction((cmd)->cmd.blpop(timeout, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), (v)->v) + .run(args); + } } @Override - public List brPop(final String[] keys, final int timeout){ + public List brPop(final String[] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisSentinelCommand>(client, ProtocolCommand.BRPOP) - .general((cmd)->cmd.brpop(timeout, keys)) - .pipeline((cmd)->cmd.brpop(timeout, keys)) - .transaction((cmd)->cmd.brpop(timeout, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + } } @Override - public List brPop(final byte[][] keys, final int timeout){ + public List brPop(final byte[][] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisSentinelCommand>(client, ProtocolCommand.BRPOP) - .general((cmd)->cmd.brpop(timeout, keys)) - .pipeline((cmd)->cmd.brpop(timeout, keys)) - .transaction((cmd)->cmd.brpop(timeout, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), (v)->v) + .run(args); + } } @Override - public String brPoplPush(final String key, final String destKey, final int timeout){ + public String brPoplPush(final String key, final String destKey, final int timeout) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("timeout", timeout); - return new JedisSentinelCommand(client, ProtocolCommand.BRPOPLPUSH) - .general((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .pipeline((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .transaction((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + } } @Override - public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout){ + public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) .put("timeout", timeout); - return new JedisSentinelCommand(client, ProtocolCommand.BRPOPLPUSH) - .general((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .pipeline((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .transaction((cmd)->cmd.brpoplpush(key, destKey, timeout)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(key, destKey, timeout), (v)->v) + .run(args); + } } @Override - public String lPop(final String key){ + public String lPop(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.LPOP) - .general((cmd)->cmd.lpop(key)) - .pipeline((cmd)->cmd.lpop(key)) - .transaction((cmd)->cmd.lpop(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + } } @Override - public byte[] lPop(final byte[] key){ + public byte[] lPop(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.LPOP) - .general((cmd)->cmd.lpop(key)) - .pipeline((cmd)->cmd.lpop(key)) - .transaction((cmd)->cmd.lpop(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), (v)->v) + .run(args); + } } @Override - public Long lPush(final String key, final String... values){ + public Long lPush(final String key, final String... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisSentinelCommand(client, ProtocolCommand.LPUSH) - .general((cmd)->cmd.lpush(key, values)) - .pipeline((cmd)->cmd.lpush(key, values)) - .transaction((cmd)->cmd.lpush(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } } @Override - public Long lPush(final byte[] key, final byte[]... values){ + public Long lPush(final byte[] key, final byte[]... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisSentinelCommand(client, ProtocolCommand.LPUSH) - .general((cmd)->cmd.lpush(key, values)) - .pipeline((cmd)->cmd.lpush(key, values)) - .transaction((cmd)->cmd.lpush(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } } @Override - public Long lPushX(final String key, final String... values){ + public Long lPushX(final String key, final String... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisSentinelCommand(client, ProtocolCommand.LPUSHX) - .general((cmd)->cmd.lpushx(key, values)) - .pipeline((cmd)->cmd.lpushx(key, values)) - .transaction((cmd)->cmd.lpushx(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } } @Override - public Long lPushX(final byte[] key, final byte[]... values){ + public Long lPushX(final byte[] key, final byte[]... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisSentinelCommand(client, ProtocolCommand.LPUSHX) - .general((cmd)->cmd.lpushx(key, values)) - .pipeline((cmd)->cmd.lpushx(key, values)) - .transaction((cmd)->cmd.lpushx(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } } @Override - public String rPop(final String key){ + public String rPop(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.RPOP) - .general((cmd)->cmd.rpop(key)) - .pipeline((cmd)->cmd.rpop(key)) - .transaction((cmd)->cmd.rpop(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + } } @Override - public byte[] rPop(final byte[] key){ + public byte[] rPop(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.RPOP) - .general((cmd)->cmd.rpop(key)) - .pipeline((cmd)->cmd.rpop(key)) - .transaction((cmd)->cmd.rpop(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), (v)->v) + .run(args); + } } @Override - public String rPoplPush(final String key, final String destKey){ + public String rPoplPush(final String key, final String destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisSentinelCommand(client, ProtocolCommand.RPOPLPUSH) - .general((cmd)->cmd.rpoplpush(key, destKey)) - .pipeline((cmd)->cmd.rpoplpush(key, destKey)) - .transaction((cmd)->cmd.rpoplpush(key, destKey)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + } } @Override - public byte[] rPoplPush(final byte[] key, final byte[] destKey){ + public byte[] rPoplPush(final byte[] key, final byte[] destKey) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); - return new JedisSentinelCommand(client, ProtocolCommand.RPOPLPUSH) - .general((cmd)->cmd.rpoplpush(key, destKey)) - .pipeline((cmd)->cmd.rpoplpush(key, destKey)) - .transaction((cmd)->cmd.rpoplpush(key, destKey)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + (v)->v) + .run(args); + } } @Override - public Long rPush(final String key, final String... values){ + public Long rPush(final String key, final String... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisSentinelCommand(client, ProtocolCommand.RPUSH) - .general((cmd)->cmd.rpush(key, values)) - .pipeline((cmd)->cmd.rpush(key, values)) - .transaction((cmd)->cmd.rpush(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } } @Override - public Long rPush(final byte[] key, final byte[]... values){ + public Long rPush(final byte[] key, final byte[]... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisSentinelCommand(client, ProtocolCommand.RPUSH) - .general((cmd)->cmd.rpush(key, values)) - .pipeline((cmd)->cmd.rpush(key, values)) - .transaction((cmd)->cmd.rpush(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } } @Override - public Long rPushX(final String key, final String... values){ + public Long rPushX(final String key, final String... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisSentinelCommand(client, ProtocolCommand.RPUSHX) - .general((cmd)->cmd.rpushx(key, values)) - .pipeline((cmd)->cmd.rpushx(key, values)) - .transaction((cmd)->cmd.rpushx(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } } @Override - public Long rPushX(final byte[] key, final byte[]... values){ + public Long rPushX(final byte[] key, final byte[]... values) { final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); - return new JedisSentinelCommand(client, ProtocolCommand.RPUSHX) - .general((cmd)->cmd.rpushx(key, values)) - .pipeline((cmd)->cmd.rpushx(key, values)) - .transaction((cmd)->cmd.rpushx(key, values)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelPubSubOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelPubSubOperations.java index 048204685..4b81db9ed 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelPubSubOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelPubSubOperations.java @@ -19,11 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.core.converter.Converter; +import com.buession.core.converter.MapConverter; import com.buession.redis.client.jedis.JedisSentinelClient; import com.buession.redis.core.PubSubListener; import com.buession.redis.core.command.CommandArguments; @@ -33,7 +35,6 @@ import com.buession.redis.pubsub.jedis.DefaultJedisPubSub; import com.buession.redis.utils.SafeEncoder; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -45,173 +46,298 @@ */ public final class JedisSentinelPubSubOperations extends AbstractPubSubOperations { - public JedisSentinelPubSubOperations(final JedisSentinelClient client){ + public JedisSentinelPubSubOperations(final JedisSentinelClient client) { super(client); } @Override - public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener){ + public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener) { final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) .put("pubSubListener", pubSubListener); - new JedisSentinelCommand(client, ProtocolCommand.PSUBSCRIBE) - .general((cmd)->{ - cmd.psubscribe(new DefaultJedisPubSub(pubSubListener), patterns); - return null; - }) - .run(args); + + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else{ + new JedisSentinelCommand<>(client, ProtocolCommand.PSUBSCRIBE, (cmd)->{ + cmd.psubscribe(new DefaultJedisPubSub(pubSubListener), patterns); + return null; + }, (v)->v) + .run(args); + } } @Override - public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener){ + public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener) { final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) .put("pubSubListener", pubSubListener); - new JedisSentinelCommand(client, ProtocolCommand.PSUBSCRIBE) - .general((cmd)->{ - cmd.psubscribe(new DefaultBinaryJedisPubSub(pubSubListener), patterns); - return null; - }) - .run(args); + + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else{ + new JedisSentinelCommand<>(client, ProtocolCommand.PSUBSCRIBE, (cmd)->{ + cmd.psubscribe(new DefaultBinaryJedisPubSub(pubSubListener), patterns); + return null; + }, (v)->v) + .run(args); + } } @Override - public Long publish(final String channel, final String message){ + public Long publish(final String channel, final String message) { final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); - return new JedisSentinelCommand(client, ProtocolCommand.PUBLISH) - .general((cmd)->cmd.publish(channel, message)) - .pipeline((cmd)->cmd.publish(channel, message)) - .transaction((cmd)->cmd.publish(channel, message)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PUBLISH, + (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.PUBLISH) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + } } @Override - public Long publish(final byte[] channel, final byte[] message){ + public Long publish(final byte[] channel, final byte[] message) { final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); - return new JedisSentinelCommand(client, ProtocolCommand.PUBLISH) - .general((cmd)->cmd.publish(channel, message)) - .pipeline((cmd)->cmd.publish(channel, message)) - .transaction((cmd)->cmd.publish(channel, message)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PUBLISH, + (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.PUBLISH) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + } } @Override - public List pubsubChannels(){ - return new JedisSentinelCommand>(client, ProtocolCommand.PUBSUB_CHANNELS) - .general((cmd)->cmd.pubsubChannels()) - .run(); + public List pubsubChannels() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + ProtocolCommand.PUBSUB_CHANNELS) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(), + (v)->v) + .run(); + } } @Override - public List pubsubChannels(final String pattern){ + public List pubsubChannels(final String pattern) { final CommandArguments args = CommandArguments.create("pattern", pattern); - return new JedisSentinelCommand>(client, ProtocolCommand.PUBSUB_CHANNELS) - .general((cmd)->cmd.pubsubChannels(pattern)) - .run(args); + return pubsubChannels(pattern, (v)->v, args); } @Override - public List pubsubChannels(final byte[] pattern){ + public List pubsubChannels(final byte[] pattern) { final CommandArguments args = CommandArguments.create("pattern", pattern); - return new JedisSentinelCommand>(client, ProtocolCommand.PUBSUB_CHANNELS) - .general((cmd)->cmd.pubsubChannels(SafeEncoder.encode(pattern)), - Converters.STRING_LIST_TO_BINARY_LIST_CONVERTER) - .run(args); + final String sPattern = SafeEncoder.encode(pattern); + final com.buession.core.converter.ListConverter stringToBinaryListConverter = + Converters.listStringToBinary(); + + return pubsubChannels(sPattern, stringToBinaryListConverter, args); } @Override - public Long pubsubNumPat(){ - return new JedisSentinelCommand(client, ProtocolCommand.PUBSUB_NUMPAT) - .general((cmd)->cmd.pubsubNumPat()) - .run(); + public Long pubsubNumPat() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.PUBSUB_NUMPAT) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.PUBSUB_NUMPAT) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PUBSUB_NUMPAT, (cmd)->cmd.pubsubNumPat(), (v)->v) + .run(); + } } @Override - public Map pubsubNumSub(final String... channels){ + public Map pubsubNumSub(final String... channels) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); - return new JedisSentinelCommand>(client, ProtocolCommand.PUBSUB_NUMSUB) - .general((cmd)->cmd.pubsubNumSub(channels)) - .run(args); + return pubsubNumSub(channels, (v)->v, args); } @Override - public Map pubsubNumSub(final byte[]... channels){ + public Map pubsubNumSub(final byte[]... channels) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); - return new JedisSentinelCommand>(client, ProtocolCommand.PUBSUB_NUMSUB) - .general((cmd)->{ - final Map temp = cmd.pubsubNumSub( - Converters.BINARY_ARRAY_TO_STRING_ARRAY_CONVERTER.convert(channels)); - final Map result = new HashMap<>(temp.size()); + final String[] sChannels = SafeEncoder.encode(channels); + final MapConverter stringToBinaryKeyPrimitiveValueMapConverter = + new MapConverter<>(SafeEncoder::encode, (v)->v); - temp.forEach((key, value)->{ - result.put(SafeEncoder.encode(key), value); - }); - - return result; - }) - .run(args); + return pubsubNumSub(sChannels, stringToBinaryKeyPrimitiveValueMapConverter, args); } @Override - public Object pUnSubscribe(){ - return new JedisSentinelCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) - .run(); + public Object pUnSubscribe() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + } } @Override - public Object pUnSubscribe(final String... patterns){ + public Object pUnSubscribe(final String... patterns) { final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); - return new JedisSentinelCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) - .run(args); + return pUnSubscribe(args); } @Override - public Object pUnSubscribe(final byte[]... patterns){ + public Object pUnSubscribe(final byte[]... patterns) { final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); - return new JedisSentinelCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) - .run(args); + return pUnSubscribe(args); } @Override - public void subscribe(final String[] channels, final PubSubListener pubSubListener){ + public void subscribe(final String[] channels, final PubSubListener pubSubListener) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) .put("pubSubListener", pubSubListener); - new JedisSentinelCommand(client, ProtocolCommand.PUBLISH) - .general((cmd)->{ - cmd.subscribe(new DefaultJedisPubSub(pubSubListener), channels); - return null; - }) - .run(args); + + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else{ + new JedisSentinelCommand<>(client, ProtocolCommand.SUBSCRIBE, (cmd)->{ + cmd.subscribe(new DefaultJedisPubSub(pubSubListener), channels); + return null; + }, (v)->v) + .run(args); + } } @Override - public void subscribe(final byte[][] channels, final PubSubListener pubSubListener){ + public void subscribe(final byte[][] channels, final PubSubListener pubSubListener) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) .put("pubSubListener", pubSubListener); - new JedisSentinelCommand(client, ProtocolCommand.PUBLISH) - .general((cmd)->{ - cmd.subscribe(new DefaultBinaryJedisPubSub(pubSubListener), channels); - return null; - }) - .run(args); + + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else{ + new JedisSentinelCommand<>(client, ProtocolCommand.SUBSCRIBE, (cmd)->{ + cmd.subscribe(new DefaultBinaryJedisPubSub(pubSubListener), channels); + return null; + }, (v)->v) + .run(args); + } } @Override - public Object unSubscribe(){ - return new JedisSentinelCommand<>(client, ProtocolCommand.UNSUBSCRIBE) - .run(); + public Object unSubscribe() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + } } @Override - public Object unSubscribe(final String... channels){ + public Object unSubscribe(final String... channels) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); - return new JedisSentinelCommand<>(client, ProtocolCommand.UNSUBSCRIBE) - .run(args); + return unSubscribe(args); } @Override - public Object unSubscribe(final byte[]... channels){ + public Object unSubscribe(final byte[]... channels) { final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); - return new JedisSentinelCommand<>(client, ProtocolCommand.UNSUBSCRIBE) - .run(args); + return unSubscribe(args); + } + + private List pubsubChannels(final String pattern, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(pattern), + converter) + .run(); + } + } + + private Map pubsubNumSub(final String[] channels, + final Converter, Map> converter, + final CommandArguments args) { + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, Map>(client, ProtocolCommand.PUBSUB_NUMSUB) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, Map>(client, + ProtocolCommand.PUBSUB_NUMSUB) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PUBSUB_NUMSUB, (cmd)->cmd.pubsubNumSub(channels), + converter) + .run(args); + } + } + + private Object pUnSubscribe(final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + } + } + + private Object unSubscribe(final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelScriptingOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelScriptingOperations.java index 478de3e1b..a54c91804 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelScriptingOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelScriptingOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -30,7 +30,6 @@ import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; import com.buession.redis.core.internal.convert.jedis.params.FlushModeConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; import java.util.Arrays; import java.util.List; @@ -43,204 +42,374 @@ */ public final class JedisSentinelScriptingOperations extends AbstractScriptingOperations { - public JedisSentinelScriptingOperations(final JedisSentinelClient client){ + public JedisSentinelScriptingOperations(final JedisSentinelClient client) { super(client); } @Override - public Object eval(final String script){ + public Object eval(final String script) { final CommandArguments args = CommandArguments.create("script", script); - return new JedisSentinelCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script)) - .pipeline((cmd)->cmd.eval(script)) - .transaction((cmd)->cmd.eval(script)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + } } @Override - public Object eval(final byte[] script){ + public Object eval(final byte[] script) { final CommandArguments args = CommandArguments.create("script", script); - return new JedisSentinelCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script)).pipeline((cmd)->cmd.eval(script)) - .transaction((cmd)->cmd.eval(script)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script), (v)->v) + .run(args); + } } @Override - public Object eval(final String script, final String... params){ + public Object eval(final String script, final String... params) { final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); final int paramsSize = params == null ? 0 : params.length; - return new JedisSentinelCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script, paramsSize, params)) - .pipeline((cmd)->cmd.eval(script, paramsSize, params)) - .transaction((cmd)->cmd.eval(script, paramsSize, params)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script, paramsSize, params), + (v)->v) + .run(args); + } } @Override - public Object eval(final byte[] script, final byte[]... params){ + public Object eval(final byte[] script, final byte[]... params) { final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); final int paramsSize = params == null ? 0 : params.length; - return new JedisSentinelCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script, paramsSize, params)) - .pipeline((cmd)->cmd.eval(script, paramsSize, params)) - .transaction((cmd)->cmd.eval(script, paramsSize, params)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EVAL, (cmd)->cmd.eval(script, paramsSize, params), + (v)->v) + .run(args); + } } @Override - public Object eval(final String script, final String[] keys, final String[] arguments){ + public Object eval(final String script, final String[] keys, final String[] arguments) { final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) .put("arguments", (Object[]) arguments); - return new JedisSentinelCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .pipeline((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .transaction((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .run(args); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + } } @Override - public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments){ + public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments) { final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) .put("arguments", (Object[]) arguments); - return new JedisSentinelCommand<>(client, ProtocolCommand.EVAL) - .general((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .pipeline((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .transaction((cmd)->cmd.eval(script, Arrays.asList(keys), Arrays.asList(arguments))) - .run(args); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, keysList, argumentsList), (v)->v) + .run(args); + } } @Override - public Object evalSha(final String digest){ + public Object evalSha(final String digest) { final CommandArguments args = CommandArguments.create("digest", digest); - return new JedisSentinelCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest)) - .pipeline((cmd)->cmd.evalsha(digest)) - .transaction((cmd)->cmd.evalsha(digest)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + } } @Override - public Object evalSha(final byte[] digest){ + public Object evalSha(final byte[] digest) { final CommandArguments args = CommandArguments.create("digest", digest); - return new JedisSentinelCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest)) - .pipeline((cmd)->cmd.evalsha(digest)) - .transaction((cmd)->cmd.evalsha(digest)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EVALSHA, (cmd)->cmd.evalsha(digest), (v)->v) + .run(args); + } } @Override - public Object evalSha(final String digest, final String... params){ + public Object evalSha(final String digest, final String... params) { final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); final int paramsSize = params == null ? 0 : params.length; - return new JedisSentinelCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest, paramsSize, params)) - .pipeline((cmd)->cmd.evalsha(digest, paramsSize, params)) - .transaction((cmd)->cmd.evalsha(digest, paramsSize, params)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + } } @Override - public Object evalSha(final byte[] digest, final byte[]... params){ + public Object evalSha(final byte[] digest, final byte[]... params) { final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); final int paramsSize = params == null ? 0 : params.length; - return new JedisSentinelCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest, paramsSize, params)) - .pipeline((cmd)->cmd.evalsha(digest, paramsSize, params)) - .transaction((cmd)->cmd.evalsha(digest, paramsSize, params)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, paramsSize, params), (v)->v) + .run(args); + } } @Override - public Object evalSha(final String digest, final String[] keys, final String[] arguments){ + public Object evalSha(final String digest, final String[] keys, final String[] arguments) { final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) .put("arguments", (Object[]) arguments); - return new JedisSentinelCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .pipeline((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .transaction((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .run(args); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + } } @Override - public Object evalSha(final byte[] digest, final byte[][] keys, final byte[][] arguments){ + public Object evalSha(final byte[] digest, final byte[][] keys, final byte[][] arguments) { final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) .put("arguments", (Object[]) arguments); - return new JedisSentinelCommand<>(client, ProtocolCommand.EVALSHA) - .general((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .pipeline((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .transaction((cmd)->cmd.evalsha(digest, Arrays.asList(keys), Arrays.asList(arguments))) - .run(args); + final List keysList = Arrays.asList(keys); + final List argumentsList = Arrays.asList(arguments); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.eval(digest, keysList, argumentsList), (v)->v) + .run(args); + } } @Override - public List scriptExists(final String... sha1){ + public List scriptExists(final String... sha1) { final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); - return new JedisSentinelCommand>(client, ProtocolCommand.SCRIPT_EXISTS) - .general((cmd)->cmd.scriptExists(sha1)) - .pipeline((cmd)->cmd.scriptExists(null, sha1)) - .transaction((cmd)->cmd.scriptExists(null, sha1)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), + (v)->v) + .run(args); + } } @Override - public List scriptExists(final byte[]... sha1){ + public List scriptExists(final byte[]... sha1) { final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); - return new JedisSentinelCommand>(client, ProtocolCommand.SCRIPT_EXISTS) - .general((cmd)->cmd.scriptExists(sha1)) - .pipeline((cmd)->cmd.scriptExists(null, sha1)) - .transaction((cmd)->cmd.scriptExists(null, sha1)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(null, sha1), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), + (v)->v) + .run(args); + } } @Override - public Status scriptFlush(){ - return new JedisSentinelCommand(client, ProtocolCommand.SCRIPT_FLUSH) - .general((cmd)->cmd.scriptFlush(), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.scriptFlush((String) null), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.scriptFlush((String) null), OkStatusConverter.INSTANCE) - .run(); + public Status scriptFlush() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null), okStatusConverter) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(); + } } @Override - public Status scriptFlush(final FlushMode mode){ + public Status scriptFlush(final FlushMode mode) { final CommandArguments args = CommandArguments.create("mode", mode); - final redis.clients.jedis.args.FlushMode flushMode = FlushModeConverter.INSTANCE.convert(mode); - return new JedisSentinelCommand(client, ProtocolCommand.SCRIPT_FLUSH) - .general((cmd)->cmd.scriptFlush(flushMode), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.scriptFlush((String) null, flushMode), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.scriptFlush((String) null, flushMode), OkStatusConverter.INSTANCE) - .run(args); + final redis.clients.jedis.args.FlushMode flushMode = (new FlushModeConverter()).convert(mode); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null, flushMode), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush((String) null, flushMode), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(flushMode), + okStatusConverter) + .run(args); + } } @Override - public String scriptLoad(final String script){ + public String scriptLoad(final String script) { final CommandArguments args = CommandArguments.create("script", script); - return new JedisSentinelCommand(client, ProtocolCommand.SCRIPT_LOAD) - .general((cmd)->cmd.scriptLoad(script)) - .pipeline((cmd)->cmd.scriptLoad(script, null)) - .transaction((cmd)->cmd.scriptLoad(script, null)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), + (v)->v) + .run(args); + } } @Override - public byte[] scriptLoad(final byte[] script){ + public byte[] scriptLoad(final byte[] script) { final CommandArguments args = CommandArguments.create("script", script); - return new JedisSentinelCommand(client, ProtocolCommand.SCRIPT_LOAD) - .general((cmd)->cmd.scriptLoad(script)) - .pipeline((cmd)->cmd.scriptLoad(script, null)) - .transaction((cmd)->cmd.scriptLoad(script, null)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script, null), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), + (v)->v) + .run(args); + } } @Override - public Status scriptKill(){ - return new JedisSentinelCommand(client, ProtocolCommand.SCRIPT_KILL) - .general((cmd)->cmd.scriptKill(), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.scriptKill((String) null), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.scriptKill((String) null), OkStatusConverter.INSTANCE) - .run(); + public Status scriptKill() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SCRIPT_KILL, + (cmd)->cmd.scriptKill((String) null), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SCRIPT_KILL, + (cmd)->cmd.scriptKill((String) null), okStatusConverter) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelServerOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelServerOperations.java index 2a18aafe0..2f4e563c4 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelServerOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelServerOperations.java @@ -19,12 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; -import com.buession.core.collect.Arrays; +import com.buession.core.converter.ListConverter; import com.buession.lang.Status; import com.buession.redis.client.jedis.JedisSentinelClient; import com.buession.redis.core.AclLog; @@ -42,17 +42,21 @@ import com.buession.redis.core.internal.convert.jedis.response.AccessControlLogEntryConverter; import com.buession.redis.core.internal.convert.jedis.response.AccessControlUserConverter; import com.buession.redis.core.internal.convert.jedis.params.FlushModeConverter; -import com.buession.redis.core.internal.convert.jedis.response.InfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.MemoryStatsConverter; +import com.buession.redis.core.internal.convert.response.InfoConverter; import com.buession.redis.core.internal.convert.jedis.response.ModuleConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; import com.buession.redis.core.internal.convert.jedis.response.RedisServerTimeConverter; import com.buession.redis.core.internal.convert.jedis.response.SlowlogConverter; import com.buession.redis.core.internal.convert.jedis.response.RoleConverter; import com.buession.redis.core.internal.jedis.JedisFailoverParams; import redis.clients.jedis.JedisMonitor; import redis.clients.jedis.args.SaveMode; +import redis.clients.jedis.params.FailoverParams; +import redis.clients.jedis.resps.AccessControlLogEntry; +import redis.clients.jedis.resps.Slowlog; import java.util.List; +import java.util.Map; /** * Jedis 哨兵模式服务端命令操作 @@ -62,538 +66,1073 @@ */ public final class JedisSentinelServerOperations extends AbstractServerOperations { - public JedisSentinelServerOperations(final JedisSentinelClient client){ + public JedisSentinelServerOperations(final JedisSentinelClient client) { super(client); } @Override - public List aclCat(){ - return new JedisSentinelCommand>(client, ProtocolCommand.ACL_CAT) - .general((cmd)->cmd.aclCat()) - .run(); + public List aclCat() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_CAT, (cmd)->cmd.aclCat(), (v)->v) + .run(); + } } @Override - public List aclCat(final String categoryName){ + public List aclCat(final String categoryName) { final CommandArguments args = CommandArguments.create("categoryName", categoryName); - return new JedisSentinelCommand>(client, ProtocolCommand.ACL_CAT) - .general((cmd)->cmd.aclCat(categoryName)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_CAT, (cmd)->cmd.aclCat(categoryName), (v)->v) + .run(args); + } } @Override - public List aclCat(final byte[] categoryName){ + public List aclCat(final byte[] categoryName) { final CommandArguments args = CommandArguments.create("categoryName", categoryName); - return new JedisSentinelCommand>(client, ProtocolCommand.ACL_CAT) - .general((cmd)->cmd.aclCat(categoryName)) - .run(args); - } - @Override - public Status aclSetUser(final String username, final String... rules){ - final CommandArguments args = CommandArguments.create("username", username).put("rules", (Object[]) rules); - return new JedisSentinelCommand(client, ProtocolCommand.ACL_SETUSER) - .general((cmd)->cmd.aclSetUser(username, rules), OkStatusConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_CAT, (cmd)->cmd.aclCat(categoryName), (v)->v) + .run(args); + } } @Override - public Status aclSetUser(final byte[] username, final byte[]... rules){ + public Status aclSetUser(final String username, final String... rules) { final CommandArguments args = CommandArguments.create("username", username).put("rules", (Object[]) rules); - return new JedisSentinelCommand(client, ProtocolCommand.ACL_SETUSER) - .general((cmd)->cmd.aclSetUser(username, rules), OkStatusConverter.INSTANCE) - .run(args); - } - @Override - public AclUser aclGetUser(final String username){ - final CommandArguments args = CommandArguments.create("username", username); - return new JedisSentinelCommand(client, ProtocolCommand.ACL_GETUSER) - .general((cmd)->cmd.aclGetUser(username), AccessControlUserConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_SETUSER, + (cmd)->cmd.aclSetUser(username, rules), okStatusConverter) + .run(args); + } } @Override - public AclUser aclGetUser(final byte[] username){ - final CommandArguments args = CommandArguments.create("username", username); - return new JedisSentinelCommand(client, ProtocolCommand.ACL_GETUSER) - .general((cmd)->cmd.aclGetUser(username), AccessControlUserConverter.INSTANCE) - .run(args); - } + public Status aclSetUser(final byte[] username, final byte[]... rules) { + final CommandArguments args = CommandArguments.create("username", username).put("rules", (Object[]) rules); - @Override - public List aclUsers(){ - return new JedisSentinelCommand>(client, ProtocolCommand.ACL_USERS) - .general((cmd)->cmd.aclUsers()) - .run(); + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_SETUSER, + (cmd)->cmd.aclSetUser(username, rules), okStatusConverter) + .run(args); + } } @Override - public String aclWhoAmI(){ - return new JedisSentinelCommand(client, ProtocolCommand.ACL_WHOAMI) - .general((cmd)->cmd.aclWhoAmI()) - .run(); - } + public AclUser aclGetUser(final String username) { + final CommandArguments args = CommandArguments.create("username", username); + final AccessControlUserConverter accessControlUserConverter = new AccessControlUserConverter(); - @Override - public Long aclDelUser(final String... usernames){ - final CommandArguments args = CommandArguments.create("usernames", (Object[]) usernames); - return new JedisSentinelCommand(client, ProtocolCommand.ACL_DELUSER) - .general((cmd)->{ - if(usernames.length > 1){ - return cmd.aclDelUser(usernames[0], Arrays.subarray(usernames, 1, usernames.length - 1)); - }else{ - return cmd.aclDelUser(usernames[0]); - } - }) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_GETUSER, (cmd)->cmd.aclGetUser(username), + accessControlUserConverter) + .run(args); + } } @Override - public Long aclDelUser(final byte[]... usernames){ + public AclUser aclGetUser(final byte[] username) { + final CommandArguments args = CommandArguments.create("username", username); + final AccessControlUserConverter accessControlUserConverter = new AccessControlUserConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_GETUSER, (cmd)->cmd.aclGetUser(username), + accessControlUserConverter) + .run(args); + } + } + + @Override + public List aclUsers() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_USERS, (cmd)->cmd.aclUsers(), (v)->v) + .run(); + } + } + + @Override + public String aclWhoAmI() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_WHOAMI, (cmd)->cmd.aclWhoAmI(), (v)->v) + .run(); + } + } + + @Override + public Long aclDelUser(final String... usernames) { final CommandArguments args = CommandArguments.create("usernames", (Object[]) usernames); - return new JedisSentinelCommand(client, ProtocolCommand.ACL_DELUSER) - .general((cmd)->{ - if(usernames.length > 1){ - return cmd.aclDelUser(usernames[0], Arrays.subarray(usernames, 1, usernames.length - 1)); - }else{ - return cmd.aclDelUser(usernames[0]); - } - }) - .run(args); - } - @Override - public String aclGenPass(){ - return new JedisSentinelCommand(client, ProtocolCommand.ACL_GENPASS) - .general((cmd)->cmd.aclGenPass()) - .run(); - } - - @Override - public List aclList(){ - return new JedisSentinelCommand>(client, ProtocolCommand.ACL_LIST) - .general((cmd)->cmd.aclList()) - .run(); + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.ACL_DELUSER) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.ACL_DELUSER) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_DELUSER, (cmd)->cmd.aclDelUser(usernames), + (v)->v) + .run(args); + } } @Override - public Status aclLoad(){ - return new JedisSentinelCommand(client, ProtocolCommand.ACL_LOAD) - .general((cmd)->cmd.aclLoad(), OkStatusConverter.INSTANCE) - .run(); - } - - @Override - public List aclLog(){ - return new JedisSentinelCommand>(client, ProtocolCommand.ACL_LOG) - .general((cmd)->cmd.aclLog(), AccessControlLogEntryConverter.LIST_CONVERTER) - .run(); - } + public Long aclDelUser(final byte[]... usernames) { + final CommandArguments args = CommandArguments.create("usernames", (Object[]) usernames); - @Override - public List aclLog(final long count){ + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.ACL_DELUSER) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.ACL_DELUSER) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_DELUSER, (cmd)->cmd.aclDelUser(usernames), + (v)->v) + .run(args); + } + } + + @Override + public String aclGenPass() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_GENPASS, (cmd)->cmd.aclGenPass(), (v)->v) + .run(); + } + } + + @Override + public List aclList() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_LIST, (cmd)->cmd.aclList(), (v)->v) + .run(); + } + } + + @Override + public Status aclLoad() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_LOAD, (cmd)->cmd.aclLoad(), okStatusConverter) + .run(); + } + } + + @Override + public List aclLog() { + final ListConverter listAccessControlLogEntryConverter = + AccessControlLogEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_LOG, (cmd)->cmd.aclLog(), + listAccessControlLogEntryConverter) + .run(); + } + } + + @Override + public List aclLog(final long count) { final CommandArguments args = CommandArguments.create("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ACL_LOG) - .general((cmd)->cmd.aclLog((int) count), AccessControlLogEntryConverter.LIST_CONVERTER) - .run(args); - } - - @Override - public Status aclLogReset(){ - return new JedisSentinelCommand(client, ProtocolCommand.ACL_LOGREST) - .general((cmd)->cmd.aclLogReset(), OkStatusConverter.INSTANCE) - .run(); - } - - @Override - public Status aclLogSave(){ - return new JedisSentinelCommand(client, ProtocolCommand.ACL_LOGSAVE) - .run(); - } - - @Override - public String bgRewriteAof(){ - return new JedisSentinelCommand(client, ProtocolCommand.BGREWRITEAOF) - .general((cmd)->cmd.bgrewriteaof()) - .run(); - } - - @Override - public String bgSave(){ - return new JedisSentinelCommand(client, ProtocolCommand.BGREWRITEAOF) - .general((cmd)->cmd.bgsave()) - .run(); - } - - @Override - public Status configSet(final String parameter, final String value){ + final ListConverter listAccessControlLogEntryConverter = + AccessControlLogEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_LOG, (cmd)->cmd.aclLog((int) count), + listAccessControlLogEntryConverter) + .run(args); + } + } + + @Override + public Status aclLogReset() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ACL_LOGREST, (cmd)->cmd.aclLogReset(), + okStatusConverter) + .run(); + } + } + + @Override + public Status aclLogSave() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + }else{ + return new JedisSentinelCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + } + } + + @Override + public String bgRewriteAof() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BGREWRITEAOF, (cmd)->cmd.bgrewriteaof(), (v)->v) + .run(); + } + } + + @Override + public String bgSave() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.BGSAVE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.BGSAVE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BGSAVE, (cmd)->cmd.bgsave(), (v)->v) + .run(); + } + } + + @Override + public Status configSet(final String parameter, final String value) { final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.CONFIG_SET) - .general((cmd)->cmd.configSet(parameter, value), OkStatusConverter.INSTANCE) - .run(args); - } - @Override - public Status configSet(final byte[] parameter, final byte[] value){ - final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.CONFIG_SET) - .general((cmd)->cmd.configSet(parameter, value), OkStatusConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CONFIG_SET, + (cmd)->cmd.configSet(parameter, value), okStatusConverter) + .run(args); + } } @Override - public List configGet(final String parameter){ - final CommandArguments args = CommandArguments.create("parameter", parameter); - return new JedisSentinelCommand>(client, ProtocolCommand.CONFIG_GET) - .general((cmd)->cmd.configGet(parameter)) - .run(args); - } + public Status configSet(final byte[] parameter, final byte[] value) { + final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); - @Override - public List configGet(final byte[] parameter){ + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CONFIG_SET, + (cmd)->cmd.configSet(parameter, value), okStatusConverter) + .run(args); + } + } + + @Override + public Status configSet(final Map configs) { + final CommandArguments args = CommandArguments.create("configs", configs); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CONFIG_SET, (cmd)->{ + configs.forEach(cmd::configSet); + return Status.SUCCESS; + }, (v)->v) + .run(args); + } + } + + @Override + public Map configGet(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, Map>(client, + ProtocolCommand.CONFIG_GET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, Map>(client, + ProtocolCommand.CONFIG_GET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CONFIG_GET, (cmd)->cmd.configGet(pattern), + (v)->v) + .run(args); + } + } + + @Override + public Map configGet(final byte[] parameter) { final CommandArguments args = CommandArguments.create("parameter", parameter); - return new JedisSentinelCommand>(client, ProtocolCommand.CONFIG_GET) - .general((cmd)->cmd.configGet(parameter)) - .run(args); - } - - @Override - public Status configResetStat(){ - return new JedisSentinelCommand(client, ProtocolCommand.CONFIG_RESETSTAT) - .general((cmd)->cmd.configResetStat(), OkStatusConverter.INSTANCE) - .run(); - } - - @Override - public Status configRewrite(){ - return new JedisSentinelCommand(client, ProtocolCommand.CONFIG_REWRITE) - .general((cmd)->cmd.configRewrite(), OkStatusConverter.INSTANCE) - .run(); - } - - @Override - public Long dbSize(){ - return new JedisSentinelCommand(client, ProtocolCommand.DBSIZE) - .general((cmd)->cmd.dbSize()).pipeline((cmd)->cmd.dbSize()) - .run(); - } - - @Override - public Status failover(){ - return new JedisSentinelCommand(client, ProtocolCommand.FAILOVER) - .general((cmd)->cmd.failover(), OkStatusConverter.INSTANCE) - .run(); - } - @Override - public Status failover(final String host, final int port){ + if(isPipeline()){ + return new JedisSentinelPipelineCommand, Map>(client, + ProtocolCommand.CONFIG_GET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, Map>(client, + ProtocolCommand.CONFIG_GET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CONFIG_GET, (cmd)->cmd.configGet(parameter), + (v)->v) + .run(args); + } + } + + @Override + public Status configResetStat() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CONFIG_RESETSTAT) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CONFIG_RESETSTAT) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CONFIG_RESETSTAT, (cmd)->cmd.configResetStat(), + okStatusConverter) + .run(); + } + } + + @Override + public Status configRewrite() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.CONFIG_REWRITE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.CONFIG_REWRITE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.CONFIG_REWRITE, (cmd)->cmd.configRewrite(), + okStatusConverter) + .run(); + } + } + + @Override + public Long dbSize() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.DBSIZE, (cmd)->cmd.dbSize(), (v)->v) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.DBSIZE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.DBSIZE, (cmd)->cmd.dbSize(), (v)->v) + .run(); + } + } + + @Override + public Status failover() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.FAILOVER) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.FAILOVER) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.FAILOVER, (cmd)->cmd.failover(), + okStatusConverter) + .run(); + } + } + + @Override + public Status failover(final String host, final int port) { final CommandArguments args = CommandArguments.create("host", host).put("port", port); - final JedisFailoverParams params = new JedisFailoverParams(host, port); - return new JedisSentinelCommand(client, ProtocolCommand.FAILOVER) - .general((cmd)->cmd.failover(params), OkStatusConverter.INSTANCE) - .run(args); + final FailoverParams failoverParams = new JedisFailoverParams(host, port); + + return failover(failoverParams, args); } @Override - public Status failover(final String host, final int port, final int timeout){ + public Status failover(final String host, final int port, final int timeout) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("timeout", timeout); - final JedisFailoverParams params = new JedisFailoverParams(host, port, timeout); - return new JedisSentinelCommand(client, ProtocolCommand.FAILOVER) - .general((cmd)->cmd.failover(params), OkStatusConverter.INSTANCE) - .run(args); + final FailoverParams failoverParams = new JedisFailoverParams(host, port, timeout); + + return failover(failoverParams, args); } @Override - public Status failover(final String host, final int port, final boolean isForce, final int timeout){ + public Status failover(final String host, final int port, final boolean isForce, final int timeout) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("isForce", isForce) .put("timeout", timeout); - final JedisFailoverParams params = new JedisFailoverParams(host, port, timeout, isForce); - return new JedisSentinelCommand(client, ProtocolCommand.FAILOVER) - .general((cmd)->cmd.failover(params), OkStatusConverter.INSTANCE) - .run(args); - } + final FailoverParams failoverParams = new JedisFailoverParams(host, port, timeout, isForce); - @Override - public Status failover(final int timeout){ - final CommandArguments args = CommandArguments.create("timeout", timeout); - final JedisFailoverParams params = new JedisFailoverParams(timeout); - return new JedisSentinelCommand(client, ProtocolCommand.FAILOVER) - .general((cmd)->cmd.failover(params), OkStatusConverter.INSTANCE) - .run(args); + return failover(failoverParams, args); } @Override - public Status flushAll(){ - return new JedisSentinelCommand(client, ProtocolCommand.FLUSHALL) - .general((cmd)->cmd.flushAll(), OkStatusConverter.INSTANCE) - .run(); - } + public Status failover(final int timeout) { + final CommandArguments args = CommandArguments.create("timeout", timeout); + final FailoverParams failoverParams = new JedisFailoverParams(timeout); - @Override - public Status flushAll(final FlushMode mode){ - final CommandArguments args = CommandArguments.create("mode", mode); - return new JedisSentinelCommand(client, ProtocolCommand.FLUSHALL) - .general((cmd)->cmd.flushAll(FlushModeConverter.INSTANCE.convert(mode)), OkStatusConverter.INSTANCE) - .run(args); + return failover(failoverParams, args); } @Override - public Status flushDb(){ - return new JedisSentinelCommand(client, ProtocolCommand.FLUSHDB) - .general((cmd)->cmd.flushDB(), OkStatusConverter.INSTANCE) - .run(); + public Status flushAll() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.FLUSHALL) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.FLUSHALL) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.FLUSHALL, (cmd)->cmd.flushAll(), + okStatusConverter) + .run(); + } } @Override - public Status flushDb(final FlushMode mode){ + public Status flushAll(final FlushMode mode) { final CommandArguments args = CommandArguments.create("mode", mode); - return new JedisSentinelCommand(client, ProtocolCommand.FLUSHDB) - .general((cmd)->cmd.flushDB(FlushModeConverter.INSTANCE.convert(mode)), OkStatusConverter.INSTANCE) - .run(args); - } + final redis.clients.jedis.args.FlushMode flushMode = (new FlushModeConverter()).convert(mode); - @Override - public Info info(){ - return new JedisSentinelCommand(client, ProtocolCommand.INFO) - .general((cmd)->cmd.info(), InfoConverter.INSTANCE) - .run(); + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.FLUSHALL) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.FLUSHALL) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.FLUSHALL, (cmd)->cmd.flushAll(flushMode), + okStatusConverter) + .run(args); + } } @Override - public Info info(final Info.Section section){ - final CommandArguments args = CommandArguments.create("section", section); - return new JedisSentinelCommand(client, ProtocolCommand.INFO) - .general((cmd)->cmd.info(section.name().toLowerCase()), InfoConverter.INSTANCE) - .run(args); + public Status flushDb() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.FLUSHDB) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.FLUSHDB) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.flushDB(), okStatusConverter) + .run(); + } } @Override - public Long lastSave(){ - return new JedisSentinelCommand(client, ProtocolCommand.LASTSAVE) - .run(); - } + public Status flushDb(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + final redis.clients.jedis.args.FlushMode flushMode = (new FlushModeConverter()).convert(mode); - @Override - public String memoryDoctor(){ - return new JedisSentinelCommand(client, ProtocolCommand.MEMORY_DOCTOR) - .general((cmd)->cmd.memoryDoctor()) - .run(); + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.FLUSHDB) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.FLUSHDB) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.flushDB(flushMode), + okStatusConverter) + .run(args); + } } @Override - public Status memoryPurge(){ - return new JedisSentinelCommand(client, ProtocolCommand.MEMORY_PURGE) - .run(); - } + public Info info() { + final InfoConverter infoConverter = new InfoConverter(); - @Override - public MemoryStats memoryStats(){ - return new JedisSentinelCommand(client, ProtocolCommand.MEMORY_STATS) - .run(); + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.INFO) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.INFO) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.INFO, (cmd)->cmd.info(), infoConverter) + .run(); + } } @Override - public Long memoryUsage(final String key){ + public Info info(final Info.Section section) { + final CommandArguments args = CommandArguments.create("section", section); + final String sectionName = section.name().toLowerCase(); + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.INFO) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.INFO) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.INFO, (cmd)->cmd.info(sectionName), infoConverter) + .run(args); + } + } + + @Override + public Long lastSave() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.LASTSAVE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.LASTSAVE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.LASTSAVE, (cmd)->cmd.lastsave(), (v)->v) + .run(); + } + } + + @Override + public String memoryDoctor() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MEMORY_DOCTOR, (cmd)->cmd.memoryDoctor(), (v)->v) + .run(); + } + } + + @Override + public Status memoryPurge() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MEMORY_PURGE, (cmd)->cmd.memoryPurge(), + okStatusConverter) + .run(); + } + } + + @Override + public MemoryStats memoryStats() { + final MemoryStatsConverter memoryStatsConverter = new MemoryStatsConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MEMORY_STATS, (cmd)->cmd.memoryStats(), + memoryStatsConverter) + .run(); + } + } + + @Override + public Long memoryUsage(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.MEMORY_USAGE) - .general((cmd)->cmd.memoryUsage(key)) - .pipeline((cmd)->cmd.memoryUsage(key)) - .transaction((cmd)->cmd.memoryUsage(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } } @Override - public Long memoryUsage(final byte[] key){ + public Long memoryUsage(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.MEMORY_USAGE) - .general((cmd)->cmd.memoryUsage(key)) - .pipeline((cmd)->cmd.memoryUsage(key)) - .transaction((cmd)->cmd.memoryUsage(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } } @Override - public Long memoryUsage(final String key, final int samples){ + public Long memoryUsage(final String key, final int samples) { final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); - return new JedisSentinelCommand(client, ProtocolCommand.MEMORY_USAGE) - .general((cmd)->cmd.memoryUsage(key, samples)) - .pipeline((cmd)->cmd.memoryUsage(key, samples)) - .transaction((cmd)->cmd.memoryUsage(key, samples)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + } } @Override - public Long memoryUsage(final byte[] key, final int samples){ + public Long memoryUsage(final byte[] key, final int samples) { final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); - return new JedisSentinelCommand(client, ProtocolCommand.MEMORY_USAGE) - .general((cmd)->cmd.memoryUsage(key, samples)) - .pipeline((cmd)->cmd.memoryUsage(key, samples)) - .transaction((cmd)->cmd.memoryUsage(key, samples)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + } } @Override - public List moduleList(){ - return new JedisSentinelCommand>(client, ProtocolCommand.MODULE_LIST) - .general((cmd)->cmd.moduleList(), ModuleConverter.LIST_CONVERTER) - .run(); + public List moduleList() { + final ListConverter listModuleConverter = ModuleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, ProtocolCommand.MODULE_LIST) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, ProtocolCommand.MODULE_LIST) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MODULE_LIST, (cmd)->cmd.moduleList(), + listModuleConverter) + .run(); + } } @Override - public Status moduleLoad(final String path, final String... arguments){ + public Status moduleLoad(final String path, final String... arguments) { final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); - return new JedisSentinelCommand(client, ProtocolCommand.MODULE_LOAD) - .general((cmd)->cmd.moduleLoad(path, arguments), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MODULE_LOAD, + (cmd)->cmd.moduleLoad(path, arguments), okStatusConverter) + .run(args); + } } @Override - public Status moduleUnLoad(final String name){ + public Status moduleUnLoad(final String name) { final CommandArguments args = CommandArguments.create("name", name); - return new JedisSentinelCommand(client, ProtocolCommand.MODULE_UNLOAD) - .general((cmd)->cmd.moduleUnload(name), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MODULE_UNLOAD, (cmd)->cmd.moduleUnload(name), + okStatusConverter) + .run(args); + } } @Override - public void monitor(final RedisMonitor redisMonitor){ + public void monitor(final RedisMonitor redisMonitor) { final CommandArguments args = CommandArguments.create("redisMonitor", redisMonitor); - new JedisSentinelCommand(client, ProtocolCommand.MONITOR) - .general((cmd)->{ - cmd.monitor(new JedisMonitor() { - @Override - public void onCommand(final String command){ - redisMonitor.onCommand(command); - } + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + }else{ + new JedisSentinelCommand<>(client, ProtocolCommand.MONITOR, (cmd)->{ + cmd.monitor(new JedisMonitor() { + + @Override + public void onCommand(final String command) { + redisMonitor.onCommand(command); + } - }); - return null; - }) - .run(args); + }); + return null; + }, (v)->v) + .run(args); + } } @Override - public Object pSync(final String replicationId, final long offset){ + public Object pSync(final String replicationId, final long offset) { final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); - return new JedisSentinelCommand<>(client, ProtocolCommand.PSYNC) - .run(args); + return pSync(args); } @Override - public Object pSync(final byte[] replicationId, final long offset){ + public Object pSync(final byte[] replicationId, final long offset) { final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); - return new JedisSentinelCommand<>(client, ProtocolCommand.PSYNC) - .run(args); - } - - @Override - public void sync(){ - new JedisSentinelCommand(client, ProtocolCommand.SYNC) - .pipeline((cmd)->{ - cmd.sync(); - return null; - }) - .run(); + return pSync(args); } @Override - public Status replicaOf(final String host, final int port){ - final CommandArguments args = CommandArguments.create("host", host).put("port", port); - return new JedisSentinelCommand(client, ProtocolCommand.REPLICAOF) - .general((cmd)->cmd.replicaof(host, port), OkStatusConverter.INSTANCE) - .run(args); + public void sync() { + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SYNC, (cmd)->{ + cmd.sync(); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SYNC) + .run(); + }else{ + new JedisSentinelCommand<>(client, ProtocolCommand.SYNC) + .run(); + } } @Override - public Status slaveOf(final String host, final int port){ + public Status replicaOf(final String host, final int port) { final CommandArguments args = CommandArguments.create("host", host).put("port", port); - return new JedisSentinelCommand(client, ProtocolCommand.SLAVEOF) - .general((cmd)->cmd.slaveof(host, port), OkStatusConverter.INSTANCE) - .run(args); - } - @Override - public List role(){ - return new JedisSentinelCommand>(client, ProtocolCommand.ROLE) - .general((cmd)->cmd.role(), RoleConverter.LIST_CONVERTER) - .run(); + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.REPLICAOF, (cmd)->cmd.replicaof(host, port), + okStatusConverter) + .run(args); + } } @Override - public Status save(){ - return new JedisSentinelCommand(client, ProtocolCommand.SAVE) - .general((cmd)->cmd.save(), OkStatusConverter.INSTANCE) - .run(); - } - - @Override - public void shutdown(){ - new JedisSentinelCommand>(client, ProtocolCommand.SHUTDOWN) - .general((cmd)->{ - cmd.shutdown(); - return null; - }) - .run(); - } + public Status slaveOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); - @Override - public void shutdown(final boolean save){ + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.SLAVEOF) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.SLAVEOF) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SLAVEOF, (cmd)->cmd.slaveof(host, port), + okStatusConverter) + .run(args); + } + } + + @Override + public Role role() { + final RoleConverter roleConverter = new RoleConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.ROLE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.ROLE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ROLE, (cmd)->cmd.role(), roleConverter) + .run(); + } + } + + @Override + public Status save() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.SAVE) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.SAVE) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SAVE, (cmd)->cmd.save(), okStatusConverter) + .run(); + } + } + + @Override + public void shutdown() { + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + }else{ + new JedisSentinelCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(); + return null; + }, (v)->v) + .run(); + } + } + + @Override + public void shutdown(final boolean save) { final CommandArguments args = CommandArguments.create("save", save); - new JedisSentinelCommand>(client, ProtocolCommand.SHUTDOWN) - .general((cmd)->{ - final SaveMode saveMode = save ? SaveMode.SAVE : SaveMode.NOSAVE; - cmd.shutdown(saveMode); - return null; - }) - .run(args); - } - - @Override - public List slowLogGet(){ - return new JedisSentinelCommand>(client, ProtocolCommand.SLOWLOG_GET) - .general((cmd)->cmd.slowlogGet(), SlowlogConverter.LIST_CONVERTER) - .run(); - } - - @Override - public List slowLogGet(final long count){ + final SaveMode saveMode = save ? SaveMode.SAVE : SaveMode.NOSAVE; + + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + }else{ + new JedisSentinelCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(saveMode); + return null; + }, (v)->v) + .run(); + } + } + + @Override + public List slowLogGet() { + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + ProtocolCommand.SLOWLOG_GET) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + } + } + + @Override + public List slowLogGet(final long count) { final CommandArguments args = CommandArguments.create("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.SLOWLOG_GET) - .general((cmd)->cmd.slowlogGet(count), SlowlogConverter.LIST_CONVERTER) - .run(args); - } - - @Override - public Long slowLogLen(){ - return new JedisSentinelCommand(client, ProtocolCommand.SLOWLOG_LEN) - .general((cmd)->cmd.slowlogLen()) - .run(); - } - - @Override - public Status slowLogReset(){ - return new JedisSentinelCommand(client, ProtocolCommand.SLOWLOG_RESET) - .general((cmd)->cmd.slowlogReset(), OkStatusConverter.INSTANCE) - .run(); - } - - @Override - public Status swapdb(final int db1, final int db2){ + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand, List>(client, + ProtocolCommand.SLOWLOG_GET) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SLOWLOG_GET, (cmd)->cmd.slowlogGet(count), + listSlowlogConverter) + .run(args); + } + } + + @Override + public Long slowLogLen() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.SLOWLOG_LEN) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.SLOWLOG_LEN) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SLOWLOG_RESET, (cmd)->cmd.slowlogLen(), (v)->v) + .run(); + } + } + + @Override + public Status slowLogReset() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.SLOWLOG_RESET) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.SLOWLOG_RESET) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + } + } + + @Override + public Status swapdb(final int db1, final int db2) { final CommandArguments args = CommandArguments.create("db1", db1).put("db2", db2); - return new JedisSentinelCommand(client, ProtocolCommand.SWAPDB) - .general((cmd)->cmd.swapDB(db1, db2), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.swapDB(db1, db2), OkStatusConverter.INSTANCE) - .run(args); - } - @Override - public RedisServerTime time(){ - return new JedisSentinelCommand(client, ProtocolCommand.TIME) - .general((cmd)->cmd.time(), RedisServerTimeConverter.INSTANCE) - .pipeline((cmd)->cmd.time(), RedisServerTimeConverter.INSTANCE) - .run(); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SWAPDB, (cmd)->cmd.swapDB(db1, db2), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.SWAPDB) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SWAPDB, (cmd)->cmd.swapDB(db1, db2), + okStatusConverter) + .run(args); + } + } + + @Override + public RedisServerTime time() { + final RedisServerTimeConverter redisServerTimeConverter = new RedisServerTimeConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.TIME, (cmd)->cmd.time(), + redisServerTimeConverter) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.TIME) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.TIME, (cmd)->cmd.time(), redisServerTimeConverter) + .run(); + } + } + + private Status failover(final FailoverParams failoverParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.FAILOVER) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand(client, ProtocolCommand.FAILOVER) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.FAILOVER, (cmd)->cmd.failover(failoverParams), + okStatusConverter) + .run(args); + } + } + + private Object pSync(final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelSetOperations.java index c65893afb..ba2e13df7 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelSetOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelSetOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -29,9 +29,9 @@ import com.buession.redis.core.ScanResult; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; import com.buession.redis.core.internal.jedis.JedisScanParams; +import redis.clients.jedis.params.ScanParams; import java.util.List; import java.util.Set; @@ -44,458 +44,753 @@ */ public final class JedisSentinelSetOperations extends AbstractSetOperations { - public JedisSentinelSetOperations(final JedisSentinelClient client){ + public JedisSentinelSetOperations(final JedisSentinelClient client) { super(client); } @Override - public Long sAdd(final String key, final String... members){ + public Long sAdd(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisSentinelCommand(client, ProtocolCommand.SADD) - .general((cmd)->cmd.sadd(key, members)) - .pipeline((cmd)->cmd.sadd(key, members)) - .transaction((cmd)->cmd.sadd(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } } @Override - public Long sAdd(final byte[] key, final byte[]... members){ + public Long sAdd(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisSentinelCommand(client, ProtocolCommand.SADD) - .general((cmd)->cmd.sadd(key, members)) - .pipeline((cmd)->cmd.sadd(key, members)) - .transaction((cmd)->cmd.sadd(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } } @Override - public Long sCard(final String key){ + public Long sCard(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.SCARD) - .general((cmd)->cmd.scard(key)) - .pipeline((cmd)->cmd.scard(key)) - .transaction((cmd)->cmd.scard(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } } @Override - public Long sCard(final byte[] key){ + public Long sCard(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.SCARD) - .general((cmd)->cmd.scard(key)) - .pipeline((cmd)->cmd.scard(key)) - .transaction((cmd)->cmd.scard(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } } @Override - public Set sDiff(final String... keys){ + public Set sDiff(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand>(client, ProtocolCommand.SDIFF) - .general((cmd)->cmd.sdiff(keys)) - .pipeline((cmd)->cmd.sdiff(keys)) - .transaction((cmd)->cmd.sdiff(keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + } } @Override - public Set sDiff(final byte[]... keys){ + public Set sDiff(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand>(client, ProtocolCommand.SDIFF) - .general((cmd)->cmd.sdiff(keys)) - .pipeline((cmd)->cmd.sdiff(keys)) - .transaction((cmd)->cmd.sdiff(keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + } } @Override - public Long sDiffStore(final String destKey, final String... keys){ + public Long sDiffStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.SDIFFSTORE) - .general((cmd)->cmd.sdiffstore(destKey, keys)) - .pipeline((cmd)->cmd.sdiffstore(destKey, keys)) - .transaction((cmd)->cmd.sdiffstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long sDiffStore(final byte[] destKey, final byte[]... keys){ + public Long sDiffStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.SDIFFSTORE) - .general((cmd)->cmd.sdiffstore(destKey, keys)) - .pipeline((cmd)->cmd.sdiffstore(destKey, keys)) - .transaction((cmd)->cmd.sdiffstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Set sInter(final String... keys){ + public Set sInter(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand>(client, ProtocolCommand.SINTER) - .general((cmd)->cmd.sinter(keys)) - .pipeline((cmd)->cmd.sinter(keys)) - .transaction((cmd)->cmd.sinter(keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + } } @Override - public Set sInter(final byte[]... keys){ + public Set sInter(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand>(client, ProtocolCommand.SINTER) - .general((cmd)->cmd.sinter(keys)) - .pipeline((cmd)->cmd.sinter(keys)) - .transaction((cmd)->cmd.sinter(keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + } } @Override - public Long sInterStore(final String destKey, final String... keys){ + public Long sInterStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.SINTERSTORE) - .general((cmd)->cmd.sinterstore(destKey, keys)) - .pipeline((cmd)->cmd.sinterstore(destKey, keys)) - .transaction((cmd)->cmd.sinterstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long sInterStore(final byte[] destKey, final byte[]... keys){ + public Long sInterStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.SINTERSTORE) - .general((cmd)->cmd.sinterstore(destKey, keys)) - .pipeline((cmd)->cmd.sinterstore(destKey, keys)) - .transaction((cmd)->cmd.sinterstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Boolean sIsMember(final String key, final String member){ + public Boolean sIsMember(final String key, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisSentinelCommand(client, ProtocolCommand.SISMEMBER) - .general((cmd)->cmd.sismember(key, member)) - .pipeline((cmd)->cmd.sismember(key, member)) - .transaction((cmd)->cmd.sismember(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + } } @Override - public Boolean sIsMember(final byte[] key, final byte[] member){ + public Boolean sIsMember(final byte[] key, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisSentinelCommand(client, ProtocolCommand.SISMEMBER) - .general((cmd)->cmd.sismember(key, member)) - .pipeline((cmd)->cmd.sismember(key, member)) - .transaction((cmd)->cmd.sismember(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + } } @Override - public List smIsMember(final String key, final String... members){ + public List smIsMember(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisSentinelCommand>(client, ProtocolCommand.SMISMEMBER) - .general((cmd)->cmd.smismember(key, members)) - .pipeline((cmd)->cmd.smismember(key, members)) - .transaction((cmd)->cmd.smismember(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SMISMEMBER, (cmd)->cmd.smismember(key, members), + (v)->v) + .run(args); + } } @Override - public List smIsMember(final byte[] key, final byte[]... members){ + public List smIsMember(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisSentinelCommand>(client, ProtocolCommand.SMISMEMBER) - .general((cmd)->cmd.smismember(key, members)) - .pipeline((cmd)->cmd.smismember(key, members)) - .transaction((cmd)->cmd.smismember(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SMISMEMBER, (cmd)->cmd.smismember(key, members), + (v)->v) + .run(args); + } } @Override - public Set sMembers(final String key){ + public Set sMembers(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand>(client, ProtocolCommand.SMEMBERS) - .general((cmd)->cmd.smembers(key)) - .pipeline((cmd)->cmd.smembers(key)) - .transaction((cmd)->cmd.smembers(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + } } @Override - public Set sMembers(final byte[] key){ + public Set sMembers(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand>(client, ProtocolCommand.SMEMBERS) - .general((cmd)->cmd.smembers(key)) - .pipeline((cmd)->cmd.smembers(key)) - .transaction((cmd)->cmd.smembers(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + } } @Override - public Status sMove(final String key, final String destKey, final String member){ + public Status sMove(final String key, final String destKey, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); - return new JedisSentinelCommand(client, ProtocolCommand.SMOVE) - .general((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + } } @Override - public Status sMove(final byte[] key, final byte[] destKey, final byte[] member){ + public Status sMove(final byte[] key, final byte[] destKey, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); - return new JedisSentinelCommand(client, ProtocolCommand.SMOVE) - .general((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SMOVE, + (cmd)->cmd.smove(key, destKey, member), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + } } @Override - public String sPop(final String key){ + public String sPop(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.SPOP) - .general((cmd)->cmd.spop(key)) - .pipeline((cmd)->cmd.spop(key)) - .transaction((cmd)->cmd.spop(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + } } @Override - public byte[] sPop(final byte[] key){ + public byte[] sPop(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.SPOP) - .general((cmd)->cmd.spop(key)) - .pipeline((cmd)->cmd.spop(key)) - .transaction((cmd)->cmd.spop(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + } } @Override - public Set sPop(final String key, final long count){ + public Set sPop(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.SPOP) - .general((cmd)->cmd.spop(key, count)) - .pipeline((cmd)->cmd.spop(key, count)) - .transaction((cmd)->cmd.spop(key, count)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + } } @Override - public Set sPop(final byte[] key, final long count){ + public Set sPop(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.SPOP) - .general((cmd)->cmd.spop(key, count)) - .pipeline((cmd)->cmd.spop(key, count)) - .transaction((cmd)->cmd.spop(key, count)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + } } @Override - public String sRandMember(final String key){ + public String sRandMember(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.SRANDMEMBER) - .general((cmd)->cmd.srandmember(key)) - .pipeline((cmd)->cmd.srandmember(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + } } @Override - public byte[] sRandMember(final byte[] key){ + public byte[] sRandMember(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.SRANDMEMBER) - .general((cmd)->cmd.srandmember(key)) - .pipeline((cmd)->cmd.srandmember(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + } } @Override - public List sRandMember(final String key, final long count){ + public List sRandMember(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.SRANDMEMBER) - .general((cmd)->cmd.srandmember(key, (int) count)) - .pipeline((cmd)->cmd.srandmember(key, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + } } @Override - public List sRandMember(final byte[] key, final long count){ + public List sRandMember(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.SRANDMEMBER) - .general((cmd)->cmd.srandmember(key, (int) count)) - .pipeline((cmd)->cmd.srandmember(key, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + } } @Override - public Long sRem(final String key, final String... members){ + public Long sRem(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisSentinelCommand(client, ProtocolCommand.SREM) - .general((cmd)->cmd.srem(key, members)) - .pipeline((cmd)->cmd.srem(key, members)) - .transaction((cmd)->cmd.srem(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } } @Override - public Long sRem(final byte[] key, final byte[]... members){ + public Long sRem(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisSentinelCommand(client, ProtocolCommand.SREM) - .general((cmd)->cmd.srem(key, members)) - .pipeline((cmd)->cmd.srem(key, members)) - .transaction((cmd)->cmd.srem(key, members)) - .run(args); - } - @Override - public ScanResult> sScan(final String key, final String cursor){ - final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisSentinelCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } } @Override - public ScanResult> sScan(final byte[] key, final byte[] cursor){ + public ScanResult> sScan(final String key, final String cursor) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisSentinelCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); - } - - @Override - public ScanResult> sScan(final String key, final String cursor, final String pattern){ + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisSentinelCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return sScan(key, cursor, scanParams, args); } @Override - public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern){ + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisSentinelCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return sScan(key, cursor, scanParams, args); } @Override - public ScanResult> sScan(final String key, final String cursor, final long count){ + public ScanResult> sScan(final String key, final String cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisSentinelCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return sScan(key, cursor, scanParams, args); } @Override - public ScanResult> sScan(final byte[] key, final byte[] cursor, final long count){ + public ScanResult> sScan(final byte[] key, final byte[] cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisSentinelCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return sScan(key, cursor, scanParams, args); } @Override public ScanResult> sScan(final String key, final String cursor, final String pattern, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisSentinelCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return sScan(key, cursor, scanParams, args); } @Override public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisSentinelCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return sScan(key, cursor, scanParams, args); } @Override - public Set sUnion(final String... keys){ + public Set sUnion(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand>(client, ProtocolCommand.SUNION) - .general((cmd)->cmd.sunion(keys)) - .pipeline((cmd)->cmd.sunion(keys)) - .transaction((cmd)->cmd.sunion(keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + } } @Override - public Set sUnion(final byte[]... keys){ + public Set sUnion(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand>(client, ProtocolCommand.SUNION) - .general((cmd)->cmd.sunion(keys)) - .pipeline((cmd)->cmd.sunion(keys)) - .transaction((cmd)->cmd.sunion(keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + } } @Override - public Long sUnionStore(final String destKey, final String... keys){ + public Long sUnionStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.SUNIONSTORE) - .general((cmd)->cmd.sunionstore(destKey, keys)) - .pipeline((cmd)->cmd.sunionstore(destKey, keys)) - .transaction((cmd)->cmd.sunionstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + } } @Override - public Long sUnionStore(final byte[] destKey, final byte[]... keys){ + public Long sUnionStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.SUNIONSTORE) - .general((cmd)->cmd.sunionstore(destKey, keys)) - .pipeline((cmd)->cmd.sunionstore(destKey, keys)) - .transaction((cmd)->cmd.sunionstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + } + } + + private ScanResult> sScan(final String key, final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelSortedSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelSortedSetOperations.java index ddb94fea5..f638a3c90 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelSortedSetOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelSortedSetOperations.java @@ -19,30 +19,35 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.SetConverter; import com.buession.core.utils.NumberUtils; +import com.buession.lang.KeyValue; import com.buession.redis.client.jedis.JedisSentinelClient; import com.buession.redis.core.Aggregate; import com.buession.redis.core.GtLt; -import com.buession.redis.core.KeyedZSetElement; import com.buession.redis.core.NxXx; import com.buession.redis.core.ScanResult; import com.buession.redis.core.Tuple; import com.buession.redis.core.ZRangeBy; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.jedis.response.KeyedZSetElementConverter; +import com.buession.redis.core.internal.convert.jedis.response.KeyValueConverter; import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; import com.buession.redis.core.internal.convert.jedis.response.TupleConverter; import com.buession.redis.core.internal.jedis.JedisScanParams; import com.buession.redis.core.internal.jedis.JedisZAddParams; import com.buession.redis.core.internal.jedis.JedisZParams; import com.buession.redis.core.internal.jedis.JedisZRangeParams; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.params.ZAddParams; import redis.clients.jedis.params.ZParams; +import redis.clients.jedis.params.ZRangeParams; import java.util.List; import java.util.Map; @@ -56,2190 +61,3243 @@ */ public final class JedisSentinelSortedSetOperations extends AbstractSortedSetOperations { - public JedisSentinelSortedSetOperations(final JedisSentinelClient client){ + public JedisSentinelSortedSetOperations(final JedisSentinelClient client) { super(client); } @Override - public Tuple zPopMin(final String key){ + public Tuple zPopMin(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.ZPOPMIN) - .general((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .pipeline((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .transaction((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .run(args); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + } } @Override - public Tuple zPopMin(final byte[] key){ + public Tuple zPopMin(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.ZPOPMIN) - .general((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .pipeline((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .transaction((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .run(args); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + } } @Override - public List zPopMin(final String key, final long count){ + public List zPopMin(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZPOPMIN) - .general((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + } } @Override - public List zPopMin(final byte[] key, final long count){ + public List zPopMin(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZPOPMIN) - .general((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, + (cmd)->cmd.zpopmin(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + } } @Override - public Tuple zPopMax(final String key){ + public Tuple zPopMax(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.ZPOPMAX) - .general((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .pipeline((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .transaction((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .run(args); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + } } @Override - public Tuple zPopMax(final byte[] key){ + public Tuple zPopMax(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.ZPOPMAX) - .general((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .pipeline((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .transaction((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .run(args); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + } } @Override - public List zPopMax(final String key, final long count){ + public List zPopMax(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZPOPMAX) - .general((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + } } @Override - public List zPopMax(final byte[] key, final long count){ + public List zPopMax(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZPOPMAX) - .general((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .run(args); - } + final ListConverter listTupleConverter = TupleConverter.listConverter(); - @Override - public KeyedZSetElement bzPopMin(final String[] keys, final int timeout){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisSentinelCommand(client, ProtocolCommand.BZPOPMIN) - .general((cmd)->cmd.bzpopmin(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .pipeline((cmd)->cmd.bzpopmin(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .transaction((cmd)->cmd.bzpopmin(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, + (cmd)->cmd.zpopmax(key, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + } } @Override - public KeyedZSetElement bzPopMin(final byte[][] keys, final int timeout){ + public KeyValue bzPopMin(final String[] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisSentinelCommand(client, ProtocolCommand.BZPOPMIN) - .general((cmd)->cmd.bzpopmin(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .pipeline((cmd)->cmd.bzpopmin(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .transaction((cmd)->cmd.bzpopmin(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .run(args); - } - - @Override - public KeyedZSetElement bzPopMax(final String[] keys, final int timeout){ + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMin(final byte[][] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisSentinelCommand(client, ProtocolCommand.BZPOPMAX) - .general((cmd)->cmd.bzpopmax(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .pipeline((cmd)->cmd.bzpopmax(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .transaction((cmd)->cmd.bzpopmax(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .run(args); - } - - @Override - public KeyedZSetElement bzPopMax(final byte[][] keys, final int timeout){ + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final String[] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisSentinelCommand(client, ProtocolCommand.BZPOPMIN) - .general((cmd)->cmd.bzpopmax(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .pipeline((cmd)->cmd.bzpopmax(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .transaction((cmd)->cmd.bzpopmax(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .run(args); - } - - @Override - public Long zAdd(final String key, final Map members){ + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), keyValueConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public Long zAdd(final String key, final Map members) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members)) - .pipeline((cmd)->cmd.zadd(key, members)) - .transaction((cmd)->cmd.zadd(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + } } @Override - public Long zAdd(final byte[] key, final Map members){ + public Long zAdd(final byte[] key, final Map members) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members)) - .pipeline((cmd)->cmd.zadd(key, members)) - .transaction((cmd)->cmd.zadd(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + } } @Override - public Long zAdd(final String key, final Map members, final NxXx nxXx){ + public Long zAdd(final String key, final Map members, final NxXx nxXx) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); - final JedisZAddParams params = new JedisZAddParams(nxXx); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final NxXx nxXx){ + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); - final JedisZAddParams params = new JedisZAddParams(nxXx); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final String key, final Map members, final GtLt gtLt){ + public Long zAdd(final String key, final Map members, final GtLt gtLt) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); - final JedisZAddParams params = new JedisZAddParams(gtLt); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(gtLt); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final GtLt gtLt){ + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); - final JedisZAddParams params = new JedisZAddParams(gtLt); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(gtLt); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final String key, final Map members, final boolean ch){ + public Long zAdd(final String key, final Map members, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(ch); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final boolean ch){ + public Long zAdd(final byte[] key, final Map members, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(ch); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt){ + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("gtLt", gtLt); - final JedisZAddParams params = new JedisZAddParams(nxXx, gtLt); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt){ + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("gtLt", gtLt); - final JedisZAddParams params = new JedisZAddParams(nxXx, gtLt); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch){ + public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(nxXx, ch); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch){ + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(nxXx, ch); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch){ + public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) .put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(gtLt, ch); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(gtLt, ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch){ + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) .put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(gtLt, ch); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(gtLt, ch); + + return zAdd(key, members, zAddParams, args); } @Override public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt, - final boolean ch){ + final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("gtLt", gtLt).put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(nxXx, gtLt, ch); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt, ch); + + return zAdd(key, members, zAddParams, args); } @Override public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt, - final boolean ch){ + final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("gtLt", gtLt).put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(nxXx, gtLt, ch); - return new JedisSentinelCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt, ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zCard(final String key){ + public Long zCard(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.ZCARD) - .general((cmd)->cmd.zcard(key)) - .pipeline((cmd)->cmd.zcard(key)) - .transaction((cmd)->cmd.zcard(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } } @Override - public Long zCard(final byte[] key){ + public Long zCard(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.ZCARD) - .general((cmd)->cmd.zcard(key)) - .pipeline((cmd)->cmd.zcard(key)) - .transaction((cmd)->cmd.zcard(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } } @Override - public Long zCount(final String key, final double min, final double max){ + public Long zCount(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand(client, ProtocolCommand.ZCOUNT) - .general((cmd)->cmd.zcount(key, min, max)) - .pipeline((cmd)->cmd.zcount(key, min, max)) - .transaction((cmd)->cmd.zcount(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZCOUNT, + (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } } @Override - public Long zCount(final byte[] key, final double min, final double max){ + public Long zCount(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand(client, ProtocolCommand.ZCOUNT) - .general((cmd)->cmd.zcount(key, min, max)) - .pipeline((cmd)->cmd.zcount(key, min, max)) - .transaction((cmd)->cmd.zcount(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZCOUNT, + (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public Long zCount(final String key, final String min, final String max){ + public Long zCount(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand(client, ProtocolCommand.ZCOUNT) - .general((cmd)->cmd.zcount(key, min, max)) - .pipeline((cmd)->cmd.zcount(key, min, max)) - .transaction((cmd)->cmd.zcount(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZCOUNT, + (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public Long zCount(final byte[] key, final byte[] min, final byte[] max){ + public Long zCount(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand(client, ProtocolCommand.ZCOUNT) - .general((cmd)->cmd.zcount(key, min, max)) - .pipeline((cmd)->cmd.zcount(key, min, max)) - .transaction((cmd)->cmd.zcount(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZCOUNT, + (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } } @Override - public Set zDiff(final String... keys){ + public List zDiff(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand>(client, ProtocolCommand.ZDIFF) - .general((cmd)->cmd.zdiff(keys)) - .pipeline((cmd)->cmd.zdiff(keys)) - .transaction((cmd)->cmd.zdiff(keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + } } @Override - public Set zDiff(final byte[]... keys){ + public List zDiff(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand>(client, ProtocolCommand.ZDIFF) - .general((cmd)->cmd.zdiff(keys)) - .pipeline((cmd)->cmd.zdiff(keys)) - .transaction((cmd)->cmd.zdiff(keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + } } @Override - public Set zDiffWithScores(final String... keys){ + public List zDiffWithScores(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand>(client, ProtocolCommand.ZDIFF) - .general((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .run(args); + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZDIFF, + (cmd)->cmd.zdiffWithScores(keys), listConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + } } @Override - public Set zDiffWithScores(final byte[]... keys){ + public List zDiffWithScores(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand>(client, ProtocolCommand.ZDIFF) - .general((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .run(args); + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZDIFF, + (cmd)->cmd.zdiffWithScores(keys), listConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + } } @Override - public Long zDiffStore(final String destKey, final String... keys){ + public Long zDiffStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.ZDIFFSTORE) - .general((cmd)->cmd.zdiffStore(destKey, keys)).pipeline((cmd)->cmd.zdiffStore(destKey, keys)) - .transaction((cmd)->cmd.zdiffStore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long zDiffStore(final byte[] destKey, final byte[]... keys){ + public Long zDiffStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.ZDIFFSTORE) - .general((cmd)->cmd.zdiffStore(destKey, keys)).pipeline((cmd)->cmd.zdiffStore(destKey, keys)) - .transaction((cmd)->cmd.zdiffStore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Double zIncrBy(final String key, final double increment, final String member){ + public Double zIncrBy(final String key, final double increment, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) .put("member", member); - return new JedisSentinelCommand(client, ProtocolCommand.ZINCRBY) - .general((cmd)->cmd.zincrby(key, increment, member)) - .pipeline((cmd)->cmd.zincrby(key, increment, member)) - .transaction((cmd)->cmd.zincrby(key, increment, member)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + } } @Override - public Double zIncrBy(final byte[] key, final double increment, final byte[] member){ + public Double zIncrBy(final byte[] key, final double increment, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) .put("member", member); - return new JedisSentinelCommand(client, ProtocolCommand.ZINCRBY) - .general((cmd)->cmd.zincrby(key, increment, member)) - .pipeline((cmd)->cmd.zincrby(key, increment, member)) - .transaction((cmd)->cmd.zincrby(key, increment, member)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + } } @Override - public Set zInter(final String... keys){ + public List zInter(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final ZParams params = new JedisZParams(); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final byte[]... keys){ + public List zInter(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final ZParams params = new JedisZParams(); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final String[] keys, final Aggregate aggregate){ + public List zInter(final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final ZParams params = new JedisZParams(aggregate); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final byte[][] keys, final Aggregate aggregate){ + public List zInter(final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final ZParams params = new JedisZParams(aggregate); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final String[] keys, final double... weights){ + public List zInter(final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final ZParams params = new JedisZParams(weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final byte[][] keys, final double... weights){ + public List zInter(final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final ZParams params = new JedisZParams(weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zInter(final String[] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final ZParams params = new JedisZParams(aggregate, weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final ZParams params = new JedisZParams(aggregate, weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInter(keys, zParams, args); } @Override - public Set zInterWithScores(final String... keys){ + public List zInterWithScores(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final ZParams params = new JedisZParams(); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final byte[]... keys){ + public List zInterWithScores(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final ZParams params = new JedisZParams(); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final String[] keys, final Aggregate aggregate){ + public List zInterWithScores(final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final ZParams params = new JedisZParams(aggregate); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final byte[][] keys, final Aggregate aggregate){ + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final ZParams params = new JedisZParams(aggregate); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final String[] keys, final double... weights){ + public List zInterWithScores(final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final ZParams params = new JedisZParams(weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final byte[][] keys, final double... weights){ + public List zInterWithScores(final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final ZParams params = new JedisZParams(weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final ZParams params = new JedisZParams(aggregate, weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final ZParams params = new JedisZParams(aggregate, weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterWithScores(keys, zParams, args); } @Override - public Long zInterStore(final String destKey, final String... keys){ + public Long zInterStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + } } @Override - public Long zInterStore(final byte[] destKey, final byte[]... keys){ + public Long zInterStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + } } @Override - public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate){ + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisSentinelCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterStore(destKey, keys, zParams, args); } @Override - public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate){ + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisSentinelCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterStore(destKey, keys, zParams, args); } @Override - public Long zInterStore(final String destKey, final String[] keys, final double... weights){ + public Long zInterStore(final String destKey, final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisSentinelCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInterStore(destKey, keys, zParams, args); } @Override - public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights){ + public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisSentinelCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInterStore(destKey, keys, zParams, args); } @Override public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate).put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisSentinelCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterStore(destKey, keys, zParams, args); } @Override public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate).put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisSentinelCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterStore(destKey, keys, zParams, args); } @Override - public Long zLexCount(final String key, final double min, final double max){ + public Long zLexCount(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand(client, ProtocolCommand.ZLEXCOUNT) - .general((cmd)->cmd.zlexcount(key, Double.toString(min), Double.toString(max))) - .pipeline((cmd)->cmd.zlexcount(key, Double.toString(min), Double.toString(max))) - .transaction((cmd)->cmd.zlexcount(key, Double.toString(min), Double.toString(max))) - .run(args); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zLexCount(key, sMin, sMax, args); } @Override - public Long zLexCount(final byte[] key, final double min, final double max){ + public Long zLexCount(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand(client, ProtocolCommand.ZLEXCOUNT) - .general((cmd)->cmd.zlexcount(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .pipeline((cmd)->cmd.zlexcount(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .transaction((cmd)->cmd.zlexcount(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .run(args); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zLexCount(key, bMin, bMax, args); } + @Deprecated @Override - public Long zLexCount(final String key, final String min, final String max){ + public Long zLexCount(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand(client, ProtocolCommand.ZLEXCOUNT) - .general((cmd)->cmd.zlexcount(key, min, max)) - .pipeline((cmd)->cmd.zlexcount(key, min, max)) - .transaction((cmd)->cmd.zlexcount(key, min, max)) - .run(args); + return zLexCount(key, min, max, args); } + @Deprecated @Override - public Long zLexCount(final byte[] key, final byte[] min, final byte[] max){ + public Long zLexCount(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand(client, ProtocolCommand.ZLEXCOUNT) - .general((cmd)->cmd.zlexcount(key, min, max)) - .pipeline((cmd)->cmd.zlexcount(key, min, max)) - .transaction((cmd)->cmd.zlexcount(key, min, max)) - .run(args); + return zLexCount(key, min, max, args); } @Override - public List zMScore(final String key, final String... members){ + public List zMScore(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisSentinelCommand>(client, ProtocolCommand.ZMSCORE) - .general((cmd)->cmd.zmscore(key, members)) - .pipeline((cmd)->cmd.zmscore(key, members)) - .transaction((cmd)->cmd.zmscore(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZMSCORE, (cmd)->cmd.zmscore(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZMSCORE, + (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + } } @Override - public List zMScore(final byte[] key, final byte[]... members){ + public List zMScore(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisSentinelCommand>(client, ProtocolCommand.ZMSCORE) - .general((cmd)->cmd.zmscore(key, members)) - .pipeline((cmd)->cmd.zmscore(key, members)) - .transaction((cmd)->cmd.zmscore(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZMSCORE, (cmd)->cmd.zmscore(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZMSCORE, + (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + } } @Override - public String zRandMember(final String key){ + public String zRandMember(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmember(key)) - .pipeline((cmd)->cmd.zrandmember(key)) - .transaction((cmd)->cmd.zrandmember(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + } } @Override - public byte[] zRandMember(final byte[] key){ + public byte[] zRandMember(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmember(key)) - .pipeline((cmd)->cmd.zrandmember(key)) - .transaction((cmd)->cmd.zrandmember(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + } } @Override - public List zRandMember(final String key, final long count){ + public List zRandMember(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmember(key, count)) - .pipeline((cmd)->cmd.zrandmember(key, count)) - .transaction((cmd)->cmd.zrandmember(key, count)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), + (v)->v) + .run(args); + } } @Override - public List zRandMember(final byte[] key, final long count){ + public List zRandMember(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmember(key, count)) - .pipeline((cmd)->cmd.zrandmember(key, count)) - .transaction((cmd)->cmd.zrandmember(key, count)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), + (v)->v) + .run(args); + } } @Override - public List zRandMemberWithScores(final String key, final long count){ + public List zRandMemberWithScores(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + } } @Override - public List zRandMemberWithScores(final byte[] key, final long count){ + public List zRandMemberWithScores(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + } } @Override - public List zRange(final String key, final long start, final long end){ + public List zRange(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGE) - .general((cmd)->cmd.zrange(key, start, end)) - .pipeline((cmd)->cmd.zrange(key, start, end)) - .transaction((cmd)->cmd.zrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + } } @Override - public List zRange(final byte[] key, final long start, final long end){ + public List zRange(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGE) - .general((cmd)->cmd.zrange(key, start, end)) - .pipeline((cmd)->cmd.zrange(key, start, end)) - .transaction((cmd)->cmd.zrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + } } @Override - public List zRangeWithScores(final String key, final long start, final long end){ + public List zRangeWithScores(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGE) - .general((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } } @Override - public List zRangeWithScores(final byte[] key, final long start, final long end){ + public List zRangeWithScores(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGE) - .general((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } } @Override - public List zRangeByLex(final String key, final double min, final double max){ + public List zRangeByLex(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max))) - .pipeline((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max))) - .transaction((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max))) - .run(args); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zRangeByLex(key, sMin, sMax, args); } @Override - public List zRangeByLex(final byte[] key, final double min, final double max){ + public List zRangeByLex(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .pipeline((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .transaction((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .run(args); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, args); } + @Deprecated @Override - public List zRangeByLex(final String key, final String min, final String max){ + public List zRangeByLex(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zrangeByLex(key, min, max)) - .run(args); + return zRangeByLex(key, min, max, args); } + @Deprecated @Override - public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max){ + public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zrangeByLex(key, min, max)) - .run(args); + return zRangeByLex(key, min, max, args); } @Override public List zRangeByLex(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max), (int) offset, - (int) count)) - .pipeline((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max), (int) offset, - (int) count)) - .transaction((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max), (int) offset, - (int) count)) - .run(args); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zRangeByLex(key, sMin, sMax, offset, count, args); } @Override public List zRangeByLex(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max), - (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max), - (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max), - (int) offset, (int) count)) - .run(args); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, offset, count, args); } + @Deprecated @Override public List zRangeByLex(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .run(args); + return zRangeByLex(key, min, max, offset, count, args); } + @Deprecated @Override public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .run(args); + return zRangeByLex(key, min, max, offset, count, args); } @Override - public List zRangeByScore(final String key, final double min, final double max){ + public List zRangeByScore(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override - public List zRangeByScore(final byte[] key, final double min, final double max){ + public List zRangeByScore(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public List zRangeByScore(final String key, final String min, final String max){ + public List zRangeByScore(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public List zRangeByScore(final byte[] key, final byte[] min, final byte[] max){ + public List zRangeByScore(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override public List zRangeByScore(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } @Override public List zRangeByScore(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRangeByScore(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRangeByScore(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); - } - @Override - public List zRangeByScoreWithScores(final String key, final double min, final double max){ - final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } @Override - public List zRangeByScoreWithScores(final byte[] key, final double min, final double max){ + public List zRangeByScoreWithScores(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); - } + final ListConverter listTupleConverter = TupleConverter.listConverter(); - @Override - public List zRangeByScoreWithScores(final String key, final String min, final String max){ - final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } } @Override - public List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max){ + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Deprecated + @Override + public List zRangeByScoreWithScores(final String key, final String min, final String max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Deprecated + @Override + public List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } } @Override public List zRangeByScoreWithScores(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } @Override public List zRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } + @Deprecated @Override public List zRangeByScoreWithScores(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } + @Deprecated @Override public List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } @Override - public Long zRangeStore(final String destKey, final String key, final long start, final long end){ + public Long zRangeStore(final String destKey, final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end); - final JedisZRangeParams params = new JedisZRangeParams(start, end); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override - public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end){ + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end); - final JedisZRangeParams params = new JedisZRangeParams(start, end); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, - final ZRangeBy by){ + final ZRangeBy by) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, - final ZRangeBy by){ + final ZRangeBy by) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, - final boolean rev){ + final boolean rev) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("rev", rev); - final JedisZRangeParams params = new JedisZRangeParams(start, end, rev); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, - final boolean rev){ + final boolean rev) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("rev", rev); - final JedisZRangeParams params = new JedisZRangeParams(start, end, rev); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(start, end, offset, count); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(start, end, offset, count); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, - final ZRangeBy by, final boolean rev){ + final ZRangeBy by, final boolean rev) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("rev", rev); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, rev); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, - final ZRangeBy by, final boolean rev){ + final ZRangeBy by, final boolean rev) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("rev", rev); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, rev); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, - final ZRangeBy by, final long offset, final long count){ + final ZRangeBy by, final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, offset, count); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, - final ZRangeBy by, final long offset, final long count){ + final ZRangeBy by, final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, offset, count); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("rev", rev).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(start, end, rev, offset, count); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("rev", rev).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(start, end, rev, offset, count); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, - final boolean rev, final long offset, final long count){ + final boolean rev, final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, rev, offset, count); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, - final boolean rev, final long offset, final long count){ + final boolean rev, final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, rev, offset, count); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override - public Long zRank(final String key, final String member){ + public Long zRank(final String key, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANK) - .general((cmd)->cmd.zrank(key, member)) - .pipeline((cmd)->cmd.zrank(key, member)) - .transaction((cmd)->cmd.zrank(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } } @Override - public Long zRank(final byte[] key, final byte[] member){ + public Long zRank(final byte[] key, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisSentinelCommand(client, ProtocolCommand.ZRANK) - .general((cmd)->cmd.zrank(key, member)) - .pipeline((cmd)->cmd.zrank(key, member)) - .transaction((cmd)->cmd.zrank(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } } @Override - public Long zRem(final String key, final String... members){ + public Long zRem(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisSentinelCommand(client, ProtocolCommand.ZREM) - .general((cmd)->cmd.zrem(key, members)) - .pipeline((cmd)->cmd.zrem(key, members)) - .transaction((cmd)->cmd.zrem(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } } @Override - public Long zRem(final byte[] key, final byte[]... members){ + public Long zRem(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisSentinelCommand(client, ProtocolCommand.ZREM) - .general((cmd)->cmd.zrem(key, members)) - .pipeline((cmd)->cmd.zrem(key, members)) - .transaction((cmd)->cmd.zrem(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } } + @Deprecated @Override - public Long zRemRangeByLex(final String key, final String min, final String max){ + public Long zRemRangeByLex(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand(client, ProtocolCommand.ZREMRANGEBYLEX) - .general((cmd)->cmd.zremrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zremrangeByLex(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public Long zRemRangeByLex(final byte[] key, final byte[] min, final byte[] max){ + public Long zRemRangeByLex(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand(client, ProtocolCommand.ZREMRANGEBYLEX) - .general((cmd)->cmd.zremrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zremrangeByLex(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), (v)->v) + .run(args); + } } @Override - public Long zRemRangeByScore(final String key, final double min, final double max){ + public Long zRemRangeByScore(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand(client, ProtocolCommand.ZREMRANGEBYSCORE) - .general((cmd)->cmd.zremrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zremrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override - public Long zRemRangeByScore(final byte[] key, final double min, final double max){ + public Long zRemRangeByScore(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand(client, ProtocolCommand.ZREMRANGEBYSCORE) - .general((cmd)->cmd.zremrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zremrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public Long zRemRangeByScore(final String key, final String min, final String max){ + public Long zRemRangeByScore(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand(client, ProtocolCommand.ZREMRANGEBYSCORE) - .general((cmd)->cmd.zremrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zremrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public Long zRemRangeByScore(final byte[] key, final byte[] min, final byte[] max){ + public Long zRemRangeByScore(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand(client, ProtocolCommand.ZREMRANGEBYSCORE) - .general((cmd)->cmd.zremrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zremrangeByScore(key, min, max)) - .run(args); - } - @Override - public Long zRemRangeByRank(final String key, final long start, final long end){ - final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand(client, ProtocolCommand.ZREMRANGEBYRANK) - .general((cmd)->cmd.zremrangeByRank(key, start, end)) - .pipeline((cmd)->cmd.zremrangeByRank(key, start, end)) - .transaction((cmd)->cmd.zremrangeByRank(key, start, end)) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override - public Long zRemRangeByRank(final byte[] key, final long start, final long end){ + public Long zRemRangeByRank(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand(client, ProtocolCommand.ZREMRANGEBYRANK) - .general((cmd)->cmd.zremrangeByRank(key, start, end)) - .pipeline((cmd)->cmd.zremrangeByRank(key, start, end)) - .transaction((cmd)->cmd.zremrangeByRank(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + } } @Override - public List zRevRange(final String key, final long start, final long end){ + public Long zRemRangeByRank(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGE) - .general((cmd)->cmd.zrevrange(key, start, end)) - .pipeline((cmd)->cmd.zrevrange(key, start, end)) - .transaction((cmd)->cmd.zrevrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + } } @Override - public List zRevRange(final byte[] key, final long start, final long end){ + public List zRevRange(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGE) - .general((cmd)->cmd.zrevrange(key, start, end)) - .pipeline((cmd)->cmd.zrevrange(key, start, end)) - .transaction((cmd)->cmd.zrevrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), + (v)->v) + .run(args); + } } @Override - public List zRevRangeWithScores(final String key, final long start, final long end){ + public List zRevRange(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGE) - .general((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), + (v)->v) + .run(args); + } } @Override - public List zRevRangeWithScores(final byte[] key, final long start, final long end){ + public List zRevRangeWithScores(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGE) - .general((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } } @Override - public List zRevRangeByLex(final String key, final String min, final String max){ + public List zRevRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } + } + + @Deprecated + @Override + public List zRevRangeByLex(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYLEX) - .general((cmd)->cmd.zrevrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByLex(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max){ + public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYLEX) - .general((cmd)->cmd.zrevrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByLex(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRevRangeByLex(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYLEX) - .general((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYLEX) - .general((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } @Override - public List zRevRangeByScore(final String key, final double min, final double max){ + public List zRevRangeByScore(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override - public List zRevRangeByScore(final byte[] key, final double min, final double max){ + public List zRevRangeByScore(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public List zRevRangeByScore(final String key, final String min, final String max){ + public List zRevRangeByScore(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max){ + public List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override public List zRevRangeByScore(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } @Override public List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRevRangeByScore(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); - } - @Override - public List zRevRangeByScoreWithScores(final String key, final double min, final double max){ - final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } @Override - public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max){ + public List zRevRangeByScoreWithScores(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); - } + final ListConverter listTupleConverter = TupleConverter.listConverter(); - @Override - public List zRevRangeByScoreWithScores(final String key, final String min, final String max){ - final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } } @Override - public List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max){ + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Deprecated + @Override + public List zRevRangeByScoreWithScores(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Deprecated + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } } @Override public List zRevRangeByScoreWithScores(final String key, final double min, final double max, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } @Override public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } + @Deprecated @Override public List zRevRangeByScoreWithScores(final String key, final String min, final String max, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } + @Deprecated @Override public List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisSentinelCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } @Override - public Long zRevRank(final String key, final String member){ + public Long zRevRank(final String key, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisSentinelCommand(client, ProtocolCommand.ZREVRANK) - .general((cmd)->cmd.zrevrank(key, member)) - .pipeline((cmd)->cmd.zrevrank(key, member)) - .transaction((cmd)->cmd.zrevrank(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + } } @Override - public Long zRevRank(final byte[] key, final byte[] member){ + public Long zRevRank(final byte[] key, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisSentinelCommand(client, ProtocolCommand.ZREVRANK) - .general((cmd)->cmd.zrevrank(key, member)) - .pipeline((cmd)->cmd.zrevrank(key, member)) - .transaction((cmd)->cmd.zrevrank(key, member)) - .run(args); - } - @Override - public ScanResult> zScan(final String key, final String cursor){ - final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisSentinelCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + } } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor){ + public ScanResult> zScan(final String key, final String cursor) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisSentinelCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); - } - - @Override - public ScanResult> zScan(final String key, final String cursor, final String pattern){ + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisSentinelCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return zScan(key, cursor, scanParams, args); } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern){ + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisSentinelCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return zScan(key, cursor, scanParams, args); } @Override - public ScanResult> zScan(final String key, final String cursor, final long count){ + public ScanResult> zScan(final String key, final String cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisSentinelCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return zScan(key, cursor, scanParams, args); } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor, final long count){ + public ScanResult> zScan(final byte[] key, final byte[] cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisSentinelCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return zScan(key, cursor, scanParams, args); } @Override - public ScanResult> zScan(final String key, final String cursor, final String pattern, final long count){ + public ScanResult> zScan(final String key, final String cursor, final String pattern, + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisSentinelCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return zScan(key, cursor, scanParams, args); } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, final long count){ + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisSentinelCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return zScan(key, cursor, scanParams, args); } @Override - public Double zScore(final String key, final String member){ + public Double zScore(final String key, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisSentinelCommand(client, ProtocolCommand.ZSCORE) - .general((cmd)->cmd.zscore(key, member)) - .pipeline((cmd)->cmd.zscore(key, member)) - .transaction((cmd)->cmd.zscore(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } } @Override - public Double zScore(final byte[] key, final byte[] member){ + public Double zScore(final byte[] key, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisSentinelCommand(client, ProtocolCommand.ZSCORE) - .general((cmd)->cmd.zscore(key, member)) - .pipeline((cmd)->cmd.zscore(key, member)) - .transaction((cmd)->cmd.zscore(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } } @Override - public Set zUnion(final String... keys){ + public List zUnion(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final JedisZParams params = new JedisZParams(); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final byte[]... keys){ + public List zUnion(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final JedisZParams params = new JedisZParams(); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final String[] keys, final Aggregate aggregate){ + public List zUnion(final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final byte[][] keys, final Aggregate aggregate){ + public List zUnion(final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final String[] keys, final double... weights){ + public List zUnion(final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final byte[][] keys, final double... weights){ + public List zUnion(final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zUnion(final String[] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnion(keys, zParams, args); } @Override - public Set zUnionWithScores(final String... keys){ + public List zUnionWithScores(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final JedisZParams params = new JedisZParams(); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final byte[]... keys){ + public List zUnionWithScores(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final JedisZParams params = new JedisZParams(); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final String[] keys, final Aggregate aggregate){ + public List zUnionWithScores(final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final byte[][] keys, final Aggregate aggregate){ + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final String[] keys, final double... weights){ + public List zUnionWithScores(final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final byte[][] keys, final double... weights){ + public List zUnionWithScores(final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisSentinelCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionWithScores(keys, zParams, args); } @Override - public Long zUnionStore(final String destKey, final String... keys){ + public Long zUnionStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + } } @Override - public Long zUnionStore(final byte[] destKey, final byte[]... keys){ + public Long zUnionStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + } } @Override - public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate){ + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisSentinelCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionStore(destKey, keys, zParams, args); } @Override - public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate){ + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisSentinelCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionStore(destKey, keys, zParams, args); } @Override - public Long zUnionStore(final String destKey, final String[] keys, final double... weights){ + public Long zUnionStore(final String destKey, final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisSentinelCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnionStore(destKey, keys, zParams, args); } @Override - public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights){ + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisSentinelCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnionStore(destKey, keys, zParams, args); } @Override public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate).put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisSentinelCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionStore(destKey, keys, zParams, args); } @Override public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate).put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisSentinelCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionStore(destKey, keys, zParams, args); + } + + private Long zAdd(final String key, final Map members, final ZAddParams zAddParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), + (v)->v) + .run(args); + } + } + + private Long zAdd(final byte[] key, final Map members, final ZAddParams zAddParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), + (v)->v) + .run(args); + } + } + + private List zInter(final String[] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinter(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + } + } + + private List zInter(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinter(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + } + } + + private List zInterWithScores(final String[] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private List zInterWithScores(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private Long zInterStore(final String destKey, final String[] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zInterStore(final byte[] destKey, final byte[][] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zLexCount(final String key, final String min, final String max, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + } + } + + private Long zLexCount(final byte[] key, final byte[] min, final byte[] max, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + } + } + + private List zRangeByLex(final String key, final String min, final String max, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + } + } + + private List zRangeByLex(final String key, final String min, final String max, final long offset, + final long count, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + private Long zRangeStore(final String destKey, final String key, final ZRangeParams zRangeParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + } + } + + private Long zRangeStore(final byte[] destKey, final byte[] key, final ZRangeParams zRangeParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + } + } + + private ScanResult> zScan(final String key, final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + } + } + + private List zUnion(final String[] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunion(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + } + } + + private List zUnion(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunion(zParams, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + } + } + + private List zUnionWithScores(final String[] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + } + } + + private List zUnionWithScores(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + } + } + + private Long zUnionStore(final String destKey, final String[] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zUnionStore(final byte[] destKey, final byte[][] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelStreamOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelStreamOperations.java index aa25aae56..5fbcc01c0 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelStreamOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelStreamOperations.java @@ -19,11 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapEntryMapConverter; import com.buession.lang.Status; import com.buession.redis.client.jedis.JedisSentinelClient; import com.buession.redis.core.Stream; @@ -36,11 +38,7 @@ import com.buession.redis.core.StreamPendingSummary; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; import com.buession.redis.core.internal.convert.jedis.params.StreamEntryIdConverter; -import com.buession.redis.core.internal.convert.jedis.params.XAddArgumentConverter; -import com.buession.redis.core.internal.convert.jedis.params.XClaimArgumentConverter; -import com.buession.redis.core.internal.convert.jedis.params.XTrimArgumentConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamConsumersInfoConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamEntryConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamEntryIDConverter; @@ -49,15 +47,25 @@ import com.buession.redis.core.internal.convert.jedis.response.StreamInfoConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamPendingEntryConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamPendingSummaryConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import com.buession.redis.core.internal.jedis.JedisStreamEntryID; +import com.buession.redis.core.internal.jedis.JedisXAddParams; import com.buession.redis.core.internal.jedis.JedisXAutoClaimParams; +import com.buession.redis.core.internal.jedis.JedisXClaimParams; import com.buession.redis.core.internal.jedis.JedisXPendingParams; import com.buession.redis.core.internal.jedis.JedisXReadGroupParams; import com.buession.redis.core.internal.jedis.JedisXReadParams; +import com.buession.redis.core.internal.jedis.JedisXTrimParams; import redis.clients.jedis.StreamEntryID; import redis.clients.jedis.params.XAddParams; +import redis.clients.jedis.params.XAutoClaimParams; import redis.clients.jedis.params.XClaimParams; +import redis.clients.jedis.params.XPendingParams; +import redis.clients.jedis.params.XReadGroupParams; +import redis.clients.jedis.params.XReadParams; import redis.clients.jedis.params.XTrimParams; +import redis.clients.jedis.resps.StreamConsumersInfo; +import redis.clients.jedis.resps.StreamGroupInfo; +import redis.clients.jedis.resps.StreamPendingEntry; import java.util.List; import java.util.Map; @@ -70,814 +78,1042 @@ */ public final class JedisSentinelStreamOperations extends AbstractStreamOperations { - public JedisSentinelStreamOperations(final JedisSentinelClient client){ + public JedisSentinelStreamOperations(final JedisSentinelClient client) { super(client); } @Override - public Long xAck(final String key, final String groupName, final StreamEntryId... ids){ + public Long xAck(final String key, final String groupName, final StreamEntryId... ids) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("ids", (Object[]) ids); - final StreamEntryID[] streamEntryIDS = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisSentinelCommand(client, ProtocolCommand.XACK) - .general((cmd)->cmd.xack(key, groupName, streamEntryIDS)) - .pipeline((cmd)->cmd.xack(key, groupName, streamEntryIDS)) - .transaction((cmd)->cmd.xack(key, groupName, streamEntryIDS)) - .run(args); + final StreamEntryID[] streamEntryIDS = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + } } @Override - public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash){ + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash) { final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(id); - return new JedisSentinelCommand(client, ProtocolCommand.XADD) - .general((cmd)->cmd.xadd(key, streamEntryID, hash), StreamEntryIDConverter.INSTANCE) - .pipeline((cmd)->cmd.xadd(key, streamEntryID, hash), StreamEntryIDConverter.INSTANCE) - .transaction((cmd)->cmd.xadd(key, streamEntryID, hash), StreamEntryIDConverter.INSTANCE) - .run(args); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XADD, + (cmd)->cmd.xadd(key, streamEntryID, hash), streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XADD, + (cmd)->cmd.xadd(key, streamEntryID, hash), streamEntryIDConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, streamEntryID, hash), + streamEntryIDConverter) + .run(args); + } } @Override public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash, - final XAddArgument xAddArgument){ + final XAddArgument xAddArgument) { final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) .put("xAddArgument", xAddArgument); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(id); - final XAddParams params = XAddArgumentConverter.INSTANCE.convert(xAddArgument).id(streamEntryID); - return new JedisSentinelCommand(client, ProtocolCommand.XADD) - .general((cmd)->cmd.xadd(key, hash, params), StreamEntryIDConverter.INSTANCE) - .pipeline((cmd)->cmd.xadd(key, hash, params), StreamEntryIDConverter.INSTANCE) - .transaction((cmd)->cmd.xadd(key, hash, params), StreamEntryIDConverter.INSTANCE) - .run(args); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + final XAddParams xAddParams = JedisXAddParams.from(xAddArgument).id(streamEntryID); + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), streamEntryIDConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + streamEntryIDConverter) + .run(args); + } } @Override public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash, - final XAddArgument xAddArgument){ + final XAddArgument xAddArgument) { final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) .put("xAddArgument", xAddArgument); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(id); - final XAddParams params = XAddArgumentConverter.INSTANCE.convert(xAddArgument).id(streamEntryID); - return new JedisSentinelCommand(client, ProtocolCommand.XADD) - .general((cmd)->cmd.xadd(key, hash, params), - StreamEntryIDConverter.BinaryStreamEntryIdConverter.INSTANCE) - .pipeline((cmd)->cmd.xadd(key, hash, params), - StreamEntryIDConverter.BinaryStreamEntryIdConverter.INSTANCE) - .transaction((cmd)->cmd.xadd(key, hash, params), - StreamEntryIDConverter.BinaryStreamEntryIdConverter.INSTANCE) - .run(args); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + final XAddParams xAddParams = JedisXAddParams.from(xAddArgument).id(streamEntryID); + final StreamEntryIDConverter.BinaryStreamEntryIdConverter binaryStreamEntryIdConverter = + new StreamEntryIDConverter.BinaryStreamEntryIdConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), binaryStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XADD, + (cmd)->cmd.xadd(key, hash, xAddParams), binaryStreamEntryIdConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + binaryStreamEntryIdConverter) + .run(args); + } } @Override public Map> xAutoClaim(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start){ + final StreamEntryId start) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final JedisXAutoClaimParams params = new JedisXAutoClaimParams(); - return new JedisSentinelCommand>>(client, ProtocolCommand.XAUTOCLAIM) - .general((cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .transaction( - (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .run(args); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); } @Override public Map> xAutoClaim(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start, final long count){ + final StreamEntryId start, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) .put("count", count); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final JedisXAutoClaimParams params = new JedisXAutoClaimParams(count); - return new JedisSentinelCommand>>(client, ProtocolCommand.XAUTOCLAIM) - .general((cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .transaction( - (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .run(args); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(count); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); } @Override public Map> xAutoClaimJustId(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start){ + final StreamEntryId start) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) .put("count"); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final JedisXAutoClaimParams params = new JedisXAutoClaimParams(); - return new JedisSentinelCommand>>(client, ProtocolCommand.XAUTOCLAIM) - .general((cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .pipeline((cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .transaction( - (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .run(args); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); } @Override public Map> xAutoClaimJustId(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start, final long count){ + final StreamEntryId start, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) .put("count", count); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final JedisXAutoClaimParams params = new JedisXAutoClaimParams(count); - return new JedisSentinelCommand>>(client, ProtocolCommand.XAUTOCLAIM) - .general((cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .pipeline((cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .transaction( - (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .run(args); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); } @Override public List xClaim(final String key, final String groupName, final String consumerName, - final int minIdleTime, final StreamEntryId... ids){ + final int minIdleTime, final StreamEntryId... ids) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); - final XClaimParams params = new XClaimParams(); - final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisSentinelCommand>(client, ProtocolCommand.XCLAIM) - .general((cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .transaction( - (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .run(args); + final XClaimParams xClaimParams = new JedisXClaimParams(); + + return xClaim(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); } @Override public List xClaim(final String key, final String groupName, final String consumerName, final int minIdleTime, final StreamEntryId[] ids, - final XClaimArgument xClaimArgument){ + final XClaimArgument xClaimArgument) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) .put("xClaimArgument", xClaimArgument); - final XClaimParams params = XClaimArgumentConverter.INSTANCE.convert(xClaimArgument); - final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisSentinelCommand>(client, ProtocolCommand.XCLAIM) - .general((cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .transaction( - (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .run(args); + final XClaimParams xClaimParams = JedisXClaimParams.from(xClaimArgument); + + return xClaim(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); } @Override public List xClaimJustId(final String key, final String groupName, final String consumerName, - final int minIdleTime, final StreamEntryId... ids){ + final int minIdleTime, final StreamEntryId... ids) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); - final XClaimParams params = new XClaimParams(); - final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisSentinelCommand>(client, ProtocolCommand.XCLAIM) - .general((cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .transaction( - (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .run(args); + final XClaimParams xClaimParams = new JedisXClaimParams(); + + return xClaimJustId(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); } @Override public List xClaimJustId(final String key, final String groupName, final String consumerName, final int minIdleTime, final StreamEntryId[] ids, - final XClaimArgument xClaimArgument){ + final XClaimArgument xClaimArgument) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) .put("xClaimArgument", xClaimArgument); - final XClaimParams params = XClaimArgumentConverter.INSTANCE.convert(xClaimArgument); - final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisSentinelCommand>(client, ProtocolCommand.XCLAIM) - .general((cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .transaction( - (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .run(args); + final XClaimParams xClaimParams = JedisXClaimParams.from(xClaimArgument); + + return xClaimJustId(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); } @Override - public Long xDel(final String key, final StreamEntryId... ids){ + public Long xDel(final String key, final StreamEntryId... ids) { final CommandArguments args = CommandArguments.create("key", key).put("ids", (Object[]) ids); - final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisSentinelCommand(client, ProtocolCommand.XDEL) - .general((cmd)->cmd.xdel(key, streamEntryIDs)) - .pipeline((cmd)->cmd.xdel(key, streamEntryIDs)) - .transaction((cmd)->cmd.xdel(key, streamEntryIDs)) - .run(args); + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XDEL, + (cmd)->cmd.xdel(key, streamEntryIDs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XDEL, + (cmd)->cmd.xdel(key, streamEntryIDs), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XDEL, (cmd)->cmd.xdel(key, streamEntryIDs), + (v)->v) + .run(args); + } } @Override public Status xGroupCreate(final String key, final String groupName, final StreamEntryId id, - final boolean makeStream){ + final boolean makeStream) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("id", id); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(id); - return new JedisSentinelCommand(client, ProtocolCommand.XGROUP_CREATE) - .general((cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), - OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), - OkStatusConverter.INSTANCE) - .run(args); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + } } @Override - public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName){ + public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - return new JedisSentinelCommand(client, ProtocolCommand.XGROUP_CREATECONSUMER) - .general((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + } } @Override - public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName){ + public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - return new JedisSentinelCommand(client, ProtocolCommand.XGROUP_CREATECONSUMER) - .general((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + } } @Override - public Long xGroupDelConsumer(final String key, final String groupName, final String consumerName){ + public Long xGroupDelConsumer(final String key, final String groupName, final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - return new JedisSentinelCommand(client, ProtocolCommand.XGROUP_DELCONSUMER) - .general((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .pipeline((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .transaction((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + } } @Override - public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName){ + public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - return new JedisSentinelCommand(client, ProtocolCommand.XGROUP_DELCONSUMER) - .general((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .pipeline((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .transaction((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName), (v)->v) + .run(args); + } } @Override - public Status xGroupDestroy(final String key, final String groupName){ + public Status xGroupDestroy(final String key, final String groupName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); - return new JedisSentinelCommand(client, ProtocolCommand.XGROUP_DESTROY) - .general((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + } } @Override - public Status xGroupDestroy(final byte[] key, final byte[] groupName){ + public Status xGroupDestroy(final byte[] key, final byte[] groupName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); - return new JedisSentinelCommand(client, ProtocolCommand.XGROUP_DESTROY) - .general((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + } } @Override - public Status xGroupSetId(final String key, final String groupName, final StreamEntryId id){ + public Status xGroupSetId(final String key, final String groupName, final StreamEntryId id) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName).put("id", id); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(id); - return new JedisSentinelCommand(client, ProtocolCommand.XGROUP_SETID) - .general((cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), OkStatusConverter.INSTANCE) - .run(args); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + } } @Override - public List xInfoConsumers(final String key, final String groupName){ + public List xInfoConsumers(final String key, final String groupName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); - return new JedisSentinelCommand>(client, - ProtocolCommand.XINFO_CONSUMERS) - .general((cmd)->cmd.xinfoConsumers(key, groupName), StreamConsumersInfoConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xinfoConsumers(key, groupName), StreamConsumersInfoConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xinfoConsumers(key, groupName), StreamConsumersInfoConverter.LIST_CONVERTER) - .run(args); + final ListConverter listStreamConsumersInfoConverter = + StreamConsumersInfoConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + } } @Override - public List xInfoGroups(final String key){ + public List xInfoGroups(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand>(client, ProtocolCommand.XINFO_GROUPS) - .general((cmd)->cmd.xinfoGroups(key), StreamGroupInfoConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xinfoGroups(key), StreamGroupInfoConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xinfoGroups(key), StreamGroupInfoConverter.LIST_CONVERTER) - .run(args); + final ListConverter listStreamGroupInfoConverter = + StreamGroupInfoConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XINFO_GROUPS, + (cmd)->cmd.xinfoGroups(key), listStreamGroupInfoConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + } } @Override - public Stream xInfoStream(final String key){ + public Stream xInfoStream(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.XINFO_STREAM) - .general((cmd)->cmd.xinfoStream(key), StreamInfoConverter.INSTANCE) - .pipeline((cmd)->cmd.xinfoStream(key), StreamInfoConverter.INSTANCE) - .transaction((cmd)->cmd.xinfoStream(key), StreamInfoConverter.INSTANCE) - .run(args); + final StreamInfoConverter streamInfoConverter = new StreamInfoConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStream(key), streamInfoConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamInfoConverter) + .run(args); + } } @Override - public StreamFull xInfoStream(final String key, final boolean full){ + public StreamFull xInfoStream(final String key, final boolean full) { final CommandArguments args = CommandArguments.create("key", key).put("full", full); - return new JedisSentinelCommand(client, ProtocolCommand.XINFO_STREAM) - .general((cmd)->cmd.xinfoStreamFull(key), StreamFullInfoConverter.INSTANCE) - .pipeline((cmd)->cmd.xinfoStreamFull(key), StreamFullInfoConverter.INSTANCE) - .transaction((cmd)->cmd.xinfoStreamFull(key), StreamFullInfoConverter.INSTANCE) - .run(args); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key), streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key), streamFullInfoConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStreamFull(key), + streamFullInfoConverter) + .run(args); + } } @Override - public StreamFull xInfoStream(final String key, final boolean full, final long count){ + public StreamFull xInfoStream(final String key, final boolean full, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("full", full).put("count", count); - return new JedisSentinelCommand(client, ProtocolCommand.XINFO_STREAM) - .general((cmd)->cmd.xinfoStreamFull(key, (int) count), StreamFullInfoConverter.INSTANCE) - .pipeline((cmd)->cmd.xinfoStreamFull(key, (int) count), StreamFullInfoConverter.INSTANCE) - .transaction((cmd)->cmd.xinfoStreamFull(key, (int) count), StreamFullInfoConverter.INSTANCE) - .run(args); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + } } @Override - public Long xLen(final String key){ + public Long xLen(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.XLEN) - .general((cmd)->cmd.xlen(key)) - .pipeline((cmd)->cmd.xlen(key)) - .transaction((cmd)->cmd.xlen(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } } @Override - public Long xLen(final byte[] key){ + public Long xLen(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.XLEN) - .general((cmd)->cmd.xlen(key)) - .pipeline((cmd)->cmd.xlen(key)) - .transaction((cmd)->cmd.xlen(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } } @Override - public StreamPendingSummary xPending(final String key, final String groupName){ + public StreamPendingSummary xPending(final String key, final String groupName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); - return new JedisSentinelCommand(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName), StreamPendingSummaryConverter.INSTANCE) - .pipeline((cmd)->cmd.xpending(key, groupName), StreamPendingSummaryConverter.INSTANCE) - .transaction((cmd)->cmd.xpending(key, groupName), StreamPendingSummaryConverter.INSTANCE) - .run(args); + final StreamPendingSummaryConverter streamPendingSummaryConverter = new StreamPendingSummaryConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName), streamPendingSummaryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName), streamPendingSummaryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XPENDING, (cmd)->cmd.xpending(key, groupName), + streamPendingSummaryConverter) + .run(args); + } } @Override - public List xPending(final String key, final String groupName, final long minIdleTime){ + public List xPending(final String key, final String groupName, final long minIdleTime) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("minIdleTime", minIdleTime); - final JedisXPendingParams params = new JedisXPendingParams(minIdleTime); - return new JedisSentinelCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime); + + return xPending(key, groupName, xPendingParams, args); } @Override public List xPending(final String key, final String groupName, final StreamEntryId start, - final StreamEntryId end, final long count){ + final StreamEntryId end, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("start", start).put("end", end).put("count", count); - final JedisXPendingParams params = new JedisXPendingParams(start, end, count); - return new JedisSentinelCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count); + + return xPending(key, groupName, xPendingParams, args); } @Override - public List xPending(final String key, final String groupName, final String consumerName){ + public List xPending(final String key, final String groupName, final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - final JedisXPendingParams params = new JedisXPendingParams(consumerName); - return new JedisSentinelCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(consumerName); + + return xPending(key, groupName, xPendingParams, args); } @Override public List xPending(final String key, final String groupName, final long minIdleTime, - final StreamEntryId start, final StreamEntryId end, final long count){ + final StreamEntryId start, final StreamEntryId end, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("minIdleTime", minIdleTime).put("start", start).put("end", end).put("count", count); - final JedisXPendingParams params = new JedisXPendingParams(minIdleTime, start, end, count); - return new JedisSentinelCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime, start, end, count); + + return xPending(key, groupName, xPendingParams, args); } @Override public List xPending(final String key, final String groupName, final long minIdleTime, - final String consumerName){ + final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("minIdleTime", minIdleTime).put("consumerName", consumerName); - final JedisXPendingParams params = new JedisXPendingParams(minIdleTime, consumerName); - return new JedisSentinelCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime, consumerName); + + return xPending(key, groupName, xPendingParams, args); } @Override public List xPending(final String key, final String groupName, final StreamEntryId start, - final StreamEntryId end, final long count, final String consumerName){ + final StreamEntryId end, final long count, final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - final JedisXPendingParams params = new JedisXPendingParams(start, end, count, consumerName); - return new JedisSentinelCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count, consumerName); + + return xPending(key, groupName, xPendingParams, args); } @Override public List xPending(final String key, final String groupName, final long minIdleTime, final StreamEntryId start, final StreamEntryId end, final long count, - final String consumerName){ + final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("minIdleTime", minIdleTime).put("consumerName", consumerName); - final JedisXPendingParams params = new JedisXPendingParams(minIdleTime, start, end, count, consumerName); - return new JedisSentinelCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime, start, end, count, consumerName); + + return xPending(key, groupName, xPendingParams, args); } @Override - public List xRange(final String key, final StreamEntryId start, final StreamEntryId end){ + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - final StreamEntryID startStreamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final StreamEntryID endStreamEntryID = StreamEntryIdConverter.INSTANCE.convert(end); - return new JedisSentinelCommand>(client, ProtocolCommand.XRANGE) - .general((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), - StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), - StreamEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), - StreamEntryConverter.LIST_CONVERTER) - .run(args); + final StreamEntryID startStreamEntryID = JedisStreamEntryID.from(start); + final StreamEntryID endStreamEntryID = JedisStreamEntryID.from(end); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), listStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), listStreamEntryConverter) + .run(args); + } } @Override public List xRange(final String key, final StreamEntryId start, final StreamEntryId end, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - final StreamEntryID startStreamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final StreamEntryID endStreamEntryID = StreamEntryIdConverter.INSTANCE.convert(end); - return new JedisSentinelCommand>(client, ProtocolCommand.XRANGE) - .general((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), - StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), - StreamEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), - StreamEntryConverter.LIST_CONVERTER) - .run(args); + final StreamEntryID startStreamEntryID = JedisStreamEntryID.from(start); + final StreamEntryID endStreamEntryID = JedisStreamEntryID.from(end); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), listStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), listStreamEntryConverter) + .run(args); + } } @Override - public List>> xRead(final Map streams){ + public List>> xRead(final Map streams) { final CommandArguments args = CommandArguments.create("streams", streams); - final JedisXReadParams params = new JedisXReadParams(); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisSentinelCommand>>>(client, ProtocolCommand.XREAD) - .general((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadParams xReadParams = new JedisXReadParams(); + + return xRead(streams, xReadParams, args); } @Override - public List>> xRead(final long count, final Map streams){ + public List>> xRead(final long count, final Map streams) { final CommandArguments args = CommandArguments.create("count", count).put("streams", streams); - final JedisXReadParams params = new JedisXReadParams(count); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisSentinelCommand>>>(client, ProtocolCommand.XREAD) - .general((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadParams xReadParams = new JedisXReadParams(count); + + return xRead(streams, xReadParams, args); } @Override - public List>> xRead(final int block, final Map streams){ + public List>> xRead(final int block, final Map streams) { final CommandArguments args = CommandArguments.create("block", block).put("streams", streams); - final JedisXReadParams params = new JedisXReadParams(block); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisSentinelCommand>>>(client, ProtocolCommand.XREAD) - .general((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadParams xReadParams = new JedisXReadParams(block); + + return xRead(streams, xReadParams, args); } @Override public List>> xRead(final long count, final int block, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("count", count).put("block", block) .put("streams", streams); - final JedisXReadParams params = new JedisXReadParams(count, block); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisSentinelCommand>>>(client, ProtocolCommand.XREAD) - .general((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadParams xReadParams = new JedisXReadParams(count, block); + + return xRead(streams, xReadParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisSentinelCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, - final long count, final Map streams){ + final long count, final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("count", count).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(count); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisSentinelCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(count); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, - final int block, final Map streams){ + final int block, final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("block", block).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(block); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisSentinelCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(block); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final boolean isNoAck, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("isNoAck", isNoAck).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(isNoAck); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisSentinelCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final long count, final int block, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("count", count).put("block", block).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(count, block); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisSentinelCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(count, block); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final long count, final boolean isNoAck, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("count", count).put("isNoAck", isNoAck).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(count, isNoAck); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisSentinelCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(count, isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final int block, final boolean isNoAck, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("block", block).put("isNoAck", isNoAck).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(block, isNoAck); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisSentinelCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(block, isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final long count, final int block, final boolean isNoAck, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("count", count).put("block", block).put("isNoAck", isNoAck).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(count, block, isNoAck); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisSentinelCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(count, block, isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override - public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start){ + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start) { final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start); - final StreamEntryID endID = StreamEntryIdConverter.INSTANCE.convert(end); - final StreamEntryID startID = StreamEntryIdConverter.INSTANCE.convert(start); - return new JedisSentinelCommand>(client, ProtocolCommand.XREVRANGE) - .general((cmd)->cmd.xrevrange(key, endID, startID), StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xrevrange(key, endID, startID), StreamEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xrevrange(key, endID, startID), StreamEntryConverter.LIST_CONVERTER) - .run(args); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), listStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), listStreamEntryConverter) + .run(args); + } } @Override public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start) .put("count", count); - final StreamEntryID endID = StreamEntryIdConverter.INSTANCE.convert(end); - final StreamEntryID startID = StreamEntryIdConverter.INSTANCE.convert(start); - return new JedisSentinelCommand>(client, ProtocolCommand.XREVRANGE) - .general((cmd)->cmd.xrevrange(key, endID, startID, (int) count), StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xrevrange(key, endID, startID, (int) count), StreamEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xrevrange(key, endID, startID, (int) count), - StreamEntryConverter.LIST_CONVERTER) - .run(args); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + } } @Override - public Long xTrim(final String key, final XTrimArgument xTrimArgument){ + public Long xTrim(final String key, final XTrimArgument xTrimArgument) { final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); - final XTrimParams params = XTrimArgumentConverter.INSTANCE.convert(xTrimArgument); - return new JedisSentinelCommand(client, ProtocolCommand.XTRIM) - .general((cmd)->cmd.xtrim(key, params)) - .pipeline((cmd)->cmd.xtrim(key, params)) - .transaction((cmd)->cmd.xtrim(key, params)) - .run(args); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument); + + return xTrim(key, xTrimParams, args); } @Override - public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument){ + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument) { final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); - final XTrimParams params = XTrimArgumentConverter.INSTANCE.convert(xTrimArgument); - return new JedisSentinelCommand(client, ProtocolCommand.XTRIM) - .general((cmd)->cmd.xtrim(key, params)) - .pipeline((cmd)->cmd.xtrim(key, params)) - .transaction((cmd)->cmd.xtrim(key, params)) - .run(args); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument); + + return xTrim(key, xTrimParams, args); } @Override - public Long xTrim(final String key, final XTrimArgument xTrimArgument, final long limit){ + public Long xTrim(final String key, final XTrimArgument xTrimArgument, final long limit) { final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) .put("limit", limit); - final XTrimParams params = XTrimArgumentConverter.INSTANCE.convert(xTrimArgument).limit(limit); - return new JedisSentinelCommand(client, ProtocolCommand.XTRIM) - .general((cmd)->cmd.xtrim(key, params)) - .pipeline((cmd)->cmd.xtrim(key, params)) - .transaction((cmd)->cmd.xtrim(key, params)) - .run(args); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument).limit(limit); + + return xTrim(key, xTrimParams, args); } @Override - public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit){ + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit) { final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) .put("limit", limit); - final XTrimParams params = XTrimArgumentConverter.INSTANCE.convert(xTrimArgument).limit(limit); - return new JedisSentinelCommand(client, ProtocolCommand.XTRIM) - .general((cmd)->cmd.xtrim(key, params)) - .pipeline((cmd)->cmd.xtrim(key, params)) - .transaction((cmd)->cmd.xtrim(key, params)) - .run(args); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument).limit(limit); + + return xTrim(key, xTrimParams, args); + } + + private Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, + final XAutoClaimParams xAutoClaimParams, + final CommandArguments args) { + final StreamEntryID startStreamEntryID = JedisStreamEntryID.from(start); + final StreamEntryConverter.MapEntryStreamEntryConverter mapEntryStreamEntryConverter = + new StreamEntryConverter.MapEntryStreamEntryConverter<>(new StreamEntryIDConverter()); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryConverter) + .run(args); + } + } + + private Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, + final XAutoClaimParams xAutoClaimParams, + final CommandArguments args) { + final StreamEntryID startStreamEntryID = JedisStreamEntryID.from(start); + final MapEntryMapConverter, StreamEntryId, List> mapEntryStreamEntryIdConverter = StreamEntryIDConverter.mapEntryMapConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryIdConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryIdConverter) + .run(args); + } + } + + private List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, final XClaimParams xClaimParams, + final CommandArguments args) { + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + } + } + + private List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimParams xClaimParams, final CommandArguments args) { + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter listStreamEntryIDConverter = StreamEntryIDConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + } + } + + private List xPending(final String key, final String groupName, + final XPendingParams xPendingParams, final CommandArguments args) { + final ListConverter listStreamPendingEntryConverter = + StreamPendingEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + } + } + + private List>> xRead(final Map streams, + final XReadParams xReadParams, final CommandArguments args) { + final Map stringStreamEntryIDMap = StreamEntryIdConverter.mapConverter().convert( + streams); + final StreamEntryConverter.ListMapEntryStreamEntryConverter listMapEntryStreamEntryConverter = + new StreamEntryConverter.ListMapEntryStreamEntryConverter<>((k)->k); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadGroupParams xReadGroupParams, + final CommandArguments args) { + final Map stringStreamEntryIDMap = StreamEntryIdConverter.mapConverter().convert( + streams); + final StreamEntryConverter.ListMapEntryStreamEntryConverter listMapEntryStreamEntryConverter = + new StreamEntryConverter.ListMapEntryStreamEntryConverter<>((k)->k); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + } + } + + private Long xTrim(final String key, final XTrimParams xTrimParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XTRIM, + (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + } + } + + private Long xTrim(final byte[] key, final XTrimParams xTrimParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.XTRIM, + (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelStringOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelStringOperations.java index 88a96602c..b96c82b97 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelStringOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelStringOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -28,10 +28,8 @@ import com.buession.redis.client.jedis.JedisSentinelClient; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; -import com.buession.redis.core.internal.convert.jedis.params.GetExArgumentConverter; -import com.buession.redis.core.internal.convert.jedis.params.SetArgumentConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import com.buession.redis.core.internal.jedis.JedisGetExParams; +import com.buession.redis.core.internal.jedis.JedisSetParams; import redis.clients.jedis.params.GetExParams; import redis.clients.jedis.params.SetParams; @@ -47,232 +45,392 @@ */ public final class JedisSentinelStringOperations extends AbstractStringOperations { - public JedisSentinelStringOperations(final JedisSentinelClient client){ + public JedisSentinelStringOperations(final JedisSentinelClient client) { super(client); } @Override - public Long append(final String key, final String value){ + public Long append(final String key, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.APPEND) - .general((cmd)->cmd.append(key, value)).pipeline((cmd)->cmd.append(key, value)) - .transaction((cmd)->cmd.append(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } } @Override - public Long append(final byte[] key, final byte[] value){ + public Long append(final byte[] key, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.APPEND) - .general((cmd)->cmd.append(key, value)).pipeline((cmd)->cmd.append(key, value)) - .transaction((cmd)->cmd.append(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } } @Override - public Long incr(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.INCR) - .general((cmd)->cmd.incr(key)) - .pipeline((cmd)->cmd.incr(key)) - .transaction((cmd)->cmd.incr(key)) - .run(args); + public Long incr(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } } @Override - public Long incr(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.INCR) - .general((cmd)->cmd.incr(key)) - .pipeline((cmd)->cmd.incr(key)) - .transaction((cmd)->cmd.incr(key)) - .run(args); + public Long incr(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } } @Override - public Long incrBy(final String key, final long value){ + public Long incrBy(final String key, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.INCRBY) - .general((cmd)->cmd.incrBy(key, value)) - .pipeline((cmd)->cmd.incrBy(key, value)) - .transaction((cmd)->cmd.incrBy(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + } } @Override - public Long incrBy(final byte[] key, final long value){ + public Long incrBy(final byte[] key, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.INCRBY) - .general((cmd)->cmd.incrBy(key, value)) - .pipeline((cmd)->cmd.incrBy(key, value)) - .transaction((cmd)->cmd.incrBy(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + } } @Override - public Double incrByFloat(final String key, final double value){ + public Double incrByFloat(final String key, final double value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.INCRBYFLOAT) - .general((cmd)->cmd.incrByFloat(key, value)) - .pipeline((cmd)->cmd.incrByFloat(key, value)) - .transaction((cmd)->cmd.incrByFloat(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), + (v)->v) + .run(args); + } } @Override - public Double incrByFloat(final byte[] key, final double value){ + public Double incrByFloat(final byte[] key, final double value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.INCRBYFLOAT) - .general((cmd)->cmd.incrByFloat(key, value)) - .pipeline((cmd)->cmd.incrByFloat(key, value)) - .transaction((cmd)->cmd.incrByFloat(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), + (v)->v) + .run(args); + } } @Override - public Long decr(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.DECR) - .general((cmd)->cmd.decr(key)) - .pipeline((cmd)->cmd.decr(key)) - .transaction((cmd)->cmd.decr(key)) - .run(args); + public Long decr(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } } @Override - public Long decr(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.DECR) - .general((cmd)->cmd.decr(key)) - .pipeline((cmd)->cmd.decr(key)) - .transaction((cmd)->cmd.decr(key)) - .run(args); + public Long decr(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } } @Override - public Long decrBy(final String key, final long value){ + public Long decrBy(final String key, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.DECRBY) - .general((cmd)->cmd.decrBy(key, value)) - .pipeline((cmd)->cmd.decrBy(key, value)) - .transaction((cmd)->cmd.decrBy(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + } } @Override - public Long decrBy(final byte[] key, final long value){ + public Long decrBy(final byte[] key, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.DECRBY) - .general((cmd)->cmd.decrBy(key, value)) - .pipeline((cmd)->cmd.decrBy(key, value)) - .transaction((cmd)->cmd.decrBy(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + } } @Override - public String get(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.GET) - .general((cmd)->cmd.get(key)) - .pipeline((cmd)->cmd.get(key)) - .transaction((cmd)->cmd.get(key)) - .run(args); + public String get(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + } } @Override - public byte[] get(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.GET) - .general((cmd)->cmd.get(key)) - .pipeline((cmd)->cmd.get(key)) - .transaction((cmd)->cmd.get(key)) - .run(args); + public byte[] get(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + } } @Override - public String getEx(final String key, final GetExArgument getExArgument){ + public String getEx(final String key, final GetExArgument getExArgument) { final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); - final GetExParams params = GetExArgumentConverter.INSTANCE.convert(getExArgument); - return new JedisSentinelCommand(client, ProtocolCommand.GETEX) - .general((cmd)->cmd.getEx(key, params)) - .pipeline((cmd)->cmd.getEx(key, params)) - .transaction((cmd)->cmd.getEx(key, params)) - .run(args); + final GetExParams getExParams = JedisGetExParams.from(getExArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GETEX, (cmd)->cmd.getEx(key, getExParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GETEX, + (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + } } @Override - public byte[] getEx(final byte[] key, final GetExArgument getExArgument){ + public byte[] getEx(final byte[] key, final GetExArgument getExArgument) { final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); - final GetExParams params = GetExArgumentConverter.INSTANCE.convert(getExArgument); - return new JedisSentinelCommand(client, ProtocolCommand.GETEX) - .general((cmd)->cmd.getEx(key, params)) - .pipeline((cmd)->cmd.getEx(key, params)) - .transaction((cmd)->cmd.getEx(key, params)) - .run(args); + final GetExParams getExParams = JedisGetExParams.from(getExArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GETEX, (cmd)->cmd.getEx(key, getExParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GETEX, + (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + } } @Override - public String getSet(final String key, final String value){ + public String getSet(final String key, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.GETSET) - .general((cmd)->cmd.getSet(key, value)) - .pipeline((cmd)->cmd.getSet(key, value)) - .transaction((cmd)->cmd.getSet(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + } } @Override - public byte[] getSet(final byte[] key, final byte[] value){ + public byte[] getSet(final byte[] key, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.GETSET) - .general((cmd)->cmd.getSet(key, value)) - .pipeline((cmd)->cmd.getSet(key, value)) - .transaction((cmd)->cmd.getSet(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), + (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + } } @Override - public String getDel(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.GETDEL) - .general((cmd)->cmd.getDel(key)) - .pipeline((cmd)->cmd.getDel(key)) - .transaction((cmd)->cmd.getDel(key)) - .run(args); + public String getDel(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + } } @Override - public byte[] getDel(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.GETDEL) - .general((cmd)->cmd.getDel(key)) - .pipeline((cmd)->cmd.getDel(key)) - .transaction((cmd)->cmd.getDel(key)) - .run(args); + public byte[] getDel(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + } } @Override - public List mGet(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand>(client, ProtocolCommand.MGET) - .general((cmd)->cmd.mget(keys)) - .pipeline((cmd)->cmd.mget(keys)) - .transaction((cmd)->cmd.mget(keys)) - .run(args); + public List mGet(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + } } @Override - public List mGet(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand>(client, ProtocolCommand.MGET) - .general((cmd)->cmd.mget(keys)) - .pipeline((cmd)->cmd.mget(keys)) - .transaction((cmd)->cmd.mget(keys)) - .run(args); + public List mGet(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + } } @Override - public Status mSet(final Map values){ + public Status mSet(final Map values) { final CommandArguments args = CommandArguments.create("values", values); final List temp = new ArrayList<>(values.size() * 2); @@ -282,15 +440,24 @@ public Status mSet(final Map values){ }); final String[] keysValues = temp.toArray(new String[0]); - return new JedisSentinelCommand(client, ProtocolCommand.MSET) - .general((cmd)->cmd.mset(keysValues), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.mset(keysValues), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.mset(keysValues), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + } } @Override - public Status mSetNx(final Map values){ + public Status mSetNx(final Map values) { final CommandArguments args = CommandArguments.create("values", values); final List temp = new ArrayList<>(values.size() * 2); @@ -300,191 +467,358 @@ public Status mSetNx(final Map values){ }); final String[] keysValues = temp.toArray(new String[0]); - return new JedisSentinelCommand(client, ProtocolCommand.MSETNX) - .general((cmd)->cmd.msetnx(keysValues), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.msetnx(keysValues), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.msetnx(keysValues), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + } } @Override - public Status pSetEx(final String key, final String value, final int lifetime){ + public Status pSetEx(final String key, final String value, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); - return new JedisSentinelCommand(client, ProtocolCommand.PSETEX) - .general((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } } @Override - public Status pSetEx(final byte[] key, final byte[] value, final int lifetime){ + public Status pSetEx(final byte[] key, final byte[] value, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); - return new JedisSentinelCommand(client, ProtocolCommand.PSETEX) - .general((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } } @Override - public Status set(final String key, final String value){ + public Status set(final String key, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.SET) - .general((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + } } @Override - public Status set(final byte[] key, final byte[] value){ + public Status set(final byte[] key, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.SET) - .general((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + } } @Override - public Status set(final String key, final String value, final SetArgument setArgument){ + public Status set(final String key, final String value, final SetArgument setArgument) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - final SetParams params = SetArgumentConverter.INSTANCE.convert(setArgument); - return new JedisSentinelCommand(client, ProtocolCommand.SET) - .general((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .run(args); + final SetParams setParams = JedisSetParams.from(setArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SET, + (cmd)->cmd.set(key, value, setParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SET, + (cmd)->cmd.set(key, value, setParams), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + } } @Override - public Status set(final byte[] key, final byte[] value, final SetArgument setArgument){ + public Status set(final byte[] key, final byte[] value, final SetArgument setArgument) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - final SetParams params = SetArgumentConverter.INSTANCE.convert(setArgument); - return new JedisSentinelCommand(client, ProtocolCommand.SET) - .general((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .run(args); + final SetParams setParams = JedisSetParams.from(setArgument); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SET, + (cmd)->cmd.set(key, value, setParams), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SET, + (cmd)->cmd.set(key, value, setParams), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + } } @Override - public Status setEx(final String key, final String value, final int lifetime){ + public Status setEx(final String key, final String value, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); - return new JedisSentinelCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } } @Override - public Status setEx(final byte[] key, final byte[] value, final int lifetime){ + public Status setEx(final byte[] key, final byte[] value, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); - return new JedisSentinelCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } } @Override - public Status setNx(final String key, final String value){ + public Status setNx(final String key, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + } } @Override - public Status setNx(final byte[] key, final byte[] value){ + public Status setNx(final byte[] key, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + } } @Override - public Long setRange(final String key, final long offset, final String value){ + public Long setRange(final String key, final long offset, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setrange(key, offset, value)) - .pipeline((cmd)->cmd.setrange(key, offset, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SETRANGE, (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + } } @Override - public Long setRange(final byte[] key, final long offset, final byte[] value){ + public Long setRange(final byte[] key, final long offset, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); - return new JedisSentinelCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setrange(key, offset, value)) - .pipeline((cmd)->cmd.setrange(key, offset, value)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SETRANGE, (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + } } @Override - public String getRange(final String key, final long start, final long end){ + public String getRange(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand(client, ProtocolCommand.GETRANGE) - .general((cmd)->cmd.getrange(key, start, end)) - .pipeline((cmd)->cmd.getrange(key, start, end)) - .transaction((cmd)->cmd.getrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + } } @Override - public byte[] getRange(final byte[] key, final long start, final long end){ + public byte[] getRange(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand(client, ProtocolCommand.GETRANGE) - .general((cmd)->cmd.getrange(key, start, end)) - .pipeline((cmd)->cmd.getrange(key, start, end)) - .transaction((cmd)->cmd.getrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + } } @Override - public Long strlen(final String key){ + public Long strlen(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.STRLEN) - .general((cmd)->cmd.strlen(key)) - .pipeline((cmd)->cmd.strlen(key)) - .transaction((cmd)->cmd.strlen(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } } @Override - public Long strlen(final byte[] key){ + public Long strlen(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisSentinelCommand(client, ProtocolCommand.STRLEN) - .general((cmd)->cmd.strlen(key)) - .pipeline((cmd)->cmd.strlen(key)) - .transaction((cmd)->cmd.strlen(key)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } } @Override - public String substr(final String key, final long start, final long end){ + public String substr(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand(client, ProtocolCommand.SUBSTR) - .general((cmd)->cmd.substr(key, (int) start, (int) end)) - .pipeline((cmd)->cmd.substr(key, (int) start, (int) end)) - .transaction((cmd)->cmd.substr(key, (int) start, (int) end)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + } } @Override - public byte[] substr(final byte[] key, final long start, final long end){ + public byte[] substr(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisSentinelCommand(client, ProtocolCommand.SUBSTR) - .general((cmd)->cmd.substr(key, (int) start, (int) end)) - .pipeline((cmd)->cmd.substr(key, (int) start, (int) end)) - .transaction((cmd)->cmd.substr(key, (int) start, (int) end)) - .run(args); + + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelTransactionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelTransactionOperations.java index dd1c1ca2f..3c8520e19 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelTransactionOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSentinelTransactionOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -29,7 +29,6 @@ import com.buession.redis.client.jedis.JedisSentinelClient; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; import com.buession.redis.exception.RedisException; import redis.clients.jedis.Builder; import redis.clients.jedis.Response; @@ -44,103 +43,194 @@ */ public final class JedisSentinelTransactionOperations extends AbstractTransactionOperations { - public JedisSentinelTransactionOperations(final JedisSentinelClient client){ + public JedisSentinelTransactionOperations(final JedisSentinelClient client) { super(client); } @Override - public Status multi(){ - return new JedisSentinelCommand(client, ProtocolCommand.MULTI) - .general((cmd)->{ - RedisConnection connection = client.getConnection(); - connection.multi(); + public void discard() { + if(isPipeline()){ + new JedisSentinelPipelineCommand<>(client, ProtocolCommand.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new JedisSentinelTransactionCommand<>(client, ProtocolCommand.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + }else{ + new JedisSentinelCommand<>(client, ProtocolCommand.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + } + } - return Status.SUCCESS; - }).transaction((cmd)->{ - RedisConnection connection = client.getConnection(); - connection.multi(); + @Override + public List exec() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); - return new Response<>(new Builder() { + return new Response<>(new Builder>() { - @Override - public Status build(Object data){ - return Status.SUCCESS; - } + @Override + public List build(Object data) { + return connection.exec(); + } - }); - }) - .run(); - } + }); + }, (v)->v).run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); - @Override - public List exec(){ - return new JedisSentinelCommand>(client, ProtocolCommand.EXEC) { + return new Response<>(new Builder>() { - @Override - public List execute() throws RedisException{ + @Override + public List build(Object data) { + return connection.exec(); + } + + }); + }, (v)->v).run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.EXEC, (cmd)->{ RedisConnection connection = client.getConnection(); return connection.exec(); - } - - }.run(); + }, (v)->v).run(); + } } @Override - public void discard(){ - new JedisSentinelCommand(client, ProtocolCommand.DISCARD) - .transaction((cmd)->{ - RedisConnection connection = client.getConnection(); - connection.discard(); - return null; - }) - .run(); - } + public Status multi() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand<>(client, ProtocolCommand.MULTI, (cmd)->{ + RedisConnection connection = client.getConnection(); - @Override - public Status watch(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.WATCH) - .general((cmd)->cmd.watch(keys), OkStatusConverter.INSTANCE) - .transaction((cmd)->new Response<>(new Builder() { + return new Response<>(new Builder() { + + @Override + public Status build(Object data) { + try{ + connection.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; + } + } + + }); + }, (v)->v) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.MULTI, (cmd)->{ + RedisConnection connection = client.getConnection(); + + return new Response<>(new Builder() { @Override - public String build(Object data){ - return cmd.watch(keys); + public Status build(Object data) { + try{ + connection.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; + } } - }), OkStatusConverter.INSTANCE) - .run(args); + }); + }, (v)->v) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.MULTI, (cmd)->{ + RedisConnection connection = client.getConnection(); + try{ + connection.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; + } + }, (v)->v) + .run(); + } + } + + @Override + public Status unwatch() { + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.UNWATCH) + .run(); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.UNWATCH, + (cmd)->new Response<>(new Builder() { + + @Override + public String build(Object data) { + return cmd.unwatch(); + } + + }), okStatusConverter) + .run(); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.UNWATCH, (cmd)->cmd.unwatch(), okStatusConverter) + .run(); + } } @Override - public Status watch(final byte[]... keys){ + public Status watch(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisSentinelCommand(client, ProtocolCommand.WATCH) - .general((cmd)->cmd.watch(keys), OkStatusConverter.INSTANCE) - .transaction((cmd)->new Response<>(new Builder() { - @Override - public String build(Object data){ - return cmd.watch(keys); - } + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.WATCH) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.WATCH, + (cmd)->new Response<>(new Builder() { + + @Override + public String build(Object data) { + return cmd.watch(keys); + } - }), OkStatusConverter.INSTANCE) - .run(args); + }), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.WATCH, (cmd)->cmd.watch(keys), okStatusConverter) + .run(args); + } } @Override - public Status unwatch(){ - return new JedisSentinelCommand(client, ProtocolCommand.UNWATCH) - .general((cmd)->cmd.unwatch(), OkStatusConverter.INSTANCE) - .transaction((cmd)->new Response<>(new Builder() { + public Status watch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - @Override - public String build(Object data){ - return cmd.unwatch(); - } + if(isPipeline()){ + return new JedisSentinelPipelineCommand(client, ProtocolCommand.WATCH) + .run(args); + }else if(isTransaction()){ + return new JedisSentinelTransactionCommand<>(client, ProtocolCommand.WATCH, + (cmd)->new Response<>(new Builder() { + + @Override + public String build(Object data) { + return cmd.watch(keys); + } - }), OkStatusConverter.INSTANCE) - .run(); + }), okStatusConverter) + .run(args); + }else{ + return new JedisSentinelCommand<>(client, ProtocolCommand.WATCH, (cmd)->cmd.watch(keys), okStatusConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisServerOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisServerOperations.java index 956590c05..6aae315d1 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisServerOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisServerOperations.java @@ -19,12 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; -import com.buession.core.collect.Arrays; +import com.buession.core.converter.ListConverter; import com.buession.lang.Status; import com.buession.redis.client.jedis.JedisStandaloneClient; import com.buession.redis.core.AclLog; @@ -42,17 +42,21 @@ import com.buession.redis.core.internal.convert.jedis.response.AccessControlLogEntryConverter; import com.buession.redis.core.internal.convert.jedis.response.AccessControlUserConverter; import com.buession.redis.core.internal.convert.jedis.params.FlushModeConverter; -import com.buession.redis.core.internal.convert.jedis.response.InfoConverter; +import com.buession.redis.core.internal.convert.jedis.response.MemoryStatsConverter; +import com.buession.redis.core.internal.convert.response.InfoConverter; import com.buession.redis.core.internal.convert.jedis.response.ModuleConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; import com.buession.redis.core.internal.convert.jedis.response.RedisServerTimeConverter; import com.buession.redis.core.internal.convert.jedis.response.SlowlogConverter; import com.buession.redis.core.internal.convert.jedis.response.RoleConverter; import com.buession.redis.core.internal.jedis.JedisFailoverParams; import redis.clients.jedis.JedisMonitor; import redis.clients.jedis.args.SaveMode; +import redis.clients.jedis.params.FailoverParams; +import redis.clients.jedis.resps.AccessControlLogEntry; +import redis.clients.jedis.resps.Slowlog; import java.util.List; +import java.util.Map; /** * Jedis 单机模式服务端命令操作 @@ -62,539 +66,1059 @@ */ public final class JedisServerOperations extends AbstractServerOperations { - public JedisServerOperations(final JedisStandaloneClient client){ + public JedisServerOperations(final JedisStandaloneClient client) { super(client); } @Override - public List aclCat(){ - return new JedisCommand>(client, ProtocolCommand.ACL_CAT) - .general((cmd)->cmd.aclCat()) - .run(); + public List aclCat() { + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_CAT, (cmd)->cmd.aclCat(), (v)->v) + .run(); + } } @Override - public List aclCat(final String categoryName){ + public List aclCat(final String categoryName) { final CommandArguments args = CommandArguments.create("categoryName", categoryName); - return new JedisCommand>(client, ProtocolCommand.ACL_CAT) - .general((cmd)->cmd.aclCat(categoryName)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_CAT, (cmd)->cmd.aclCat(categoryName), (v)->v) + .run(args); + } } @Override - public List aclCat(final byte[] categoryName){ + public List aclCat(final byte[] categoryName) { final CommandArguments args = CommandArguments.create("categoryName", categoryName); - return new JedisCommand>(client, ProtocolCommand.ACL_CAT) - .general((cmd)->cmd.aclCat(categoryName)) - .run(args); - } - @Override - public Status aclSetUser(final String username, final String... rules){ - final CommandArguments args = CommandArguments.create("username", username).put("rules", (Object[]) rules); - return new JedisCommand(client, ProtocolCommand.ACL_SETUSER) - .general((cmd)->cmd.aclSetUser(username, rules), OkStatusConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_CAT, (cmd)->cmd.aclCat(categoryName), (v)->v) + .run(args); + } } @Override - public Status aclSetUser(final byte[] username, final byte[]... rules){ + public Status aclSetUser(final String username, final String... rules) { final CommandArguments args = CommandArguments.create("username", username).put("rules", (Object[]) rules); - return new JedisCommand(client, ProtocolCommand.ACL_SETUSER) - .general((cmd)->cmd.aclSetUser(username, rules), OkStatusConverter.INSTANCE) - .run(args); - } - @Override - public AclUser aclGetUser(final String username){ - final CommandArguments args = CommandArguments.create("username", username); - return new JedisCommand(client, ProtocolCommand.ACL_GETUSER) - .general((cmd)->cmd.aclGetUser(username), AccessControlUserConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_SETUSER, (cmd)->cmd.aclSetUser(username, rules), + okStatusConverter) + .run(args); + } } @Override - public AclUser aclGetUser(final byte[] username){ - final CommandArguments args = CommandArguments.create("username", username); - return new JedisCommand(client, ProtocolCommand.ACL_GETUSER) - .general((cmd)->cmd.aclGetUser(username), AccessControlUserConverter.INSTANCE) - .run(args); - } + public Status aclSetUser(final byte[] username, final byte[]... rules) { + final CommandArguments args = CommandArguments.create("username", username).put("rules", (Object[]) rules); - @Override - public List aclUsers(){ - return new JedisCommand>(client, ProtocolCommand.ACL_USERS) - .general((cmd)->cmd.aclUsers()) - .run(); + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_SETUSER, (cmd)->cmd.aclSetUser(username, rules), + okStatusConverter) + .run(args); + } } @Override - public String aclWhoAmI(){ - return new JedisCommand(client, ProtocolCommand.ACL_WHOAMI) - .general((cmd)->cmd.aclWhoAmI()) - .run(); - } + public AclUser aclGetUser(final String username) { + final CommandArguments args = CommandArguments.create("username", username); + final AccessControlUserConverter accessControlUserConverter = new AccessControlUserConverter(); - @Override - public Long aclDelUser(final String... usernames){ - final CommandArguments args = CommandArguments.create("usernames", (Object[]) usernames); - return new JedisCommand(client, ProtocolCommand.ACL_DELUSER) - .general((cmd)->{ - if(usernames.length > 1){ - return cmd.aclDelUser(usernames[0], Arrays.subarray(usernames, 1, usernames.length - 1)); - }else{ - return cmd.aclDelUser(usernames[0]); - } - }) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_GETUSER, (cmd)->cmd.aclGetUser(username), + accessControlUserConverter) + .run(args); + } } @Override - public Long aclDelUser(final byte[]... usernames){ + public AclUser aclGetUser(final byte[] username) { + final CommandArguments args = CommandArguments.create("username", username); + final AccessControlUserConverter accessControlUserConverter = new AccessControlUserConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_GETUSER, (cmd)->cmd.aclGetUser(username), + accessControlUserConverter) + .run(args); + } + } + + @Override + public List aclUsers() { + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_USERS, (cmd)->cmd.aclUsers(), (v)->v) + .run(); + } + } + + @Override + public String aclWhoAmI() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_WHOAMI, (cmd)->cmd.aclWhoAmI(), (v)->v) + .run(); + } + } + + @Override + public Long aclDelUser(final String... usernames) { final CommandArguments args = CommandArguments.create("usernames", (Object[]) usernames); - return new JedisCommand(client, ProtocolCommand.ACL_DELUSER) - .general((cmd)->{ - if(usernames.length > 1){ - return cmd.aclDelUser(usernames[0], Arrays.subarray(usernames, 1, usernames.length - 1)); - }else{ - return cmd.aclDelUser(usernames[0]); - } - }) - .run(args); - } - @Override - public String aclGenPass(){ - return new JedisCommand(client, ProtocolCommand.ACL_GENPASS) - .general((cmd)->cmd.aclGenPass()) - .run(); - } - - @Override - public List aclList(){ - return new JedisCommand>(client, ProtocolCommand.ACL_LIST) - .general((cmd)->cmd.aclList()) - .run(); + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.ACL_DELUSER) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.ACL_DELUSER) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_DELUSER, (cmd)->cmd.aclDelUser(usernames), (v)->v) + .run(args); + } } @Override - public Status aclLoad(){ - return new JedisCommand(client, ProtocolCommand.ACL_LOAD) - .general((cmd)->cmd.aclLoad(), OkStatusConverter.INSTANCE) - .run(); - } - - @Override - public List aclLog(){ - return new JedisCommand>(client, ProtocolCommand.ACL_LOG) - .general((cmd)->cmd.aclLog(), AccessControlLogEntryConverter.LIST_CONVERTER) - .run(); - } + public Long aclDelUser(final byte[]... usernames) { + final CommandArguments args = CommandArguments.create("usernames", (Object[]) usernames); - @Override - public List aclLog(final long count){ + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.ACL_DELUSER) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.ACL_DELUSER) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_DELUSER, (cmd)->cmd.aclDelUser(usernames), (v)->v) + .run(args); + } + } + + @Override + public String aclGenPass() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_GENPASS, (cmd)->cmd.aclGenPass(), (v)->v) + .run(); + } + } + + @Override + public List aclList() { + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_LIST, (cmd)->cmd.aclList(), (v)->v) + .run(); + } + } + + @Override + public Status aclLoad() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_LOAD, (cmd)->cmd.aclLoad(), okStatusConverter) + .run(); + } + } + + @Override + public List aclLog() { + final ListConverter listAccessControlLogEntryConverter = + AccessControlLogEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_LOG, (cmd)->cmd.aclLog(), + listAccessControlLogEntryConverter) + .run(); + } + } + + @Override + public List aclLog(final long count) { final CommandArguments args = CommandArguments.create("count", count); - return new JedisCommand>(client, ProtocolCommand.ACL_LOG) - .general((cmd)->cmd.aclLog((int) count), AccessControlLogEntryConverter.LIST_CONVERTER) - .run(args); - } - - @Override - public Status aclLogReset(){ - return new JedisCommand(client, ProtocolCommand.ACL_LOGREST) - .general((cmd)->cmd.aclLogReset(), OkStatusConverter.INSTANCE) - .run(); - } - - @Override - public Status aclLogSave(){ - return new JedisCommand(client, ProtocolCommand.ACL_LOGSAVE) - .run(); - } - - @Override - public String bgRewriteAof(){ - return new JedisCommand(client, ProtocolCommand.BGREWRITEAOF) - .general((cmd)->cmd.bgrewriteaof()) - .run(); - } - - @Override - public String bgSave(){ - return new JedisCommand(client, ProtocolCommand.BGREWRITEAOF) - .general((cmd)->cmd.bgsave()) - .run(); - } - - @Override - public Status configSet(final String parameter, final String value){ - final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); - return new JedisCommand(client, ProtocolCommand.CONFIG_SET) - .general((cmd)->cmd.configSet(parameter, value), OkStatusConverter.INSTANCE) - .run(args); - } - - @Override - public Status configSet(final byte[] parameter, final byte[] value){ + final ListConverter listAccessControlLogEntryConverter = + AccessControlLogEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_LOG, (cmd)->cmd.aclLog((int) count), + listAccessControlLogEntryConverter) + .run(args); + } + } + + @Override + public Status aclLogReset() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ACL_LOGREST, (cmd)->cmd.aclLogReset(), + okStatusConverter) + .run(); + } + } + + @Override + public Status aclLogSave() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + }else{ + return new JedisCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + } + } + + @Override + public String bgRewriteAof() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BGREWRITEAOF, (cmd)->cmd.bgrewriteaof(), (v)->v) + .run(); + } + } + + @Override + public String bgSave() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.BGSAVE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.BGSAVE) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BGSAVE, (cmd)->cmd.bgsave(), (v)->v) + .run(); + } + } + + @Override + public Status configSet(final String parameter, final String value) { final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); - return new JedisCommand(client, ProtocolCommand.CONFIG_SET) - .general((cmd)->cmd.configSet(parameter, value), OkStatusConverter.INSTANCE) - .run(args); - } - - @Override - public List configGet(final String parameter){ - final CommandArguments args = CommandArguments.create("parameter", parameter); - return new JedisCommand>(client, ProtocolCommand.CONFIG_GET) - .general((cmd)->cmd.configGet(parameter)) - .run(args); - } - - @Override - public List configGet(final byte[] parameter){ - final CommandArguments args = CommandArguments.create("parameter", parameter); - return new JedisCommand>(client, ProtocolCommand.CONFIG_GET) - .general((cmd)->cmd.configGet(parameter)) - .run(args); - } - - @Override - public Status configResetStat(){ - return new JedisCommand(client, ProtocolCommand.CONFIG_RESETSTAT) - .general((cmd)->cmd.configResetStat(), OkStatusConverter.INSTANCE) - .run(); - } - - @Override - public Status configRewrite(){ - return new JedisCommand(client, ProtocolCommand.CONFIG_REWRITE) - .general((cmd)->cmd.configRewrite(), OkStatusConverter.INSTANCE) - .run(); - } - @Override - public Long dbSize(){ - return new JedisCommand(client, ProtocolCommand.DBSIZE) - .general((cmd)->cmd.dbSize()).pipeline((cmd)->cmd.dbSize()) - .run(); + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CONFIG_SET, (cmd)->cmd.configSet(parameter, value), + okStatusConverter) + .run(args); + } } @Override - public Status failover(){ - return new JedisCommand(client, ProtocolCommand.FAILOVER) - .general((cmd)->cmd.failover(), OkStatusConverter.INSTANCE) - .run(); - } + public Status configSet(final byte[] parameter, final byte[] value) { + final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); - @Override - public Status failover(final String host, final int port){ + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CONFIG_SET, (cmd)->cmd.configSet(parameter, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status configSet(final Map configs) { + final CommandArguments args = CommandArguments.create("configs", configs); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CONFIG_SET, (cmd)->cmd.configSet(configs), + okStatusConverter) + .run(args); + } + } + + @Override + public Map configGet(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + + if(isPipeline()){ + return new JedisPipelineCommand, Map>(client, + ProtocolCommand.CONFIG_GET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, Map>(client, + ProtocolCommand.CONFIG_GET) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CONFIG_GET, (cmd)->cmd.configGet(pattern), (v)->v) + .run(args); + } + } + + @Override + public Map configGet(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + + if(isPipeline()){ + return new JedisPipelineCommand, Map>(client, + ProtocolCommand.CONFIG_GET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, Map>(client, + ProtocolCommand.CONFIG_GET) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CONFIG_GET, (cmd)->cmd.configGet(pattern), (v)->v) + .run(args); + } + } + + @Override + public Status configResetStat() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CONFIG_RESETSTAT) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CONFIG_RESETSTAT) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CONFIG_RESETSTAT, (cmd)->cmd.configResetStat(), + okStatusConverter) + .run(); + } + } + + @Override + public Status configRewrite() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.CONFIG_REWRITE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.CONFIG_REWRITE) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.CONFIG_REWRITE, (cmd)->cmd.configRewrite(), + okStatusConverter) + .run(); + } + } + + @Override + public Long dbSize() { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.DBSIZE, (cmd)->cmd.dbSize(), (v)->v) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.DBSIZE) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.DBSIZE, (cmd)->cmd.dbSize(), (v)->v) + .run(); + } + } + + @Override + public Status failover() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.FAILOVER) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.FAILOVER) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.FAILOVER, (cmd)->cmd.failover(), okStatusConverter) + .run(); + } + } + + @Override + public Status failover(final String host, final int port) { final CommandArguments args = CommandArguments.create("host", host).put("port", port); - final JedisFailoverParams params = new JedisFailoverParams(host, port); - return new JedisCommand(client, ProtocolCommand.FAILOVER) - .general((cmd)->cmd.failover(params), OkStatusConverter.INSTANCE) - .run(args); + final FailoverParams failoverParams = new JedisFailoverParams(host, port); + + return failover(failoverParams, args); } @Override - public Status failover(final String host, final int port, final int timeout){ + public Status failover(final String host, final int port, final int timeout) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("timeout", timeout); - final JedisFailoverParams params = new JedisFailoverParams(host, port, timeout); - return new JedisCommand(client, ProtocolCommand.FAILOVER) - .general((cmd)->cmd.failover(params), OkStatusConverter.INSTANCE) - .run(args); + final FailoverParams failoverParams = new JedisFailoverParams(host, port, timeout); + + return failover(failoverParams, args); } @Override - public Status failover(final String host, final int port, final boolean isForce, final int timeout){ + public Status failover(final String host, final int port, final boolean isForce, final int timeout) { final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("isForce", isForce) .put("timeout", timeout); - final JedisFailoverParams params = new JedisFailoverParams(host, port, timeout, isForce); - return new JedisCommand(client, ProtocolCommand.FAILOVER) - .general((cmd)->cmd.failover(params), OkStatusConverter.INSTANCE) - .run(args); - } + final FailoverParams failoverParams = new JedisFailoverParams(host, port, timeout, isForce); - @Override - public Status failover(final int timeout){ - final CommandArguments args = CommandArguments.create("timeout", timeout); - final JedisFailoverParams params = new JedisFailoverParams(timeout); - return new JedisCommand(client, ProtocolCommand.FAILOVER) - .general((cmd)->cmd.failover(params), OkStatusConverter.INSTANCE) - .run(args); + return failover(failoverParams, args); } @Override - public Status flushAll(){ - return new JedisCommand(client, ProtocolCommand.FLUSHALL) - .general((cmd)->cmd.flushAll(), OkStatusConverter.INSTANCE) - .run(); - } + public Status failover(final int timeout) { + final CommandArguments args = CommandArguments.create("timeout", timeout); + final FailoverParams failoverParams = new JedisFailoverParams(timeout); - @Override - public Status flushAll(final FlushMode mode){ - final CommandArguments args = CommandArguments.create("mode", mode); - return new JedisCommand(client, ProtocolCommand.FLUSHALL) - .general((cmd)->cmd.flushAll(FlushModeConverter.INSTANCE.convert(mode)), OkStatusConverter.INSTANCE) - .run(args); + return failover(failoverParams, args); } @Override - public Status flushDb(){ - return new JedisCommand(client, ProtocolCommand.FLUSHDB) - .general((cmd)->cmd.flushDB(), OkStatusConverter.INSTANCE) - .run(); + public Status flushAll() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.FLUSHALL) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.FLUSHALL) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.FLUSHALL, (cmd)->cmd.flushAll(), okStatusConverter) + .run(); + } } @Override - public Status flushDb(final FlushMode mode){ + public Status flushAll(final FlushMode mode) { final CommandArguments args = CommandArguments.create("mode", mode); - return new JedisCommand(client, ProtocolCommand.FLUSHDB) - .general((cmd)->cmd.flushDB(FlushModeConverter.INSTANCE.convert(mode)), OkStatusConverter.INSTANCE) - .run(args); - } + final redis.clients.jedis.args.FlushMode flushMode = (new FlushModeConverter()).convert(mode); - @Override - public Info info(){ - return new JedisCommand(client, ProtocolCommand.INFO) - .general((cmd)->cmd.info(), InfoConverter.INSTANCE) - .run(); + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.FLUSHALL) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.FLUSHALL) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.FLUSHALL, (cmd)->cmd.flushAll(flushMode), + okStatusConverter) + .run(args); + } } @Override - public Info info(final Info.Section section){ - final CommandArguments args = CommandArguments.create("section", section); - return new JedisCommand(client, ProtocolCommand.INFO) - .general((cmd)->cmd.info(section.name().toLowerCase()), InfoConverter.INSTANCE) - .run(args); + public Status flushDb() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.FLUSHDB) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.FLUSHDB) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.flushDB(), okStatusConverter) + .run(); + } } @Override - public Long lastSave(){ - return new JedisCommand(client, ProtocolCommand.LASTSAVE) - .general((cmd)->cmd.lastsave()) - .run(); - } + public Status flushDb(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + final redis.clients.jedis.args.FlushMode flushMode = (new FlushModeConverter()).convert(mode); - @Override - public String memoryDoctor(){ - return new JedisCommand(client, ProtocolCommand.MEMORY_DOCTOR) - .general((cmd)->cmd.memoryDoctor()) - .run(); + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.FLUSHDB) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.FLUSHDB) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.flushDB(flushMode), okStatusConverter) + .run(args); + } } @Override - public Status memoryPurge(){ - return new JedisCommand(client, ProtocolCommand.MEMORY_PURGE) - .run(); - } + public Info info() { + final InfoConverter infoConverter = new InfoConverter(); - @Override - public MemoryStats memoryStats(){ - return new JedisCommand(client, ProtocolCommand.MEMORY_STATS) - .run(); + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.INFO) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.INFO) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.INFO, (cmd)->cmd.info(), infoConverter) + .run(); + } } @Override - public Long memoryUsage(final String key){ + public Info info(final Info.Section section) { + final CommandArguments args = CommandArguments.create("section", section); + final String sectionName = section.name().toLowerCase(); + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.INFO) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.INFO) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.INFO, (cmd)->cmd.info(sectionName), infoConverter) + .run(args); + } + } + + @Override + public Long lastSave() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.LASTSAVE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.LASTSAVE) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.LASTSAVE, (cmd)->cmd.lastsave(), (v)->v) + .run(); + } + } + + @Override + public String memoryDoctor() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MEMORY_DOCTOR, (cmd)->cmd.memoryDoctor(), (v)->v) + .run(); + } + } + + @Override + public Status memoryPurge() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MEMORY_PURGE, (cmd)->cmd.memoryPurge(), + okStatusConverter) + .run(); + } + } + + @Override + public MemoryStats memoryStats() { + final MemoryStatsConverter memoryStatsConverter = new MemoryStatsConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MEMORY_STATS, (cmd)->cmd.memoryStats(), + memoryStatsConverter) + .run(); + } + } + + @Override + public Long memoryUsage(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.MEMORY_USAGE) - .general((cmd)->cmd.memoryUsage(key)) - .pipeline((cmd)->cmd.memoryUsage(key)) - .transaction((cmd)->cmd.memoryUsage(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } } @Override - public Long memoryUsage(final byte[] key){ + public Long memoryUsage(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.MEMORY_USAGE) - .general((cmd)->cmd.memoryUsage(key)) - .pipeline((cmd)->cmd.memoryUsage(key)) - .transaction((cmd)->cmd.memoryUsage(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } } @Override - public Long memoryUsage(final String key, final int samples){ + public Long memoryUsage(final String key, final int samples) { final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); - return new JedisCommand(client, ProtocolCommand.MEMORY_USAGE) - .general((cmd)->cmd.memoryUsage(key, samples)) - .pipeline((cmd)->cmd.memoryUsage(key, samples)) - .transaction((cmd)->cmd.memoryUsage(key, samples)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key, samples), + (v)->v) + .run(args); + } } @Override - public Long memoryUsage(final byte[] key, final int samples){ + public Long memoryUsage(final byte[] key, final int samples) { final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); - return new JedisCommand(client, ProtocolCommand.MEMORY_USAGE) - .general((cmd)->cmd.memoryUsage(key, samples)) - .pipeline((cmd)->cmd.memoryUsage(key, samples)) - .transaction((cmd)->cmd.memoryUsage(key, samples)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key, samples), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key, samples), + (v)->v) + .run(args); + } } @Override - public List moduleList(){ - return new JedisCommand>(client, ProtocolCommand.MODULE_LIST) - .general((cmd)->cmd.moduleList(), ModuleConverter.LIST_CONVERTER) - .run(); + public List moduleList() { + final ListConverter listModuleConverter = ModuleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.MODULE_LIST) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, ProtocolCommand.MODULE_LIST) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MODULE_LIST, (cmd)->cmd.moduleList(), + listModuleConverter) + .run(); + } } @Override - public Status moduleLoad(final String path, final String... arguments){ + public Status moduleLoad(final String path, final String... arguments) { final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); - return new JedisCommand(client, ProtocolCommand.MODULE_LOAD) - .general((cmd)->cmd.moduleLoad(path, arguments), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MODULE_LOAD, (cmd)->cmd.moduleLoad(path, arguments), + okStatusConverter) + .run(args); + } } @Override - public Status moduleUnLoad(final String name){ + public Status moduleUnLoad(final String name) { final CommandArguments args = CommandArguments.create("name", name); - return new JedisCommand(client, ProtocolCommand.MODULE_UNLOAD) - .general((cmd)->cmd.moduleUnload(name), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MODULE_UNLOAD, (cmd)->cmd.moduleUnload(name), + okStatusConverter) + .run(args); + } } @Override - public void monitor(final RedisMonitor redisMonitor){ + public void monitor(final RedisMonitor redisMonitor) { final CommandArguments args = CommandArguments.create("redisMonitor", redisMonitor); - new JedisCommand(client, ProtocolCommand.MONITOR) - .general((cmd)->{ - cmd.monitor(new JedisMonitor() { - @Override - public void onCommand(final String command){ - redisMonitor.onCommand(command); - } + if(isPipeline()){ + new JedisPipelineCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + }else{ + new JedisCommand<>(client, ProtocolCommand.MONITOR, (cmd)->{ + cmd.monitor(new JedisMonitor() { + + @Override + public void onCommand(final String command) { + redisMonitor.onCommand(command); + } - }); - return null; - }) - .run(args); + }); + return null; + }, (v)->v) + .run(args); + } } @Override - public Object pSync(final String replicationId, final long offset){ + public Object pSync(final String replicationId, final long offset) { final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); - return new JedisCommand<>(client, ProtocolCommand.PSYNC) - .run(args); + return pSync(args); } @Override - public Object pSync(final byte[] replicationId, final long offset){ + public Object pSync(final byte[] replicationId, final long offset) { final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); - return new JedisCommand<>(client, ProtocolCommand.PSYNC) - .run(args); - } - - @Override - public void sync(){ - new JedisCommand(client, ProtocolCommand.SYNC) - .pipeline((cmd)->{ - cmd.sync(); - return null; - }) - .run(); + return pSync(args); } @Override - public Status replicaOf(final String host, final int port){ - final CommandArguments args = CommandArguments.create("host", host).put("port", port); - return new JedisCommand(client, ProtocolCommand.REPLICAOF) - .general((cmd)->cmd.replicaof(host, port), OkStatusConverter.INSTANCE) - .run(args); + public void sync() { + if(isPipeline()){ + new JedisPipelineCommand<>(client, ProtocolCommand.SYNC, (cmd)->{ + cmd.sync(); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, ProtocolCommand.SYNC) + .run(); + }else{ + new JedisCommand<>(client, ProtocolCommand.SYNC) + .run(); + } } @Override - public Status slaveOf(final String host, final int port){ + public Status replicaOf(final String host, final int port) { final CommandArguments args = CommandArguments.create("host", host).put("port", port); - return new JedisCommand(client, ProtocolCommand.SLAVEOF) - .general((cmd)->cmd.slaveof(host, port), OkStatusConverter.INSTANCE) - .run(args); - } - @Override - public List role(){ - return new JedisCommand>(client, ProtocolCommand.ROLE) - .general((cmd)->cmd.role(), RoleConverter.LIST_CONVERTER) - .run(); + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.REPLICAOF, (cmd)->cmd.replicaof(host, port), + okStatusConverter) + .run(args); + } } @Override - public Status save(){ - return new JedisCommand(client, ProtocolCommand.SAVE) - .general((cmd)->cmd.save(), OkStatusConverter.INSTANCE) - .run(); - } - - @Override - public void shutdown(){ - new JedisCommand(client, ProtocolCommand.SHUTDOWN) - .general((cmd)->{ - cmd.shutdown(); - return null; - }) - .run(); - } + public Status slaveOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); - @Override - public void shutdown(final boolean save){ + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.SLAVEOF) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.SLAVEOF) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SLAVEOF, (cmd)->cmd.slaveof(host, port), + okStatusConverter) + .run(args); + } + } + + @Override + public Role role() { + final RoleConverter roleConverter = new RoleConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.ROLE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.ROLE) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ROLE, (cmd)->cmd.role(), roleConverter) + .run(); + } + } + + @Override + public Status save() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.SAVE) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.SAVE) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SAVE, (cmd)->cmd.save(), okStatusConverter) + .run(); + } + } + + @Override + public void shutdown() { + if(isPipeline()){ + new JedisPipelineCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + }else{ + new JedisCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(); + return null; + }, (v)->v) + .run(); + } + } + + @Override + public void shutdown(final boolean save) { final CommandArguments args = CommandArguments.create("save", save); - new JedisCommand(client, ProtocolCommand.SHUTDOWN) - .general((cmd)->{ - final SaveMode saveMode = save ? SaveMode.SAVE : SaveMode.NOSAVE; - cmd.shutdown(saveMode); - return null; - }) - .run(args); - } - - @Override - public List slowLogGet(){ - return new JedisCommand>(client, ProtocolCommand.SLOWLOG_GET) - .general((cmd)->cmd.slowlogGet(), SlowlogConverter.LIST_CONVERTER) - .run(); - } - - @Override - public List slowLogGet(final long count){ + final SaveMode saveMode = save ? SaveMode.SAVE : SaveMode.NOSAVE; + + if(isPipeline()){ + new JedisPipelineCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + }else{ + new JedisCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(saveMode); + return null; + }, (v)->v) + .run(); + } + } + + @Override + public List slowLogGet() { + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + } + } + + @Override + public List slowLogGet(final long count) { final CommandArguments args = CommandArguments.create("count", count); - return new JedisCommand>(client, ProtocolCommand.SLOWLOG_GET) - .general((cmd)->cmd.slowlogGet(count), SlowlogConverter.LIST_CONVERTER) - .run(args); - } - - @Override - public Long slowLogLen(){ - return new JedisCommand(client, ProtocolCommand.SLOWLOG_LEN) - .general((cmd)->cmd.slowlogLen()) - .run(); - } - - @Override - public Status slowLogReset(){ - return new JedisCommand(client, ProtocolCommand.SLOWLOG_RESET) - .general((cmd)->cmd.slowlogReset(), OkStatusConverter.INSTANCE) - .run(); - } - - @Override - public Status swapdb(final int db1, final int db2){ + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SLOWLOG_GET, (cmd)->cmd.slowlogGet(count), + listSlowlogConverter) + .run(args); + } + } + + @Override + public Long slowLogLen() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.SLOWLOG_LEN) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.SLOWLOG_LEN) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SLOWLOG_RESET, (cmd)->cmd.slowlogLen(), (v)->v) + .run(); + } + } + + @Override + public Status slowLogReset() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.SLOWLOG_RESET) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.SLOWLOG_RESET) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + } + } + + @Override + public Status swapdb(final int db1, final int db2) { final CommandArguments args = CommandArguments.create("db1", db1).put("db2", db2); - return new JedisCommand(client, ProtocolCommand.SWAPDB) - .general((cmd)->cmd.swapDB(db1, db2), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.swapDB(db1, db2), OkStatusConverter.INSTANCE) - .run(args); - } - @Override - public RedisServerTime time(){ - return new JedisCommand(client, ProtocolCommand.TIME) - .general((cmd)->cmd.time(), RedisServerTimeConverter.INSTANCE) - .pipeline((cmd)->cmd.time(), RedisServerTimeConverter.INSTANCE) - .run(); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SWAPDB, (cmd)->cmd.swapDB(db1, db2), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.SWAPDB) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SWAPDB, (cmd)->cmd.swapDB(db1, db2), okStatusConverter) + .run(args); + } + } + + @Override + public RedisServerTime time() { + final RedisServerTimeConverter redisServerTimeConverter = new RedisServerTimeConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.TIME, (cmd)->cmd.time(), + redisServerTimeConverter) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.TIME) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.TIME, (cmd)->cmd.time(), redisServerTimeConverter) + .run(); + } + } + + private Status failover(final FailoverParams failoverParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.FAILOVER) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand(client, ProtocolCommand.FAILOVER) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.FAILOVER, (cmd)->cmd.failover(failoverParams), + okStatusConverter) + .run(args); + } + } + + private Object pSync(final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSetOperations.java index 238067605..7225955dd 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSetOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSetOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -29,9 +29,9 @@ import com.buession.redis.core.ScanResult; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; import com.buession.redis.core.internal.jedis.JedisScanParams; +import redis.clients.jedis.params.ScanParams; import java.util.List; import java.util.Set; @@ -44,458 +44,726 @@ */ public final class JedisSetOperations extends AbstractSetOperations { - public JedisSetOperations(final JedisStandaloneClient client){ + public JedisSetOperations(final JedisStandaloneClient client) { super(client); } @Override - public Long sAdd(final String key, final String... members){ + public Long sAdd(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisCommand(client, ProtocolCommand.SADD) - .general((cmd)->cmd.sadd(key, members)) - .pipeline((cmd)->cmd.sadd(key, members)) - .transaction((cmd)->cmd.sadd(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } } @Override - public Long sAdd(final byte[] key, final byte[]... members){ + public Long sAdd(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisCommand(client, ProtocolCommand.SADD) - .general((cmd)->cmd.sadd(key, members)) - .pipeline((cmd)->cmd.sadd(key, members)) - .transaction((cmd)->cmd.sadd(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } } @Override - public Long sCard(final String key){ + public Long sCard(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.SCARD) - .general((cmd)->cmd.scard(key)) - .pipeline((cmd)->cmd.scard(key)) - .transaction((cmd)->cmd.scard(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } } @Override - public Long sCard(final byte[] key){ + public Long sCard(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.SCARD) - .general((cmd)->cmd.scard(key)) - .pipeline((cmd)->cmd.scard(key)) - .transaction((cmd)->cmd.scard(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } } @Override - public Set sDiff(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand>(client, ProtocolCommand.SDIFF) - .general((cmd)->cmd.sdiff(keys)) - .pipeline((cmd)->cmd.sdiff(keys)) - .transaction((cmd)->cmd.sdiff(keys)) - .run(args); + public Set sDiff(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + } } @Override - public Set sDiff(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand>(client, ProtocolCommand.SDIFF) - .general((cmd)->cmd.sdiff(keys)) - .pipeline((cmd)->cmd.sdiff(keys)) - .transaction((cmd)->cmd.sdiff(keys)) - .run(args); + public Set sDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), (v)->v) + .run(args); + } } @Override - public Long sDiffStore(final String destKey, final String... keys){ + public Long sDiffStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.SDIFFSTORE) - .general((cmd)->cmd.sdiffstore(destKey, keys)) - .pipeline((cmd)->cmd.sdiffstore(destKey, keys)) - .transaction((cmd)->cmd.sdiffstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + } } @Override - public Long sDiffStore(final byte[] destKey, final byte[]... keys){ + public Long sDiffStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.SDIFFSTORE) - .general((cmd)->cmd.sdiffstore(destKey, keys)) - .pipeline((cmd)->cmd.sdiffstore(destKey, keys)) - .transaction((cmd)->cmd.sdiffstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + } } @Override - public Set sInter(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand>(client, ProtocolCommand.SINTER) - .general((cmd)->cmd.sinter(keys)) - .pipeline((cmd)->cmd.sinter(keys)) - .transaction((cmd)->cmd.sinter(keys)) - .run(args); + public Set sInter(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + } } @Override - public Set sInter(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand>(client, ProtocolCommand.SINTER) - .general((cmd)->cmd.sinter(keys)) - .pipeline((cmd)->cmd.sinter(keys)) - .transaction((cmd)->cmd.sinter(keys)) - .run(args); + public Set sInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), (v)->v) + .run(args); + } } @Override - public Long sInterStore(final String destKey, final String... keys){ + public Long sInterStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.SINTERSTORE) - .general((cmd)->cmd.sinterstore(destKey, keys)) - .pipeline((cmd)->cmd.sinterstore(destKey, keys)) - .transaction((cmd)->cmd.sinterstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SINTERSTORE, (cmd)->cmd.sinterstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long sInterStore(final byte[] destKey, final byte[]... keys){ + public Long sInterStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.SINTERSTORE) - .general((cmd)->cmd.sinterstore(destKey, keys)) - .pipeline((cmd)->cmd.sinterstore(destKey, keys)) - .transaction((cmd)->cmd.sinterstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SINTERSTORE, (cmd)->cmd.sinterstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Boolean sIsMember(final String key, final String member){ + public Boolean sIsMember(final String key, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisCommand(client, ProtocolCommand.SISMEMBER) - .general((cmd)->cmd.sismember(key, member)) - .pipeline((cmd)->cmd.sismember(key, member)) - .transaction((cmd)->cmd.sismember(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SISMEMBER, (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + } } @Override - public Boolean sIsMember(final byte[] key, final byte[] member){ + public Boolean sIsMember(final byte[] key, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisCommand(client, ProtocolCommand.SISMEMBER) - .general((cmd)->cmd.sismember(key, member)) - .pipeline((cmd)->cmd.sismember(key, member)) - .transaction((cmd)->cmd.sismember(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SISMEMBER, (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + } } @Override - public List smIsMember(final String key, final String... members){ + public List smIsMember(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisCommand>(client, ProtocolCommand.SMISMEMBER) - .general((cmd)->cmd.smismember(key, members)) - .pipeline((cmd)->cmd.smismember(key, members)) - .transaction((cmd)->cmd.smismember(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SMISMEMBER, (cmd)->cmd.smismember(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SMISMEMBER, (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + } } @Override - public List smIsMember(final byte[] key, final byte[]... members){ + public List smIsMember(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisCommand>(client, ProtocolCommand.SMISMEMBER) - .general((cmd)->cmd.smismember(key, members)) - .pipeline((cmd)->cmd.smismember(key, members)) - .transaction((cmd)->cmd.smismember(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SMISMEMBER, (cmd)->cmd.smismember(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SMISMEMBER, + (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SMISMEMBER, (cmd)->cmd.smismember(key, members), (v)->v) + .run(args); + } } @Override - public Set sMembers(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand>(client, ProtocolCommand.SMEMBERS) - .general((cmd)->cmd.smembers(key)) - .pipeline((cmd)->cmd.smembers(key)) - .transaction((cmd)->cmd.smembers(key)) - .run(args); + public Set sMembers(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + } } @Override - public Set sMembers(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand>(client, ProtocolCommand.SMEMBERS) - .general((cmd)->cmd.smembers(key)) - .pipeline((cmd)->cmd.smembers(key)) - .transaction((cmd)->cmd.smembers(key)) - .run(args); + public Set sMembers(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), (v)->v) + .run(args); + } } @Override - public Status sMove(final String key, final String destKey, final String member){ + public Status sMove(final String key, final String destKey, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); - return new JedisCommand(client, ProtocolCommand.SMOVE) - .general((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + } } @Override - public Status sMove(final byte[] key, final byte[] destKey, final byte[] member){ + public Status sMove(final byte[] key, final byte[] destKey, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); - return new JedisCommand(client, ProtocolCommand.SMOVE) - .general((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.smove(key, destKey, member), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SMOVE, (cmd)->cmd.smove(key, destKey, member), + oneStatusConverter) + .run(args); + } } @Override - public String sPop(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.SPOP) - .general((cmd)->cmd.spop(key)) - .pipeline((cmd)->cmd.spop(key)) - .transaction((cmd)->cmd.spop(key)) - .run(args); + public String sPop(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + } } @Override - public byte[] sPop(final byte[] key){ + public byte[] sPop(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.SPOP) - .general((cmd)->cmd.spop(key)) - .pipeline((cmd)->cmd.spop(key)) - .transaction((cmd)->cmd.spop(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), (v)->v) + .run(args); + } } @Override - public Set sPop(final String key, final long count){ + public Set sPop(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.SPOP) - .general((cmd)->cmd.spop(key, count)) - .pipeline((cmd)->cmd.spop(key, count)) - .transaction((cmd)->cmd.spop(key, count)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + } } @Override - public Set sPop(final byte[] key, final long count){ + public Set sPop(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.SPOP) - .general((cmd)->cmd.spop(key, count)) - .pipeline((cmd)->cmd.spop(key, count)) - .transaction((cmd)->cmd.spop(key, count)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), (v)->v) + .run(args); + } } @Override - public String sRandMember(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.SRANDMEMBER) - .general((cmd)->cmd.srandmember(key)) - .pipeline((cmd)->cmd.srandmember(key)) - .run(args); + public String sRandMember(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + } } @Override - public byte[] sRandMember(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.SRANDMEMBER) - .general((cmd)->cmd.srandmember(key)) - .pipeline((cmd)->cmd.srandmember(key)) - .run(args); + public byte[] sRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), (v)->v) + .run(args); + } } @Override - public List sRandMember(final String key, final long count){ + public List sRandMember(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.SRANDMEMBER) - .general((cmd)->cmd.srandmember(key, (int) count)) - .pipeline((cmd)->cmd.srandmember(key, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key, (int) count), + (v)->v) + .run(args); + } } @Override - public List sRandMember(final byte[] key, final long count){ + public List sRandMember(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.SRANDMEMBER) - .general((cmd)->cmd.srandmember(key, (int) count)) - .pipeline((cmd)->cmd.srandmember(key, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, (int) count), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key, (int) count), + (v)->v) + .run(args); + } } @Override - public Long sRem(final String key, final String... members){ + public Long sRem(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisCommand(client, ProtocolCommand.SREM) - .general((cmd)->cmd.srem(key, members)) - .pipeline((cmd)->cmd.srem(key, members)) - .transaction((cmd)->cmd.srem(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } } @Override - public Long sRem(final byte[] key, final byte[]... members){ + public Long sRem(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisCommand(client, ProtocolCommand.SREM) - .general((cmd)->cmd.srem(key, members)) - .pipeline((cmd)->cmd.srem(key, members)) - .transaction((cmd)->cmd.srem(key, members)) - .run(args); - } - @Override - public ScanResult> sScan(final String key, final String cursor){ - final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } } @Override - public ScanResult> sScan(final byte[] key, final byte[] cursor){ + public ScanResult> sScan(final String key, final String cursor) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); - } - - @Override - public ScanResult> sScan(final String key, final String cursor, final String pattern){ + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + listScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return sScan(key, cursor, scanParams, args); } @Override - public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern){ + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return sScan(key, cursor, scanParams, args); } @Override - public ScanResult> sScan(final String key, final String cursor, final long count){ + public ScanResult> sScan(final String key, final String cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return sScan(key, cursor, scanParams, args); } @Override - public ScanResult> sScan(final byte[] key, final byte[] cursor, final long count){ + public ScanResult> sScan(final byte[] key, final byte[] cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return sScan(key, cursor, scanParams, args); } @Override public ScanResult> sScan(final String key, final String cursor, final String pattern, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.STRING_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return sScan(key, cursor, scanParams, args); } @Override public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisCommand>>(client, ProtocolCommand.SSCAN) - .general((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .pipeline((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .transaction((cmd)->cmd.sscan(key, cursor, params), - ScanResultConverter.ListScanResultConverter.BINARY_LIST_CONVERTER) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return sScan(key, cursor, scanParams, args); } @Override - public Set sUnion(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand>(client, ProtocolCommand.SUNION) - .general((cmd)->cmd.sunion(keys)) - .pipeline((cmd)->cmd.sunion(keys)) - .transaction((cmd)->cmd.sunion(keys)) - .run(args); + public Set sUnion(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + } } @Override - public Set sUnion(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand>(client, ProtocolCommand.SUNION) - .general((cmd)->cmd.sunion(keys)) - .pipeline((cmd)->cmd.sunion(keys)) - .transaction((cmd)->cmd.sunion(keys)) - .run(args); + public Set sUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), (v)->v) + .run(args); + } } @Override - public Long sUnionStore(final String destKey, final String... keys){ + public Long sUnionStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.SUNIONSTORE) - .general((cmd)->cmd.sunionstore(destKey, keys)) - .pipeline((cmd)->cmd.sunionstore(destKey, keys)) - .transaction((cmd)->cmd.sunionstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SUNIONSTORE, (cmd)->cmd.sunionstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long sUnionStore(final byte[] destKey, final byte[]... keys){ + public Long sUnionStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.SUNIONSTORE) - .general((cmd)->cmd.sunionstore(destKey, keys)) - .pipeline((cmd)->cmd.sunionstore(destKey, keys)) - .transaction((cmd)->cmd.sunionstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SUNIONSTORE, (cmd)->cmd.sunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + private ScanResult> sScan(final String key, final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListScanResultConverter listScanResultConverter = + new ScanResultConverter.ListScanResultConverter<>(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanParams), listScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor, scanParams), + listScanResultConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSortedSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSortedSetOperations.java index e19a30b80..0121dd5dc 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSortedSetOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisSortedSetOperations.java @@ -19,31 +19,35 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.SetConverter; import com.buession.core.utils.NumberUtils; -import com.buession.redis.client.connection.jedis.JedisConnection; +import com.buession.lang.KeyValue; import com.buession.redis.client.jedis.JedisStandaloneClient; import com.buession.redis.core.Aggregate; import com.buession.redis.core.GtLt; -import com.buession.redis.core.KeyedZSetElement; import com.buession.redis.core.NxXx; import com.buession.redis.core.ScanResult; import com.buession.redis.core.Tuple; import com.buession.redis.core.ZRangeBy; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.jedis.response.KeyedZSetElementConverter; +import com.buession.redis.core.internal.convert.jedis.response.KeyValueConverter; import com.buession.redis.core.internal.convert.jedis.response.ScanResultConverter; import com.buession.redis.core.internal.convert.jedis.response.TupleConverter; import com.buession.redis.core.internal.jedis.JedisScanParams; import com.buession.redis.core.internal.jedis.JedisZAddParams; import com.buession.redis.core.internal.jedis.JedisZParams; import com.buession.redis.core.internal.jedis.JedisZRangeParams; +import redis.clients.jedis.params.ScanParams; +import redis.clients.jedis.params.ZAddParams; import redis.clients.jedis.params.ZParams; +import redis.clients.jedis.params.ZRangeParams; import java.util.List; import java.util.Map; @@ -57,2190 +61,3194 @@ */ public final class JedisSortedSetOperations extends AbstractSortedSetOperations { - public JedisSortedSetOperations(final JedisStandaloneClient client){ + public JedisSortedSetOperations(final JedisStandaloneClient client) { super(client); } @Override - public Tuple zPopMin(final String key){ + public Tuple zPopMin(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.ZPOPMIN) - .general((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .pipeline((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .transaction((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .run(args); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + } } @Override - public Tuple zPopMin(final byte[] key){ + public Tuple zPopMin(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.ZPOPMIN) - .general((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .pipeline((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .transaction((cmd)->cmd.zpopmin(key), TupleConverter.INSTANCE) - .run(args); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), + tupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), tupleConverter) + .run(args); + } } @Override - public List zPopMin(final String key, final long count){ + public List zPopMin(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZPOPMIN) - .general((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + } } @Override - public List zPopMin(final byte[] key, final long count){ + public List zPopMin(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZPOPMIN) - .general((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zpopmin(key, (int) count), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key, (int) count), + listTupleConverter) + .run(args); + } } @Override - public Tuple zPopMax(final String key){ + public Tuple zPopMax(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.ZPOPMAX) - .general((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .pipeline((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .transaction((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .run(args); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + } } @Override - public Tuple zPopMax(final byte[] key){ + public Tuple zPopMax(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.ZPOPMAX) - .general((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .pipeline((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .transaction((cmd)->cmd.zpopmax(key), TupleConverter.INSTANCE) - .run(args); + final TupleConverter tupleConverter = new TupleConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), + tupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key), tupleConverter) + .run(args); + } } @Override - public List zPopMax(final String key, final long count){ + public List zPopMax(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZPOPMAX) - .general((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + } } @Override - public List zPopMax(final byte[] key, final long count){ + public List zPopMax(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZPOPMAX) - .general((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zpopmax(key, (int) count), TupleConverter.LIST_CONVERTER) - .run(args); - } + final ListConverter listTupleConverter = TupleConverter.listConverter(); - @Override - public KeyedZSetElement bzPopMin(final String[] keys, final int timeout){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisCommand(client, ProtocolCommand.BZPOPMIN) - .general((cmd)->cmd.bzpopmin(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .pipeline((cmd)->cmd.bzpopmin(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .transaction((cmd)->cmd.bzpopmin(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmax(key, (int) count), + listTupleConverter) + .run(args); + } } @Override - public KeyedZSetElement bzPopMin(final byte[][] keys, final int timeout){ + public KeyValue bzPopMin(final String[] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisCommand(client, ProtocolCommand.BZPOPMIN) - .general((cmd)->cmd.bzpopmin(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .pipeline((cmd)->cmd.bzpopmin(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .transaction((cmd)->cmd.bzpopmin(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .run(args); - } - - @Override - public KeyedZSetElement bzPopMax(final String[] keys, final int timeout){ + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMin(final byte[][] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisCommand(client, ProtocolCommand.BZPOPMAX) - .general((cmd)->cmd.bzpopmax(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .pipeline((cmd)->cmd.bzpopmax(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .transaction((cmd)->cmd.bzpopmax(timeout, keys), KeyedZSetElementConverter.INSTANCE) - .run(args); - } - - @Override - public KeyedZSetElement bzPopMax(final byte[][] keys, final int timeout){ + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final String[] keys, final int timeout) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); - return new JedisCommand(client, ProtocolCommand.BZPOPMIN) - .general((cmd)->cmd.bzpopmax(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .pipeline((cmd)->cmd.bzpopmax(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .transaction((cmd)->cmd.bzpopmax(timeout, keys), - KeyedZSetElementConverter.BinaryDataKeyedZSetElementConverter.INSTANCE) - .run(args); - } - - @Override - public Long zAdd(final String key, final Map members){ + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter keyValueConverter = + new KeyValueConverter<>((k)->k, new TupleConverter()); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + keyValueConverter) + .run(args); + } + } + + @Override + public Long zAdd(final String key, final Map members) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members)) - .pipeline((cmd)->cmd.zadd(key, members)) - .transaction((cmd)->cmd.zadd(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + } } @Override - public Long zAdd(final byte[] key, final Map members){ + public Long zAdd(final byte[] key, final Map members) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members)) - .pipeline((cmd)->cmd.zadd(key, members)) - .transaction((cmd)->cmd.zadd(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members), (v)->v) + .run(args); + } } @Override - public Long zAdd(final String key, final Map members, final NxXx nxXx){ + public Long zAdd(final String key, final Map members, final NxXx nxXx) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); - final JedisZAddParams params = new JedisZAddParams(nxXx); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final NxXx nxXx){ + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); - final JedisZAddParams params = new JedisZAddParams(nxXx); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final String key, final Map members, final GtLt gtLt){ + public Long zAdd(final String key, final Map members, final GtLt gtLt) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); - final JedisZAddParams params = new JedisZAddParams(gtLt); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(gtLt); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final GtLt gtLt){ + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); - final JedisZAddParams params = new JedisZAddParams(gtLt); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(gtLt); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final String key, final Map members, final boolean ch){ + public Long zAdd(final String key, final Map members, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(ch); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final boolean ch){ + public Long zAdd(final byte[] key, final Map members, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(ch); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt){ + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("gtLt", gtLt); - final JedisZAddParams params = new JedisZAddParams(nxXx, gtLt); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt){ + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("gtLt", gtLt); - final JedisZAddParams params = new JedisZAddParams(nxXx, gtLt); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch){ + public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(nxXx, ch); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch){ + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(nxXx, ch); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch){ + public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) .put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(gtLt, ch); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(gtLt, ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch){ + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) .put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(gtLt, ch); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(gtLt, ch); + + return zAdd(key, members, zAddParams, args); } @Override public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt, - final boolean ch){ + final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("gtLt", gtLt).put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(nxXx, gtLt, ch); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt, ch); + + return zAdd(key, members, zAddParams, args); } @Override public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt, - final boolean ch){ + final boolean ch) { final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) .put("gtLt", gtLt).put("ch", ch); - final JedisZAddParams params = new JedisZAddParams(nxXx, gtLt, ch); - return new JedisCommand(client, ProtocolCommand.ZADD) - .general((cmd)->cmd.zadd(key, members, params)) - .pipeline((cmd)->cmd.zadd(key, members, params)) - .transaction((cmd)->cmd.zadd(key, members, params)) - .run(args); + final ZAddParams zAddParams = new JedisZAddParams(nxXx, gtLt, ch); + + return zAdd(key, members, zAddParams, args); } @Override - public Long zCard(final String key){ + public Long zCard(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.ZCARD) - .general((cmd)->cmd.zcard(key)) - .pipeline((cmd)->cmd.zcard(key)) - .transaction((cmd)->cmd.zcard(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } } @Override - public Long zCard(final byte[] key){ + public Long zCard(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.ZCARD) - .general((cmd)->cmd.zcard(key)) - .pipeline((cmd)->cmd.zcard(key)) - .transaction((cmd)->cmd.zcard(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } } @Override - public Long zCount(final String key, final double min, final double max){ + public Long zCount(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand(client, ProtocolCommand.ZCOUNT) - .general((cmd)->cmd.zcount(key, min, max)) - .pipeline((cmd)->cmd.zcount(key, min, max)) - .transaction((cmd)->cmd.zcount(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } } @Override - public Long zCount(final byte[] key, final double min, final double max){ + public Long zCount(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand(client, ProtocolCommand.ZCOUNT) - .general((cmd)->cmd.zcount(key, min, max)) - .pipeline((cmd)->cmd.zcount(key, min, max)) - .transaction((cmd)->cmd.zcount(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public Long zCount(final String key, final String min, final String max){ + public Long zCount(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand(client, ProtocolCommand.ZCOUNT) - .general((cmd)->cmd.zcount(key, min, max)) - .pipeline((cmd)->cmd.zcount(key, min, max)) - .transaction((cmd)->cmd.zcount(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public Long zCount(final byte[] key, final byte[] min, final byte[] max){ + public Long zCount(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand(client, ProtocolCommand.ZCOUNT) - .general((cmd)->cmd.zcount(key, min, max)) - .pipeline((cmd)->cmd.zcount(key, min, max)) - .transaction((cmd)->cmd.zcount(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, min, max), (v)->v) + .run(args); + } } @Override - public Set zDiff(final String... keys){ + public List zDiff(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand>(client, ProtocolCommand.ZDIFF) - .general((cmd)->cmd.zdiff(keys)) - .pipeline((cmd)->cmd.zdiff(keys)) - .transaction((cmd)->cmd.zdiff(keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + } } @Override - public Set zDiff(final byte[]... keys){ + public List zDiff(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand>(client, ProtocolCommand.ZDIFF) - .general((cmd)->cmd.zdiff(keys)) - .pipeline((cmd)->cmd.zdiff(keys)) - .transaction((cmd)->cmd.zdiff(keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiff(keys), (v)->v) + .run(args); + } } @Override - public Set zDiffWithScores(final String... keys){ + public List zDiffWithScores(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand>(client, ProtocolCommand.ZDIFF) - .general((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .run(args); + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + } } @Override - public Set zDiffWithScores(final byte[]... keys){ + public List zDiffWithScores(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand>(client, ProtocolCommand.ZDIFF) - .general((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zdiffWithScores(keys), TupleConverter.SET_CONVERTER) - .run(args); + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZDIFF, (cmd)->cmd.zdiffWithScores(keys), + listConverter) + .run(args); + } } @Override - public Long zDiffStore(final String destKey, final String... keys){ + public Long zDiffStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.ZDIFFSTORE) - .general((cmd)->cmd.zdiffStore(destKey, keys)).pipeline((cmd)->cmd.zdiffStore(destKey, keys)) - .transaction((cmd)->cmd.zdiffStore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + } } @Override - public Long zDiffStore(final byte[] destKey, final byte[]... keys){ + public Long zDiffStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.ZDIFFSTORE) - .general((cmd)->cmd.zdiffStore(destKey, keys)).pipeline((cmd)->cmd.zdiffStore(destKey, keys)) - .transaction((cmd)->cmd.zdiffStore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZDIFFSTORE, + (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZDIFFSTORE, (cmd)->cmd.zdiffStore(destKey, keys), (v)->v) + .run(args); + } } @Override - public Double zIncrBy(final String key, final double increment, final String member){ + public Double zIncrBy(final String key, final double increment, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) .put("member", member); - return new JedisCommand(client, ProtocolCommand.ZINCRBY) - .general((cmd)->cmd.zincrby(key, increment, member)) - .pipeline((cmd)->cmd.zincrby(key, increment, member)) - .transaction((cmd)->cmd.zincrby(key, increment, member)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZINCRBY, (cmd)->cmd.zincrby(key, increment, member), + (v)->v) + .run(args); + } } @Override - public Double zIncrBy(final byte[] key, final double increment, final byte[] member){ + public Double zIncrBy(final byte[] key, final double increment, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) .put("member", member); - return new JedisCommand(client, ProtocolCommand.ZINCRBY) - .general((cmd)->cmd.zincrby(key, increment, member)) - .pipeline((cmd)->cmd.zincrby(key, increment, member)) - .transaction((cmd)->cmd.zincrby(key, increment, member)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZINCRBY, (cmd)->cmd.zincrby(key, increment, member), + (v)->v) + .run(args); + } } @Override - public Set zInter(final String... keys){ + public List zInter(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final ZParams params = new JedisZParams(); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final byte[]... keys){ + public List zInter(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final ZParams params = new JedisZParams(); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final String[] keys, final Aggregate aggregate){ + public List zInter(final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final ZParams params = new JedisZParams(aggregate); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final byte[][] keys, final Aggregate aggregate){ + public List zInter(final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final ZParams params = new JedisZParams(aggregate); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final String[] keys, final double... weights){ + public List zInter(final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final ZParams params = new JedisZParams(weights); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final byte[][] keys, final double... weights){ + public List zInter(final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final ZParams params = new JedisZParams(weights); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zInter(final String[] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final ZParams params = new JedisZParams(aggregate, weights); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInter(keys, zParams, args); } @Override - public Set zInter(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final ZParams params = new JedisZParams(aggregate, weights); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinter(params, keys)) - .pipeline((cmd)->cmd.zinter(params, keys)) - .transaction((cmd)->cmd.zinter(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInter(keys, zParams, args); } @Override - public Set zInterWithScores(final String... keys){ + public List zInterWithScores(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final ZParams params = new JedisZParams(); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final byte[]... keys){ + public List zInterWithScores(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final ZParams params = new JedisZParams(); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final String[] keys, final Aggregate aggregate){ + public List zInterWithScores(final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final ZParams params = new JedisZParams(aggregate); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final byte[][] keys, final Aggregate aggregate){ + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final ZParams params = new JedisZParams(aggregate); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final String[] keys, final double... weights){ + public List zInterWithScores(final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final ZParams params = new JedisZParams(weights); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final byte[][] keys, final double... weights){ + public List zInterWithScores(final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final ZParams params = new JedisZParams(weights); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final ZParams params = new JedisZParams(aggregate, weights); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterWithScores(keys, zParams, args); } @Override - public Set zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final ZParams params = new JedisZParams(aggregate, weights); - return new JedisCommand>(client, ProtocolCommand.ZINTER) - .general((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zinterWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterWithScores(keys, zParams, args); } @Override - public Long zInterStore(final String destKey, final String... keys){ + public Long zInterStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZINTERSTORE, (cmd)->cmd.zinterstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long zInterStore(final byte[] destKey, final byte[]... keys){ + public Long zInterStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZINTERSTORE, (cmd)->cmd.zinterstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate){ + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterStore(destKey, keys, zParams, args); } @Override - public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate){ + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zInterStore(destKey, keys, zParams, args); } @Override - public Long zInterStore(final String destKey, final String[] keys, final double... weights){ + public Long zInterStore(final String destKey, final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInterStore(destKey, keys, zParams, args); } @Override - public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights){ + public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zInterStore(destKey, keys, zParams, args); } @Override public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate).put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterStore(destKey, keys, zParams, args); } @Override public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate).put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisCommand(client, ProtocolCommand.ZINTERSTORE) - .general((cmd)->cmd.zinterstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zinterstore(destKey, params, keys)) - .transaction((cmd)->cmd.zinterstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zInterStore(destKey, keys, zParams, args); } @Override - public Long zLexCount(final String key, final double min, final double max){ + public Long zLexCount(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand(client, ProtocolCommand.ZLEXCOUNT) - .general((cmd)->cmd.zlexcount(key, Double.toString(min), Double.toString(max))) - .pipeline((cmd)->cmd.zlexcount(key, Double.toString(min), Double.toString(max))) - .transaction((cmd)->cmd.zlexcount(key, Double.toString(min), Double.toString(max))) - .run(args); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zLexCount(key, sMin, sMax, args); } @Override - public Long zLexCount(final byte[] key, final double min, final double max){ + public Long zLexCount(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand(client, ProtocolCommand.ZLEXCOUNT) - .general((cmd)->cmd.zlexcount(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .pipeline((cmd)->cmd.zlexcount(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .transaction((cmd)->cmd.zlexcount(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .run(args); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zLexCount(key, bMin, bMax, args); } + @Deprecated @Override - public Long zLexCount(final String key, final String min, final String max){ + public Long zLexCount(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand(client, ProtocolCommand.ZLEXCOUNT) - .general((cmd)->cmd.zlexcount(key, min, max)) - .pipeline((cmd)->cmd.zlexcount(key, min, max)) - .transaction((cmd)->cmd.zlexcount(key, min, max)) - .run(args); + return zLexCount(key, min, max, args); } + @Deprecated @Override - public Long zLexCount(final byte[] key, final byte[] min, final byte[] max){ + public Long zLexCount(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand(client, ProtocolCommand.ZLEXCOUNT) - .general((cmd)->cmd.zlexcount(key, min, max)) - .pipeline((cmd)->cmd.zlexcount(key, min, max)) - .transaction((cmd)->cmd.zlexcount(key, min, max)) - .run(args); + return zLexCount(key, min, max, args); } @Override - public List zMScore(final String key, final String... members){ + public List zMScore(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisCommand>(client, ProtocolCommand.ZMSCORE) - .general((cmd)->cmd.zmscore(key, members)) - .pipeline((cmd)->cmd.zmscore(key, members)) - .transaction((cmd)->cmd.zmscore(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZMSCORE, (cmd)->cmd.zmscore(key, members), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + } } @Override - public List zMScore(final byte[] key, final byte[]... members){ + public List zMScore(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisCommand>(client, ProtocolCommand.ZMSCORE) - .general((cmd)->cmd.zmscore(key, members)) - .pipeline((cmd)->cmd.zmscore(key, members)) - .transaction((cmd)->cmd.zmscore(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZMSCORE, (cmd)->cmd.zmscore(key, members), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZMSCORE, (cmd)->cmd.zmscore(key, members), (v)->v) + .run(args); + } } @Override - public String zRandMember(final String key){ + public String zRandMember(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmember(key)) - .pipeline((cmd)->cmd.zrandmember(key)) - .transaction((cmd)->cmd.zrandmember(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + } } @Override - public byte[] zRandMember(final byte[] key){ + public byte[] zRandMember(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmember(key)) - .pipeline((cmd)->cmd.zrandmember(key)) - .transaction((cmd)->cmd.zrandmember(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key), (v)->v) + .run(args); + } } @Override - public List zRandMember(final String key, final long count){ + public List zRandMember(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmember(key, count)) - .pipeline((cmd)->cmd.zrandmember(key, count)) - .transaction((cmd)->cmd.zrandmember(key, count)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + } } @Override - public List zRandMember(final byte[] key, final long count){ + public List zRandMember(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmember(key, count)) - .pipeline((cmd)->cmd.zrandmember(key, count)) - .transaction((cmd)->cmd.zrandmember(key, count)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmember(key, count), (v)->v) + .run(args); + } } @Override - public List zRandMemberWithScores(final String key, final long count){ + public List zRandMemberWithScores(final String key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmemberWithScores(key, count), + listTupleConverter) + .run(args); + } } @Override - public List zRandMemberWithScores(final byte[] key, final long count){ + public List zRandMemberWithScores(final byte[] key, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANDMEMBER) - .general((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrandmemberWithScores(key, count), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANDMEMBER, + (cmd)->cmd.zrandmemberWithScores(key, count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANDMEMBER, (cmd)->cmd.zrandmemberWithScores(key, count), + listTupleConverter) + .run(args); + } } @Override - public List zRange(final String key, final long start, final long end){ + public List zRange(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand>(client, ProtocolCommand.ZRANGE) - .general((cmd)->cmd.zrange(key, start, end)) - .pipeline((cmd)->cmd.zrange(key, start, end)) - .transaction((cmd)->cmd.zrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + } } @Override - public List zRange(final byte[] key, final long start, final long end){ + public List zRange(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand>(client, ProtocolCommand.ZRANGE) - .general((cmd)->cmd.zrange(key, start, end)) - .pipeline((cmd)->cmd.zrange(key, start, end)) - .transaction((cmd)->cmd.zrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), (v)->v) + .run(args); + } } @Override - public List zRangeWithScores(final String key, final long start, final long end){ + public List zRangeWithScores(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand>(client, ProtocolCommand.ZRANGE) - .general((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrangeWithScores(key, start, end), + listTupleConverter) + .run(args); + } } @Override - public List zRangeWithScores(final byte[] key, final long start, final long end){ + public List zRangeWithScores(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand>(client, ProtocolCommand.ZRANGE) - .general((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrangeWithScores(key, start, end), + listTupleConverter) + .run(args); + } } @Override - public List zRangeByLex(final String key, final double min, final double max){ + public List zRangeByLex(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max))) - .pipeline((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max))) - .transaction((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max))) - .run(args); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zRangeByLex(key, sMin, sMax, args); } @Override - public List zRangeByLex(final byte[] key, final double min, final double max){ + public List zRangeByLex(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .pipeline((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .transaction((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max))) - .run(args); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, args); } + @Deprecated @Override - public List zRangeByLex(final String key, final String min, final String max){ + public List zRangeByLex(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zrangeByLex(key, min, max)) - .run(args); + return zRangeByLex(key, min, max, args); } + @Deprecated @Override - public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max){ + public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zrangeByLex(key, min, max)) - .run(args); + return zRangeByLex(key, min, max, args); } @Override public List zRangeByLex(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max), (int) offset, - (int) count)) - .pipeline((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max), (int) offset, - (int) count)) - .transaction((cmd)->cmd.zrangeByLex(key, Double.toString(min), Double.toString(max), (int) offset, - (int) count)) - .run(args); + final String sMin = Double.toString(min); + final String sMax = Double.toString(max); + + return zRangeByLex(key, sMin, sMax, offset, count, args); } @Override public List zRangeByLex(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max), - (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max), - (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max), - (int) offset, (int) count)) - .run(args); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, offset, count, args); } + @Deprecated @Override public List zRangeByLex(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .run(args); + return zRangeByLex(key, min, max, offset, count, args); } + @Deprecated @Override public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYLEX) - .general((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count)) - .run(args); + return zRangeByLex(key, min, max, offset, count, args); } @Override - public List zRangeByScore(final String key, final double min, final double max){ + public List zRangeByScore(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override - public List zRangeByScore(final byte[] key, final double min, final double max){ + public List zRangeByScore(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public List zRangeByScore(final String key, final String min, final String max){ + public List zRangeByScore(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public List zRangeByScore(final byte[] key, final byte[] min, final byte[] max){ + public List zRangeByScore(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override public List zRangeByScore(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } @Override public List zRangeByScore(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRangeByScore(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRangeByScore(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); - } - @Override - public List zRangeByScoreWithScores(final String key, final double min, final double max){ - final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } @Override - public List zRangeByScoreWithScores(final byte[] key, final double min, final double max){ + public List zRangeByScoreWithScores(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); - } + final ListConverter listTupleConverter = TupleConverter.listConverter(); - @Override - public List zRangeByScoreWithScores(final String key, final String min, final String max){ - final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } } @Override - public List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max){ + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Deprecated + @Override + public List zRangeByScoreWithScores(final String key, final String min, final String max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Deprecated + @Override + public List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } } @Override public List zRangeByScoreWithScores(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } @Override public List zRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } + @Deprecated @Override public List zRangeByScoreWithScores(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } + @Deprecated @Override public List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZRANGEBYSCORE) - .general((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } @Override - public Long zRangeStore(final String destKey, final String key, final long start, final long end){ + public Long zRangeStore(final String destKey, final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end); - final JedisZRangeParams params = new JedisZRangeParams(start, end); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override - public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end){ + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end); - final JedisZRangeParams params = new JedisZRangeParams(start, end); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, - final ZRangeBy by){ + final ZRangeBy by) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, - final ZRangeBy by){ + final ZRangeBy by) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, - final boolean rev){ + final boolean rev) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("rev", rev); - final JedisZRangeParams params = new JedisZRangeParams(start, end, rev); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, - final boolean rev){ + final boolean rev) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("rev", rev); - final JedisZRangeParams params = new JedisZRangeParams(start, end, rev); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(start, end, offset, count); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(start, end, offset, count); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, - final ZRangeBy by, final boolean rev){ + final ZRangeBy by, final boolean rev) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("rev", rev); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, rev); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, - final ZRangeBy by, final boolean rev){ + final ZRangeBy by, final boolean rev) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("rev", rev); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, rev); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, - final ZRangeBy by, final long offset, final long count){ + final ZRangeBy by, final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, offset, count); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, - final ZRangeBy by, final long offset, final long count){ + final ZRangeBy by, final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, offset, count); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("rev", rev).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(start, end, rev, offset, count); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("rev", rev).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(start, end, rev, offset, count); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, - final boolean rev, final long offset, final long count){ + final boolean rev, final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, rev, offset, count); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, - final boolean rev, final long offset, final long count){ + final boolean rev, final long offset, final long count) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); - final JedisZRangeParams params = new JedisZRangeParams(by, start, end, rev, offset, count); - return new JedisCommand(client, ProtocolCommand.ZRANGESTORE) - .general((cmd)->cmd.zrangestore(destKey, key, params)) - .pipeline((cmd)->cmd.zrangestore(destKey, key, params)) - .transaction((cmd)->cmd.zrangestore(destKey, key, params)) - .run(args); + final ZRangeParams zRangeParams = new JedisZRangeParams(by, start, end, rev, offset, count); + + return zRangeStore(destKey, key, zRangeParams, args); } @Override - public Long zRank(final String key, final String member){ + public Long zRank(final String key, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisCommand(client, ProtocolCommand.ZRANK) - .general((cmd)->cmd.zrank(key, member)) - .pipeline((cmd)->cmd.zrank(key, member)) - .transaction((cmd)->cmd.zrank(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } } @Override - public Long zRank(final byte[] key, final byte[] member){ + public Long zRank(final byte[] key, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisCommand(client, ProtocolCommand.ZRANK) - .general((cmd)->cmd.zrank(key, member)) - .pipeline((cmd)->cmd.zrank(key, member)) - .transaction((cmd)->cmd.zrank(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } } @Override - public Long zRem(final String key, final String... members){ + public Long zRem(final String key, final String... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisCommand(client, ProtocolCommand.ZREM) - .general((cmd)->cmd.zrem(key, members)) - .pipeline((cmd)->cmd.zrem(key, members)) - .transaction((cmd)->cmd.zrem(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } } @Override - public Long zRem(final byte[] key, final byte[]... members){ + public Long zRem(final byte[] key, final byte[]... members) { final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); - return new JedisCommand(client, ProtocolCommand.ZREM) - .general((cmd)->cmd.zrem(key, members)) - .pipeline((cmd)->cmd.zrem(key, members)) - .transaction((cmd)->cmd.zrem(key, members)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } } + @Deprecated @Override - public Long zRemRangeByLex(final String key, final String min, final String max){ + public Long zRemRangeByLex(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand(client, ProtocolCommand.ZREMRANGEBYLEX) - .general((cmd)->cmd.zremrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zremrangeByLex(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, (cmd)->cmd.zremrangeByLex(key, min, max), + (v)->v) + .run(args); + } } + @Deprecated @Override - public Long zRemRangeByLex(final byte[] key, final byte[] min, final byte[] max){ + public Long zRemRangeByLex(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand(client, ProtocolCommand.ZREMRANGEBYLEX) - .general((cmd)->cmd.zremrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zremrangeByLex(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, (cmd)->cmd.zremrangeByLex(key, min, max), + (v)->v) + .run(args); + } } @Override - public Long zRemRangeByScore(final String key, final double min, final double max){ + public Long zRemRangeByScore(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand(client, ProtocolCommand.ZREMRANGEBYSCORE) - .general((cmd)->cmd.zremrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zremrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override - public Long zRemRangeByScore(final byte[] key, final double min, final double max){ + public Long zRemRangeByScore(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand(client, ProtocolCommand.ZREMRANGEBYSCORE) - .general((cmd)->cmd.zremrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zremrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public Long zRemRangeByScore(final String key, final String min, final String max){ + public Long zRemRangeByScore(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand(client, ProtocolCommand.ZREMRANGEBYSCORE) - .general((cmd)->cmd.zremrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zremrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public Long zRemRangeByScore(final byte[] key, final byte[] min, final byte[] max){ + public Long zRemRangeByScore(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand(client, ProtocolCommand.ZREMRANGEBYSCORE) - .general((cmd)->cmd.zremrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zremrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zremrangeByScore(key, min, max)) - .run(args); - } - @Override - public Long zRemRangeByRank(final String key, final long start, final long end){ - final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand(client, ProtocolCommand.ZREMRANGEBYRANK) - .general((cmd)->cmd.zremrangeByRank(key, start, end)) - .pipeline((cmd)->cmd.zremrangeByRank(key, start, end)) - .transaction((cmd)->cmd.zremrangeByRank(key, start, end)) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override - public Long zRemRangeByRank(final byte[] key, final long start, final long end){ + public Long zRemRangeByRank(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand(client, ProtocolCommand.ZREMRANGEBYRANK) - .general((cmd)->cmd.zremrangeByRank(key, start, end)) - .pipeline((cmd)->cmd.zremrangeByRank(key, start, end)) - .transaction((cmd)->cmd.zremrangeByRank(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + } } @Override - public List zRevRange(final String key, final long start, final long end){ + public Long zRemRangeByRank(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGE) - .general((cmd)->cmd.zrevrange(key, start, end)) - .pipeline((cmd)->cmd.zrevrange(key, start, end)) - .transaction((cmd)->cmd.zrevrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangeByRank(key, start, end), (v)->v) + .run(args); + } } @Override - public List zRevRange(final byte[] key, final long start, final long end){ + public List zRevRange(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGE) - .general((cmd)->cmd.zrevrange(key, start, end)) - .pipeline((cmd)->cmd.zrevrange(key, start, end)) - .transaction((cmd)->cmd.zrevrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + } } @Override - public List zRevRangeWithScores(final String key, final long start, final long end){ + public List zRevRange(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGE) - .general((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), (v)->v) + .run(args); + } } @Override - public List zRevRangeWithScores(final byte[] key, final long start, final long end){ + public List zRevRangeWithScores(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGE) - .general((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeWithScores(key, start, end), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } } @Override - public List zRevRangeByLex(final String key, final String min, final String max){ + public List zRevRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listTupleConverter) + .run(args); + } + } + + @Deprecated + @Override + public List zRevRangeByLex(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYLEX) - .general((cmd)->cmd.zrevrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByLex(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, (cmd)->cmd.zrevrangeByLex(key, min, max), + (v)->v) + .run(args); + } } + @Deprecated @Override - public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max){ + public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYLEX) - .general((cmd)->cmd.zrevrangeByLex(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByLex(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByLex(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, (cmd)->cmd.zrevrangeByLex(key, min, max), + (v)->v) + .run(args); + } } + @Deprecated @Override public List zRevRangeByLex(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYLEX) - .general((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYLEX) - .general((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } @Override - public List zRevRangeByScore(final String key, final double min, final double max){ + public List zRevRangeByScore(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override - public List zRevRangeByScore(final byte[] key, final double min, final double max){ + public List zRevRangeByScore(final byte[] key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public List zRevRangeByScore(final String key, final String min, final String max){ + public List zRevRangeByScore(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } } + @Deprecated @Override - public List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max){ + public List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max), (v)->v) + .run(args); + } } @Override public List zRevRangeByScore(final String key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } @Override public List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRevRangeByScore(final String key, final String min, final String max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } + @Deprecated @Override public List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max, final long offset, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .pipeline((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .transaction((cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count)) - .run(args); - } - @Override - public List zRevRangeByScoreWithScores(final String key, final double min, final double max){ - final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScore(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } } @Override - public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max){ + public List zRevRangeByScoreWithScores(final String key, final double min, final double max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); - } + final ListConverter listTupleConverter = TupleConverter.listConverter(); - @Override - public List zRevRangeByScoreWithScores(final String key, final String min, final String max){ - final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } } @Override - public List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max){ + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Deprecated + @Override + public List zRevRangeByScoreWithScores(final String key, final String min, final String max) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } + } + + @Deprecated + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max), listTupleConverter) + .run(args); + } } @Override public List zRevRangeByScoreWithScores(final String key, final double min, final double max, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } @Override public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } + @Deprecated @Override public List zRevRangeByScoreWithScores(final String key, final String min, final String max, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } + @Deprecated @Override public List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max, - final long offset, final long count){ + final long offset, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) .put("offset", offset).put("count", count); - return new JedisCommand>(client, ProtocolCommand.ZREVRANGEBYSCORE) - .general((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), - TupleConverter.LIST_CONVERTER) - .run(args); + final ListConverter listTupleConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangeByScoreWithScores(key, min, max, (int) offset, (int) count), listTupleConverter) + .run(args); + } } @Override - public Long zRevRank(final String key, final String member){ + public Long zRevRank(final String key, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisCommand(client, ProtocolCommand.ZREVRANK) - .general((cmd)->cmd.zrevrank(key, member)) - .pipeline((cmd)->cmd.zrevrank(key, member)) - .transaction((cmd)->cmd.zrevrank(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + } } @Override - public Long zRevRank(final byte[] key, final byte[] member){ + public Long zRevRank(final byte[] key, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisCommand(client, ProtocolCommand.ZREVRANK) - .general((cmd)->cmd.zrevrank(key, member)) - .pipeline((cmd)->cmd.zrevrank(key, member)) - .transaction((cmd)->cmd.zrevrank(key, member)) - .run(args); - } - @Override - public ScanResult> zScan(final String key, final String cursor){ - final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + } } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor){ + public ScanResult> zScan(final String key, final String cursor) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); - return new JedisCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor), ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); - } - - @Override - public ScanResult> zScan(final String key, final String cursor, final String pattern){ + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor), + listTupleScanResultConverter) + .run(args); + } + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return zScan(key, cursor, scanParams, args); } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern){ + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); - final JedisScanParams params = new JedisScanParams(pattern); - return new JedisCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern); + + return zScan(key, cursor, scanParams, args); } @Override - public ScanResult> zScan(final String key, final String cursor, final long count){ + public ScanResult> zScan(final String key, final String cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return zScan(key, cursor, scanParams, args); } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor, final long count){ + public ScanResult> zScan(final byte[] key, final byte[] cursor, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); - final JedisScanParams params = new JedisScanParams(count); - return new JedisCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(count); + + return zScan(key, cursor, scanParams, args); } @Override - public ScanResult> zScan(final String key, final String cursor, final String pattern, final long count){ + public ScanResult> zScan(final String key, final String cursor, final String pattern, + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return zScan(key, cursor, scanParams, args); } @Override - public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, final long count){ + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) .put("count", count); - final JedisScanParams params = new JedisScanParams(pattern, count); - return new JedisCommand>>(client, ProtocolCommand.ZSCAN) - .general((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .pipeline((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .transaction((cmd)->cmd.zscan(key, cursor, params), - ScanResultConverter.ListTupleScanResultConverter.INSTANCE) - .run(args); + final ScanParams scanParams = new JedisScanParams(pattern, count); + + return zScan(key, cursor, scanParams, args); } @Override - public Double zScore(final String key, final String member){ + public Double zScore(final String key, final String member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisCommand(client, ProtocolCommand.ZSCORE) - .general((cmd)->cmd.zscore(key, member)) - .pipeline((cmd)->cmd.zscore(key, member)) - .transaction((cmd)->cmd.zscore(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } } @Override - public Double zScore(final byte[] key, final byte[] member){ + public Double zScore(final byte[] key, final byte[] member) { final CommandArguments args = CommandArguments.create("key", key).put("member", member); - return new JedisCommand(client, ProtocolCommand.ZSCORE) - .general((cmd)->cmd.zscore(key, member)) - .pipeline((cmd)->cmd.zscore(key, member)) - .transaction((cmd)->cmd.zscore(key, member)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } } @Override - public Set zUnion(final String... keys){ + public List zUnion(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final JedisZParams params = new JedisZParams(); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final byte[]... keys){ + public List zUnion(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final JedisZParams params = new JedisZParams(); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final String[] keys, final Aggregate aggregate){ + public List zUnion(final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final byte[][] keys, final Aggregate aggregate){ + public List zUnion(final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final String[] keys, final double... weights){ + public List zUnion(final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final byte[][] keys, final double... weights){ + public List zUnion(final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zUnion(final String[] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnion(keys, zParams, args); } @Override - public Set zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunion(params, keys)) - .pipeline((cmd)->cmd.zunion(params, keys)) - .transaction((cmd)->cmd.zunion(params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnion(keys, zParams, args); } @Override - public Set zUnionWithScores(final String... keys){ + public List zUnionWithScores(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final JedisZParams params = new JedisZParams(); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final byte[]... keys){ + public List zUnionWithScores(final byte[]... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - final JedisZParams params = new JedisZParams(); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final String[] keys, final Aggregate aggregate){ + public List zUnionWithScores(final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final byte[][] keys, final Aggregate aggregate){ + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final String[] keys, final double... weights){ + public List zUnionWithScores(final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final byte[][] keys, final double... weights){ + public List zUnionWithScores(final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights){ + public List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionWithScores(keys, zParams, args); } @Override - public Set zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights){ + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) .put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisCommand>(client, ProtocolCommand.ZUNION) - .general((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .pipeline((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .transaction((cmd)->cmd.zunionWithScores(params, keys), TupleConverter.SET_CONVERTER) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionWithScores(keys, zParams, args); } @Override - public Long zUnionStore(final String destKey, final String... keys){ + public Long zUnionStore(final String destKey, final String... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZUNIONSTORE, (cmd)->cmd.zunionstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long zUnionStore(final byte[] destKey, final byte[]... keys){ + public Long zUnionStore(final byte[] destKey, final byte[]... keys) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, keys)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZUNIONSTORE, (cmd)->cmd.zunionstore(destKey, keys), + (v)->v) + .run(args); + } } @Override - public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate){ + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionStore(destKey, keys, zParams, args); } @Override - public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate){ + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate); - final JedisZParams params = new JedisZParams(aggregate); - return new JedisCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate); + + return zUnionStore(destKey, keys, zParams, args); } @Override - public Long zUnionStore(final String destKey, final String[] keys, final double... weights){ + public Long zUnionStore(final String destKey, final String[] keys, final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnionStore(destKey, keys, zParams, args); } @Override - public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights){ + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("weights", weights); - final JedisZParams params = new JedisZParams(weights); - return new JedisCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(weights); + + return zUnionStore(destKey, keys, zParams, args); } @Override public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate).put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionStore(destKey, keys, zParams, args); } @Override public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, - final double... weights){ + final double... weights) { final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) .put("aggregate", aggregate).put("weights", weights); - final JedisZParams params = new JedisZParams(aggregate, weights); - return new JedisCommand(client, ProtocolCommand.ZUNIONSTORE) - .general((cmd)->cmd.zunionstore(destKey, params, keys)) - .pipeline((cmd)->cmd.zunionstore(destKey, params, keys)) - .transaction((cmd)->cmd.zunionstore(destKey, params, keys)) - .run(args); + final ZParams zParams = new JedisZParams(aggregate, weights); + + return zUnionStore(destKey, keys, zParams, args); + } + + private Long zAdd(final String key, final Map members, final ZAddParams zAddParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + } + } + + private Long zAdd(final byte[] key, final Map members, final ZAddParams zAddParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, members, zAddParams), (v)->v) + .run(args); + } + } + + private List zInter(final String[] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinter(zParams, keys), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + } + } + + private List zInter(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinter(zParams, keys), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinter(zParams, keys), (v)->v) + .run(args); + } + } + + private List zInterWithScores(final String[] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinterWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private List zInterWithScores(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZINTER, + (cmd)->cmd.zinterWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZINTER, (cmd)->cmd.zinterWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private Long zInterStore(final String destKey, final String[] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zInterStore(final byte[] destKey, final byte[][] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zLexCount(final String key, final String min, final String max, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + } + } + + private Long zLexCount(final byte[] key, final byte[] min, final byte[] max, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, min, max), (v)->v) + .run(args); + } + } + + private List zRangeByLex(final String key, final String min, final String max, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYLEX, (cmd)->cmd.zrangeByLex(key, min, max), + (v)->v) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYLEX, (cmd)->cmd.zrangeByLex(key, min, max), + (v)->v) + .run(args); + } + } + + private List zRangeByLex(final String key, final String min, final String max, final long offset, + final long count, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangeByLex(key, min, max, (int) offset, (int) count), (v)->v) + .run(args); + } + } + + private Long zRangeStore(final String destKey, final String key, final ZRangeParams zRangeParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + } + } + + private Long zRangeStore(final byte[] destKey, final byte[] key, final ZRangeParams zRangeParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZRANGESTORE, + (cmd)->cmd.zrangestore(destKey, key, zRangeParams), (v)->v) + .run(args); + } + } + + private ScanResult> zScan(final String key, final String cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final byte[] cursor, final ScanParams scanParams, + final CommandArguments args) { + final ScanResultConverter.ListTupleScanResultConverter listTupleScanResultConverter = + new ScanResultConverter.ListTupleScanResultConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanParams), listTupleScanResultConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanParams), + listTupleScanResultConverter) + .run(args); + } + } + + private List zUnion(final String[] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunion(zParams, keys), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + } + } + + private List zUnion(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunion(zParams, keys), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunion(zParams, keys), (v)->v) + .run(args); + } + } + + private List zUnionWithScores(final String[] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunionWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private List zUnionWithScores(final byte[][] keys, final ZParams zParams, final CommandArguments args) { + final ListConverter listConverter = TupleConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZUNION, + (cmd)->cmd.zunionWithScores(zParams, keys), listConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZUNION, (cmd)->cmd.zunionWithScores(zParams, keys), + listConverter) + .run(args); + } + } + + private Long zUnionStore(final String destKey, final String[] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + } + } + + private Long zUnionStore(final byte[] destKey, final byte[][] keys, final ZParams zParams, + final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zParams, keys), (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisStreamOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisStreamOperations.java index 187180c51..2bf904f18 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisStreamOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisStreamOperations.java @@ -19,11 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapEntryMapConverter; import com.buession.lang.Status; import com.buession.redis.client.jedis.JedisStandaloneClient; import com.buession.redis.core.Stream; @@ -36,28 +38,34 @@ import com.buession.redis.core.StreamPendingSummary; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; import com.buession.redis.core.internal.convert.jedis.params.StreamEntryIdConverter; -import com.buession.redis.core.internal.convert.jedis.params.XClaimArgumentConverter; -import com.buession.redis.core.internal.convert.jedis.params.XTrimArgumentConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamConsumersInfoConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamEntryConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamEntryIDConverter; -import com.buession.redis.core.internal.convert.jedis.params.XAddArgumentConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamFullInfoConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamGroupInfoConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamInfoConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamPendingEntryConverter; import com.buession.redis.core.internal.convert.jedis.response.StreamPendingSummaryConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import com.buession.redis.core.internal.jedis.JedisStreamEntryID; +import com.buession.redis.core.internal.jedis.JedisXAddParams; import com.buession.redis.core.internal.jedis.JedisXAutoClaimParams; +import com.buession.redis.core.internal.jedis.JedisXClaimParams; import com.buession.redis.core.internal.jedis.JedisXPendingParams; import com.buession.redis.core.internal.jedis.JedisXReadGroupParams; import com.buession.redis.core.internal.jedis.JedisXReadParams; +import com.buession.redis.core.internal.jedis.JedisXTrimParams; import redis.clients.jedis.StreamEntryID; import redis.clients.jedis.params.XAddParams; +import redis.clients.jedis.params.XAutoClaimParams; import redis.clients.jedis.params.XClaimParams; +import redis.clients.jedis.params.XPendingParams; +import redis.clients.jedis.params.XReadGroupParams; +import redis.clients.jedis.params.XReadParams; import redis.clients.jedis.params.XTrimParams; +import redis.clients.jedis.resps.StreamConsumersInfo; +import redis.clients.jedis.resps.StreamGroupInfo; +import redis.clients.jedis.resps.StreamPendingEntry; import java.util.List; import java.util.Map; @@ -70,814 +78,1046 @@ */ public final class JedisStreamOperations extends AbstractStreamOperations { - public JedisStreamOperations(final JedisStandaloneClient client){ + public JedisStreamOperations(final JedisStandaloneClient client) { super(client); } @Override - public Long xAck(final String key, final String groupName, final StreamEntryId... ids){ + public Long xAck(final String key, final String groupName, final StreamEntryId... ids) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("ids", (Object[]) ids); - final StreamEntryID[] streamEntryIDS = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisCommand(client, ProtocolCommand.XACK) - .general((cmd)->cmd.xack(key, groupName, streamEntryIDS)) - .pipeline((cmd)->cmd.xack(key, groupName, streamEntryIDS)) - .transaction((cmd)->cmd.xack(key, groupName, streamEntryIDS)) - .run(args); + final StreamEntryID[] streamEntryIDS = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XACK, + (cmd)->cmd.xack(key, groupName, streamEntryIDS), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XACK, (cmd)->cmd.xack(key, groupName, streamEntryIDS), + (v)->v) + .run(args); + } } @Override - public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash){ + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash) { final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(id); - return new JedisCommand(client, ProtocolCommand.XADD) - .general((cmd)->cmd.xadd(key, streamEntryID, hash), StreamEntryIDConverter.INSTANCE) - .pipeline((cmd)->cmd.xadd(key, streamEntryID, hash), StreamEntryIDConverter.INSTANCE) - .transaction((cmd)->cmd.xadd(key, streamEntryID, hash), StreamEntryIDConverter.INSTANCE) - .run(args); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, streamEntryID, hash), + streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XADD, + (cmd)->cmd.xadd(key, streamEntryID, hash), streamEntryIDConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, streamEntryID, hash), + streamEntryIDConverter) + .run(args); + } } @Override public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash, - final XAddArgument xAddArgument){ + final XAddArgument xAddArgument) { final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) .put("xAddArgument", xAddArgument); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(id); - final XAddParams params = XAddArgumentConverter.INSTANCE.convert(xAddArgument).id(streamEntryID); - return new JedisCommand(client, ProtocolCommand.XADD) - .general((cmd)->cmd.xadd(key, hash, params), StreamEntryIDConverter.INSTANCE) - .pipeline((cmd)->cmd.xadd(key, hash, params), StreamEntryIDConverter.INSTANCE) - .transaction((cmd)->cmd.xadd(key, hash, params), StreamEntryIDConverter.INSTANCE) - .run(args); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + final XAddParams xAddParams = JedisXAddParams.from(xAddArgument).id(streamEntryID); + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + streamEntryIDConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + streamEntryIDConverter) + .run(args); + } } @Override public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash, - final XAddArgument xAddArgument){ + final XAddArgument xAddArgument) { final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) .put("xAddArgument", xAddArgument); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(id); - final XAddParams params = XAddArgumentConverter.INSTANCE.convert(xAddArgument).id(streamEntryID); - return new JedisCommand(client, ProtocolCommand.XADD) - .general((cmd)->cmd.xadd(key, hash, params), - StreamEntryIDConverter.BinaryStreamEntryIdConverter.INSTANCE) - .pipeline((cmd)->cmd.xadd(key, hash, params), - StreamEntryIDConverter.BinaryStreamEntryIdConverter.INSTANCE) - .transaction((cmd)->cmd.xadd(key, hash, params), - StreamEntryIDConverter.BinaryStreamEntryIdConverter.INSTANCE) - .run(args); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + final XAddParams xAddParams = JedisXAddParams.from(xAddArgument).id(streamEntryID); + final StreamEntryIDConverter.BinaryStreamEntryIdConverter binaryStreamEntryIdConverter = + new StreamEntryIDConverter.BinaryStreamEntryIdConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + binaryStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + binaryStreamEntryIdConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, hash, xAddParams), + binaryStreamEntryIdConverter) + .run(args); + } } @Override public Map> xAutoClaim(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start){ + final StreamEntryId start) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final JedisXAutoClaimParams params = new JedisXAutoClaimParams(); - return new JedisCommand>>(client, ProtocolCommand.XAUTOCLAIM) - .general((cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .transaction( - (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .run(args); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); } @Override public Map> xAutoClaim(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start, final long count){ + final StreamEntryId start, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) .put("count", count); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final JedisXAutoClaimParams params = new JedisXAutoClaimParams(count); - return new JedisCommand>>(client, ProtocolCommand.XAUTOCLAIM) - .general((cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .transaction( - (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryConverter.MapStreamEntryConverter.STREAMENTRYID_KEY_MAP_CONVERTER) - .run(args); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(count); + + return xAutoClaim(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); } @Override public Map> xAutoClaimJustId(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start){ + final StreamEntryId start) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) .put("count"); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final JedisXAutoClaimParams params = new JedisXAutoClaimParams(); - return new JedisCommand>>(client, ProtocolCommand.XAUTOCLAIM) - .general((cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .pipeline((cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .transaction( - (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .run(args); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); } @Override public Map> xAutoClaimJustId(final String key, final String groupName, final String consumerName, final int minIdleTime, - final StreamEntryId start, final long count){ + final StreamEntryId start, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) .put("count", count); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final JedisXAutoClaimParams params = new JedisXAutoClaimParams(count); - return new JedisCommand>>(client, ProtocolCommand.XAUTOCLAIM) - .general((cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .pipeline((cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .transaction( - (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, streamEntryID, params), - StreamEntryIDConverter.MapStreamEntryIdConverter.INSTANCE) - .run(args); + final XAutoClaimParams xAutoClaimParams = new JedisXAutoClaimParams(); + + return xAutoClaimJustId(key, groupName, consumerName, minIdleTime, start, xAutoClaimParams, args); } @Override public List xClaim(final String key, final String groupName, final String consumerName, - final int minIdleTime, final StreamEntryId... ids){ + final int minIdleTime, final StreamEntryId... ids) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); - final XClaimParams params = new XClaimParams(); - final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisCommand>(client, ProtocolCommand.XCLAIM) - .general((cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .transaction( - (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .run(args); + final XClaimParams xClaimParams = new JedisXClaimParams(); + + return xClaim(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); } @Override public List xClaim(final String key, final String groupName, final String consumerName, final int minIdleTime, final StreamEntryId[] ids, - final XClaimArgument xClaimArgument){ + final XClaimArgument xClaimArgument) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) .put("xClaimArgument", xClaimArgument); - final XClaimParams params = XClaimArgumentConverter.INSTANCE.convert(xClaimArgument); - final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisCommand>(client, ProtocolCommand.XCLAIM) - .general((cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .transaction( - (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryConverter.LIST_CONVERTER) - .run(args); + final XClaimParams xClaimParams = JedisXClaimParams.from(xClaimArgument); + + return xClaim(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); } @Override public List xClaimJustId(final String key, final String groupName, final String consumerName, - final int minIdleTime, final StreamEntryId... ids){ + final int minIdleTime, final StreamEntryId... ids) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); - final XClaimParams params = new XClaimParams(); - final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisCommand>(client, ProtocolCommand.XCLAIM) - .general((cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .transaction( - (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .run(args); + final XClaimParams xClaimParams = new JedisXClaimParams(); + + return xClaimJustId(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); } @Override public List xClaimJustId(final String key, final String groupName, final String consumerName, final int minIdleTime, final StreamEntryId[] ids, - final XClaimArgument xClaimArgument){ + final XClaimArgument xClaimArgument) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) .put("xClaimArgument", xClaimArgument); - final XClaimParams params = XClaimArgumentConverter.INSTANCE.convert(xClaimArgument); - final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisCommand>(client, ProtocolCommand.XCLAIM) - .general((cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .transaction( - (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, params, streamEntryIDs), - StreamEntryIDConverter.LIST_CONVERTER) - .run(args); + final XClaimParams xClaimParams = JedisXClaimParams.from(xClaimArgument); + + return xClaimJustId(key, groupName, consumerName, minIdleTime, ids, xClaimParams, args); } @Override - public Long xDel(final String key, final StreamEntryId... ids){ + public Long xDel(final String key, final StreamEntryId... ids) { final CommandArguments args = CommandArguments.create("key", key).put("ids", (Object[]) ids); - final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.ARRAY_CONVERTER.convert(ids); - return new JedisCommand(client, ProtocolCommand.XDEL) - .general((cmd)->cmd.xdel(key, streamEntryIDs)) - .pipeline((cmd)->cmd.xdel(key, streamEntryIDs)) - .transaction((cmd)->cmd.xdel(key, streamEntryIDs)) - .run(args); + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XDEL, (cmd)->cmd.xdel(key, streamEntryIDs), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XDEL, (cmd)->cmd.xdel(key, streamEntryIDs), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XDEL, (cmd)->cmd.xdel(key, streamEntryIDs), (v)->v) + .run(args); + } } @Override public Status xGroupCreate(final String key, final String groupName, final StreamEntryId id, - final boolean makeStream){ + final boolean makeStream) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("id", id); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(id); - return new JedisCommand(client, ProtocolCommand.XGROUP_CREATE) - .general((cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), - OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), - OkStatusConverter.INSTANCE) - .run(args); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(key, groupName, streamEntryID, makeStream), okStatusConverter) + .run(args); + } } @Override - public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName){ + public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - return new JedisCommand(client, ProtocolCommand.XGROUP_CREATECONSUMER) - .general((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + } } @Override - public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName){ + public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - return new JedisCommand(client, ProtocolCommand.XGROUP_CREATECONSUMER) - .general((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .pipeline((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .transaction((cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), - Converters.BOOLEAN_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XGROUP_CREATECONSUMER, + (cmd)->cmd.xgroupCreateConsumer(key, groupName, consumerName), booleanStatusConverter) + .run(args); + } } @Override - public Long xGroupDelConsumer(final String key, final String groupName, final String consumerName){ + public Long xGroupDelConsumer(final String key, final String groupName, final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - return new JedisCommand(client, ProtocolCommand.XGROUP_DELCONSUMER) - .general((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .pipeline((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .transaction((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, + groupName, consumerName), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, + groupName, consumerName), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, (cmd)->cmd.xgroupDelConsumer(key, + groupName, consumerName), (v)->v) + .run(args); + } } @Override - public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName){ + public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - return new JedisCommand(client, ProtocolCommand.XGROUP_DELCONSUMER) - .general((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .pipeline((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .transaction((cmd)->cmd.xgroupDelConsumer(key, groupName, consumerName)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, + groupName, consumerName), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelConsumer(key, + groupName, consumerName), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, (cmd)->cmd.xgroupDelConsumer(key, + groupName, consumerName), (v)->v) + .run(args); + } } @Override - public Status xGroupDestroy(final String key, final String groupName){ + public Status xGroupDestroy(final String key, final String groupName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); - return new JedisCommand(client, ProtocolCommand.XGROUP_DESTROY) - .general((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XGROUP_DESTROY, (cmd)->cmd.xgroupDestroy(key, groupName), + oneStatusConverter) + .run(args); + } } @Override - public Status xGroupDestroy(final byte[] key, final byte[] groupName){ + public Status xGroupDestroy(final byte[] key, final byte[] groupName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); - return new JedisCommand(client, ProtocolCommand.XGROUP_DESTROY) - .general((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.xgroupDestroy(key, groupName), Converters.ONE_STATUS_CONVERTER) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XGROUP_DESTROY, (cmd)->cmd.xgroupDestroy(key, groupName), + oneStatusConverter) + .run(args); + } } @Override - public Status xGroupSetId(final String key, final String groupName, final StreamEntryId id){ + public Status xGroupSetId(final String key, final String groupName, final StreamEntryId id) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName).put("id", id); - final StreamEntryID streamEntryID = StreamEntryIdConverter.INSTANCE.convert(id); - return new JedisCommand(client, ProtocolCommand.XGROUP_SETID) - .general((cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), OkStatusConverter.INSTANCE) - .run(args); + final StreamEntryID streamEntryID = JedisStreamEntryID.from(id); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XGROUP_SETID, + (cmd)->cmd.xgroupSetID(key, groupName, streamEntryID), okStatusConverter) + .run(args); + } } @Override - public List xInfoConsumers(final String key, final String groupName){ + public List xInfoConsumers(final String key, final String groupName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); - return new JedisCommand>(client, - ProtocolCommand.XINFO_CONSUMERS) - .general((cmd)->cmd.xinfoConsumers(key, groupName), StreamConsumersInfoConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xinfoConsumers(key, groupName), StreamConsumersInfoConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xinfoConsumers(key, groupName), StreamConsumersInfoConverter.LIST_CONVERTER) - .run(args); + final ListConverter listStreamConsumersInfoConverter = + StreamConsumersInfoConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + } } @Override - public List xInfoGroups(final String key){ + public List xInfoGroups(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand>(client, ProtocolCommand.XINFO_GROUPS) - .general((cmd)->cmd.xinfoGroups(key), StreamGroupInfoConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xinfoGroups(key), StreamGroupInfoConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xinfoGroups(key), StreamGroupInfoConverter.LIST_CONVERTER) - .run(args); + final ListConverter listStreamGroupInfoConverter = + StreamGroupInfoConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + } } @Override - public Stream xInfoStream(final String key){ + public Stream xInfoStream(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.XINFO_STREAM) - .general((cmd)->cmd.xinfoStream(key), StreamInfoConverter.INSTANCE) - .pipeline((cmd)->cmd.xinfoStream(key), StreamInfoConverter.INSTANCE) - .transaction((cmd)->cmd.xinfoStream(key), StreamInfoConverter.INSTANCE) - .run(args); + final StreamInfoConverter streamInfoConverter = new StreamInfoConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamInfoConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamInfoConverter) + .run(args); + } } @Override - public StreamFull xInfoStream(final String key, final boolean full){ + public StreamFull xInfoStream(final String key, final boolean full) { final CommandArguments args = CommandArguments.create("key", key).put("full", full); - return new JedisCommand(client, ProtocolCommand.XINFO_STREAM) - .general((cmd)->cmd.xinfoStreamFull(key), StreamFullInfoConverter.INSTANCE) - .pipeline((cmd)->cmd.xinfoStreamFull(key), StreamFullInfoConverter.INSTANCE) - .transaction((cmd)->cmd.xinfoStreamFull(key), StreamFullInfoConverter.INSTANCE) - .run(args); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStreamFull(key), + streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStreamFull(key), + streamFullInfoConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStreamFull(key), + streamFullInfoConverter) + .run(args); + } } @Override - public StreamFull xInfoStream(final String key, final boolean full, final long count){ + public StreamFull xInfoStream(final String key, final boolean full, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("full", full).put("count", count); - return new JedisCommand(client, ProtocolCommand.XINFO_STREAM) - .general((cmd)->cmd.xinfoStreamFull(key, (int) count), StreamFullInfoConverter.INSTANCE) - .pipeline((cmd)->cmd.xinfoStreamFull(key, (int) count), StreamFullInfoConverter.INSTANCE) - .transaction((cmd)->cmd.xinfoStreamFull(key, (int) count), StreamFullInfoConverter.INSTANCE) - .run(args); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStreamFull(key, (int) count), streamFullInfoConverter) + .run(args); + } } @Override - public Long xLen(final String key){ + public Long xLen(final String key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.XLEN) - .general((cmd)->cmd.xlen(key)) - .pipeline((cmd)->cmd.xlen(key)) - .transaction((cmd)->cmd.xlen(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } } @Override - public Long xLen(final byte[] key){ + public Long xLen(final byte[] key) { final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.XLEN) - .general((cmd)->cmd.xlen(key)) - .pipeline((cmd)->cmd.xlen(key)) - .transaction((cmd)->cmd.xlen(key)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } } @Override - public StreamPendingSummary xPending(final String key, final String groupName){ + public StreamPendingSummary xPending(final String key, final String groupName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); - return new JedisCommand(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName), StreamPendingSummaryConverter.INSTANCE) - .pipeline((cmd)->cmd.xpending(key, groupName), StreamPendingSummaryConverter.INSTANCE) - .transaction((cmd)->cmd.xpending(key, groupName), StreamPendingSummaryConverter.INSTANCE) - .run(args); + final StreamPendingSummaryConverter streamPendingSummaryConverter = new StreamPendingSummaryConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XPENDING, (cmd)->cmd.xpending(key, groupName), + streamPendingSummaryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XPENDING, (cmd)->cmd.xpending(key, groupName), + streamPendingSummaryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XPENDING, (cmd)->cmd.xpending(key, groupName), + streamPendingSummaryConverter) + .run(args); + } } @Override - public List xPending(final String key, final String groupName, final long minIdleTime){ + public List xPending(final String key, final String groupName, final long minIdleTime) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("minIdleTime", minIdleTime); - final JedisXPendingParams params = new JedisXPendingParams(minIdleTime); - return new JedisCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime); + + return xPending(key, groupName, xPendingParams, args); } @Override public List xPending(final String key, final String groupName, final StreamEntryId start, - final StreamEntryId end, final long count){ + final StreamEntryId end, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("start", start).put("end", end).put("count", count); - final JedisXPendingParams params = new JedisXPendingParams(start, end, count); - return new JedisCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count); + + return xPending(key, groupName, xPendingParams, args); } @Override - public List xPending(final String key, final String groupName, final String consumerName){ + public List xPending(final String key, final String groupName, final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - final JedisXPendingParams params = new JedisXPendingParams(consumerName); - return new JedisCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(consumerName); + + return xPending(key, groupName, xPendingParams, args); } @Override public List xPending(final String key, final String groupName, final long minIdleTime, - final StreamEntryId start, final StreamEntryId end, final long count){ + final StreamEntryId start, final StreamEntryId end, final long count) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("minIdleTime", minIdleTime).put("start", start).put("end", end).put("count", count); - final JedisXPendingParams params = new JedisXPendingParams(minIdleTime, start, end, count); - return new JedisCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime, start, end, count); + + return xPending(key, groupName, xPendingParams, args); } @Override public List xPending(final String key, final String groupName, final long minIdleTime, - final String consumerName){ + final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("minIdleTime", minIdleTime).put("consumerName", consumerName); - final JedisXPendingParams params = new JedisXPendingParams(minIdleTime, consumerName); - return new JedisCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime, consumerName); + + return xPending(key, groupName, xPendingParams, args); } @Override public List xPending(final String key, final String groupName, final StreamEntryId start, - final StreamEntryId end, final long count, final String consumerName){ + final StreamEntryId end, final long count, final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("consumerName", consumerName); - final JedisXPendingParams params = new JedisXPendingParams(start, end, count, consumerName); - return new JedisCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(start, end, count, consumerName); + + return xPending(key, groupName, xPendingParams, args); } @Override public List xPending(final String key, final String groupName, final long minIdleTime, final StreamEntryId start, final StreamEntryId end, final long count, - final String consumerName){ + final String consumerName) { final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) .put("minIdleTime", minIdleTime).put("consumerName", consumerName); - final JedisXPendingParams params = new JedisXPendingParams(minIdleTime, start, end, count, consumerName); - return new JedisCommand>(client, ProtocolCommand.XPENDING) - .general((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xpending(key, groupName, params), StreamPendingEntryConverter.LIST_CONVERTER) - .run(args); + final XPendingParams xPendingParams = new JedisXPendingParams(minIdleTime, start, end, count, + consumerName); + + return xPending(key, groupName, xPendingParams, args); } @Override - public List xRange(final String key, final StreamEntryId start, final StreamEntryId end){ + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - final StreamEntryID startStreamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final StreamEntryID endStreamEntryID = StreamEntryIdConverter.INSTANCE.convert(end); - return new JedisCommand>(client, ProtocolCommand.XRANGE) - .general((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), - StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), - StreamEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), - StreamEntryConverter.LIST_CONVERTER) - .run(args); + final StreamEntryID startStreamEntryID = JedisStreamEntryID.from(start); + final StreamEntryID endStreamEntryID = JedisStreamEntryID.from(end); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), listStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID), listStreamEntryConverter) + .run(args); + } } @Override public List xRange(final String key, final StreamEntryId start, final StreamEntryId end, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - final StreamEntryID startStreamEntryID = StreamEntryIdConverter.INSTANCE.convert(start); - final StreamEntryID endStreamEntryID = StreamEntryIdConverter.INSTANCE.convert(end); - return new JedisCommand>(client, ProtocolCommand.XRANGE) - .general((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), - StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), - StreamEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), - StreamEntryConverter.LIST_CONVERTER) - .run(args); + final StreamEntryID startStreamEntryID = JedisStreamEntryID.from(start); + final StreamEntryID endStreamEntryID = JedisStreamEntryID.from(end); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), listStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, startStreamEntryID, endStreamEntryID, (int) count), listStreamEntryConverter) + .run(args); + } } @Override - public List>> xRead(final Map streams){ + public List>> xRead(final Map streams) { final CommandArguments args = CommandArguments.create("streams", streams); - final JedisXReadParams params = new JedisXReadParams(); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisCommand>>>(client, ProtocolCommand.XREAD) - .general((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadParams xReadParams = new JedisXReadParams(); + + return xRead(streams, xReadParams, args); } @Override - public List>> xRead(final long count, final Map streams){ + public List>> xRead(final long count, final Map streams) { final CommandArguments args = CommandArguments.create("count", count).put("streams", streams); - final JedisXReadParams params = new JedisXReadParams(count); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisCommand>>>(client, ProtocolCommand.XREAD) - .general((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadParams xReadParams = new JedisXReadParams(count); + + return xRead(streams, xReadParams, args); } @Override - public List>> xRead(final int block, final Map streams){ + public List>> xRead(final int block, final Map streams) { final CommandArguments args = CommandArguments.create("block", block).put("streams", streams); - final JedisXReadParams params = new JedisXReadParams(block); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisCommand>>>(client, ProtocolCommand.XREAD) - .general((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadParams xReadParams = new JedisXReadParams(block); + + return xRead(streams, xReadParams, args); } @Override public List>> xRead(final long count, final int block, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("count", count).put("block", block) .put("streams", streams); - final JedisXReadParams params = new JedisXReadParams(count, block); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisCommand>>>(client, ProtocolCommand.XREAD) - .general((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xread(params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadParams xReadParams = new JedisXReadParams(count, block); + + return xRead(streams, xReadParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, - final long count, final Map streams){ + final long count, final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("count", count).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(count); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(count); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, - final int block, final Map streams){ + final int block, final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("block", block).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(block); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(block); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final boolean isNoAck, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("isNoAck", isNoAck).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(isNoAck); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final long count, final int block, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("count", count).put("block", block).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(count, block); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(count, block); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final long count, final boolean isNoAck, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("count", count).put("isNoAck", isNoAck).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(count, isNoAck); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(count, isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final int block, final boolean isNoAck, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("block", block).put("isNoAck", isNoAck).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(block, isNoAck); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(block, isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override public List>> xReadGroup(final String groupName, final String consumerName, final long count, final int block, final boolean isNoAck, - final Map streams){ + final Map streams) { final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) .put("count", count).put("block", block).put("isNoAck", isNoAck).put("streams", streams); - final JedisXReadGroupParams params = new JedisXReadGroupParams(count, block, isNoAck); - final Map stringStreamEntryIDMap = StreamEntryIdConverter.MapStreamEntryIdConverter.STRING_MAP_CONVERTER.convert( - streams); - return new JedisCommand>>>(client, ProtocolCommand.XREADGROUP) - .general((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .pipeline((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .transaction((cmd)->cmd.xreadGroup(groupName, consumerName, params, stringStreamEntryIDMap), - StreamEntryConverter.ListMapStreamEntryConverter.STRING_KEY_MAP_CONVERTER) - .run(args); + final XReadGroupParams xReadGroupParams = new JedisXReadGroupParams(count, block, isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadGroupParams, args); } @Override - public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start){ + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start) { final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start); - final StreamEntryID endID = StreamEntryIdConverter.INSTANCE.convert(end); - final StreamEntryID startID = StreamEntryIdConverter.INSTANCE.convert(start); - return new JedisCommand>(client, ProtocolCommand.XREVRANGE) - .general((cmd)->cmd.xrevrange(key, endID, startID), StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xrevrange(key, endID, startID), StreamEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xrevrange(key, endID, startID), StreamEntryConverter.LIST_CONVERTER) - .run(args); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), + listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID), + listStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XREVRANGE, (cmd)->cmd.xrevrange(key, endID, startID), + listStreamEntryConverter) + .run(args); + } } @Override public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start, - final long count){ + final long count) { final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start) .put("count", count); - final StreamEntryID endID = StreamEntryIdConverter.INSTANCE.convert(end); - final StreamEntryID startID = StreamEntryIdConverter.INSTANCE.convert(start); - return new JedisCommand>(client, ProtocolCommand.XREVRANGE) - .general((cmd)->cmd.xrevrange(key, endID, startID, (int) count), StreamEntryConverter.LIST_CONVERTER) - .pipeline((cmd)->cmd.xrevrange(key, endID, startID, (int) count), StreamEntryConverter.LIST_CONVERTER) - .transaction((cmd)->cmd.xrevrange(key, endID, startID, (int) count), - StreamEntryConverter.LIST_CONVERTER) - .run(args); + final StreamEntryID endID = JedisStreamEntryID.from(end); + final StreamEntryID startID = JedisStreamEntryID.from(start); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, endID, startID, (int) count), listStreamEntryConverter) + .run(args); + } } @Override - public Long xTrim(final String key, final XTrimArgument xTrimArgument){ + public Long xTrim(final String key, final XTrimArgument xTrimArgument) { final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); - final XTrimParams params = XTrimArgumentConverter.INSTANCE.convert(xTrimArgument); - return new JedisCommand(client, ProtocolCommand.XTRIM) - .general((cmd)->cmd.xtrim(key, params)) - .pipeline((cmd)->cmd.xtrim(key, params)) - .transaction((cmd)->cmd.xtrim(key, params)) - .run(args); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument); + + return xTrim(key, xTrimParams, args); } @Override - public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument){ + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument) { final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); - final XTrimParams params = XTrimArgumentConverter.INSTANCE.convert(xTrimArgument); - return new JedisCommand(client, ProtocolCommand.XTRIM) - .general((cmd)->cmd.xtrim(key, params)) - .pipeline((cmd)->cmd.xtrim(key, params)) - .transaction((cmd)->cmd.xtrim(key, params)) - .run(args); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument); + + return xTrim(key, xTrimParams, args); } @Override - public Long xTrim(final String key, final XTrimArgument xTrimArgument, final long limit){ + public Long xTrim(final String key, final XTrimArgument xTrimArgument, final long limit) { final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) .put("limit", limit); - final XTrimParams params = XTrimArgumentConverter.INSTANCE.convert(xTrimArgument).limit(limit); - return new JedisCommand(client, ProtocolCommand.XTRIM) - .general((cmd)->cmd.xtrim(key, params)) - .pipeline((cmd)->cmd.xtrim(key, params)) - .transaction((cmd)->cmd.xtrim(key, params)) - .run(args); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument).limit(limit); + + return xTrim(key, xTrimParams, args); } @Override - public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit){ + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit) { final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) .put("limit", limit); - final XTrimParams params = XTrimArgumentConverter.INSTANCE.convert(xTrimArgument).limit(limit); - return new JedisCommand(client, ProtocolCommand.XTRIM) - .general((cmd)->cmd.xtrim(key, params)) - .pipeline((cmd)->cmd.xtrim(key, params)) - .transaction((cmd)->cmd.xtrim(key, params)) - .run(args); + final XTrimParams xTrimParams = JedisXTrimParams.from(xTrimArgument).limit(limit); + + return xTrim(key, xTrimParams, args); + } + + private Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, + final XAutoClaimParams xAutoClaimParams, + final CommandArguments args) { + final StreamEntryID startStreamEntryID = JedisStreamEntryID.from(start); + final StreamEntryConverter.MapEntryStreamEntryConverter mapEntryStreamEntryConverter = + new StreamEntryConverter.MapEntryStreamEntryConverter<>(new StreamEntryIDConverter()); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaim(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryConverter) + .run(args); + } + } + + private Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, + final XAutoClaimParams xAutoClaimParams, + final CommandArguments args) { + final StreamEntryID startStreamEntryID = JedisStreamEntryID.from(start); + final MapEntryMapConverter, StreamEntryId, List> mapEntryStreamEntryIdConverter = StreamEntryIDConverter.mapEntryMapConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryIdConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XAUTOCLAIM, + (cmd)->cmd.xautoclaimJustId(key, groupName, consumerName, minIdleTime, startStreamEntryID, + xAutoClaimParams), mapEntryStreamEntryIdConverter) + .run(args); + } + } + + private List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, final XClaimParams xClaimParams, + final CommandArguments args) { + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryConverter) + .run(args); + } + } + + private List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimParams xClaimParams, final CommandArguments args) { + final StreamEntryID[] streamEntryIDs = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter listStreamEntryIDConverter = StreamEntryIDConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaimJustId(key, groupName, consumerName, minIdleTime, xClaimParams, streamEntryIDs), + listStreamEntryIDConverter) + .run(args); + } + } + + private List xPending(final String key, final String groupName, + final XPendingParams xPendingParams, final CommandArguments args) { + final ListConverter listStreamPendingEntryConverter = + StreamPendingEntryConverter.listConverter(); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName, xPendingParams), listStreamPendingEntryConverter) + .run(args); + } + } + + private List>> xRead(final Map streams, + final XReadParams xReadParams, final CommandArguments args) { + final Map stringStreamEntryIDMap = StreamEntryIdConverter.mapConverter().convert( + streams); + final StreamEntryConverter.ListMapEntryStreamEntryConverter listMapEntryStreamEntryConverter = + new StreamEntryConverter.ListMapEntryStreamEntryConverter<>((k)->k); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XREAD, + (cmd)->cmd.xread(xReadParams, stringStreamEntryIDMap), listMapEntryStreamEntryConverter) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadGroupParams xReadGroupParams, + final CommandArguments args) { + final Map stringStreamEntryIDMap = StreamEntryIdConverter.mapConverter().convert( + streams); + final StreamEntryConverter.ListMapEntryStreamEntryConverter listMapEntryStreamEntryConverter = + new StreamEntryConverter.ListMapEntryStreamEntryConverter<>((k)->k); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadGroup(groupName, consumerName, xReadGroupParams, stringStreamEntryIDMap), + listMapEntryStreamEntryConverter) + .run(args); + } + } + + private Long xTrim(final String key, final XTrimParams xTrimParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + } + } + + private Long xTrim(final byte[] key, final XTrimParams xTrimParams, final CommandArguments args) { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.XTRIM, (cmd)->cmd.xtrim(key, xTrimParams), (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisStringOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisStringOperations.java index 3bffa2de7..f5abeac86 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisStringOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisStringOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -28,10 +28,8 @@ import com.buession.redis.client.jedis.JedisStandaloneClient; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.Converters; -import com.buession.redis.core.internal.convert.jedis.params.GetExArgumentConverter; -import com.buession.redis.core.internal.convert.jedis.params.SetArgumentConverter; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import com.buession.redis.core.internal.jedis.JedisGetExParams; +import com.buession.redis.core.internal.jedis.JedisSetParams; import redis.clients.jedis.params.GetExParams; import redis.clients.jedis.params.SetParams; @@ -47,231 +45,373 @@ */ public final class JedisStringOperations extends AbstractStringOperations { - public JedisStringOperations(final JedisStandaloneClient client){ + public JedisStringOperations(final JedisStandaloneClient client) { super(client); } @Override - public Long append(final String key, final String value){ + public Long append(final String key, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.APPEND) - .general((cmd)->cmd.append(key, value)) - .pipeline((cmd)->cmd.append(key, value)) - .transaction((cmd)->cmd.append(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } } @Override - public Long append(final byte[] key, final byte[] value){ + public Long append(final byte[] key, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.APPEND) - .general((cmd)->cmd.append(key, value)) - .pipeline((cmd)->cmd.append(key, value)) - .transaction((cmd)->cmd.append(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } } @Override - public Long incr(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.INCR) - .general((cmd)->cmd.incr(key)) - .pipeline((cmd)->cmd.incr(key)) - .transaction((cmd)->cmd.incr(key)) - .run(args); + public Long incr(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } } @Override - public Long incr(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.INCR) - .general((cmd)->cmd.incr(key)) - .pipeline((cmd)->cmd.incr(key)) - .transaction((cmd)->cmd.incr(key)) - .run(args); + public Long incr(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } } @Override - public Long incrBy(final String key, final long value){ + public Long incrBy(final String key, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.INCRBY) - .general((cmd)->cmd.incrBy(key, value)) - .pipeline((cmd)->cmd.incrBy(key, value)) - .transaction((cmd)->cmd.incrBy(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + } } @Override - public Long incrBy(final byte[] key, final long value){ + public Long incrBy(final byte[] key, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.INCRBY) - .general((cmd)->cmd.incrBy(key, value)) - .pipeline((cmd)->cmd.incrBy(key, value)) - .transaction((cmd)->cmd.incrBy(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrBy(key, value), (v)->v) + .run(args); + } } @Override - public Double incrByFloat(final String key, final double value){ + public Double incrByFloat(final String key, final double value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.INCRBYFLOAT) - .general((cmd)->cmd.incrByFloat(key, value)) - .pipeline((cmd)->cmd.incrByFloat(key, value)) - .transaction((cmd)->cmd.incrByFloat(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + } } @Override - public Double incrByFloat(final byte[] key, final double value){ + public Double incrByFloat(final byte[] key, final double value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.INCRBYFLOAT) - .general((cmd)->cmd.incrByFloat(key, value)) - .pipeline((cmd)->cmd.incrByFloat(key, value)) - .transaction((cmd)->cmd.incrByFloat(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.INCRBYFLOAT, + (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.INCRBYFLOAT, (cmd)->cmd.incrByFloat(key, value), (v)->v) + .run(args); + } } @Override - public Long decr(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.DECR) - .general((cmd)->cmd.decr(key)) - .pipeline((cmd)->cmd.decr(key)) - .transaction((cmd)->cmd.decr(key)) - .run(args); + public Long decr(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } } @Override - public Long decr(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.DECR) - .general((cmd)->cmd.decr(key)) - .pipeline((cmd)->cmd.decr(key)) - .transaction((cmd)->cmd.decr(key)) - .run(args); + public Long decr(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } } @Override - public Long decrBy(final String key, final long value){ + public Long decrBy(final String key, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.DECRBY) - .general((cmd)->cmd.decrBy(key, value)) - .pipeline((cmd)->cmd.decrBy(key, value)) - .transaction((cmd)->cmd.decrBy(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + } } @Override - public Long decrBy(final byte[] key, final long value){ + public Long decrBy(final byte[] key, final long value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.DECRBY) - .general((cmd)->cmd.decrBy(key, value)) - .pipeline((cmd)->cmd.decrBy(key, value)) - .transaction((cmd)->cmd.decrBy(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrBy(key, value), (v)->v) + .run(args); + } } @Override - public String get(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.GET) - .general((cmd)->cmd.get(key)) - .pipeline((cmd)->cmd.get(key)) - .transaction((cmd)->cmd.get(key)) - .run(args); + public String get(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + } } @Override - public byte[] get(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.GET) - .general((cmd)->cmd.get(key)) - .pipeline((cmd)->cmd.get(key)) - .transaction((cmd)->cmd.get(key)) - .run(args); + public byte[] get(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), (v)->v) + .run(args); + } } @Override - public String getEx(final String key, final GetExArgument getExArgument){ + public String getEx(final String key, final GetExArgument getExArgument) { final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); - final GetExParams params = GetExArgumentConverter.INSTANCE.convert(getExArgument); - return new JedisCommand(client, ProtocolCommand.GETEX) - .general((cmd)->cmd.getEx(key, params)).pipeline((cmd)->cmd.getEx(key, params)) - .transaction((cmd)->cmd.getEx(key, params)) - .run(args); + final GetExParams getExParams = JedisGetExParams.from(getExArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GETEX, (cmd)->cmd.getEx(key, getExParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + } } @Override - public byte[] getEx(final byte[] key, final GetExArgument getExArgument){ + public byte[] getEx(final byte[] key, final GetExArgument getExArgument) { final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); - final GetExParams params = GetExArgumentConverter.INSTANCE.convert(getExArgument); - return new JedisCommand(client, ProtocolCommand.GETEX) - .general((cmd)->cmd.getEx(key, params)).pipeline((cmd)->cmd.getEx(key, params)) - .transaction((cmd)->cmd.getEx(key, params)) - .run(args); + final GetExParams getExParams = JedisGetExParams.from(getExArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GETEX, (cmd)->cmd.getEx(key, getExParams), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GETEX, (cmd)->cmd.getEx(key, getExParams), (v)->v) + .run(args); + } } @Override - public String getSet(final String key, final String value){ + public String getSet(final String key, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.GETSET) - .general((cmd)->cmd.getSet(key, value)).pipeline((cmd)->cmd.getSet(key, value)) - .transaction((cmd)->cmd.getSet(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + } } @Override - public byte[] getSet(final byte[] key, final byte[] value){ + public byte[] getSet(final byte[] key, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.GETSET) - .general((cmd)->cmd.getSet(key, value)).pipeline((cmd)->cmd.getSet(key, value)) - .transaction((cmd)->cmd.getSet(key, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getSet(key, value), (v)->v) + .run(args); + } } @Override - public String getDel(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.GETDEL) - .general((cmd)->cmd.getDel(key)) - .pipeline((cmd)->cmd.getDel(key)) - .transaction((cmd)->cmd.getDel(key)) - .run(args); + public String getDel(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + } } @Override - public byte[] getDel(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.GETDEL) - .general((cmd)->cmd.getDel(key)) - .pipeline((cmd)->cmd.getDel(key)) - .transaction((cmd)->cmd.getDel(key)) - .run(args); + public byte[] getDel(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GETDEL, (cmd)->cmd.getDel(key), (v)->v) + .run(args); + } } @Override - public List mGet(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand>(client, ProtocolCommand.MGET) - .general((cmd)->cmd.mget(keys)) - .pipeline((cmd)->cmd.mget(keys)) - .transaction((cmd)->cmd.mget(keys)) - .run(args); + public List mGet(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + } } @Override - public List mGet(final byte[]... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand>(client, ProtocolCommand.MGET) - .general((cmd)->cmd.mget(keys)) - .pipeline((cmd)->cmd.mget(keys)) - .transaction((cmd)->cmd.mget(keys)) - .run(args); + public List mGet(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), (v)->v) + .run(args); + } } @Override - public Status mSet(final Map values){ - final CommandArguments args = CommandArguments.create("values", values); + public Status mSet(final Map values) { + final CommandArguments args = CommandArguments.create(values); final List temp = new ArrayList<>(values.size() * 2); values.forEach((key, value)->{ @@ -280,16 +420,24 @@ public Status mSet(final Map values){ }); final String[] keysValues = temp.toArray(new String[0]); - return new JedisCommand(client, ProtocolCommand.MSET) - .general((cmd)->cmd.mset(keysValues), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.mset(keysValues), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.mset(keysValues), OkStatusConverter.INSTANCE) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.MSET, (cmd)->cmd.mset(keysValues), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MSET, (cmd)->cmd.mset(keysValues), okStatusConverter) + .run(args); + } } @Override - public Status mSetNx(final Map values){ - final CommandArguments args = CommandArguments.create("values", values); + public Status mSetNx(final Map values) { + final CommandArguments args = CommandArguments.create(values); final List temp = new ArrayList<>(values.size() * 2); values.forEach((key, value)->{ @@ -298,191 +446,349 @@ public Status mSetNx(final Map values){ }); final String[] keysValues = temp.toArray(new String[0]); - return new JedisCommand(client, ProtocolCommand.MSETNX) - .general((cmd)->cmd.msetnx(keysValues), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.msetnx(keysValues), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.msetnx(keysValues), Converters.ONE_STATUS_CONVERTER) - .run(args); - } - @Override - public Status pSetEx(final String key, final String value, final int lifetime){ - final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); - return new JedisCommand(client, ProtocolCommand.PSETEX) - .general((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.MSETNX, (cmd)->cmd.msetnx(keysValues), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MSETNX, (cmd)->cmd.msetnx(keysValues), oneStatusConverter) + .run(args); + } } @Override - public Status pSetEx(final byte[] key, final byte[] value, final int lifetime){ + public Status pSetEx(final String key, final String value, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); - return new JedisCommand(client, ProtocolCommand.PSETEX) - .general((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.psetex(key, lifetime, value), OkStatusConverter.INSTANCE) - .run(args); - } - - @Override - public Status set(final String key, final String value){ - final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.SET) - .general((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .run(args); - } - - @Override - public Status set(final byte[] key, final byte[] value){ - final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.SET) - .general((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.set(key, value), OkStatusConverter.INSTANCE) - .run(args); - } - @Override - public Status set(final String key, final String value, final SetArgument setArgument){ - final CommandArguments args = CommandArguments.create("key", key).put("value", value); - final SetParams params = SetArgumentConverter.INSTANCE.convert(setArgument); - return new JedisCommand(client, ProtocolCommand.SET) - .general((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } } @Override - public Status set(final byte[] key, final byte[] value, final SetArgument setArgument){ - final CommandArguments args = CommandArguments.create("key", key).put("value", value); - final SetParams params = SetArgumentConverter.INSTANCE.convert(setArgument); - return new JedisCommand(client, ProtocolCommand.SET) - .general((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.set(key, value, params), OkStatusConverter.INSTANCE) - .run(args); - } - - @Override - public Status setEx(final String key, final String value, final int lifetime){ + public Status pSetEx(final byte[] key, final byte[] value, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); - return new JedisCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .run(args); - } - @Override - public Status setEx(final byte[] key, final byte[] value, final int lifetime){ + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final String key, final String value) { + final CommandArguments args = CommandArguments.create(key).add(value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create(key).add(value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final String key, final String value, final SetArgument setArgument) { + final CommandArguments args = CommandArguments.create(key).add(value); + final SetParams setParams = JedisSetParams.from(setArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value, final SetArgument setArgument) { + final CommandArguments args = CommandArguments.create(key).add(value); + final SetParams setParams = JedisSetParams.from(setArgument); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setParams), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setEx(final String key, final String value, final int lifetime) { final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); - return new JedisCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .pipeline((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .transaction((cmd)->cmd.setex(key, lifetime, value), OkStatusConverter.INSTANCE) - .run(args); - } - @Override - public Status setNx(final String key, final String value){ - final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .run(args); + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } } @Override - public Status setNx(final byte[] key, final byte[] value){ - final CommandArguments args = CommandArguments.create("key", key).put("value", value); - return new JedisCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .pipeline((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .transaction((cmd)->cmd.setnx(key, value), Converters.ONE_STATUS_CONVERTER) - .run(args); - } + public Status setEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); - @Override - public Long setRange(final String key, final long offset, final String value){ + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setNx(final String key, final String value) { + final CommandArguments args = CommandArguments.create(key).add(value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), oneStatusConverter) + .run(args); + } + } + + @Override + public Status setNx(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create(key).add(value); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + oneStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), oneStatusConverter) + .run(args); + } + } + + @Override + public Long setRange(final String key, final long offset, final String value) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); - return new JedisCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setrange(key, offset, value)) - .pipeline((cmd)->cmd.setrange(key, offset, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SETRANGE, (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SETRANGE, (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + } } @Override - public Long setRange(final byte[] key, final long offset, final byte[] value){ + public Long setRange(final byte[] key, final long offset, final byte[] value) { final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); - return new JedisCommand(client, ProtocolCommand.SETEX) - .general((cmd)->cmd.setrange(key, offset, value)) - .pipeline((cmd)->cmd.setrange(key, offset, value)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SETRANGE, (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SETRANGE, (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + } } @Override - public String getRange(final String key, final long start, final long end){ + public String getRange(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand(client, ProtocolCommand.GETRANGE) - .general((cmd)->cmd.getrange(key, start, end)) - .pipeline((cmd)->cmd.getrange(key, start, end)) - .transaction((cmd)->cmd.getrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GETRANGE, (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + } } @Override - public byte[] getRange(final byte[] key, final long start, final long end){ + public byte[] getRange(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand(client, ProtocolCommand.GETRANGE) - .general((cmd)->cmd.getrange(key, start, end)) - .pipeline((cmd)->cmd.getrange(key, start, end)) - .transaction((cmd)->cmd.getrange(key, start, end)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.GETRANGE, (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + } } @Override - public Long strlen(final String key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.STRLEN) - .general((cmd)->cmd.strlen(key)) - .pipeline((cmd)->cmd.strlen(key)) - .transaction((cmd)->cmd.strlen(key)) - .run(args); + public Long strlen(final String key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } } @Override - public Long strlen(final byte[] key){ - final CommandArguments args = CommandArguments.create("key", key); - return new JedisCommand(client, ProtocolCommand.STRLEN) - .general((cmd)->cmd.strlen(key)) - .pipeline((cmd)->cmd.strlen(key)) - .transaction((cmd)->cmd.strlen(key)) - .run(args); + public Long strlen(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } } @Override - public String substr(final String key, final long start, final long end){ + public String substr(final String key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand(client, ProtocolCommand.SUBSTR) - .general((cmd)->cmd.substr(key, (int) start, (int) end)) - .pipeline((cmd)->cmd.substr(key, (int) start, (int) end)) - .transaction((cmd)->cmd.substr(key, (int) start, (int) end)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SUBSTR, (cmd)->cmd.substr(key, (int) start, (int) end), + (v)->v) + .run(args); + } } @Override - public byte[] substr(final byte[] key, final long start, final long end){ + public byte[] substr(final byte[] key, final long start, final long end) { final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); - return new JedisCommand(client, ProtocolCommand.SUBSTR) - .general((cmd)->cmd.substr(key, (int) start, (int) end)) - .pipeline((cmd)->cmd.substr(key, (int) start, (int) end)) - .transaction((cmd)->cmd.substr(key, (int) start, (int) end)) - .run(args); + + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.SUBSTR, + (cmd)->cmd.substr(key, (int) start, (int) end), (v)->v) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.SUBSTR, (cmd)->cmd.substr(key, (int) start, (int) end), + (v)->v) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisTransactionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisTransactionOperations.java index 48cad61ea..7161b09c4 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisTransactionOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/jedis/operations/JedisTransactionOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.jedis.operations; @@ -29,8 +29,6 @@ import com.buession.redis.client.jedis.JedisStandaloneClient; import com.buession.redis.core.command.CommandArguments; import com.buession.redis.core.command.ProtocolCommand; -import com.buession.redis.core.internal.convert.response.OkStatusConverter; -import com.buession.redis.exception.RedisException; import redis.clients.jedis.Builder; import redis.clients.jedis.Response; @@ -44,103 +42,174 @@ */ public final class JedisTransactionOperations extends AbstractTransactionOperations { - public JedisTransactionOperations(final JedisStandaloneClient client){ + public JedisTransactionOperations(final JedisStandaloneClient client) { super(client); } @Override - public Status multi(){ - return new JedisCommand(client, ProtocolCommand.MULTI) - .general((cmd)->{ - RedisConnection connection = client.getConnection(); - connection.multi(); + public void discard() { + if(isPipeline()){ + new JedisPipelineCommand<>(client, ProtocolCommand.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new JedisTransactionCommand<>(client, ProtocolCommand.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + }else{ + new JedisCommand<>(client, ProtocolCommand.DISCARD, (cmd)->{ + RedisConnection connection = client.getConnection(); + connection.discard(); + return null; + }, (v)->v) + .run(); + } + } - return Status.SUCCESS; - }).transaction((cmd)->{ - RedisConnection connection = client.getConnection(); - connection.multi(); + @Override + public List exec() { + if(isPipeline()){ + return new JedisPipelineCommand<>(client, ProtocolCommand.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); - return new Response<>(new Builder() { + return new Response<>(new Builder>() { - @Override - public Status build(Object data){ - return Status.SUCCESS; - } + @Override + public List build(Object data) { + return connection.exec(); + } - }); - }) - .run(); - } + }); + }, (v)->v).run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.EXEC, (cmd)->{ + RedisConnection connection = client.getConnection(); - @Override - public List exec(){ - return new JedisCommand>(client, ProtocolCommand.EXEC) { + return new Response<>(new Builder>() { + + @Override + public List build(Object data) { + return connection.exec(); + } - @Override - public List execute() throws RedisException{ + }); + }, (v)->v).run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.EXEC, (cmd)->{ RedisConnection connection = client.getConnection(); return connection.exec(); - } - - }.run(); + }, (v)->v).run(); + } } @Override - public void discard(){ - new JedisCommand(client, ProtocolCommand.DISCARD) - .transaction((cmd)->{ - RedisConnection connection = client.getConnection(); - connection.discard(); - return null; - }) - .run(); + public Status multi() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.MULTI) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.MULTI, + (cmd)->new Response<>(new Builder() { + + @Override + public Status build(Object data) { + try{ + cmd.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; + } + } + + }), (v)->v) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.MULTI, (cmd)->{ + try{ + cmd.multi(); + return Status.SUCCESS; + }catch(Exception e){ + return Status.FAILURE; + } + }, (v)->v) + .run(); + } } @Override - public Status watch(final String... keys){ - final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.WATCH) - .general((cmd)->cmd.watch(keys), OkStatusConverter.INSTANCE) - .transaction((cmd)->new Response<>(new Builder() { + public Status unwatch() { + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.UNWATCH) + .run(); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.UNWATCH, + (cmd)->new Response<>(new Builder() { - @Override - public String build(Object data){ - return cmd.watch(keys); - } + @Override + public String build(Object data) { + return cmd.unwatch(); + } - }), OkStatusConverter.INSTANCE) - .run(args); + }), okStatusConverter) + .run(); + }else{ + return new JedisCommand<>(client, ProtocolCommand.UNWATCH, (cmd)->cmd.unwatch(), okStatusConverter) + .run(); + } } @Override - public Status watch(final byte[]... keys){ + public Status watch(final String... keys) { final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - return new JedisCommand(client, ProtocolCommand.WATCH) - .general((cmd)->cmd.watch(keys), OkStatusConverter.INSTANCE) - .transaction((cmd)->new Response<>(new Builder() { - @Override - public String build(Object data){ - return cmd.watch(keys); - } + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.WATCH) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.WATCH, + (cmd)->new Response<>(new Builder() { - }), OkStatusConverter.INSTANCE) - .run(args); + @Override + public String build(Object data) { + return cmd.watch(keys); + } + + }), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.WATCH, (cmd)->cmd.watch(keys), okStatusConverter) + .run(args); + } } @Override - public Status unwatch(){ - return new JedisCommand(client, ProtocolCommand.UNWATCH) - .general((cmd)->cmd.unwatch(), OkStatusConverter.INSTANCE) - .transaction((cmd)->new Response<>(new Builder() { + public Status watch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); - @Override - public String build(Object data){ - return cmd.unwatch(); - } + if(isPipeline()){ + return new JedisPipelineCommand(client, ProtocolCommand.WATCH) + .run(args); + }else if(isTransaction()){ + return new JedisTransactionCommand<>(client, ProtocolCommand.WATCH, + (cmd)->new Response<>(new Builder() { + + @Override + public String build(Object data) { + return cmd.watch(keys); + } - }), OkStatusConverter.INSTANCE) - .run(); + }), okStatusConverter) + .run(args); + }else{ + return new JedisCommand<>(client, ProtocolCommand.WATCH, (cmd)->cmd.watch(keys), okStatusConverter) + .run(args); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/AbstractLettuceRedisClient.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/AbstractLettuceRedisClient.java new file mode 100644 index 000000000..d5b71edf3 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/AbstractLettuceRedisClient.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce; + +import com.buession.redis.client.AbstractRedisClient; +import com.buession.redis.client.connection.lettuce.LettuceRedisConnection; + +/** + * Lettuce Redis 客户端抽象类 + * + * @param + * Lettuce Redis 连接对象类型 {@link LettuceRedisConnection} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractLettuceRedisClient extends AbstractRedisClient + implements LettuceRedisClient { + + /** + * 构造函数 + */ + public AbstractLettuceRedisClient() { + super(); + } + + /** + * 构造函数 + * + * @param connection + * Lettuce Redis 连接对象 {@link LettuceRedisConnection} + */ + public AbstractLettuceRedisClient(final CONN connection) { + super(connection); + } + +} \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/LettuceClusterClient.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/LettuceClusterClient.java new file mode 100644 index 000000000..ede0d9497 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/LettuceClusterClient.java @@ -0,0 +1,227 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce; + +import com.buession.redis.client.RedisClusterClient; +import com.buession.redis.client.connection.lettuce.LettuceClusterConnection; +import com.buession.redis.client.lettuce.operations.LettuceClusterBitMapOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterClusterOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterConnectionOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterGenericOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterGeoOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterHashOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterHyperLogLogOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterKeyOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterListOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterPubSubOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterScriptingOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterServerOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterSetOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterSortedSetOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterStreamOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterStringOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterTransactionOperations; +import com.buession.redis.client.operations.*; + +/** + * Lettuce 集群模式客户端 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceClusterClient extends AbstractLettuceRedisClient + implements RedisClusterClient { + + /** + * 构造函数 + */ + public LettuceClusterClient() { + super(); + } + + /** + * 构造函数 + * + * @param connection + * Lettuce Redis 集群连接对象 {@link LettuceClusterConnection} + */ + public LettuceClusterClient(final LettuceClusterConnection connection) { + super(connection); + } + + @Override + public BitMapOperations bitMapOperations() { + if(bitMapOperations == null){ + bitMapOperations = new LettuceClusterBitMapOperations(this); + } + + return bitMapOperations; + } + + @Override + public ClusterOperations clusterOperations() { + if(clusterOperations == null){ + clusterOperations = new LettuceClusterClusterOperations(this); + } + + return clusterOperations; + } + + @Override + public ConnectionOperations connectionOperations() { + if(connectionOperations == null){ + connectionOperations = new LettuceClusterConnectionOperations(this); + } + + return connectionOperations; + } + + @Override + public GenericOperations genericOperations() { + if(genericOperations == null){ + genericOperations = new LettuceClusterGenericOperations(this); + } + + return genericOperations; + } + + @Override + public GeoOperations geoOperations() { + if(geoOperations == null){ + geoOperations = new LettuceClusterGeoOperations(this); + } + + return geoOperations; + } + + @Override + public HashOperations hashOperations() { + if(hashOperations == null){ + hashOperations = new LettuceClusterHashOperations(this); + } + + return hashOperations; + } + + @Override + public HyperLogLogOperations hyperLogLogOperations() { + if(hyperLogLogOperations == null){ + hyperLogLogOperations = new LettuceClusterHyperLogLogOperations(this); + } + + return hyperLogLogOperations; + } + + @Override + public KeyOperations keyOperations() { + if(keyOperations == null){ + keyOperations = new LettuceClusterKeyOperations(this); + } + + return keyOperations; + } + + @Override + public ListOperations listOperations() { + if(listOperations == null){ + listOperations = new LettuceClusterListOperations(this); + } + + return listOperations; + } + + @Override + public PubSubOperations pubSubOperations() { + if(pubSubOperations == null){ + pubSubOperations = new LettuceClusterPubSubOperations(this); + } + + return pubSubOperations; + } + + @Override + public ScriptingOperations scriptingOperations() { + if(scriptingOperations == null){ + scriptingOperations = new LettuceClusterScriptingOperations(this); + } + + return scriptingOperations; + } + + @Override + public ServerOperations serverOperations() { + if(serverOperations == null){ + serverOperations = new LettuceClusterServerOperations(this); + } + + return serverOperations; + } + + @Override + public SetOperations setOperations() { + if(setOperations == null){ + setOperations = new LettuceClusterSetOperations(this); + } + + return setOperations; + } + + @Override + public SortedSetOperations sortedSetOperations() { + if(sortedSetOperations == null){ + sortedSetOperations = new LettuceClusterSortedSetOperations(this); + } + + return sortedSetOperations; + } + + @Override + public StreamOperations streamOperations() { + if(streamOperations == null){ + streamOperations = new LettuceClusterStreamOperations(this); + } + + return streamOperations; + } + + @Override + public StringOperations stringOperations() { + if(stringOperations == null){ + stringOperations = new LettuceClusterStringOperations(this); + } + + return stringOperations; + } + + @Override + public TransactionOperations transactionOperations() { + if(transactionOperations == null){ + transactionOperations = new LettuceClusterTransactionOperations(this); + } + + return transactionOperations; + } + +} \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/LettuceRedisClient.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/LettuceRedisClient.java new file mode 100644 index 000000000..ee0b2631c --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/LettuceRedisClient.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce; + +import com.buession.redis.client.RedisClient; + +/** + * Lettuce Redis 客户端 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface LettuceRedisClient extends RedisClient { + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/LettuceSentinelClient.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/LettuceSentinelClient.java new file mode 100644 index 000000000..b8c2184b2 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/LettuceSentinelClient.java @@ -0,0 +1,227 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce; + +import com.buession.redis.client.RedisSentinelClient; +import com.buession.redis.client.connection.lettuce.LettuceSentinelConnection; +import com.buession.redis.client.lettuce.operations.LettuceSentinelBitMapOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelClusterOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelConnectionOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelGenericOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelGeoOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelHashOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelHyperLogLogOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelKeyOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelListOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelPubSubOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelScriptingOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelServerOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelSetOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelSortedSetOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelStreamOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelStringOperations; +import com.buession.redis.client.lettuce.operations.LettuceSentinelTransactionOperations; +import com.buession.redis.client.operations.*; + +/** + * Lettuce 哨兵模式客户端 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceSentinelClient extends AbstractLettuceRedisClient + implements RedisSentinelClient { + + /** + * 构造函数 + */ + public LettuceSentinelClient() { + super(); + } + + /** + * 构造函数 + * + * @param connection + * Lettuce Redis 哨兵连接对象 {@link LettuceSentinelConnection} + */ + public LettuceSentinelClient(final LettuceSentinelConnection connection) { + super(connection); + } + + @Override + public BitMapOperations bitMapOperations() { + if(bitMapOperations == null){ + bitMapOperations = new LettuceSentinelBitMapOperations(this); + } + + return bitMapOperations; + } + + @Override + public ClusterOperations clusterOperations() { + if(clusterOperations == null){ + clusterOperations = new LettuceSentinelClusterOperations(this); + } + + return clusterOperations; + } + + @Override + public ConnectionOperations connectionOperations() { + if(connectionOperations == null){ + connectionOperations = new LettuceSentinelConnectionOperations(this); + } + + return connectionOperations; + } + + @Override + public GenericOperations genericOperations() { + if(genericOperations == null){ + genericOperations = new LettuceSentinelGenericOperations(this); + } + + return genericOperations; + } + + @Override + public GeoOperations geoOperations() { + if(geoOperations == null){ + geoOperations = new LettuceSentinelGeoOperations(this); + } + + return geoOperations; + } + + @Override + public HashOperations hashOperations() { + if(hashOperations == null){ + hashOperations = new LettuceSentinelHashOperations(this); + } + + return hashOperations; + } + + @Override + public HyperLogLogOperations hyperLogLogOperations() { + if(hyperLogLogOperations == null){ + hyperLogLogOperations = new LettuceSentinelHyperLogLogOperations(this); + } + + return hyperLogLogOperations; + } + + @Override + public KeyOperations keyOperations() { + if(keyOperations == null){ + keyOperations = new LettuceSentinelKeyOperations(this); + } + + return keyOperations; + } + + @Override + public ListOperations listOperations() { + if(listOperations == null){ + listOperations = new LettuceSentinelListOperations(this); + } + + return listOperations; + } + + @Override + public PubSubOperations pubSubOperations() { + if(pubSubOperations == null){ + pubSubOperations = new LettuceSentinelPubSubOperations(this); + } + + return pubSubOperations; + } + + @Override + public ScriptingOperations scriptingOperations() { + if(scriptingOperations == null){ + scriptingOperations = new LettuceSentinelScriptingOperations(this); + } + + return scriptingOperations; + } + + @Override + public ServerOperations serverOperations() { + if(serverOperations == null){ + serverOperations = new LettuceSentinelServerOperations(this); + } + + return serverOperations; + } + + @Override + public SetOperations setOperations() { + if(setOperations == null){ + setOperations = new LettuceSentinelSetOperations(this); + } + + return setOperations; + } + + @Override + public SortedSetOperations sortedSetOperations() { + if(sortedSetOperations == null){ + sortedSetOperations = new LettuceSentinelSortedSetOperations(this); + } + + return sortedSetOperations; + } + + @Override + public StreamOperations streamOperations() { + if(streamOperations == null){ + streamOperations = new LettuceSentinelStreamOperations(this); + } + + return streamOperations; + } + + @Override + public StringOperations stringOperations() { + if(stringOperations == null){ + stringOperations = new LettuceSentinelStringOperations(this); + } + + return stringOperations; + } + + @Override + public TransactionOperations transactionOperations() { + if(transactionOperations == null){ + transactionOperations = new LettuceSentinelTransactionOperations(this); + } + + return transactionOperations; + } + +} \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/LettuceStandaloneClient.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/LettuceStandaloneClient.java new file mode 100644 index 000000000..f3c005a49 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/LettuceStandaloneClient.java @@ -0,0 +1,227 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce; + +import com.buession.redis.client.RedisStandaloneClient; +import com.buession.redis.client.connection.lettuce.LettuceConnection; +import com.buession.redis.client.lettuce.operations.LettuceBitMapOperations; +import com.buession.redis.client.lettuce.operations.LettuceClusterOperations; +import com.buession.redis.client.lettuce.operations.LettuceConnectionOperations; +import com.buession.redis.client.lettuce.operations.LettuceGenericOperations; +import com.buession.redis.client.lettuce.operations.LettuceGeoOperations; +import com.buession.redis.client.lettuce.operations.LettuceHashOperations; +import com.buession.redis.client.lettuce.operations.LettuceHyperLogLogOperations; +import com.buession.redis.client.lettuce.operations.LettuceKeyOperations; +import com.buession.redis.client.lettuce.operations.LettuceListOperations; +import com.buession.redis.client.lettuce.operations.LettucePubSubOperations; +import com.buession.redis.client.lettuce.operations.LettuceScriptingOperations; +import com.buession.redis.client.lettuce.operations.LettuceServerOperations; +import com.buession.redis.client.lettuce.operations.LettuceSetOperations; +import com.buession.redis.client.lettuce.operations.LettuceSortedSetOperations; +import com.buession.redis.client.lettuce.operations.LettuceStreamOperations; +import com.buession.redis.client.lettuce.operations.LettuceStringOperations; +import com.buession.redis.client.lettuce.operations.LettuceTransactionOperations; +import com.buession.redis.client.operations.*; + +/** + * Lettuce 单机模式客户端 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceStandaloneClient extends AbstractLettuceRedisClient + implements RedisStandaloneClient { + + /** + * 构造函数 + */ + public LettuceStandaloneClient() { + super(); + } + + /** + * 构造函数 + * + * @param connection + * Lettuce Redis 单机连接对象 {@link LettuceConnection} + */ + public LettuceStandaloneClient(final LettuceConnection connection) { + super(connection); + } + + @Override + public BitMapOperations bitMapOperations() { + if(bitMapOperations == null){ + bitMapOperations = new LettuceBitMapOperations(this); + } + + return bitMapOperations; + } + + @Override + public ClusterOperations clusterOperations() { + if(clusterOperations == null){ + clusterOperations = new LettuceClusterOperations(this); + } + + return clusterOperations; + } + + @Override + public ConnectionOperations connectionOperations() { + if(connectionOperations == null){ + connectionOperations = new LettuceConnectionOperations(this); + } + + return connectionOperations; + } + + @Override + public GenericOperations genericOperations() { + if(genericOperations == null){ + genericOperations = new LettuceGenericOperations(this); + } + + return genericOperations; + } + + @Override + public GeoOperations geoOperations() { + if(geoOperations == null){ + geoOperations = new LettuceGeoOperations(this); + } + + return geoOperations; + } + + @Override + public HashOperations hashOperations() { + if(hashOperations == null){ + hashOperations = new LettuceHashOperations(this); + } + + return hashOperations; + } + + @Override + public HyperLogLogOperations hyperLogLogOperations() { + if(hyperLogLogOperations == null){ + hyperLogLogOperations = new LettuceHyperLogLogOperations(this); + } + + return hyperLogLogOperations; + } + + @Override + public KeyOperations keyOperations() { + if(keyOperations == null){ + keyOperations = new LettuceKeyOperations(this); + } + + return keyOperations; + } + + @Override + public ListOperations listOperations() { + if(listOperations == null){ + listOperations = new LettuceListOperations(this); + } + + return listOperations; + } + + @Override + public PubSubOperations pubSubOperations() { + if(pubSubOperations == null){ + pubSubOperations = new LettucePubSubOperations(this); + } + + return pubSubOperations; + } + + @Override + public ScriptingOperations scriptingOperations() { + if(scriptingOperations == null){ + scriptingOperations = new LettuceScriptingOperations(this); + } + + return scriptingOperations; + } + + @Override + public ServerOperations serverOperations() { + if(serverOperations == null){ + serverOperations = new LettuceServerOperations(this); + } + + return serverOperations; + } + + @Override + public SetOperations setOperations() { + if(setOperations == null){ + setOperations = new LettuceSetOperations(this); + } + + return setOperations; + } + + @Override + public SortedSetOperations sortedSetOperations() { + if(sortedSetOperations == null){ + sortedSetOperations = new LettuceSortedSetOperations(this); + } + + return sortedSetOperations; + } + + @Override + public StreamOperations streamOperations() { + if(streamOperations == null){ + streamOperations = new LettuceStreamOperations(this); + } + + return streamOperations; + } + + @Override + public StringOperations stringOperations() { + if(stringOperations == null){ + stringOperations = new LettuceStringOperations(this); + } + + return stringOperations; + } + + @Override + public TransactionOperations transactionOperations() { + if(transactionOperations == null){ + transactionOperations = new LettuceTransactionOperations(this); + } + + return transactionOperations; + } + +} \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractBitMapOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractBitMapOperations.java new file mode 100644 index 000000000..11ee6e813 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractBitMapOperations.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.BitMapOperations; +import com.buession.redis.core.BitCountOption; +import com.buession.redis.core.BitOperation; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce BitMap 命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractBitMapOperations extends AbstractLettuceRedisOperations + implements BitMapOperations { + + public AbstractBitMapOperations(final C client) { + super(client); + } + + @Override + public Long bitCount(final String key) { + return bitCount(SafeEncoder.encode(key)); + } + + @Override + public Long bitCount(final String key, final long start, final long end) { + return bitCount(SafeEncoder.encode(key), start, end); + } + + @Override + public Long bitCount(final String key, final long start, final long end, final BitCountOption bitCountOption) { + return bitCount(SafeEncoder.encode(key), start, end, bitCountOption); + } + + @Override + public List bitField(final String key, final BitFieldArgument argument) { + return bitField(SafeEncoder.encode(key), argument); + } + + @Override + public Long bitOp(final BitOperation operation, final String destKey, final String... keys) { + return bitOp(operation, SafeEncoder.encode(destKey), SafeEncoder.encode(keys)); + } + + @Override + public Long bitPos(final String key, final boolean value) { + return bitPos(SafeEncoder.encode(key), value); + } + + @Override + public Long bitPos(final String key, final boolean value, final long start, final long end) { + return bitPos(SafeEncoder.encode(key), value, start, end); + } + + @Override + public Boolean getBit(final String key, final long offset) { + return getBit(SafeEncoder.encode(key), offset); + } + + @Override + public Boolean setBit(final String key, final long offset, final boolean value) { + return setBit(SafeEncoder.encode(key), offset, value); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractClusterOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractClusterOperations.java new file mode 100644 index 000000000..86e62f0db --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractClusterOperations.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.ClusterOperations; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.ClusterResetOption; +import com.buession.redis.core.ClusterSetSlotOption; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce 集群命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractClusterOperations extends AbstractLettuceRedisOperations + implements ClusterOperations { + + public AbstractClusterOperations(final C client) { + super(client); + } + + @Override + public Integer clusterCountFailureReports(final byte[] nodeId) { + return clusterCountFailureReports(SafeEncoder.encode(nodeId)); + } + + @Override + public Status clusterForget(final byte[] nodeId) { + return clusterForget(SafeEncoder.encode(nodeId)); + } + + @Override + public Long clusterKeySlot(final String key) { + return clusterKeySlot(SafeEncoder.encode(key)); + } + + @Override + public List clusterSlaves(final byte[] nodeId) { + return clusterSlaves(SafeEncoder.encode(nodeId)); + } + + @Override + public List clusterReplicas(final byte[] nodeId) { + return clusterReplicas(SafeEncoder.encode(nodeId)); + } + + @Override + public Status clusterReplicate(final byte[] nodeId) { + return clusterReplicate(SafeEncoder.encode(nodeId)); + } + + @Override + public Status clusterReset() { + return clusterReset(ClusterResetOption.SOFT); + } + + @Override + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final byte[] nodeId) { + return clusterSetSlot(slot, setSlotOption, SafeEncoder.encode(nodeId)); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractConnectionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractConnectionOperations.java new file mode 100644 index 000000000..a52b09e9f --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractConnectionOperations.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.ConnectionOperations; +import com.buession.redis.utils.SafeEncoder; + +/** + * Jedis 连接命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractConnectionOperations + extends AbstractLettuceRedisOperations implements ConnectionOperations { + + public AbstractConnectionOperations(final C client) { + super(client); + } + + @Override + public Status auth(final byte[] user, final byte[] password) { + return auth(SafeEncoder.encode(user), SafeEncoder.encode(password)); + } + + @Override + public Status auth(final byte[] password) { + return auth(SafeEncoder.encode(password)); + } + + @Override + public Status clientSetName(final String name) { + return clientSetName(SafeEncoder.encode(name)); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractGenericOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractGenericOperations.java new file mode 100644 index 000000000..ccf9b5973 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractGenericOperations.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.GenericOperations; + +/** + * Lettuce 一般命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractGenericOperations extends AbstractLettuceRedisOperations + implements GenericOperations { + + public AbstractGenericOperations(final C client) { + super(client); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractGeoOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractGeoOperations.java new file mode 100644 index 000000000..5d8c6969c --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractGeoOperations.java @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.builder.ListBuilder; +import com.buession.lang.Geo; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.GeoOperations; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 地理位置命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractGeoOperations extends AbstractLettuceRedisOperations + implements GeoOperations { + + public AbstractGeoOperations(final C client) { + super(client); + } + + @Override + public Long geoAdd(final String key, final String member, final double longitude, final double latitude) { + return geoAdd(SafeEncoder.encode(key), SafeEncoder.encode(member), longitude, latitude); + } + + @Override + public List geoPos(final String key, final String... members) { + return geoPos(SafeEncoder.encode(key), SafeEncoder.encode(members)); + } + + @Override + public Double geoDist(final String key, final String member1, final String member2) { + return geoDist(SafeEncoder.encode(key), SafeEncoder.encode(member1), SafeEncoder.encode(member2)); + } + + @Override + public Double geoDist(final String key, final String member1, final String member2, final GeoUnit unit) { + return geoDist(SafeEncoder.encode(key), SafeEncoder.encode(member1), SafeEncoder.encode(member2), unit); + } + + @Override + public List geoRadius(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + return geoRadius(SafeEncoder.encode(key), longitude, latitude, radius, unit); + } + + @Override + public List geoRadius(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + return geoRadius(SafeEncoder.encode(key), longitude, latitude, radius, unit, geoRadiusArgument); + } + + @Override + public List geoRadiusByMember(final String key, final String member, final double radius, + final GeoUnit unit) { + return geoRadiusByMember(SafeEncoder.encode(key), SafeEncoder.encode(member), radius, unit); + } + + @Override + public List geoRadiusByMember(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + return geoRadiusByMember(SafeEncoder.encode(key), SafeEncoder.encode(member), radius, unit, geoRadiusArgument); + } + + protected Long geoAdd(final String key, final Map memberCoordinates, final CommandArguments args) { + final byte[] bKey = SafeEncoder.encode(key); + final ListBuilder lngLatMemberBuilder = ListBuilder.create(memberCoordinates == null ? 0 : + memberCoordinates.size() * 3); + + if(memberCoordinates != null){ + memberCoordinates.forEach((k, v)->{ + lngLatMemberBuilder. + add(v.getLongitude()). + add(v.getLatitude()). + add(SafeEncoder.encode(k)); + }); + } + + return geoAdd(bKey, lngLatMemberBuilder, args); + } + + protected Long geoAdd(final byte[] key, final Map memberCoordinates, final CommandArguments args) { + final ListBuilder lngLatMemberBuilder = ListBuilder.create(memberCoordinates == null ? 0 : + memberCoordinates.size() * 3); + + if(memberCoordinates != null){ + memberCoordinates.forEach((k, v)->{ + lngLatMemberBuilder. + add(v.getLongitude()). + add(v.getLatitude()). + add(k); + }); + } + + return geoAdd(key, lngLatMemberBuilder, args); + } + + protected abstract Long geoAdd(final byte[] key, final ListBuilder lngLatMemberBuilder, + final CommandArguments args); + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractHashOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractHashOperations.java new file mode 100644 index 000000000..afc7ea855 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractHashOperations.java @@ -0,0 +1,140 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.utils.NumberUtils; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.HashOperations; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.utils.SafeEncoder; + +import java.util.Map; + +/** + * Lettuce 哈希表命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractHashOperations extends AbstractLettuceRedisOperations + implements HashOperations { + + public AbstractHashOperations(final C client) { + super(client); + } + + @Override + public Long hDel(final String key, final String... fields) { + return hDel(SafeEncoder.encode(key), SafeEncoder.encode(fields)); + } + + @Override + public Boolean hExists(final String key, final String field) { + return hExists(SafeEncoder.encode(key), SafeEncoder.encode(field)); + } + + @Override + public Long hIncrBy(final String key, final String field, final long value) { + return hIncrBy(SafeEncoder.encode(key), SafeEncoder.encode(field), value); + } + + @Override + public Double hIncrByFloat(final String key, final String field, final double value) { + return hIncrByFloat(SafeEncoder.encode(key), SafeEncoder.encode(field), value); + } + + @Override + public Long hLen(final String key) { + return hLen(SafeEncoder.encode(key)); + } + + @Override + public Status hMSet(final String key, final Map data) { + return hMSet(SafeEncoder.encode(key), Converters.mapStringToBinary().convert(data)); + } + + @Override + public ScanResult> hScan(final String key, final long cursor) { + return hScan(key, Long.toString(cursor)); + } + + @Override + public ScanResult> hScan(final byte[] key, final long cursor) { + return hScan(key, NumberUtils.long2bytes(cursor)); + } + + @Override + public ScanResult> hScan(final String key, final long cursor, final String pattern) { + return hScan(key, Long.toString(cursor), pattern); + } + + @Override + public ScanResult> hScan(final byte[] key, final long cursor, final byte[] pattern) { + return hScan(key, NumberUtils.long2bytes(cursor), pattern); + } + + @Override + public ScanResult> hScan(final String key, final long cursor, final long count) { + return hScan(key, Long.toString(cursor), count); + } + + @Override + public ScanResult> hScan(final byte[] key, final long cursor, final long count) { + return hScan(key, NumberUtils.long2bytes(cursor), count); + } + + @Override + public ScanResult> hScan(final String key, final long cursor, final String pattern, + final long count) { + return hScan(key, Long.toString(cursor), pattern, count); + } + + @Override + public ScanResult> hScan(final byte[] key, final long cursor, final byte[] pattern, + final long count) { + return hScan(key, NumberUtils.long2bytes(cursor), pattern, count); + } + + @Override + public Long hSet(final String key, final String field, final String value) { + return hSet(SafeEncoder.encode(key), SafeEncoder.encode(field), SafeEncoder.encode(value)); + } + + @Override + public Status hSetNx(final String key, final String field, final String value) { + return hSetNx(SafeEncoder.encode(key), SafeEncoder.encode(field), SafeEncoder.encode(value)); + } + + @Override + public Long hStrLen(final String key, final String field) { + return hStrLen(SafeEncoder.encode(key), SafeEncoder.encode(field)); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractHyperLogLogOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractHyperLogLogOperations.java new file mode 100644 index 000000000..8fa1692df --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractHyperLogLogOperations.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.HyperLogLogOperations; +import com.buession.redis.utils.SafeEncoder; + +/** + * Lettuce HyperLogLog 命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractHyperLogLogOperations + extends AbstractLettuceRedisOperations implements HyperLogLogOperations { + + public AbstractHyperLogLogOperations(final C client) { + super(client); + } + + @Override + public Status pfAdd(final String key, final String... elements) { + return pfAdd(SafeEncoder.encode(key), SafeEncoder.encode(elements)); + } + + @Override + public Status pfMerge(final String destKey, final String... keys) { + return pfMerge(SafeEncoder.encode(destKey), SafeEncoder.encode(keys)); + } + + @Override + public Long pfCount(final String... keys) { + return pfCount(SafeEncoder.encode(keys)); + } + +} \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractKeyOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractKeyOperations.java new file mode 100644 index 000000000..a95dbbeee --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractKeyOperations.java @@ -0,0 +1,254 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.utils.NumberUtils; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.KeyOperations; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.MigrateOperation; +import com.buession.redis.core.ObjectEncoding; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Type; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce Key 命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractKeyOperations extends AbstractLettuceRedisOperations + implements KeyOperations { + + public AbstractKeyOperations(final C client) { + super(client); + } + + @Override + public Long del(final String... keys) { + return del(SafeEncoder.encode(keys)); + } + + @Override + public String dump(final String key) { + return SafeEncoder.encode(dump(SafeEncoder.encode(key))); + } + + @Override + public Boolean exists(final String key) { + return exists(SafeEncoder.encode(key)); + } + + @Override + public Long exists(final String... keys) { + return exists(SafeEncoder.encode(keys)); + } + + @Override + public Status expire(final String key, final int lifetime) { + return expire(SafeEncoder.encode(key), lifetime); + } + + @Override + public Status expire(final String key, final int lifetime, final ExpireOption expireOption) { + return expire(SafeEncoder.encode(key), lifetime, expireOption); + } + + @Override + public Status expireAt(final String key, final long unixTimestamp) { + return expireAt(SafeEncoder.encode(key), unixTimestamp); + } + + @Override + public Status pExpire(final String key, final int lifetime) { + return pExpire(SafeEncoder.encode(key), lifetime); + } + + @Override + public Status pExpireAt(final String key, final long unixTimestamp) { + return pExpireAt(SafeEncoder.encode(key), unixTimestamp); + } + + @Override + public Status persist(final String key) { + return persist(SafeEncoder.encode(key)); + } + + @Override + public Long ttl(final String key) { + return ttl(SafeEncoder.encode(key)); + } + + @Override + public Long pTtl(final String key) { + return pTtl(SafeEncoder.encode(key)); + } + + @Override + public Status move(final String key, final int db) { + return move(SafeEncoder.encode(key), db); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final String... keys) { + return migrate(host, port, db, timeout, SafeEncoder.encode(keys)); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateOperation operation, final String... keys) { + return migrate(host, port, db, timeout, operation, SafeEncoder.encode(keys)); + } + + @Override + public Status migrate(final String host, final int port, final int db, final String password, final int timeout, + final String... keys) { + return migrate(host, port, db, SafeEncoder.encode(password), timeout, SafeEncoder.encode(keys)); + } + + @Override + public Status migrate(final String host, final int port, final int db, final String password, final int timeout, + final MigrateOperation operation, final String... keys) { + return migrate(host, port, db, SafeEncoder.encode(password), timeout, operation, SafeEncoder.encode(keys)); + } + + @Override + public Status migrate(final String host, final int port, final int db, final String user, final String password, + final int timeout, final String... keys) { + return migrate(host, port, db, SafeEncoder.encode(user), SafeEncoder.encode(password), timeout, + SafeEncoder.encode(keys)); + } + + @Override + public Status migrate(final String host, final int port, final int db, final String user, final String password, + final int timeout, final MigrateOperation operation, final String... keys) { + return migrate(host, port, db, SafeEncoder.encode(user), SafeEncoder.encode(password), timeout, operation, + SafeEncoder.encode(keys)); + } + + @Override + public Status rename(final String key, final String newKey) { + return rename(SafeEncoder.encode(key), SafeEncoder.encode(newKey)); + } + + @Override + public Status renameNx(final String key, final String newKey) { + return renameNx(SafeEncoder.encode(key), SafeEncoder.encode(newKey)); + } + + @Override + public Status restore(final String key, final byte[] serializedValue, final int ttl) { + return restore(SafeEncoder.encode(key), serializedValue, ttl); + } + + @Override + public Status restore(final String key, final byte[] serializedValue, final int ttl, + final RestoreArgument argument) { + return restore(SafeEncoder.encode(key), serializedValue, ttl, argument); + } + + @Override + public ScanResult> scan(final long cursor) { + return scan(Long.toString(cursor)); + } + + @Override + public ScanResult> scan(final long cursor, final String pattern) { + return scan(Long.toString(cursor), pattern); + } + + @Override + public ScanResult> scan(final long cursor, final byte[] pattern) { + return scan(NumberUtils.long2bytes(cursor), pattern); + } + + @Override + public ScanResult> scan(final long cursor, final long count) { + return scan(Long.toString(cursor), count); + } + + @Override + public ScanResult> scan(final long cursor, final String pattern, final long count) { + return scan(Long.toString(cursor), pattern, count); + } + + @Override + public ScanResult> scan(final long cursor, final byte[] pattern, final long count) { + return scan(NumberUtils.long2bytes(cursor), pattern, count); + } + + @Override + public Long sort(final String key, final String destKey) { + return sort(SafeEncoder.encode(key), SafeEncoder.encode(destKey)); + } + + @Override + public Long sort(final String key, final String destKey, final SortArgument sortArgument) { + return sort(SafeEncoder.encode(key), SafeEncoder.encode(destKey), sortArgument); + } + + @Override + public Long touch(final String... keys) { + return touch(SafeEncoder.encode(keys)); + } + + @Override + public Type type(final String key) { + return type(SafeEncoder.encode(key)); + } + + @Override + public Long unlink(final String... keys) { + return unlink(SafeEncoder.encode(keys)); + } + + @Override + public ObjectEncoding objectEncoding(final String key) { + return objectEncoding(SafeEncoder.encode(key)); + } + + @Override + public Long objectFreq(final String key) { + return objectFreq(SafeEncoder.encode(key)); + } + + @Override + public Long objectIdleTime(final String key) { + return objectIdleTime(SafeEncoder.encode(key)); + } + + @Override + public Long objectRefcount(final String key) { + return objectRefcount(SafeEncoder.encode(key)); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractLettuceRedisOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractLettuceRedisOperations.java new file mode 100644 index 000000000..f1799df1b --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractLettuceRedisOperations.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.client.operations.AbstractRedisOperations; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; + +/** + * Lettuce Redis 命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractLettuceRedisOperations extends AbstractRedisOperations + implements LettuceRedisOperations { + + public AbstractLettuceRedisOperations(final C client) { + super(client); + } + + protected T notCommand(final LettuceStandaloneClient client, final ProtocolCommand command, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, command) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, command) + .run(args); + }else{ + return new LettuceCommand(client, command) + .run(args); + } + } + + protected T notCommand(final LettuceSentinelClient client, final ProtocolCommand command, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, command) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, command) + .run(args); + }else{ + return new LettuceSentinelCommand(client, command) + .run(args); + } + } + + protected T notCommand(final LettuceClusterClient client, final ProtocolCommand command, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, command) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, command) + .run(args); + }else{ + return new LettuceClusterCommand(client, command) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractListOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractListOperations.java new file mode 100644 index 000000000..60366af73 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractListOperations.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.ListOperations; +import com.buession.redis.core.ListPosition; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce 列表命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractListOperations extends AbstractLettuceRedisOperations + implements ListOperations { + + public AbstractListOperations(final C client) { + super(client); + } + + @Override + public Long lInsert(final String key, final ListPosition position, final String pivot, final String value) { + return lInsert(SafeEncoder.encode(key), position, SafeEncoder.encode(pivot), SafeEncoder.encode(value)); + } + + @Override + public Status lSet(final String key, final long index, final String value) { + return lSet(SafeEncoder.encode(key), index, SafeEncoder.encode(value)); + } + + @Override + public Long lLen(final String key) { + return lLen(SafeEncoder.encode(key)); + } + + @Override + public Long lPos(final String key, final String element) { + return lPos(SafeEncoder.encode(key), SafeEncoder.encode(element)); + } + + @Override + public Long lPos(final String key, final String element, final LPosArgument lPosArgument) { + return lPos(SafeEncoder.encode(key), SafeEncoder.encode(element), lPosArgument); + } + + @Override + public List lPos(final String key, final String element, final LPosArgument lPosArgument, final long count) { + return lPos(SafeEncoder.encode(key), SafeEncoder.encode(element), lPosArgument, count); + } + + @Override + public Long lRem(final String key, final String value, final long count) { + return lRem(SafeEncoder.encode(key), SafeEncoder.encode(value), count); + } + + @Override + public Status lTrim(final String key, final long start, final long end) { + return lTrim(SafeEncoder.encode(key), start, end); + } + + @Override + public Long lPush(final String key, final String... values) { + return lPush(SafeEncoder.encode(key), SafeEncoder.encode(values)); + } + + @Override + public Long lPushX(final String key, final String... values) { + return lPushX(SafeEncoder.encode(key), SafeEncoder.encode(values)); + } + + @Override + public Long rPush(final String key, final String... values) { + return rPush(SafeEncoder.encode(key), SafeEncoder.encode(values)); + } + + @Override + public Long rPushX(final String key, final String... values) { + return rPushX(SafeEncoder.encode(key), SafeEncoder.encode(values)); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractPubSubOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractPubSubOperations.java new file mode 100644 index 000000000..c5f102a15 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractPubSubOperations.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.PubSubOperations; +import com.buession.redis.utils.SafeEncoder; + +/** + * Lettuce Pub/Sub 命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractPubSubOperations extends AbstractLettuceRedisOperations + implements PubSubOperations { + + public AbstractPubSubOperations(final C client) { + super(client); + } + + @Override + public Long publish(final String channel, final String message) { + return publish(SafeEncoder.encode(channel), SafeEncoder.encode(message)); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractScriptingOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractScriptingOperations.java new file mode 100644 index 000000000..5863eadd0 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractScriptingOperations.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.ScriptingOperations; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce Script 命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractScriptingOperations + extends AbstractLettuceRedisOperations + implements ScriptingOperations { + + public AbstractScriptingOperations(final C client) { + super(client); + } + + @Override + public Object eval(final byte[] script) { + return eval(SafeEncoder.encode(script)); + } + + @Override + public Object eval(final byte[] script, final byte[]... params) { + return eval(SafeEncoder.encode(script), SafeEncoder.encode(params)); + } + + @Override + public Object eval(final byte[] script, final byte[][] keys, final byte[][] arguments) { + return eval(SafeEncoder.encode(script), SafeEncoder.encode(keys), SafeEncoder.encode(arguments)); + } + + @Override + public Object evalSha(final byte[] digest) { + return evalSha(SafeEncoder.encode(digest)); + } + + @Override + public Object evalSha(final byte[] digest, final byte[]... params) { + return evalSha(SafeEncoder.encode(digest), SafeEncoder.encode(params)); + } + + @Override + public Object evalSha(final byte[] digest, final byte[][] keys, final byte[][] arguments) { + return evalSha(SafeEncoder.encode(digest), SafeEncoder.encode(keys), SafeEncoder.encode(arguments)); + } + + @Override + public List scriptExists(final byte[]... sha1) { + return scriptExists(SafeEncoder.encode(sha1)); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractServerOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractServerOperations.java new file mode 100644 index 000000000..9a996e107 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractServerOperations.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.ServerOperations; +import com.buession.redis.utils.SafeEncoder; + +/** + * Lettuce 服务端命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractServerOperations extends AbstractLettuceRedisOperations + implements ServerOperations { + + public AbstractServerOperations(final C client) { + super(client); + } + + @Override + public Status configSet(final byte[] parameter, final byte[] value) { + return configSet(SafeEncoder.encode(parameter), SafeEncoder.encode(value)); + } + + @Override + public Long memoryUsage(final String key) { + return memoryUsage(SafeEncoder.encode(key)); + } + + @Override + public Long memoryUsage(final String key, final int samples) { + return memoryUsage(SafeEncoder.encode(key), samples); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractSetOperations.java new file mode 100644 index 000000000..01340494e --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractSetOperations.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.utils.NumberUtils; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.SetOperations; +import com.buession.redis.core.ScanResult; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce 集合命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractSetOperations extends AbstractLettuceRedisOperations + implements SetOperations { + + public AbstractSetOperations(final C client) { + super(client); + } + + @Override + public Long sAdd(final String key, final String... members) { + return sAdd(SafeEncoder.encode(key), SafeEncoder.encode(members)); + } + + @Override + public Long sCard(final String key) { + return sCard(SafeEncoder.encode(key)); + } + + @Override + public Long sDiffStore(final String destKey, final String... keys) { + return sDiffStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys)); + } + + @Override + public Long sInterStore(final String destKey, final String... keys) { + return sInterStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys)); + } + + @Override + public Boolean sIsMember(final String key, final String member) { + return sIsMember(SafeEncoder.encode(key), SafeEncoder.encode(member)); + } + + @Override + public Status sMove(final String key, final String destKey, final String member) { + return sMove(SafeEncoder.encode(key), SafeEncoder.encode(destKey), SafeEncoder.encode(member)); + } + + @Override + public Long sRem(final String key, final String... members) { + return sRem(SafeEncoder.encode(key), SafeEncoder.encode(members)); + } + + @Override + public ScanResult> sScan(final String key, final long cursor) { + return sScan(key, Long.toString(cursor)); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor) { + return sScan(key, NumberUtils.long2bytes(cursor)); + } + + @Override + public ScanResult> sScan(final String key, final long cursor, final String pattern) { + return sScan(key, Long.toString(cursor), pattern); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor, final byte[] pattern) { + return sScan(key, NumberUtils.long2bytes(cursor), pattern); + } + + @Override + public ScanResult> sScan(final String key, final long cursor, final long count) { + return sScan(key, Long.toString(cursor), count); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor, final long count) { + return sScan(key, NumberUtils.long2bytes(cursor), count); + } + + @Override + public ScanResult> sScan(final String key, final long cursor, final String pattern, final long count) { + return sScan(key, Long.toString(cursor), pattern, count); + } + + @Override + public ScanResult> sScan(final byte[] key, final long cursor, final byte[] pattern, final long count) { + return sScan(key, NumberUtils.long2bytes(cursor), pattern, count); + } + + @Override + public Long sUnionStore(final String destKey, final String... keys) { + return sUnionStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys)); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractSortedSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractSortedSetOperations.java new file mode 100644 index 000000000..77643798f --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractSortedSetOperations.java @@ -0,0 +1,396 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.utils.NumberUtils; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.SortedSetOperations; +import com.buession.redis.core.Aggregate; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce 有序集合命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractSortedSetOperations + extends AbstractLettuceRedisOperations implements SortedSetOperations { + + public AbstractSortedSetOperations(final C client) { + super(client); + } + + @Override + public Tuple zPopMin(final String key) { + return zPopMin(SafeEncoder.encode(key)); + } + + @Override + public List zPopMin(final String key, final long count) { + return zPopMin(SafeEncoder.encode(key), count); + } + + @Override + public Tuple zPopMax(final String key) { + return zPopMax(SafeEncoder.encode(key)); + } + + @Override + public List zPopMax(final String key, final long count) { + return zPopMax(SafeEncoder.encode(key), count); + } + + @Override + public Long zCard(final String key) { + return zCard(SafeEncoder.encode(key)); + } + + @Override + public Long zCount(final String key, final double min, final double max) { + return zCount(SafeEncoder.encode(key), min, max); + } + + @Deprecated + @Override + public Long zCount(final String key, final String min, final String max) { + return zCount(key, Double.parseDouble(min), Double.parseDouble(max)); + } + + @Deprecated + @Override + public Long zCount(final byte[] key, final byte[] min, final byte[] max) { + return zCount(key, NumberUtils.bytes2double(min), NumberUtils.bytes2double(max)); + } + + @Override + public Double zIncrBy(final String key, final double increment, final String member) { + return zIncrBy(SafeEncoder.encode(key), increment, SafeEncoder.encode(member)); + } + + @Override + public Long zInterStore(final String destKey, final String... keys) { + return zInterStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys)); + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate) { + return zInterStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys), aggregate); + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final double... weights) { + return zInterStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys), weights); + } + + @Override + public Long zInterStore(final String destKey, final String[] keys, final Aggregate aggregate, + final double... weights) { + return zInterStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys), aggregate, weights); + } + + @Override + public Long zLexCount(final String key, final double min, final double max) { + return zLexCount(SafeEncoder.encode(key), NumberUtils.double2bytes(min), NumberUtils.double2bytes(max)); + } + + @Override + public Long zLexCount(final byte[] key, final double min, final double max) { + return zLexCount(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max)); + } + + @Deprecated + @Override + public Long zLexCount(final String key, final String min, final String max) { + return zLexCount(SafeEncoder.encode(key), SafeEncoder.encode(min), SafeEncoder.encode(max)); + } + + @Override + public List zRangeWithScores(final String key, final long start, final long end) { + return zRangeWithScores(SafeEncoder.encode(key), start, end); + } + + @Deprecated + @Override + public List zRangeByScore(final String key, final String min, final String max) { + return zRangeByScore(key, Double.parseDouble(min), Double.parseDouble(max)); + } + + @Deprecated + @Override + public List zRangeByScore(final byte[] key, final byte[] min, final byte[] max) { + return zRangeByScore(key, NumberUtils.bytes2double(min), NumberUtils.bytes2double(max)); + } + + @Deprecated + @Override + public List zRangeByScore(final String key, final String min, final String max, final long offset, + final long count) { + return zRangeByScore(key, Double.parseDouble(min), Double.parseDouble(max), offset, count); + } + + @Deprecated + @Override + public List zRangeByScore(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count) { + return zRangeByScore(key, NumberUtils.bytes2double(min), NumberUtils.bytes2double(max), offset, count); + } + + @Override + public List zRangeByScoreWithScores(final String key, final double min, final double max) { + return zRangeByScoreWithScores(SafeEncoder.encode(key), min, max); + } + + @Deprecated + @Override + public List zRangeByScoreWithScores(final String key, final String min, final String max) { + return zRangeByScoreWithScores(key, Double.parseDouble(min), Double.parseDouble(max)); + } + + @Deprecated + @Override + public List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max) { + return zRangeByScoreWithScores(key, NumberUtils.bytes2double(min), NumberUtils.bytes2double(max)); + } + + @Override + public List zRangeByScoreWithScores(final String key, final double min, final double max, final long offset, + final long count) { + return zRangeByScoreWithScores(SafeEncoder.encode(key), min, max, offset, count); + } + + @Deprecated + @Override + public List zRangeByScoreWithScores(final String key, final String min, final String max, final long offset, + final long count) { + return zRangeByScoreWithScores(key, Double.parseDouble(min), Double.parseDouble(max), offset, count); + } + + @Deprecated + @Override + public List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count) { + return zRangeByScoreWithScores(key, NumberUtils.bytes2double(min), NumberUtils.bytes2double(max), offset, + count); + } + + @Override + public Long zRank(final String key, final String member) { + return zRank(SafeEncoder.encode(key), SafeEncoder.encode(member)); + } + + @Override + public Long zRem(final String key, final String... members) { + return zRem(SafeEncoder.encode(key), SafeEncoder.encode(members)); + } + + @Override + public Long zRemRangeByLex(final String key, final double min, final double max) { + return zRemRangeByLex(SafeEncoder.encode(key), NumberUtils.double2bytes(min), NumberUtils.double2bytes(max)); + } + + @Override + public Long zRemRangeByLex(final byte[] key, final double min, final double max) { + return zRemRangeByLex(key, NumberUtils.double2bytes(min), NumberUtils.double2bytes(max)); + } + + @Deprecated + @Override + public Long zRemRangeByLex(final String key, final String min, final String max) { + return zRemRangeByLex(SafeEncoder.encode(key), SafeEncoder.encode(min), SafeEncoder.encode(max)); + } + + @Override + public Long zRemRangeByScore(final String key, final double min, final double max) { + return zRemRangeByScore(SafeEncoder.encode(key), min, max); + } + + @Deprecated + @Override + public Long zRemRangeByScore(final String key, final String min, final String max) { + return zRemRangeByScore(key, Double.parseDouble(min), Double.parseDouble(max)); + } + + @Deprecated + @Override + public Long zRemRangeByScore(final byte[] key, final byte[] min, final byte[] max) { + return zRemRangeByScore(key, NumberUtils.bytes2double(min), NumberUtils.bytes2double(max)); + } + + @Override + public Long zRemRangeByRank(final String key, final long start, final long end) { + return zRemRangeByRank(SafeEncoder.encode(key), start, end); + } + + @Override + public List zRevRangeWithScores(final String key, final long start, final long end) { + return zRevRangeWithScores(SafeEncoder.encode(key), start, end); + } + + @Deprecated + @Override + public List zRevRangeByScore(final String key, final String min, final String max) { + return zRevRangeByScore(key, Double.parseDouble(min), Double.parseDouble(max)); + } + + @Deprecated + @Override + public List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max) { + return zRevRangeByScore(key, NumberUtils.bytes2double(min), NumberUtils.bytes2double(max)); + } + + @Deprecated + @Override + public List zRevRangeByScore(final String key, final String min, final String max, final long offset, + final long count) { + return zRevRangeByScore(key, Double.parseDouble(min), Double.parseDouble(max), offset, count); + } + + @Deprecated + @Override + public List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count) { + return zRevRangeByScore(key, NumberUtils.bytes2double(min), NumberUtils.bytes2double(max), offset, count); + } + + @Override + public List zRevRangeByScoreWithScores(final String key, final double min, final double max) { + return zRevRangeByScoreWithScores(SafeEncoder.encode(key), min, max); + } + + @Deprecated + @Override + public List zRevRangeByScoreWithScores(final String key, final String min, final String max) { + return zRevRangeByScoreWithScores(SafeEncoder.encode(key), Double.parseDouble(min), Double.parseDouble(max)); + } + + @Deprecated + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max) { + return zRevRangeByScoreWithScores(key, NumberUtils.bytes2double(min), NumberUtils.bytes2double(max)); + } + + @Override + public List zRevRangeByScoreWithScores(final String key, final double min, final double max, + final long offset, final long count) { + return zRevRangeByScoreWithScores(SafeEncoder.encode(key), min, max, offset, count); + } + + @Deprecated + @Override + public List zRevRangeByScoreWithScores(final String key, final String min, final String max, + final long offset, final long count) { + return zRevRangeByScoreWithScores(SafeEncoder.encode(key), Double.parseDouble(min), Double.parseDouble(max), + offset, count); + } + + @Deprecated + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max, + final long offset, final long count) { + return zRevRangeByScoreWithScores(key, NumberUtils.bytes2double(min), NumberUtils.bytes2double(max), offset, + count); + } + + @Override + public Long zRevRank(final String key, final String member) { + return zRevRank(SafeEncoder.encode(key), SafeEncoder.encode(member)); + } + + + @Override + public ScanResult> zScan(final String key, final long cursor) { + return zScan(key, Long.toString(cursor)); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor) { + return zScan(key, NumberUtils.long2bytes(cursor)); + } + + @Override + public ScanResult> zScan(final String key, final long cursor, final String pattern) { + return zScan(key, Long.toString(cursor), pattern); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor, final byte[] pattern) { + return zScan(key, NumberUtils.long2bytes(cursor), pattern); + } + + @Override + public ScanResult> zScan(final String key, final long cursor, final long count) { + return zScan(key, Long.toString(cursor), Long.toString(count)); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor, final long count) { + return zScan(key, NumberUtils.long2bytes(cursor), NumberUtils.long2bytes(count)); + } + + @Override + public ScanResult> zScan(final String key, final long cursor, final String pattern, final long count) { + return zScan(key, Long.toString(cursor), pattern, count); + } + + @Override + public ScanResult> zScan(final byte[] key, final long cursor, final byte[] pattern, final long count) { + return zScan(key, NumberUtils.long2bytes(cursor), pattern, count); + } + + @Override + public Double zScore(final String key, final String member) { + return zScore(SafeEncoder.encode(key), SafeEncoder.encode(member)); + } + + @Override + public Long zUnionStore(final String destKey, final String... keys) { + return zUnionStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys)); + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate) { + return zUnionStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys), aggregate); + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final double... weights) { + return zUnionStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys), weights); + } + + @Override + public Long zUnionStore(final String destKey, final String[] keys, final Aggregate aggregate, + final double... weights) { + return zUnionStore(SafeEncoder.encode(destKey), SafeEncoder.encode(keys), aggregate, weights); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractStreamOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractStreamOperations.java new file mode 100644 index 000000000..37892b8a5 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractStreamOperations.java @@ -0,0 +1,272 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.StreamOperations; +import com.buession.redis.core.Stream; +import com.buession.redis.core.StreamConsumer; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import com.buession.redis.core.StreamGroup; +import com.buession.redis.core.StreamPending; +import com.buession.redis.core.StreamPendingSummary; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.XReadArgs; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce Stream 命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractStreamOperations extends AbstractLettuceRedisOperations + implements StreamOperations { + + public AbstractStreamOperations(final C client) { + super(client); + } + + @Override + public Long xAck(final String key, final String groupName, final StreamEntryId... ids) { + return xAck(SafeEncoder.encode(key), SafeEncoder.encode(groupName), ids); + } + + @Override + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash) { + return xAdd(SafeEncoder.encode(key), id, Converters.mapStringToBinary().convert(hash)); + } + + @Override + public StreamEntryId xAdd(final String key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + return xAdd(SafeEncoder.encode(key), id, Converters.mapStringToBinary().convert(hash), + xAddArgument); + } + + @Override + public List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId... ids) { + return xClaim(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), + minIdleTime, ids); + } + + @Override + public List xClaim(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + return xClaim(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), + minIdleTime, ids, xClaimArgument); + } + + @Override + public List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId... ids) { + return xClaimJustId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), + minIdleTime, ids); + } + + @Override + public List xClaimJustId(final String key, final String groupName, final String consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + return xClaimJustId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), + minIdleTime, ids, xClaimArgument); + } + + @Override + public Long xDel(final String key, final StreamEntryId... ids) { + return xDel(SafeEncoder.encode(key), ids); + } + + @Override + public Status xGroupCreate(final String key, final String groupName, final StreamEntryId id, + final boolean makeStream) { + return xGroupCreate(SafeEncoder.encode(key), SafeEncoder.encode(groupName), id, makeStream); + } + + @Override + public Long xGroupDelConsumer(final String key, final String groupName, final String consumerName) { + return xGroupDelConsumer(SafeEncoder.encode(key), SafeEncoder.encode(groupName), + SafeEncoder.encode(consumerName)); + } + + @Override + public Status xGroupDestroy(final String key, final String groupName) { + return xGroupDestroy(SafeEncoder.encode(key), SafeEncoder.encode(groupName)); + } + + @Override + public Status xGroupSetId(final String key, final String groupName, final StreamEntryId id) { + return xGroupSetId(SafeEncoder.encode(key), SafeEncoder.encode(groupName), id); + } + + @Override + public List xInfoConsumers(final String key, final String groupName) { + return xInfoConsumers(SafeEncoder.encode(key), SafeEncoder.encode(groupName)); + } + + @Override + public List xInfoGroups(final String key) { + return xInfoGroups(SafeEncoder.encode(key)); + } + + @Override + public Stream xInfoStream(final String key) { + return xInfoStream(SafeEncoder.encode(key)); + } + + @Override + public StreamFull xInfoStream(final String key, final boolean full) { + return xInfoStream(SafeEncoder.encode(key), full); + } + + @Override + public StreamFull xInfoStream(final String key, final boolean full, final long count) { + return xInfoStream(SafeEncoder.encode(key), full, count); + } + + @Override + public Long xLen(final String key) { + return xLen(SafeEncoder.encode(key)); + } + + @Override + public StreamPendingSummary xPending(final String key, final String groupName) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName)); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime); + } + + @Override + public List xPending(final String key, final String groupName, final StreamEntryId start, + final StreamEntryId end, final long count) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), start, end, count); + } + + @Override + public List xPending(final String key, final String groupName, final String consumerName) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName)); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final long count) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime, start, end, count); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final String consumerName) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime, + SafeEncoder.encode(consumerName)); + } + + @Override + public List xPending(final String key, final String groupName, final StreamEntryId start, + final StreamEntryId end, final long count, final String consumerName) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), start, end, count, + SafeEncoder.encode(consumerName)); + } + + @Override + public List xPending(final String key, final String groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final long count, + final String consumerName) { + return xPending(SafeEncoder.encode(key), SafeEncoder.encode(groupName), minIdleTime, start, end, count, + SafeEncoder.encode(consumerName)); + } + + @Override + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end) { + return xRange(SafeEncoder.encode(key), start, end); + } + + @Override + public List xRange(final String key, final StreamEntryId start, final StreamEntryId end, + final long count) { + return xRange(SafeEncoder.encode(key), start, end, count); + } + + @Override + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start) { + return xRevRange(SafeEncoder.encode(key), end, start); + } + + @Override + public List xRevRange(final String key, final StreamEntryId end, final StreamEntryId start, + final long count) { + return xRevRange(SafeEncoder.encode(key), end, start, count); + } + + @Override + public Long xTrim(final String key, final XTrimArgument xTrimArgument) { + return xTrim(SafeEncoder.encode(key), xTrimArgument); + } + + @Override + public Long xTrim(final String key, final XTrimArgument xTrimArgument, final long limit) { + return xTrim(SafeEncoder.encode(key), xTrimArgument, limit); + } + + @SuppressWarnings({"unchecked"}) + protected XReadArgs.StreamOffset[] createStreamOffsetFromStreamEntryIdMap(final Map streams) { + final XReadArgs.StreamOffset[] streamOffsets = new XReadArgs.StreamOffset[streams.size()]; + int i = 0; + + for(Map.Entry e : streams.entrySet()){ + streamOffsets[i++] = XReadArgs.StreamOffset.from(SafeEncoder.encode(e.getKey()), e.getValue().toString()); + } + + return streamOffsets; + } + + @SuppressWarnings({"unchecked"}) + protected XReadArgs.StreamOffset[] createStreamOffsetFromBinaryStreamEntryIdMap(final Map streams) { + final XReadArgs.StreamOffset[] streamOffsets = new XReadArgs.StreamOffset[streams.size()]; + int i = 0; + + for(Map.Entry e : streams.entrySet()){ + streamOffsets[i++] = XReadArgs.StreamOffset.from(e.getKey(), e.getValue().toString()); + } + + return streamOffsets; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractStringOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractStringOperations.java new file mode 100644 index 000000000..4304f3f3f --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractStringOperations.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.StringOperations; +import com.buession.redis.utils.SafeEncoder; + +/** + * Lettuce 字符串命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractStringOperations extends AbstractLettuceRedisOperations + implements StringOperations { + + public AbstractStringOperations(final C client) { + super(client); + } + + @Override + public Long append(final String key, final String value) { + return append(SafeEncoder.encode(key), SafeEncoder.encode(value)); + } + + @Override + public Long incr(final String key) { + return incr(SafeEncoder.encode(key)); + } + + @Override + public Long incrBy(final String key, final long value) { + return incrBy(SafeEncoder.encode(key), value); + } + + @Override + public Double incrByFloat(final String key, final double value) { + return incrByFloat(SafeEncoder.encode(key), value); + } + + @Override + public Long decr(final String key) { + return decr(SafeEncoder.encode(key)); + } + + @Override + public Long decrBy(final String key, final long value) { + return decrBy(SafeEncoder.encode(key), value); + } + + @Override + public Status pSetEx(final String key, final String value, final int lifetime) { + return pSetEx(SafeEncoder.encode(key), SafeEncoder.encode(value), lifetime); + } + + @Override + public Status set(final String key, final String value) { + return set(SafeEncoder.encode(key), SafeEncoder.encode(value)); + } + + @Override + public Status set(final String key, final String value, final SetArgument setArgument) { + return set(SafeEncoder.encode(key), SafeEncoder.encode(value), setArgument); + } + + @Override + public Status setEx(final String key, final String value, final int lifetime) { + return setEx(SafeEncoder.encode(key), SafeEncoder.encode(value), lifetime); + } + + @Override + public Status setNx(final String key, final String value) { + return setNx(SafeEncoder.encode(key), SafeEncoder.encode(value)); + } + + @Override + public Long setRange(final String key, final long offset, final String value) { + return setRange(SafeEncoder.encode(key), offset, SafeEncoder.encode(value)); + } + + @Override + public String getRange(final String key, final long start, final long end) { + return SafeEncoder.encode(getRange(SafeEncoder.encode(key), start, end)); + } + + @Override + public Long strlen(final String key) { + return strlen(SafeEncoder.encode(key)); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractTransactionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractTransactionOperations.java new file mode 100644 index 000000000..f5d44804d --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/AbstractTransactionOperations.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceRedisClient; +import com.buession.redis.client.operations.TransactionOperations; +import com.buession.redis.utils.SafeEncoder; + +/** + * Lettuce 事务命令操作抽象类 + * + * @param + * Redis Client {@link LettuceRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractTransactionOperations + extends AbstractLettuceRedisOperations implements TransactionOperations { + + public AbstractTransactionOperations(final C client) { + super(client); + } + + @Override + public Status watch(final String... keys) { + return watch(SafeEncoder.encode(keys)); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceBitMapOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceBitMapOperations.java new file mode 100644 index 000000000..ba8a15f93 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceBitMapOperations.java @@ -0,0 +1,276 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.BitCountOption; +import com.buession.redis.core.BitOperation; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.lettuce.LettuceBitFieldArgs; +import io.lettuce.core.BitFieldArgs; + +import java.util.List; + +/** + * Lettuce 单机模式 BitMap 命令操作抽象类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceBitMapOperations extends AbstractBitMapOperations { + + public LettuceBitMapOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Long bitCount(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end, final BitCountOption bitCountOption) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end) + .put("bitCountOption", bitCountOption); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List bitField(final byte[] key, final BitFieldArgument argument) { + final CommandArguments args = CommandArguments.create("key", key).put("arguments", argument); + final BitFieldArgs bitFieldArgs = LettuceBitFieldArgs.from(argument); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.BITFIELD, + (cmd)->cmd.bitfield(key, bitFieldArgs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.BITFIELD, + (cmd)->cmd.bitfield(key, bitFieldArgs), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.BITFIELD, (cmd)->cmd.bitfield(key, bitFieldArgs), + (v)->v) + .run(args); + } + } + + @Override + public List bitFieldRo(final String key, final String... arguments) { + final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); + return bitFieldRo(args); + } + + @Override + public List bitFieldRo(final byte[] key, final byte[]... arguments) { + final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); + return bitFieldRo(args); + } + + @Override + public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("operation", operation).put("destKey", destKey) + .put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.BITOP, (cmd)->{ + if(operation == BitOperation.AND){ + return cmd.bitopAnd(destKey, keys); + }else if(operation == BitOperation.OR){ + return cmd.bitopOr(destKey, keys); + }else if(operation == BitOperation.NOT){ + return cmd.bitopNot(destKey, keys[0]); + }else if(operation == BitOperation.XOR){ + return cmd.bitopXor(destKey, keys); + }else{ + return null; + } + }, (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.BITOP, (cmd)->{ + if(operation == BitOperation.AND){ + return cmd.bitopAnd(destKey, keys); + }else if(operation == BitOperation.OR){ + return cmd.bitopOr(destKey, keys); + }else if(operation == BitOperation.NOT){ + return cmd.bitopNot(destKey, keys[0]); + }else if(operation == BitOperation.XOR){ + return cmd.bitopXor(destKey, keys); + }else{ + return null; + } + }, (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.BITOP, (cmd)->{ + if(operation == BitOperation.AND){ + return cmd.bitopAnd(destKey, keys); + }else if(operation == BitOperation.OR){ + return cmd.bitopOr(destKey, keys); + }else if(operation == BitOperation.NOT){ + return cmd.bitopNot(destKey, keys[0]); + }else if(operation == BitOperation.XOR){ + return cmd.bitopXor(destKey, keys); + }else{ + return null; + } + }, (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("start", start) + .put("end", end); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, start, end), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value, start, end), + (v)->v) + .run(args); + } + } + + @Override + public Boolean getBit(final byte[] key, final long offset) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), + oneBooleanConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), + oneBooleanConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), + oneBooleanConverter) + .run(args); + } + } + + @Override + public Boolean setBit(final byte[] key, final long offset, final boolean value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + final int iValue = value ? 1 : 0; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SETBIT, + (cmd)->cmd.setbit(key, offset, iValue), oneBooleanConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SETBIT, + (cmd)->cmd.setbit(key, offset, iValue), oneBooleanConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SETBIT, (cmd)->cmd.setbit(key, offset, iValue), + oneBooleanConverter) + .run(args); + } + } + + private List bitFieldRo(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, ProtocolCommand.BITFIELD_RO) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, ProtocolCommand.BITFIELD_RO) + .run(args); + }else{ + return new LettuceCommand, List>(client, ProtocolCommand.BITFIELD_RO) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterBitMapOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterBitMapOperations.java new file mode 100644 index 000000000..5fba0a9bf --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterBitMapOperations.java @@ -0,0 +1,283 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.BitCountOption; +import com.buession.redis.core.BitOperation; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.lettuce.LettuceBitFieldArgs; +import io.lettuce.core.BitFieldArgs; + +import java.util.List; + +/** + * Lettuce 集群模式 BitMap 命令操作抽象类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterBitMapOperations extends AbstractBitMapOperations { + + public LettuceClusterBitMapOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Long bitCount(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key), (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end, final BitCountOption bitCountOption) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end) + .put("bitCountOption", bitCountOption); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.BITCOUNT, + (cmd)->cmd.bitcount(key, start, end), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.BITCOUNT, (cmd)->cmd.bitcount(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public List bitField(final byte[] key, final BitFieldArgument argument) { + final CommandArguments args = CommandArguments.create("key", key).put("arguments", argument); + final BitFieldArgs bitFieldArgs = LettuceBitFieldArgs.from(argument); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.BITFIELD, + (cmd)->cmd.bitfield(key, bitFieldArgs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.BITFIELD, + (cmd)->cmd.bitfield(key, bitFieldArgs), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.BITFIELD, + (cmd)->cmd.bitfield(key, bitFieldArgs), + (v)->v) + .run(args); + } + } + + @Override + public List bitFieldRo(final String key, final String... arguments) { + final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); + return bitFieldRo(args); + } + + @Override + public List bitFieldRo(final byte[] key, final byte[]... arguments) { + final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); + return bitFieldRo(args); + } + + @Override + public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("operation", operation).put("destKey", destKey) + .put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.BITOP, (cmd)->{ + if(operation == BitOperation.AND){ + return cmd.bitopAnd(destKey, keys); + }else if(operation == BitOperation.OR){ + return cmd.bitopOr(destKey, keys); + }else if(operation == BitOperation.NOT){ + return cmd.bitopNot(destKey, keys[0]); + }else if(operation == BitOperation.XOR){ + return cmd.bitopXor(destKey, keys); + }else{ + return null; + } + }, (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.BITOP, (cmd)->{ + if(operation == BitOperation.AND){ + return cmd.bitopAnd(destKey, keys); + }else if(operation == BitOperation.OR){ + return cmd.bitopOr(destKey, keys); + }else if(operation == BitOperation.NOT){ + return cmd.bitopNot(destKey, keys[0]); + }else if(operation == BitOperation.XOR){ + return cmd.bitopXor(destKey, keys); + }else{ + return null; + } + }, (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.BITOP, (cmd)->{ + if(operation == BitOperation.AND){ + return cmd.bitopAnd(destKey, keys); + }else if(operation == BitOperation.OR){ + return cmd.bitopOr(destKey, keys); + }else if(operation == BitOperation.NOT){ + return cmd.bitopNot(destKey, keys[0]); + }else if(operation == BitOperation.XOR){ + return cmd.bitopXor(destKey, keys); + }else{ + return null; + } + }, (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.BITPOS, (cmd)->cmd.bitpos(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("start", start) + .put("end", end); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, start, end), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.BITPOS, + (cmd)->cmd.bitpos(key, value, start, end), + (v)->v) + .run(args); + } + } + + @Override + public Boolean getBit(final byte[] key, final long offset) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), + oneBooleanConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.GETBIT, + (cmd)->cmd.getbit(key, offset), oneBooleanConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.GETBIT, (cmd)->cmd.getbit(key, offset), + oneBooleanConverter) + .run(args); + } + } + + @Override + public Boolean setBit(final byte[] key, final long offset, final boolean value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + final int iValue = value ? 1 : 0; + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SETBIT, + (cmd)->cmd.setbit(key, offset, iValue), oneBooleanConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SETBIT, + (cmd)->cmd.setbit(key, offset, iValue), oneBooleanConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SETBIT, (cmd)->cmd.setbit(key, offset, iValue), + oneBooleanConverter) + .run(args); + } + } + + private List bitFieldRo(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, ProtocolCommand.BITFIELD_RO) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, ProtocolCommand.BITFIELD_RO) + .run(args); + }else{ + return new LettuceClusterCommand, List>(client, ProtocolCommand.BITFIELD_RO) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterClusterOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterClusterOperations.java new file mode 100644 index 000000000..e9b5619a4 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterClusterOperations.java @@ -0,0 +1,564 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.BumpEpoch; +import com.buession.redis.core.ClusterFailoverOption; +import com.buession.redis.core.ClusterInfo; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.ClusterResetOption; +import com.buession.redis.core.ClusterSetSlotOption; +import com.buession.redis.core.ClusterSlot; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.response.ClusterReplicasConverter; +import com.buession.redis.core.internal.convert.response.BumpEpochConverter; +import com.buession.redis.core.internal.convert.response.ClusterInfoConverter; +import com.buession.redis.core.internal.convert.response.ClusterNodeConverter; +import com.buession.redis.core.internal.convert.response.ClusterNodesConverter; +import com.buession.redis.core.internal.convert.response.ClusterSlotConverter; + +import java.util.List; + +/** + * Lettuce 集群模式集群命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterClusterOperations extends AbstractClusterOperations { + + public LettuceClusterClusterOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public String clusterMyId() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_MY_ID, (cmd)->cmd.clusterMyId(), + (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_MY_ID, + (cmd)->cmd.clusterMyId(), (v)->v) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_MY_ID, (cmd)->cmd.clusterMyId(), (v)->v) + .run(); + } + } + + @Override + public Status clusterAddSlots(final int... slots) { + final CommandArguments args = CommandArguments.create(slots); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_ADDSLOTS, + (cmd)->cmd.clusterAddSlots(slots), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_ADDSLOTS, + (cmd)->cmd.clusterAddSlots(slots), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_ADDSLOTS, + (cmd)->cmd.clusterAddSlots(slots), + okStatusConverter) + .run(args); + } + } + + @Override + public List clusterSlots() { + final ListConverter listClusterSlotConverter = ClusterSlotConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_SLOTS, (cmd)->cmd.clusterSlots(), + listClusterSlotConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_SLOTS, + (cmd)->cmd.clusterSlots(), listClusterSlotConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_SLOTS, (cmd)->cmd.clusterSlots(), + listClusterSlotConverter) + .run(); + } + } + + @Override + public Integer clusterCountFailureReports(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS, + (cmd)->cmd.clusterCountFailureReports(nodeId), Long::intValue) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS, + (cmd)->cmd.clusterCountFailureReports(nodeId), Long::intValue) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS, + (cmd)->cmd.clusterCountFailureReports(nodeId), Long::intValue) + .run(args); + } + } + + @Override + public Long clusterCountKeysInSlot(final int slot) { + final CommandArguments args = CommandArguments.create(slot); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + } + } + + @Override + public Status clusterDelSlots(final int... slots) { + final CommandArguments args = CommandArguments.create(slots); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_DELSLOTS, + (cmd)->cmd.clusterDelSlots(slots), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_DELSLOTS, + (cmd)->cmd.clusterDelSlots(slots), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_DELSLOTS, + (cmd)->cmd.clusterDelSlots(slots), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterFlushSlots() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_FLUSHSLOTS, + (cmd)->cmd.clusterFlushslots(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_FLUSHSLOTS, + (cmd)->cmd.clusterFlushslots(), okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_FLUSHSLOTS, + (cmd)->cmd.clusterFlushslots(), okStatusConverter) + .run(); + } + } + + @Override + public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption) { + final CommandArguments args = CommandArguments.create(clusterFailoverOption); + final boolean force = ClusterFailoverOption.FORCE == clusterFailoverOption; + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_FAILOVER, + (cmd)->cmd.clusterFailover(force), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_FAILOVER, + (cmd)->cmd.clusterFailover(force), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_FAILOVER, + (cmd)->cmd.clusterFailover(force), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterForget(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_FORGET, + (cmd)->cmd.clusterForget(nodeId), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_FORGET, + (cmd)->cmd.clusterForget(nodeId), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_FORGET, (cmd)->cmd.clusterForget(nodeId), + okStatusConverter) + .run(args); + } + } + + @Override + public List clusterGetKeysInSlot(final int slot, final long count) { + final CommandArguments args = CommandArguments.create("slot", slot).put("count", count); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, (int) count), binaryToStringListConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, (int) count), binaryToStringListConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, (int) count), binaryToStringListConverter) + .run(args); + } + } + + @Override + public Long clusterKeySlot(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterKeyslot(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterKeyslot(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterKeyslot(key), (v)->v) + .run(args); + } + } + + @Override + public ClusterInfo clusterInfo() { + final ClusterInfoConverter clusterInfoConverter = new ClusterInfoConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_INFO, (cmd)->cmd.clusterInfo(), + clusterInfoConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_INFO, + (cmd)->cmd.clusterInfo(), clusterInfoConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_INFO, (cmd)->cmd.clusterInfo(), + clusterInfoConverter) + .run(); + } + } + + @Override + public Status clusterMeet(final String ip, final int port) { + final CommandArguments args = CommandArguments.create(ip).add(port); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_MEET, + (cmd)->cmd.clusterMeet(ip, port), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_MEET, + (cmd)->cmd.clusterMeet(ip, port), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_MEET, (cmd)->cmd.clusterMeet(ip, port), + okStatusConverter) + .run(args); + } + } + + @Override + public List clusterNodes() { + final ClusterNodesConverter clusterNodesConverter = new ClusterNodesConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_NODES, (cmd)->cmd.clusterNodes(), + clusterNodesConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_NODES, + (cmd)->cmd.clusterNodes(), clusterNodesConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_NODES, (cmd)->cmd.clusterNodes(), + clusterNodesConverter) + .run(); + } + } + + @Override + public List clusterSlaves(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + final ListConverter listClusterNodeConverter = ClusterNodeConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_SLAVES, + (cmd)->cmd.clusterSlaves(nodeId), listClusterNodeConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_SLAVES, + (cmd)->cmd.clusterSlaves(nodeId), listClusterNodeConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_SLAVES, (cmd)->cmd.clusterSlaves(nodeId), + listClusterNodeConverter) + .run(args); + } + } + + @Override + public List clusterReplicas(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + final ClusterReplicasConverter clusterReplicasConverter = new ClusterReplicasConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_REPLICAS, + (cmd)->cmd.clusterReplicate(nodeId), clusterReplicasConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_REPLICAS, + (cmd)->cmd.clusterReplicate(nodeId), clusterReplicasConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_REPLICAS, + (cmd)->cmd.clusterReplicate(nodeId), clusterReplicasConverter) + .run(args); + } + } + + @Override + public Status clusterReplicate(final String nodeId) { + final CommandArguments args = CommandArguments.create(nodeId); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_REPLICATE, + (cmd)->cmd.clusterReplicate(nodeId), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_REPLICATE, + (cmd)->cmd.clusterReplicate(nodeId), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_REPLICATE, + (cmd)->cmd.clusterReplicate(nodeId), okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterReset(final ClusterResetOption clusterResetOption) { + final CommandArguments args = CommandArguments.create(clusterResetOption); + final boolean hard = ClusterResetOption.HARD == clusterResetOption; + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_RESET, + (cmd)->cmd.clusterReset(hard), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_RESET, + (cmd)->cmd.clusterReset(hard), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_RESET, (cmd)->cmd.clusterReset(hard), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterSaveConfig() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_SAVECONFIG, + (cmd)->cmd.clusterSaveconfig(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_SAVECONFIG, + (cmd)->cmd.clusterSaveconfig(), okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_SAVECONFIG, + (cmd)->cmd.clusterSaveconfig(), okStatusConverter) + .run(); + } + } + + @Override + public Status clusterSetConfigEpoch(final long configEpoch) { + final CommandArguments args = CommandArguments.create("configEpoch", configEpoch); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + } + } + + @Override + public KeyValue clusterBumpEpoch() { + final BumpEpochConverter bumpEpochConverter = new BumpEpochConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_BUMPEPOCH, + (cmd)->cmd.clusterBumpepoch(), bumpEpochConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_BUMPEPOCH, + (cmd)->cmd.clusterBumpepoch(), bumpEpochConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_BUMPEPOCH, (cmd)->cmd.clusterBumpepoch(), + bumpEpochConverter) + .run(); + } + } + + @Override + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId) { + final CommandArguments args = CommandArguments.create("slot", slot).put("setSlotOption", setSlotOption) + .put("nodeId", nodeId); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + } + } + + @Override + public Status asking() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ASKING, (cmd)->cmd.asking(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ASKING, (cmd)->cmd.asking(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ASKING, (cmd)->cmd.asking(), okStatusConverter) + .run(); + } + } + + @Override + public Status readWrite() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.READWRITE, (cmd)->cmd.readWrite(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.READWRITE, (cmd)->cmd.readWrite(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.READWRITE, (cmd)->cmd.readWrite(), + okStatusConverter) + .run(); + } + } + + @Override + public Status readOnly() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.READONLY, (cmd)->cmd.readOnly(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.READONLY, (cmd)->cmd.readOnly(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.READONLY, (cmd)->cmd.readOnly(), + okStatusConverter) + .run(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterConnectionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterConnectionOperations.java new file mode 100644 index 000000000..610e3061c --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterConnectionOperations.java @@ -0,0 +1,428 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.Client; +import com.buession.redis.core.ClientReply; +import com.buession.redis.core.ClientType; +import com.buession.redis.core.ClientUnblockType; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.params.ClientUnblockTypeConverter; +import com.buession.redis.core.internal.convert.response.ClientConverter; +import com.buession.redis.core.internal.convert.response.PingResultConverter; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.UnblockType; +import io.lettuce.core.codec.ByteArrayCodec; +import io.lettuce.core.output.StatusOutput; +import io.lettuce.core.protocol.CommandArgs; +import io.lettuce.core.protocol.CommandKeyword; +import io.lettuce.core.protocol.CommandType; + +import java.util.List; + +/** + * Lettuce 集群模式连接命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterConnectionOperations extends AbstractConnectionOperations { + + public LettuceClusterConnectionOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Status auth(final String user, final String password) { + final CommandArguments args = CommandArguments.create(user).add(password); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.AUTH, + (cmd)->client.getConnection().getStatefulRedisClusterConnection().async().dispatch(CommandType.AUTH, + new StatusOutput<>(ByteArrayCodec.INSTANCE), + new CommandArgs<>(ByteArrayCodec.INSTANCE).add(password)), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.AUTH, + (cmd)->client.getConnection().getStatefulRedisClusterConnection().async().dispatch(CommandType.AUTH, + new StatusOutput<>(ByteArrayCodec.INSTANCE), + new CommandArgs<>(ByteArrayCodec.INSTANCE).add(password)), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.AUTH, (cmd)->cmd.auth(password), + okStatusConverter) + .run(args); + } + } + + @Override + public Status auth(final String password) { + final CommandArguments args = CommandArguments.create(password); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.AUTH, + (cmd)->client.getConnection().getStatefulRedisClusterConnection().async().dispatch(CommandType.AUTH, + new StatusOutput<>(ByteArrayCodec.INSTANCE), + new CommandArgs<>(ByteArrayCodec.INSTANCE).add(password)), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.AUTH, + (cmd)->client.getConnection().getStatefulRedisClusterConnection().async().dispatch(CommandType.AUTH, + new StatusOutput<>(ByteArrayCodec.INSTANCE), + new CommandArgs<>(ByteArrayCodec.INSTANCE).add(password)), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.AUTH, (cmd)->cmd.auth(password), + okStatusConverter) + .run(args); + } + } + + @Override + public String echo(final String str) { + final CommandArguments args = CommandArguments.create(str); + final byte[] msg = SafeEncoder.encode(str); + + return echo(msg, SafeEncoder::encode, args); + } + + @Override + public byte[] echo(final byte[] str) { + final CommandArguments args = CommandArguments.create(str); + return echo(str, (v)->v, args); + } + + @Override + public Status ping() { + final PingResultConverter pingResultConverter = new PingResultConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.ping(), + pingResultConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.ping(), + pingResultConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.ping(), pingResultConverter) + .run(); + } + } + + @Override + public Status reset() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.RESET, + (cmd)->client.getConnection().getStatefulRedisClusterConnection().async() + .dispatch(CommandKeyword.RESET, + new StatusOutput<>(ByteArrayCodec.INSTANCE), + new CommandArgs<>(ByteArrayCodec.INSTANCE)), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.RESET, + (cmd)->client.getConnection().getStatefulRedisClusterConnection().async() + .dispatch(CommandKeyword.RESET, + new StatusOutput<>(ByteArrayCodec.INSTANCE), + new CommandArgs<>(ByteArrayCodec.INSTANCE)), okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.RESET, (cmd)->{ + cmd.reset(); + return Status.SUCCESS; + }, (v)->v) + .run(); + } + } + + @Override + public Status quit() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.QUIT, (cmd)->cmd.quit(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.QUIT, (cmd)->cmd.quit(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.QUIT, (cmd)->cmd.quit(), okStatusConverter) + .run(); + } + } + + @Override + public Status select(final int db) { + final CommandArguments args = CommandArguments.create(db); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.SELECT) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.SELECT) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.SELECT) + .run(args); + } + } + + @Override + public Status clientCaching(final boolean isYes) { + final CommandArguments args = CommandArguments.create("isYes", isYes); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + } + } + + @Override + public Long clientId() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLIENT_ID, (cmd)->cmd.clientId(), (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLIENT_ID, (cmd)->cmd.clientId(), + (v)->v) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLIENT_ID, (cmd)->cmd.clientId(), (v)->v) + .run(); + } + } + + @Override + public Status clientSetName(final byte[] name) { + final CommandArguments args = CommandArguments.create("name", name); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLIENT_SETNAME, (cmd)->cmd.clientSetname(name), + okStatusConverter) + .run(args); + } + } + + @Override + public String clientGetName() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLIENT_GETNAME, + (cmd)->cmd.clientGetname(), SafeEncoder::encode) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLIENT_GETNAME, + (cmd)->cmd.clientGetname(), SafeEncoder::encode) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLIENT_GETNAME, (cmd)->cmd.clientGetname(), + SafeEncoder::encode) + .run(); + } + } + + @Override + public Integer clientGetRedir() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + } + } + + @Override + public List clientList() { + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + } + } + + @Override + public List clientList(final ClientType clientType) { + final CommandArguments args = CommandArguments.create("clientType", clientType); + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(args); + } + } + + @Override + public Client clientInfo() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.CLIENT_INFO) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.CLIENT_INFO) + .run(); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.CLIENT_INFO) + .run(); + } + } + + @Override + public Status clientPause(final int timeout) { + final CommandArguments args = CommandArguments.create("timeout", timeout); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLIENT_PAUSE, (cmd)->cmd.clientPause(timeout), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clientReply(final ClientReply option) { + final CommandArguments args = CommandArguments.create("option", option); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + } + } + + @Override + public Status clientKill(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + final String addr = host + ':' + port; + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLIENT_KILL, (cmd)->cmd.clientKill(addr), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(addr), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLIENT_KILL, (cmd)->cmd.clientKill(addr), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clientUnblock(final int clientId) { + final CommandArguments args = CommandArguments.create("clientId", clientId); + return clientUnblock(clientId, UnblockType.ERROR, args); + } + + @Override + public Status clientUnblock(final int clientId, final ClientUnblockType type) { + final CommandArguments args = CommandArguments.create("clientId", clientId).put("type", type); + final UnblockType unblockType = (new ClientUnblockTypeConverter()).convert(type); + + return clientUnblock(clientId, unblockType, args); + } + + private V echo(final byte[] str, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.echo(str), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.echo(str), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.echo(str), converter) + .run(args); + } + } + + private Status clientUnblock(final int clientId, final UnblockType unblockType, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CLIENT_KILL, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CLIENT_KILL, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CLIENT_KILL, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterGenericOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterGenericOperations.java new file mode 100644 index 000000000..c7bd239b2 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterGenericOperations.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.KeyValue; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; + +/** + * Lettuce 集群模式一般命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterGenericOperations extends AbstractGenericOperations { + + public LettuceClusterGenericOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Long wait(final int replicas, final int timeout) { + final CommandArguments args = CommandArguments.create(replicas).add(timeout); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.WAIT, + (cmd)->cmd.waitForReplication(replicas, timeout), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.WAIT, + (cmd)->cmd.waitForReplication(replicas, timeout), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.WAIT, + (cmd)->cmd.waitForReplication(replicas, timeout), (v)->v) + .run(args); + } + } + + @Override + public KeyValue waitOf(final int locals, final int replicas, final int timeout) { + final CommandArguments args = CommandArguments.create(locals).add(replicas).add(timeout); + return notCommand(client, ProtocolCommand.WAITOF, args); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterGeoOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterGeoOperations.java new file mode 100644 index 000000000..4c5c98549 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterGeoOperations.java @@ -0,0 +1,414 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.builder.ListBuilder; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.SetListConverter; +import com.buession.lang.Geo; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.params.GeoUnitConverter; +import com.buession.redis.core.internal.convert.lettuce.response.GeoCoordinateConverter; +import com.buession.redis.core.internal.convert.lettuce.response.GeoRadiusGeneralResultConverter; +import com.buession.redis.core.internal.convert.lettuce.response.GeoRadiusResponseConverter; +import com.buession.redis.core.internal.lettuce.LettuceGeoArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.GeoArgs; +import io.lettuce.core.GeoCoordinates; +import io.lettuce.core.GeoWithin; +import io.lettuce.core.Value; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 集群模式地理位置命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterGeoOperations extends AbstractGeoOperations { + + public LettuceClusterGeoOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member) + .put("longitude", longitude).put("latitude", latitude); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create("key", key).put("memberCoordinates", memberCoordinates); + return geoAdd(key, memberCoordinates, args); + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create("key", key).put("memberCoordinates", memberCoordinates); + return geoAdd(key, memberCoordinates, args); + } + + @Override + public List geoHash(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + final byte[] bKey = SafeEncoder.encode(key); + final byte[][] bMembers = SafeEncoder.encode(members); + final ListConverter, String> listConverter = new ListConverter<>(Value::getValue); + + return geoHash(bKey, bMembers, listConverter, args); + } + + @Override + public List geoHash(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + final ListConverter, byte[]> listConverter = new ListConverter<>( + (v)->SafeEncoder.encode(v.getValue())); + + return geoHash(key, members, listConverter, args); + } + + @Override + public List geoPos(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.GEOPOS, + (cmd)->cmd.geopos(key, members), listGeoCoordinateConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2) { + final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) + .put("member2", member2); + return geoDist(key, member1, member2, GeoArgs.Unit.m, args); + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) + .put("member2", member2).put("unit", unit); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + + return geoDist(key, member1, member2, geoArgsUnit, args); + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final SetListConverter setListGeoRadiusGeneralResultConverter = + GeoRadiusGeneralResultConverter.setListConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + } + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit) + .put("geoRadiusArgument", geoRadiusArgument); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final GeoArgs geoArgs = LettuceGeoArgs.from(geoRadiusArgument); + final ListConverter, GeoRadius> listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit); + return geoRadiusRo(args); + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit); + return geoRadiusRo(args); + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit) + .put("geoRadiusArgument", geoRadiusArgument); + return geoRadiusRo(args); + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit) + .put("geoRadiusArgument", geoRadiusArgument); + return geoRadiusRo(args); + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final SetListConverter setListGeoRadiusGeneralResultConverter = + GeoRadiusGeneralResultConverter.setListConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final GeoArgs geoArgs = LettuceGeoArgs.from(geoRadiusArgument); + final ListConverter, GeoRadius> listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit); + return geoRadiusByMemberRo(args); + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit); + return geoRadiusByMemberRo(args); + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); + return geoRadiusByMemberRo(args); + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); + return geoRadiusByMemberRo(args); + } + + @Override + protected Long geoAdd(final byte[] key, final ListBuilder lngLatMemberBuilder, + final CommandArguments args) { + final Object[] lngLatMembers = lngLatMemberBuilder.build().toArray(new Object[]{}); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, lngLatMembers), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, lngLatMembers), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, lngLatMembers), + (v)->v) + .run(args); + } + } + + private List geoHash(final byte[] key, final byte[][] members, + final ListConverter, V> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.GEOHASH, + (cmd)->cmd.geohash(key, members), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.GEOHASH, + (cmd)->cmd.geohash(key, members), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), + converter) + .run(args); + } + } + + private Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoArgs.Unit unit, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, unit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, unit), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, unit), (v)->v) + .run(args); + } + } + + private List geoRadiusRo(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, + ProtocolCommand.GEORADIUS_RO) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, + ProtocolCommand.GEORADIUS_RO) + .run(args); + }else{ + return new LettuceClusterCommand, List>(client, ProtocolCommand.GEORADIUS_RO) + .run(args); + } + } + + private List geoRadiusByMemberRo(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, + ProtocolCommand.GEORADIUSBYMEMBER_RO) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, + ProtocolCommand.GEORADIUSBYMEMBER_RO) + .run(args); + }else{ + return new LettuceClusterCommand, List>(client, + ProtocolCommand.GEORADIUSBYMEMBER_RO) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterHashOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterHashOperations.java new file mode 100644 index 000000000..e2d52d003 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterHashOperations.java @@ -0,0 +1,561 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.ListSetConverter; +import com.buession.core.converter.MapConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyValue; +import io.lettuce.core.MapScanCursor; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.Value; + +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Lettuce 集群模式模式哈希表命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterHashOperations extends AbstractHashOperations { + + public LettuceClusterHashOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Long hDel(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } + } + + @Override + public Boolean hExists(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HEXISTS, + (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } + } + + @Override + public String hGet(final String key, final String field) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bField = SafeEncoder.encode(field); + + return hGet(bKey, bField, SafeEncoder::encode, args); + } + + @Override + public byte[] hGet(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field); + return hGet(key, field, (v)->v, args); + } + + @Override + public Map hGetAll(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final MapConverter binaryToStringMapConverter = Converters.mapBinaryToString(); + + return hGetAll(bKey, binaryToStringMapConverter, args); + } + + @Override + public Map hGetAll(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return hGetAll(key, (v)->v, args); + } + + @Override + public Long hIncrBy(final byte[] key, final byte[] field, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HINCRBY, + (cmd)->cmd.hincrby(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HINCRBY, + (cmd)->cmd.hincrby(key, field, value), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HINCRBY, (cmd)->cmd.hincrby(key, field, value), + (v)->v) + .run(args); + } + } + + @Override + public Double hIncrByFloat(final byte[] key, final byte[] field, final double value) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrbyfloat(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrbyfloat(key, field, value), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrbyfloat(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Set hKeys(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final ListSetConverter binaryToStringListSetConverter = + Converters.listSetBinaryToString(); + + return hKeys(bKey, binaryToStringListSetConverter, args); + } + + @Override + public Set hKeys(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return hKeys(key, HashSet::new, args); + } + + @Override + public Long hLen(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } + } + + @Override + public List hMGet(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); + final byte[] bKey = SafeEncoder.encode(key); + final byte[][] bFields = SafeEncoder.encode(fields); + final ListConverter, String> listConverter = + new ListConverter<>((v)->SafeEncoder.encode(v.getValue())); + + return hMGet(bKey, bFields, listConverter, args); + } + + @Override + public List hMGet(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); + final ListConverter, byte[]> listConverter = new ListConverter<>(Value::getValue); + + return hMGet(key, fields, listConverter, args); + } + + @Override + public Status hMSet(final byte[] key, final Map data) { + final CommandArguments args = CommandArguments.create("key", key).put("data", data); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + } + } + + @Override + public String hRandField(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + return hRandField(args); + } + + @Override + public byte[] hRandField(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return hRandField(args); + } + + @Override + public List hRandField(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return hRandField(args); + } + + @Override + public List hRandField(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return hRandField(args); + } + + @Override + public Map hRandFieldWithValues(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return hRandField(args); + } + + @Override + public Map hRandFieldWithValues(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return hRandField(args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, mapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, scanArgs, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, scanArgs, mapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, scanArgs, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, scanArgs, mapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor, final String pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, scanArgs, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, scanArgs, mapScanCursorConverter, args); + } + + @Override + public Long hSet(final byte[] key, final byte[] field, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); + final Converter converter = (v)->Boolean.TRUE.equals(v) ? 1L : 0L; + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HSET, + (cmd)->cmd.hset(key, field, value), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), + converter) + .run(args); + } + } + + @Override + public Status hSetNx(final byte[] key, final byte[] field, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HSETNX, + (cmd)->cmd.hsetnx(key, field, value), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HSETNX, + (cmd)->cmd.hsetnx(key, field, value), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Long hStrLen(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hstrlen(key, field), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HSETNX, + (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } + } + + @Override + public List hVals(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return hVals(bKey, binaryToStringListConverter, args); + } + + @Override + public List hVals(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return hVals(key, (v)->v, args); + } + + private V hGet(final byte[] key, final byte[] field, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), converter) + .run(args); + } + } + + private Map hGetAll(final byte[] key, final Converter, Map> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetall(key), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetall(key), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetall(key), converter) + .run(args); + } + } + + private Set hKeys(final byte[] key, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), converter) + .run(args); + } + } + + private List hMGet(final byte[] key, final byte[][] fields, + final Converter>, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), converter) + .run(args); + } + } + + private TV hRandField(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.HRANDFIELD) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.HRANDFIELD) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.HRANDFIELD) + .run(args); + } + } + + private ScanResult> hScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), converter) + .run(args); + } + } + + private ScanResult> hScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanArgs), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanArgs), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor, scanArgs), + converter) + .run(args); + } + } + + private List hVals(final byte[] key, final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterHyperLogLogOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterHyperLogLogOperations.java new file mode 100644 index 000000000..e117e3926 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterHyperLogLogOperations.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; + +/** + * Lettuce 集群模式 HyperLogLog 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterHyperLogLogOperations extends AbstractHyperLogLogOperations { + + public LettuceClusterHyperLogLogOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Status pfAdd(final byte[] key, final byte[]... elements) { + final CommandArguments args = CommandArguments.create("key", key).put("elements", (Object[]) elements); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PFADD, + (cmd)->cmd.pfadd(key, elements), oneStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pfMerge(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PFMERGE, + (cmd)->cmd.pfmerge(destKey, keys), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PFMERGE, + (cmd)->cmd.pfmerge(destKey, keys), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + } + } + + @Override + public Long pfCount(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfcount(keys), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfcount(keys), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterKeyOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterKeyOperations.java new file mode 100644 index 000000000..9781a4414 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterKeyOperations.java @@ -0,0 +1,928 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListSetConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.MigrateOperation; +import com.buession.redis.core.ObjectEncoding; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Type; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.convert.response.ObjectEncodingConverter; +import com.buession.redis.core.internal.convert.response.TypeConverter; +import com.buession.redis.core.internal.lettuce.LettuceMigrateArgs; +import com.buession.redis.core.internal.lettuce.LettuceRestoreArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.core.internal.lettuce.LettuceSortArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyScanCursor; +import io.lettuce.core.MigrateArgs; +import io.lettuce.core.RestoreArgs; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.SortArgs; + +import java.util.List; +import java.util.Set; + +/** + * Lettuce 集群模式 Key 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterKeyOperations extends AbstractKeyOperations { + + public LettuceClusterKeyOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Long del(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } + } + + @Override + public byte[] dump(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + } + } + + @Override + public Boolean exists(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), + (v)->v == 1L) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), + (v)->v == 1L) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v == 1L) + .run(args); + } + } + + @Override + public Long exists(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime), booleanStatusConverter) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime) + .put("expireOption", expireOption); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.expireat(key, unixTimestamp), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.expireat(key, unixTimestamp), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.expireat(key, unixTimestamp), booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PEXPIRE, + (cmd)->cmd.pexpire(key, lifetime), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.pexpireat(key, unixTimestamp), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.pexpireat(key, unixTimestamp), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.pexpireat(key, unixTimestamp), booleanStatusConverter) + .run(args); + } + } + + @Override + public Status persist(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Long ttl(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } + } + + @Override + public Long pTtl(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } + } + + @Override + public Status copy(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + return copy(args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + return copy(args); + } + + @Override + public Status copy(final String key, final String destKey, final int db) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("db", db); + return copy(args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("db", db); + return copy(args); + } + + @Override + public Status copy(final String key, final String destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("replace", replace); + return copy(args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("replace", replace); + return copy(args); + } + + @Override + public Status copy(final String key, final String destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("db", db) + .put("replace", replace); + return copy(args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("db", db) + .put("replace", replace); + return copy(args); + } + + @Override + public Status move(final byte[] key, final int db) { + final CommandArguments args = CommandArguments.create("key", key).put("db", db); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.MOVE, (cmd)->cmd.move(key, db), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.MOVE, (cmd)->cmd.move(key, db), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.MOVE, (cmd)->cmd.move(key, db), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... + keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("timeout", timeout).put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(keys); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateOperation operation, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("timeout", timeout).put("operation", operation).put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(operation, keys); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final byte[] password, + final int timeout, + final byte[]... keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("password", password).put("timeout", timeout).put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(keys, password); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final byte[] password, + final int timeout, + final MigrateOperation operation, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("password", password).put("timeout", timeout).put("operation", operation) + .put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(operation, keys, password); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final byte[] user, + final byte[] password, + final int timeout, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("user", user).put("password", password).put("timeout", timeout) + .put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(keys, user, password); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final byte[] user, + final byte[] password, + final int timeout, final MigrateOperation operation, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("user", user).put("password", password).put("timeout", timeout) + .put("operation", operation) + .put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(keys, user, password); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Set keys(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final byte[] bPattern = SafeEncoder.encode(pattern); + final ListSetConverter binaryToStringListSetConverter = + Converters.listSetBinaryToString(); + + return keys(bPattern, binaryToStringListSetConverter, args); + } + + @Override + public Set keys(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final ListSetConverter converter = new ListSetConverter<>((v)->v); + + return keys(pattern, converter, args); + } + + @Override + public String randomKey() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.RANDOMKEY, (cmd)->cmd.randomkey(), + SafeEncoder::encode) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.RANDOMKEY, (cmd)->cmd.randomkey(), + SafeEncoder::encode) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.RANDOMKEY, (cmd)->cmd.randomkey(), + SafeEncoder::encode) + .run(); + } + } + + @Override + public Status rename(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.RENAME, + (cmd)->cmd.rename(key, newKey), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + } + } + + @Override + public Status renameNx(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.RENAMENX, + (cmd)->cmd.renamenx(key, newKey), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.RENAMENX, + (cmd)->cmd.renamenx(key, newKey), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl) { + final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) + .put("ttl", ttl); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl, + final RestoreArgument argument) { + final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) + .put("ttl", ttl).put("argument", argument); + final RestoreArgs restoreArgs = LettuceRestoreArgs.from(argument).ttl(ttl); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, serializedValue, restoreArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, serializedValue, restoreArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, serializedValue, restoreArgs), okStatusConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final String cursor) { + final CommandArguments args = CommandArguments.create("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor) { + final CommandArguments args = CommandArguments.create("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, keyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, scanArgs, keyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final String cursor, final long count) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final long count) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, scanArgs, keyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern, final long count) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern, final long count) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, scanArgs, keyScanCursorConverter, args); + } + + @Override + public List sort(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return sort(bKey, binaryToStringListConverter, args); + } + + @Override + public List sort(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return sort(key, (v)->v, args); + } + + @Override + public List sort(final String key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("sortArgument", sortArgument); + final byte[] bKey = SafeEncoder.encode(key); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + + return sort(bKey, sortArgs, binaryToStringListConverter, args); + } + + @Override + public List sort(final byte[] key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("sortArgument", sortArgument); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + + return sort(key, sortArgs, (v)->v, args); + } + + @Override + public Long sort(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + final SortArgs sortArgs = new LettuceSortArgs(); + + return sortStore(key, destKey, sortArgs, args); + } + + @Override + public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("sortArgument", sortArgument); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + + return sortStore(key, destKey, sortArgs, args); + } + + @Override + public Long touch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } + } + + @Override + public Type type(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), + typeConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), + typeConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } + } + + @Override + public Long unlink(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } + } + + @Override + public ObjectEncoding objectEncoding(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final ObjectEncodingConverter objectEncodingConverter = new ObjectEncodingConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + } + } + + @Override + public Long objectFreq(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.OBJECT_REFQ) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.OBJECT_REFQ) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.OBJECT_REFQ) + .run(args); + } + } + + @Override + public Long objectIdleTime(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectRefcount(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + } + } + + private Status copy(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.COPY) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.COPY) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.COPY) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgs migrateArgs, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateArgs), okStatusConverter) + .run(args); + } + } + + private Set keys(final byte[] pattern, final ListSetConverter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), converter) + .run(args); + } + } + + private ScanResult> scan(final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), converter) + .run(args); + } + } + + private ScanResult> scan(final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SCAN, + (cmd)->cmd.scan(cursor, scanArgs), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanArgs), + converter) + .run(args); + } + } + + private List sort(final byte[] key, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), converter) + .run(args); + } + } + + private List sort(final byte[] key, final SortArgs sortArgs, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortArgs), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortArgs), + converter) + .run(args); + } + } + + private Long sortStore(final byte[] key, final byte[] destKey, final SortArgs sortArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sortStore(key, sortArgs, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sortStore(key, sortArgs, destKey), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sortStore(key, sortArgs, destKey), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterListOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterListOperations.java new file mode 100644 index 000000000..b81a0c7df --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterListOperations.java @@ -0,0 +1,585 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.builder.ListBuilder; +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.Direction; +import com.buession.redis.core.ListPosition; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.lettuce.LettuceLPosArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyValue; +import io.lettuce.core.LPosArgs; + +import java.util.List; + +/** + * Lettuce 集群模式列表命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterListOperations extends AbstractListOperations { + + public LettuceClusterListOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public String lIndex(final String key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + final byte[] bKey = SafeEncoder.encode(key); + + return lIndex(bKey, index, SafeEncoder::encode, args); + } + + @Override + public byte[] lIndex(final byte[] key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + return lIndex(key, index, (v)->v, args); + } + + @Override + public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) + .put("value", value); + final boolean before = ListPosition.BEFORE == position; + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, before, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, before, pivot, value), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, before, pivot, value), (v)->v) + .run(args); + } + } + + @Override + public Status lSet(final byte[] key, final long index, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.LSET, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.LSET, + (cmd)->cmd.lset(key, index, value), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.LSET, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Long lLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } + } + + @Override + public List lRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + + return lRange(bKey, start, end, binaryToStringListConverter, args); + } + + @Override + public List lRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return lRange(key, start, end, (v)->v, args); + } + + @Override + public Long lPos(final byte[] key, final byte[] element) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); + final LPosArgs lPosArgs = LettuceLPosArgs.from(lPosArgument); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosArgs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosArgs), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element, lPosArgs), + (v)->v) + .run(args); + } + } + + @Override + public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) + .put("count", count); + final LPosArgs lPosArgs = LettuceLPosArgs.from(lPosArgument); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, (int) count, lPosArgs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, (int) count, lPosArgs), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, (int) count, lPosArgs), (v)->v) + .run(args); + } + } + + @Override + public Long lRem(final byte[] key, final byte[] value, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.LREM, + (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } + } + + @Override + public Status lTrim(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.LTRIM, + (cmd)->cmd.ltrim(key, start, end), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } + } + + @Override + public String lMove(final String key, final String destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + return lMove(args); + } + + @Override + public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + return lMove(args); + } + + @Override + public String blMove(final String key, final String destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + return blMove(args); + } + + @Override + public byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to).put("timeout", timeout); + return blMove(args); + } + + @Override + public List blPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final Converter, List> converter = + (v)->ListBuilder.of(SafeEncoder.encode(v.getValue())); + + return blPop(bKeys, timeout, converter, args); + } + + @Override + public List blPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final Converter, List> converter = (v)->ListBuilder.of(v.getValue()); + + return blPop(keys, timeout, converter, args); + } + + @Override + public List brPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final Converter, List> converter = + (v)->ListBuilder.of(SafeEncoder.encode(v.getValue())); + + return brPop(bKeys, timeout, converter, args); + } + + @Override + public List brPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final Converter, List> converter = (v)->ListBuilder.of(v.getValue()); + + return brPop(keys, timeout, converter, args); + } + + @Override + public String brPoplPush(final String key, final String destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + + return brPoplPush(bKey, bDestKey, timeout, SafeEncoder::encode, args); + } + + @Override + public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + return brPoplPush(key, destKey, timeout, (v)->v, args); + } + + @Override + public String lPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return lPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] lPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return lPop(key, (v)->v, args); + } + + @Override + public Long lPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long lPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.LPUSHX, + (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } + } + + @Override + public String rPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return rPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] rPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return rPop(key, (v)->v, args); + } + + @Override + public String rPoplPush(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + + return rPoplPush(bKey, bDestKey, SafeEncoder::encode, args); + } + + @Override + public byte[] rPoplPush(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + return rPoplPush(key, destKey, (v)->v, args); + } + + @Override + public Long rPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long rPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.RPUSHX, + (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } + } + + private V lIndex(final byte[] key, final long index, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), converter) + .run(args); + } + } + + private List lRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.LRANGE, + (cmd)->cmd.lrange(key, start, end), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.LRANGE, + (cmd)->cmd.lrange(key, start, end), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), + converter) + .run(args); + } + } + + private V lMove(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.LMOVE) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.LMOVE) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.LMOVE) + .run(args); + } + } + + private V blMove(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.BLMOVE) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.BLMOVE) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.BLMOVE) + .run(args); + } + } + + private List blPop(final byte[][] keys, final int timeout, final Converter, + List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.BLPOP, + (cmd)->cmd.blpop(timeout, keys), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), + converter) + .run(args); + } + } + + private List brPop(final byte[][] keys, final int timeout, final Converter, + List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.BRPOP, + (cmd)->cmd.brpop(timeout, keys), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), + converter) + .run(args); + } + } + + private V brPoplPush(final byte[] key, final byte[] destKey, final int timeout, + final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(timeout, key, destKey), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(timeout, key, destKey), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(timeout, key, destKey), converter) + .run(args); + } + } + + private V lPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), converter) + .run(args); + } + } + + private V rPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), converter) + .run(args); + } + } + + private V rPoplPush(final byte[] key, final byte[] destKey, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterOperations.java new file mode 100644 index 000000000..5c449571b --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterOperations.java @@ -0,0 +1,559 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.BumpEpoch; +import com.buession.redis.core.ClusterFailoverOption; +import com.buession.redis.core.ClusterInfo; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.ClusterResetOption; +import com.buession.redis.core.ClusterSetSlotOption; +import com.buession.redis.core.ClusterSlot; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.response.ClusterReplicasConverter; +import com.buession.redis.core.internal.convert.response.BumpEpochConverter; +import com.buession.redis.core.internal.convert.response.ClusterInfoConverter; +import com.buession.redis.core.internal.convert.response.ClusterNodeConverter; +import com.buession.redis.core.internal.convert.response.ClusterNodesConverter; +import com.buession.redis.core.internal.convert.response.ClusterSlotConverter; + +import java.util.List; + +/** + * Lettuce 单机模式集群命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterOperations extends AbstractClusterOperations { + + public LettuceClusterOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public String clusterMyId() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_MY_ID, (cmd)->cmd.clusterMyId(), (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_MY_ID, (cmd)->cmd.clusterMyId(), + (v)->v) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_MY_ID, (cmd)->cmd.clusterMyId(), (v)->v) + .run(); + } + } + + @Override + public Status clusterAddSlots(final int... slots) { + final CommandArguments args = CommandArguments.create("slots", slots); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_ADDSLOTS, + (cmd)->cmd.clusterAddSlots(slots), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_ADDSLOTS, + (cmd)->cmd.clusterAddSlots(slots), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_ADDSLOTS, (cmd)->cmd.clusterAddSlots(slots), + okStatusConverter) + .run(args); + } + } + + @Override + public List clusterSlots() { + final ListConverter listClusterSlotConverter = ClusterSlotConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_SLOTS, (cmd)->cmd.clusterSlots(), + listClusterSlotConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_SLOTS, (cmd)->cmd.clusterSlots(), + listClusterSlotConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_SLOTS, (cmd)->cmd.clusterSlots(), + listClusterSlotConverter) + .run(); + } + } + + @Override + public Integer clusterCountFailureReports(final String nodeId) { + final CommandArguments args = CommandArguments.create("nodeId", nodeId); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS, + (cmd)->cmd.clusterCountFailureReports(nodeId), Long::intValue) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS, + (cmd)->cmd.clusterCountFailureReports(nodeId), Long::intValue) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS, + (cmd)->cmd.clusterCountFailureReports(nodeId), Long::intValue) + .run(args); + } + } + + @Override + public Long clusterCountKeysInSlot(final int slot) { + final CommandArguments args = CommandArguments.create("slot", slot); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT, + (cmd)->cmd.clusterCountKeysInSlot(slot), (v)->v) + .run(args); + } + } + + @Override + public Status clusterDelSlots(final int... slots) { + final CommandArguments args = CommandArguments.create("slots", slots); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_DELSLOTS, + (cmd)->cmd.clusterDelSlots(slots), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_DELSLOTS, + (cmd)->cmd.clusterDelSlots(slots), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_DELSLOTS, (cmd)->cmd.clusterDelSlots(slots), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterFlushSlots() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_FLUSHSLOTS, + (cmd)->cmd.clusterFlushslots(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_FLUSHSLOTS, + (cmd)->cmd.clusterFlushslots(), okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_FLUSHSLOTS, (cmd)->cmd.clusterFlushslots(), + okStatusConverter) + .run(); + } + } + + @Override + public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption) { + final CommandArguments args = CommandArguments.create("clusterFailoverOption", clusterFailoverOption); + final boolean force = ClusterFailoverOption.FORCE == clusterFailoverOption; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_FAILOVER, + (cmd)->cmd.clusterFailover(force), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_FAILOVER, + (cmd)->cmd.clusterFailover(force), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_FAILOVER, (cmd)->cmd.clusterFailover(force), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterForget(final String nodeId) { + final CommandArguments args = CommandArguments.create("nodeId", nodeId); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_FORGET, + (cmd)->cmd.clusterForget(nodeId), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_FORGET, + (cmd)->cmd.clusterForget(nodeId), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_FORGET, (cmd)->cmd.clusterForget(nodeId), + okStatusConverter) + .run(args); + } + } + + @Override + public List clusterGetKeysInSlot(final int slot, final long count) { + final CommandArguments args = CommandArguments.create("slot", slot).put("count", count); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, (int) count), binaryToStringListConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, (int) count), binaryToStringListConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterGetKeysInSlot(slot, (int) count), binaryToStringListConverter) + .run(args); + } + } + + @Override + public Long clusterKeySlot(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterKeyslot(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, + (cmd)->cmd.clusterKeyslot(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT, (cmd)->cmd.clusterKeyslot(key), + (v)->v) + .run(args); + } + } + + @Override + public ClusterInfo clusterInfo() { + final ClusterInfoConverter clusterInfoConverter = new ClusterInfoConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_INFO, (cmd)->cmd.clusterInfo(), + clusterInfoConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_INFO, (cmd)->cmd.clusterInfo(), + clusterInfoConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_INFO, (cmd)->cmd.clusterInfo(), + clusterInfoConverter) + .run(); + } + } + + @Override + public Status clusterMeet(final String ip, final int port) { + final CommandArguments args = CommandArguments.create("ip", ip).put("port", port); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_MEET, (cmd)->cmd.clusterMeet(ip, port), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_MEET, + (cmd)->cmd.clusterMeet(ip, port), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_MEET, (cmd)->cmd.clusterMeet(ip, port), + okStatusConverter) + .run(args); + } + } + + @Override + public List clusterNodes() { + final ClusterNodesConverter clusterNodesConverter = new ClusterNodesConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_NODES, (cmd)->cmd.clusterNodes(), + clusterNodesConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_NODES, (cmd)->cmd.clusterNodes(), + clusterNodesConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_NODES, (cmd)->cmd.clusterNodes(), + clusterNodesConverter) + .run(); + } + } + + @Override + public List clusterSlaves(final String nodeId) { + final CommandArguments args = CommandArguments.create("nodeId", nodeId); + final ListConverter listClusterNodeConverter = ClusterNodeConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_SLAVES, + (cmd)->cmd.clusterSlaves(nodeId), listClusterNodeConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_SLAVES, + (cmd)->cmd.clusterSlaves(nodeId), listClusterNodeConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_SLAVES, (cmd)->cmd.clusterSlaves(nodeId), + listClusterNodeConverter) + .run(args); + } + } + + @Override + public List clusterReplicas(final String nodeId) { + final CommandArguments args = CommandArguments.create("nodeId", nodeId); + final ClusterReplicasConverter clusterReplicasConverter = new ClusterReplicasConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_REPLICAS, + (cmd)->cmd.clusterReplicate(nodeId), clusterReplicasConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_REPLICAS, + (cmd)->cmd.clusterReplicate(nodeId), clusterReplicasConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_REPLICAS, (cmd)->cmd.clusterReplicate(nodeId), + clusterReplicasConverter) + .run(args); + } + } + + @Override + public Status clusterReplicate(final String nodeId) { + final CommandArguments args = CommandArguments.create("nodeId", nodeId); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_REPLICATE, + (cmd)->cmd.clusterReplicate(nodeId), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_REPLICATE, + (cmd)->cmd.clusterReplicate(nodeId), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_REPLICATE, (cmd)->cmd.clusterReplicate(nodeId), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterReset(final ClusterResetOption clusterResetOption) { + final CommandArguments args = CommandArguments.create("clusterResetOption", clusterResetOption); + final boolean hard = ClusterResetOption.HARD == clusterResetOption; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_RESET, (cmd)->cmd.clusterReset(hard), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_RESET, (cmd)->cmd.clusterReset(hard), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_RESET, (cmd)->cmd.clusterReset(hard), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clusterSaveConfig() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_SAVECONFIG, + (cmd)->cmd.clusterSaveconfig(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_SAVECONFIG, + (cmd)->cmd.clusterSaveconfig(), okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_SAVECONFIG, (cmd)->cmd.clusterSaveconfig(), + okStatusConverter) + .run(); + } + } + + @Override + public Status clusterSetConfigEpoch(final long configEpoch) { + final CommandArguments args = CommandArguments.create("configEpoch", configEpoch); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH, + (cmd)->cmd.clusterSetConfigEpoch(configEpoch), okStatusConverter) + .run(args); + } + } + + @Override + public KeyValue clusterBumpEpoch() { + final BumpEpochConverter bumpEpochConverter = new BumpEpochConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_BUMPEPOCH, + (cmd)->cmd.clusterBumpepoch(), bumpEpochConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_BUMPEPOCH, + (cmd)->cmd.clusterBumpepoch(), bumpEpochConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_BUMPEPOCH, (cmd)->cmd.clusterBumpepoch(), + bumpEpochConverter) + .run(); + } + } + + @Override + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId) { + final CommandArguments args = CommandArguments.create("slot", slot).put("setSlotOption", setSlotOption) + .put("nodeId", nodeId); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLUSTER_SETSLOT, (cmd)->{ + switch(setSlotOption){ + case IMPORTING: + return cmd.clusterSetSlotImporting(slot, nodeId); + case MIGRATING: + return cmd.clusterSetSlotMigrating(slot, nodeId); + case STABLE: + return cmd.clusterSetSlotStable(slot); + case NODE: + return cmd.clusterSetSlotNode(slot, nodeId); + default: + return null; + } + }, okStatusConverter) + .run(args); + } + } + + @Override + public Status asking() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ASKING, (cmd)->cmd.asking(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ASKING, (cmd)->cmd.asking(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ASKING, (cmd)->cmd.asking(), okStatusConverter) + .run(); + } + } + + @Override + public Status readWrite() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.READWRITE, (cmd)->cmd.readWrite(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.READWRITE, (cmd)->cmd.readWrite(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.READWRITE, (cmd)->cmd.readWrite(), okStatusConverter) + .run(); + } + } + + @Override + public Status readOnly() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.READONLY, (cmd)->cmd.readOnly(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.READONLY, (cmd)->cmd.readOnly(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.READONLY, (cmd)->cmd.readOnly(), okStatusConverter) + .run(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterPubSubOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterPubSubOperations.java new file mode 100644 index 000000000..6f6747eb0 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterPubSubOperations.java @@ -0,0 +1,298 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.MapConverter; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.PubSubListener; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 集群模式 Pub/Sub 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterPubSubOperations extends AbstractPubSubOperations { + + public LettuceClusterPubSubOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + pSubscribe(args); + } + + @Override + public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + pSubscribe(args); + } + + @Override + public Long publish(final byte[] channel, final byte[] message) { + final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PUBLISH, + (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PUBLISH, + (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + } + } + + @Override + public List pubsubChannels() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(), binaryToStringListConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(), binaryToStringListConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(), + binaryToStringListConverter) + .run(); + } + } + + @Override + public List pubsubChannels(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final byte[] bPattern = SafeEncoder.encode(pattern); + + return pubsubChannels(bPattern, binaryToStringListConverter, args); + } + + @Override + public List pubsubChannels(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return pubsubChannels(pattern, (v)->v, args); + } + + @Override + public Long pubsubNumPat() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PUBSUB_NUMPAT, (cmd)->cmd.pubsubNumpat(), + (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PUBSUB_NUMPAT, + (cmd)->cmd.pubsubNumpat(), (v)->v) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.PUBSUB_NUMPAT, (cmd)->cmd.pubsubNumpat(), (v)->v) + .run(); + } + } + + @Override + public Map pubsubNumSub(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + final byte[][] bChannels = SafeEncoder.encode(channels); + final MapConverter converter = new MapConverter<>(SafeEncoder::encode, (v)->v); + + return pubsubNumSub(bChannels, converter, args); + } + + @Override + public Map pubsubNumSub(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return pubsubNumSub(channels, (v)->v, args); + } + + @Override + public Object pUnSubscribe() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + } + } + + @Override + public Object pUnSubscribe(final String... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return pUnSubscribe(args); + } + + @Override + public Object pUnSubscribe(final byte[]... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return pUnSubscribe(args); + } + + @Override + public void subscribe(final String[] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + subscribe(args); + } + + @Override + public void subscribe(final byte[][] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + subscribe(args); + } + + @Override + public Object unSubscribe() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + } + } + + @Override + public Object unSubscribe(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return unSubscribe(args); + } + + @Override + public Object unSubscribe(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return unSubscribe(args); + } + + private void pSubscribe(final CommandArguments args) { + if(isPipeline()){ + new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else{ + new LettuceClusterCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + } + } + + private List pubsubChannels(final byte[] pattern, final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(pattern), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(pattern), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(pattern), converter) + .run(args); + } + } + + private Map pubsubNumSub(final byte[][] channels, + final Converter, Map> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PUBSUB_NUMSUB, + (cmd)->cmd.pubsubNumsub(channels), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PUBSUB_NUMSUB, + (cmd)->cmd.pubsubNumsub(channels), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.PUBSUB_NUMSUB, (cmd)->cmd.pubsubNumsub(channels), + converter) + .run(args); + } + } + + private Object pUnSubscribe(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + } + } + + private void subscribe(final CommandArguments args) { + if(isPipeline()){ + new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else{ + new LettuceClusterCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + } + } + + private Object unSubscribe(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterScriptingOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterScriptingOperations.java new file mode 100644 index 000000000..5141fa765 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterScriptingOperations.java @@ -0,0 +1,242 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce 集群模式 Script 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterScriptingOperations extends AbstractScriptingOperations { + + public LettuceClusterScriptingOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Object eval(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + final byte[][] bKeys = new byte[][]{}; + + return eval(script, bKeys, null, args); + } + + @Override + public Object eval(final String script, final String... params) { + final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + final byte[][] bKeys = new byte[][]{}; + final byte[][] bParams = SafeEncoder.encode(params); + + return eval(script, bKeys, bParams, args); + } + + @Override + public Object eval(final String script, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final byte[][] bKeys = SafeEncoder.encode(keys); + final byte[][] bArguments = SafeEncoder.encode(arguments); + + return eval(script, bKeys, bArguments, args); + } + + @Override + public Object evalSha(final String digest) { + final CommandArguments args = CommandArguments.create("digest", digest); + final byte[][] bKeys = new byte[][]{}; + + return evalSha(digest, bKeys, null, args); + } + + @Override + public Object evalSha(final String digest, final String... params) { + final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); + final byte[][] bKeys = new byte[][]{}; + final byte[][] bParams = SafeEncoder.encode(params); + + return evalSha(digest, bKeys, bParams, args); + } + + @Override + public Object evalSha(final String digest, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final byte[][] bKeys = SafeEncoder.encode(keys); + final byte[][] bArguments = SafeEncoder.encode(arguments); + + return evalSha(digest, bKeys, bArguments, args); + } + + @Override + public List scriptExists(final String... sha1) { + final CommandArguments args = CommandArguments.create(sha1); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(sha1), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, + (cmd)->cmd.scriptExists(sha1), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), + (v)->v) + .run(args); + } + } + + @Override + public Status scriptFlush() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush(), okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(); + } + } + + @Override + public Status scriptFlush(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, + (cmd)->cmd.scriptFlush(), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(args); + } + } + + @Override + public String scriptLoad(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + final byte[] bScript = SafeEncoder.encode(script); + + return scriptLoad(bScript, (v)->v, args); + } + + @Override + public byte[] scriptLoad(final byte[] script) { + final CommandArguments args = CommandArguments.create("script", script); + return scriptLoad(script, SafeEncoder::encode, args); + } + + @Override + public Status scriptKill() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + } + } + + private Object eval(final String script, final byte[][] keys, final byte[][] arguments, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, null, keys, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, null, keys, arguments), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, null, keys, arguments), (v)->v) + .run(args); + } + } + + private Object evalSha(final String digest, final byte[][] keys, final byte[][] arguments, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, null, keys, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, null, keys, arguments), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, null, keys, arguments), (v)->v) + .run(args); + } + } + + private V scriptLoad(final byte[] script, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SCRIPT_LOAD, + (cmd)->cmd.scriptLoad(script), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), + converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterServerOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterServerOperations.java new file mode 100644 index 000000000..cff2337c9 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterServerOperations.java @@ -0,0 +1,1064 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.AclLog; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.Info; +import com.buession.redis.core.MemoryStats; +import com.buession.redis.core.Module; +import com.buession.redis.core.RedisMonitor; +import com.buession.redis.core.RedisServerTime; +import com.buession.redis.core.Role; +import com.buession.redis.core.SlowLog; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.RedisServerTimeConverter; +import com.buession.redis.core.internal.convert.lettuce.response.RoleConverter; +import com.buession.redis.core.internal.convert.lettuce.response.SlowlogConverter; +import com.buession.redis.core.internal.convert.response.InfoConverter; +import com.buession.redis.utils.SafeEncoder; + +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * Lettuce 集群模式服务端命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterServerOperations extends AbstractServerOperations { + + public LettuceClusterServerOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public List aclCat() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else{ + return new LettuceClusterCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + } + } + + @Override + public List aclCat(final String categoryName) { + final CommandArguments args = CommandArguments.create("categoryName", categoryName); + return aclCat(args); + } + + @Override + public List aclCat(final byte[] categoryName) { + final CommandArguments args = CommandArguments.create("categoryName", categoryName); + return aclCat(args); + } + + @Override + public Status aclSetUser(final String username, final String... rules) { + final CommandArguments args = CommandArguments.create("username", username).put("rules", (Object[]) rules); + return aclSetUser(args); + } + + @Override + public Status aclSetUser(final byte[] username, final byte[]... rules) { + final CommandArguments args = CommandArguments.create("username", username).put("rules", (Object[]) rules); + return aclSetUser(args); + } + + @Override + public AclUser aclGetUser(final String username) { + final CommandArguments args = CommandArguments.create("username", username); + return aclGetUser(args); + } + + @Override + public AclUser aclGetUser(final byte[] username) { + final CommandArguments args = CommandArguments.create("username", username); + return aclGetUser(args); + } + + @Override + public List aclUsers() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + }else{ + return new LettuceClusterCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + } + } + + @Override + public String aclWhoAmI() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + } + } + + @Override + public Long aclDelUser(final String... usernames) { + final CommandArguments args = CommandArguments.create("usernames", (Object[]) usernames); + return aclDelUser(args); + } + + @Override + public Long aclDelUser(final byte[]... usernames) { + final CommandArguments args = CommandArguments.create("usernames", (Object[]) usernames); + return aclDelUser(args); + } + + @Override + public String aclGenPass() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + } + } + + @Override + public List aclList() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + }else{ + return new LettuceClusterCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + } + } + + @Override + public Status aclLoad() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + } + } + + @Override + public List aclLog() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + }else{ + return new LettuceClusterCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + } + } + + @Override + public List aclLog(final long count) { + final CommandArguments args = CommandArguments.create("count", count); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + }else{ + return new LettuceClusterCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + } + } + + @Override + public Status aclLogReset() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + } + } + + @Override + public Status aclLogSave() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + } + } + + @Override + public String bgRewriteAof() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + } + } + + @Override + public String bgSave() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.BGSAVE) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.BGSAVE) + .run(); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.BGSAVE) + .run(); + } + } + + @Override + public Status configSet(final String parameter, final String value) { + final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CONFIG_SET, + (cmd)->cmd.configSet(parameter, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CONFIG_SET, + (cmd)->cmd.configSet(parameter, value), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CONFIG_SET, + (cmd)->cmd.configSet(parameter, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status configSet(final Map configs) { + final CommandArguments args = CommandArguments.create("configs", configs); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CONFIG_SET, + (cmd)->cmd.configSet(configs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CONFIG_SET, + (cmd)->cmd.configSet(configs), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CONFIG_SET, (cmd)->cmd.configSet(configs), + okStatusConverter) + .run(args); + } + } + + @Override + public Map configGet(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CONFIG_GET, + (cmd)->cmd.configGet(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CONFIG_GET, + (cmd)->cmd.configGet(pattern), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CONFIG_GET, (cmd)->cmd.configGet(pattern), + (v)->v) + .run(args); + } + } + + @Override + public Map configGet(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final String sPattern = SafeEncoder.encode(pattern); + final Converter, Map> converter = Converters.mapStringToBinary(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CONFIG_GET, + (cmd)->cmd.configGet(sPattern), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CONFIG_GET, + (cmd)->cmd.configGet(sPattern), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CONFIG_GET, (cmd)->cmd.configGet(sPattern), + converter) + .run(args); + } + } + + @Override + public Status configResetStat() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CONFIG_RESETSTAT, + (cmd)->cmd.configResetstat(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CONFIG_RESETSTAT, + (cmd)->cmd.configResetstat(), okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CONFIG_RESETSTAT, (cmd)->cmd.configResetstat(), + okStatusConverter) + .run(); + } + } + + @Override + public Status configRewrite() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.CONFIG_REWRITE, + (cmd)->cmd.configRewrite(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.CONFIG_REWRITE, + (cmd)->cmd.configRewrite(), okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.CONFIG_REWRITE, (cmd)->cmd.configRewrite(), + okStatusConverter) + .run(); + } + } + + @Override + public Long dbSize() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.DBSIZE, (cmd)->cmd.dbsize(), (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.DBSIZE, (cmd)->cmd.dbsize(), (v)->v) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.DBSIZE, (cmd)->cmd.dbsize(), (v)->v) + .run(); + } + } + + @Override + public Status failover() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.FAILOVER) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.FAILOVER) + .run(); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.FAILOVER) + .run(); + } + } + + @Override + public Status failover(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + return failover(args); + } + + @Override + public Status failover(final String host, final int port, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("timeout", timeout); + return failover(args); + } + + @Override + public Status failover(final String host, final int port, final boolean isForce, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("isForce", isForce) + .put("timeout", timeout); + return failover(args); + } + + @Override + public Status failover(final int timeout) { + final CommandArguments args = CommandArguments.create("timeout", timeout); + return failover(args); + } + + @Override + public Status flushAll() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.FLUSHALL, (cmd)->cmd.flushall(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.FLUSHALL, (cmd)->cmd.flushall(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.FLUSHALL, (cmd)->cmd.flushall(), + okStatusConverter) + .run(); + } + } + + @Override + public Status flushAll(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.FLUSHALL, + (cmd)->mode == FlushMode.ASYNC ? cmd.flushallAsync() : cmd.flushall(), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.FLUSHALL, + (cmd)->mode == FlushMode.ASYNC ? cmd.flushallAsync() : cmd.flushall(), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.FLUSHALL, + (cmd)->mode == FlushMode.ASYNC ? cmd.flushallAsync() : cmd.flushall(), okStatusConverter) + .run(args); + } + } + + @Override + public Status flushDb() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.flushdb(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.flushdb(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.flushdb(), okStatusConverter) + .run(); + } + } + + @Override + public Status flushDb(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->mode == FlushMode.ASYNC ? + cmd.flushdbAsync() : cmd.flushdb(), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.FLUSHDB, + (cmd)->mode == FlushMode.ASYNC ? + cmd.flushdbAsync() : cmd.flushdb(), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->mode == FlushMode.ASYNC ? + cmd.flushdbAsync() : cmd.flushdb(), okStatusConverter) + .run(args); + } + } + + @Override + public Info info() { + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(), + infoConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(), + infoConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(), infoConverter) + .run(); + } + } + + @Override + public Info info(final Info.Section section) { + final CommandArguments args = CommandArguments.create("section", section); + final String sectionName = section.name().toLowerCase(); + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(sectionName), + infoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(sectionName), + infoConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(sectionName), + infoConverter) + .run(args); + } + } + + @Override + public Long lastSave() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.LASTSAVE, (cmd)->cmd.lastsave(), + Date::getTime) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.LASTSAVE, (cmd)->cmd.lastsave(), + Date::getTime) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.LASTSAVE, (cmd)->cmd.lastsave(), Date::getTime) + .run(); + } + } + + @Override + public String memoryDoctor() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + } + } + + @Override + public Status memoryPurge() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + } + } + + @Override + public MemoryStats memoryStats() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + } + } + + @Override + public Long memoryUsage(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + } + } + + @Override + public Long memoryUsage(final byte[] key, final int samples) { + final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, + (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + } + } + + @Override + public List moduleList() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, ProtocolCommand.MODULE_LIST) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, ProtocolCommand.MODULE_LIST) + .run(); + }else{ + return new LettuceClusterCommand, List>(client, ProtocolCommand.MODULE_LIST) + .run(); + } + } + + @Override + public Status moduleLoad(final String path, final String... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + return moduleLoad(args); + } + + @Override + public Status moduleLoad(final byte[] path, final byte[]... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + return moduleLoad(args); + } + + @Override + public Status moduleUnLoad(final String name) { + final CommandArguments args = CommandArguments.create("name", name); + return moduleUnLoad(args); + } + + @Override + public Status moduleUnLoad(final byte[] name) { + final CommandArguments args = CommandArguments.create("name", name); + return moduleUnLoad(args); + } + + @Override + public void monitor(final RedisMonitor redisMonitor) { + final CommandArguments args = CommandArguments.create("redisMonitor", redisMonitor); + + if(isPipeline()){ + new LettuceClusterPipelineCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + }else if(isTransaction()){ + new LettuceClusterTransactionCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + }else{ + new LettuceClusterCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + } + } + + @Override + public Object pSync(final String replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return pSync(args); + } + + @Override + public Object pSync(final byte[] replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return pSync(args); + } + + @Override + public void sync() { + if(isPipeline()){ + new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SYNC) + .run(); + }else if(isTransaction()){ + new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SYNC) + .run(); + }else{ + new LettuceClusterCommand<>(client, ProtocolCommand.SYNC) + .run(); + } + } + + @Override + public Status replicaOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + } + } + + @Override + public Status slaveOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SLAVEOF, (cmd)->cmd.slaveof(host, port), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SLAVEOF, + (cmd)->cmd.slaveof(host, port), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SLAVEOF, (cmd)->cmd.slaveof(host, port), + okStatusConverter) + .run(args); + } + } + + @Override + public Role role() { + final RoleConverter roleConverter = new RoleConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ROLE, (cmd)->cmd.role(), roleConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ROLE, (cmd)->cmd.role(), + roleConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ROLE, (cmd)->cmd.role(), roleConverter) + .run(); + } + } + + @Override + public Status save() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SAVE, (cmd)->cmd.save(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SAVE, (cmd)->cmd.save(), + okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SAVE, (cmd)->cmd.save(), okStatusConverter) + .run(); + } + } + + @Override + public void shutdown() { + if(isPipeline()){ + new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(true); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(true); + return null; + }, (v)->v) + .run(); + }else{ + new LettuceClusterCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(true); + return null; + }, (v)->v) + .run(); + } + } + + @Override + public void shutdown(final boolean save) { + final CommandArguments args = CommandArguments.create("save", save); + + if(isPipeline()){ + new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(save); + return null; + }, (v)->v) + .run(args); + }else if(isTransaction()){ + new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(save); + return null; + }, (v)->v) + .run(args); + }else{ + new LettuceClusterCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(save); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public List slowLogGet() { + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + } + } + + @Override + public List slowLogGet(final long count) { + final CommandArguments args = CommandArguments.create("count", count); + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SLOWLOG_GET, + (cmd)->cmd.slowlogGet((int) count), listSlowlogConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SLOWLOG_GET, + (cmd)->cmd.slowlogGet((int) count), listSlowlogConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SLOWLOG_GET, (cmd)->cmd.slowlogGet((int) count), + listSlowlogConverter) + .run(args); + } + } + + @Override + public Long slowLogLen() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SLOWLOG_LEN, (cmd)->cmd.slowlogLen(), + (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SLOWLOG_LEN, (cmd)->cmd.slowlogLen(), + (v)->v) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SLOWLOG_LEN, (cmd)->cmd.slowlogLen(), (v)->v) + .run(); + } + } + + @Override + public Status slowLogReset() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SLOWLOG_RESET, + (cmd)->cmd.slowlogReset(), okStatusConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + } + } + + @Override + public Status swapdb(final int db1, final int db2) { + final CommandArguments args = CommandArguments.create("db1", db1).put("db2", db2); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.SWAPDB) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.SWAPDB) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.SWAPDB) + .run(args); + } + } + + @Override + public RedisServerTime time() { + final RedisServerTimeConverter redisServerTimeConverter = new RedisServerTimeConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.TIME, (cmd)->cmd.time(), + redisServerTimeConverter) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.TIME, (cmd)->cmd.time(), + redisServerTimeConverter) + .run(); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.TIME, (cmd)->cmd.time(), + redisServerTimeConverter) + .run(); + } + } + + private List aclCat(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(args); + }else{ + return new LettuceClusterCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(args); + } + } + + private Status aclSetUser(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + } + } + + private AclUser aclGetUser(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + } + } + + private Long aclDelUser(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.ACL_DELUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.ACL_DELUSER) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.ACL_DELUSER) + .run(args); + } + } + + private Status failover(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.FAILOVER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.FAILOVER) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.FAILOVER) + .run(args); + } + } + + private Status moduleLoad(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + } + } + + private Status moduleUnLoad(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + } + } + + private Object pSync(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterSetOperations.java new file mode 100644 index 000000000..a63d64620 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterSetOperations.java @@ -0,0 +1,596 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.SetConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.ValueScanCursor; + +import java.util.List; +import java.util.Set; + +/** + * Lettuce 集群模式集合命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterSetOperations extends AbstractSetOperations { + + public LettuceClusterSetOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Long sAdd(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long sCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } + } + + @Override + public Set sDiff(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sDiff(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return sDiff(keys, (v)->v, args); + } + + @Override + public Long sDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Set sInter(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sInter(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return sInter(keys, (v)->v, args); + } + + @Override + public Long sInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Boolean sIsMember(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SISMEMBER, + (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + } + } + + @Override + public List smIsMember(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return smIsMember(args); + } + + @Override + public List smIsMember(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return smIsMember(args); + } + + @Override + public Set sMembers(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sMembers(bKey, binaryToStringSetConverter, args); + } + + @Override + public Set sMembers(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return sMembers(key, (v)->v, args); + } + + @Override + public Status sMove(final byte[] key, final byte[] destKey, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SMOVE, + (cmd)->cmd.smove(key, destKey, member), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SMOVE, + (cmd)->cmd.smove(key, destKey, member), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SMOVE, (cmd)->cmd.smove(key, destKey, member), + booleanStatusConverter) + .run(args); + } + } + + @Override + public String sPop(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + + return sPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] sPop(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return sPop(key, (v)->v, args); + } + + @Override + public Set sPop(final String key, final long count) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sPop(bKey, count, binaryToStringSetConverter, args); + } + + @Override + public Set sPop(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return sPop(key, count, (v)->v, args); + } + + @Override + public String sRandMember(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + + return sRandMember(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] sRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return sRandMember(key, (v)->v, args); + } + + @Override + public List sRandMember(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + + return sRandMember(bKey, count, binaryToStringListConverter, args); + } + + @Override + public List sRandMember(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return sRandMember(key, count, (v)->v, args); + } + + @Override + public Long sRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } + } + + @Override + public ScanResult> sScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(pattern); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(pattern); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, scanArgs, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, scanArgs, valueScanCursorConverter, args); + } + + @Override + public Set sUnion(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sUnion(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return sUnion(keys, (v)->v, args); + } + + @Override + public Long sUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + } + } + + private Set sDiff(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), converter) + .run(args); + } + } + + private Set sInter(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), converter) + .run(args); + } + } + + private List smIsMember(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, ProtocolCommand.SMISMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, + ProtocolCommand.SMISMEMBER) + .run(args); + }else{ + return new LettuceClusterCommand, List>(client, ProtocolCommand.SMISMEMBER) + .run(args); + } + } + + private Set sMembers(final byte[] key, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), converter) + .run(args); + } + } + + private V sPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), converter) + .run(args); + } + } + + private Set sPop(final byte[] key, final long count, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), converter) + .run(args); + } + } + + private V sRandMember(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.srandmember(key), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.srandmember(key), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), + converter) + .run(args); + } + } + + private List sRandMember(final byte[] key, final long count, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, count), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key, count), + converter) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), converter) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanArgs), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanArgs), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor, scanArgs), + converter) + .run(args); + } + } + + private Set sUnion(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterSortedSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterSortedSetOperations.java new file mode 100644 index 000000000..bd49f6e75 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterSortedSetOperations.java @@ -0,0 +1,1990 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.NumberUtils; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.Aggregate; +import com.buession.redis.core.GtLt; +import com.buession.redis.core.NxXx; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; +import com.buession.redis.core.ZRangeBy; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.response.KeyValueConverter; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.convert.lettuce.response.ScoredValueTupleConverter; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.core.internal.lettuce.LettuceZAddArgs; +import com.buession.redis.core.internal.lettuce.LettuceZStoreArgs; +import com.buession.redis.core.internal.lettuce.utils.ScoredValueUtils; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.Limit; +import io.lettuce.core.Range; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.ScoredValue; +import io.lettuce.core.ScoredValueScanCursor; +import io.lettuce.core.ZAddArgs; +import io.lettuce.core.ZStoreArgs; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 集群模式模式有序集合命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterSortedSetOperations extends AbstractSortedSetOperations { + + public LettuceClusterSortedSetOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Tuple zPopMin(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final ScoredValueTupleConverter.BinaryScoredValueTupleConverter scoredValueConverter = new ScoredValueTupleConverter.BinaryScoredValueTupleConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + } + } + + @Override + public List zPopMin(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, + (cmd)->cmd.zpopmin(key, count), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + } + } + + @Override + public Tuple zPopMax(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final ScoredValueTupleConverter.BinaryScoredValueTupleConverter scoredValueConverter = new ScoredValueTupleConverter.BinaryScoredValueTupleConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + } + } + + @Override + public List zPopMax(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, + (cmd)->cmd.zpopmin(key, count), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + } + } + + @Override + public com.buession.lang.KeyValue bzPopMin(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final KeyValueConverter, String, Tuple> converter = new KeyValueConverter<>( + SafeEncoder::encode, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMin(bKeys, timeout, converter, args); + } + + @Override + public com.buession.lang.KeyValue bzPopMin(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter, byte[], Tuple> converter = new KeyValueConverter<>( + (k)->k, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMin(keys, timeout, converter, args); + } + + @Override + public com.buession.lang.KeyValue bzPopMax(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final KeyValueConverter, String, Tuple> converter = new KeyValueConverter<>( + SafeEncoder::encode, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMax(bKeys, timeout, converter, args); + } + + @Override + public com.buession.lang.KeyValue bzPopMax(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter, byte[], Tuple> converter = new KeyValueConverter<>( + (k)->k, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMax(keys, timeout, converter, args); + } + + @Override + public Long zAdd(final String key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + return zAdd(key, members, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + return zAdd(key, members, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } + } + + @Override + public Long zCount(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, range), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, range), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, range), (v)->v) + .run(args); + } + } + + @Override + public List zDiff(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public List zDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public List zDiffWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public List zDiffWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public Long zDiffStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + return zDiffStore(args); + } + + @Override + public Long zDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + return zDiffStore(args); + } + + @Override + public Double zIncrBy(final byte[] key, final double increment, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) + .put("member", member); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), + (v)->v) + .run(args); + } + } + + @Override + public List zInter(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + } + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate); + + return zInterStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(weights); + + return zInterStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate, weights); + + return zInterStore(destKey, keys, zStoreArgs, args); + } + + @Deprecated + @Override + public Long zLexCount(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, range), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZLEXCOUNT, + (cmd)->cmd.zlexcount(key, range), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, range), + (v)->v) + .run(args); + } + } + + @Override + public List zMScore(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return zMScore(args); + } + + @Override + public List zMScore(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return zMScore(args); + } + + @Override + public String zRandMember(final String key) { + final CommandArguments args = CommandArguments.create(key); + return zRandMember(args); + } + + @Override + public byte[] zRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return zRandMember(args); + } + + @Override + public List zRandMember(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMember(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMemberWithScores(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMemberWithScores(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + + return zRange(bKey, start, end, binaryToStringListConverter, args); + } + + @Override + public List zRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return zRange(key, start, end, (v)->v, args); + } + + @Override + public List zRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRangeByLex(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(bKey, bMin, bMax, binaryToStringListConverter, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, (v)->v, args); + } + + @Deprecated + @Override + public List zRangeByLex(final String key, final String min, final String max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = SafeEncoder.encode(min); + final byte[] bMax = SafeEncoder.encode(max); + + return zRangeByLex(bKey, bMin, bMax, binaryToStringListConverter, args); + } + + @Deprecated + @Override + public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRangeByLex(key, min, max, (v)->v, args); + } + + @Override + public List zRangeByLex(final String key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(bKey, bMin, bMax, offset, count, binaryToStringListConverter, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, offset, count, (v)->v, args); + } + + @Deprecated + @Override + public List zRangeByLex(final String key, final String min, final String max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = SafeEncoder.encode(min); + final byte[] bMax = SafeEncoder.encode(max); + + return zRangeByLex(bKey, bMin, bMax, offset, count, binaryToStringListConverter, args); + } + + @Deprecated + @Override + public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRangeByLex(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + + return zRangeByScore(bKey, min, max, binaryToStringListConverter, args); + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRangeByScore(key, min, max, (v)->v, args); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + + return zRangeByScore(bKey, min, max, offset, count, binaryToStringListConverter, args); + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRangeByScore(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final Range range = Range.create(min, max); + final Limit limit = Limit.create(offset, count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + } + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev, + final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev, + final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public Long zRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } + } + + @Deprecated + @Override + public Long zRemRangeByLex(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangebylex(key, range), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangebylex(key, range), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangebylex(key, range), + (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangebyscore(key, range), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangebyscore(key, range), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangebyscore(key, range), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByRank(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangebyrank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangebyrank(key, start, end), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangebyrank(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List zRevRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + + return zRevRange(bKey, start, end, binaryToStringListConverter, args); + } + + @Override + public List zRevRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return zRevRange(key, start, end, (v)->v, args); + } + + @Override + public List zRevRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(bKey, bMin, bMax, binaryToStringListConverter, args); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(key, bMin, bMax, (v)->v, args); + } + + @Deprecated + @Override + public List zRevRangeByLex(final String key, final String min, final String max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = SafeEncoder.encode(min); + final byte[] bMax = SafeEncoder.encode(max); + + return zRevRangeByLex(bKey, bMin, bMax, binaryToStringListConverter, args); + } + + @Deprecated + @Override + public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRevRangeByLex(key, min, max, (v)->v, args); + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(bKey, bMin, bMax, offset, count, binaryToStringListConverter, args); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(key, bMin, bMax, offset, count, (v)->v, args); + } + + @Deprecated + @Override + public List zRevRangeByLex(final String key, final String min, final String max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = SafeEncoder.encode(min); + final byte[] bMax = SafeEncoder.encode(max); + + return zRevRangeByLex(bKey, bMin, bMax, offset, count, binaryToStringListConverter, args); + } + + @Deprecated + @Override + public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + return zRevRangeByLex(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + + return zRevRangeByScore(bKey, min, max, binaryToStringListConverter, args); + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRevRangeByScore(key, min, max, (v)->v, args); + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + + return zRevRangeByScore(bKey, min, max, offset, count, binaryToStringListConverter, args); + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRevRangeByScore(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max, + final long offset, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final Range range = Range.create(min, max); + final Limit limit = Limit.create(offset, count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + } + } + + @Override + public Long zRevRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANK, + (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + } + } + + @Override + public ScanResult> zScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public Double zScore(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZSCORE, + (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } + } + + @Override + public List zUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate); + + return zUnionStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(weights); + + return zUnionStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate, weights); + + return zUnionStore(destKey, keys, zStoreArgs, args); + } + + private com.buession.lang.KeyValue bzPopMin(final byte[][] keys, final int timeout, + final KeyValueConverter, K, + Tuple> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + converter) + .run(args); + } + } + + private com.buession.lang.KeyValue bzPopMax(final byte[][] keys, final int timeout, + final KeyValueConverter, + K, Tuple> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + converter) + .run(args); + } + } + + private Long zAdd(final String key, final Map members, final CommandArguments args) { + final byte[] bKey = SafeEncoder.encode(key); + return zAdd(bKey, ScoredValueUtils.fromStringMap(members), args); + } + + private Long zAdd(final String key, final Map members, final ZAddArgs zAddArgs, + final CommandArguments args) { + final byte[] bKey = SafeEncoder.encode(key); + return zAdd(bKey, ScoredValueUtils.fromStringMap(members), zAddArgs, args); + } + + private Long zAdd(final byte[] key, final Map members, final CommandArguments args) { + return zAdd(key, ScoredValueUtils.fromBinaryMap(members), args); + } + + private Long zAdd(final byte[] key, final Map members, final ZAddArgs zAddArgs, + final CommandArguments args) { + return zAdd(key, ScoredValueUtils.fromBinaryMap(members), zAddArgs, args); + } + + private Long zAdd(final byte[] key, final ScoredValue[] scoredValues, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, scoredValues), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, scoredValues), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, scoredValues), (v)->v) + .run(args); + } + } + + private Long zAdd(final byte[] key, final ScoredValue[] scoredValues, final ZAddArgs zAddArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, zAddArgs, scoredValues), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, zAddArgs, scoredValues), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, zAddArgs, scoredValues), (v)->v) + .run(args); + } + } + + private List zDiff(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, ProtocolCommand.ZDIFF) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, ProtocolCommand.ZDIFF) + .run(args); + }else{ + return new LettuceClusterCommand, List>(client, ProtocolCommand.ZDIFF) + .run(args); + } + } + + private Long zDiffStore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.ZDIFFSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.ZDIFFSTORE) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.ZDIFFSTORE) + .run(args); + } + } + + private List zInter(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, ProtocolCommand.ZINTER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, ProtocolCommand.ZINTER) + .run(args); + }else{ + return new LettuceClusterCommand, List>(client, ProtocolCommand.ZINTER) + .run(args); + } + } + + private Long zInterStore(final byte[] destKey, final byte[][] keys, final ZStoreArgs zStoreArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + } + } + + private List zMScore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, ProtocolCommand.ZMSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, ProtocolCommand.ZMSCORE) + .run(args); + }else{ + return new LettuceClusterCommand, List>(client, ProtocolCommand.ZMSCORE) + .run(args); + } + } + + private V zRandMember(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.ZRANDMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.ZRANDMEMBER) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.ZRANDMEMBER) + .run(args); + } + } + + private List zRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrange(key, start, end), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrange(key, start, end), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), + converter) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final Converter, List> converter, final CommandArguments args) { + return zRangeByLex(key, Range.create(min, max), converter, args); + } + + private List zRangeByLex(final byte[] key, final Range range, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZRANGEBYLEX, (cmd)->cmd.zrangebylex(key, range), + converter) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count, final Converter, List> converter, + final CommandArguments args) { + return zRangeByLex(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRangeByLex(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range, limit), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range, limit), converter) + .run(args); + } + } + + private List zRangeByScore(final byte[] key, final double min, final double max, + final Converter, List> converter, final CommandArguments args) { + return zRangeByScore(key, Range.create(min, max), converter, args); + } + + private List zRangeByScore(final byte[] key, final Range range, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range), converter) + .run(args); + } + } + + private List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final long count, final Converter, List> converter, + final CommandArguments args) { + return zRangeByScore(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRangeByScore(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range, limit), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range, limit), converter) + .run(args); + } + } + + private Long zRangeStore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.ZRANGESTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.ZRANGESTORE) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.ZRANGESTORE) + .run(args); + } + } + + private List zRevRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), + converter) + .run(args); + } + } + + private List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final Converter, List> converter, final CommandArguments args) { + return zRevRangeByLex(key, Range.create(min, max), converter, args); + } + + private List zRevRangeByLex(final byte[] key, final Range range, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range), converter) + .run(args); + } + } + + private List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count, final Converter, List> converter, + final CommandArguments args) { + return zRevRangeByLex(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRevRangeByLex(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range, limit), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range, limit), converter) + .run(args); + } + } + + private List zRevRangeByScore(final byte[] key, final double min, final double max, + final Converter, List> converter, + final CommandArguments args) { + return zRevRangeByScore(key, Range.create(min, max), converter, args); + } + + private List zRevRangeByScore(final byte[] key, final Range range, + final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range), converter) + .run(args); + } + } + + private List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final long count, final Converter, List> converter, + final CommandArguments args) { + return zRevRangeByScore(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRevRangeByScore(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range, limit), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range, limit), converter) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zscan(key, cursor), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZREVRANK, + (cmd)->cmd.zscan(key, cursor), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zscan(key, cursor), + converter) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanArgs), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanArgs), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanArgs), + converter) + .run(args); + } + } + + private List zUnion(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, ProtocolCommand.ZUNION) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, ProtocolCommand.ZUNION) + .run(args); + }else{ + return new LettuceClusterCommand, List>(client, ProtocolCommand.ZUNION) + .run(args); + } + } + + private Long zUnionStore(final byte[] destKey, final byte[][] keys, final ZStoreArgs zStoreArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterStreamOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterStreamOperations.java new file mode 100644 index 000000000..4170af103 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterStreamOperations.java @@ -0,0 +1,1199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.Stream; +import com.buession.redis.core.StreamConsumer; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import com.buession.redis.core.StreamGroup; +import com.buession.redis.core.StreamPending; +import com.buession.redis.core.StreamPendingSummary; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.params.StreamEntryIdConverter; +import com.buession.redis.core.internal.convert.lettuce.response.PendingMessageConverter; +import com.buession.redis.core.internal.convert.lettuce.response.PendingMessagesConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamConsumersInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamEntryIDConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamFullInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamGroupInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamMessageConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamMessageMapConverter; +import com.buession.redis.core.internal.lettuce.LettuceXAddArgs; +import com.buession.redis.core.internal.lettuce.LettuceXClaimArgs; +import com.buession.redis.core.internal.lettuce.LettuceXGroupCreateArgs; +import com.buession.redis.core.internal.lettuce.LettuceXPendingArgs; +import com.buession.redis.core.internal.lettuce.LettuceXReadArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.Consumer; +import io.lettuce.core.Limit; +import io.lettuce.core.Range; +import io.lettuce.core.StreamMessage; +import io.lettuce.core.XAddArgs; +import io.lettuce.core.XClaimArgs; +import io.lettuce.core.XGroupCreateArgs; +import io.lettuce.core.XReadArgs; +import io.lettuce.core.models.stream.PendingMessage; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 集群模式 Stream 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterStreamOperations extends AbstractStreamOperations { + + public LettuceClusterStreamOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("ids", (Object[]) ids); + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XACK, + (cmd)->cmd.xack(key, groupName, messageIds), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XACK, + (cmd)->cmd.xack(key, groupName, messageIds), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XACK, + (cmd)->cmd.xack(key, groupName, messageIds), (v)->v) + .run(args); + } + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash); + final XAddArgs xAddArgs = new LettuceXAddArgs(id); + + return xAdd(key, hash, xAddArgs, args); + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) + .put("xAddArgument", xAddArgument); + final StreamEntryIdConverter streamEntryIdConverter = new StreamEntryIdConverter(); + final XAddArgs xAddArgs = LettuceXAddArgs.from(xAddArgument).id(streamEntryIdConverter.convert(id)); + + return xAdd(key, hash, xAddArgs, args); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count"); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count"); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaimJustId(args); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = new LettuceXClaimArgs(minIdleTime); + + return xClaim(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = LettuceXClaimArgs.from(xClaimArgument).minIdleTime(minIdleTime); + + return xClaim(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = new LettuceXClaimArgs(minIdleTime, true); + + return xClaimJustId(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = LettuceXClaimArgs.from(xClaimArgument).minIdleTime(minIdleTime).justid(); + + return xClaimJustId(key, ids, consumer, xClaimArgs, args); + } + + @Override + public Long xDel(final byte[] key, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("ids", (Object[]) ids); + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XDEL, (cmd)->cmd.xdel(key, messageIds), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XDEL, + (cmd)->cmd.xdel(key, messageIds), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XDEL, (cmd)->cmd.xdel(key, messageIds), (v)->v) + .run(args); + } + } + + @Override + public Status xGroupCreate(final byte[] key, final byte[] groupName, final StreamEntryId id, + final boolean makeStream) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("id", id); + final XReadArgs.StreamOffset streamOffset = XReadArgs.StreamOffset.latest(key); + final XGroupCreateArgs xGroupCreateArgs = new LettuceXGroupCreateArgs(makeStream); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(streamOffset, groupName, xGroupCreateArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(streamOffset, groupName, xGroupCreateArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(streamOffset, groupName, xGroupCreateArgs), okStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + return xGroupCreateConsumer(args); + } + + @Override + public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + return xGroupCreateConsumer(args); + } + + @Override + public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelconsumer(key, consumer), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelconsumer(key, consumer), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelconsumer(key, consumer), (v)->v) + .run(args); + } + } + + @Override + public Status xGroupDestroy(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), booleanStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupSetId(final byte[] key, final byte[] groupName, final StreamEntryId id) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName).put("id", id); + final XReadArgs.StreamOffset streamOffset = XReadArgs.StreamOffset.from(key, id.toString()); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XGROUP_SETID, + (cmd)->cmd.xgroupSetid(streamOffset, groupName), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XGROUP_SETID, + (cmd)->cmd.xgroupSetid(streamOffset, groupName), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XGROUP_SETID, + (cmd)->cmd.xgroupSetid(streamOffset, groupName), okStatusConverter) + .run(args); + } + } + + @Override + public List xInfoConsumers(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + final ListConverter listStreamConsumersInfoConverter = StreamConsumersInfoConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + } + } + + @Override + public List xInfoGroups(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final ListConverter listStreamGroupInfoConverter = StreamGroupInfoConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XINFO_GROUPS, + (cmd)->cmd.xinfoGroups(key), listStreamGroupInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XINFO_GROUPS, + (cmd)->cmd.xinfoGroups(key), listStreamGroupInfoConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + } + } + + @Override + public Stream xInfoStream(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final StreamInfoConverter streamInfoConverter = new StreamInfoConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream( + key), streamInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream( + key), streamInfoConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream( + key), streamInfoConverter) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStream(key), streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStream(key), streamFullInfoConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full).put("count", count); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStream(key), streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XINFO_STREAM, + (cmd)->cmd.xinfoStream(key), streamFullInfoConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + } + } + + @Override + public Long xLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } + } + + @Override + public StreamPendingSummary xPending(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + final PendingMessagesConverter pendingMessagesConverter = new PendingMessagesConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName), pendingMessagesConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName), pendingMessagesConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XPENDING, (cmd)->cmd.xpending(key, groupName), + pendingMessagesConverter) + .run(args); + } + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime); + final LettuceXPendingArgs xPendingArgs = new LettuceXPendingArgs<>(minIdleTime, groupName, null); + final ListConverter listStreamPendingConverter = PendingMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, xPendingArgs), listStreamPendingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, xPendingArgs), listStreamPendingConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XPENDING, (cmd)->cmd.xpending(key, xPendingArgs), + listStreamPendingConverter) + .run(args); + } + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("start", start).put("end", end).put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, groupName, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.unbounded(); + final Limit limit = Limit.unlimited(); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("start", start).put("end", end).put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, groupName, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.unbounded(); + final Limit limit = Limit.unlimited(); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final long count, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final long count, + final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final Range range = Range.create(start.toString(), end.toString()); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XRANGE, (cmd)->cmd.xrange(key, range), + listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XRANGE, (cmd)->cmd.xrange(key, range), + listStreamMessageConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XRANGE, (cmd)->cmd.xrange(key, range), + listStreamMessageConverter) + .run(args); + } + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, range, limit), listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XRANGE, + (cmd)->cmd.xrange(key, range, limit), listStreamMessageConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XRANGE, (cmd)->cmd.xrange(key, range, limit), + listStreamMessageConverter) + .run(args); + } + } + + @Override + public List>> xRead(final Map streams) { + final CommandArguments args = CommandArguments.create("streams", streams); + return xRead(streams, args); + } + + @Override + public List>> xRead(final long count, final Map streams) { + final CommandArguments args = CommandArguments.create("count", count).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(count); + + return xRead(xReadArgs, streams, args); + } + + @Override + public List>> xRead(final int block, final Map streams) { + final CommandArguments args = CommandArguments.create("block", block).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block); + + return xRead(xReadArgs, streams, args); + } + + @Override + public List>> xRead(final long count, final int block, + final Map streams) { + final CommandArguments args = CommandArguments.create("count", count).put("block", block) + .put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block, count); + + return xRead(xReadArgs, streams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams); + return xReadGroup(groupName, consumerName, streams, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams); + return xReadGroup(groupName, consumerName, streams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final long count, final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final long count, final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final int block, final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("block", block).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final int block, final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("block", block).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = (new LettuceXReadArgs()).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = (new LettuceXReadArgs()).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final long count, final int block, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("block", block).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final long count, final int block, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("block", block).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final long count, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(isNoAck, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final long count, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(isNoAck, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final int block, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("block", block).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = (new LettuceXReadArgs()).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final int block, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("block", block).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = (new LettuceXReadArgs()).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final long count, final int block, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("block", block).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block, isNoAck, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final long count, final int block, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("block", block).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block, isNoAck, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start); + final Range range = Range.create(start.toString(), end.toString()); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, range), listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, range), listStreamMessageConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XREVRANGE, (cmd)->cmd.xrevrange(key, range), + listStreamMessageConverter) + .run(args); + } + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start) + .put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, range, limit), listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, range, limit), listStreamMessageConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, range, limit), listStreamMessageConverter) + .run(args); + } + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); + return xTrim(key, xTrimArgument.isApproximateTrimming(), Long.MAX_VALUE, args); + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) + .put("limit", limit); + return xTrim(key, xTrimArgument.isApproximateTrimming(), limit, args); + } + + private StreamEntryId xAdd(final byte[] key, final Map hash, final XAddArgs xAddArgs, + final CommandArguments args) { + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XADD, + (cmd)->cmd.xadd(key, xAddArgs, hash), streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XADD, + (cmd)->cmd.xadd(key, xAddArgs, hash), streamEntryIDConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, xAddArgs, hash), + streamEntryIDConverter) + .run(args); + } + } + + private Map> xAutoClaim(final CommandArguments args) { + + if(isPipeline()){ + return new LettuceClusterPipelineCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + }else{ + return new LettuceClusterCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + } + } + + private Map> xAutoClaimJustId(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + }else{ + return new LettuceClusterCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + } + } + + private List xClaim(final byte[] key, final StreamEntryId[] ids, final Consumer consumer, + final XClaimArgs xClaimArgs, final CommandArguments args) { + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageConverter) + .run(args); + } + } + + private List xClaimJustId(final byte[] key, final StreamEntryId[] ids, + final Consumer consumer, final XClaimArgs xClaimArgs, + final CommandArguments args) { + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter, StreamEntryId> listStreamMessageStreamEntryIdConverter + = StreamMessageConverter.StreamMessageStreamEntryIdConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageStreamEntryIdConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageStreamEntryIdConverter) + .run(args); + } + } + + private Status xGroupCreateConsumer(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.XGROUP_CREATECONSUMER) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.XGROUP_CREATECONSUMER) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.XGROUP_CREATECONSUMER) + .run(args); + } + } + + private List xPending(final byte[] key, final byte[] groupName, Range range, + final Limit limit, final CommandArguments args) { + final ListConverter listStreamPendingConverter = PendingMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName, range, limit), listStreamPendingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName, range, limit), listStreamPendingConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName, range, limit), listStreamPendingConverter) + .run(args); + } + } + + private List xPending(final byte[] key, final Consumer consumer, Range range, + final Limit limit, final CommandArguments args) { + final ListConverter listStreamPendingConverter = PendingMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, consumer, range, limit), listStreamPendingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, consumer, range, limit), listStreamPendingConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, consumer, range, limit), listStreamPendingConverter) + .run(args); + } + } + + private List>> xRead(final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = createStreamOffsetFromStreamEntryIdMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XREAD, (cmd)->cmd.xread(streamOffsets), + listStreamMessageMapConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XREAD, + (cmd)->cmd.xread(streamOffsets), listStreamMessageMapConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XREAD, (cmd)->cmd.xread(streamOffsets), + listStreamMessageMapConverter) + .run(args); + } + } + + private List>> xRead(final XReadArgs xReadArgs, final Map streams, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = createStreamOffsetFromStreamEntryIdMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XREAD, + (cmd)->cmd.xread(xReadArgs, streamOffsets), listStreamMessageMapConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XREAD, + (cmd)->cmd.xread(xReadArgs, streamOffsets), listStreamMessageMapConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XREAD, + (cmd)->cmd.xread(xReadArgs, streamOffsets), listStreamMessageMapConverter) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = createStreamOffsetFromStreamEntryIdMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), streamOffsets, + listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = createStreamOffsetFromBinaryStreamEntryIdMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(groupName, consumerName, streamOffsets, listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final XReadArgs.StreamOffset[] streamOffsets, + final Converter>, + List>>> converter, + final CommandArguments args) { + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, streamOffsets), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, streamOffsets), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, streamOffsets), converter) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadArgs xReadArgs, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = new XReadArgs.StreamOffset[streams.size()]; + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + int i = 0; + + for(Map.Entry e : streams.entrySet()){ + streamOffsets[i++] = XReadArgs.StreamOffset.from(SafeEncoder.encode(e.getKey()), e.getValue().toString()); + } + + return xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), streamOffsets, xReadArgs, + listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final XReadArgs xReadArgs, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = new XReadArgs.StreamOffset[streams.size()]; + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + int i = 0; + + for(Map.Entry e : streams.entrySet()){ + streamOffsets[i++] = XReadArgs.StreamOffset.from(e.getKey(), e.getValue().toString()); + } + + return xReadGroup(groupName, consumerName, streamOffsets, xReadArgs, listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final XReadArgs.StreamOffset[] streamOffsets, + final XReadArgs xReadArgs, + final Converter>, + List>>> converter, + final CommandArguments args) { + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, xReadArgs, streamOffsets), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, xReadArgs, streamOffsets), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, xReadArgs, streamOffsets), converter) + .run(args); + } + } + + private Long xTrim(final byte[] key, final boolean approximateTrimming, final long limit, + final CommandArguments args) { + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.XTRIM, + (cmd)->cmd.xtrim(key, approximateTrimming, limit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.XTRIM, + (cmd)->cmd.xtrim(key, approximateTrimming, limit), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.XTRIM, + (cmd)->cmd.xtrim(key, approximateTrimming, limit), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterStringOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterStringOperations.java new file mode 100644 index 000000000..0718e1162 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterStringOperations.java @@ -0,0 +1,528 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.StringUtils; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.lettuce.LettuceSetArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyValue; +import io.lettuce.core.SetArgs; +import io.lettuce.core.Value; + +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; + +/** + * Lettuce 集群模式字符串命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterStringOperations extends AbstractStringOperations { + + public LettuceClusterStringOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public Long append(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long incr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } + } + + @Override + public Long incrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrby(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrby(key, value), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrby(key, value), (v)->v) + .run(args); + } + } + + @Override + public Double incrByFloat(final byte[] key, final double value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.INCRBYFLOAT, + (cmd)->cmd.incrbyfloat(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.INCRBYFLOAT, + (cmd)->cmd.incrbyfloat(key, value), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.INCRBYFLOAT, (cmd)->cmd.incrbyfloat(key, value), + (v)->v) + .run(args); + } + } + + @Override + public Long decr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } + } + + @Override + public Long decrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrby(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrby(key, value), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrby(key, value), (v)->v) + .run(args); + } + } + + @Override + public String get(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return get(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] get(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return get(key, (v)->v, args); + } + + @Override + public String getEx(final String key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + return getEx(args); + } + + @Override + public byte[] getEx(final byte[] key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + return getEx(args); + } + + @Override + public String getSet(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bValue = SafeEncoder.encode(value); + + return getSet(bKey, bValue, SafeEncoder::encode, args); + } + + @Override + public byte[] getSet(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return getSet(key, value, (v)->v, args); + } + + @Override + public String getDel(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + return getDel(args); + } + + @Override + public byte[] getDel(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return getDel(args); + } + + @Override + public List mGet(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final ListConverter, String> listConverter = + new ListConverter<>((v)->SafeEncoder.encode(v.getValue())); + + return mGet(bKeys, listConverter, args); + } + + @Override + public List mGet(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ListConverter, byte[]> listConverter = new ListConverter<>(Value::getValue); + + return mGet(keys, listConverter, args); + } + + @Override + public Status mSet(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final Map bValues = Converters.mapStringToBinary().convert(values); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.MSET, (cmd)->cmd.mset(bValues), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.MSET, (cmd)->cmd.mset(bValues), + okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.MSET, (cmd)->cmd.mset(bValues), + okStatusConverter) + .run(args); + } + } + + @Override + public Status mSetNx(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final Map bValues = Converters.mapStringToBinary().convert(values); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.MSETNX, (cmd)->cmd.msetnx(bValues), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.MSETNX, (cmd)->cmd.msetnx(bValues), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.MSETNX, (cmd)->cmd.msetnx(bValues), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pSetEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value, final SetArgument setArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final SetArgs setArgs = LettuceSetArgs.from(setArgument); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setArgs), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SET, + (cmd)->cmd.set(key, value, setArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setArgs), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setNx(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Long setRange(final byte[] key, final long offset, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + } + } + + @Override + public byte[] getRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + } + } + + @Override + public Long strlen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), + (v)->v) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } + } + + @Override + public String substr(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + final Converter converter = (v)->StringUtils.substring(SafeEncoder.encode(v), + (int) start, (int) end); + + return substr(bKey, converter, args); + } + + @Override + public byte[] substr(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final Converter converter = (v)->StringUtils.substring(SafeEncoder.encode(v), (int) start, + (int) end).getBytes(StandardCharsets.UTF_8); + + return substr(key, converter, args); + } + + private V get(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), converter) + .run(args); + } + } + + private V getEx(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.GETEX) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.GETEX) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.GETEX) + .run(args); + } + } + + private V getSet(final byte[] key, final byte[] value, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getset(key, value), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getset(key, value), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getset(key, value), converter) + .run(args); + } + } + + private V getDel(final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.GETDEL) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.GETDEL) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.GETDEL) + .run(args); + } + } + + private List mGet(final byte[][] keys, final Converter>, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), converter) + .run(args); + } + } + + private V substr(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceClusterPipelineCommand<>(client, ProtocolCommand.SUBSTR, (cmd)->cmd.get(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand<>(client, ProtocolCommand.SUBSTR, (cmd)->cmd.get(key), + converter) + .run(args); + }else{ + return new LettuceClusterCommand<>(client, ProtocolCommand.SUBSTR, (cmd)->cmd.get(key), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterTransactionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterTransactionOperations.java new file mode 100644 index 000000000..740e19499 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceClusterTransactionOperations.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; + +import java.util.List; + +/** + * Lettuce 集群模式事务命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceClusterTransactionOperations extends AbstractTransactionOperations { + + public LettuceClusterTransactionOperations(final LettuceClusterClient client) { + super(client); + } + + @Override + public void discard() { + if(isPipeline()){ + new LettuceClusterPipelineCommand<>(client, ProtocolCommand.DISCARD) + .run(); + }else if(isTransaction()){ + new LettuceClusterTransactionCommand<>(client, ProtocolCommand.DISCARD) + .run(); + }else{ + new LettuceClusterCommand<>(client, ProtocolCommand.DISCARD) + .run(); + } + } + + @Override + public List exec() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand, List>(client, ProtocolCommand.MULTI) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand, List>(client, ProtocolCommand.MULTI) + .run(); + }else{ + return new LettuceClusterCommand, List>(client, ProtocolCommand.MULTI) + .run(); + } + } + + @Override + public Status multi() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.MULTI) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.MULTI) + .run(); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.MULTI) + .run(); + } + } + + @Override + public Status unwatch() { + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.UNWATCH) + .run(); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.UNWATCH) + .run(); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.UNWATCH) + .run(); + } + } + + @Override + public Status watch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceClusterPipelineCommand(client, ProtocolCommand.WATCH) + .run(args); + }else if(isTransaction()){ + return new LettuceClusterTransactionCommand(client, ProtocolCommand.WATCH) + .run(args); + }else{ + return new LettuceClusterCommand(client, ProtocolCommand.WATCH) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceConnectionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceConnectionOperations.java new file mode 100644 index 000000000..2ea5f09dd --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceConnectionOperations.java @@ -0,0 +1,426 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.Client; +import com.buession.redis.core.ClientReply; +import com.buession.redis.core.ClientType; +import com.buession.redis.core.ClientUnblockType; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.params.ClientUnblockTypeConverter; +import com.buession.redis.core.internal.convert.response.ClientConverter; +import com.buession.redis.core.internal.convert.response.PingResultConverter; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.UnblockType; +import io.lettuce.core.codec.ByteArrayCodec; +import io.lettuce.core.output.StatusOutput; +import io.lettuce.core.protocol.CommandArgs; +import io.lettuce.core.protocol.CommandKeyword; +import io.lettuce.core.protocol.CommandType; + +import java.util.List; + +/** + * Lettuce 单机模式连接命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceConnectionOperations extends AbstractConnectionOperations { + + public LettuceConnectionOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Status auth(final String user, final String password) { + final CommandArguments args = CommandArguments.create("user", user).put("password", password); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.AUTH, + (cmd)->client.getConnection().getStatefulConnection().async().dispatch(CommandType.AUTH, + new StatusOutput<>(ByteArrayCodec.INSTANCE), + new CommandArgs<>(ByteArrayCodec.INSTANCE).add(password)), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.AUTH, + (cmd)->client.getConnection().getStatefulConnection().async().dispatch(CommandType.AUTH, + new StatusOutput<>(ByteArrayCodec.INSTANCE), + new CommandArgs<>(ByteArrayCodec.INSTANCE).add(password)), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.AUTH, (cmd)->cmd.auth(password), okStatusConverter) + .run(args); + } + } + + @Override + public Status auth(final String password) { + final CommandArguments args = CommandArguments.create("password", password); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.AUTH, + (cmd)->client.getConnection().getStatefulConnection().async().dispatch(CommandType.AUTH, + new StatusOutput<>(ByteArrayCodec.INSTANCE), + new CommandArgs<>(ByteArrayCodec.INSTANCE).add(password)), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.AUTH, + (cmd)->client.getConnection().getStatefulConnection().async().dispatch(CommandType.AUTH, + new StatusOutput<>(ByteArrayCodec.INSTANCE), + new CommandArgs<>(ByteArrayCodec.INSTANCE).add(password)), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.AUTH, (cmd)->cmd.auth(password), okStatusConverter) + .run(args); + } + } + + @Override + public String echo(final String str) { + final CommandArguments args = CommandArguments.create("str", str); + final byte[] msg = SafeEncoder.encode(str); + + return echo(msg, SafeEncoder::encode, args); + } + + @Override + public byte[] echo(final byte[] str) { + final CommandArguments args = CommandArguments.create("str", str); + return echo(str, (v)->v, args); + } + + @Override + public Status ping() { + final PingResultConverter pingResultConverter = new PingResultConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.ping(), pingResultConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.ping(), pingResultConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.ping(), pingResultConverter) + .run(); + } + } + + @Override + public Status reset() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.RESET, + (cmd)->client.getConnection().getStatefulConnection().async().dispatch(CommandKeyword.RESET, + new StatusOutput<>(ByteArrayCodec.INSTANCE), + new CommandArgs<>(ByteArrayCodec.INSTANCE)), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.RESET, + (cmd)->client.getConnection().getStatefulConnection().async().dispatch(CommandKeyword.RESET, + new StatusOutput<>(ByteArrayCodec.INSTANCE), + new CommandArgs<>(ByteArrayCodec.INSTANCE)), okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.RESET, (cmd)->{ + cmd.reset(); + return Status.SUCCESS; + }, (v)->v) + .run(); + } + } + + @Override + public Status quit() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.QUIT, (cmd)->cmd.quit(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.QUIT, (cmd)->cmd.quit(), okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.QUIT, (cmd)->cmd.quit(), okStatusConverter) + .run(); + } + } + + @Override + public Status select(final int db) { + final CommandArguments args = CommandArguments.create("db", db); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SELECT, + (cmd)->client.getConnection().getStatefulConnection().async().dispatch(CommandType.SELECT, + new StatusOutput<>(ByteArrayCodec.INSTANCE), + new CommandArgs<>(ByteArrayCodec.INSTANCE).add(db)), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SELECT, + (cmd)->client.getConnection().getStatefulConnection().async().dispatch(CommandType.SELECT, + new StatusOutput<>(ByteArrayCodec.INSTANCE), + new CommandArgs<>(ByteArrayCodec.INSTANCE).add(db)), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SELECT, (cmd)->cmd.select(db), okStatusConverter) + .run(args); + } + } + + @Override + public Status clientCaching(final boolean isYes) { + final CommandArguments args = CommandArguments.create("isYes", isYes); + + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + } + } + + @Override + public Long clientId() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLIENT_ID, (cmd)->cmd.clientId(), (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLIENT_ID, (cmd)->cmd.clientId(), (v)->v) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLIENT_ID, (cmd)->cmd.clientId(), (v)->v) + .run(); + } + } + + @Override + public Status clientSetName(final byte[] name) { + final CommandArguments args = CommandArguments.create("name", name); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLIENT_SETNAME, (cmd)->cmd.clientSetname(name), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLIENT_SETNAME, (cmd)->cmd.clientSetname(name), + okStatusConverter) + .run(args); + } + } + + @Override + public String clientGetName() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLIENT_GETNAME, (cmd)->cmd.clientGetname(), + SafeEncoder::encode) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLIENT_GETNAME, (cmd)->cmd.clientGetname(), + SafeEncoder::encode) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLIENT_GETNAME, (cmd)->cmd.clientGetname(), + SafeEncoder::encode) + .run(); + } + } + + @Override + public Integer clientGetRedir() { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + }else{ + return new LettuceCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + } + } + + @Override + public List clientList() { + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + } + } + + @Override + public List clientList(final ClientType clientType) { + final CommandArguments args = CommandArguments.create("clientType", clientType); + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(args); + } + } + + @Override + public Client clientInfo() { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.CLIENT_INFO) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.CLIENT_INFO) + .run(); + }else{ + return new LettuceCommand(client, ProtocolCommand.CLIENT_INFO) + .run(); + } + } + + @Override + public Status clientPause(final int timeout) { + final CommandArguments args = CommandArguments.create("timeout", timeout); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLIENT_PAUSE, (cmd)->cmd.clientPause(timeout), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLIENT_PAUSE, (cmd)->cmd.clientPause(timeout), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clientReply(final ClientReply option) { + final CommandArguments args = CommandArguments.create("option", option); + + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + } + } + + @Override + public Status clientKill(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + final String addr = host + ':' + port; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLIENT_KILL, (cmd)->cmd.clientKill(addr), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLIENT_KILL, (cmd)->cmd.clientKill(addr), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLIENT_KILL, (cmd)->cmd.clientKill(addr), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clientUnblock(final int clientId) { + final CommandArguments args = CommandArguments.create("clientId", clientId); + return clientUnblock(clientId, UnblockType.ERROR, args); + } + + @Override + public Status clientUnblock(final int clientId, final ClientUnblockType type) { + final CommandArguments args = CommandArguments.create("clientId", clientId).put("type", type); + final UnblockType unblockType = (new ClientUnblockTypeConverter()).convert(type); + + return clientUnblock(clientId, unblockType, args); + } + + private V echo(final byte[] str, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.echo(str), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.echo(str), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.echo(str), converter) + .run(args); + } + } + + private Status clientUnblock(final int clientId, final UnblockType unblockType, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CLIENT_KILL, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CLIENT_KILL, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CLIENT_KILL, + (cmd)->cmd.clientUnblock(clientId, unblockType), oneStatusConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceGenericOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceGenericOperations.java new file mode 100644 index 000000000..337c459e4 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceGenericOperations.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.KeyValue; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; + +/** + * Lettuce 单机模式一般命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceGenericOperations extends AbstractGenericOperations { + + public LettuceGenericOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Long wait(final int replicas, final int timeout) { + final CommandArguments args = CommandArguments.create(replicas).add(timeout); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.WAIT, + (cmd)->cmd.waitForReplication(replicas, timeout), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.WAIT, + (cmd)->cmd.waitForReplication(replicas, timeout), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.WAIT, (cmd)->cmd.waitForReplication(replicas, timeout), + (v)->v) + .run(args); + } + } + + @Override + public KeyValue waitOf(final int locals, final int replicas, final int timeout) { + final CommandArguments args = CommandArguments.create(locals).add(replicas).add(timeout); + return notCommand(client, ProtocolCommand.WAITOF, args); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceGeoOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceGeoOperations.java new file mode 100644 index 000000000..7b605d67d --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceGeoOperations.java @@ -0,0 +1,409 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.builder.ListBuilder; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.SetListConverter; +import com.buession.lang.Geo; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.params.GeoUnitConverter; +import com.buession.redis.core.internal.convert.lettuce.response.GeoCoordinateConverter; +import com.buession.redis.core.internal.convert.lettuce.response.GeoRadiusGeneralResultConverter; +import com.buession.redis.core.internal.convert.lettuce.response.GeoRadiusResponseConverter; +import com.buession.redis.core.internal.lettuce.LettuceGeoArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.GeoArgs; +import io.lettuce.core.GeoCoordinates; +import io.lettuce.core.GeoWithin; +import io.lettuce.core.Value; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 单机模式地理位置命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceGeoOperations extends AbstractGeoOperations { + + public LettuceGeoOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member) + .put("longitude", longitude).put("latitude", latitude); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, longitude, latitude, member), (v)->v) + .run(args); + } + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create("key", key).put("memberCoordinates", memberCoordinates); + return geoAdd(key, memberCoordinates, args); + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create("key", key).put("memberCoordinates", memberCoordinates); + return geoAdd(key, memberCoordinates, args); + } + + @Override + public List geoHash(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + final byte[] bKey = SafeEncoder.encode(key); + final byte[][] bMembers = SafeEncoder.encode(members); + final ListConverter, String> listConverter = new ListConverter<>(Value::getValue); + + return geoHash(bKey, bMembers, listConverter, args); + } + + @Override + public List geoHash(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + final ListConverter, byte[]> listConverter = new ListConverter<>( + (v)->SafeEncoder.encode(v.getValue())); + + return geoHash(key, members, listConverter, args); + } + + @Override + public List geoPos(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.GEOPOS, (cmd)->cmd.geopos(key, members), + listGeoCoordinateConverter) + .run(args); + } + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2) { + final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) + .put("member2", member2); + return geoDist(key, member1, member2, GeoArgs.Unit.m, args); + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) + .put("member2", member2).put("unit", unit); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + + return geoDist(key, member1, member2, geoArgsUnit, args); + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final SetListConverter setListGeoRadiusGeneralResultConverter = + GeoRadiusGeneralResultConverter.setListConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + } + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit) + .put("geoRadiusArgument", geoRadiusArgument); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final GeoArgs geoArgs = LettuceGeoArgs.from(geoRadiusArgument); + final ListConverter, GeoRadius> listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.GEORADIUS, + (cmd)->cmd.georadius(key, longitude, latitude, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit); + return geoRadiusRo(args); + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit); + return geoRadiusRo(args); + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit) + .put("geoRadiusArgument", geoRadiusArgument); + return geoRadiusRo(args); + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit) + .put("geoRadiusArgument", geoRadiusArgument); + return geoRadiusRo(args); + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final SetListConverter setListGeoRadiusGeneralResultConverter = + GeoRadiusGeneralResultConverter.setListConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit), + setListGeoRadiusGeneralResultConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final GeoArgs geoArgs = LettuceGeoArgs.from(geoRadiusArgument); + final ListConverter, GeoRadius> listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.GEORADIUSBYMEMBER, + (cmd)->cmd.georadiusbymember(key, member, radius, geoArgsUnit, geoArgs), + listGeoRadiusResponseConverter) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit); + return geoRadiusByMemberRo(args); + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit); + return geoRadiusByMemberRo(args); + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); + return geoRadiusByMemberRo(args); + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); + return geoRadiusByMemberRo(args); + } + + @Override + protected Long geoAdd(final byte[] key, final ListBuilder lngLatMemberBuilder, + final CommandArguments args) { + final Object[] lngLatMembers = lngLatMemberBuilder.build().toArray(new Object[]{}); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, lngLatMembers), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.GEOADD, + (cmd)->cmd.geoadd(key, lngLatMembers), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.GEOADD, (cmd)->cmd.geoadd(key, lngLatMembers), (v)->v) + .run(args); + } + } + + private List geoHash(final byte[] key, final byte[][] members, + final ListConverter, V> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.GEOHASH, (cmd)->cmd.geohash(key, members), converter) + .run(args); + } + } + + private Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoArgs.Unit unit, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, unit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, unit), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.GEODIST, + (cmd)->cmd.geodist(key, member1, member2, unit), (v)->v) + .run(args); + } + } + + private List geoRadiusRo(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, ProtocolCommand.GEORADIUS_RO) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, ProtocolCommand.GEORADIUS_RO) + .run(args); + }else{ + return new LettuceCommand, List>(client, ProtocolCommand.GEORADIUS_RO) + .run(args); + } + } + + private List geoRadiusByMemberRo(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, + ProtocolCommand.GEORADIUSBYMEMBER_RO) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, + ProtocolCommand.GEORADIUSBYMEMBER_RO) + .run(args); + }else{ + return new LettuceCommand, List>(client, ProtocolCommand.GEORADIUSBYMEMBER_RO) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceHashOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceHashOperations.java new file mode 100644 index 000000000..774b4d47b --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceHashOperations.java @@ -0,0 +1,546 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.ListSetConverter; +import com.buession.core.converter.MapConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyValue; +import io.lettuce.core.MapScanCursor; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.Value; + +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Lettuce 单机模式模式哈希表命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceHashOperations extends AbstractHashOperations { + + public LettuceHashOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Long hDel(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HDEL, (cmd)->cmd.hdel(key, fields), (v)->v) + .run(args); + } + } + + @Override + public Boolean hExists(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HEXISTS, (cmd)->cmd.hexists(key, field), (v)->v) + .run(args); + } + } + + @Override + public String hGet(final String key, final String field) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bField = SafeEncoder.encode(field); + + return hGet(bKey, bField, SafeEncoder::encode, args); + } + + @Override + public byte[] hGet(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field); + return hGet(key, field, (v)->v, args); + } + + @Override + public Map hGetAll(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + final MapConverter binaryToStringMapConverter = Converters.mapBinaryToString(); + + return hGetAll(bKey, binaryToStringMapConverter, args); + } + + @Override + public Map hGetAll(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return hGetAll(key, (v)->v, args); + } + + @Override + public Long hIncrBy(final byte[] key, final byte[] field, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HINCRBY, (cmd)->cmd.hincrby(key, field, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HINCRBY, + (cmd)->cmd.hincrby(key, field, value), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HINCRBY, (cmd)->cmd.hincrby(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Double hIncrByFloat(final byte[] key, final byte[] field, final double value) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrbyfloat(key, field, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrbyfloat(key, field, value), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HINCRBYFLOAT, + (cmd)->cmd.hincrbyfloat(key, field, value), (v)->v) + .run(args); + } + } + + @Override + public Set hKeys(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + final ListSetConverter binaryToStringListSetConverter = + Converters.listSetBinaryToString(); + + return hKeys(bKey, binaryToStringListSetConverter, args); + } + + @Override + public Set hKeys(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return hKeys(key, HashSet::new, args); + } + + @Override + public Long hLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HLEN, (cmd)->cmd.hlen(key), (v)->v) + .run(args); + } + } + + @Override + public List hMGet(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); + final byte[] bKey = SafeEncoder.encode(key); + final byte[][] bFields = SafeEncoder.encode(fields); + final ListConverter, String> listConverter = + new ListConverter<>((v)->SafeEncoder.encode(v.getValue())); + + return hMGet(bKey, bFields, listConverter, args); + } + + @Override + public List hMGet(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); + final ListConverter, byte[]> listConverter = new ListConverter<>(Value::getValue); + + return hMGet(key, fields, listConverter, args); + } + + @Override + public Status hMSet(final byte[] key, final Map data) { + final CommandArguments args = CommandArguments.create("key", key).put("data", data); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmset(key, data), okStatusConverter) + .run(args); + } + } + + @Override + public String hRandField(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + return hRandField(args); + } + + @Override + public byte[] hRandField(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return hRandField(args); + } + + @Override + public List hRandField(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return hRandField(args); + } + + @Override + public List hRandField(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return hRandField(args); + } + + @Override + public Map hRandFieldWithValues(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return hRandField(args); + } + + @Override + public Map hRandFieldWithValues(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return hRandField(args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, mapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, scanArgs, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, scanArgs, mapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, scanArgs, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, scanArgs, mapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor, final String pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, scanArgs, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, scanArgs, mapScanCursorConverter, args); + } + + @Override + public Long hSet(final byte[] key, final byte[] field, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); + final Converter converter = (v)->Boolean.TRUE.equals(v) ? 1L : 0L; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HSET, (cmd)->cmd.hset(key, field, value), converter) + .run(args); + } + } + + @Override + public Status hSetNx(final byte[] key, final byte[] field, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hsetnx(key, field, value), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Long hStrLen(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hstrlen(key, field), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HSETNX, (cmd)->cmd.hstrlen(key, field), (v)->v) + .run(args); + } + } + + @Override + public List hVals(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return hVals(bKey, binaryToStringListConverter, args); + } + + @Override + public List hVals(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return hVals(key, (v)->v, args); + } + + private V hGet(final byte[] key, final byte[] field, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HGET, (cmd)->cmd.hget(key, field), converter) + .run(args); + } + } + + private Map hGetAll(final byte[] key, final Converter, Map> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetall(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetall(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HGETALL, (cmd)->cmd.hgetall(key), converter) + .run(args); + } + } + + private Set hKeys(final byte[] key, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HKEYS, (cmd)->cmd.hkeys(key), converter) + .run(args); + } + } + + private List hMGet(final byte[] key, final byte[][] fields, + final Converter>, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HMGET, (cmd)->cmd.hmget(key, fields), converter) + .run(args); + } + } + + private TV hRandField(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.HRANDFIELD) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.HRANDFIELD) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.HRANDFIELD) + .run(args); + } + } + + private ScanResult> hScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor), converter) + .run(args); + } + } + + private ScanResult> hScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor, scanArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HSCAN, + (cmd)->cmd.hscan(key, cursor, scanArgs), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HSCAN, (cmd)->cmd.hscan(key, cursor, scanArgs), + converter) + .run(args); + } + } + + private List hVals(final byte[] key, final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.HVALS, (cmd)->cmd.hvals(key), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceHyperLogLogOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceHyperLogLogOperations.java new file mode 100644 index 000000000..11c44fd3c --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceHyperLogLogOperations.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; + +/** + * Lettuce 单机模式 HyperLogLog 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceHyperLogLogOperations extends AbstractHyperLogLogOperations { + + public LettuceHyperLogLogOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Status pfAdd(final byte[] key, final byte[]... elements) { + final CommandArguments args = CommandArguments.create("key", key).put("elements", (Object[]) elements); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.PFADD, (cmd)->cmd.pfadd(key, elements), + oneStatusConverter) + .run(args); + } + } + + @Override + public Status pfMerge(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfmerge(destKey, keys), + okStatusConverter) + .run(args); + } + } + + @Override + public Long pfCount(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.PFMERGE, (cmd)->cmd.pfcount(keys), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceKeyOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceKeyOperations.java new file mode 100644 index 000000000..52333b10c --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceKeyOperations.java @@ -0,0 +1,918 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListSetConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.MigrateOperation; +import com.buession.redis.core.ObjectEncoding; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Type; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.convert.response.ObjectEncodingConverter; +import com.buession.redis.core.internal.convert.response.TypeConverter; +import com.buession.redis.core.internal.lettuce.LettuceMigrateArgs; +import com.buession.redis.core.internal.lettuce.LettuceRestoreArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.core.internal.lettuce.LettuceSortArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyScanCursor; +import io.lettuce.core.MigrateArgs; +import io.lettuce.core.RestoreArgs; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.SortArgs; + +import java.util.List; +import java.util.Set; + +/** + * Lettuce 单机模式 Key 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceKeyOperations extends AbstractKeyOperations { + + public LettuceKeyOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Long del(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.DEL, (cmd)->cmd.del(keys), (v)->v) + .run(args); + } + } + + @Override + public byte[] dump(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.DUMP, (cmd)->cmd.dump(key), (v)->v) + .run(args); + } + } + + @Override + public Boolean exists(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v == 1L) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v == 1L) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(key), (v)->v == 1L) + .run(args); + } + } + + @Override + public Long exists(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.EXISTS, (cmd)->cmd.exists(keys), (v)->v) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.EXPIRE, + (cmd)->cmd.expire(key, lifetime), booleanStatusConverter) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime) + .put("expireOption", expireOption); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.EXPIRE, (cmd)->cmd.expire(key, lifetime), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.expireat(key, unixTimestamp), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.expireat(key, unixTimestamp), booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.EXPIREAT, (cmd)->cmd.expireat(key, unixTimestamp), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pExpire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.PEXPIRE, (cmd)->cmd.pexpire(key, lifetime), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.pexpireat(key, unixTimestamp), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.pexpireat(key, unixTimestamp), booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.EXPIREAT, + (cmd)->cmd.pexpireat(key, unixTimestamp), booleanStatusConverter) + .run(args); + } + } + + @Override + public Status persist(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.PERSIST, (cmd)->cmd.persist(key), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Long ttl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.TTL, (cmd)->cmd.ttl(key), (v)->v) + .run(args); + } + } + + @Override + public Long pTtl(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.PTTL, (cmd)->cmd.pttl(key), (v)->v) + .run(args); + } + } + + @Override + public Status copy(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + return copy(args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + return copy(args); + } + + @Override + public Status copy(final String key, final String destKey, final int db) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("db", db); + return copy(args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("db", db); + return copy(args); + } + + @Override + public Status copy(final String key, final String destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("replace", replace); + return copy(args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("replace", replace); + return copy(args); + } + + @Override + public Status copy(final String key, final String destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("db", db) + .put("replace", replace); + return copy(args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("db", db).put("replace", replace); + return copy(args); + } + + @Override + public Status move(final byte[] key, final int db) { + final CommandArguments args = CommandArguments.create("key", key).put("db", db); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.MOVE, (cmd)->cmd.move(key, db), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.MOVE, (cmd)->cmd.move(key, db), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.MOVE, (cmd)->cmd.move(key, db), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... + keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("timeout", timeout).put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(keys); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateOperation operation, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("timeout", timeout).put("operation", operation).put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(operation, keys); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final byte[] password, + final int timeout, + final byte[]... keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("password", password).put("timeout", timeout).put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(keys, password); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final byte[] password, + final int timeout, + final MigrateOperation operation, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("password", password).put("timeout", timeout).put("operation", operation) + .put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(operation, keys, password); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final byte[] user, + final byte[] password, + final int timeout, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("user", user).put("password", password).put("timeout", timeout) + .put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(keys, user, password); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final byte[] user, + final byte[] password, + final int timeout, final MigrateOperation operation, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("user", user).put("password", password).put("timeout", timeout) + .put("operation", operation) + .put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(keys, user, password); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Set keys(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final byte[] bPattern = SafeEncoder.encode(pattern); + final ListSetConverter binaryToStringListSetConverter = + Converters.listSetBinaryToString(); + + return keys(bPattern, binaryToStringListSetConverter, args); + } + + @Override + public Set keys(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final ListSetConverter converter = new ListSetConverter<>((v)->v); + + return keys(pattern, converter, args); + } + + @Override + public String randomKey() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.RANDOMKEY, (cmd)->cmd.randomkey(), + SafeEncoder::encode) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.RANDOMKEY, (cmd)->cmd.randomkey(), + SafeEncoder::encode) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.RANDOMKEY, (cmd)->cmd.randomkey(), + SafeEncoder::encode) + .run(); + } + } + + @Override + public Status rename(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.RENAME, (cmd)->cmd.rename(key, newKey), + okStatusConverter) + .run(args); + } + } + + @Override + public Status renameNx(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.RENAMENX, (cmd)->cmd.renamenx(key, newKey), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl) { + final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) + .put("ttl", ttl); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, ttl, serializedValue), okStatusConverter) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl, + final RestoreArgument argument) { + final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) + .put("ttl", ttl).put("argument", argument); + final RestoreArgs restoreArgs = LettuceRestoreArgs.from(argument).ttl(ttl); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, serializedValue, restoreArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, serializedValue, restoreArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.RESTORE, + (cmd)->cmd.restore(key, serializedValue, restoreArgs), okStatusConverter) + .run(args); + } + } + + @Override + public ScanResult> scan(final String cursor) { + final CommandArguments args = CommandArguments.create("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor) { + final CommandArguments args = CommandArguments.create("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, keyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, scanArgs, keyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final String cursor, final long count) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final long count) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, scanArgs, keyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern, final long count) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern, final long count) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, scanArgs, keyScanCursorConverter, args); + } + + @Override + public List sort(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return sort(bKey, binaryToStringListConverter, args); + } + + @Override + public List sort(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return sort(key, (v)->v, args); + } + + @Override + public List sort(final String key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("sortArgument", sortArgument); + final byte[] bKey = SafeEncoder.encode(key); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + + return sort(bKey, sortArgs, binaryToStringListConverter, args); + } + + @Override + public List sort(final byte[] key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("sortArgument", sortArgument); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + + return sort(key, sortArgs, (v)->v, args); + } + + @Override + public Long sort(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + final SortArgs sortArgs = new LettuceSortArgs(); + + return sortStore(key, destKey, sortArgs, args); + } + + @Override + public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("sortArgument", sortArgument); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + + return sortStore(key, destKey, sortArgs, args); + } + + @Override + public Long touch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.TOUCH, (cmd)->cmd.touch(keys), (v)->v) + .run(args); + } + } + + @Override + public Type type(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.TYPE, (cmd)->cmd.type(key), typeConverter) + .run(args); + } + } + + @Override + public Long unlink(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.UNLINK, (cmd)->cmd.unlink(keys), (v)->v) + .run(args); + } + } + + @Override + public ObjectEncoding objectEncoding(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final ObjectEncodingConverter objectEncodingConverter = new ObjectEncodingConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.OBJECT_ENCODING, + (cmd)->cmd.objectEncoding(key), objectEncodingConverter) + .run(args); + } + } + + @Override + public Long objectFreq(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.OBJECT_REFQ) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.OBJECT_REFQ) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.OBJECT_REFQ) + .run(args); + } + } + + @Override + public Long objectIdleTime(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.OBJECT_IDLETIME, + (cmd)->cmd.objectIdletime(key), (v)->v) + .run(args); + } + } + + @Override + public Long objectRefcount(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.OBJECT_REFCOUNT, + (cmd)->cmd.objectRefcount(key), (v)->v) + .run(args); + } + } + + private Status copy(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.COPY) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.COPY) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.COPY) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgs migrateArgs, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.MIGRATE, + (cmd)->cmd.migrate(host, port, db, timeout, migrateArgs), okStatusConverter) + .run(args); + } + } + + private Set keys(final byte[] pattern, final ListSetConverter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.KEYS, (cmd)->cmd.keys(pattern), converter) + .run(args); + } + } + + private ScanResult> scan(final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor), converter) + .run(args); + } + } + + private ScanResult> scan(final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanArgs), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SCAN, (cmd)->cmd.scan(cursor, scanArgs), + converter) + .run(args); + } + } + + private List sort(final byte[] key, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key), converter) + .run(args); + } + } + + private List sort(final byte[] key, final SortArgs sortArgs, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortArgs), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sort(key, sortArgs), + converter) + .run(args); + } + } + + private Long sortStore(final byte[] key, final byte[] destKey, final SortArgs sortArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sortStore(key, sortArgs, destKey), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SORT, + (cmd)->cmd.sortStore(key, sortArgs, destKey), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SORT, (cmd)->cmd.sortStore(key, sortArgs, destKey), + (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceListOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceListOperations.java new file mode 100644 index 000000000..8d471f674 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceListOperations.java @@ -0,0 +1,574 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.builder.ListBuilder; +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.Direction; +import com.buession.redis.core.ListPosition; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.lettuce.LettuceLPosArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyValue; +import io.lettuce.core.LPosArgs; + +import java.util.List; + +/** + * Lettuce 单机模式列表命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceListOperations extends AbstractListOperations { + + public LettuceListOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public String lIndex(final String key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + final byte[] bKey = SafeEncoder.encode(key); + + return lIndex(bKey, index, SafeEncoder::encode, args); + } + + @Override + public byte[] lIndex(final byte[] key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + return lIndex(key, index, (v)->v, args); + } + + @Override + public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) + .put("value", value); + final boolean before = ListPosition.BEFORE == position; + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, before, pivot, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.LINSERT, + (cmd)->cmd.linsert(key, before, pivot, value), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.LINSERT, (cmd)->cmd.linsert(key, before, pivot, value), + (v)->v) + .run(args); + } + } + + @Override + public Status lSet(final byte[] key, final long index, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.LSET, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.LSET, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.LSET, (cmd)->cmd.lset(key, index, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Long lLen(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.LLEN, (cmd)->cmd.llen(key), (v)->v) + .run(args); + } + } + + @Override + public List lRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + + return lRange(bKey, start, end, binaryToStringListConverter, args); + } + + @Override + public List lRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return lRange(key, start, end, (v)->v, args); + } + + @Override + public Long lPos(final byte[] key, final byte[] element) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element), (v)->v) + .run(args); + } + } + + @Override + public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); + final LPosArgs lPosArgs = LettuceLPosArgs.from(lPosArgument); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosArgs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, lPosArgs), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.LPOS, (cmd)->cmd.lpos(key, element, lPosArgs), (v)->v) + .run(args); + } + } + + @Override + public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) + .put("count", count); + final LPosArgs lPosArgs = LettuceLPosArgs.from(lPosArgument); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, (int) count, lPosArgs), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, (int) count, lPosArgs), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.LPOS, + (cmd)->cmd.lpos(key, element, (int) count, lPosArgs), (v)->v) + .run(args); + } + } + + @Override + public Long lRem(final byte[] key, final byte[] value, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.LREM, (cmd)->cmd.lrem(key, count, value), (v)->v) + .run(args); + } + } + + @Override + public Status lTrim(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.LTRIM, (cmd)->cmd.ltrim(key, start, end), + okStatusConverter) + .run(args); + } + } + + @Override + public String lMove(final String key, final String destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + return lMove(args); + } + + @Override + public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + return lMove(args); + } + + @Override + public String blMove(final String key, final String destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + return blMove(args); + } + + @Override + public byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to).put("timeout", timeout); + return blMove(args); + } + + @Override + public List blPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final Converter, List> converter = + (v)->ListBuilder.of(SafeEncoder.encode(v.getValue())); + + return blPop(bKeys, timeout, converter, args); + } + + @Override + public List blPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final Converter, List> converter = (v)->ListBuilder.of(v.getValue()); + + return blPop(keys, timeout, converter, args); + } + + @Override + public List brPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final Converter, List> converter = + (v)->ListBuilder.of(SafeEncoder.encode(v.getValue())); + + return brPop(bKeys, timeout, converter, args); + } + + @Override + public List brPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final Converter, List> converter = (v)->ListBuilder.of(v.getValue()); + + return brPop(keys, timeout, converter, args); + } + + @Override + public String brPoplPush(final String key, final String destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + + return brPoplPush(bKey, bDestKey, timeout, SafeEncoder::encode, args); + } + + @Override + public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + return brPoplPush(key, destKey, timeout, (v)->v, args); + } + + @Override + public String lPop(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + + return lPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] lPop(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return lPop(key, (v)->v, args); + } + + @Override + public Long lPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.LPUSH, (cmd)->cmd.lpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long lPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.LPUSHX, (cmd)->cmd.lpushx(key, values), (v)->v) + .run(args); + } + } + + @Override + public String rPop(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + + return rPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] rPop(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return rPop(key, (v)->v, args); + } + + @Override + public String rPoplPush(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + + return rPoplPush(bKey, bDestKey, SafeEncoder::encode, args); + } + + @Override + public byte[] rPoplPush(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + return rPoplPush(key, destKey, (v)->v, args); + } + + @Override + public Long rPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.RPUSH, (cmd)->cmd.rpush(key, values), (v)->v) + .run(args); + } + } + + @Override + public Long rPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.RPUSHX, (cmd)->cmd.rpushx(key, values), (v)->v) + .run(args); + } + } + + private V lIndex(final byte[] key, final long index, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.LINDEX, (cmd)->cmd.lindex(key, index), converter) + .run(args); + } + } + + private List lRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.LRANGE, (cmd)->cmd.lrange(key, start, end), + converter) + .run(args); + } + } + + private V lMove(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.LMOVE) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.LMOVE) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.LMOVE) + .run(args); + } + } + + private V blMove(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.BLMOVE) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.BLMOVE) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.BLMOVE) + .run(args); + } + } + + private List blPop(final byte[][] keys, final int timeout, final Converter, + List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.BLPOP, (cmd)->cmd.blpop(timeout, keys), converter) + .run(args); + } + } + + private List brPop(final byte[][] keys, final int timeout, final Converter, + List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.BRPOP, (cmd)->cmd.brpop(timeout, keys), converter) + .run(args); + } + } + + private V brPoplPush(final byte[] key, final byte[] destKey, final int timeout, + final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(timeout, key, destKey), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(timeout, key, destKey), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.BRPOPLPUSH, + (cmd)->cmd.brpoplpush(timeout, key, destKey), converter) + .run(args); + } + } + + private V lPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.LPOP, (cmd)->cmd.lpop(key), converter) + .run(args); + } + } + + private V rPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.RPOP, (cmd)->cmd.rpop(key), converter) + .run(args); + } + } + + private V rPoplPush(final byte[] key, final byte[] destKey, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.RPOPLPUSH, + (cmd)->cmd.rpoplpush(key, destKey), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.RPOPLPUSH, (cmd)->cmd.rpoplpush(key, destKey), + converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettucePubSubOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettucePubSubOperations.java new file mode 100644 index 000000000..7ee4241d8 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettucePubSubOperations.java @@ -0,0 +1,297 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.MapConverter; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.PubSubListener; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 单机模式 Pub/Sub 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettucePubSubOperations extends AbstractPubSubOperations { + + public LettucePubSubOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + pSubscribe(args); + } + + @Override + public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + pSubscribe(args); + } + + @Override + public Long publish(final byte[] channel, final byte[] message) { + final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.PUBLISH, (cmd)->cmd.publish(channel, message), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.PUBLISH, + (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.PUBLISH, (cmd)->cmd.publish(channel, message), (v)->v) + .run(args); + } + } + + @Override + public List pubsubChannels() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(), + binaryToStringListConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(), + binaryToStringListConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(), + binaryToStringListConverter) + .run(); + } + } + + @Override + public List pubsubChannels(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final byte[] bPattern = SafeEncoder.encode(pattern); + + return pubsubChannels(bPattern, binaryToStringListConverter, args); + } + + @Override + public List pubsubChannels(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return pubsubChannels(pattern, (v)->v, args); + } + + @Override + public Long pubsubNumPat() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.PUBSUB_NUMPAT, (cmd)->cmd.pubsubNumpat(), + (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.PUBSUB_NUMPAT, (cmd)->cmd.pubsubNumpat(), + (v)->v) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.PUBSUB_NUMPAT, (cmd)->cmd.pubsubNumpat(), (v)->v) + .run(); + } + } + + @Override + public Map pubsubNumSub(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + final byte[][] bChannels = SafeEncoder.encode(channels); + final MapConverter converter = new MapConverter<>(SafeEncoder::encode, (v)->v); + + return pubsubNumSub(bChannels, converter, args); + } + + @Override + public Map pubsubNumSub(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return pubsubNumSub(channels, (v)->v, args); + } + + @Override + public Object pUnSubscribe() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + } + } + + @Override + public Object pUnSubscribe(final String... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return pUnSubscribe(args); + } + + @Override + public Object pUnSubscribe(final byte[]... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return pUnSubscribe(args); + } + + @Override + public void subscribe(final String[] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + subscribe(args); + } + + @Override + public void subscribe(final byte[][] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + subscribe(args); + } + + @Override + public Object unSubscribe() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + } + } + + @Override + public Object unSubscribe(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return unSubscribe(args); + } + + @Override + public Object unSubscribe(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return unSubscribe(args); + } + + private void pSubscribe(final CommandArguments args) { + if(isPipeline()){ + new LettucePipelineCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new LettuceTransactionCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else{ + new LettuceCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + } + } + + private List pubsubChannels(final byte[] pattern, final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(pattern), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, + (cmd)->cmd.pubsubChannels(pattern), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.PUBSUB_CHANNELS, (cmd)->cmd.pubsubChannels(pattern), + converter) + .run(args); + } + } + + private Map pubsubNumSub(final byte[][] channels, + final Converter, Map> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.PUBSUB_NUMSUB, + (cmd)->cmd.pubsubNumsub(channels), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.PUBSUB_NUMSUB, + (cmd)->cmd.pubsubNumsub(channels), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.PUBSUB_NUMSUB, (cmd)->cmd.pubsubNumsub(channels), + converter) + .run(args); + } + } + + private Object pUnSubscribe(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + } + } + + private void subscribe(final CommandArguments args) { + if(isPipeline()){ + new LettucePipelineCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new LettuceTransactionCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else{ + new LettuceCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + } + } + + private Object unSubscribe(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceRedisOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceRedisOperations.java new file mode 100644 index 000000000..33bff44bc --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceRedisOperations.java @@ -0,0 +1,408 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.redis.client.connection.lettuce.LettuceClusterConnection; +import com.buession.redis.client.connection.lettuce.LettuceConnection; +import com.buession.redis.client.connection.lettuce.LettuceSentinelConnection; +import com.buession.redis.client.lettuce.LettuceClusterClient; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.client.operations.RedisOperations; +import com.buession.redis.core.Command; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.lettuce.LettuceResult; +import com.buession.redis.exception.RedisException; +import com.buession.redis.exception.RedisPipelineException; +import com.buession.redis.exception.RedisTransactionException; +import com.buession.redis.pipeline.PipelineProxy; +import com.buession.redis.transaction.TransactionProxy; +import io.lettuce.core.FlushEachCommand; +import io.lettuce.core.RedisFuture; +import io.lettuce.core.api.async.RedisAsyncCommands; +import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.core.cluster.api.async.RedisClusterAsyncCommands; +import io.lettuce.core.cluster.api.sync.RedisClusterCommands; +import io.lettuce.core.sentinel.api.async.RedisSentinelAsyncCommands; +import io.lettuce.core.sentinel.api.sync.RedisSentinelCommands; + +/** + * Lettuce Redis 命令操作接口 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface LettuceRedisOperations extends RedisOperations { + + class LettuceCommand extends + AbstractStandaloneCommand, SR, SR, R> { + + public LettuceCommand(final LettuceStandaloneClient client, final ProtocolCommand command) { + super(client, command); + } + + public LettuceCommand(final LettuceStandaloneClient client, final ProtocolCommand command, + final Executor, SR> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + @Override + protected R doExecute() throws RedisException { + final SR result = executor.execute(connection.getStatefulConnection().sync()); + return result == null ? null : converter.convert(result); + } + + } + + class LettucePipelineCommand extends + AbstractStandaloneCommand, RedisFuture, SR, R> { + + public LettucePipelineCommand(final LettuceStandaloneClient client, final ProtocolCommand command) { + super(client, command); + } + + public LettucePipelineCommand(final LettuceStandaloneClient client, final ProtocolCommand command, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.pipeline.Pipeline pipeline = pipeline(); + + if(pipeline instanceof PipelineProxy){ + final PipelineProxy> pipelineFactory = + (PipelineProxy>) pipeline; + + final Runner runner = new PipelineRunner<>((context)->{ + context.onCommand(connection.getStatefulConnection()); + return executor.execute(connection.getStatefulConnection().async()); + }, pipelineFactory, converter); + + pipelineFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisPipelineException("ERR EXEC without pipeline. Did you forget to call openPipeline?"); + } + } + + } + + class LettuceTransactionCommand extends + AbstractStandaloneCommand, + RedisFuture, SR, R> { + + public LettuceTransactionCommand(final LettuceStandaloneClient client, final ProtocolCommand command) { + super(client, command); + } + + public LettuceTransactionCommand(final LettuceStandaloneClient client, final ProtocolCommand command, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.transaction.Transaction transaction = transaction(); + + if(transaction instanceof TransactionProxy){ + final TransactionProxy, LettuceResult> transactionFactory = + (TransactionProxy, LettuceResult>) transaction; + + final Runner runner = new TransactionRunner<>( + (context)->executor.execute(connection.getStatefulConnection().async()), transactionFactory, + converter); + + transactionFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisTransactionException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + } + + class LettuceSentinelCommand extends + AbstractSentinelCommand, SR, SR, R> { + + public LettuceSentinelCommand(final LettuceSentinelClient client, final ProtocolCommand command) { + super(client, command); + } + + public LettuceSentinelCommand(final LettuceSentinelClient client, final ProtocolCommand command, + final Executor, SR> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + @Override + protected R doExecute() throws RedisException { + final SR result = executor.execute(connection.getStatefulRedisSentinelConnection().sync()); + return result == null ? null : converter.convert(result); + } + + } + + class LettuceSentinelPipelineCommand extends + AbstractSentinelCommand, RedisFuture, SR, R> { + + public LettuceSentinelPipelineCommand(final LettuceSentinelClient client, final ProtocolCommand command) { + super(client, command); + } + + public LettuceSentinelPipelineCommand(final LettuceSentinelClient client, final ProtocolCommand command, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.pipeline.Pipeline pipeline = pipeline(); + + if(pipeline instanceof PipelineProxy){ + final PipelineProxy> pipelineFactory = + (PipelineProxy>) pipeline; + + final Runner runner = new PipelineRunner<>((context)->{ + context.onCommand(connection.getStatefulRedisSentinelConnection()); + return executor.execute(connection.getStatefulRedisSentinelConnection().async()); + }, pipelineFactory, converter); + + pipelineFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisPipelineException("ERR EXEC without pipeline. Did you forget to call openPipeline?"); + } + } + + } + + class LettuceSentinelTransactionCommand extends + AbstractSentinelCommand, + RedisFuture, SR, R> { + + public LettuceSentinelTransactionCommand(final LettuceSentinelClient client, final ProtocolCommand command) { + super(client, command); + } + + public LettuceSentinelTransactionCommand(final LettuceSentinelClient client, final ProtocolCommand command, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.transaction.Transaction transaction = transaction(); + + if(transaction instanceof TransactionProxy){ + final TransactionProxy, LettuceResult> transactionFactory = + (TransactionProxy, LettuceResult>) transaction; + + final Runner runner = new TransactionRunner<>( + (context)->executor.execute(connection.getStatefulRedisSentinelConnection().async()), + transactionFactory, converter); + + transactionFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisTransactionException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + } + + class LettuceClusterCommand extends + AbstractClusterCommand, SR, SR, R> { + + public LettuceClusterCommand(final LettuceClusterClient client, final ProtocolCommand command) { + super(client, command); + } + + public LettuceClusterCommand(final LettuceClusterClient client, final ProtocolCommand command, + final Executor, SR> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + @Override + protected R doExecute() throws RedisException { + final SR result = executor.execute(connection.getStatefulRedisClusterConnection().sync()); + return result == null ? null : converter.convert(result); + } + + } + + class LettuceClusterPipelineCommand extends + AbstractClusterCommand, RedisFuture, SR, R> { + + public LettuceClusterPipelineCommand(final LettuceClusterClient client, final ProtocolCommand command) { + super(client, command); + } + + public LettuceClusterPipelineCommand(final LettuceClusterClient client, final ProtocolCommand command, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.pipeline.Pipeline pipeline = pipeline(); + + if(pipeline instanceof PipelineProxy){ + final PipelineProxy> pipelineFactory = + (PipelineProxy>) pipeline; + + final Runner runner = new PipelineRunner<>((context)->{ + context.onCommand(connection.getStatefulRedisClusterConnection()); + return executor.execute(connection.getStatefulRedisClusterConnection().async()); + }, pipelineFactory, converter); + + pipelineFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisPipelineException("ERR EXEC without pipeline. Did you forget to call openPipeline?"); + } + } + + } + + class LettuceClusterTransactionCommand extends + AbstractClusterCommand, + RedisFuture, SR, R> { + + public LettuceClusterTransactionCommand(final LettuceClusterClient client, final ProtocolCommand command) { + super(client, command); + } + + public LettuceClusterTransactionCommand(final LettuceClusterClient client, final ProtocolCommand command, + final Executor, RedisFuture> executor, + final Converter converter) { + super(client, command, executor, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + protected R doExecute() throws RedisException { + final com.buession.redis.transaction.Transaction transaction = transaction(); + + if(transaction instanceof TransactionProxy){ + final TransactionProxy, LettuceResult> transactionFactory = + (TransactionProxy, LettuceResult>) transaction; + + final Runner runner = new TransactionRunner<>( + (context)->executor.execute(connection.getStatefulRedisClusterConnection().async()), + transactionFactory, converter); + + transactionFactory.getTxResults().add(runner.run()); + + return null; + }else{ + throw new RedisTransactionException("ERR EXEC without MULTI. Did you forget to call multi?"); + } + } + + } + + abstract class PtRunner implements Command.Runner { + + protected final Command.Executor> executor; + + protected final Converter converter; + + public PtRunner(final Command.Executor> executor, + final Converter converter) { + this.executor = executor; + this.converter = converter; + } + + protected LettuceResult newLettuceResult(final RedisFuture future) { + return LettuceResult.Builder.fromRedisFuture(future).build(); + } + + protected LettuceResult newLettuceResult(final RedisFuture future, + final Converter converter) { + return LettuceResult.Builder.fromRedisFuture(future).mappedWith(converter).build(); + } + + } + + final class PipelineRunner extends PtRunner { + + private final PipelineProxy> pipelineFactory; + + public PipelineRunner(final Command.Executor> executor, + final PipelineProxy> pipelineFactory, + final Converter converter) { + super(executor, converter); + this.pipelineFactory = pipelineFactory; + } + + @SuppressWarnings({"unchecked"}) + @Override + public LettuceResult run() throws RedisException { + final RedisFuture future = executor.execute(pipelineFactory.getObject()); + return converter == null ? newLettuceResult(future) : newLettuceResult(future, converter); + } + + } + + final class TransactionRunner extends PtRunner { + + private final TransactionProxy> transactionProxy; + + public TransactionRunner(final Command.Executor> executor, + final TransactionProxy> transactionProxy, + final Converter converter) { + super(executor, converter); + this.transactionProxy = transactionProxy; + } + + @SuppressWarnings({"unchecked"}) + @Override + public LettuceResult run() throws RedisException { + final RedisFuture future = executor.execute(transactionProxy.getObject()); + return converter == null ? newLettuceResult(future) : newLettuceResult(future, converter); + } + + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceScriptingOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceScriptingOperations.java new file mode 100644 index 000000000..62ae7e4f6 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceScriptingOperations.java @@ -0,0 +1,238 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce 单机模式 Script 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceScriptingOperations extends AbstractScriptingOperations { + + public LettuceScriptingOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Object eval(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + final byte[][] bKeys = new byte[][]{}; + + return eval(script, bKeys, null, args); + } + + @Override + public Object eval(final String script, final String... params) { + final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + final byte[][] bKeys = new byte[][]{}; + final byte[][] bParams = SafeEncoder.encode(params); + + return eval(script, bKeys, bParams, args); + } + + @Override + public Object eval(final String script, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final byte[][] bKeys = SafeEncoder.encode(keys); + final byte[][] bArguments = SafeEncoder.encode(arguments); + + return eval(script, bKeys, bArguments, args); + } + + @Override + public Object evalSha(final String digest) { + final CommandArguments args = CommandArguments.create("digest", digest); + final byte[][] bKeys = new byte[][]{}; + + return evalSha(digest, bKeys, null, args); + } + + @Override + public Object evalSha(final String digest, final String... params) { + final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); + final byte[][] bKeys = new byte[][]{}; + final byte[][] bParams = SafeEncoder.encode(params); + + return evalSha(digest, bKeys, bParams, args); + } + + @Override + public Object evalSha(final String digest, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final byte[][] bKeys = SafeEncoder.encode(keys); + final byte[][] bArguments = SafeEncoder.encode(arguments); + + return evalSha(digest, bKeys, bArguments, args); + } + + @Override + public List scriptExists(final String... sha1) { + final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SCRIPT_EXISTS, (cmd)->cmd.scriptExists(sha1), (v)->v) + .run(args); + } + } + + @Override + public Status scriptFlush() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(); + } + } + + @Override + public Status scriptFlush(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SCRIPT_FLUSH, (cmd)->cmd.scriptFlush(), + okStatusConverter) + .run(args); + } + } + + @Override + public String scriptLoad(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + final byte[] bScript = SafeEncoder.encode(script); + + return scriptLoad(bScript, (v)->v, args); + } + + @Override + public byte[] scriptLoad(final byte[] script) { + final CommandArguments args = CommandArguments.create("script", script); + return scriptLoad(script, SafeEncoder::encode, args); + } + + @Override + public Status scriptKill() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SCRIPT_KILL, (cmd)->cmd.scriptKill(), + okStatusConverter) + .run(); + } + } + + private Object eval(final String script, final byte[][] keys, final byte[][] arguments, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, null, keys, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, null, keys, arguments), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.EVAL, + (cmd)->cmd.eval(script, null, keys, arguments), (v)->v) + .run(args); + } + } + + private Object evalSha(final String digest, final byte[][] keys, final byte[][] arguments, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, null, keys, arguments), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, null, keys, arguments), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.EVALSHA, + (cmd)->cmd.evalsha(digest, null, keys, arguments), (v)->v) + .run(args); + } + } + + private V scriptLoad(final byte[] script, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SCRIPT_LOAD, (cmd)->cmd.scriptLoad(script), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelBitMapOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelBitMapOperations.java new file mode 100644 index 000000000..110422ad6 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelBitMapOperations.java @@ -0,0 +1,223 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.BitCountOption; +import com.buession.redis.core.BitOperation; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.lettuce.LettuceBitFieldArgs; +import io.lettuce.core.BitFieldArgs; + +import java.util.List; + +/** + * Lettuce 哨兵模式 BitMap 命令操作抽象类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelBitMapOperations extends AbstractBitMapOperations { + + public LettuceSentinelBitMapOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Long bitCount(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.BITCOUNT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.BITCOUNT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.BITCOUNT) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.BITCOUNT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.BITCOUNT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.BITCOUNT) + .run(args); + } + } + + @Override + public Long bitCount(final byte[] key, final long start, final long end, final BitCountOption bitCountOption) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end) + .put("bitCountOption", bitCountOption); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.BITCOUNT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.BITCOUNT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.BITCOUNT) + .run(args); + } + } + + @Override + public List bitField(final byte[] key, final BitFieldArgument argument) { + final CommandArguments args = CommandArguments.create("key", key).put("arguments", argument); + final BitFieldArgs bitFieldArgs = LettuceBitFieldArgs.from(argument); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.BITFIELD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.BITFIELD) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.BITFIELD) + .run(args); + } + } + + @Override + public List bitFieldRo(final String key, final String... arguments) { + final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); + return bitFieldRo(args); + } + + @Override + public List bitFieldRo(final byte[] key, final byte[]... arguments) { + final CommandArguments args = CommandArguments.create("key", key).put("arguments", (Object[]) arguments); + return bitFieldRo(args); + } + + @Override + public Long bitOp(final BitOperation operation, final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("operation", operation).put("destKey", destKey) + .put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.BITOP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.BITOP) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.BITOP) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.BITPOS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.BITPOS) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.BITPOS) + .run(args); + } + } + + @Override + public Long bitPos(final byte[] key, final boolean value, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("start", start) + .put("end", end); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.BITPOS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.BITPOS) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.BITPOS) + .run(args); + } + } + + @Override + public Boolean getBit(final byte[] key, final long offset) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.GETBIT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.GETBIT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.GETBIT) + .run(args); + } + } + + @Override + public Boolean setBit(final byte[] key, final long offset, final boolean value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + final int iValue = value ? 1 : 0; + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SETBIT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SETBIT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SETBIT) + .run(args); + } + } + + private List bitFieldRo(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.BITFIELD_RO) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.BITFIELD_RO) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.BITFIELD_RO) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelClusterOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelClusterOperations.java new file mode 100644 index 000000000..bf287e8de --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelClusterOperations.java @@ -0,0 +1,474 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.lang.KeyValue; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.BumpEpoch; +import com.buession.redis.core.ClusterFailoverOption; +import com.buession.redis.core.ClusterInfo; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.ClusterResetOption; +import com.buession.redis.core.ClusterSetSlotOption; +import com.buession.redis.core.ClusterSlot; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.response.ClusterReplicasConverter; +import com.buession.redis.core.internal.convert.response.BumpEpochConverter; +import com.buession.redis.core.internal.convert.response.ClusterInfoConverter; +import com.buession.redis.core.internal.convert.response.ClusterNodeConverter; +import com.buession.redis.core.internal.convert.response.ClusterNodesConverter; +import com.buession.redis.core.internal.convert.response.ClusterSlotConverter; + +import java.util.List; + +/** + * Lettuce 哨兵模式集群命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelClusterOperations extends AbstractClusterOperations { + + public LettuceSentinelClusterOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public String clusterMyId() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_MY_ID) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_MY_ID) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLUSTER_MY_ID) + .run(); + } + } + + @Override + public Status clusterAddSlots(final int... slots) { + final CommandArguments args = CommandArguments.create("slots", slots); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_ADDSLOTS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_ADDSLOTS) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLUSTER_ADDSLOTS) + .run(args); + } + } + + @Override + public List clusterSlots() { + final ListConverter listClusterSlotConverter = ClusterSlotConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_SLOTS) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_SLOTS) + .run(); + }else{ + return new LettuceSentinelCommand, List>(client, + ProtocolCommand.CLUSTER_SLOTS) + .run(); + } + } + + @Override + public Integer clusterCountFailureReports(final String nodeId) { + final CommandArguments args = CommandArguments.create("nodeId", nodeId); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, + ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, + ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) + .run(args); + }else{ + return new LettuceSentinelCommand(client, + ProtocolCommand.CLUSTER_COUNTFAILUREREPORTS) + .run(args); + } + } + + @Override + public Long clusterCountKeysInSlot(final int slot) { + final CommandArguments args = CommandArguments.create("slot", slot); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLUSTER_COUNTKEYSINSLOT) + .run(args); + } + } + + @Override + public Status clusterDelSlots(final int... slots) { + final CommandArguments args = CommandArguments.create("slots", slots); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_DELSLOTS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_DELSLOTS) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLUSTER_DELSLOTS) + .run(args); + } + } + + @Override + public Status clusterFlushSlots() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_FLUSHSLOTS) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_FLUSHSLOTS) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLUSTER_FLUSHSLOTS) + .run(); + } + } + + @Override + public Status clusterFailover(final ClusterFailoverOption clusterFailoverOption) { + final CommandArguments args = CommandArguments.create("clusterFailoverOption", clusterFailoverOption); + final boolean force = ClusterFailoverOption.FORCE == clusterFailoverOption; + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_FAILOVER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_FAILOVER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLUSTER_FAILOVER) + .run(args); + } + } + + @Override + public Status clusterForget(final String nodeId) { + final CommandArguments args = CommandArguments.create("nodeId", nodeId); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_FORGET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_FORGET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLUSTER_FORGET) + .run(args); + } + } + + @Override + public List clusterGetKeysInSlot(final int slot, final long count) { + final CommandArguments args = CommandArguments.create("slot", slot).put("count", count); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + } + } + + @Override + public Long clusterKeySlot(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLUSTER_GETKEYSINSLOT) + .run(args); + } + } + + @Override + public ClusterInfo clusterInfo() { + final ClusterInfoConverter clusterInfoConverter = new ClusterInfoConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_INFO) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_INFO) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLUSTER_INFO) + .run(); + } + } + + @Override + public Status clusterMeet(final String ip, final int port) { + final CommandArguments args = CommandArguments.create("ip", ip).put("port", port); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_MEET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_MEET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLUSTER_MEET) + .run(args); + } + } + + @Override + public List clusterNodes() { + final ClusterNodesConverter clusterNodesConverter = new ClusterNodesConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_NODES) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_NODES) + .run(); + }else{ + return new LettuceSentinelCommand, List>(client, + ProtocolCommand.CLUSTER_NODES) + .run(); + } + } + + @Override + public List clusterSlaves(final String nodeId) { + final CommandArguments args = CommandArguments.create("nodeId", nodeId); + final ListConverter listClusterNodeConverter = ClusterNodeConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_SLAVES) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_SLAVES) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + ProtocolCommand.CLUSTER_SLAVES) + .run(args); + } + } + + @Override + public List clusterReplicas(final String nodeId) { + final CommandArguments args = CommandArguments.create("nodeId", nodeId); + final ClusterReplicasConverter clusterReplicasConverter = new ClusterReplicasConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.CLUSTER_REPLICAS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.CLUSTER_REPLICAS) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + ProtocolCommand.CLUSTER_REPLICAS) + .run(args); + } + } + + @Override + public Status clusterReplicate(final String nodeId) { + final CommandArguments args = CommandArguments.create("nodeId", nodeId); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_REPLICATE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_REPLICATE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLUSTER_REPLICATE) + .run(args); + } + } + + @Override + public Status clusterReset(final ClusterResetOption clusterResetOption) { + final CommandArguments args = CommandArguments.create("clusterResetOption", clusterResetOption); + final boolean hard = ClusterResetOption.HARD == clusterResetOption; + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_RESET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_RESET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLUSTER_RESET) + .run(args); + } + } + + @Override + public Status clusterSaveConfig() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_SAVECONFIG) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_SAVECONFIG) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLUSTER_SAVECONFIG) + .run(); + } + } + + @Override + public Status clusterSetConfigEpoch(final long configEpoch) { + final CommandArguments args = CommandArguments.create("configEpoch", configEpoch); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLUSTER_SETCONFIGEPOCH) + .run(args); + } + } + + @Override + public KeyValue clusterBumpEpoch() { + final BumpEpochConverter bumpEpochConverter = new BumpEpochConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, KeyValue>( + client, ProtocolCommand.CLUSTER_BUMPEPOCH) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, KeyValue>( + client, ProtocolCommand.CLUSTER_BUMPEPOCH) + .run(); + }else{ + return new LettuceSentinelCommand, KeyValue>( + client, ProtocolCommand.CLUSTER_BUMPEPOCH) + .run(); + } + } + + @Override + public Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId) { + final CommandArguments args = CommandArguments.create("slot", slot).put("setSlotOption", setSlotOption) + .put("nodeId", nodeId); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLUSTER_SETSLOT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLUSTER_SETSLOT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLUSTER_SETSLOT) + .run(args); + } + } + + @Override + public Status asking() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ASKING) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ASKING) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ASKING) + .run(); + } + } + + @Override + public Status readWrite() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.READWRITE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.READWRITE) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.READWRITE) + .run(); + } + } + + @Override + public Status readOnly() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.READONLY) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.READONLY) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.READONLY) + .run(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelConnectionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelConnectionOperations.java new file mode 100644 index 000000000..2c00b4a56 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelConnectionOperations.java @@ -0,0 +1,399 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.Client; +import com.buession.redis.core.ClientReply; +import com.buession.redis.core.ClientType; +import com.buession.redis.core.ClientUnblockType; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.params.ClientUnblockTypeConverter; +import com.buession.redis.core.internal.convert.response.ClientConverter; +import com.buession.redis.core.internal.convert.response.PingResultConverter; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.UnblockType; + +import java.util.List; + +/** + * Lettuce 哨兵模式连接命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelConnectionOperations extends AbstractConnectionOperations { + + public LettuceSentinelConnectionOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Status auth(final String user, final String password) { + final CommandArguments args = CommandArguments.create("user", user).put("password", password); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.AUTH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.AUTH) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.AUTH) + .run(args); + } + } + + @Override + public Status auth(final String password) { + final CommandArguments args = CommandArguments.create("password", password); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.AUTH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.AUTH) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.AUTH) + .run(args); + } + } + + @Override + public String echo(final String str) { + final CommandArguments args = CommandArguments.create("str", str); + final byte[] msg = SafeEncoder.encode(str); + + return echo(msg, SafeEncoder::encode, args); + } + + @Override + public byte[] echo(final byte[] str) { + final CommandArguments args = CommandArguments.create("str", str); + return echo(str, (v)->v, args); + } + + @Override + public Status ping() { + final PingResultConverter pingResultConverter = new PingResultConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.ping(), + pingResultConverter) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.ping(), + pingResultConverter) + .run(); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.ECHO, (cmd)->cmd.ping(), pingResultConverter) + .run(); + } + } + + @Override + public Status reset() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.RESET) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.RESET) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.RESET) + .run(); + } + } + + @Override + public Status quit() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.QUIT) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.QUIT) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.QUIT) + .run(); + } + } + + @Override + public Status select(final int db) { + final CommandArguments args = CommandArguments.create("db", db); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SELECT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SELECT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SELECT) + .run(args); + } + } + + @Override + public Status clientCaching(final boolean isYes) { + final CommandArguments args = CommandArguments.create("isYes", isYes); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLIENT_CACHING) + .run(args); + } + } + + @Override + public Long clientId() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLIENT_ID) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLIENT_ID) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLIENT_ID) + .run(); + } + } + + @Override + public Status clientSetName(final byte[] name) { + final CommandArguments args = CommandArguments.create("name", name); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.CLIENT_SETNAME, + (cmd)->cmd.clientSetname(name), + okStatusConverter) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.CLIENT_SETNAME, (cmd)->cmd.clientSetname(name), + okStatusConverter) + .run(args); + } + } + + @Override + public String clientGetName() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.CLIENT_GETNAME, + (cmd)->cmd.clientGetname(), + SafeEncoder::encode) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.CLIENT_GETNAME, + (cmd)->cmd.clientGetname(), + SafeEncoder::encode) + .run(); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.CLIENT_GETNAME, (cmd)->cmd.clientGetname(), + SafeEncoder::encode) + .run(); + } + } + + @Override + public Integer clientGetRedir() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLIENT_GETREDIR) + .run(); + } + } + + @Override + public List clientList() { + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(); + } + } + + @Override + public List clientList(final ClientType clientType) { + final CommandArguments args = CommandArguments.create("clientType", clientType); + final ClientConverter.ClientListConverter clientListConverter = new ClientConverter.ClientListConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.CLIENT_LIST, (cmd)->cmd.clientList(), + clientListConverter) + .run(args); + } + } + + @Override + public Client clientInfo() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLIENT_INFO) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLIENT_INFO) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLIENT_INFO) + .run(); + } + } + + @Override + public Status clientPause(final int timeout) { + final CommandArguments args = CommandArguments.create("timeout", timeout); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.CLIENT_PAUSE, + (cmd)->cmd.clientPause(timeout), okStatusConverter) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.CLIENT_PAUSE, (cmd)->cmd.clientPause(timeout), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clientReply(final ClientReply option) { + final CommandArguments args = CommandArguments.create("option", option); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLIENT_REPLY) + .run(args); + } + } + + @Override + public Status clientKill(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + final String addr = host + ':' + port; + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(addr), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.CLIENT_KILL, + (cmd)->cmd.clientKill(addr), + okStatusConverter) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.CLIENT_KILL, (cmd)->cmd.clientKill(addr), + okStatusConverter) + .run(args); + } + } + + @Override + public Status clientUnblock(final int clientId) { + final CommandArguments args = CommandArguments.create("clientId", clientId); + return clientUnblock(clientId, UnblockType.ERROR, args); + } + + @Override + public Status clientUnblock(final int clientId, final ClientUnblockType type) { + final CommandArguments args = CommandArguments.create("clientId", clientId).put("type", type); + final UnblockType unblockType = (new ClientUnblockTypeConverter()).convert(type); + + return clientUnblock(clientId, unblockType, args); + } + + private V echo(final byte[] str, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ECHO) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ECHO) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ECHO) + .run(args); + } + } + + private Status clientUnblock(final int clientId, final UnblockType unblockType, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CLIENT_KILL) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CLIENT_KILL) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CLIENT_KILL) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelGenericOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelGenericOperations.java new file mode 100644 index 000000000..d63129931 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelGenericOperations.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.KeyValue; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; + +/** + * Lettuce 哨兵模式一般命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelGenericOperations extends AbstractGenericOperations { + + public LettuceSentinelGenericOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Long wait(final int replicas, final int timeout) { + final CommandArguments args = CommandArguments.create(replicas).add(timeout); + return notCommand(client, ProtocolCommand.WAIT, args); + } + + @Override + public KeyValue waitOf(final int locals, final int replicas, final int timeout) { + final CommandArguments args = CommandArguments.create(locals).add(replicas).add(timeout); + return notCommand(client, ProtocolCommand.WAITOF, args); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelGeoOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelGeoOperations.java new file mode 100644 index 000000000..1a8cf0b05 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelGeoOperations.java @@ -0,0 +1,385 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.builder.ListBuilder; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.SetListConverter; +import com.buession.lang.Geo; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.params.GeoUnitConverter; +import com.buession.redis.core.internal.convert.lettuce.response.GeoCoordinateConverter; +import com.buession.redis.core.internal.convert.lettuce.response.GeoRadiusGeneralResultConverter; +import com.buession.redis.core.internal.convert.lettuce.response.GeoRadiusResponseConverter; +import com.buession.redis.core.internal.lettuce.LettuceGeoArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.GeoArgs; +import io.lettuce.core.GeoCoordinates; +import io.lettuce.core.GeoWithin; +import io.lettuce.core.Value; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 哨兵模式地理位置命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelGeoOperations extends AbstractGeoOperations { + + public LettuceSentinelGeoOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Long geoAdd(final byte[] key, final byte[] member, final double longitude, final double latitude) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member) + .put("longitude", longitude).put("latitude", latitude); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.GEOADD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.GEOADD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.GEOADD) + .run(args); + } + } + + @Override + public Long geoAdd(final String key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create("key", key).put("memberCoordinates", memberCoordinates); + return geoAdd(key, memberCoordinates, args); + } + + @Override + public Long geoAdd(final byte[] key, final Map memberCoordinates) { + final CommandArguments args = CommandArguments.create("key", key).put("memberCoordinates", memberCoordinates); + return geoAdd(key, memberCoordinates, args); + } + + @Override + public List geoHash(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + final byte[] bKey = SafeEncoder.encode(key); + final byte[][] bMembers = SafeEncoder.encode(members); + final ListConverter, String> listConverter = new ListConverter<>(Value::getValue); + + return geoHash(bKey, bMembers, listConverter, args); + } + + @Override + public List geoHash(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + final ListConverter, byte[]> listConverter = new ListConverter<>( + (v)->SafeEncoder.encode(v.getValue())); + + return geoHash(key, members, listConverter, args); + } + + @Override + public List geoPos(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + final ListConverter listGeoCoordinateConverter = GeoCoordinateConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.GEOPOS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.GEOPOS) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.GEOPOS) + .run(args); + } + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2) { + final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) + .put("member2", member2); + return geoDist(key, member1, member2, GeoArgs.Unit.m, args); + } + + @Override + public Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("member1", member1) + .put("member2", member2).put("unit", unit); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + + return geoDist(key, member1, member2, geoArgsUnit, args); + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final SetListConverter setListGeoRadiusGeneralResultConverter = + GeoRadiusGeneralResultConverter.setListConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.GEORADIUS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.GEORADIUS) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.GEORADIUS) + .run(args); + } + } + + @Override + public List geoRadius(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit) + .put("geoRadiusArgument", geoRadiusArgument); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final GeoArgs geoArgs = LettuceGeoArgs.from(geoRadiusArgument); + final ListConverter, GeoRadius> listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.GEORADIUS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.GEORADIUS) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.GEORADIUS) + .run(args); + } + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit); + return geoRadiusRo(args); + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit); + return geoRadiusRo(args); + } + + @Override + public List geoRadiusRo(final String key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit) + .put("geoRadiusArgument", geoRadiusArgument); + return geoRadiusRo(args); + } + + @Override + public List geoRadiusRo(final byte[] key, final double longitude, final double latitude, + final double radius, final GeoUnit unit, + final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("longitude", longitude) + .put("latitude", latitude).put("radius", radius).put("unit", unit) + .put("geoRadiusArgument", geoRadiusArgument); + return geoRadiusRo(args); + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final SetListConverter setListGeoRadiusGeneralResultConverter = + GeoRadiusGeneralResultConverter.setListConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.GEORADIUSBYMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.GEORADIUSBYMEMBER) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + ProtocolCommand.GEORADIUSBYMEMBER) + .run(args); + } + } + + @Override + public List geoRadiusByMember(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); + final GeoArgs.Unit geoArgsUnit = (new GeoUnitConverter()).convert(unit); + final GeoArgs geoArgs = LettuceGeoArgs.from(geoRadiusArgument); + final ListConverter, GeoRadius> listGeoRadiusResponseConverter = + GeoRadiusResponseConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.GEORADIUSBYMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.GEORADIUSBYMEMBER) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + ProtocolCommand.GEORADIUSBYMEMBER) + .run(args); + } + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit); + return geoRadiusByMemberRo(args); + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit); + return geoRadiusByMemberRo(args); + } + + @Override + public List geoRadiusByMemberRo(final String key, final String member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); + return geoRadiusByMemberRo(args); + } + + @Override + public List geoRadiusByMemberRo(final byte[] key, final byte[] member, final double radius, + final GeoUnit unit, final GeoRadiusArgument geoRadiusArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member).put("radius", radius) + .put("unit", unit).put("geoRadiusArgument", geoRadiusArgument); + return geoRadiusByMemberRo(args); + } + + @Override + protected Long geoAdd(final byte[] key, final ListBuilder lngLatMemberBuilder, + final CommandArguments args) { + final Object[] lngLatMembers = lngLatMemberBuilder.build().toArray(new Object[]{}); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.GEOADD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.GEOADD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.GEOADD) + .run(args); + } + } + + private List geoHash(final byte[] key, final byte[][] members, + final ListConverter, V> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.GEOHASH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.GEOHASH) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.GEOHASH) + .run(args); + } + } + + private Double geoDist(final byte[] key, final byte[] member1, final byte[] member2, final GeoArgs.Unit unit, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.GEODIST) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.GEODIST) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.GEODIST) + .run(args); + } + } + + private List geoRadiusRo(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.GEORADIUS_RO) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.GEORADIUS_RO) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.GEORADIUS_RO) + .run(args); + } + } + + private List geoRadiusByMemberRo(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.GEORADIUSBYMEMBER_RO) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.GEORADIUSBYMEMBER_RO) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + ProtocolCommand.GEORADIUSBYMEMBER_RO) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelHashOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelHashOperations.java new file mode 100644 index 000000000..b39b06bc1 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelHashOperations.java @@ -0,0 +1,533 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.ListSetConverter; +import com.buession.core.converter.MapConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyValue; +import io.lettuce.core.MapScanCursor; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.Value; + +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Lettuce 哨兵模式模式哈希表命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelHashOperations extends AbstractHashOperations { + + public LettuceSentinelHashOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Long hDel(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.HDEL) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.HDEL) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.HDEL) + .run(args); + } + } + + @Override + public Boolean hExists(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.HEXISTS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.HEXISTS) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.HEXISTS) + .run(args); + } + } + + @Override + public String hGet(final String key, final String field) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bField = SafeEncoder.encode(field); + + return hGet(bKey, bField, SafeEncoder::encode, args); + } + + @Override + public byte[] hGet(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field); + return hGet(key, field, (v)->v, args); + } + + @Override + public Map hGetAll(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final MapConverter binaryToStringMapConverter = Converters.mapBinaryToString(); + + return hGetAll(bKey, binaryToStringMapConverter, args); + } + + @Override + public Map hGetAll(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return hGetAll(key, (v)->v, args); + } + + @Override + public Long hIncrBy(final byte[] key, final byte[] field, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.HINCRBY) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.HINCRBY) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.HINCRBY) + .run(args); + } + } + + @Override + public Double hIncrByFloat(final byte[] key, final byte[] field, final double value) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.HINCRBYFLOAT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.HINCRBYFLOAT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.HINCRBYFLOAT) + .run(args); + } + } + + @Override + public Set hKeys(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final ListSetConverter binaryToStringListSetConverter = + Converters.listSetBinaryToString(); + + return hKeys(bKey, binaryToStringListSetConverter, args); + } + + @Override + public Set hKeys(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return hKeys(key, HashSet::new, args); + } + + @Override + public Long hLen(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.HLEN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.HLEN) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.HLEN) + .run(args); + } + } + + @Override + public List hMGet(final String key, final String... fields) { + final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); + final byte[] bKey = SafeEncoder.encode(key); + final byte[][] bFields = SafeEncoder.encode(fields); + final ListConverter, String> listConverter = + new ListConverter<>((v)->SafeEncoder.encode(v.getValue())); + + return hMGet(bKey, bFields, listConverter, args); + } + + @Override + public List hMGet(final byte[] key, final byte[]... fields) { + final CommandArguments args = CommandArguments.create("key", key).put("fields", (Object[]) fields); + final ListConverter, byte[]> listConverter = new ListConverter<>(Value::getValue); + + return hMGet(key, fields, listConverter, args); + } + + @Override + public Status hMSet(final byte[] key, final Map data) { + final CommandArguments args = CommandArguments.create("key", key).put("data", data); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.HMGET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.HMGET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.HMGET) + .run(args); + } + } + + @Override + public String hRandField(final String key) { + final CommandArguments args = CommandArguments.create(key); + return hRandField(args); + } + + @Override + public byte[] hRandField(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return hRandField(args); + } + + @Override + public List hRandField(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return hRandField(args); + } + + @Override + public List hRandField(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return hRandField(args); + } + + @Override + public Map hRandFieldWithValues(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return hRandField(args); + } + + @Override + public Map hRandFieldWithValues(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return hRandField(args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, mapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, scanArgs, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, scanArgs, mapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, scanArgs, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, scanArgs, mapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final String key, final String cursor, final String pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter bvSvMapScanCursorConverter = + new ScanCursorConverter.MapScanCursorConverter.BvSvMapScanCursorConverter(); + + return hScan(bKey, scanCursor, scanArgs, bvSvMapScanCursorConverter, args); + } + + @Override + public ScanResult> hScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.MapScanCursorConverter mapScanCursorConverter = new ScanCursorConverter.MapScanCursorConverter<>(); + + return hScan(key, scanCursor, scanArgs, mapScanCursorConverter, args); + } + + @Override + public Long hSet(final byte[] key, final byte[] field, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); + final Converter converter = (v)->Boolean.TRUE.equals(v) ? 1L : 0L; + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.HSET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.HSET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.HSET) + .run(args); + } + } + + @Override + public Status hSetNx(final byte[] key, final byte[] field, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field).put("value", value); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.HSETNX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.HSETNX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.HSETNX) + .run(args); + } + } + + @Override + public Long hStrLen(final byte[] key, final byte[] field) { + final CommandArguments args = CommandArguments.create("key", key).put("field", field); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.HSETNX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.HSETNX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.HSETNX) + .run(args); + } + } + + @Override + public List hVals(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return hVals(bKey, binaryToStringListConverter, args); + } + + @Override + public List hVals(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return hVals(key, (v)->v, args); + } + + private V hGet(final byte[] key, final byte[] field, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.HGET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.HGET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.HGET) + .run(args); + } + } + + private Map hGetAll(final byte[] key, final Converter, Map> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Map>(client, ProtocolCommand.HGETALL) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Map>(client, ProtocolCommand.HGETALL) + .run(args); + }else{ + return new LettuceSentinelCommand, Map>(client, ProtocolCommand.HGETALL) + .run(args); + } + } + + private Set hKeys(final byte[] key, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Set>(client, ProtocolCommand.HKEYS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Set>(client, ProtocolCommand.HKEYS) + .run(args); + }else{ + return new LettuceSentinelCommand, Set>(client, ProtocolCommand.HKEYS) + .run(args); + } + } + + private List hMGet(final byte[] key, final byte[][] fields, + final Converter>, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.HMGET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.HMGET) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.HMGET) + .run(args); + } + } + + private TV hRandField(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.HRANDFIELD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.HRANDFIELD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.HRANDFIELD) + .run(args); + } + } + + private ScanResult> hScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>, ScanResult>>(client, + ProtocolCommand.HSCAN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>, ScanResult>>(client, + ProtocolCommand.HSCAN) + .run(args); + }else{ + return new LettuceSentinelCommand>, ScanResult>>(client, + ProtocolCommand.HSCAN) + .run(args); + } + } + + private ScanResult> hScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>, ScanResult>>(client, + ProtocolCommand.HSCAN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>, ScanResult>>(client, + ProtocolCommand.HSCAN) + .run(args); + }else{ + return new LettuceSentinelCommand>, ScanResult>>(client, + ProtocolCommand.HSCAN) + .run(args); + } + } + + private List hVals(final byte[] key, final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.HVALS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.HVALS) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.HVALS) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelHyperLogLogOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelHyperLogLogOperations.java new file mode 100644 index 000000000..365d6510b --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelHyperLogLogOperations.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; + +/** + * Lettuce 哨兵模式 HyperLogLog 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelHyperLogLogOperations extends AbstractHyperLogLogOperations { + + public LettuceSentinelHyperLogLogOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Status pfAdd(final byte[] key, final byte[]... elements) { + final CommandArguments args = CommandArguments.create("key", key).put("elements", (Object[]) elements); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.PFADD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.PFADD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.PFADD) + .run(args); + } + } + + @Override + public Status pfMerge(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.PFMERGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.PFMERGE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.PFMERGE) + .run(args); + } + } + + @Override + public Long pfCount(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.PFMERGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.PFMERGE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.PFMERGE) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelKeyOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelKeyOperations.java new file mode 100644 index 000000000..d5884f959 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelKeyOperations.java @@ -0,0 +1,871 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListSetConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.ExpireOption; +import com.buession.redis.core.MigrateOperation; +import com.buession.redis.core.ObjectEncoding; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Type; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.convert.response.ObjectEncodingConverter; +import com.buession.redis.core.internal.convert.response.TypeConverter; +import com.buession.redis.core.internal.lettuce.LettuceMigrateArgs; +import com.buession.redis.core.internal.lettuce.LettuceRestoreArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.core.internal.lettuce.LettuceSortArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyScanCursor; +import io.lettuce.core.MigrateArgs; +import io.lettuce.core.RestoreArgs; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.SortArgs; + +import java.util.List; +import java.util.Set; + +/** + * Lettuce 哨兵模式 Key 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelKeyOperations extends AbstractKeyOperations { + + public LettuceSentinelKeyOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Long del(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.DEL) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.DEL) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.DEL) + .run(args); + } + } + + @Override + public byte[] dump(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.DUMP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.DUMP) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.DUMP) + .run(args); + } + } + + @Override + public Boolean exists(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.EXISTS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.EXISTS) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.EXISTS) + .run(args); + } + } + + @Override + public Long exists(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.EXISTS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.EXISTS) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.EXISTS) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.EXPIRE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.EXPIRE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.EXPIRE) + .run(args); + } + } + + @Override + public Status expire(final byte[] key, final int lifetime, final ExpireOption expireOption) { + final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime) + .put("expireOption", expireOption); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.EXPIRE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.EXPIRE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.EXPIRE) + .run(args); + } + } + + @Override + public Status expireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.EXPIREAT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.EXPIREAT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.EXPIREAT) + .run(args); + } + } + + @Override + public Status pExpire(final byte[] key, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.PEXPIRE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.PEXPIRE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.PEXPIRE) + .run(args); + } + } + + @Override + public Status pExpireAt(final byte[] key, final long unixTimestamp) { + final CommandArguments args = CommandArguments.create("key", key).put("unixTimestamp", unixTimestamp); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.EXPIREAT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.EXPIREAT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.EXPIREAT) + .run(args); + } + } + + @Override + public Status persist(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.PERSIST) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.PERSIST) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.PERSIST) + .run(args); + } + } + + @Override + public Long ttl(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.TTL) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.TTL) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.TTL) + .run(args); + } + } + + @Override + public Long pTtl(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.PTTL) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.PTTL) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.PTTL) + .run(args); + } + } + + @Override + public Status copy(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + return copy(args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + return copy(args); + } + + @Override + public Status copy(final String key, final String destKey, final int db) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("db", db); + return copy(args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("db", db); + return copy(args); + } + + @Override + public Status copy(final String key, final String destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("replace", replace); + return copy(args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final boolean replace) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("replace", replace); + return copy(args); + } + + @Override + public Status copy(final String key, final String destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("db", db) + .put("replace", replace); + return copy(args); + } + + @Override + public Status copy(final byte[] key, final byte[] destKey, final int db, final boolean replace) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("db", db) + .put("replace", replace); + return copy(args); + } + + @Override + public Status move(final byte[] key, final int db) { + final CommandArguments args = CommandArguments.create("key", key).put("db", db); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.MOVE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.MOVE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.MOVE) + .run(args); + } + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, final byte[]... + keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("timeout", timeout).put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(keys); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateOperation operation, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("timeout", timeout).put("operation", operation).put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(operation, keys); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final byte[] password, + final int timeout, + final byte[]... keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("password", password).put("timeout", timeout).put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(keys, password); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final byte[] password, + final int timeout, + final MigrateOperation operation, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("password", password).put("timeout", timeout).put("operation", operation) + .put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(operation, keys, password); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final byte[] user, + final byte[] password, + final int timeout, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("user", user).put("password", password).put("timeout", timeout) + .put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(keys, user, password); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Status migrate(final String host, final int port, final int db, final byte[] user, + final byte[] password, + final int timeout, final MigrateOperation operation, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("db", db) + .put("user", user).put("password", password).put("timeout", timeout) + .put("operation", operation) + .put("keys", (Object[]) keys); + final MigrateArgs migrateArgs = new LettuceMigrateArgs<>(keys, user, password); + + return migrate(host, port, db, timeout, migrateArgs, args); + } + + @Override + public Set keys(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final byte[] bPattern = SafeEncoder.encode(pattern); + final ListSetConverter binaryToStringListSetConverter = + Converters.listSetBinaryToString(); + + return keys(bPattern, binaryToStringListSetConverter, args); + } + + @Override + public Set keys(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final ListSetConverter converter = new ListSetConverter<>((v)->v); + + return keys(pattern, converter, args); + } + + @Override + public String randomKey() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.RANDOMKEY) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.RANDOMKEY) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.RANDOMKEY) + .run(); + } + } + + @Override + public Status rename(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.RENAME) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.RENAME) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.RENAME) + .run(args); + } + } + + @Override + public Status renameNx(final byte[] key, final byte[] newKey) { + final CommandArguments args = CommandArguments.create("key", key).put("newKey", newKey); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.RENAMENX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.RENAMENX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.RENAMENX) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl) { + final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) + .put("ttl", ttl); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.RESTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.RESTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.RESTORE) + .run(args); + } + } + + @Override + public Status restore(final byte[] key, final byte[] serializedValue, final int ttl, + final RestoreArgument argument) { + final CommandArguments args = CommandArguments.create("key", key).put("serializedValue", serializedValue) + .put("ttl", ttl).put("argument", argument); + final RestoreArgs restoreArgs = LettuceRestoreArgs.from(argument).ttl(ttl); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.RESTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.RESTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.RESTORE) + .run(args); + } + } + + @Override + public ScanResult> scan(final String cursor) { + final CommandArguments args = CommandArguments.create("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor) { + final CommandArguments args = CommandArguments.create("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, keyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, scanArgs, keyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final String cursor, final long count) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final long count) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, scanArgs, keyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final String cursor, final String pattern, final long count) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.KeyScanCursorConverter.BSKeyScanCursorConverter(); + + return scan(scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> scan(final byte[] cursor, final byte[] pattern, final long count) { + final CommandArguments args = CommandArguments.create("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.KeyScanCursorConverter keyScanCursorConverter = new ScanCursorConverter.KeyScanCursorConverter<>(); + + return scan(scanCursor, scanArgs, keyScanCursorConverter, args); + } + + @Override + public List sort(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return sort(bKey, binaryToStringListConverter, args); + } + + @Override + public List sort(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return sort(key, (v)->v, args); + } + + @Override + public List sort(final String key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("sortArgument", sortArgument); + final byte[] bKey = SafeEncoder.encode(key); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + + return sort(bKey, sortArgs, binaryToStringListConverter, args); + } + + @Override + public List sort(final byte[] key, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("sortArgument", sortArgument); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + + return sort(key, sortArgs, (v)->v, args); + } + + @Override + public Long sort(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + final SortArgs sortArgs = new LettuceSortArgs(); + + return sortStore(key, destKey, sortArgs, args); + } + + @Override + public Long sort(final byte[] key, final byte[] destKey, final SortArgument sortArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("sortArgument", sortArgument); + final SortArgs sortArgs = LettuceSortArgs.from(sortArgument); + + return sortStore(key, destKey, sortArgs, args); + } + + @Override + public Long touch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.TOUCH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.TOUCH) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.TOUCH) + .run(args); + } + } + + @Override + public Type type(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final TypeConverter typeConverter = new TypeConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.TYPE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.TYPE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.TYPE) + .run(args); + } + } + + @Override + public Long unlink(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.UNLINK) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.UNLINK) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.UNLINK) + .run(args); + } + } + + @Override + public ObjectEncoding objectEncoding(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final ObjectEncodingConverter objectEncodingConverter = new ObjectEncodingConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, + ProtocolCommand.OBJECT_ENCODING) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, + ProtocolCommand.OBJECT_ENCODING) + .run(args); + }else{ + return new LettuceSentinelCommand(client, + ProtocolCommand.OBJECT_ENCODING) + .run(args); + } + } + + @Override + public Long objectFreq(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.OBJECT_REFQ) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.OBJECT_REFQ) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.OBJECT_REFQ) + .run(args); + } + } + + @Override + public Long objectIdleTime(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.OBJECT_IDLETIME) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.OBJECT_IDLETIME) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.OBJECT_IDLETIME) + .run(args); + } + } + + @Override + public Long objectRefcount(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.OBJECT_REFCOUNT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.OBJECT_REFCOUNT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.OBJECT_REFCOUNT) + .run(args); + } + } + + private Status copy(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.COPY) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.COPY) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.COPY) + .run(args); + } + } + + private Status migrate(final String host, final int port, final int db, final int timeout, + final MigrateArgs migrateArgs, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.MIGRATE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.MIGRATE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.MIGRATE) + .run(args); + } + } + + private Set keys(final byte[] pattern, final ListSetConverter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Set>(client, ProtocolCommand.KEYS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Set>(client, ProtocolCommand.KEYS) + .run(args); + }else{ + return new LettuceSentinelCommand, Set>(client, ProtocolCommand.KEYS) + .run(args); + } + } + + private ScanResult> scan(final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>, ScanResult>>(client, + ProtocolCommand.SCAN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>, ScanResult>>(client, + ProtocolCommand.SCAN) + .run(args); + }else{ + return new LettuceSentinelCommand>, ScanResult>>(client, + ProtocolCommand.SCAN) + .run(args); + } + } + + private ScanResult> scan(final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>, ScanResult>>(client, + ProtocolCommand.SCAN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>, ScanResult>>(client, + ProtocolCommand.SCAN) + .run(args); + }else{ + return new LettuceSentinelCommand>, ScanResult>>(client, + ProtocolCommand.SCAN) + .run(args); + } + } + + private List sort(final byte[] key, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.SORT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.SORT) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.SORT) + .run(args); + } + } + + private List sort(final byte[] key, final SortArgs sortArgs, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.SORT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.SORT) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.SORT) + .run(args); + } + } + + private Long sortStore(final byte[] key, final byte[] destKey, final SortArgs sortArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SORT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SORT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SORT) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelListOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelListOperations.java new file mode 100644 index 000000000..a12978352 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelListOperations.java @@ -0,0 +1,541 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.builder.ListBuilder; +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.Direction; +import com.buession.redis.core.ListPosition; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.lettuce.LettuceLPosArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyValue; +import io.lettuce.core.LPosArgs; + +import java.util.List; + +/** + * Lettuce 哨兵模式列表命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelListOperations extends AbstractListOperations { + + public LettuceSentinelListOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public String lIndex(final String key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + final byte[] bKey = SafeEncoder.encode(key); + + return lIndex(bKey, index, SafeEncoder::encode, args); + } + + @Override + public byte[] lIndex(final byte[] key, final long index) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index); + return lIndex(key, index, (v)->v, args); + } + + @Override + public Long lInsert(final byte[] key, final ListPosition position, final byte[] pivot, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("position", position).put("pivot", pivot) + .put("value", value); + final boolean before = ListPosition.BEFORE == position; + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.LINSERT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.LINSERT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.LINSERT) + .run(args); + } + } + + @Override + public Status lSet(final byte[] key, final long index, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("index", index).put("value", value); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.LSET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.LSET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.LSET) + .run(args); + } + } + + @Override + public Long lLen(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.LLEN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.LLEN) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.LLEN) + .run(args); + } + } + + @Override + public List lRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + + return lRange(bKey, start, end, binaryToStringListConverter, args); + } + + @Override + public List lRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return lRange(key, start, end, (v)->v, args); + } + + @Override + public Long lPos(final byte[] key, final byte[] element) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.LPOS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.LPOS) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.LPOS) + .run(args); + } + } + + @Override + public Long lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument); + final LPosArgs lPosArgs = LettuceLPosArgs.from(lPosArgument); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.LPOS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.LPOS) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.LPOS) + .run(args); + } + } + + @Override + public List lPos(final byte[] key, final byte[] element, final LPosArgument lPosArgument, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("lPosArgument", lPosArgument) + .put("count", count); + final LPosArgs lPosArgs = LettuceLPosArgs.from(lPosArgument); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.LPOS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.LPOS) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.LPOS) + .run(args); + } + } + + @Override + public Long lRem(final byte[] key, final byte[] value, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("count", count); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.LREM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.LREM) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.LREM) + .run(args); + } + } + + @Override + public Status lTrim(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.LTRIM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.LTRIM) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.LTRIM) + .run(args); + } + } + + @Override + public String lMove(final String key, final String destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + return lMove(args); + } + + @Override + public byte[] lMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + return lMove(args); + } + + @Override + public String blMove(final String key, final String destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to); + return blMove(args); + } + + @Override + public byte[] blMove(final byte[] key, final byte[] destKey, final Direction from, final Direction to, + final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("from", from) + .put("to", to).put("timeout", timeout); + return blMove(args); + } + + @Override + public List blPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final Converter, List> converter = + (v)->ListBuilder.of(SafeEncoder.encode(v.getValue())); + + return blPop(bKeys, timeout, converter, args); + } + + @Override + public List blPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final Converter, List> converter = (v)->ListBuilder.of(v.getValue()); + + return blPop(keys, timeout, converter, args); + } + + @Override + public List brPop(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final Converter, List> converter = + (v)->ListBuilder.of(SafeEncoder.encode(v.getValue())); + + return brPop(bKeys, timeout, converter, args); + } + + @Override + public List brPop(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final Converter, List> converter = (v)->ListBuilder.of(v.getValue()); + + return brPop(keys, timeout, converter, args); + } + + @Override + public String brPoplPush(final String key, final String destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + + return brPoplPush(bKey, bDestKey, timeout, SafeEncoder::encode, args); + } + + @Override + public byte[] brPoplPush(final byte[] key, final byte[] destKey, final int timeout) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey) + .put("timeout", timeout); + return brPoplPush(key, destKey, timeout, (v)->v, args); + } + + @Override + public String lPop(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + + return lPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] lPop(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return lPop(key, (v)->v, args); + } + + @Override + public Long lPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.LPUSH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.LPUSH) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.LPUSH) + .run(args); + } + } + + @Override + public Long lPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.LPUSHX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.LPUSHX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.LPUSHX) + .run(args); + } + } + + @Override + public String rPop(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + + return rPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] rPop(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return rPop(key, (v)->v, args); + } + + @Override + public String rPoplPush(final String key, final String destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bDestKey = SafeEncoder.encode(destKey); + + return rPoplPush(bKey, bDestKey, SafeEncoder::encode, args); + } + + @Override + public byte[] rPoplPush(final byte[] key, final byte[] destKey) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey); + return rPoplPush(key, destKey, (v)->v, args); + } + + @Override + public Long rPush(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.RPUSH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.RPUSH) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.RPUSH) + .run(args); + } + } + + @Override + public Long rPushX(final byte[] key, final byte[]... values) { + final CommandArguments args = CommandArguments.create("key", key).put("values", (Object[]) values); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.RPUSHX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.RPUSHX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.RPUSHX) + .run(args); + } + } + + private V lIndex(final byte[] key, final long index, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.LINDEX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.LINDEX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.LINDEX) + .run(args); + } + } + + private List lRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.LRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.LRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.LRANGE) + .run(args); + } + } + + private V lMove(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.LMOVE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.LMOVE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.LMOVE) + .run(args); + } + } + + private V blMove(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.BLMOVE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.BLMOVE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.BLMOVE) + .run(args); + } + } + + private List blPop(final byte[][] keys, final int timeout, final Converter, + List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.BLPOP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.BLPOP) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.BLPOP) + .run(args); + } + } + + private List brPop(final byte[][] keys, final int timeout, final Converter, + List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.BRPOP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.BRPOP) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.BRPOP) + .run(args); + } + } + + private V brPoplPush(final byte[] key, final byte[] destKey, final int timeout, + final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.BRPOPLPUSH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.BRPOPLPUSH) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.BRPOPLPUSH) + .run(args); + } + } + + private V lPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.LPOP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.LPOP) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.LPOP) + .run(args); + } + } + + private V rPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.RPOP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.RPOP) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.RPOP) + .run(args); + } + } + + private V rPoplPush(final byte[] key, final byte[] destKey, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.RPOPLPUSH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.RPOPLPUSH) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.RPOPLPUSH) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelPubSubOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelPubSubOperations.java new file mode 100644 index 000000000..b4d9c50dd --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelPubSubOperations.java @@ -0,0 +1,287 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.MapConverter; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.PubSubListener; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 哨兵模式 Pub/Sub 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelPubSubOperations extends AbstractPubSubOperations { + + public LettuceSentinelPubSubOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public void pSubscribe(final String[] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + pSubscribe(args); + } + + @Override + public void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns) + .put("pubSubListener", pubSubListener); + pSubscribe(args); + } + + @Override + public Long publish(final byte[] channel, final byte[] message) { + final CommandArguments args = CommandArguments.create("channel", channel).put("message", message); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.PUBLISH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.PUBLISH) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.PUBLISH) + .run(args); + } + } + + @Override + public List pubsubChannels() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.PUBSUB_CHANNELS) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.PUBSUB_CHANNELS) + .run(); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(); + } + } + + @Override + public List pubsubChannels(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final byte[] bPattern = SafeEncoder.encode(pattern); + + return pubsubChannels(bPattern, binaryToStringListConverter, args); + } + + @Override + public List pubsubChannels(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + return pubsubChannels(pattern, (v)->v, args); + } + + @Override + public Long pubsubNumPat() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.PUBSUB_NUMPAT) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.PUBSUB_NUMPAT) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.PUBSUB_NUMPAT) + .run(); + } + } + + @Override + public Map pubsubNumSub(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + final byte[][] bChannels = SafeEncoder.encode(channels); + final MapConverter converter = new MapConverter<>(SafeEncoder::encode, (v)->v); + + return pubsubNumSub(bChannels, converter, args); + } + + @Override + public Map pubsubNumSub(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return pubsubNumSub(channels, (v)->v, args); + } + + @Override + public Object pUnSubscribe() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(); + } + } + + @Override + public Object pUnSubscribe(final String... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return pUnSubscribe(args); + } + + @Override + public Object pUnSubscribe(final byte[]... patterns) { + final CommandArguments args = CommandArguments.create("patterns", (Object[]) patterns); + return pUnSubscribe(args); + } + + @Override + public void subscribe(final String[] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + subscribe(args); + } + + @Override + public void subscribe(final byte[][] channels, final PubSubListener pubSubListener) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels) + .put("pubSubListener", pubSubListener); + subscribe(args); + } + + @Override + public Object unSubscribe() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(); + } + } + + @Override + public Object unSubscribe(final String... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return unSubscribe(args); + } + + @Override + public Object unSubscribe(final byte[]... channels) { + final CommandArguments args = CommandArguments.create("channels", (Object[]) channels); + return unSubscribe(args); + } + + private void pSubscribe(final CommandArguments args) { + if(isPipeline()){ + new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + }else{ + new LettuceSentinelCommand<>(client, ProtocolCommand.PSUBSCRIBE) + .run(args); + } + } + + private List pubsubChannels(final byte[] pattern, final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.PUBSUB_CHANNELS) + .run(args); + } + } + + private Map pubsubNumSub(final byte[][] channels, + final Converter, Map> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Map>(client, ProtocolCommand.PUBSUB_NUMSUB) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Map>(client, + ProtocolCommand.PUBSUB_NUMSUB) + .run(args); + }else{ + return new LettuceSentinelCommand, Map>(client, ProtocolCommand.PUBSUB_NUMSUB) + .run(args); + } + } + + private Object pUnSubscribe(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.PUNSUBSCRIBE) + .run(args); + } + } + + private void subscribe(final CommandArguments args) { + if(isPipeline()){ + new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else if(isTransaction()){ + new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + }else{ + new LettuceSentinelCommand<>(client, ProtocolCommand.SUBSCRIBE) + .run(args); + } + } + + private Object unSubscribe(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.UNSUBSCRIBE) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelScriptingOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelScriptingOperations.java new file mode 100644 index 000000000..26e0722fe --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelScriptingOperations.java @@ -0,0 +1,221 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; + +/** + * Lettuce 哨兵模式 Script 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelScriptingOperations extends AbstractScriptingOperations { + + public LettuceSentinelScriptingOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Object eval(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + final byte[][] bKeys = new byte[][]{}; + + return eval(script, bKeys, null, args); + } + + @Override + public Object eval(final String script, final String... params) { + final CommandArguments args = CommandArguments.create("script", script).put("params", (Object[]) params); + final byte[][] bKeys = new byte[][]{}; + final byte[][] bParams = SafeEncoder.encode(params); + + return eval(script, bKeys, bParams, args); + } + + @Override + public Object eval(final String script, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("script", script).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final byte[][] bKeys = SafeEncoder.encode(keys); + final byte[][] bArguments = SafeEncoder.encode(arguments); + + return eval(script, bKeys, bArguments, args); + } + + @Override + public Object evalSha(final String digest) { + final CommandArguments args = CommandArguments.create("digest", digest); + final byte[][] bKeys = new byte[][]{}; + + return evalSha(digest, bKeys, null, args); + } + + @Override + public Object evalSha(final String digest, final String... params) { + final CommandArguments args = CommandArguments.create("digest", digest).put("params", (Object[]) params); + final byte[][] bKeys = new byte[][]{}; + final byte[][] bParams = SafeEncoder.encode(params); + + return evalSha(digest, bKeys, bParams, args); + } + + @Override + public Object evalSha(final String digest, final String[] keys, final String[] arguments) { + final CommandArguments args = CommandArguments.create("digest", digest).put("keys", (Object[]) keys) + .put("arguments", (Object[]) arguments); + final byte[][] bKeys = SafeEncoder.encode(keys); + final byte[][] bArguments = SafeEncoder.encode(arguments); + + return evalSha(digest, bKeys, bArguments, args); + } + + @Override + public List scriptExists(final String... sha1) { + final CommandArguments args = CommandArguments.create("sha1", (Object[]) sha1); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.SCRIPT_EXISTS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.SCRIPT_EXISTS) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.SCRIPT_EXISTS) + .run(args); + } + } + + @Override + public Status scriptFlush() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SCRIPT_FLUSH) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SCRIPT_FLUSH) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SCRIPT_FLUSH) + .run(); + } + } + + @Override + public Status scriptFlush(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SCRIPT_FLUSH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SCRIPT_FLUSH) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SCRIPT_FLUSH) + .run(args); + } + } + + @Override + public String scriptLoad(final String script) { + final CommandArguments args = CommandArguments.create("script", script); + final byte[] bScript = SafeEncoder.encode(script); + + return scriptLoad(bScript, (v)->v, args); + } + + @Override + public byte[] scriptLoad(final byte[] script) { + final CommandArguments args = CommandArguments.create("script", script); + return scriptLoad(script, SafeEncoder::encode, args); + } + + @Override + public Status scriptKill() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SCRIPT_KILL) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SCRIPT_KILL) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SCRIPT_KILL) + .run(); + } + } + + private Object eval(final String script, final byte[][] keys, final byte[][] arguments, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.EVAL) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.EVAL) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.EVAL) + .run(args); + } + } + + private Object evalSha(final String digest, final byte[][] keys, final byte[][] arguments, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.EVALSHA) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.EVALSHA) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.EVALSHA) + .run(args); + } + } + + private V scriptLoad(final byte[] script, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SCRIPT_LOAD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SCRIPT_LOAD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SCRIPT_LOAD) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelServerOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelServerOperations.java new file mode 100644 index 000000000..e19c9384d --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelServerOperations.java @@ -0,0 +1,980 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.AclLog; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.Info; +import com.buession.redis.core.MemoryStats; +import com.buession.redis.core.Module; +import com.buession.redis.core.RedisMonitor; +import com.buession.redis.core.RedisServerTime; +import com.buession.redis.core.Role; +import com.buession.redis.core.SlowLog; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.response.RedisServerTimeConverter; +import com.buession.redis.core.internal.convert.lettuce.response.RoleConverter; +import com.buession.redis.core.internal.convert.lettuce.response.SlowlogConverter; +import com.buession.redis.core.internal.convert.response.InfoConverter; +import com.buession.redis.utils.SafeEncoder; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 哨兵模式服务端命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelServerOperations extends AbstractServerOperations { + + public LettuceSentinelServerOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public List aclCat() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + } + } + + @Override + public List aclCat(final String categoryName) { + final CommandArguments args = CommandArguments.create("categoryName", categoryName); + return aclCat(args); + } + + @Override + public List aclCat(final byte[] categoryName) { + final CommandArguments args = CommandArguments.create("categoryName", categoryName); + return aclCat(args); + } + + @Override + public Status aclSetUser(final String username, final String... rules) { + final CommandArguments args = CommandArguments.create("username", username).put("rules", (Object[]) rules); + return aclSetUser(args); + } + + @Override + public Status aclSetUser(final byte[] username, final byte[]... rules) { + final CommandArguments args = CommandArguments.create("username", username).put("rules", (Object[]) rules); + return aclSetUser(args); + } + + @Override + public AclUser aclGetUser(final String username) { + final CommandArguments args = CommandArguments.create("username", username); + return aclGetUser(args); + } + + @Override + public AclUser aclGetUser(final byte[] username) { + final CommandArguments args = CommandArguments.create("username", username); + return aclGetUser(args); + } + + @Override + public List aclUsers() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + } + } + + @Override + public String aclWhoAmI() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + } + } + + @Override + public Long aclDelUser(final String... usernames) { + final CommandArguments args = CommandArguments.create("usernames", (Object[]) usernames); + return aclDelUser(args); + } + + @Override + public Long aclDelUser(final byte[]... usernames) { + final CommandArguments args = CommandArguments.create("usernames", (Object[]) usernames); + return aclDelUser(args); + } + + @Override + public String aclGenPass() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + } + } + + @Override + public List aclList() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + } + } + + @Override + public Status aclLoad() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + } + } + + @Override + public List aclLog() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + } + } + + @Override + public List aclLog(final long count) { + final CommandArguments args = CommandArguments.create("count", count); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + } + } + + @Override + public Status aclLogReset() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + } + } + + @Override + public Status aclLogSave() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + } + } + + @Override + public String bgRewriteAof() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + } + } + + @Override + public String bgSave() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.BGSAVE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.BGSAVE) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.BGSAVE) + .run(); + } + } + + @Override + public Status configSet(final String parameter, final String value) { + final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + } + } + + @Override + public Status configSet(final Map configs) { + final CommandArguments args = CommandArguments.create(configs); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CONFIG_SET) + .run(args); + } + } + + @Override + public Map configGet(final String pattern) { + final CommandArguments args = CommandArguments.create(pattern); + return configGet(pattern, args); + } + + @Override + public Map configGet(final byte[] pattern) { + final CommandArguments args = CommandArguments.create(pattern); + final String sPattern = SafeEncoder.encode(pattern); + + return configGet(sPattern, args); + } + + @Override + public Status configResetStat() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CONFIG_RESETSTAT) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CONFIG_RESETSTAT) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CONFIG_RESETSTAT) + .run(); + } + } + + @Override + public Status configRewrite() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.CONFIG_REWRITE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.CONFIG_REWRITE) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.CONFIG_REWRITE) + .run(); + } + } + + @Override + public Long dbSize() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.DBSIZE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.DBSIZE) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.DBSIZE) + .run(); + } + } + + @Override + public Status failover() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.FAILOVER) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.FAILOVER) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.FAILOVER) + .run(); + } + } + + @Override + public Status failover(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + return failover(args); + } + + @Override + public Status failover(final String host, final int port, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("timeout", timeout); + return failover(args); + } + + @Override + public Status failover(final String host, final int port, final boolean isForce, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("isForce", isForce) + .put("timeout", timeout); + return failover(args); + } + + @Override + public Status failover(final int timeout) { + final CommandArguments args = CommandArguments.create(timeout); + return failover(args); + } + + @Override + public Status flushAll() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.FLUSHALL) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.FLUSHALL) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.FLUSHALL) + .run(); + } + } + + @Override + public Status flushAll(final FlushMode mode) { + final CommandArguments args = CommandArguments.create(mode); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.FLUSHALL) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.FLUSHALL) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.FLUSHALL) + .run(args); + } + } + + @Override + public Status flushDb() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.FLUSHDB) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.FLUSHDB) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.FLUSHDB) + .run(); + } + } + + @Override + public Status flushDb(final FlushMode mode) { + final CommandArguments args = CommandArguments.create(mode); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.FLUSHDB) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.FLUSHDB) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.FLUSHDB) + .run(args); + } + } + + @Override + public Info info() { + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(), + infoConverter) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(), + infoConverter) + .run(); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(), infoConverter) + .run(); + } + } + + @Override + public Info info(final Info.Section section) { + final CommandArguments args = CommandArguments.create(section); + final String sectionName = section.name().toLowerCase(); + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(sectionName), + infoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.FLUSHDB, + (cmd)->cmd.info(sectionName), infoConverter) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(sectionName), + infoConverter) + .run(args); + } + } + + @Override + public Long lastSave() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.LASTSAVE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.LASTSAVE) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.LASTSAVE) + .run(); + } + } + + @Override + public String memoryDoctor() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + } + } + + @Override + public Status memoryPurge() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + } + } + + @Override + public MemoryStats memoryStats() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + } + } + + @Override + public Long memoryUsage(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.MEMORY_USAGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.MEMORY_USAGE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.MEMORY_USAGE) + .run(args); + } + } + + @Override + public Long memoryUsage(final byte[] key, final int samples) { + final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.MEMORY_USAGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.MEMORY_USAGE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.MEMORY_USAGE) + .run(args); + } + } + + @Override + public List moduleList() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.MODULE_LIST) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.MODULE_LIST) + .run(); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.MODULE_LIST) + .run(); + } + } + + @Override + public Status moduleLoad(final String path, final String... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + return moduleLoad(args); + } + + @Override + public Status moduleLoad(final byte[] path, final byte[]... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + return moduleLoad(args); + } + + @Override + public Status moduleUnLoad(final String name) { + final CommandArguments args = CommandArguments.create("name", name); + return moduleUnLoad(args); + } + + @Override + public Status moduleUnLoad(final byte[] name) { + final CommandArguments args = CommandArguments.create("name", name); + return moduleUnLoad(args); + } + + @Override + public void monitor(final RedisMonitor redisMonitor) { + final CommandArguments args = CommandArguments.create("redisMonitor", redisMonitor); + + if(isPipeline()){ + new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + }else if(isTransaction()){ + new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + }else{ + new LettuceSentinelCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + } + } + + @Override + public Object pSync(final String replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return pSync(args); + } + + @Override + public Object pSync(final byte[] replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return pSync(args); + } + + @Override + public void sync() { + if(isPipeline()){ + new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.SYNC) + .run(); + }else if(isTransaction()){ + new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.SYNC) + .run(); + }else{ + new LettuceSentinelCommand<>(client, ProtocolCommand.SYNC) + .run(); + } + } + + @Override + public Status replicaOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + } + } + + @Override + public Status slaveOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SLAVEOF) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SLAVEOF) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SLAVEOF) + .run(args); + } + } + + @Override + public Role role() { + final RoleConverter roleConverter = new RoleConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ROLE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ROLE) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ROLE) + .run(); + } + } + + @Override + public Status save() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SAVE) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SAVE) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SAVE) + .run(); + } + } + + @Override + public void shutdown() { + if(isPipeline()){ + new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + }else if(isTransaction()){ + new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + }else{ + new LettuceSentinelCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(); + } + } + + @Override + public void shutdown(final boolean save) { + final CommandArguments args = CommandArguments.create("save", save); + + if(isPipeline()){ + new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(args); + }else if(isTransaction()){ + new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(args); + }else{ + new LettuceSentinelCommand<>(client, ProtocolCommand.SHUTDOWN) + .run(args); + } + } + + @Override + public List slowLogGet() { + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.SLOWLOG_GET) + .run(); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(); + } + } + + @Override + public List slowLogGet(final long count) { + final CommandArguments args = CommandArguments.create("count", count); + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.SLOWLOG_GET) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.SLOWLOG_GET) + .run(args); + } + } + + @Override + public Long slowLogLen() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SLOWLOG_LEN) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SLOWLOG_LEN) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SLOWLOG_LEN) + .run(); + } + } + + @Override + public Status slowLogReset() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SLOWLOG_RESET) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SLOWLOG_RESET) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SLOWLOG_RESET) + .run(); + } + } + + @Override + public Status swapdb(final int db1, final int db2) { + final CommandArguments args = CommandArguments.create("db1", db1).put("db2", db2); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SWAPDB) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SWAPDB) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SWAPDB) + .run(args); + } + } + + @Override + public RedisServerTime time() { + final RedisServerTimeConverter redisServerTimeConverter = new RedisServerTimeConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.TIME) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.TIME) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.TIME) + .run(); + } + } + + private List aclCat(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(args); + } + } + + private Status aclSetUser(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + } + } + + private AclUser aclGetUser(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + } + } + + private Long aclDelUser(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ACL_DELUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ACL_DELUSER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ACL_DELUSER) + .run(args); + } + } + + private Map configGet(final String pattern, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Map>(client, ProtocolCommand.CONFIG_GET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Map>(client, ProtocolCommand.CONFIG_GET) + .run(args); + }else{ + return new LettuceSentinelCommand, Map>(client, ProtocolCommand.CONFIG_GET) + .run(args); + } + } + + private Status failover(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.FAILOVER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.FAILOVER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.FAILOVER) + .run(args); + } + } + + private Status moduleLoad(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + } + } + + private Status moduleUnLoad(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + } + } + + private Object pSync(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + }else{ + return new LettuceSentinelCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelSetOperations.java new file mode 100644 index 000000000..f7d49a73f --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelSetOperations.java @@ -0,0 +1,562 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.SetConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.ValueScanCursor; + +import java.util.List; +import java.util.Set; + +/** + * Lettuce 哨兵模式集合命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelSetOperations extends AbstractSetOperations { + + public LettuceSentinelSetOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Long sAdd(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SADD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SADD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SADD) + .run(args); + } + } + + @Override + public Long sCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SCARD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SCARD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SCARD) + .run(args); + } + } + + @Override + public Set sDiff(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sDiff(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return sDiff(keys, (v)->v, args); + } + + @Override + public Long sDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SDIFFSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SDIFFSTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SDIFFSTORE) + .run(args); + } + } + + @Override + public Set sInter(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sInter(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return sInter(keys, (v)->v, args); + } + + @Override + public Long sInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SINTERSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SINTERSTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SINTERSTORE) + .run(args); + } + } + + @Override + public Boolean sIsMember(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SISMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SISMEMBER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SISMEMBER) + .run(args); + } + } + + @Override + public List smIsMember(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return smIsMember(args); + } + + @Override + public List smIsMember(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return smIsMember(args); + } + + @Override + public Set sMembers(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sMembers(bKey, binaryToStringSetConverter, args); + } + + @Override + public Set sMembers(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return sMembers(key, (v)->v, args); + } + + @Override + public Status sMove(final byte[] key, final byte[] destKey, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SMOVE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SMOVE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SMOVE) + .run(args); + } + } + + @Override + public String sPop(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + + return sPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] sPop(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return sPop(key, (v)->v, args); + } + + @Override + public Set sPop(final String key, final long count) { + final CommandArguments args = CommandArguments.create(key).add(count); + final byte[] bKey = SafeEncoder.encode(key); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sPop(bKey, count, binaryToStringSetConverter, args); + } + + @Override + public Set sPop(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create(key).add(count); + return sPop(key, count, (v)->v, args); + } + + @Override + public String sRandMember(final String key) { + final CommandArguments args = CommandArguments.create(key); + final byte[] bKey = SafeEncoder.encode(key); + + return sRandMember(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] sRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return sRandMember(key, (v)->v, args); + } + + @Override + public List sRandMember(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + + return sRandMember(bKey, count, binaryToStringListConverter, args); + } + + @Override + public List sRandMember(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return sRandMember(key, count, (v)->v, args); + } + + @Override + public Long sRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SREM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SREM) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SREM) + .run(args); + } + } + + @Override + public ScanResult> sScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(pattern); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(pattern); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, scanArgs, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, scanArgs, valueScanCursorConverter, args); + } + + @Override + public Set sUnion(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sUnion(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return sUnion(keys, (v)->v, args); + } + + @Override + public Long sUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SUNIONSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SUNIONSTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SUNIONSTORE) + .run(args); + } + } + + private Set sDiff(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Set>(client, ProtocolCommand.SDIFF) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Set>(client, ProtocolCommand.SDIFF) + .run(args); + }else{ + return new LettuceSentinelCommand, Set>(client, ProtocolCommand.SDIFF) + .run(args); + } + } + + private Set sInter(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Set>(client, ProtocolCommand.SINTER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Set>(client, ProtocolCommand.SINTER) + .run(args); + }else{ + return new LettuceSentinelCommand, Set>(client, ProtocolCommand.SINTER) + .run(args); + } + } + + private List smIsMember(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.SMISMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.SMISMEMBER) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.SMISMEMBER) + .run(args); + } + } + + private Set sMembers(final byte[] key, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Set>(client, ProtocolCommand.SMEMBERS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Set>(client, ProtocolCommand.SMEMBERS) + .run(args); + }else{ + return new LettuceSentinelCommand, Set>(client, ProtocolCommand.SMEMBERS) + .run(args); + } + } + + private V sPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SPOP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SPOP) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SPOP) + .run(args); + } + } + + private Set sPop(final byte[] key, final long count, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Set>(client, ProtocolCommand.SPOP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Set>(client, ProtocolCommand.SPOP) + .run(args); + }else{ + return new LettuceSentinelCommand, Set>(client, ProtocolCommand.SPOP) + .run(args); + } + } + + private V sRandMember(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SPOP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SPOP) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SPOP) + .run(args); + } + } + + private List sRandMember(final byte[] key, final long count, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.SRANDMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.SRANDMEMBER) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.SRANDMEMBER) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>, ScanResult>>(client, + ProtocolCommand.SSCAN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>, ScanResult>>(client, + ProtocolCommand.SSCAN) + .run(args); + }else{ + return new LettuceSentinelCommand>, ScanResult>>(client, ProtocolCommand.SSCAN) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>, ScanResult>>(client, + ProtocolCommand.SSCAN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>, ScanResult>>(client, + ProtocolCommand.SSCAN) + .run(args); + }else{ + return new LettuceSentinelCommand>, ScanResult>>(client, + ProtocolCommand.SSCAN) + .run(args); + } + } + + private Set sUnion(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, Set>(client, ProtocolCommand.SUNION) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, Set>(client, ProtocolCommand.SUNION) + .run(args); + }else{ + return new LettuceSentinelCommand, Set>(client, ProtocolCommand.SUNION) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelSortedSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelSortedSetOperations.java new file mode 100644 index 000000000..f915dea57 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelSortedSetOperations.java @@ -0,0 +1,1901 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.utils.NumberUtils; +import com.buession.lang.KeyValue; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.Aggregate; +import com.buession.redis.core.GtLt; +import com.buession.redis.core.NxXx; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; +import com.buession.redis.core.ZRangeBy; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.core.internal.lettuce.LettuceZAddArgs; +import com.buession.redis.core.internal.lettuce.LettuceZStoreArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.Limit; +import io.lettuce.core.Range; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.ScoredValue; +import io.lettuce.core.ScoredValueScanCursor; +import io.lettuce.core.ZAddArgs; +import io.lettuce.core.ZStoreArgs; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 哨兵模式模式有序集合命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelSortedSetOperations extends AbstractSortedSetOperations { + + public LettuceSentinelSortedSetOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Tuple zPopMin(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZPOPMIN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZPOPMIN) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZPOPMIN) + .run(args); + } + } + + @Override + public List zPopMin(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZPOPMIN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZPOPMIN) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZPOPMIN) + .run(args); + } + } + + @Override + public Tuple zPopMax(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZPOPMAX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZPOPMAX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZPOPMAX) + .run(args); + } + } + + @Override + public List zPopMax(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZPOPMAX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZPOPMAX) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZPOPMAX) + .run(args); + } + } + + @Override + public KeyValue bzPopMin(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, KeyValue>( + client, ProtocolCommand.BZPOPMIN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, KeyValue>( + client, ProtocolCommand.BZPOPMIN) + .run(args); + }else{ + return new LettuceSentinelCommand, KeyValue>( + client, ProtocolCommand.BZPOPMIN) + .run(args); + } + } + + @Override + public KeyValue bzPopMin(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, KeyValue>( + client, ProtocolCommand.BZPOPMIN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, KeyValue>( + client, ProtocolCommand.BZPOPMIN) + .run(args); + }else{ + return new LettuceSentinelCommand, KeyValue>( + client, ProtocolCommand.BZPOPMIN) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, KeyValue>( + client, ProtocolCommand.BZPOPMAX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, KeyValue>( + client, ProtocolCommand.BZPOPMAX) + .run(args); + }else{ + return new LettuceSentinelCommand, KeyValue>( + client, ProtocolCommand.BZPOPMAX) + .run(args); + } + } + + @Override + public KeyValue bzPopMax(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, KeyValue>( + client, ProtocolCommand.BZPOPMAX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, KeyValue>( + client, ProtocolCommand.BZPOPMAX) + .run(args); + }else{ + return new LettuceSentinelCommand, KeyValue>( + client, ProtocolCommand.BZPOPMAX) + .run(args); + } + } + + @Override + public Long zAdd(final String key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + return zAdd(key, members, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + return zAdd(key, members, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZCARD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZCARD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZCARD) + .run(args); + } + } + + @Override + public Long zCount(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZCOUNT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZCOUNT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZCOUNT) + .run(args); + } + } + + @Override + public List zDiff(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public List zDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public List zDiffWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public List zDiffWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zDiff(args); + } + + @Override + public Long zDiffStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + return zDiffStore(args); + } + + @Override + public Long zDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + return zDiffStore(args); + } + + @Override + public Double zIncrBy(final byte[] key, final double increment, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) + .put("member", member); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZINCRBY) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZINCRBY) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZINCRBY) + .run(args); + } + } + + @Override + public List zInter(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZINTERSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZINTERSTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZINTERSTORE) + .run(args); + } + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate); + + return zInterStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(weights); + + return zInterStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate, weights); + + return zInterStore(destKey, keys, zStoreArgs, args); + } + + @Deprecated + @Override + public Long zLexCount(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZLEXCOUNT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZLEXCOUNT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZLEXCOUNT) + .run(args); + } + } + + @Override + public List zMScore(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return zMScore(args); + } + + @Override + public List zMScore(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return zMScore(args); + } + + @Override + public String zRandMember(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + return zRandMember(args); + } + + @Override + public byte[] zRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return zRandMember(args); + } + + @Override + public List zRandMember(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMember(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMemberWithScores(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMemberWithScores(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + + return zRange(bKey, start, end, binaryToStringListConverter, args); + } + + @Override + public List zRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return zRange(key, start, end, (v)->v, args); + } + + @Override + public List zRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZRANGE) + .run(args); + } + } + + @Override + public List zRangeByLex(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(bKey, bMin, bMax, binaryToStringListConverter, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, (v)->v, args); + } + + @Deprecated + @Override + public List zRangeByLex(final String key, final String min, final String max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = SafeEncoder.encode(min); + final byte[] bMax = SafeEncoder.encode(max); + + return zRangeByLex(bKey, bMin, bMax, binaryToStringListConverter, args); + } + + @Deprecated + @Override + public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRangeByLex(key, min, max, (v)->v, args); + } + + @Override + public List zRangeByLex(final String key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(bKey, bMin, bMax, offset, count, binaryToStringListConverter, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, offset, count, (v)->v, args); + } + + @Deprecated + @Override + public List zRangeByLex(final String key, final String min, final String max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = SafeEncoder.encode(min); + final byte[] bMax = SafeEncoder.encode(max); + + return zRangeByLex(bKey, bMin, bMax, offset, count, binaryToStringListConverter, args); + } + + @Deprecated + @Override + public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRangeByLex(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + + return zRangeByScore(bKey, min, max, binaryToStringListConverter, args); + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRangeByScore(key, min, max, (v)->v, args); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + + return zRangeByScore(bKey, min, max, offset, count, binaryToStringListConverter, args); + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRangeByScore(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.ZRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZRANGEBYSCORE) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.ZRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZRANGEBYSCORE) + .run(args); + } + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev, + final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev, + final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZRANK) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZRANK) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZRANK) + .run(args); + } + } + + @Override + public Long zRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZREM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZREM) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZREM) + .run(args); + } + } + + @Deprecated + @Override + public Long zRemRangeByLex(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZREMRANGEBYLEX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZREMRANGEBYLEX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZREMRANGEBYLEX) + .run(args); + } + } + + @Override + public Long zRemRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZREMRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZREMRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZREMRANGEBYSCORE) + .run(args); + } + } + + @Override + public Long zRemRangeByRank(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZREMRANGEBYRANK) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZREMRANGEBYRANK) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZREMRANGEBYRANK) + .run(args); + } + } + + @Override + public List zRevRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + + return zRevRange(bKey, start, end, binaryToStringListConverter, args); + } + + @Override + public List zRevRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return zRevRange(key, start, end, (v)->v, args); + } + + @Override + public List zRevRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZREVRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZREVRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZREVRANGE) + .run(args); + } + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(bKey, bMin, bMax, binaryToStringListConverter, args); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(key, bMin, bMax, (v)->v, args); + } + + @Deprecated + @Override + public List zRevRangeByLex(final String key, final String min, final String max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = SafeEncoder.encode(min); + final byte[] bMax = SafeEncoder.encode(max); + + return zRevRangeByLex(bKey, bMin, bMax, binaryToStringListConverter, args); + } + + @Deprecated + @Override + public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRevRangeByLex(key, min, max, (v)->v, args); + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(bKey, bMin, bMax, offset, count, binaryToStringListConverter, args); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(key, bMin, bMax, offset, count, (v)->v, args); + } + + @Deprecated + @Override + public List zRevRangeByLex(final String key, final String min, final String max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = SafeEncoder.encode(min); + final byte[] bMax = SafeEncoder.encode(max); + + return zRevRangeByLex(bKey, bMin, bMax, offset, count, binaryToStringListConverter, args); + } + + @Deprecated + @Override + public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + return zRevRangeByLex(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + + return zRevRangeByScore(bKey, min, max, binaryToStringListConverter, args); + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRevRangeByScore(key, min, max, (v)->v, args); + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + + return zRevRangeByScore(bKey, min, max, offset, count, binaryToStringListConverter, args); + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRevRangeByScore(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.ZREVRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.ZREVRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZREVRANGEBYSCORE) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max, + final long offset, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.ZREVRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.ZREVRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZREVRANGEBYSCORE) + .run(args); + } + } + + @Override + public Long zRevRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZREVRANK) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZREVRANK) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZREVRANK) + .run(args); + } + } + + @Override + public ScanResult> zScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public Double zScore(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZSCORE) + .run(args); + } + } + + @Override + public List zUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZUNIONSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZUNIONSTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZUNIONSTORE) + .run(args); + } + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate); + + return zUnionStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(weights); + + return zUnionStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate, weights); + + return zUnionStore(destKey, keys, zStoreArgs, args); + } + + private Long zAdd(final String key, final Map members, final CommandArguments args) { + final byte[] bKey = SafeEncoder.encode(key); + final ScoredValue[] scoredValues = new ScoredValue[members.size()]; + int i = 0; + + for(Map.Entry e : members.entrySet()){ + scoredValues[i++] = e.getValue() == null ? ScoredValue.empty() : ScoredValue.just(e.getValue(), + SafeEncoder.encode(e.getKey())); + } + + return zAdd(bKey, scoredValues, args); + } + + private Long zAdd(final String key, final Map members, final ZAddArgs zAddArgs, + final CommandArguments args) { + final byte[] bKey = SafeEncoder.encode(key); + final ScoredValue[] scoredValues = new ScoredValue[members.size()]; + int i = 0; + + for(Map.Entry e : members.entrySet()){ + scoredValues[i++] = e.getValue() == null ? ScoredValue.empty() : ScoredValue.just(e.getValue(), + SafeEncoder.encode(e.getKey())); + } + + return zAdd(bKey, scoredValues, zAddArgs, args); + } + + private Long zAdd(final byte[] key, final Map members, final CommandArguments args) { + final ScoredValue[] scoredValues = new ScoredValue[members.size()]; + int i = 0; + + for(Map.Entry e : members.entrySet()){ + scoredValues[i++] = e.getValue() == null ? ScoredValue.empty() : ScoredValue.just(e.getValue(), + e.getKey()); + } + + return zAdd(key, scoredValues, args); + } + + private Long zAdd(final byte[] key, final Map members, final ZAddArgs zAddArgs, + final CommandArguments args) { + final ScoredValue[] scoredValues = new ScoredValue[members.size()]; + int i = 0; + + for(Map.Entry e : members.entrySet()){ + scoredValues[i++] = e.getValue() == null ? ScoredValue.empty() : ScoredValue.just(e.getValue(), + e.getKey()); + } + + return zAdd(key, scoredValues, zAddArgs, args); + } + + private Long zAdd(final byte[] key, final ScoredValue[] scoredValues, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZADD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZADD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZADD) + .run(args); + } + } + + private Long zAdd(final byte[] key, final ScoredValue[] scoredValues, final ZAddArgs zAddArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZADD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZADD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZADD) + .run(args); + } + } + + private List zDiff(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZDIFF) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZDIFF) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZDIFF) + .run(args); + } + } + + private Long zDiffStore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZDIFFSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZDIFFSTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZDIFFSTORE) + .run(args); + } + } + + private List zInter(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZINTER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZINTER) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZINTER) + .run(args); + } + } + + private Long zInterStore(final byte[] destKey, final byte[][] keys, final ZStoreArgs zStoreArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZINTERSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZINTERSTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZINTERSTORE) + .run(args); + } + } + + private List zMScore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZMSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZMSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZMSCORE) + .run(args); + } + } + + private V zRandMember(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZRANDMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZRANDMEMBER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZRANDMEMBER) + .run(args); + } + } + + private List zRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZRANGE) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final Converter, List> converter, final CommandArguments args) { + return zRangeByLex(key, Range.create(min, max), converter, args); + } + + private List zRangeByLex(final byte[] key, final Range range, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZRANGEBYLEX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZRANGEBYLEX) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZRANGEBYLEX) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count, final Converter, List> converter, + final CommandArguments args) { + return zRangeByLex(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRangeByLex(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZRANGEBYLEX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZRANGEBYLEX) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZRANGEBYLEX) + .run(args); + } + } + + private List zRangeByScore(final byte[] key, final double min, final double max, + final Converter, List> converter, final CommandArguments args) { + return zRangeByScore(key, Range.create(min, max), converter, args); + } + + private List zRangeByScore(final byte[] key, final Range range, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZRANGEBYSCORE) + .run(args); + } + } + + private List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final long count, final Converter, List> converter, + final CommandArguments args) { + return zRangeByScore(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRangeByScore(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZRANGEBYSCORE) + .run(args); + } + } + + private Long zRangeStore(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZRANGESTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZRANGESTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZRANGESTORE) + .run(args); + } + } + + private List zRevRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZREVRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZREVRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZREVRANGE) + .run(args); + } + } + + private List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final Converter, List> converter, final CommandArguments args) { + return zRevRangeByLex(key, Range.create(min, max), converter, args); + } + + private List zRevRangeByLex(final byte[] key, final Range range, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZREVRANGEBYLEX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZREVRANGEBYLEX) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZREVRANGEBYLEX) + .run(args); + } + } + + private List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count, final Converter, List> converter, + final CommandArguments args) { + return zRevRangeByLex(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRevRangeByLex(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZREVRANGEBYLEX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZREVRANGEBYLEX) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZREVRANGEBYLEX) + .run(args); + } + } + + private List zRevRangeByScore(final byte[] key, final double min, final double max, + final Converter, List> converter, + final CommandArguments args) { + return zRevRangeByScore(key, Range.create(min, max), converter, args); + } + + private List zRevRangeByScore(final byte[] key, final Range range, + final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZREVRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZREVRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZREVRANGEBYSCORE) + .run(args); + } + } + + private List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final long count, final Converter, List> converter, + final CommandArguments args) { + return zRevRangeByScore(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRevRangeByScore(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZREVRANGEBYSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZREVRANGEBYSCORE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZREVRANGEBYSCORE) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>, ScanResult>>(client, + ProtocolCommand.ZREVRANK) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>, ScanResult>>(client, + ProtocolCommand.ZREVRANK) + .run(args); + }else{ + return new LettuceSentinelCommand>, ScanResult>>(client, + ProtocolCommand.ZREVRANK) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>, ScanResult>>(client, + ProtocolCommand.ZREVRANK) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>, ScanResult>>(client, + ProtocolCommand.ZREVRANK) + .run(args); + }else{ + return new LettuceSentinelCommand>, ScanResult>>(client, + ProtocolCommand.ZREVRANK) + .run(args); + } + } + + private List zUnion(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.ZUNION) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.ZUNION) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.ZUNION) + .run(args); + } + } + + private Long zUnionStore(final byte[] destKey, final byte[][] keys, final ZStoreArgs zStoreArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.ZUNIONSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.ZUNIONSTORE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.ZUNIONSTORE) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelStreamOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelStreamOperations.java new file mode 100644 index 000000000..40d68c1ff --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelStreamOperations.java @@ -0,0 +1,1130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.Stream; +import com.buession.redis.core.StreamConsumer; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import com.buession.redis.core.StreamGroup; +import com.buession.redis.core.StreamPending; +import com.buession.redis.core.StreamPendingSummary; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.params.StreamEntryIdConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamEntryIDConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamMessageConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamMessageMapConverter; +import com.buession.redis.core.internal.lettuce.LettuceXAddArgs; +import com.buession.redis.core.internal.lettuce.LettuceXClaimArgs; +import com.buession.redis.core.internal.lettuce.LettuceXReadArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.Consumer; +import io.lettuce.core.Limit; +import io.lettuce.core.Range; +import io.lettuce.core.StreamMessage; +import io.lettuce.core.XAddArgs; +import io.lettuce.core.XClaimArgs; +import io.lettuce.core.XReadArgs; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 哨兵模式 Stream 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelStreamOperations extends AbstractStreamOperations { + + public LettuceSentinelStreamOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("ids", (Object[]) ids); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.XACK) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.XACK) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.XACK) + .run(args); + } + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash); + final XAddArgs xAddArgs = new LettuceXAddArgs(id); + + return xAdd(key, hash, xAddArgs, args); + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) + .put("xAddArgument", xAddArgument); + final StreamEntryIdConverter streamEntryIdConverter = new StreamEntryIdConverter(); + final XAddArgs xAddArgs = LettuceXAddArgs.from(xAddArgument).id(streamEntryIdConverter.convert(id)); + + return xAdd(key, hash, xAddArgs, args); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count"); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count"); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaimJustId(args); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = new LettuceXClaimArgs(minIdleTime); + + return xClaim(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = LettuceXClaimArgs.from(xClaimArgument).minIdleTime(minIdleTime); + + return xClaim(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = new LettuceXClaimArgs(minIdleTime, true); + + return xClaimJustId(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = LettuceXClaimArgs.from(xClaimArgument).minIdleTime(minIdleTime).justid(); + + return xClaimJustId(key, ids, consumer, xClaimArgs, args); + } + + @Override + public Long xDel(final byte[] key, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("ids", (Object[]) ids); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.XDEL) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.XDEL) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.XDEL) + .run(args); + } + } + + @Override + public Status xGroupCreate(final byte[] key, final byte[] groupName, final StreamEntryId id, + final boolean makeStream) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("id", id); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.XGROUP_CREATE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.XGROUP_CREATE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.XGROUP_CREATE) + .run(args); + } + } + + @Override + public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + return xGroupCreateConsumer(args); + } + + @Override + public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + return xGroupCreateConsumer(args); + } + + @Override + public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Converter converter = (v)->v ? 1L : 0L; + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.XGROUP_DELCONSUMER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.XGROUP_DELCONSUMER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.XGROUP_DELCONSUMER) + .run(args); + } + } + + @Override + public Status xGroupDestroy(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.XGROUP_DESTROY) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.XGROUP_DESTROY) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.XGROUP_DESTROY) + .run(args); + } + } + + @Override + public Status xGroupSetId(final byte[] key, final byte[] groupName, final StreamEntryId id) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName).put("id", id); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.XGROUP_SETID) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.XGROUP_SETID) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.XGROUP_SETID) + .run(args); + } + } + + @Override + public List xInfoConsumers(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.XINFO_CONSUMERS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.XINFO_CONSUMERS) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + ProtocolCommand.XINFO_CONSUMERS) + .run(args); + } + } + + @Override + public List xInfoGroups(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.XINFO_GROUPS) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.XINFO_GROUPS) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + ProtocolCommand.XINFO_GROUPS) + .run(args); + } + } + + @Override + public Stream xInfoStream(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.XINFO_STREAM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.XINFO_STREAM) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.XINFO_STREAM) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.XINFO_STREAM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.XINFO_STREAM) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.XINFO_STREAM) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full).put("count", count); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.XINFO_STREAM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.XINFO_STREAM) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.XINFO_STREAM) + .run(args); + } + } + + @Override + public Long xLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.XLEN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.XLEN) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.XLEN) + .run(args); + } + } + + @Override + public StreamPendingSummary xPending(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, + ProtocolCommand.XPENDING) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, + ProtocolCommand.XPENDING) + .run(args); + }else{ + return new LettuceSentinelCommand(client, + ProtocolCommand.XPENDING) + .run(args); + } + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.XPENDING) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.XPENDING) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + ProtocolCommand.XPENDING) + .run(args); + } + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("start", start).put("end", end).put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, groupName, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.unbounded(); + final Limit limit = Limit.unlimited(); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("start", start).put("end", end).put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, groupName, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.unbounded(); + final Limit limit = Limit.unlimited(); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final long count, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final long count, + final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.XRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.XRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.XRANGE) + .run(args); + } + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.XRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.XRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.XRANGE) + .run(args); + } + } + + @Override + public List>> xRead(final Map streams) { + final CommandArguments args = CommandArguments.create("streams", streams); + return xRead(streams, args); + } + + @Override + public List>> xRead(final long count, final Map streams) { + final CommandArguments args = CommandArguments.create("count", count).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(count); + + return xRead(xReadArgs, streams, args); + } + + @Override + public List>> xRead(final int block, final Map streams) { + final CommandArguments args = CommandArguments.create("block", block).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block); + + return xRead(xReadArgs, streams, args); + } + + @Override + public List>> xRead(final long count, final int block, + final Map streams) { + final CommandArguments args = CommandArguments.create("count", count).put("block", block) + .put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block, count); + + return xRead(xReadArgs, streams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams); + return xReadGroup(groupName, consumerName, streams, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams); + return xReadGroup(groupName, consumerName, streams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final long count, final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final long count, final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final int block, final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("block", block).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final int block, final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("block", block).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = (new LettuceXReadArgs()).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = (new LettuceXReadArgs()).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final long count, final int block, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("block", block).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final long count, final int block, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("block", block).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final long count, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(isNoAck, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final long count, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(isNoAck, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final int block, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("block", block).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = (new LettuceXReadArgs()).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final int block, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("block", block).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = (new LettuceXReadArgs()).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final long count, final int block, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("block", block).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block, isNoAck, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final long count, final int block, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("block", block).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block, isNoAck, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start); + final Range range = Range.create(start.toString(), end.toString()); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.XREVRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.XREVRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.XREVRANGE) + .run(args); + } + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start) + .put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.XREVRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.XREVRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.XREVRANGE) + .run(args); + } + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); + return xTrim(key, xTrimArgument.isApproximateTrimming(), Long.MAX_VALUE, args); + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) + .put("limit", limit); + return xTrim(key, xTrimArgument.isApproximateTrimming(), limit, args); + } + + private StreamEntryId xAdd(final byte[] key, final Map hash, final XAddArgs xAddArgs, + final CommandArguments args) { + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.XADD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.XADD) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.XADD) + .run(args); + } + } + + private Map> xAutoClaim(final CommandArguments args) { + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + }else{ + return new LettuceSentinelCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + } + } + + private Map> xAutoClaimJustId(final CommandArguments args) { + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + }else{ + return new LettuceSentinelCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + } + } + + private List xClaim(final byte[] key, final StreamEntryId[] ids, final Consumer consumer, + final XClaimArgs xClaimArgs, final CommandArguments args) { + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.XCLAIM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.XCLAIM) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.XCLAIM) + .run(args); + } + } + + private List xClaimJustId(final byte[] key, final StreamEntryId[] ids, + final Consumer consumer, final XClaimArgs xClaimArgs, + final CommandArguments args) { + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter, StreamEntryId> listStreamMessageStreamEntryIdConverter + = StreamMessageConverter.StreamMessageStreamEntryIdConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.XCLAIM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.XCLAIM) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + ProtocolCommand.XCLAIM) + .run(args); + } + } + + private Status xGroupCreateConsumer(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.XGROUP_CREATECONSUMER) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.XGROUP_CREATECONSUMER) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.XGROUP_CREATECONSUMER) + .run(args); + } + } + + private List xPending(final byte[] key, final byte[] groupName, Range range, + final Limit limit, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.XPENDING) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.XPENDING) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + ProtocolCommand.XPENDING) + .run(args); + } + } + + private List xPending(final byte[] key, final Consumer consumer, Range range, + final Limit limit, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, + ProtocolCommand.XPENDING) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, + ProtocolCommand.XPENDING) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, + ProtocolCommand.XPENDING) + .run(args); + } + } + + private List>> xRead(final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = createStreamOffsetFromStreamEntryIdMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>>, List>>>( + client, ProtocolCommand.XREAD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>>, List>>>( + client, ProtocolCommand.XREAD) + .run(args); + }else{ + return new LettuceSentinelCommand>>, List>>>( + client, ProtocolCommand.XREAD) + .run(args); + } + } + + private List>> xRead(final XReadArgs xReadArgs, final Map streams, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = createStreamOffsetFromStreamEntryIdMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>>, List>>>( + client, ProtocolCommand.XREAD) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>>, List>>>( + client, ProtocolCommand.XREAD) + .run(args); + }else{ + return new LettuceSentinelCommand>>, List>>>( + client, ProtocolCommand.XREAD) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = createStreamOffsetFromStreamEntryIdMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), streamOffsets, + listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = createStreamOffsetFromBinaryStreamEntryIdMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(groupName, consumerName, streamOffsets, listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final XReadArgs.StreamOffset[] streamOffsets, + final Converter>, + List>>> converter, + final CommandArguments args) { + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>>, List>>>( + client, ProtocolCommand.XREADGROUP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>>, List>>>( + client, ProtocolCommand.XREADGROUP) + .run(args); + }else{ + return new LettuceSentinelCommand>>, List>>>( + client, ProtocolCommand.XREADGROUP) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadArgs xReadArgs, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = new XReadArgs.StreamOffset[streams.size()]; + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + int i = 0; + + for(Map.Entry e : streams.entrySet()){ + streamOffsets[i++] = XReadArgs.StreamOffset.from(SafeEncoder.encode(e.getKey()), e.getValue().toString()); + } + + return xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), streamOffsets, xReadArgs, + listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final XReadArgs xReadArgs, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = new XReadArgs.StreamOffset[streams.size()]; + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + int i = 0; + + for(Map.Entry e : streams.entrySet()){ + streamOffsets[i++] = XReadArgs.StreamOffset.from(e.getKey(), e.getValue().toString()); + } + + return xReadGroup(groupName, consumerName, streamOffsets, xReadArgs, listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final XReadArgs.StreamOffset[] streamOffsets, + final XReadArgs xReadArgs, + final Converter>, + List>>> converter, + final CommandArguments args) { + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand>>, List>>>( + client, ProtocolCommand.XREADGROUP) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand>>, List>>>( + client, ProtocolCommand.XREADGROUP) + .run(args); + }else{ + return new LettuceSentinelCommand>>, List>>>( + client, ProtocolCommand.XREADGROUP) + .run(args); + } + } + + private Long xTrim(final byte[] key, final boolean approximateTrimming, final long limit, + final CommandArguments args) { + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.XTRIM) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.XTRIM) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.XTRIM) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelStringOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelStringOperations.java new file mode 100644 index 000000000..3f159a343 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelStringOperations.java @@ -0,0 +1,486 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.StringUtils; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.lettuce.LettuceSetArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyValue; +import io.lettuce.core.SetArgs; +import io.lettuce.core.Value; + +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; + +/** + * Lettuce 哨兵模式字符串命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelStringOperations extends AbstractStringOperations { + + public LettuceSentinelStringOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public Long append(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.APPEND) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.APPEND) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.APPEND) + .run(args); + } + } + + @Override + public Long incr(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.INCR) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.INCR) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.INCR) + .run(args); + } + } + + @Override + public Long incrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.INCRBY) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.INCRBY) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.INCRBY) + .run(args); + } + } + + @Override + public Double incrByFloat(final byte[] key, final double value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.INCRBYFLOAT) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.INCRBYFLOAT) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.INCRBYFLOAT) + .run(args); + } + } + + @Override + public Long decr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.DECR) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.DECR) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.DECR) + .run(args); + } + } + + @Override + public Long decrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.DECRBY) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.DECRBY) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.DECRBY) + .run(args); + } + } + + @Override + public String get(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return get(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] get(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return get(key, (v)->v, args); + } + + @Override + public String getEx(final String key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + return getEx(args); + } + + @Override + public byte[] getEx(final byte[] key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + return getEx(args); + } + + @Override + public String getSet(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bValue = SafeEncoder.encode(value); + + return getSet(bKey, bValue, SafeEncoder::encode, args); + } + + @Override + public byte[] getSet(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return getSet(key, value, (v)->v, args); + } + + @Override + public String getDel(final String key) { + final CommandArguments args = CommandArguments.create(key); + return getDel(args); + } + + @Override + public byte[] getDel(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return getDel(args); + } + + @Override + public List mGet(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final ListConverter, String> listConverter = + new ListConverter<>((v)->SafeEncoder.encode(v.getValue())); + + return mGet(bKeys, listConverter, args); + } + + @Override + public List mGet(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + final ListConverter, byte[]> listConverter = new ListConverter<>(Value::getValue); + + return mGet(keys, listConverter, args); + } + + @Override + public Status mSet(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final Map bValues = Converters.mapStringToBinary().convert(values); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.MSET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.MSET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.MSET) + .run(args); + } + } + + @Override + public Status mSetNx(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final Map bValues = Converters.mapStringToBinary().convert(values); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.MSETNX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.MSETNX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.MSETNX) + .run(args); + } + } + + @Override + public Status pSetEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.PSETEX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.PSETEX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.PSETEX) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SET) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value, final SetArgument setArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final SetArgs setArgs = LettuceSetArgs.from(setArgument); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SET) + .run(args); + } + } + + @Override + public Status setEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SETEX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SETEX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SETEX) + .run(args); + } + } + + @Override + public Status setNx(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SETNX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SETNX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SETNX) + .run(args); + } + } + + @Override + public Long setRange(final byte[] key, final long offset, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SETRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SETRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SETRANGE) + .run(args); + } + } + + @Override + public byte[] getRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.GETRANGE) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.GETRANGE) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.GETRANGE) + .run(args); + } + } + + @Override + public Long strlen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.STRLEN) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.STRLEN) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.STRLEN) + .run(args); + } + } + + @Override + public String substr(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + final Converter converter = (v)->StringUtils.substring(SafeEncoder.encode(v), + (int) start, (int) end); + + return substr(bKey, converter, args); + } + + @Override + public byte[] substr(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final Converter converter = (v)->StringUtils.substring(SafeEncoder.encode(v), (int) start, + (int) end).getBytes(StandardCharsets.UTF_8); + + return substr(key, converter, args); + } + + private V get(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.GET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.GET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.GET) + .run(args); + } + } + + private V getEx(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.GETEX) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.GETEX) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.GETEX) + .run(args); + } + } + + private V getSet(final byte[] key, final byte[] value, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.GETSET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.GETSET) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.GETSET) + .run(args); + } + } + + private V getDel(final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.GETDEL) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.GETDEL) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.GETDEL) + .run(args); + } + } + + private List mGet(final byte[][] keys, final Converter>, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.MGET) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.MGET) + .run(args); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.MGET) + .run(args); + } + } + + private V substr(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.SUBSTR) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.SUBSTR) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.SUBSTR) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelTransactionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelTransactionOperations.java new file mode 100644 index 000000000..fe13b70bb --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSentinelTransactionOperations.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceSentinelClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import io.lettuce.core.TransactionResult; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Lettuce 哨兵模式事务命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSentinelTransactionOperations extends AbstractTransactionOperations { + + public LettuceSentinelTransactionOperations(final LettuceSentinelClient client) { + super(client); + } + + @Override + public void discard() { + if(isPipeline()){ + new LettuceSentinelPipelineCommand<>(client, ProtocolCommand.DISCARD) + .run(); + }else if(isTransaction()){ + new LettuceSentinelTransactionCommand<>(client, ProtocolCommand.DISCARD) + .run(); + }else{ + new LettuceSentinelCommand<>(client, ProtocolCommand.DISCARD) + .run(); + } + } + + @Override + public List exec() { + final Converter> converter = (v)->v.stream().collect(Collectors.toList()); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand, List>(client, ProtocolCommand.MULTI) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand, List>(client, ProtocolCommand.MULTI) + .run(); + }else{ + return new LettuceSentinelCommand, List>(client, ProtocolCommand.MULTI) + .run(); + } + } + + @Override + public Status multi() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.MULTI) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.MULTI) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.MULTI) + .run(); + } + } + + @Override + public Status unwatch() { + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.UNWATCH) + .run(); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.UNWATCH) + .run(); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.UNWATCH) + .run(); + } + } + + @Override + public Status watch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + + if(isPipeline()){ + return new LettuceSentinelPipelineCommand(client, ProtocolCommand.WATCH) + .run(args); + }else if(isTransaction()){ + return new LettuceSentinelTransactionCommand(client, ProtocolCommand.WATCH) + .run(args); + }else{ + return new LettuceSentinelCommand(client, ProtocolCommand.WATCH) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceServerOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceServerOperations.java new file mode 100644 index 000000000..6ca711e58 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceServerOperations.java @@ -0,0 +1,1051 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.AclLog; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.Info; +import com.buession.redis.core.MemoryStats; +import com.buession.redis.core.Module; +import com.buession.redis.core.RedisMonitor; +import com.buession.redis.core.RedisServerTime; +import com.buession.redis.core.Role; +import com.buession.redis.core.SlowLog; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.RedisServerTimeConverter; +import com.buession.redis.core.internal.convert.lettuce.response.RoleConverter; +import com.buession.redis.core.internal.convert.lettuce.response.SlowlogConverter; +import com.buession.redis.core.internal.convert.response.InfoConverter; +import com.buession.redis.utils.SafeEncoder; + +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * Lettuce 单机模式服务端命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceServerOperations extends AbstractServerOperations { + + public LettuceServerOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public List aclCat() { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + }else{ + return new LettuceCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(); + } + } + + @Override + public List aclCat(final String categoryName) { + final CommandArguments args = CommandArguments.create("categoryName", categoryName); + return aclCat(args); + } + + @Override + public List aclCat(final byte[] categoryName) { + final CommandArguments args = CommandArguments.create("categoryName", categoryName); + return aclCat(args); + } + + @Override + public Status aclSetUser(final String username, final String... rules) { + final CommandArguments args = CommandArguments.create("username", username).put("rules", (Object[]) rules); + return aclSetUser(args); + } + + @Override + public Status aclSetUser(final byte[] username, final byte[]... rules) { + final CommandArguments args = CommandArguments.create("username", username).put("rules", (Object[]) rules); + return aclSetUser(args); + } + + @Override + public AclUser aclGetUser(final String username) { + final CommandArguments args = CommandArguments.create("username", username); + return aclGetUser(args); + } + + @Override + public AclUser aclGetUser(final byte[] username) { + final CommandArguments args = CommandArguments.create("username", username); + return aclGetUser(args); + } + + @Override + public List aclUsers() { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + }else{ + return new LettuceCommand, List>(client, ProtocolCommand.ACL_USERS) + .run(); + } + } + + @Override + public String aclWhoAmI() { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + }else{ + return new LettuceCommand(client, ProtocolCommand.ACL_WHOAMI) + .run(); + } + } + + @Override + public Long aclDelUser(final String... usernames) { + final CommandArguments args = CommandArguments.create("usernames", (Object[]) usernames); + return aclDelUser(args); + } + + @Override + public Long aclDelUser(final byte[]... usernames) { + final CommandArguments args = CommandArguments.create("usernames", (Object[]) usernames); + return aclDelUser(args); + } + + @Override + public String aclGenPass() { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + }else{ + return new LettuceCommand(client, ProtocolCommand.ACL_GENPASS) + .run(); + } + } + + @Override + public List aclList() { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + }else{ + return new LettuceCommand, List>(client, ProtocolCommand.ACL_LIST) + .run(); + } + } + + @Override + public Status aclLoad() { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + }else{ + return new LettuceCommand(client, ProtocolCommand.ACL_LOAD) + .run(); + } + } + + @Override + public List aclLog() { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + }else{ + return new LettuceCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(); + } + } + + @Override + public List aclLog(final long count) { + final CommandArguments args = CommandArguments.create("count", count); + + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + }else{ + return new LettuceCommand, List>(client, ProtocolCommand.ACL_LOG) + .run(args); + } + } + + @Override + public Status aclLogReset() { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + }else{ + return new LettuceCommand(client, ProtocolCommand.ACL_LOGREST) + .run(); + } + } + + @Override + public Status aclLogSave() { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + }else{ + return new LettuceCommand(client, ProtocolCommand.ACL_LOGSAVE) + .run(); + } + } + + @Override + public String bgRewriteAof() { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + }else{ + return new LettuceCommand(client, ProtocolCommand.BGREWRITEAOF) + .run(); + } + } + + @Override + public String bgSave() { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.BGSAVE) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.BGSAVE) + .run(); + }else{ + return new LettuceCommand(client, ProtocolCommand.BGSAVE) + .run(); + } + } + + @Override + public Status configSet(final String parameter, final String value) { + final CommandArguments args = CommandArguments.create("parameter", parameter).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CONFIG_SET, + (cmd)->cmd.configSet(parameter, value), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CONFIG_SET, + (cmd)->cmd.configSet(parameter, value), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CONFIG_SET, (cmd)->cmd.configSet(parameter, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status configSet(final Map configs) { + final CommandArguments args = CommandArguments.create("configs", configs); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CONFIG_SET, + (cmd)->cmd.configSet(configs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CONFIG_SET, + (cmd)->cmd.configSet(configs), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CONFIG_SET, (cmd)->cmd.configSet(configs), + okStatusConverter) + .run(args); + } + } + + @Override + public Map configGet(final String pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CONFIG_GET, + (cmd)->cmd.configGet(pattern), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CONFIG_GET, + (cmd)->cmd.configGet(pattern), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CONFIG_GET, (cmd)->cmd.configGet(pattern), (v)->v) + .run(args); + } + } + + @Override + public Map configGet(final byte[] pattern) { + final CommandArguments args = CommandArguments.create("pattern", pattern); + final String sPattern = SafeEncoder.encode(pattern); + final MapConverter converter = Converters.mapStringToBinary(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CONFIG_GET, (cmd)->cmd.configGet(sPattern), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CONFIG_GET, (cmd)->cmd.configGet(sPattern), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CONFIG_GET, (cmd)->cmd.configGet(sPattern), + converter) + .run(args); + } + } + + @Override + public Status configResetStat() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CONFIG_RESETSTAT, (cmd)->cmd.configResetstat(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CONFIG_RESETSTAT, + (cmd)->cmd.configResetstat(), okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CONFIG_RESETSTAT, (cmd)->cmd.configResetstat(), + okStatusConverter) + .run(); + } + } + + @Override + public Status configRewrite() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.CONFIG_REWRITE, (cmd)->cmd.configRewrite(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.CONFIG_REWRITE, (cmd)->cmd.configRewrite(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.CONFIG_REWRITE, (cmd)->cmd.configRewrite(), + okStatusConverter) + .run(); + } + } + + @Override + public Long dbSize() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.DBSIZE, (cmd)->cmd.dbsize(), (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.DBSIZE, (cmd)->cmd.dbsize(), (v)->v) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.DBSIZE, (cmd)->cmd.dbsize(), (v)->v) + .run(); + } + } + + @Override + public Status failover() { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.FAILOVER) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.FAILOVER) + .run(); + }else{ + return new LettuceCommand(client, ProtocolCommand.FAILOVER) + .run(); + } + } + + @Override + public Status failover(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + return failover(args); + } + + @Override + public Status failover(final String host, final int port, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("timeout", timeout); + return failover(args); + } + + @Override + public Status failover(final String host, final int port, final boolean isForce, final int timeout) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port).put("isForce", isForce) + .put("timeout", timeout); + return failover(args); + } + + @Override + public Status failover(final int timeout) { + final CommandArguments args = CommandArguments.create("timeout", timeout); + return failover(args); + } + + @Override + public Status flushAll() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.FLUSHALL, (cmd)->cmd.flushall(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.FLUSHALL, (cmd)->cmd.flushall(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.FLUSHALL, (cmd)->cmd.flushall(), okStatusConverter) + .run(); + } + } + + @Override + public Status flushAll(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.FLUSHALL, + (cmd)->mode == FlushMode.ASYNC ? cmd.flushallAsync() : cmd.flushall(), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.FLUSHALL, + (cmd)->mode == FlushMode.ASYNC ? cmd.flushallAsync() : cmd.flushall(), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.FLUSHALL, + (cmd)->mode == FlushMode.ASYNC ? cmd.flushallAsync() : cmd.flushall(), okStatusConverter) + .run(args); + } + } + + @Override + public Status flushDb() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.flushdb(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.flushdb(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.flushdb(), okStatusConverter) + .run(); + } + } + + @Override + public Status flushDb(final FlushMode mode) { + final CommandArguments args = CommandArguments.create("mode", mode); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->mode == FlushMode.ASYNC ? + cmd.flushdbAsync() : cmd.flushdb(), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->mode == FlushMode.ASYNC ? + cmd.flushdbAsync() : cmd.flushdb(), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->mode == FlushMode.ASYNC ? + cmd.flushdbAsync() : cmd.flushdb(), okStatusConverter) + .run(args); + } + } + + @Override + public Info info() { + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(), infoConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(), infoConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(), infoConverter) + .run(); + } + } + + @Override + public Info info(final Info.Section section) { + final CommandArguments args = CommandArguments.create("section", section); + final String sectionName = section.name().toLowerCase(); + final InfoConverter infoConverter = new InfoConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(sectionName), + infoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(sectionName), + infoConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.FLUSHDB, (cmd)->cmd.info(sectionName), infoConverter) + .run(args); + } + } + + @Override + public Long lastSave() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.LASTSAVE, (cmd)->cmd.lastsave(), Date::getTime) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.LASTSAVE, (cmd)->cmd.lastsave(), + Date::getTime) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.LASTSAVE, (cmd)->cmd.lastsave(), Date::getTime) + .run(); + } + } + + @Override + public String memoryDoctor() { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + }else{ + return new LettuceCommand(client, ProtocolCommand.MEMORY_DOCTOR) + .run(); + } + } + + @Override + public Status memoryPurge() { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + }else{ + return new LettuceCommand(client, ProtocolCommand.MEMORY_PURGE) + .run(); + } + } + + @Override + public MemoryStats memoryStats() { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + }else{ + return new LettuceCommand(client, ProtocolCommand.MEMORY_STATS) + .run(); + } + } + + @Override + public Long memoryUsage(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } + } + + @Override + public Long memoryUsage(final byte[] key, final int samples) { + final CommandArguments args = CommandArguments.create("key", key).put("samples", samples); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.MEMORY_USAGE, (cmd)->cmd.memoryUsage(key), (v)->v) + .run(args); + } + } + + @Override + public List moduleList() { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, ProtocolCommand.MODULE_LIST) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, ProtocolCommand.MODULE_LIST) + .run(); + }else{ + return new LettuceCommand, List>(client, ProtocolCommand.MODULE_LIST) + .run(); + } + } + + @Override + public Status moduleLoad(final String path, final String... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + return moduleLoad(args); + } + + @Override + public Status moduleLoad(final byte[] path, final byte[]... arguments) { + final CommandArguments args = CommandArguments.create("path", path).put("arguments", (Object[]) arguments); + return moduleLoad(args); + } + + @Override + public Status moduleUnLoad(final String name) { + final CommandArguments args = CommandArguments.create("name", name); + return moduleUnLoad(args); + } + + @Override + public Status moduleUnLoad(final byte[] name) { + final CommandArguments args = CommandArguments.create("name", name); + return moduleUnLoad(args); + } + + @Override + public void monitor(final RedisMonitor redisMonitor) { + final CommandArguments args = CommandArguments.create("redisMonitor", redisMonitor); + + if(isPipeline()){ + new LettucePipelineCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + }else if(isTransaction()){ + new LettuceTransactionCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + }else{ + new LettuceCommand<>(client, ProtocolCommand.MONITOR) + .run(args); + } + } + + @Override + public Object pSync(final String replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return pSync(args); + } + + @Override + public Object pSync(final byte[] replicationId, final long offset) { + final CommandArguments args = CommandArguments.create("replicationId", replicationId).put("offset", offset); + return pSync(args); + } + + @Override + public void sync() { + if(isPipeline()){ + new LettucePipelineCommand<>(client, ProtocolCommand.SYNC) + .run(); + }else if(isTransaction()){ + new LettuceTransactionCommand<>(client, ProtocolCommand.SYNC) + .run(); + }else{ + new LettuceCommand<>(client, ProtocolCommand.SYNC) + .run(); + } + } + + @Override + public Status replicaOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.REPLICAOF) + .run(args); + } + } + + @Override + public Status slaveOf(final String host, final int port) { + final CommandArguments args = CommandArguments.create("host", host).put("port", port); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SLAVEOF, (cmd)->cmd.slaveof(host, port), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SLAVEOF, (cmd)->cmd.slaveof(host, port), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SLAVEOF, (cmd)->cmd.slaveof(host, port), + okStatusConverter) + .run(args); + } + } + + @Override + public Role role() { + final RoleConverter roleConverter = new RoleConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ROLE, (cmd)->cmd.role(), roleConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ROLE, (cmd)->cmd.role(), roleConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ROLE, (cmd)->cmd.role(), roleConverter) + .run(); + } + } + + @Override + public Status save() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SAVE, (cmd)->cmd.save(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SAVE, (cmd)->cmd.save(), okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SAVE, (cmd)->cmd.save(), okStatusConverter) + .run(); + } + } + + @Override + public void shutdown() { + if(isPipeline()){ + new LettucePipelineCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(true); + return null; + }, (v)->v) + .run(); + }else if(isTransaction()){ + new LettuceTransactionCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(true); + return null; + }, (v)->v) + .run(); + }else{ + new LettuceCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(true); + return null; + }, (v)->v) + .run(); + } + } + + @Override + public void shutdown(final boolean save) { + final CommandArguments args = CommandArguments.create("save", save); + + if(isPipeline()){ + new LettucePipelineCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(save); + return null; + }, (v)->v) + .run(args); + }else if(isTransaction()){ + new LettuceTransactionCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(save); + return null; + }, (v)->v) + .run(args); + }else{ + new LettuceCommand<>(client, ProtocolCommand.SHUTDOWN, (cmd)->{ + cmd.shutdown(save); + return null; + }, (v)->v) + .run(args); + } + } + + @Override + public List slowLogGet() { + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SLOWLOG_GET, (cmd)->cmd.slowlogGet(), + listSlowlogConverter) + .run(); + } + } + + @Override + public List slowLogGet(final long count) { + final CommandArguments args = CommandArguments.create("count", count); + final ListConverter listSlowlogConverter = SlowlogConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SLOWLOG_GET, (cmd)->cmd.slowlogGet((int) count), + listSlowlogConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SLOWLOG_GET, + (cmd)->cmd.slowlogGet((int) count), + listSlowlogConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SLOWLOG_GET, (cmd)->cmd.slowlogGet((int) count), + listSlowlogConverter) + .run(args); + } + } + + @Override + public Long slowLogLen() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SLOWLOG_LEN, (cmd)->cmd.slowlogLen(), (v)->v) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SLOWLOG_LEN, (cmd)->cmd.slowlogLen(), (v)->v) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SLOWLOG_LEN, (cmd)->cmd.slowlogLen(), (v)->v) + .run(); + } + } + + @Override + public Status slowLogReset() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SLOWLOG_RESET, (cmd)->cmd.slowlogReset(), + okStatusConverter) + .run(); + } + } + + @Override + public Status swapdb(final int db1, final int db2) { + final CommandArguments args = CommandArguments.create("db1", db1).put("db2", db2); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SWAPDB, (cmd)->cmd.swapdb(db1, db2), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SWAPDB, (cmd)->cmd.swapdb(db1, db2), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SWAPDB, (cmd)->cmd.swapdb(db1, db2), okStatusConverter) + .run(args); + } + } + + @Override + public RedisServerTime time() { + final RedisServerTimeConverter redisServerTimeConverter = new RedisServerTimeConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.TIME, (cmd)->cmd.time(), + redisServerTimeConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.TIME, (cmd)->cmd.time(), + redisServerTimeConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.TIME, (cmd)->cmd.time(), redisServerTimeConverter) + .run(); + } + } + + private List aclCat(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(args); + }else{ + return new LettuceCommand, List>(client, ProtocolCommand.ACL_CAT) + .run(args); + } + } + + private Status aclSetUser(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.ACL_SETUSER) + .run(args); + } + } + + private AclUser aclGetUser(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.ACL_GETUSER) + .run(args); + } + } + + private Long aclDelUser(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.ACL_DELUSER) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.ACL_DELUSER) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.ACL_DELUSER) + .run(args); + } + } + + private Status failover(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.FAILOVER) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.FAILOVER) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.FAILOVER) + .run(args); + } + } + + private Status moduleLoad(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.MODULE_LOAD) + .run(args); + } + } + + private Status moduleUnLoad(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.MODULE_UNLOAD) + .run(args); + } + } + + private Object pSync(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.PSYNC) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSetOperations.java new file mode 100644 index 000000000..1e24145d5 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSetOperations.java @@ -0,0 +1,578 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.SetConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.ValueScanCursor; + +import java.util.List; +import java.util.Set; + +/** + * Lettuce 单机模式集合命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSetOperations extends AbstractSetOperations { + + public LettuceSetOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Long sAdd(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SADD, (cmd)->cmd.sadd(key, members), (v)->v) + .run(args); + } + } + + @Override + public Long sCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SCARD, (cmd)->cmd.scard(key), (v)->v) + .run(args); + } + } + + @Override + public Set sDiff(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sDiff(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return sDiff(keys, (v)->v, args); + } + + @Override + public Long sDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SDIFFSTORE, + (cmd)->cmd.sdiffstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SDIFFSTORE, (cmd)->cmd.sdiffstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Set sInter(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sInter(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return sInter(keys, (v)->v, args); + } + + @Override + public Long sInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SINTERSTORE, + (cmd)->cmd.sinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SINTERSTORE, (cmd)->cmd.sinterstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Boolean sIsMember(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SISMEMBER, (cmd)->cmd.sismember(key, member), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SISMEMBER, (cmd)->cmd.sismember(key, member), (v)->v) + .run(args); + } + } + + @Override + public List smIsMember(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return smIsMember(args); + } + + @Override + public List smIsMember(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return smIsMember(args); + } + + @Override + public Set sMembers(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sMembers(bKey, binaryToStringSetConverter, args); + } + + @Override + public Set sMembers(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return sMembers(key, (v)->v, args); + } + + @Override + public Status sMove(final byte[] key, final byte[] destKey, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("destKey", destKey).put("member", member); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SMOVE, (cmd)->cmd.smove(key, destKey, member), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SMOVE, + (cmd)->cmd.smove(key, destKey, member), booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SMOVE, (cmd)->cmd.smove(key, destKey, member), + booleanStatusConverter) + .run(args); + } + } + + @Override + public String sPop(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return sPop(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] sPop(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return sPop(key, (v)->v, args); + } + + @Override + public Set sPop(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sPop(bKey, count, binaryToStringSetConverter, args); + } + + @Override + public Set sPop(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return sPop(key, count, (v)->v, args); + } + + @Override + public String sRandMember(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return sRandMember(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] sRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return sRandMember(key, (v)->v, args); + } + + @Override + public List sRandMember(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + + return sRandMember(bKey, count, binaryToStringListConverter, args); + } + + @Override + public List sRandMember(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return sRandMember(key, count, (v)->v, args); + } + + @Override + public Long sRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SREM, (cmd)->cmd.srem(key, members), (v)->v) + .run(args); + } + } + + @Override + public ScanResult> sScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(pattern); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(pattern); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, scanArgs, valueScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final String key, final String cursor, final String pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter bsKeyScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.BSKeyScanCursorConverter(); + + return sScan(bKey, scanCursor, scanArgs, bsKeyScanCursorConverter, args); + } + + @Override + public ScanResult> sScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter valueScanCursorConverter = new ScanCursorConverter.ValueScanCursorConverter<>(); + + return sScan(key, scanCursor, scanArgs, valueScanCursorConverter, args); + } + + @Override + public Set sUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final SetConverter binaryToStringSetConverter = Converters.setBinaryToString(); + + return sUnion(bKeys, binaryToStringSetConverter, args); + } + + @Override + public Set sUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return sUnion(keys, (v)->v, args); + } + + @Override + public Long sUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SUNIONSTORE, + (cmd)->cmd.sunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SUNIONSTORE, (cmd)->cmd.sunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + private Set sDiff(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SDIFF, (cmd)->cmd.sdiff(keys), converter) + .run(args); + } + } + + private Set sInter(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SINTER, (cmd)->cmd.sinter(keys), converter) + .run(args); + } + } + + private List smIsMember(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, ProtocolCommand.SMISMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, ProtocolCommand.SMISMEMBER) + .run(args); + }else{ + return new LettuceCommand, List>(client, ProtocolCommand.SMISMEMBER) + .run(args); + } + } + + private Set sMembers(final byte[] key, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SMEMBERS, (cmd)->cmd.smembers(key), converter) + .run(args); + } + } + + private V sPop(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key), converter) + .run(args); + } + } + + private Set sPop(final byte[] key, final long count, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.spop(key, count), converter) + .run(args); + } + } + + private V sRandMember(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.srandmember(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SPOP, (cmd)->cmd.srandmember(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key), converter) + .run(args); + } + } + + private List sRandMember(final byte[] key, final long count, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key, count), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SRANDMEMBER, + (cmd)->cmd.srandmember(key, count), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SRANDMEMBER, (cmd)->cmd.srandmember(key, count), + converter) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor), converter) + .run(args); + } + } + + private ScanResult> sScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor, scanArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SSCAN, + (cmd)->cmd.sscan(key, cursor, scanArgs), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SSCAN, (cmd)->cmd.sscan(key, cursor, scanArgs), + converter) + .run(args); + } + } + + private Set sUnion(final byte[][] keys, final Converter, Set> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SUNION, (cmd)->cmd.sunion(keys), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSortedSetOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSortedSetOperations.java new file mode 100644 index 000000000..710836f63 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceSortedSetOperations.java @@ -0,0 +1,2002 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.NumberUtils; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.Aggregate; +import com.buession.redis.core.GtLt; +import com.buession.redis.core.NxXx; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; +import com.buession.redis.core.ZRangeBy; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.response.KeyValueConverter; +import com.buession.redis.core.internal.convert.lettuce.response.ScanCursorConverter; +import com.buession.redis.core.internal.convert.lettuce.response.ScoredValueTupleConverter; +import com.buession.redis.core.internal.lettuce.LettuceScanArgs; +import com.buession.redis.core.internal.lettuce.LettuceScanCursor; +import com.buession.redis.core.internal.lettuce.LettuceZAddArgs; +import com.buession.redis.core.internal.lettuce.LettuceZStoreArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.Limit; +import io.lettuce.core.Range; +import io.lettuce.core.ScanArgs; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.ScoredValue; +import io.lettuce.core.ScoredValueScanCursor; +import io.lettuce.core.ZAddArgs; +import io.lettuce.core.ZStoreArgs; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 单机模式模式有序集合命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSortedSetOperations extends AbstractSortedSetOperations { + + public LettuceSortedSetOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Tuple zPopMin(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final ScoredValueTupleConverter.BinaryScoredValueTupleConverter scoredValueConverter = new ScoredValueTupleConverter.BinaryScoredValueTupleConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key), scoredValueConverter) + .run(args); + } + } + + @Override + public List zPopMin(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZPOPMIN, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + } + } + + @Override + public Tuple zPopMax(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + final ScoredValueTupleConverter.BinaryScoredValueTupleConverter scoredValueConverter = new ScoredValueTupleConverter.BinaryScoredValueTupleConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmin(key), + scoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmin(key), scoredValueConverter) + .run(args); + } + } + + @Override + public List zPopMax(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZPOPMAX, (cmd)->cmd.zpopmin(key, count), + listScoredValueConverter) + .run(args); + } + } + + @Override + public com.buession.lang.KeyValue bzPopMin(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final KeyValueConverter, String, Tuple> converter = new KeyValueConverter<>( + SafeEncoder::encode, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMin(bKeys, timeout, converter, args); + } + + @Override + public com.buession.lang.KeyValue bzPopMin(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter, byte[], Tuple> converter = new KeyValueConverter<>( + (k)->k, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMin(keys, timeout, converter, args); + } + + @Override + public com.buession.lang.KeyValue bzPopMax(final String[] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final byte[][] bKeys = SafeEncoder.encode(keys); + final KeyValueConverter, String, Tuple> converter = new KeyValueConverter<>( + SafeEncoder::encode, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMax(bKeys, timeout, converter, args); + } + + @Override + public com.buession.lang.KeyValue bzPopMax(final byte[][] keys, final int timeout) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("timeout", timeout); + final KeyValueConverter, byte[], Tuple> converter = new KeyValueConverter<>( + (k)->k, new ScoredValueTupleConverter.BinaryScoredValueTupleConverter()); + + return bzPopMax(keys, timeout, converter, args); + } + + @Override + public Long zAdd(final String key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + return zAdd(key, members, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members); + return zAdd(key, members, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final GtLt gtLt, final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("gtLt", gtLt) + .put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final String key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zAdd(final byte[] key, final Map members, final NxXx nxXx, final GtLt gtLt, + final boolean ch) { + final CommandArguments args = CommandArguments.create("keys", key).put("members", members).put("nxXx", nxXx) + .put("gtLt", gtLt).put("ch", ch); + final ZAddArgs zAddArgs = new LettuceZAddArgs(nxXx, gtLt, ch); + + return zAdd(key, members, zAddArgs, args); + } + + @Override + public Long zCard(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZCARD, (cmd)->cmd.zcard(key), (v)->v) + .run(args); + } + } + + @Override + public Long zCount(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, range), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, range), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZCOUNT, (cmd)->cmd.zcount(key, range), (v)->v) + .run(args); + } + } + + @Override + public List zDiff(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + return zDiff(args); + } + + @Override + public List zDiff(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return zDiff(args); + } + + @Override + public List zDiffWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + return zDiff(args); + } + + @Override + public List zDiffWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return zDiff(args); + } + + @Override + public Long zDiffStore(final String destKey, final String... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + return zDiffStore(args); + } + + @Override + public Long zDiffStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + return zDiffStore(args); + } + + @Override + public Double zIncrBy(final byte[] key, final double increment, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("increment", increment) + .put("member", member); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZINCRBY, + (cmd)->cmd.zincrby(key, increment, member), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZINCRBY, (cmd)->cmd.zincrby(key, increment, member), + (v)->v) + .run(args); + } + } + + @Override + public List zInter(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + return zInter(args); + } + + @Override + public List zInter(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create(keys); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create(keys); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zInter(args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZINTERSTORE, (cmd)->cmd.zinterstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate); + + return zInterStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(weights); + + return zInterStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zInterStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate, weights); + + return zInterStore(destKey, keys, zStoreArgs, args); + } + + @Deprecated + @Override + public Long zLexCount(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, range), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, range), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZLEXCOUNT, (cmd)->cmd.zlexcount(key, range), (v)->v) + .run(args); + } + } + + @Override + public List zMScore(final String key, final String... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return zMScore(args); + } + + @Override + public List zMScore(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + return zMScore(args); + } + + @Override + public String zRandMember(final String key) { + final CommandArguments args = CommandArguments.create(key); + return zRandMember(args); + } + + @Override + public byte[] zRandMember(final byte[] key) { + final CommandArguments args = CommandArguments.create(key); + return zRandMember(args); + } + + @Override + public List zRandMember(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMember(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMemberWithScores(final String key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRandMemberWithScores(final byte[] key, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("count", count); + return zRandMember(args); + } + + @Override + public List zRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + + return zRange(bKey, start, end, binaryToStringListConverter, args); + } + + @Override + public List zRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return zRange(key, start, end, (v)->v, args); + } + + @Override + public List zRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZRANGE, + (cmd)->cmd.zrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrangeWithScores(key, start, end), + listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRangeByLex(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(bKey, bMin, bMax, binaryToStringListConverter, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, (v)->v, args); + } + + @Deprecated + @Override + public List zRangeByLex(final String key, final String min, final String max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = SafeEncoder.encode(min); + final byte[] bMax = SafeEncoder.encode(max); + + return zRangeByLex(bKey, bMin, bMax, binaryToStringListConverter, args); + } + + @Deprecated + @Override + public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRangeByLex(key, min, max, (v)->v, args); + } + + @Override + public List zRangeByLex(final String key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(bKey, bMin, bMax, offset, count, binaryToStringListConverter, args); + } + + @Override + public List zRangeByLex(final byte[] key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRangeByLex(key, bMin, bMax, offset, count, (v)->v, args); + } + + @Deprecated + @Override + public List zRangeByLex(final String key, final String min, final String max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = SafeEncoder.encode(min); + final byte[] bMax = SafeEncoder.encode(max); + + return zRangeByLex(bKey, bMin, bMax, offset, count, binaryToStringListConverter, args); + } + + @Deprecated + @Override + public List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRangeByLex(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + + return zRangeByScore(bKey, min, max, binaryToStringListConverter, args); + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRangeByScore(key, min, max, (v)->v, args); + } + + @Override + public List zRangeByScore(final String key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + + return zRangeByScore(bKey, min, max, offset, count, binaryToStringListConverter, args); + } + + @Override + public List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRangeByScore(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRangeByScoreWithScores(final byte[] key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final Range range = Range.create(min, max); + final Limit limit = Limit.create(offset, count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + } + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final boolean rev) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, + final ZRangeBy by, final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, + final ZRangeBy by, final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final boolean rev, + final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final boolean rev, + final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final String destKey, final String key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final long end, final ZRangeBy by, + final boolean rev, final long offset, final long count) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("key", key).put("start", start) + .put("end", end).put("by", by).put("rev", rev).put("offset", offset).put("count", count); + return zRangeStore(args); + } + + @Override + public Long zRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZRANK, (cmd)->cmd.zrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public Long zRem(final byte[] key, final byte[]... members) { + final CommandArguments args = CommandArguments.create("key", key).put("members", (Object[]) members); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZREM, (cmd)->cmd.zrem(key, members), (v)->v) + .run(args); + } + } + + @Deprecated + @Override + public Long zRemRangeByLex(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangebylex(key, range), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, + (cmd)->cmd.zremrangebylex(key, range), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZREMRANGEBYLEX, (cmd)->cmd.zremrangebylex(key, range), + (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangebyscore(key, range), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangebyscore(key, range), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZREMRANGEBYSCORE, + (cmd)->cmd.zremrangebyscore(key, range), (v)->v) + .run(args); + } + } + + @Override + public Long zRemRangeByRank(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangebyrank(key, start, end), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangebyrank(key, start, end), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZREMRANGEBYRANK, + (cmd)->cmd.zremrangebyrank(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public List zRevRange(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + + return zRevRange(bKey, start, end, binaryToStringListConverter, args); + } + + @Override + public List zRevRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + return zRevRange(key, start, end, (v)->v, args); + } + + @Override + public List zRevRangeWithScores(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrangeWithScores(key, start, end), listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(bKey, bMin, bMax, binaryToStringListConverter, args); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(key, bMin, bMax, (v)->v, args); + } + + @Deprecated + @Override + public List zRevRangeByLex(final String key, final String min, final String max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = SafeEncoder.encode(min); + final byte[] bMax = SafeEncoder.encode(max); + + return zRevRangeByLex(bKey, bMin, bMax, binaryToStringListConverter, args); + } + + @Deprecated + @Override + public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRevRangeByLex(key, min, max, (v)->v, args); + } + + @Override + public List zRevRangeByLex(final String key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(bKey, bMin, bMax, offset, count, binaryToStringListConverter, args); + } + + @Override + public List zRevRangeByLex(final byte[] key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + final byte[] bMin = NumberUtils.double2bytes(min); + final byte[] bMax = NumberUtils.double2bytes(max); + + return zRevRangeByLex(key, bMin, bMax, offset, count, (v)->v, args); + } + + @Deprecated + @Override + public List zRevRangeByLex(final String key, final String min, final String max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bMin = SafeEncoder.encode(min); + final byte[] bMax = SafeEncoder.encode(max); + + return zRevRangeByLex(bKey, bMin, bMax, offset, count, binaryToStringListConverter, args); + } + + @Deprecated + @Override + public List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max).put("count" + , count); + return zRevRangeByLex(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final byte[] bKey = SafeEncoder.encode(key); + + return zRevRangeByScore(bKey, min, max, binaryToStringListConverter, args); + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + return zRevRangeByScore(key, min, max, (v)->v, args); + } + + @Override + public List zRevRangeByScore(final String key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + + return zRevRangeByScore(bKey, min, max, offset, count, binaryToStringListConverter, args); + } + + @Override + public List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + return zRevRangeByScore(key, min, max, offset, count, (v)->v, args); + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max); + final Range range = Range.create(min, max); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range), listScoredValueConverter) + .run(args); + } + } + + @Override + public List zRevRangeByScoreWithScores(final byte[] key, final double min, final double max, + final long offset, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("min", min).put("max", max) + .put("offset", offset).put("count", count); + final Range range = Range.create(min, max); + final Limit limit = Limit.create(offset, count); + final ListConverter, Tuple> listScoredValueConverter = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscoreWithScores(key, range, limit), listScoredValueConverter) + .run(args); + } + } + + @Override + public Long zRevRank(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zrevrank(key, member), (v)->v) + .run(args); + } + } + + @Override + public ScanResult> zScan(final String key, final String cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final String key, final String cursor, final String pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final byte[] bKey = SafeEncoder.encode(key); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(bKey, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public ScanResult> zScan(final byte[] key, final byte[] cursor, final byte[] pattern, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("cursor", cursor).put("pattern", pattern) + .put("count", count); + final ScanCursor scanCursor = new LettuceScanCursor(cursor); + final ScanArgs scanArgs = new LettuceScanArgs(pattern, count); + final ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter scoredValueScanCursorConverter = + new ScanCursorConverter.ValueScanCursorConverter.ScoredValueScanCursorConverter(); + + return zScan(key, scanCursor, scanArgs, scoredValueScanCursorConverter, args); + } + + @Override + public Double zScore(final byte[] key, final byte[] member) { + final CommandArguments args = CommandArguments.create("key", key).put("member", member); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZSCORE, (cmd)->cmd.zscore(key, member), (v)->v) + .run(args); + } + } + + @Override + public List zUnion(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnion(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys).put("aggregate", aggregate) + .put("weights", weights); + return zUnion(args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[]... keys) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZUNIONSTORE, (cmd)->cmd.zunionstore(destKey, keys), + (v)->v) + .run(args); + } + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate); + + return zUnionStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(weights); + + return zUnionStore(destKey, keys, zStoreArgs, args); + } + + @Override + public Long zUnionStore(final byte[] destKey, final byte[][] keys, final Aggregate aggregate, + final double... weights) { + final CommandArguments args = CommandArguments.create("destKey", destKey).put("keys", (Object[]) keys) + .put("aggregate", aggregate).put("weights", weights); + final ZStoreArgs zStoreArgs = new LettuceZStoreArgs(aggregate, weights); + + return zUnionStore(destKey, keys, zStoreArgs, args); + } + + private com.buession.lang.KeyValue bzPopMin(final byte[][] keys, final int timeout, + final KeyValueConverter, K, + Tuple> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.BZPOPMIN, + (cmd)->cmd.bzpopmin(timeout, keys), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.BZPOPMIN, (cmd)->cmd.bzpopmin(timeout, keys), + converter) + .run(args); + } + } + + private com.buession.lang.KeyValue bzPopMax(final byte[][] keys, final int timeout, + final KeyValueConverter, + K, Tuple> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.BZPOPMAX, + (cmd)->cmd.bzpopmax(timeout, keys), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.BZPOPMAX, (cmd)->cmd.bzpopmax(timeout, keys), + converter) + .run(args); + } + } + + private Long zAdd(final String key, final Map members, final CommandArguments args) { + final byte[] bKey = SafeEncoder.encode(key); + final ScoredValue[] scoredValues = new ScoredValue[members.size()]; + int i = 0; + + for(Map.Entry e : members.entrySet()){ + scoredValues[i++] = e.getValue() == null ? ScoredValue.empty() : ScoredValue.just(e.getValue(), + SafeEncoder.encode(e.getKey())); + } + + return zAdd(bKey, scoredValues, args); + } + + private Long zAdd(final String key, final Map members, final ZAddArgs zAddArgs, + final CommandArguments args) { + final byte[] bKey = SafeEncoder.encode(key); + final ScoredValue[] scoredValues = new ScoredValue[members.size()]; + int i = 0; + + for(Map.Entry e : members.entrySet()){ + scoredValues[i++] = e.getValue() == null ? ScoredValue.empty() : ScoredValue.just(e.getValue(), + SafeEncoder.encode(e.getKey())); + } + + return zAdd(bKey, scoredValues, zAddArgs, args); + } + + private Long zAdd(final byte[] key, final Map members, final CommandArguments args) { + final ScoredValue[] scoredValues = new ScoredValue[members.size()]; + int i = 0; + + for(Map.Entry e : members.entrySet()){ + scoredValues[i++] = e.getValue() == null ? ScoredValue.empty() : ScoredValue.just(e.getValue(), e.getKey()); + } + + return zAdd(key, scoredValues, args); + } + + private Long zAdd(final byte[] key, final Map members, final ZAddArgs zAddArgs, + final CommandArguments args) { + final ScoredValue[] scoredValues = new ScoredValue[members.size()]; + int i = 0; + + for(Map.Entry e : members.entrySet()){ + scoredValues[i++] = e.getValue() == null ? ScoredValue.empty() : ScoredValue.just(e.getValue(), e.getKey()); + } + + return zAdd(key, scoredValues, zAddArgs, args); + } + + private Long zAdd(final byte[] key, final ScoredValue[] scoredValues, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, scoredValues), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, scoredValues), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, scoredValues), (v)->v) + .run(args); + } + } + + private Long zAdd(final byte[] key, final ScoredValue[] scoredValues, final ZAddArgs zAddArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, zAddArgs, scoredValues), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZADD, + (cmd)->cmd.zadd(key, zAddArgs, scoredValues), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZADD, (cmd)->cmd.zadd(key, zAddArgs, scoredValues), + (v)->v) + .run(args); + } + } + + private List zDiff(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, ProtocolCommand.ZDIFF) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, ProtocolCommand.ZDIFF) + .run(args); + }else{ + return new LettuceCommand, List>(client, ProtocolCommand.ZDIFF) + .run(args); + } + } + + private Long zDiffStore(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.ZDIFFSTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.ZDIFFSTORE) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.ZDIFFSTORE) + .run(args); + } + } + + private List zInter(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, ProtocolCommand.ZINTER) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, ProtocolCommand.ZINTER) + .run(args); + }else{ + return new LettuceCommand, List>(client, ProtocolCommand.ZINTER) + .run(args); + } + } + + private Long zInterStore(final byte[] destKey, final byte[][] keys, final ZStoreArgs zStoreArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZINTERSTORE, + (cmd)->cmd.zinterstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + } + } + + private List zMScore(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, ProtocolCommand.ZMSCORE) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, ProtocolCommand.ZMSCORE) + .run(args); + }else{ + return new LettuceCommand, List>(client, ProtocolCommand.ZMSCORE) + .run(args); + } + } + + private V zRandMember(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.ZRANDMEMBER) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.ZRANDMEMBER) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.ZRANDMEMBER) + .run(args); + } + } + + private List zRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZRANGE, (cmd)->cmd.zrange(key, start, end), converter) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final Converter, List> converter, final CommandArguments args) { + return zRangeByLex(key, Range.create(min, max), converter, args); + } + + private List zRangeByLex(final byte[] key, final Range range, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, (cmd)->cmd.zrangebylex(key, range), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZRANGEBYLEX, (cmd)->cmd.zrangebylex(key, range), + converter) + .run(args); + } + } + + private List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count, final Converter, List> converter, + final CommandArguments args) { + return zRangeByLex(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRangeByLex(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZRANGEBYLEX, + (cmd)->cmd.zrangebylex(key, range, limit), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZRANGEBYLEX, (cmd)->cmd.zrangebylex(key, range, limit), + converter) + .run(args); + } + } + + private List zRangeByScore(final byte[] key, final double min, final double max, + final Converter, List> converter, final CommandArguments args) { + return zRangeByScore(key, Range.create(min, max), converter, args); + } + + private List zRangeByScore(final byte[] key, final Range range, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, (cmd)->cmd.zrangebyscore(key, range), + converter) + .run(args); + } + } + + private List zRangeByScore(final byte[] key, final double min, final double max, final long offset, + final long count, final Converter, List> converter, + final CommandArguments args) { + return zRangeByScore(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRangeByScore(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range, limit), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZRANGEBYSCORE, + (cmd)->cmd.zrangebyscore(key, range, limit), converter) + .run(args); + } + } + + private Long zRangeStore(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.ZRANGESTORE) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.ZRANGESTORE) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.ZRANGESTORE) + .run(args); + } + } + + private List zRevRange(final byte[] key, final long start, final long end, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZREVRANGE, + (cmd)->cmd.zrevrange(key, start, end), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZREVRANGE, (cmd)->cmd.zrevrange(key, start, end), + converter) + .run(args); + } + } + + private List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, + final Converter, List> converter, final CommandArguments args) { + return zRevRangeByLex(key, Range.create(min, max), converter, args); + } + + private List zRevRangeByLex(final byte[] key, final Range range, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, (cmd)->cmd.zrevrangebylex(key, range), + converter) + .run(args); + } + } + + private List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, + final long count, final Converter, List> converter, + final CommandArguments args) { + return zRevRangeByLex(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRevRangeByLex(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range, limit), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZREVRANGEBYLEX, + (cmd)->cmd.zrevrangebylex(key, range, limit), converter) + .run(args); + } + } + + private List zRevRangeByScore(final byte[] key, final double min, final double max, + final Converter, List> converter, + final CommandArguments args) { + return zRevRangeByScore(key, Range.create(min, max), converter, args); + } + + private List zRevRangeByScore(final byte[] key, final Range range, + final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range), converter) + .run(args); + } + } + + private List zRevRangeByScore(final byte[] key, final double min, final double max, final long offset, + final long count, final Converter, List> converter, + final CommandArguments args) { + return zRevRangeByScore(key, Range.create(min, max), Limit.create(offset, count), converter, args); + } + + private List zRevRangeByScore(final byte[] key, final Range range, final Limit limit, + final Converter, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range, limit), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range, limit), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZREVRANGEBYSCORE, + (cmd)->cmd.zrevrangebyscore(key, range, limit), converter) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final ScanCursor cursor, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zscan(key, cursor), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zscan(key, cursor), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZREVRANK, (cmd)->cmd.zscan(key, cursor), converter) + .run(args); + } + } + + private ScanResult> zScan(final byte[] key, final ScanCursor cursor, final ScanArgs scanArgs, + final Converter, ScanResult>> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanArgs), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZSCAN, + (cmd)->cmd.zscan(key, cursor, scanArgs), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZSCAN, (cmd)->cmd.zscan(key, cursor, scanArgs), + converter) + .run(args); + } + } + + private List zUnion(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand, List>(client, ProtocolCommand.ZUNION) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand, List>(client, ProtocolCommand.ZUNION) + .run(args); + }else{ + return new LettuceCommand, List>(client, ProtocolCommand.ZUNION) + .run(args); + } + } + + private Long zUnionStore(final byte[] destKey, final byte[][] keys, final ZStoreArgs zStoreArgs, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.ZUNIONSTORE, + (cmd)->cmd.zunionstore(destKey, zStoreArgs, keys), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceStreamOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceStreamOperations.java new file mode 100644 index 000000000..e82a53a76 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceStreamOperations.java @@ -0,0 +1,1200 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.Stream; +import com.buession.redis.core.StreamConsumer; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import com.buession.redis.core.StreamGroup; +import com.buession.redis.core.StreamPending; +import com.buession.redis.core.StreamPendingSummary; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.lettuce.params.StreamEntryIdConverter; +import com.buession.redis.core.internal.convert.lettuce.response.PendingMessageConverter; +import com.buession.redis.core.internal.convert.lettuce.response.PendingMessagesConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamConsumersInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamEntryIDConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamFullInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamGroupInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamInfoConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamMessageConverter; +import com.buession.redis.core.internal.convert.lettuce.response.StreamMessageMapConverter; +import com.buession.redis.core.internal.lettuce.LettuceXAddArgs; +import com.buession.redis.core.internal.lettuce.LettuceXClaimArgs; +import com.buession.redis.core.internal.lettuce.LettuceXGroupCreateArgs; +import com.buession.redis.core.internal.lettuce.LettuceXPendingArgs; +import com.buession.redis.core.internal.lettuce.LettuceXReadArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.Consumer; +import io.lettuce.core.Limit; +import io.lettuce.core.Range; +import io.lettuce.core.StreamMessage; +import io.lettuce.core.XAddArgs; +import io.lettuce.core.XClaimArgs; +import io.lettuce.core.XGroupCreateArgs; +import io.lettuce.core.XReadArgs; +import io.lettuce.core.models.stream.PendingMessage; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce 单机模式 Stream 命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceStreamOperations extends AbstractStreamOperations { + + public LettuceStreamOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Long xAck(final byte[] key, final byte[] groupName, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("ids", (Object[]) ids); + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XACK, + (cmd)->cmd.xack(key, groupName, messageIds), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XACK, + (cmd)->cmd.xack(key, groupName, messageIds), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XACK, (cmd)->cmd.xack(key, groupName, messageIds), + (v)->v) + .run(args); + } + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash); + final XAddArgs xAddArgs = new LettuceXAddArgs(id); + + return xAdd(key, hash, xAddArgs, args); + } + + @Override + public StreamEntryId xAdd(final byte[] key, final StreamEntryId id, final Map hash, + final XAddArgument xAddArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("id", id).put("hash", hash) + .put("xAddArgument", xAddArgument); + final StreamEntryIdConverter streamEntryIdConverter = new StreamEntryIdConverter(); + final XAddArgs xAddArgs = LettuceXAddArgs.from(xAddArgument).id(streamEntryIdConverter.convert(id)); + + return xAdd(key, hash, xAddArgs, args); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaim(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaim(args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count"); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count"); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final byte[] key, final byte[] groupName, + final byte[] consumerName, final int minIdleTime, + final StreamEntryId start, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaimJustId(args); + } + + @Override + public Map> xAutoClaimJustId(final String key, final String groupName, + final String consumerName, final int minIdleTime, + final StreamEntryId start, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("start", start) + .put("count", count); + return xAutoClaimJustId(args); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = new LettuceXClaimArgs(minIdleTime); + + return xClaim(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaim(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = LettuceXClaimArgs.from(xClaimArgument).minIdleTime(minIdleTime); + + return xClaim(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = new LettuceXClaimArgs(minIdleTime, true); + + return xClaimJustId(key, ids, consumer, xClaimArgs, args); + } + + @Override + public List xClaimJustId(final byte[] key, final byte[] groupName, final byte[] consumerName, + final int minIdleTime, final StreamEntryId[] ids, + final XClaimArgument xClaimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName).put("minIdleTime", minIdleTime).put("ids", (Object[]) ids) + .put("xClaimArgument", xClaimArgument); + final Consumer consumer = Consumer.from(groupName, consumerName); + final XClaimArgs xClaimArgs = LettuceXClaimArgs.from(xClaimArgument).minIdleTime(minIdleTime).justid(); + + return xClaimJustId(key, ids, consumer, xClaimArgs, args); + } + + @Override + public Long xDel(final byte[] key, final StreamEntryId... ids) { + final CommandArguments args = CommandArguments.create("key", key).put("ids", (Object[]) ids); + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XDEL, (cmd)->cmd.xdel(key, messageIds), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XDEL, (cmd)->cmd.xdel(key, messageIds), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XDEL, (cmd)->cmd.xdel(key, messageIds), (v)->v) + .run(args); + } + } + + @Override + public Status xGroupCreate(final byte[] key, final byte[] groupName, final StreamEntryId id, + final boolean makeStream) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("id", id); + final XReadArgs.StreamOffset streamOffset = XReadArgs.StreamOffset.latest(key); + final XGroupCreateArgs xGroupCreateArgs = new LettuceXGroupCreateArgs(makeStream); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(streamOffset, groupName, xGroupCreateArgs), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(streamOffset, groupName, xGroupCreateArgs), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XGROUP_CREATE, + (cmd)->cmd.xgroupCreate(streamOffset, groupName, xGroupCreateArgs), okStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupCreateConsumer(final String key, final String groupName, final String consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + return xGroupCreateConsumer(args); + } + + @Override + public Status xGroupCreateConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + return xGroupCreateConsumer(args); + } + + @Override + public Long xGroupDelConsumer(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelconsumer(key, consumer), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelconsumer(key, consumer), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XGROUP_DELCONSUMER, + (cmd)->cmd.xgroupDelconsumer(key, consumer), (v)->v) + .run(args); + } + } + + @Override + public Status xGroupDestroy(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XGROUP_DESTROY, + (cmd)->cmd.xgroupDestroy(key, groupName), booleanStatusConverter) + .run(args); + } + } + + @Override + public Status xGroupSetId(final byte[] key, final byte[] groupName, final StreamEntryId id) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName).put("id", id); + final XReadArgs.StreamOffset streamOffset = XReadArgs.StreamOffset.from(key, id.toString()); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XGROUP_SETID, + (cmd)->cmd.xgroupSetid(streamOffset, groupName), okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XGROUP_SETID, + (cmd)->cmd.xgroupSetid(streamOffset, groupName), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XGROUP_SETID, + (cmd)->cmd.xgroupSetid(streamOffset, groupName), okStatusConverter) + .run(args); + } + } + + @Override + public List xInfoConsumers(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + final ListConverter listStreamConsumersInfoConverter = StreamConsumersInfoConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XINFO_CONSUMERS, + (cmd)->cmd.xinfoConsumers(key, groupName), listStreamConsumersInfoConverter) + .run(args); + } + } + + @Override + public List xInfoGroups(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final ListConverter listStreamGroupInfoConverter = StreamGroupInfoConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XINFO_GROUPS, (cmd)->cmd.xinfoGroups(key), + listStreamGroupInfoConverter) + .run(args); + } + } + + @Override + public Stream xInfoStream(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + final StreamInfoConverter streamInfoConverter = new StreamInfoConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream( + key), streamInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream( + key), streamInfoConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream( + key), streamInfoConverter) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + } + } + + @Override + public StreamFull xInfoStream(final byte[] key, final boolean full, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("full", full).put("count", count); + final StreamFullInfoConverter streamFullInfoConverter = new StreamFullInfoConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XINFO_STREAM, (cmd)->cmd.xinfoStream(key), + streamFullInfoConverter) + .run(args); + } + } + + @Override + public Long xLen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XLEN, (cmd)->cmd.xlen(key), (v)->v) + .run(args); + } + } + + @Override + public StreamPendingSummary xPending(final byte[] key, final byte[] groupName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName); + final PendingMessagesConverter pendingMessagesConverter = new PendingMessagesConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XPENDING, (cmd)->cmd.xpending(key, groupName), + pendingMessagesConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName), pendingMessagesConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XPENDING, (cmd)->cmd.xpending(key, groupName), + pendingMessagesConverter) + .run(args); + } + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime); + final LettuceXPendingArgs xPendingArgs = new LettuceXPendingArgs<>(minIdleTime, groupName, null); + final ListConverter listStreamPendingConverter = PendingMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, xPendingArgs), + listStreamPendingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, xPendingArgs), listStreamPendingConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XPENDING, (cmd)->cmd.xpending(key, xPendingArgs), + listStreamPendingConverter) + .run(args); + } + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("start", start).put("end", end).put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, groupName, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.unbounded(); + final Limit limit = Limit.unlimited(); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("start", start).put("end", end).put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, groupName, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.unbounded(); + final Limit limit = Limit.unlimited(); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final StreamEntryId start, + final StreamEntryId end, final long count, final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xPending(final byte[] key, final byte[] groupName, final long minIdleTime, + final StreamEntryId start, final StreamEntryId end, final long count, + final byte[] consumerName) { + final CommandArguments args = CommandArguments.create("key", key).put("groupName", groupName) + .put("minIdleTime", minIdleTime).put("consumerName", consumerName); + final Consumer consumer = Consumer.from(groupName, consumerName); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + + return xPending(key, consumer, range, limit, args); + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final Range range = Range.create(start.toString(), end.toString()); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XRANGE, (cmd)->cmd.xrange(key, range), + listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XRANGE, (cmd)->cmd.xrange(key, range), + listStreamMessageConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XRANGE, (cmd)->cmd.xrange(key, range), + listStreamMessageConverter) + .run(args); + } + } + + @Override + public List xRange(final byte[] key, final StreamEntryId start, final StreamEntryId end, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XRANGE, (cmd)->cmd.xrange(key, range, limit), + listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XRANGE, (cmd)->cmd.xrange(key, range, limit), + listStreamMessageConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XRANGE, (cmd)->cmd.xrange(key, range, limit), + listStreamMessageConverter) + .run(args); + } + } + + @Override + public List>> xRead(final Map streams) { + final CommandArguments args = CommandArguments.create("streams", streams); + return xRead(streams, args); + } + + @Override + public List>> xRead(final long count, final Map streams) { + final CommandArguments args = CommandArguments.create("count", count).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(count); + + return xRead(xReadArgs, streams, args); + } + + @Override + public List>> xRead(final int block, final Map streams) { + final CommandArguments args = CommandArguments.create("block", block).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block); + + return xRead(xReadArgs, streams, args); + } + + @Override + public List>> xRead(final long count, final int block, + final Map streams) { + final CommandArguments args = CommandArguments.create("count", count).put("block", block) + .put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block, count); + + return xRead(xReadArgs, streams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams); + return xReadGroup(groupName, consumerName, streams, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("streams", streams); + return xReadGroup(groupName, consumerName, streams, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final long count, final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final long count, final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final int block, final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("block", block).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final int block, final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("block", block).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = (new LettuceXReadArgs()).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = (new LettuceXReadArgs()).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final long count, final int block, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("block", block).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final long count, final int block, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("block", block).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final long count, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(isNoAck, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final long count, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(isNoAck, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final int block, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("block", block).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = (new LettuceXReadArgs()).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final int block, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("block", block).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = (new LettuceXReadArgs()).noack(isNoAck); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final String groupName, final String consumerName, + final long count, final int block, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("block", block).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block, isNoAck, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final long count, final int block, final boolean isNoAck, + final Map streams) { + final CommandArguments args = CommandArguments.create("groupName", groupName).put("consumerName", consumerName) + .put("count", count).put("block", block).put("isNoAck", isNoAck).put("streams", streams); + final XReadArgs xReadArgs = new LettuceXReadArgs(block, isNoAck, count); + + return xReadGroup(groupName, consumerName, streams, xReadArgs, args); + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start); + final Range range = Range.create(start.toString(), end.toString()); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XREVRANGE, (cmd)->cmd.xrevrange(key, range), + listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XREVRANGE, (cmd)->cmd.xrevrange(key, range), + listStreamMessageConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XREVRANGE, (cmd)->cmd.xrevrange(key, range), + listStreamMessageConverter) + .run(args); + } + } + + @Override + public List xRevRange(final byte[] key, final StreamEntryId end, final StreamEntryId start, + final long count) { + final CommandArguments args = CommandArguments.create("key", key).put("end", end).put("start", start) + .put("count", count); + final Range range = Range.create(start.toString(), end.toString()); + final Limit limit = Limit.from(count); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, range, limit), listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XREVRANGE, + (cmd)->cmd.xrevrange(key, range, limit), listStreamMessageConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XREVRANGE, (cmd)->cmd.xrevrange(key, range, limit), + listStreamMessageConverter) + .run(args); + } + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument); + return xTrim(key, xTrimArgument.isApproximateTrimming(), Long.MAX_VALUE, args); + } + + @Override + public Long xTrim(final byte[] key, final XTrimArgument xTrimArgument, final long limit) { + final CommandArguments args = CommandArguments.create("key", key).put("xTrimArgument", xTrimArgument) + .put("limit", limit); + return xTrim(key, xTrimArgument.isApproximateTrimming(), limit, args); + } + + private StreamEntryId xAdd(final byte[] key, final Map hash, final XAddArgs xAddArgs, + final CommandArguments args) { + final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, xAddArgs, hash), + streamEntryIDConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, xAddArgs, hash), + streamEntryIDConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XADD, (cmd)->cmd.xadd(key, xAddArgs, hash), + streamEntryIDConverter) + .run(args); + } + } + + private Map> xAutoClaim(final CommandArguments args) { + + if(isPipeline()){ + return new LettucePipelineCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + }else{ + return new LettuceCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + } + } + + private Map> xAutoClaimJustId(final CommandArguments args) { + + if(isPipeline()){ + return new LettucePipelineCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + }else{ + return new LettuceCommand>, Map>>( + client, ProtocolCommand.XAUTOCLAIM) + .run(args); + } + } + + private List xClaim(final byte[] key, final StreamEntryId[] ids, final Consumer consumer, + final XClaimArgs xClaimArgs, final CommandArguments args) { + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter, StreamEntry> listStreamMessageConverter = + StreamMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XCLAIM, (cmd)->cmd.xclaim(key, consumer, xClaimArgs, + messageIds), listStreamMessageConverter) + .run(args); + } + } + + private List xClaimJustId(final byte[] key, final StreamEntryId[] ids, + final Consumer consumer, final XClaimArgs xClaimArgs, + final CommandArguments args) { + final String[] messageIds = StreamEntryIdConverter.arrayConverter().convert(ids); + final ListConverter, StreamEntryId> listStreamMessageStreamEntryIdConverter + = StreamMessageConverter.StreamMessageStreamEntryIdConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageStreamEntryIdConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageStreamEntryIdConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XCLAIM, + (cmd)->cmd.xclaim(key, consumer, xClaimArgs, messageIds), listStreamMessageStreamEntryIdConverter) + .run(args); + } + } + + private Status xGroupCreateConsumer(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.XGROUP_CREATECONSUMER) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.XGROUP_CREATECONSUMER) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.XGROUP_CREATECONSUMER) + .run(args); + } + } + + private List xPending(final byte[] key, final byte[] groupName, Range range, + final Limit limit, final CommandArguments args) { + final ListConverter listStreamPendingConverter = PendingMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName, range, limit), listStreamPendingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName, range, limit), listStreamPendingConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, groupName, range, limit), listStreamPendingConverter) + .run(args); + } + } + + private List xPending(final byte[] key, final Consumer consumer, Range range, + final Limit limit, final CommandArguments args) { + final ListConverter listStreamPendingConverter = PendingMessageConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, consumer, range, limit), listStreamPendingConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, consumer, range, limit), listStreamPendingConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XPENDING, + (cmd)->cmd.xpending(key, consumer, range, limit), listStreamPendingConverter) + .run(args); + } + } + + private List>> xRead(final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = createStreamOffsetFromStreamEntryIdMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XREAD, (cmd)->cmd.xread(streamOffsets), + listStreamMessageMapConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XREAD, (cmd)->cmd.xread(streamOffsets), + listStreamMessageMapConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XREAD, (cmd)->cmd.xread(streamOffsets), + listStreamMessageMapConverter) + .run(args); + } + } + + private List>> xRead(final XReadArgs xReadArgs, final Map streams, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = createStreamOffsetFromStreamEntryIdMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XREAD, + (cmd)->cmd.xread(xReadArgs, streamOffsets), listStreamMessageMapConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XREAD, + (cmd)->cmd.xread(xReadArgs, streamOffsets), listStreamMessageMapConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XREAD, (cmd)->cmd.xread(xReadArgs, streamOffsets), + listStreamMessageMapConverter) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = createStreamOffsetFromStreamEntryIdMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), streamOffsets, + listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = createStreamOffsetFromBinaryStreamEntryIdMap(streams); + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + + return xReadGroup(groupName, consumerName, streamOffsets, listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final XReadArgs.StreamOffset[] streamOffsets, + final Converter>, + List>>> converter, + final CommandArguments args) { + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, streamOffsets), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, streamOffsets), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, streamOffsets), converter) + .run(args); + } + } + + private List>> xReadGroup(final String groupName, final String consumerName, + final Map streams, + final XReadArgs xReadArgs, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = new XReadArgs.StreamOffset[streams.size()]; + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + int i = 0; + + for(Map.Entry e : streams.entrySet()){ + streamOffsets[i++] = XReadArgs.StreamOffset.from(SafeEncoder.encode(e.getKey()), e.getValue().toString()); + } + + return xReadGroup(SafeEncoder.encode(groupName), SafeEncoder.encode(consumerName), streamOffsets, xReadArgs, + listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final Map streams, + final XReadArgs xReadArgs, final CommandArguments args) { + final XReadArgs.StreamOffset[] streamOffsets = new XReadArgs.StreamOffset[streams.size()]; + final ListConverter, Map>> listStreamMessageMapConverter = + StreamMessageMapConverter.listConverter(); + int i = 0; + + for(Map.Entry e : streams.entrySet()){ + streamOffsets[i++] = XReadArgs.StreamOffset.from(e.getKey(), e.getValue().toString()); + } + + return xReadGroup(groupName, consumerName, streamOffsets, xReadArgs, listStreamMessageMapConverter, args); + } + + private List>> xReadGroup(final byte[] groupName, final byte[] consumerName, + final XReadArgs.StreamOffset[] streamOffsets, + final XReadArgs xReadArgs, + final Converter>, + List>>> converter, + final CommandArguments args) { + final Consumer consumer = Consumer.from(groupName, consumerName); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, xReadArgs, streamOffsets), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, xReadArgs, streamOffsets), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XREADGROUP, + (cmd)->cmd.xreadgroup(consumer, xReadArgs, streamOffsets), converter) + .run(args); + } + } + + private Long xTrim(final byte[] key, final boolean approximateTrimming, final long limit, + final CommandArguments args) { + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.XTRIM, + (cmd)->cmd.xtrim(key, approximateTrimming, limit), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.XTRIM, + (cmd)->cmd.xtrim(key, approximateTrimming, limit), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.XTRIM, + (cmd)->cmd.xtrim(key, approximateTrimming, limit), (v)->v) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceStringOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceStringOperations.java new file mode 100644 index 000000000..7800fb71d --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceStringOperations.java @@ -0,0 +1,517 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.StringUtils; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.core.internal.lettuce.LettuceSetArgs; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyValue; +import io.lettuce.core.SetArgs; +import io.lettuce.core.Value; + +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; + +/** + * Lettuce 单机模式字符串命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceStringOperations extends AbstractStringOperations { + + public LettuceStringOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public Long append(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.APPEND, (cmd)->cmd.append(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long incr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.INCR, (cmd)->cmd.incr(key), (v)->v) + .run(args); + } + } + + @Override + public Long incrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrby(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrby(key, value), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.INCRBY, (cmd)->cmd.incrby(key, value), (v)->v) + .run(args); + } + } + + @Override + public Double incrByFloat(final byte[] key, final double value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.INCRBYFLOAT, (cmd)->cmd.incrbyfloat(key, value), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.INCRBYFLOAT, + (cmd)->cmd.incrbyfloat(key, value), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.INCRBYFLOAT, (cmd)->cmd.incrbyfloat(key, value), (v)->v) + .run(args); + } + } + + @Override + public Long decr(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.DECR, (cmd)->cmd.decr(key), (v)->v) + .run(args); + } + } + + @Override + public Long decrBy(final byte[] key, final long value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrby(key, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrby(key, value), + (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.DECRBY, (cmd)->cmd.decrby(key, value), (v)->v) + .run(args); + } + } + + @Override + public String get(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + final byte[] bKey = SafeEncoder.encode(key); + + return get(bKey, SafeEncoder::encode, args); + } + + @Override + public byte[] get(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return get(key, (v)->v, args); + } + + @Override + public String getEx(final String key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + return getEx(args); + } + + @Override + public byte[] getEx(final byte[] key, final GetExArgument getExArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("getExArgument", getExArgument); + return getEx(args); + } + + @Override + public String getSet(final String key, final String value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final byte[] bKey = SafeEncoder.encode(key); + final byte[] bValue = SafeEncoder.encode(value); + + return getSet(bKey, bValue, SafeEncoder::encode, args); + } + + @Override + public byte[] getSet(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + return getSet(key, value, (v)->v, args); + } + + @Override + public String getDel(final String key) { + final CommandArguments args = CommandArguments.create("key", key); + return getDel(args); + } + + @Override + public byte[] getDel(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + return getDel(args); + } + + @Override + public List mGet(final String... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final byte[][] bKeys = SafeEncoder.encode(keys); + final com.buession.core.converter.ListConverter, String> listConverter = + new com.buession.core.converter.ListConverter<>((v)->SafeEncoder.encode(v.getValue())); + + return mGet(bKeys, listConverter, args); + } + + @Override + public List mGet(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + final ListConverter, byte[]> listConverter = new ListConverter<>(Value::getValue); + + return mGet(keys, listConverter, args); + } + + @Override + public Status mSet(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final Map bValues = Converters.mapStringToBinary().convert(values); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.MSET, (cmd)->cmd.mset(bValues), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.MSET, (cmd)->cmd.mset(bValues), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.MSET, (cmd)->cmd.mset(bValues), okStatusConverter) + .run(args); + } + } + + @Override + public Status mSetNx(final Map values) { + final CommandArguments args = CommandArguments.create("values", values); + final Map bValues = Converters.mapStringToBinary().convert(values); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.MSETNX, (cmd)->cmd.msetnx(bValues), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.MSETNX, (cmd)->cmd.msetnx(bValues), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.MSETNX, (cmd)->cmd.msetnx(bValues), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Status pSetEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.PSETEX, + (cmd)->cmd.psetex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.PSETEX, (cmd)->cmd.psetex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value), okStatusConverter) + .run(args); + } + } + + @Override + public Status set(final byte[] key, final byte[] value, final SetArgument setArgument) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + final SetArgs setArgs = LettuceSetArgs.from(setArgument); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setArgs), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setArgs), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SET, (cmd)->cmd.set(key, value, setArgs), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setEx(final byte[] key, final byte[] value, final int lifetime) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value).put("lifetime", lifetime); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SETEX, + (cmd)->cmd.setex(key, lifetime, value), okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SETEX, (cmd)->cmd.setex(key, lifetime, value), + okStatusConverter) + .run(args); + } + } + + @Override + public Status setNx(final byte[] key, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + booleanStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + booleanStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SETNX, (cmd)->cmd.setnx(key, value), + booleanStatusConverter) + .run(args); + } + } + + @Override + public Long setRange(final byte[] key, final long offset, final byte[] value) { + final CommandArguments args = CommandArguments.create("key", key).put("offset", offset).put("value", value); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SETRANGE, + (cmd)->cmd.setrange(key, offset, value), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SETRANGE, (cmd)->cmd.setrange(key, offset, value), + (v)->v) + .run(args); + } + } + + @Override + public byte[] getRange(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.GETRANGE, (cmd)->cmd.getrange(key, start, end), + (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.GETRANGE, + (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.GETRANGE, (cmd)->cmd.getrange(key, start, end), (v)->v) + .run(args); + } + } + + @Override + public Long strlen(final byte[] key) { + final CommandArguments args = CommandArguments.create("key", key); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.STRLEN, (cmd)->cmd.strlen(key), (v)->v) + .run(args); + } + } + + @Override + public String substr(final String key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final byte[] bKey = SafeEncoder.encode(key); + final Converter converter = (v)->StringUtils.substring(SafeEncoder.encode(v), + (int) start, (int) end); + + return substr(bKey, converter, args); + } + + @Override + public byte[] substr(final byte[] key, final long start, final long end) { + final CommandArguments args = CommandArguments.create("key", key).put("start", start).put("end", end); + final Converter converter = (v)->StringUtils.substring(SafeEncoder.encode(v), (int) start, + (int) end).getBytes(StandardCharsets.UTF_8); + + return substr(key, converter, args); + } + + private V get(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.GET, (cmd)->cmd.get(key), converter) + .run(args); + } + } + + private V getEx(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.GETEX) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.GETEX) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.GETEX) + .run(args); + } + } + + private V getSet(final byte[] key, final byte[] value, final Converter converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getset(key, value), + converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getset(key, value), + converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.GETSET, (cmd)->cmd.getset(key, value), converter) + .run(args); + } + } + + private V getDel(final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand(client, ProtocolCommand.GETDEL) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand(client, ProtocolCommand.GETDEL) + .run(args); + }else{ + return new LettuceCommand(client, ProtocolCommand.GETDEL) + .run(args); + } + } + + private List mGet(final byte[][] keys, final Converter>, List> converter, + final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.MGET, (cmd)->cmd.mget(keys), converter) + .run(args); + } + } + + private V substr(final byte[] key, final Converter converter, final CommandArguments args) { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.SUBSTR, (cmd)->cmd.get(key), converter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.SUBSTR, (cmd)->cmd.get(key), converter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.SUBSTR, (cmd)->cmd.get(key), converter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceTransactionOperations.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceTransactionOperations.java new file mode 100644 index 000000000..ca4e4c5e2 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/LettuceTransactionOperations.java @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.lettuce.operations; + +import com.buession.core.converter.Converter; +import com.buession.lang.Status; +import com.buession.redis.client.lettuce.LettuceStandaloneClient; +import com.buession.redis.core.command.CommandArguments; +import com.buession.redis.core.command.ProtocolCommand; +import io.lettuce.core.TransactionResult; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Lettuce 单机模式事务命令操作 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceTransactionOperations extends AbstractTransactionOperations { + + public LettuceTransactionOperations(final LettuceStandaloneClient client) { + super(client); + } + + @Override + public void discard() { + if(isPipeline()){ + new LettucePipelineCommand<>(client, ProtocolCommand.DISCARD, (cmd)->cmd.discard(), (v)->v) + .run(); + }else if(isTransaction()){ + new LettuceTransactionCommand<>(client, ProtocolCommand.DISCARD, (cmd)->cmd.discard(), (v)->v) + .run(); + }else{ + new LettuceCommand<>(client, ProtocolCommand.DISCARD, (cmd)->cmd.discard(), (v)->v) + .run(); + } + } + + @Override + public List exec() { + final Converter> converter = (v)->v.stream().collect(Collectors.toList()); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.MULTI, (cmd)->cmd.exec(), converter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.MULTI, (cmd)->cmd.exec(), converter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.MULTI, (cmd)->cmd.exec(), converter) + .run(); + } + } + + @Override + public Status multi() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.MULTI, (cmd)->cmd.multi(), okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.MULTI, (cmd)->cmd.multi(), okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.MULTI, (cmd)->cmd.multi(), okStatusConverter) + .run(); + } + } + + @Override + public Status unwatch() { + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.UNWATCH, (cmd)->cmd.unwatch(), + okStatusConverter) + .run(); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.UNWATCH, (cmd)->cmd.unwatch(), + okStatusConverter) + .run(); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.UNWATCH, (cmd)->cmd.unwatch(), okStatusConverter) + .run(); + } + } + + @Override + public Status watch(final byte[]... keys) { + final CommandArguments args = CommandArguments.create("keys", (Object[]) keys); + + if(isPipeline()){ + return new LettucePipelineCommand<>(client, ProtocolCommand.WATCH, (cmd)->cmd.watch(keys), + okStatusConverter) + .run(args); + }else if(isTransaction()){ + return new LettuceTransactionCommand<>(client, ProtocolCommand.WATCH, (cmd)->cmd.watch(keys), + okStatusConverter) + .run(args); + }else{ + return new LettuceCommand<>(client, ProtocolCommand.WATCH, (cmd)->cmd.watch(keys), okStatusConverter) + .run(args); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/package-info.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/package-info.java new file mode 100644 index 000000000..d6466871b --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/operations/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.client.lettuce.operations; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/client/lettuce/package-info.java b/buession-redis/src/main/java/com/buession/redis/client/lettuce/package-info.java new file mode 100644 index 000000000..f7a8cceb4 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/lettuce/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.client.lettuce; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/client/operations/AbstractRedisOperations.java b/buession-redis/src/main/java/com/buession/redis/client/operations/AbstractRedisOperations.java index 16c0f733c..cf8d18143 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/operations/AbstractRedisOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/operations/AbstractRedisOperations.java @@ -19,14 +19,19 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.operations; +import com.buession.core.converter.BooleanStatusConverter; +import com.buession.core.converter.ListConverter; import com.buession.redis.client.RedisClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import com.buession.redis.client.connection.RedisConnection; +import com.buession.redis.core.internal.convert.response.OkStatusConverter; +import com.buession.redis.core.internal.convert.response.OneBooleanConverter; +import com.buession.redis.core.internal.convert.response.OneStatusConverter; +import com.buession.redis.utils.SafeEncoder; /** * Redis 命令操作抽象类 @@ -38,8 +43,34 @@ */ public abstract class AbstractRedisOperations implements RedisOperations { - protected final Logger logger = LoggerFactory.getLogger(getClass()); - protected C client; + protected final ListConverter binaryToStringListConverter = + new ListConverter<>(SafeEncoder::encode); + + protected final static OkStatusConverter okStatusConverter = new OkStatusConverter(); + + protected final static BooleanStatusConverter booleanStatusConverter = new BooleanStatusConverter(); + + protected final static OneStatusConverter oneStatusConverter = new OneStatusConverter(); + + protected final static OneBooleanConverter oneBooleanConverter = new OneBooleanConverter(); + + public AbstractRedisOperations(final C client) { + this.client = client; + } + + protected boolean isPipeline() { + return client.getConnection().isPipeline(); + } + + protected boolean isTransaction() { + return client.getConnection().isTransaction(); + } + + protected boolean isMulti() { + final RedisConnection connection = client.getConnection(); + return connection.isPipeline() || connection.isTransaction(); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/client/operations/GenericOperations.java b/buession-redis/src/main/java/com/buession/redis/client/operations/GenericOperations.java new file mode 100644 index 000000000..747b337df --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/client/operations/GenericOperations.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.client.operations; + +import com.buession.redis.core.command.GenericCommand; + +/** + * 一般命令操作接口 + * + *

详情说明 https://redis.io/docs/latest/commands/?group=generic

+ * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface GenericOperations extends GenericCommand, RedisOperations { + +} diff --git a/buession-redis/src/main/java/com/buession/redis/client/operations/RedisOperations.java b/buession-redis/src/main/java/com/buession/redis/client/operations/RedisOperations.java index ab73fec2d..f4f2c8623 100644 --- a/buession-redis/src/main/java/com/buession/redis/client/operations/RedisOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/client/operations/RedisOperations.java @@ -19,11 +19,27 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.client.operations; +import com.buession.core.converter.Converter; +import com.buession.redis.client.RedisClusterClient; +import com.buession.redis.client.RedisSentinelClient; +import com.buession.redis.client.RedisStandaloneClient; +import com.buession.redis.client.connection.RedisClusterConnection; +import com.buession.redis.client.connection.RedisConnectionUtils; +import com.buession.redis.client.connection.RedisSentinelConnection; +import com.buession.redis.client.connection.RedisStandaloneConnection; +import com.buession.redis.core.RedisMode; +import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.core.internal.AbstractRedisOperationsCommand; +import com.buession.redis.exception.NotSupportedCommandException; +import com.buession.redis.exception.NotSupportedPipelineCommandException; +import com.buession.redis.exception.NotSupportedTransactionCommandException; +import com.buession.redis.exception.RedisException; + /** * Redis 命令操作接口 * @@ -31,4 +47,112 @@ */ public interface RedisOperations { + abstract class AbstractStandaloneCommand + extends AbstractRedisOperationsCommand { + + public AbstractStandaloneCommand(final CLIENT client, final ProtocolCommand command) { + super(client, command); + } + + public AbstractStandaloneCommand(final CLIENT client, final ProtocolCommand command, + final Executor executor, final Converter converter) { + super(client, command, executor, converter); + } + + @Override + public R execute() throws RedisException { + final RedisMode mode = RedisConnectionUtils.getRedisMode(connection); + + if(executor == null){ + if(connection.isPipeline()){ + throw new NotSupportedPipelineCommandException(mode, getCommand()); + }else if(connection.isTransaction()){ + throw new NotSupportedTransactionCommandException(mode, getCommand()); + }else{ + throw new NotSupportedCommandException(RedisConnectionUtils.getRedisMode(connection), + NotSupportedCommandException.Type.NORMAL, getCommand()); + } + }else{ + try{ + return doExecute(); + }catch(Exception e){ + throw new RedisException(e.getMessage(), e); + } + } + } + + } + + abstract class AbstractSentinelCommand + extends AbstractRedisOperationsCommand { + + public AbstractSentinelCommand(final CLIENT client, final ProtocolCommand command) { + super(client, command); + } + + public AbstractSentinelCommand(final CLIENT client, ProtocolCommand command, + final Executor executor, final Converter converter) { + super(client, command, executor, converter); + } + + @Override + public R execute() throws RedisException { + final RedisMode mode = RedisConnectionUtils.getRedisMode(connection); + + if(executor == null){ + if(connection.isPipeline()){ + throw new NotSupportedPipelineCommandException(mode, getCommand()); + }else if(connection.isTransaction()){ + throw new NotSupportedTransactionCommandException(mode, getCommand()); + }else{ + throw new NotSupportedCommandException(RedisConnectionUtils.getRedisMode(connection), + NotSupportedCommandException.Type.NORMAL, getCommand()); + } + }else{ + try{ + return doExecute(); + }catch(Exception e){ + throw new RedisException(e.getMessage(), e); + } + } + } + + } + + abstract class AbstractClusterCommand + extends AbstractRedisOperationsCommand { + + public AbstractClusterCommand(final CLIENT client, final ProtocolCommand command) { + super(client, command); + } + + public AbstractClusterCommand(final CLIENT client, final ProtocolCommand command, + final Executor executor, final Converter converter) { + super(client, command, executor, converter); + } + + @Override + public R execute() throws RedisException { + final RedisMode mode = RedisConnectionUtils.getRedisMode(connection); + + if(executor == null){ + if(connection.isPipeline()){ + throw new NotSupportedPipelineCommandException(mode, getCommand()); + }else if(connection.isTransaction()){ + throw new NotSupportedTransactionCommandException(mode, getCommand()); + }else{ + throw new NotSupportedCommandException(RedisConnectionUtils.getRedisMode(connection), + NotSupportedCommandException.Type.NORMAL, getCommand()); + } + }else{ + try{ + return doExecute(); + }catch(Exception e){ + throw new RedisException(e.getMessage(), e); + } + } + } + + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/AbstractRedisCommand.java b/buession-redis/src/main/java/com/buession/redis/core/AbstractRedisCommand.java index e7f97cac3..6878a26ff 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/AbstractRedisCommand.java +++ b/buession-redis/src/main/java/com/buession/redis/core/AbstractRedisCommand.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core; @@ -34,6 +34,8 @@ import org.slf4j.LoggerFactory; /** + * Redis 命令抽象类 + * * @author Yong.Teng * @since 2.0.0 */ diff --git a/buession-redis/src/main/java/com/buession/redis/core/AclLog.java b/buession-redis/src/main/java/com/buession/redis/core/AclLog.java index 998030ab8..615e2bf44 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/AclLog.java +++ b/buession-redis/src/main/java/com/buession/redis/core/AclLog.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core; @@ -30,6 +30,8 @@ import java.util.Map; /** + * Acl 日志 + * * @author Yong.Teng * @since 2.0.0 */ @@ -37,6 +39,29 @@ public class AclLog implements Serializable { private final static long serialVersionUID = -1362912160889551004L; + // Redis 7.2 + public final static String ENTRY_ID = "entry-id"; + + public final static String COUNT = "count"; + + public final static String REASON = "reason"; + + public final static String CONTEXT = "context"; + + public final static String OBJECT = "object"; + + public final static String USERNAME = "username"; + + public final static String AGE_SECONDS = "age-seconds"; + + public final static String CLIENT_INFO = "client-info"; + + public final static String TIMESTAMP_CREATED = "timestamp-created"; + + public final static String TIMESTAMP_LAST_UPDATED = "timestamp-last-updated"; + + private final long entryId; + private final long count; private final String reason; @@ -47,15 +72,20 @@ public class AclLog implements Serializable { private final String username; - private final String ageSeconds; + private final Double ageSeconds; private final Client clientInfo; + private final long timestampCreated; + + private final long timestampLastUpdated; + private final Map logEntry; - public AclLog(final long count, final String reason, final String context, final String object, - final String username, final String ageSeconds, final Client clientInfo, - final Map logEntry){ + public AclLog(final long entryId, final long count, final String reason, final String context, final String object, + final String username, final Double ageSeconds, final Client clientInfo, final long timestampCreated, + final long timestampLastUpdated, final Map logEntry) { + this.entryId = entryId; this.count = count; this.reason = reason; this.context = context; @@ -63,52 +93,68 @@ public AclLog(final long count, final String reason, final String context, final this.username = username; this.ageSeconds = ageSeconds; this.clientInfo = clientInfo; + this.timestampCreated = timestampCreated; + this.timestampLastUpdated = timestampLastUpdated; this.logEntry = logEntry; } - public long getCount(){ + public long getEntryId() { + return entryId; + } + + public long getCount() { return count; } - public String getReason(){ + public String getReason() { return reason; } - public String getContext(){ + public String getContext() { return context; } - public String getObject(){ + public String getObject() { return object; } - public String getUsername(){ + public String getUsername() { return username; } - public String getAgeSeconds(){ + public Double getAgeSeconds() { return ageSeconds; } - public Client getClientInfo(){ + public Client getClientInfo() { return clientInfo; } - public Map getLogEntry(){ + public long getTimestampCreated() { + return timestampCreated; + } + + public long getTimestampLastUpdated() { + return timestampLastUpdated; + } + + public Map getLogEntry() { return logEntry; } @Override - public String toString(){ + public String toString() { return ObjectStringBuilder.create() - .add("count", count) - .add("reason", reason) - .add("context", context) - .add("object", object) - .add("username", username) - .add("ageSeconds", ageSeconds) - .add("clientInfo", clientInfo) - .add("logEntry", logEntry) + .add(ENTRY_ID, entryId) + .add(COUNT, count) + .add(REASON, reason) + .add(CONTEXT, context) + .add(OBJECT, object) + .add(USERNAME, username) + .add(AGE_SECONDS, ageSeconds) + .add(CLIENT_INFO, clientInfo) + .add(TIMESTAMP_CREATED, timestampCreated) + .add(TIMESTAMP_LAST_UPDATED, timestampLastUpdated) .build(); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/AclUser.java b/buession-redis/src/main/java/com/buession/redis/core/AclUser.java index e01dbdc00..e2a1926e8 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/AclUser.java +++ b/buession-redis/src/main/java/com/buession/redis/core/AclUser.java @@ -19,16 +19,19 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core; +import com.buession.core.validator.Validate; import com.buession.redis.utils.ObjectStringBuilder; import java.io.Serializable; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @author Yong.Teng @@ -38,54 +41,88 @@ public class AclUser implements Serializable { private final static long serialVersionUID = -2237993389031684508L; + private final String commands; + + private final Map userInfo = new HashMap<>(); + + private final List passwords = new ArrayList<>(); + private final List flags = new ArrayList<>(); private final List keys = new ArrayList<>(); - private final List passwords = new ArrayList<>(); + private final List channels = new ArrayList<>(); - private final String commands; + private final List selectors = new ArrayList<>(); + + public AclUser(final String commands, final Map userInfo, final List passwords, + final List flags, final List keys, final List channels, + final List selectors) { + this.commands = commands; + + if(Validate.isNotEmpty(userInfo)){ + this.userInfo.putAll(userInfo); + } + + if(passwords != null){ + this.passwords.addAll(passwords); + } - public AclUser(final List flags, final List keys, final List passwords, - final String commands){ if(flags != null){ - flags.addAll(flags); + this.flags.addAll(flags); } if(keys != null){ - keys.addAll(keys); + this.keys.addAll(keys); } - if(passwords != null){ - passwords.addAll(passwords); + if(channels != null){ + this.channels.addAll(channels); } - this.commands = commands; + if(selectors != null){ + this.selectors.addAll(selectors); + } + } + + public String getCommands() { + return commands; } - public List getFlags(){ + public Map getUserInfo() { + return userInfo; + } + + public List getPasswords() { + return passwords; + } + + public List getFlags() { return flags; } - public List getKeys(){ + public List getKeys() { return keys; } - public List getPasswords(){ - return passwords; + public List getChannels() { + return channels; } - public String getCommands(){ - return commands; + public List getSelectors() { + return selectors; } @Override - public String toString(){ + public String toString() { return ObjectStringBuilder.create() + .add("commands", commands) + .add("userInfo", userInfo) + .add("passwords", passwords) .add("flags", flags) .add("keys", keys) - .add("passwords", passwords) - .add("commands", commands) + .add("channels", channels) + .add("selectors", selectors) .build(); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/BitType.java b/buession-redis/src/main/java/com/buession/redis/core/BitType.java new file mode 100644 index 000000000..a52d9e224 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/BitType.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public enum BitType { + + BYTE, + + BIT + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/Command.java b/buession-redis/src/main/java/com/buession/redis/core/Command.java index e3a4834f3..c4d394100 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/Command.java +++ b/buession-redis/src/main/java/com/buession/redis/core/Command.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core; @@ -81,6 +81,24 @@ default R run() throws RedisException { */ R run(final CommandArguments arguments) throws RedisException; + /** + * Redis 命令执行器 + * + * @param + * Redis 对象上下文 + * @param + * 命令执行返回值类型 + * + * @since 3.0.0 + */ + @FunctionalInterface + interface Executor extends com.buession.core.Executor { + + @Override + R execute(C context) throws RedisException; + + } + /** * Redis 命令运行器 * @@ -97,10 +115,10 @@ interface Runner { * * @return Redis 命令运行结果 * - * @throws Exception + * @throws RedisException * Redis 命令运行异常 */ - R run() throws Exception; + R run() throws RedisException; } diff --git a/buession-redis/src/main/java/com/buession/redis/core/FutureResult.java b/buession-redis/src/main/java/com/buession/redis/core/FutureResult.java index 1db4cb874..a8b72345a 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/FutureResult.java +++ b/buession-redis/src/main/java/com/buession/redis/core/FutureResult.java @@ -19,48 +19,47 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core; import com.buession.core.converter.Converter; +import com.buession.redis.core.internal.convert.Converters; import org.springframework.lang.Nullable; -import java.util.function.Supplier; - /** * 事务、管道异步结果 * * @param * Response - * @param - * 原始结果类型 - * @param - * 目标结果类型 * * @author Yong.Teng */ -public abstract class FutureResult implements Supplier { +public abstract class FutureResult { private final T holder; - private final Converter converter; + @SuppressWarnings({"rawtypes"}) + private final Converter converter; - public FutureResult(final T holder){ - this(holder, null); + public FutureResult(final T holder) { + this(holder, Converters.always()); } - @SuppressWarnings("unchecked") - public FutureResult(final T holder, final Converter converter){ + @SuppressWarnings({"rawtypes"}) + public FutureResult(final T holder, final Converter converter) { this.holder = holder; - this.converter = converter != null ? converter : val->(TV) val; + this.converter = converter; } - public T getHolder(){ + public final T getHolder() { return holder; } + @Nullable + public abstract Object get(); + /** * 将 事务、管道 * @@ -69,8 +68,9 @@ public T getHolder(){ * * @return 转换结果 */ + @SuppressWarnings({"unchecked"}) @Nullable - public TV convert(@Nullable SV result){ + public Object convert(@Nullable Object result) { return result == null ? null : converter.convert(result); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/GeoRadius.java b/buession-redis/src/main/java/com/buession/redis/core/GeoRadius.java index 393c69a55..d2daca6e0 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/GeoRadius.java +++ b/buession-redis/src/main/java/com/buession/redis/core/GeoRadius.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core; @@ -41,41 +41,53 @@ public class GeoRadius implements Serializable { private final byte[] member; - private final double distance; + private final Double distance; private final Geo geo; - public GeoRadius(final byte[] member, final double distance, final Geo geo){ + public GeoRadius(final byte[] member) { + this(member, null, null); + } + + public GeoRadius(final byte[] member, final Double distance) { + this(member, distance, null); + } + + public GeoRadius(final byte[] member, final Geo geo) { + this(member, null, geo); + } + + public GeoRadius(final byte[] member, final Double distance, final Geo geo) { this.member = member; this.distance = distance; this.geo = geo; } - public byte[] getMember(){ + public byte[] getMember() { return member; } - public String getMemberAsString(){ + public String getMemberAsString() { return new String(member, StandardCharsets.UTF_8); } - public double getDistance(){ + public Double getDistance() { return distance; } - public Geo getGeo(){ + public Geo getGeo() { return geo; } @Override - public int hashCode(){ + public int hashCode() { int result = Objects.hash(distance, geo); result = 31 * result + Arrays.hashCode(member); return result; } @Override - public boolean equals(Object obj){ + public boolean equals(Object obj) { if(this == obj){ return true; } @@ -90,11 +102,11 @@ public boolean equals(Object obj){ } @Override - public String toString(){ + public String toString() { return ObjectStringBuilder.create() .add("member", member) - .add("distance", distance) - .add("geo", geo) + .addIfAbsent("distance", distance) + .addIfAbsent("geo", geo) .build(); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/MemoryStats.java b/buession-redis/src/main/java/com/buession/redis/core/MemoryStats.java index 058aee474..a7c68eef8 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/MemoryStats.java +++ b/buession-redis/src/main/java/com/buession/redis/core/MemoryStats.java @@ -25,6 +25,8 @@ package com.buession.redis.core; import java.io.Serializable; +import java.util.List; +import java.util.Map; /** * @author Yong.Teng @@ -33,4 +35,655 @@ public class MemoryStats implements Serializable { private final static long serialVersionUID = -5308964580953471955L; + + /** + * 全部数据所使用的内存{for dataset.bytes} + */ + private Long dataset; + + /** + * redis 数据占用内存占总内存分配的百分比{for dataset.percentage} + */ + private Double datasetPercentage; + + /** + * 常驻内存开销大小{for rss-overhead.bytes} + */ + private Long rssOverhead; + + /** + * 常驻内存开销比例{for rss-overhead.ratio} + */ + private Double rssOverheadRatio; + + /** + * 当前内存使用量与峰值时的占比{for peak.percentage} + */ + private Double peakPercentage; + + /** + * Aof 持久化使用的缓存和 Aof Rewrite 时产生的缓存之和,若关闭了 appendonly 则为 0{for aof.buffer} + */ + private Long aofBuffer; + + /** + * 平均每一个 key 的内存大小{for keys.bytes-per-key} + */ + private Long keysBytesPerKey; + + /** + * 分配器分配的内存{for allocator.allocated} + */ + private Long allocatorAllocated; + + /** + * used_memory_rss 和 used_memory 的差值 {for allocator-fragmentation.bytes} + */ + private Long allocatorFragmentation; + + /** + * used_memory_rss Redis从系统申请的内存和 used_memory Redis 给数据分配的内存的比率;不仅包括碎片,还包括其他进程及代码、共享库、堆栈的内存开销等等{for allocator + * -fragmentation.ratio} + */ + private Double allocatorFragmentationRatio; + + /** + * 分配器活动页中的字节量,包含外部碎片{for allocator.active} + */ + private Long allocatorActive; + + /** + * 分配器的常驻内存大小{for allocator-rss.bytes} + */ + private Long allocatorRss; + + /** + * 分配器常驻内存比例{for allocator-rss.ratio} + */ + private Double allocatorRssRatio; + + /** + * 分配器包含的总字节量{for allocator.resident} + */ + private Long allocatorResident; + + /** + * 所有常规客户端消耗内存节字数{for clients.normal} + */ + private Long clientsNormal; + + /** + * 所有 slave clients 消耗的内存字节数{for clients.slaves} + */ + private Long clientsSlaves; + + /** + * 内存碎片{for fragmentation.bytes} + */ + private Long fragmentation; + + /** + * 内存碎片率{for fragmentation} + */ + private Double fragmentationRatio; + + /** + * Lua 脚本缓存开销内存节字数{for lua.caches} + */ + private Long luaCaches; + + /** + * redis 启动至今,最多使用过多少内存{for peak.allocated} + */ + private Long peakAllocated; + + /** + * 当前使用的内存总量{for total.allocated} + */ + private Long totalAllocated; + + /** + * 主从复制 backlog 使用的内存{for replication.backlog} + */ + private Long replicationBacklog; + + /** + * redis 启动完成使用的内存字节数{for startup.allocated} + */ + private Long startupAllocated; + + /** + * redis 额外的总开销内存字节数;即分配器分配的总内存 total.allocated,减去数据实际存储使用内存{for overhead.total} + */ + private Long overheadTotal; + + /** + * key 总量{for keys.count} + */ + private Long keysCount; + + /** + * 每个 DB 统计{for db.x} + */ + private Map dbs; + + /** + * 返回全部数据所使用的内存 + * + * @return 全部数据所使用的内存{for dataset.bytes} + */ + public Long getDataset() { + return dataset; + } + + /** + * 设置全部数据所使用的内存{for dataset.bytes} + * + * @param dataset + * 全部数据所使用的内存 + */ + public void setDataset(Long dataset) { + this.dataset = dataset; + } + + /** + * 返回 redis 数据占用内存占总内存分配的百分比 + * + * @return redis 数据占用内存占总内存分配的百分比{for dataset.percentage} + */ + public Double getDatasetPercentage() { + return datasetPercentage; + } + + /** + * 设置 redis 数据占用内存占总内存分配的百分比{for dataset.percentage} + * + * @param datasetPercentage + * redis 数据占用内存占总内存分配的百分比 + */ + public void setDatasetPercentage(Double datasetPercentage) { + this.datasetPercentage = datasetPercentage; + } + + /** + * 返回常驻内存开销大小{for rss-overhead.bytes} + * + * @return 常驻内存开销大小 + */ + public Long getRssOverhead() { + return rssOverhead; + } + + /** + * 设置常驻内存开销大小{for rss-overhead.bytes} + * + * @param rssOverhead + * 常驻内存开销大小 + */ + public void setRssOverhead(Long rssOverhead) { + this.rssOverhead = rssOverhead; + } + + /** + * 返回常驻内存开销比例{for rss-overhead.ratio} + * + * @return 常驻内存开销比例{for rss-overhead.ratio} + */ + public Double getRssOverheadRatio() { + return rssOverheadRatio; + } + + /** + * 设置常驻内存开销比例{for rss-overhead.ratio} + * + * @param rssOverheadRatio + * 常驻内存开销比例 + */ + public void setRssOverheadRatio(Double rssOverheadRatio) { + this.rssOverheadRatio = rssOverheadRatio; + } + + /** + * 返回当前内存使用量与峰值时的占比{for peak.percentage} + * + * @return 当前内存使用量与峰值时的占比 + */ + public Double getPeakPercentage() { + return peakPercentage; + } + + /** + * 设置当前内存使用量与峰值时的占比{for peak.percentage} + * + * @param peakPercentage + * 当前内存使用量与峰值时的占比 + */ + public void setPeakPercentage(Double peakPercentage) { + this.peakPercentage = peakPercentage; + } + + /** + * 返回 Aof 持久化使用的缓存和 Aof Rewrite 时产生的缓存之和{for aof.buffer} + * + * @return Aof 持久化使用的缓存和 Aof Rewrite 时产生的缓存之和,若关闭了 appendonly 则为 0 + */ + public Long getAofBuffer() { + return aofBuffer; + } + + /** + * 设置 Aof 持久化使用的缓存和 Aof Rewrite 时产生的缓存之和{for aof.buffer} + * + * @param aofBuffer + * Aof 持久化使用的缓存和 Aof Rewrite 时产生的缓存之和 + */ + public void setAofBuffer(Long aofBuffer) { + this.aofBuffer = aofBuffer; + } + + /** + * 返回平均每一个 key 的内存大小{for keys.bytes-per-key} + * + * @return 平均每一个 key 的内存大小 + */ + public Long getKeysBytesPerKey() { + return keysBytesPerKey; + } + + /** + * 设置平均每一个 key 的内存大小{for keys.bytes-per-key} + * + * @param keysBytesPerKey + * 平均每一个 key 的内存大小 + */ + public void setKeysBytesPerKey(Long keysBytesPerKey) { + this.keysBytesPerKey = keysBytesPerKey; + } + + /** + * 返回分配器分配的内存{for allocator.allocated} + * + * @return 分配器分配的内存 + */ + public Long getAllocatorAllocated() { + return allocatorAllocated; + } + + /** + * 设置分配器分配的内存{for allocator.allocated} + * + * @param allocatorAllocated + * 分配器分配的内存 + */ + public void setAllocatorAllocated(Long allocatorAllocated) { + this.allocatorAllocated = allocatorAllocated; + } + + /** + * 返回 used_memory_rss 和 used_memory 的差值 {for allocator-fragmentation.bytes} + * + * @return used_memory_rss 和 used_memory 的差值 + */ + public Long getAllocatorFragmentation() { + return allocatorFragmentation; + } + + /** + * 设置 used_memory_rss 和 used_memory 的差值 {for allocator-fragmentation.bytes} + * + * @param allocatorFragmentation + * used_memory_rss 和 used_memory 的差值 + */ + public void setAllocatorFragmentation(Long allocatorFragmentation) { + this.allocatorFragmentation = allocatorFragmentation; + } + + /** + * 返回 used_memory_rss Redis从系统申请的内存和 used_memory Redis 给数据分配的内存的比率;不仅包括碎片,还包括其他进程及代码、共享库、堆栈的内存开销等等{for allocator + * -fragmentation.ratio} + * + * @return used_memory_rss Redis从系统申请的内存和 used_memory Redis 给数据分配的内存的比率 + */ + public Double getAllocatorFragmentationRatio() { + return allocatorFragmentationRatio; + } + + /** + * 设置 used_memory_rss Redis从系统申请的内存和 used_memory Redis 给数据分配的内存的比率;不仅包括碎片,还包括其他进程及代码、共享库、堆栈的内存开销等等{for allocator-fragmentation.ratio} + * + * @param allocatorFragmentationRatio + * used_memory_rss Redis从系统申请的内存和 used_memory Redis 给数据分配的内存的比率 + */ + public void setAllocatorFragmentationRatio(Double allocatorFragmentationRatio) { + this.allocatorFragmentationRatio = allocatorFragmentationRatio; + } + + /** + * 返回分配器活动页中的字节量,包含外部碎片{for allocator.active} + * + * @return 分配器活动页中的字节量,包含外部碎片 + */ + public Long getAllocatorActive() { + return allocatorActive; + } + + /** + * 设置分配器活动页中的字节量,包含外部碎片{for allocator.active} + * + * @param allocatorActive + * 分配器活动页中的字节量 + */ + public void setAllocatorActive(Long allocatorActive) { + this.allocatorActive = allocatorActive; + } + + /** + * 返回分配器的常驻内存大小{for allocator-rss.bytes} + * + * @return 分配器的常驻内存大小 + */ + public Long getAllocatorRss() { + return allocatorRss; + } + + /** + * 设置分配器的常驻内存大小{for allocator-rss.bytes} + * + * @param allocatorRss + * 分配器的常驻内存大小 + */ + public void setAllocatorRss(Long allocatorRss) { + this.allocatorRss = allocatorRss; + } + + /** + * 返回分配器常驻内存比例{for allocator-rss.ratio} + * + * @return 分配器常驻内存比例 + */ + public Double getAllocatorRssRatio() { + return allocatorRssRatio; + } + + /** + * 设置分配器常驻内存比例{for allocator-rss.ratio} + * + * @param allocatorRssRatio + * 分配器常驻内存比例 + */ + public void setAllocatorRssRatio(Double allocatorRssRatio) { + this.allocatorRssRatio = allocatorRssRatio; + } + + /** + * 返回分配器包含的总字节量{for allocator.resident} + * + * @return 分配器包含的总字节量 + */ + public Long getAllocatorResident() { + return allocatorResident; + } + + /** + * 设置分配器包含的总字节量{for allocator.resident} + * + * @param allocatorResident + * 分配器包含的总字节量 + */ + public void setAllocatorResident(Long allocatorResident) { + this.allocatorResident = allocatorResident; + } + + /** + * 返回所有常规客户端消耗内存节字数{for clients.normal} + * + * @return 所有常规客户端消耗内存节字数 + */ + public Long getClientsNormal() { + return clientsNormal; + } + + /** + * 设置所有常规客户端消耗内存节字数{for clients.normal} + * + * @param clientsNormal + * 所有常规客户端消耗内存节字数 + */ + public void setClientsNormal(Long clientsNormal) { + this.clientsNormal = clientsNormal; + } + + /** + * 返回所有 slave clients 消耗的内存字节数{for clients.slaves} + * + * @return 所有 slave clients 消耗的内存字节数 + */ + public Long getClientsSlaves() { + return clientsSlaves; + } + + /** + * 设置所有 slave clients 消耗的内存字节数{for clients.slaves} + * + * @param clientsSlaves + * 所有 slave clients 消耗的内存字节数 + */ + public void setClientsSlaves(Long clientsSlaves) { + this.clientsSlaves = clientsSlaves; + } + + /** + * 返回内存碎片{for fragmentation.bytes} + * + * @return 内存碎片 + */ + public Long getFragmentation() { + return fragmentation; + } + + /** + * 设置内存碎片{for fragmentation.bytes} + * + * @param fragmentation + * 内存碎片 + */ + public void setFragmentation(Long fragmentation) { + this.fragmentation = fragmentation; + } + + /** + * 返回内存碎片率{for fragmentation} + * + * @return 内存碎片率 + */ + public Double getFragmentationRatio() { + return fragmentationRatio; + } + + /** + * 设置内存碎片率{for fragmentation} + * + * @param fragmentationRatio + * 内存碎片率 + */ + public void setFragmentationRatio(Double fragmentationRatio) { + this.fragmentationRatio = fragmentationRatio; + } + + /** + * 返回 Lua 脚本缓存开销内存节字数{for lua.caches} + * + * @return Lua 脚本缓存开销内存节字数 + */ + public Long getLuaCaches() { + return luaCaches; + } + + /** + * 设置 Lua 脚本缓存开销内存节字数{for lua.caches} + * + * @param luaCaches + * Lua 脚本缓存开销内存节字数 + */ + public void setLuaCaches(Long luaCaches) { + this.luaCaches = luaCaches; + } + + /** + * 返回 redis 启动至今,最多使用过多少内存{for peak.allocated} + * + * @return redis 启动至今,最多使用过多少内存 + */ + public Long getPeakAllocated() { + return peakAllocated; + } + + /** + * 设置 redis 启动至今,最多使用过多少内存{for peak.allocated} + * + * @param peakAllocated + * redis 启动至今,最多使用过多少内存 + */ + public void setPeakAllocated(Long peakAllocated) { + this.peakAllocated = peakAllocated; + } + + /** + * 返回当前使用的内存总量{for total.allocated} + * + * @return 当前使用的内存总量 + */ + public Long getTotalAllocated() { + return totalAllocated; + } + + /** + * 设置当前使用的内存总量{for total.allocated} + * + * @param totalAllocated + * 当前使用的内存总量 + */ + public void setTotalAllocated(Long totalAllocated) { + this.totalAllocated = totalAllocated; + } + + /** + * 返回主从复制 backlog 使用的内存{for replication.backlog} + * + * @return 主从复制 backlog 使用的内存 + */ + public Long getReplicationBacklog() { + return replicationBacklog; + } + + /** + * 设置主从复制 backlog 使用的内存{for replication.backlog} + * + * @param replicationBacklog + * 主从复制 backlog 使用的内存 + */ + public void setReplicationBacklog(Long replicationBacklog) { + this.replicationBacklog = replicationBacklog; + } + + /** + * 返回 redis 启动完成使用的内存字节数{for startup.allocated} + * + * @return redis 启动完成使用的内存字节数 + */ + public Long getStartupAllocated() { + return startupAllocated; + } + + /** + * 设置 redis 启动完成使用的内存字节数{for startup.allocated} + * + * @param startupAllocated + * redis 启动完成使用的内存字节数 + */ + public void setStartupAllocated(Long startupAllocated) { + this.startupAllocated = startupAllocated; + } + + /** + * 返回 redis 额外的总开销内存字节数;即分配器分配的总内存 total.allocated,减去数据实际存储使用内存{for overhead.total} + * + * @return redis 额外的总开销内存字节数 + */ + public Long getOverheadTotal() { + return overheadTotal; + } + + /** + * 设置 redis 额外的总开销内存字节数;即分配器分配的总内存 total.allocated,减去数据实际存储使用内存{for overhead.total} + * + * @param overheadTotal + * redis 额外的总开销内存字节数;即分配器分配的总内存 total.allocated,减去数据实际存储使用内存 + */ + public void setOverheadTotal(Long overheadTotal) { + this.overheadTotal = overheadTotal; + } + + /** + * 返回 key 总量{for keys.count} + * + * @return key 总量 + */ + public Long getKeysCount() { + return keysCount; + } + + /** + * 设置 key 总量{for keys.count} + * + * @param keysCount + * key 总量 + */ + public void setKeysCount(Long keysCount) { + this.keysCount = keysCount; + } + + /** + * 返回每个 DB 统计{for db.x} + * + * @return 每个 DB 统计 + */ + public Map getDbs() { + return dbs; + } + + /** + * 设置每个 DB 统计{for db.x} + * + * @param dbs + * 每个 DB 统计 + */ + public void setDbs(Map dbs) { + this.dbs = dbs; + } + + public final static class Db { + + private long overheadHashTableMain; + + private long overheadHashTableExpires; + + public long getOverheadHashTableMain() { + return overheadHashTableMain; + } + + public void setOverheadHashTableMain(long overheadHashTableMain) { + this.overheadHashTableMain = overheadHashTableMain; + } + + public long getOverheadHashTableExpires() { + return overheadHashTableExpires; + } + + public void setOverheadHashTableExpires(long overheadHashTableExpires) { + this.overheadHashTableExpires = overheadHashTableExpires; + } + + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/NxXx.java b/buession-redis/src/main/java/com/buession/redis/core/NxXx.java index 7c793101f..d77ce83cc 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/NxXx.java +++ b/buession-redis/src/main/java/com/buession/redis/core/NxXx.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2020 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core; @@ -29,8 +29,14 @@ */ public enum NxXx { + /** + * 只有键 key 不存在的时候 + */ NX, + /** + * 只有键 key 存在的时候 + */ XX } diff --git a/buession-redis/src/main/java/com/buession/redis/core/Options.java b/buession-redis/src/main/java/com/buession/redis/core/Options.java index 5a6c116dc..2ddc9d25b 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/Options.java +++ b/buession-redis/src/main/java/com/buession/redis/core/Options.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core; @@ -30,6 +30,8 @@ import com.buession.redis.serializer.GsonJsonSerializer; import com.buession.redis.serializer.JacksonJsonSerializer; +import java.util.Optional; + /** * @author Yong.Teng */ @@ -61,7 +63,7 @@ public class Options { * * @return Key 前缀 */ - public String getPrefix(){ + public String getPrefix() { return prefix; } @@ -71,7 +73,7 @@ public String getPrefix(){ * @param prefix * Key 前缀 */ - public void setPrefix(String prefix){ + public void setPrefix(String prefix) { this.prefix = prefix; } @@ -86,7 +88,7 @@ public void setPrefix(String prefix){ * @see GsonJsonSerializer * @see JacksonJsonSerializer */ - public Serializer getSerializer(){ + public Serializer getSerializer() { return serializer; } @@ -102,7 +104,7 @@ public Serializer getSerializer(){ * @see GsonJsonSerializer * @see JacksonJsonSerializer */ - public void setSerializer(Serializer serializer){ + public void setSerializer(Serializer serializer) { this.serializer = serializer; } @@ -111,7 +113,7 @@ public void setSerializer(Serializer serializer){ * * @return 是否开启事务支持 */ - public boolean isEnableTransactionSupport(){ + public boolean isEnableTransactionSupport() { return getEnableTransactionSupport(); } @@ -120,7 +122,7 @@ public boolean isEnableTransactionSupport(){ * * @return 是否开启事务支持 */ - public boolean getEnableTransactionSupport(){ + public boolean getEnableTransactionSupport() { return enableTransactionSupport; } @@ -130,7 +132,7 @@ public boolean getEnableTransactionSupport(){ * @param enableTransactionSupport * 是否开启事务支持 */ - public void setEnableTransactionSupport(boolean enableTransactionSupport){ + public void setEnableTransactionSupport(boolean enableTransactionSupport) { this.enableTransactionSupport = enableTransactionSupport; } @@ -144,7 +146,7 @@ public final static class Builder { private final Options options = new Options(); - private Builder(){ + private Builder() { } @@ -153,7 +155,7 @@ private Builder(){ * * @return {@link Builder} 实例 */ - public static Builder getInstance(){ + public static Builder getInstance() { return new Builder(); } @@ -165,7 +167,7 @@ public static Builder getInstance(){ * * @return {@link Builder} 实例 */ - public Builder prefix(String prefix){ + public Builder prefix(String prefix) { options.setPrefix(prefix); return this; } @@ -184,7 +186,7 @@ public Builder prefix(String prefix){ * @see GsonJsonSerializer * @see JacksonJsonSerializer */ - public Builder serializer(Serializer serializer){ + public Builder serializer(Serializer serializer) { options.setSerializer(serializer); return this; } @@ -197,11 +199,8 @@ public Builder serializer(Serializer serializer){ * * @return {@link Builder} 实例 */ - public Builder enableTransactionSupport(Boolean enableTransactionSupport){ - if(enableTransactionSupport != null){ - options.setEnableTransactionSupport(enableTransactionSupport); - } - + public Builder enableTransactionSupport(Boolean enableTransactionSupport) { + Optional.ofNullable(enableTransactionSupport).ifPresent(options::setEnableTransactionSupport); return this; } @@ -210,7 +209,7 @@ public Builder enableTransactionSupport(Boolean enableTransactionSupport){ * * @return {@link Options} 实例 */ - public Options build(){ + public Options build() { return options; } diff --git a/buession-redis/src/main/java/com/buession/redis/core/PoolConfig.java b/buession-redis/src/main/java/com/buession/redis/core/PoolConfig.java index 5b0dd7b0a..ba9122f9d 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/PoolConfig.java +++ b/buession-redis/src/main/java/com/buession/redis/core/PoolConfig.java @@ -19,11 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core; +import com.buession.core.converter.mapper.PropertyMapper; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import java.time.Duration; @@ -576,27 +577,31 @@ public void setMaxIdle(int maxIdle) { * @since 2.3.2 */ public GenericObjectPoolConfig toGenericObjectPoolConfig(final GenericObjectPoolConfig poolConfig) { + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); + poolConfig.setLifo(getLifo()); poolConfig.setFairness(getFairness()); poolConfig.setMaxWait(getMaxWait()); - poolConfig.setMinEvictableIdleTime(getMinEvictableIdleTime()); - poolConfig.setSoftMinEvictableIdleTime(getSoftMinEvictableIdleTime()); - poolConfig.setEvictionPolicyClassName(getEvictionPolicyClassName()); - poolConfig.setEvictorShutdownTimeout(getEvictorShutdownTimeout()); poolConfig.setNumTestsPerEvictionRun(getNumTestsPerEvictionRun()); poolConfig.setTestOnCreate(getTestOnCreate()); poolConfig.setTestOnBorrow(getTestOnBorrow()); poolConfig.setTestOnReturn(getTestOnReturn()); poolConfig.setTestWhileIdle(getTestWhileIdle()); - poolConfig.setTimeBetweenEvictionRuns(getTimeBetweenEvictionRuns()); poolConfig.setBlockWhenExhausted(getBlockWhenExhausted()); poolConfig.setJmxEnabled(getJmxEnabled()); - poolConfig.setJmxNamePrefix(getJmxNamePrefix()); - poolConfig.setJmxNameBase(getJmxNameBase()); poolConfig.setMaxTotal(getMaxTotal()); poolConfig.setMinIdle(getMinIdle()); poolConfig.setMaxIdle(getMaxIdle()); + propertyMapper.from(getMinEvictableIdleTime()).to(poolConfig::setMinEvictableIdleTime); + propertyMapper.from(getSoftMinEvictableIdleTime()).to(poolConfig::setSoftMinEvictableIdleTime); + propertyMapper.from(getEvictorShutdownTimeout()).to(poolConfig::setEvictorShutdownTimeout); + propertyMapper.from(getTimeBetweenEvictionRuns()).to(poolConfig::setTimeBetweenEvictionRuns); + propertyMapper.alwaysApplyingWhenHasText().from(getEvictionPolicyClassName()) + .to(poolConfig::setEvictionPolicyClassName); + propertyMapper.alwaysApplyingWhenHasText().from(getJmxNamePrefix()).to(poolConfig::setJmxNamePrefix); + propertyMapper.alwaysApplyingWhenHasText().from(getJmxNameBase()).to(poolConfig::setJmxNameBase); + return poolConfig; } diff --git a/buession-redis/src/main/java/com/buession/redis/core/RedisNamedNode.java b/buession-redis/src/main/java/com/buession/redis/core/RedisNamedNode.java index 0b7ad8876..98d8738da 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/RedisNamedNode.java +++ b/buession-redis/src/main/java/com/buession/redis/core/RedisNamedNode.java @@ -24,7 +24,7 @@ */ package com.buession.redis.core; -import com.buession.core.NamedNode; +import com.buession.lang.NamedNode; /** * @author Yong.Teng diff --git a/buession-redis/src/main/java/com/buession/redis/core/RedisServerTime.java b/buession-redis/src/main/java/com/buession/redis/core/RedisServerTime.java index c697bd542..596c4ea21 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/RedisServerTime.java +++ b/buession-redis/src/main/java/com/buession/redis/core/RedisServerTime.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core; @@ -33,7 +33,7 @@ /** * @author Yong.Teng */ -public class RedisServerTime implements Serializable { +public final class RedisServerTime implements Serializable { private final static long serialVersionUID = 7818271427941747714L; @@ -41,26 +41,26 @@ public class RedisServerTime implements Serializable { private final long usec; - public RedisServerTime(final Date date, final long usec){ + public RedisServerTime(final Date date, final long usec) { this.date = date; this.usec = usec; } - public Date getDate(){ + public Date getDate() { return date; } - public long getUsec(){ + public long getUsec() { return usec; } @Override - public int hashCode(){ + public int hashCode() { return Objects.hash(date, usec); } @Override - public boolean equals(Object obj){ + public boolean equals(Object obj) { if(this == obj){ return true; } @@ -74,7 +74,7 @@ public boolean equals(Object obj){ } @Override - public String toString(){ + public String toString() { return ObjectStringBuilder.create() .add("date", date) .add("usec", usec) diff --git a/buession-redis/src/main/java/com/buession/redis/core/SessionCallback.java b/buession-redis/src/main/java/com/buession/redis/core/SessionCallback.java index 6ffd41ee2..3887ec8ce 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/SessionCallback.java +++ b/buession-redis/src/main/java/com/buession/redis/core/SessionCallback.java @@ -25,6 +25,7 @@ package com.buession.redis.core; import com.buession.redis.client.RedisClient; +import com.buession.redis.exception.RedisException; /** * @author Yong.Teng @@ -32,4 +33,7 @@ @FunctionalInterface public interface SessionCallback extends com.buession.core.Executor { + @Override + R execute(RedisClient context) throws RedisException; + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/SlotRange.java b/buession-redis/src/main/java/com/buession/redis/core/SlotRange.java index 55affe20a..f63cc4acd 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/SlotRange.java +++ b/buession-redis/src/main/java/com/buession/redis/core/SlotRange.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core; @@ -45,7 +45,7 @@ public class SlotRange implements Serializable { private final Set range; - public SlotRange(int lowerBound, int upperBound){ + public SlotRange(int lowerBound, int upperBound) { this.range = new LinkedHashSet<>(); this.lowerBound = lowerBound; this.upperBound = upperBound; @@ -55,15 +55,15 @@ public SlotRange(int lowerBound, int upperBound){ } } - public boolean contains(int slot){ + public boolean contains(int slot) { return range.contains(slot); } - public Set getSlots(){ + public Set getSlots() { return Collections.unmodifiableSet(range); } - public int[] getSlotsArray(){ + public int[] getSlotsArray() { int[] slots = new int[range.size()]; int pos = 0; @@ -75,12 +75,8 @@ public int[] getSlotsArray(){ } @Override - public String toString(){ - final StringBuilder sb = new StringBuilder(); - - sb.append(lowerBound).append('-').append(upperBound); - - return sb.toString(); + public String toString() { + return String.valueOf(lowerBound) + '-' + upperBound; } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/BitMapCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/BitMapCommands.java index 201340847..0e96d253c 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/BitMapCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/BitMapCommands.java @@ -19,14 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; import com.buession.redis.core.BitCountOption; import com.buession.redis.core.BitOperation; -import com.buession.redis.utils.ObjectStringBuilder; import java.util.List; @@ -168,40 +167,6 @@ public interface BitMapCommands extends RedisCommands { */ List bitField(final byte[] key, final BitFieldArgument argument); - /** - * 可以将一个 Redis 字符串看作是一个由二进制位组成的数组,并对这个数组中储存的长度不同的整数进行访问; - * 可以在一次调用中同时对多个位范围进行操作, - * 它接受一系列待执行的操作作为参数,并返回一个数组作为回复,数组中的每个元素就是对应操作的执行结果 - * - *

详情说明 http://redisdoc.com/bitmap/bitfield.html

- * - * @param key - * Key - * @param arguments - * 命令参数 - * - * @return 返回值是一个数组,数组中的每个元素对应一个被执行的子命令 - */ - @Deprecated - List bitField(final String key, final String... arguments); - - /** - * 可以将一个 Redis 字符串看作是一个由二进制位组成的数组,并对这个数组中储存的长度不同的整数进行访问; - * 可以在一次调用中同时对多个位范围进行操作, - * 它接受一系列待执行的操作作为参数,并返回一个数组作为回复,数组中的每个元素就是对应操作的执行结果 - * - *

详情说明 http://redisdoc.com/bitmap/bitfield.html

- * - * @param key - * Key - * @param arguments - * 命令参数 - * - * @return 返回值是一个数组,数组中的每个元素对应一个被执行的子命令 - */ - @Deprecated - List bitField(final byte[] key, final byte[]... arguments); - /** * 可以将一个 Redis 字符串看作是一个由二进制位组成的数组,并对这个数组中储存的长度不同的整数进行访问; * 可以在一次调用中同时对多个位范围进行操作, diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/CommandArguments.java b/buession-redis/src/main/java/com/buession/redis/core/command/CommandArguments.java index 24adb4dee..027b2a0df 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/CommandArguments.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/CommandArguments.java @@ -19,66 +19,446 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; -import com.buession.core.collect.Arrays; +import com.buession.core.utils.StringUtils; import com.buession.core.validator.Validate; import com.buession.lang.Constants; -import java.util.LinkedHashMap; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import java.util.Map; -import java.util.Optional; /** * @author Yong.Teng */ public final class CommandArguments { - private final static String NIL = ""; - - private final Map parameters = new LinkedHashMap<>(); + private final List parameters = new ArrayList<>(); private CommandArguments() { } - private CommandArguments(final String key, final Object value) { - put(key, value); + private CommandArguments(final byte[] value) { + add(value); + } + + private CommandArguments(final char value) { + add(value); + } + + private CommandArguments(final short value) { + add(value); + } + + private CommandArguments(final int value) { + add(value); + } + + private CommandArguments(final long value) { + add(value); + } + + private CommandArguments(final float value) { + add(value); + } + + private CommandArguments(final double value) { + add(value); } - private CommandArguments(final String key, final Object... values) { - put(key, values); + private CommandArguments(final boolean value) { + add(value); + } + + private CommandArguments(final String value) { + add(value); + } + + private CommandArguments(final Collection value) { + add(value); + } + + private CommandArguments(final Map value) { + add(value); + } + + private CommandArguments(final Object value) { + add(value); + } + + private CommandArguments(final byte[]... values) { + add(values); + } + + private CommandArguments(final char... values) { + add(values); + } + + private CommandArguments(final short... values) { + add(values); + } + + private CommandArguments(final int... values) { + add(values); + } + + private CommandArguments(final long... values) { + add(values); + } + + private CommandArguments(final float... values) { + add(values); + } + + private CommandArguments(final double... values) { + add(values); + } + + private CommandArguments(final boolean... values) { + add(values); + } + + private CommandArguments(final String... values) { + add(values); + } + + private CommandArguments(final Collection... values) { + add(values); + } + + private CommandArguments(final Map... values) { + add(values); + } + + private CommandArguments(final Object... values) { + add(values); } public static CommandArguments create() { return new CommandArguments(); } + public static CommandArguments create(final byte[] value) { + return new CommandArguments(value); + } + + public static CommandArguments create(final char value) { + return new CommandArguments(value); + } + + public static CommandArguments create(final short value) { + return new CommandArguments(value); + } + + public static CommandArguments create(final int value) { + return new CommandArguments(value); + } + + public static CommandArguments create(final long value) { + return new CommandArguments(value); + } + + public static CommandArguments create(final float value) { + return new CommandArguments(value); + } + + public static CommandArguments create(final double value) { + return new CommandArguments(value); + } + + public static CommandArguments create(final boolean value) { + return new CommandArguments(value); + } + + public static CommandArguments create(final String value) { + return new CommandArguments(value); + } + + public static CommandArguments create(final Collection value) { + return new CommandArguments(value); + } + + public static CommandArguments create(final Map value) { + return new CommandArguments(value); + } + + public static CommandArguments create(final Object value) { + return new CommandArguments(value); + } + + public static CommandArguments create(final byte[]... values) { + return new CommandArguments(values); + } + + public static CommandArguments create(final char... values) { + return new CommandArguments(values); + } + + public static CommandArguments create(final short... values) { + return new CommandArguments(values); + } + + public static CommandArguments create(final int... values) { + return new CommandArguments(values); + } + + public static CommandArguments create(final long... values) { + return new CommandArguments(values); + } + + public static CommandArguments create(final float... values) { + return new CommandArguments(values); + } + + public static CommandArguments create(final double... values) { + return new CommandArguments(values); + } + + public static CommandArguments create(final boolean... values) { + return new CommandArguments(values); + } + + public static CommandArguments create(final String... values) { + return new CommandArguments(values); + } + + public static CommandArguments create(final Collection... values) { + return new CommandArguments(values); + } + + public static CommandArguments create(final Map... values) { + return new CommandArguments(values); + } + + public static CommandArguments create(final Object... values) { + return new CommandArguments(values); + } + + @Deprecated public static CommandArguments create(final String key, final Object value) { - return new CommandArguments(key, value); + return new CommandArguments(value); } + @Deprecated public static CommandArguments create(final String key, final Object... values) { - return new CommandArguments(key, values); + return new CommandArguments(values); } - public CommandArguments put(final String key, final Object value) { - parameters.put(key, Optional.ofNullable(value).orElse(NIL)); + public CommandArguments add(final byte[] value) { + if(value != null){ + parameters.add(value); + } + return this; } - public CommandArguments put(final String key, final Object... values) { - parameters.put(key, values == null ? NIL : Arrays.toString(values)); + public CommandArguments add(final char value) { + parameters.add(value); + return this; + } + + public CommandArguments add(final short value) { + parameters.add(value); + return this; + } + + public CommandArguments add(final int value) { + parameters.add(value); + return this; + } + + public CommandArguments add(final long value) { + parameters.add(value); + return this; + } + + public CommandArguments add(final float value) { + parameters.add(value); + return this; + } + + public CommandArguments add(final double value) { + parameters.add(value); + return this; + } + + public CommandArguments add(final boolean value) { + parameters.add(value ? "1" : "0"); + return this; + } + + public CommandArguments add(final String value) { + if(value != null){ + parameters.add(value); + } + + return this; + } + + public CommandArguments add(final Collection value) { + if(value != null){ + value.forEach(this::add); + } + + return this; + } + + public CommandArguments add(final Map value) { + if(value != null){ + value.forEach(this::add); + } + + return this; + } + + public CommandArguments add(final Object value) { + if(value != null){ + parameters.add(value); + } + + return this; + } + + public CommandArguments add(final byte[]... values) { + if(Validate.isNotEmpty(values)){ + for(Object value : values){ + add(value); + } + } + + return this; + } + + public CommandArguments add(final char... values) { + if(Validate.isNotEmpty(values)){ + for(Object value : values){ + add(value); + } + } + + return this; + } + + public CommandArguments add(final short... values) { + if(Validate.isNotEmpty(values)){ + for(Object value : values){ + add(value); + } + } + + return this; + } + + public CommandArguments add(final int... values) { + if(Validate.isNotEmpty(values)){ + for(Object value : values){ + add(value); + } + } + + return this; + } + + public CommandArguments add(final long... values) { + if(Validate.isNotEmpty(values)){ + for(Object value : values){ + add(value); + } + } + + return this; + } + + public CommandArguments add(final float... values) { + if(Validate.isNotEmpty(values)){ + for(Object value : values){ + add(value); + } + } + + return this; + } + + public CommandArguments add(final double... values) { + if(Validate.isNotEmpty(values)){ + for(Object value : values){ + add(value); + } + } + return this; } - public Map getParameters() { + public CommandArguments add(final boolean... values) { + if(Validate.isNotEmpty(values)){ + for(Object value : values){ + add(value); + } + } + + return this; + } + + public CommandArguments add(final String... values) { + if(Validate.isNotEmpty(values)){ + for(Object value : values){ + add(value); + } + } + + return this; + } + + public CommandArguments add(final Collection... values) { + if(Validate.isNotEmpty(values)){ + for(Object value : values){ + add(value); + } + } + + return this; + } + + public CommandArguments add(final Map... values) { + if(Validate.isNotEmpty(values)){ + for(Object value : values){ + add(value); + } + } + + return this; + } + + public CommandArguments add(final Object... values) { + if(Validate.isNotEmpty(values)){ + for(Object value : values){ + add(value); + } + } + + return this; + } + + @Deprecated + public CommandArguments put(final String key, final Object value) { + return add(value); + } + + @Deprecated + public CommandArguments put(final String key, final Object... values) { + return add(values); + } + + public List getParameters() { return parameters; } - public Map build() { + public List build() { return getParameters(); } @@ -86,17 +466,7 @@ public String asString() { if(Validate.isEmpty(getParameters())){ return Constants.EMPTY_STRING; }else{ - final StringBuilder sb = new StringBuilder(getParameters().size() * 8); - - getParameters().forEach((name, value)->{ - if(sb.length() > 0){ - sb.append(", "); - } - - sb.append(name).append(" => ").append(value); - }); - - return sb.toString(); + return StringUtils.join(getParameters(), " "); } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/GenericCommand.java b/buession-redis/src/main/java/com/buession/redis/core/command/GenericCommand.java new file mode 100644 index 000000000..1c9af25f7 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/command/GenericCommand.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.command; + +import com.buession.lang.KeyValue; + +/** + * 一般命令 + * + *

详情说明 https://redis.io/docs/latest/commands/?group=generic

+ * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface GenericCommand extends RedisCommands { + + /** + * 阻塞当前客户端,直到所有以前的写命令都成功的传输和指定的slaves确认 + * + *

详情说明 http://www.redis.cn/commands/wait.html

+ * + * @param replicas + * 副本数量 + * @param timeout + * 超时(单位:毫秒) + * + * @return The number of replicas reached by all the writes performed in the context of the current connection. + */ + Long wait(final int replicas, final int timeout); + + /** + * Return the number of masters and replicas that have fsynced all write commands sent by the current client + * before the {@code WAITAOF} command, both in the case where the specified thresholds were met, and when the + * timeout is reached. + * + *

详情说明 https://redis.io/docs/latest/commands/waitaof/

+ * + * @param locals + * - + * @param replicas + * 副本数量 + * @param timeout + * 超时(单位:毫秒) + * + * @return The number of masters and replicas that have fsynced all write commands sent by the current client + * before the {@code WAITAOF} command, both in the case where the specified thresholds were met, and when the + * timeout is reached. + * + * @since 3.0.0 + */ + KeyValue waitOf(final int locals, final int replicas, final int timeout); + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/KeyCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/KeyCommands.java index 11287affe..d7b12f532 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/KeyCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/KeyCommands.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; @@ -1373,20 +1373,6 @@ Status migrate(final String host, final int port, final int db, final byte[] use */ Long unlink(final byte[]... keys); - /** - * 阻塞当前客户端,直到所有以前的写命令都成功的传输和指定的slaves确认 - * - *

详情说明 http://www.redis.cn/commands/wait.html

- * - * @param replicas - * 副本数量 - * @param timeout - * 超时(单位:毫秒) - * - * @return 被删除 key 的数量 - */ - Long wait(final int replicas, final int timeout); - /** * 返回指定 key 对应 value 所使用的内部表示 * diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/ProtocolCommand.java b/buession-redis/src/main/java/com/buession/redis/core/command/ProtocolCommand.java index e61a0835a..d66003413 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/ProtocolCommand.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/ProtocolCommand.java @@ -271,8 +271,6 @@ public enum ProtocolCommand { UNLINK(ProtocolCommandGroup.KEY), - WAIT(ProtocolCommandGroup.KEY), - OBJECT_ENCODING(ProtocolCommandGroup.KEY), OBJECT_REFQ(ProtocolCommandGroup.KEY), @@ -280,7 +278,13 @@ public enum ProtocolCommand { OBJECT_IDLETIME(ProtocolCommandGroup.KEY), OBJECT_REFCOUNT(ProtocolCommandGroup.KEY), - /** key command end **/ + /** + * key command end + **/ + + WAIT(ProtocolCommandGroup.GENERIC), + + WAITOF(ProtocolCommandGroup.GENERIC), /** * list command start @@ -687,16 +691,16 @@ public enum ProtocolCommand { private final ProtocolCommandGroup group; - ProtocolCommand(final ProtocolCommandGroup group){ + ProtocolCommand(final ProtocolCommandGroup group) { this.group = group; } - public ProtocolCommandGroup getGroup(){ + public ProtocolCommandGroup getGroup() { return group; } @Override - public String toString(){ + public String toString() { return StringUtils.replace(name(), "_", " "); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/ProtocolCommandGroup.java b/buession-redis/src/main/java/com/buession/redis/core/command/ProtocolCommandGroup.java index 31431f54e..8ff196b96 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/ProtocolCommandGroup.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/ProtocolCommandGroup.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; @@ -46,6 +46,13 @@ public enum ProtocolCommandGroup { */ CONNECTION("Connection"), + /** + * 一般命令 + * + * @since 3.0.0 + */ + GENERIC("Generic"), + /** * 地理位置命令 */ diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/PubSubCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/PubSubCommands.java index c04fbefa5..ab774318b 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/PubSubCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/PubSubCommands.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2020 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/ScriptingCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/ScriptingCommands.java index 334be85b1..184a81a1a 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/ScriptingCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/ScriptingCommands.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2020 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/ServerCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/ServerCommands.java index c8b753d08..fe3f4bb3f 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/ServerCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/ServerCommands.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; @@ -37,6 +37,7 @@ import com.buession.redis.core.AclUser; import java.util.List; +import java.util.Map; /** * 服务端命令 @@ -277,7 +278,7 @@ public interface ServerCommands extends RedisCommands { /** * 动态地调整 Redis 服务器的配置 * - *

详情说明 http://redisdoc.com/configure/config_set.html

+ *

详情说明 https://www.redisio.com/commands/Config-Set.html

* * @param parameter * 配置项 @@ -288,29 +289,43 @@ public interface ServerCommands extends RedisCommands { */ Status configSet(final byte[] parameter, final byte[] value); + /** + * 批量动态地调整 Redis 服务器的配置 + * + *

详情说明 https://www.redisio.com/commands/Config-Set.html

+ * + * @param configs + * 配置 + * + * @return 设置成功时返回,返回 Status.SUCCESS;否则,返回 Status.FAILURE + * + * @since 3.0.0 + */ + Status configSet(final Map configs); + /** * 获取 Redis 服务器的配置参数 * - *

详情说明 http://redisdoc.com/configure/config_get.html

+ *

详情说明 https://www.redisio.com/commands/Config-Get.html

* - * @param parameter + * @param pattern * 配置项 * * @return 给定配置参数的值 */ - List configGet(final String parameter); + Map configGet(final String pattern); /** * 获取 Redis 服务器的配置参数 * - *

详情说明 http://redisdoc.com/configure/config_get.html

+ *

详情说明 https://www.redisio.com/commands/Config-Get.html

* - * @param parameter + * @param pattern * 配置项 * * @return 给定配置参数的值 */ - List configGet(final byte[] parameter); + Map configGet(final byte[] pattern); /** * 重置 INFO 命令中的某些统计数据,包括: @@ -711,7 +726,7 @@ public interface ServerCommands extends RedisCommands { * * @return 实例在复制中担任的角色信息 */ - List role(); + Role role(); /** * 执行一个同步保存操作,将当前 Redis 实例的所有数据快照(snapshot)以 RDB 文件的形式保存到硬盘; diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/SortedSetCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/SortedSetCommands.java index 97389b1d2..906c6df87 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/SortedSetCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/SortedSetCommands.java @@ -19,14 +19,14 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; +import com.buession.lang.KeyValue; import com.buession.redis.core.Aggregate; import com.buession.redis.core.GtLt; -import com.buession.redis.core.KeyedZSetElement; import com.buession.redis.core.NxXx; import com.buession.redis.core.ScanResult; import com.buession.redis.core.Tuple; @@ -34,7 +34,6 @@ import java.util.List; import java.util.Map; -import java.util.Set; /** * 有序集合命令 @@ -154,7 +153,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 元素 key 名称,成员名称,元素分数 */ - KeyedZSetElement bzPopMin(final String[] keys, final int timeout); + KeyValue bzPopMin(final String[] keys, final int timeout); /** * 从非空的第一个有序集中弹出得分最小的成员,按照命令中 key 出现的顺序检查;是有序集 ZPOPMIN 的阻塞变体; @@ -169,7 +168,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 元素 key 名称,成员名称,元素分数 */ - KeyedZSetElement bzPopMin(final byte[][] keys, final int timeout); + KeyValue bzPopMin(final byte[][] keys, final int timeout); /** * 从非空的第一个有序集中弹出得分最高的成员,按照命令中 key 出现的顺序检查;是有序集 ZPOPMAX 的阻塞变体; @@ -184,7 +183,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 元素 key 名称,成员名称,元素分数 */ - KeyedZSetElement bzPopMax(final String[] keys, final int timeout); + KeyValue bzPopMax(final String[] keys, final int timeout); /** * 从非空的第一个有序集中弹出得分最高的成员,按照命令中 key 出现的顺序检查;是有序集 ZPOPMAX 的阻塞变体; @@ -199,7 +198,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 元素 key 名称,成员名称,元素分数 */ - KeyedZSetElement bzPopMax(final byte[][] keys, final int timeout); + KeyValue bzPopMax(final byte[][] keys, final int timeout); /** * 将一个或多个 member 元素及其 score 值加入到有序集 key 当中 @@ -583,6 +582,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return score 值在 min 和 max 之间的成员的数量 */ + @Deprecated Long zCount(final String key, final String min, final String max); /** @@ -599,6 +599,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return score 值在 min 和 max 之间的成员的数量 */ + @Deprecated Long zCount(final byte[] key, final byte[] min, final byte[] max); /** @@ -611,7 +612,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return The result of the difference */ - Set zDiff(final String... keys); + List zDiff(final String... keys); /** * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client @@ -623,7 +624,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return The result of the difference */ - Set zDiff(final byte[]... keys); + List zDiff(final byte[]... keys); /** * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client @@ -635,7 +636,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return The result of the difference with their scores */ - Set zDiffWithScores(final String... keys); + List zDiffWithScores(final String... keys); /** * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client @@ -647,7 +648,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return The result of the difference with their scores */ - Set zDiffWithScores(final byte[]... keys); + List zDiffWithScores(final byte[]... keys); /** * Computes the difference between the first and all successive input sorted sets and stores the result in destination @@ -719,7 +720,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 有序集合的交集 */ - Set zInter(final String... keys); + List zInter(final String... keys); /** * 计算给定的一个或多个有序集合的交集 @@ -731,7 +732,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 有序集合的交集 */ - Set zInter(final byte[]... keys); + List zInter(final byte[]... keys); /** * 计算给定的一个或多个有序集合的交集 @@ -745,7 +746,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 有序集合的交集 */ - Set zInter(final String[] keys, final Aggregate aggregate); + List zInter(final String[] keys, final Aggregate aggregate); /** * 计算给定的一个或多个有序集合的交集 @@ -759,7 +760,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 有序集合的交集 */ - Set zInter(final byte[][] keys, final Aggregate aggregate); + List zInter(final byte[][] keys, final Aggregate aggregate); /** * 计算给定的一个或多个有序集合的交集 @@ -773,7 +774,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 有序集合的交集 */ - Set zInter(final String[] keys, final double... weights); + List zInter(final String[] keys, final double... weights); /** * 计算给定的一个或多个有序集合的交集 @@ -787,7 +788,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 有序集合的交集 */ - Set zInter(final byte[][] keys, final double... weights); + List zInter(final byte[][] keys, final double... weights); /** * 计算给定的一个或多个有序集合的交集 @@ -803,7 +804,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 有序集合的交集 */ - Set zInter(final String[] keys, final Aggregate aggregate, final double... weights); + List zInter(final String[] keys, final Aggregate aggregate, final double... weights); /** * 计算给定的一个或多个有序集合的交集 @@ -819,7 +820,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 有序集合的交集 */ - Set zInter(final byte[][] keys, final Aggregate aggregate, final double... weights); + List zInter(final byte[][] keys, final Aggregate aggregate, final double... weights); /** * 计算给定的一个或多个有序集合的交集 @@ -831,7 +832,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 含 scores 的有序集合的交集 */ - Set zInterWithScores(final String... keys); + List zInterWithScores(final String... keys); /** * 计算给定的一个或多个有序集合的交集 @@ -843,7 +844,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 含 scores 的有序集合的交集 */ - Set zInterWithScores(final byte[]... keys); + List zInterWithScores(final byte[]... keys); /** * 计算给定的一个或多个有序集合的交集 @@ -857,7 +858,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 含 scores 的有序集合的交集 */ - Set zInterWithScores(final String[] keys, final Aggregate aggregate); + List zInterWithScores(final String[] keys, final Aggregate aggregate); /** * 计算给定的一个或多个有序集合的交集 @@ -871,7 +872,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 含 scores 的有序集合的交集 */ - Set zInterWithScores(final byte[][] keys, final Aggregate aggregate); + List zInterWithScores(final byte[][] keys, final Aggregate aggregate); /** * 计算给定的一个或多个有序集合的交集 @@ -885,7 +886,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 含 scores 的有序集合的交集 */ - Set zInterWithScores(final String[] keys, final double... weights); + List zInterWithScores(final String[] keys, final double... weights); /** * 计算给定的一个或多个有序集合的交集 @@ -899,7 +900,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 含 scores 的有序集合的交集 */ - Set zInterWithScores(final byte[][] keys, final double... weights); + List zInterWithScores(final byte[][] keys, final double... weights); /** * 计算给定的一个或多个有序集合的交集 @@ -915,7 +916,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 含 scores 的有序集合的交集 */ - Set zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights); + List zInterWithScores(final String[] keys, final Aggregate aggregate, final double... weights); /** * 计算给定的一个或多个有序集合的交集 @@ -931,7 +932,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 含 scores 的有序集合的交集 */ - Set zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights); + List zInterWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights); /** * 计算给定的一个或多个有序集的交集,并将该交集储存到 destKey 中 @@ -1107,6 +1108,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 集合 Key 中,成员介于 min 和 max 范围内的元素数量 */ + @Deprecated Long zLexCount(final String key, final String min, final String max); /** @@ -1123,6 +1125,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 集合 Key 中,成员介于 min 和 max 范围内的元素数量 */ + @Deprecated Long zLexCount(final byte[] key, final byte[] min, final byte[] max); /** @@ -1362,6 +1365,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 包含了有序集合在指定范围内的成员的列表 */ + @Deprecated List zRangeByLex(final String key, final String min, final String max); /** @@ -1379,6 +1383,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 包含了有序集合在指定范围内的成员的列表 */ + @Deprecated List zRangeByLex(final byte[] key, final byte[] min, final byte[] max); /** @@ -1442,6 +1447,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 包含了有序集合在指定范围内从 offset 开始的 count 个成员的列表 */ + @Deprecated List zRangeByLex(final String key, final String min, final String max, final long offset, final long count); /** @@ -1463,6 +1469,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 包含了有序集合在指定范围内从 offset 开始的 count 个成员的列表 */ + @Deprecated List zRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, final long count); /** @@ -1514,6 +1521,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 指定区间内,有序集成员的列表 */ + @Deprecated List zRangeByScore(final String key, final String min, final String max); /** @@ -1532,6 +1540,7 @@ public interface SortedSetCommands extends RedisCommands { * * @return 指定区间内,有序集成员的列表 */ + @Deprecated List zRangeByScore(final byte[] key, final byte[] min, final byte[] max); /** @@ -1597,6 +1606,7 @@ List zRangeByScore(final byte[] key, final double min, final double max, * * @return 指定区间内从 offset 开是的 count 个,有序集成员的列表 */ + @Deprecated List zRangeByScore(final String key, final String min, final String max, final long offset, final long count); @@ -1619,6 +1629,7 @@ List zRangeByScore(final String key, final String min, final String max, * * @return 指定区间内从 offset 开是的 count 个,有序集成员的列表 */ + @Deprecated List zRangeByScore(final byte[] key, final byte[] min, final byte[] max, final long offset, final long count); @@ -1671,6 +1682,7 @@ List zRangeByScore(final byte[] key, final byte[] min, final byte[] max, * * @return 指定区间内,带有 score 的有序集成员的列表 */ + @Deprecated List zRangeByScoreWithScores(final String key, final String min, final String max); /** @@ -1688,6 +1700,7 @@ List zRangeByScore(final byte[] key, final byte[] min, final byte[] max, * * @return 指定区间内,带有 score 的有序集成员的列表 */ + @Deprecated List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max); /** @@ -1753,6 +1766,7 @@ List zRangeByScoreWithScores(final byte[] key, final double min, final do * * @return 指定区间内带有 score 的从 offset 开是的 count 个,有序集成员的列表 */ + @Deprecated List zRangeByScoreWithScores(final String key, final String min, final String max, final long offset, final long count); @@ -1775,6 +1789,7 @@ List zRangeByScoreWithScores(final String key, final String min, final St * * @return 指定区间内带有 score 的从 offset 开是的 count 个,有序集成员的列表 */ + @Deprecated List zRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max, final long offset, final long count); @@ -2244,6 +2259,7 @@ Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final * * @return 被移除的元素数量 */ + @Deprecated Long zRemRangeByLex(final String key, final String min, final String max); /** @@ -2260,6 +2276,7 @@ Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final * * @return 被移除的元素数量 */ + @Deprecated Long zRemRangeByLex(final byte[] key, final byte[] min, final byte[] max); /** @@ -2308,6 +2325,7 @@ Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final * * @return 被移除成员的数量 */ + @Deprecated Long zRemRangeByScore(final String key, final String min, final String max); /** @@ -2324,6 +2342,7 @@ Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final * * @return 被移除成员的数量 */ + @Deprecated Long zRemRangeByScore(final byte[] key, final byte[] min, final byte[] max); /** @@ -2489,6 +2508,7 @@ Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final * * @return 包含了有序集合在指定范围内的成员列表 */ + @Deprecated List zRevRangeByLex(final String key, final String min, final String max); /** @@ -2506,6 +2526,7 @@ Long zRangeStore(final byte[] destKey, final byte[] key, final long start, final * * @return 包含了有序集合在指定范围内的成员列表 */ + @Deprecated List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max); /** @@ -2571,6 +2592,7 @@ List zRevRangeByLex(final byte[] key, final double min, final double max * * @return 包含了有序集合在指定范围内的成员列表 */ + @Deprecated List zRevRangeByLex(final String key, final String min, final String max, final long offset, final long count); @@ -2593,6 +2615,7 @@ List zRevRangeByLex(final String key, final String min, final String max * * @return 包含了有序集合在指定范围内的成员列表 */ + @Deprecated List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max, final long offset, final long count); @@ -2648,6 +2671,7 @@ List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max * * @return 指定区间内,有序集成员的列表 */ + @Deprecated List zRevRangeByScore(final String key, final String min, final String max); /** @@ -2666,6 +2690,7 @@ List zRevRangeByLex(final byte[] key, final byte[] min, final byte[] max * * @return 指定区间内,有序集成员的列表 */ + @Deprecated List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max); /** @@ -2734,6 +2759,7 @@ List zRevRangeByScore(final byte[] key, final double min, final double m * * @return 指定区间内,有序集成员的列表 */ + @Deprecated List zRevRangeByScore(final String key, final String min, final String max, final long offset, final long count); @@ -2757,6 +2783,7 @@ List zRevRangeByScore(final String key, final String min, final String m * * @return 指定区间内,有序集成员的列表 */ + @Deprecated List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] max, final long offset, final long count); @@ -2812,6 +2839,7 @@ List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] m * * @return 指定区间内,有序集成员的列表 */ + @Deprecated List zRevRangeByScoreWithScores(final String key, final String min, final String max); /** @@ -2830,6 +2858,7 @@ List zRevRangeByScore(final byte[] key, final byte[] min, final byte[] m * * @return 指定区间内,有序集成员的列表 */ + @Deprecated List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max); /** @@ -2898,6 +2927,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final double min, final * * @return 指定区间内,有序集成员的列表 */ + @Deprecated List zRevRangeByScoreWithScores(final String key, final String min, final String max, final long offset, final long count); @@ -2921,6 +2951,7 @@ List zRevRangeByScoreWithScores(final String key, final String min, final * * @return 指定区间内,有序集成员的列表 */ + @Deprecated List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final byte[] max, final long offset, final long count); @@ -3248,7 +3279,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 集合的并集 */ - Set zUnion(final String... keys); + List zUnion(final String... keys); /** * 计算给定的一个或多个有序集的并集 @@ -3260,7 +3291,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 集合的并集 */ - Set zUnion(final byte[]... keys); + List zUnion(final byte[]... keys); /** * 计算给定的一个或多个有序集的并集 @@ -3274,7 +3305,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 集合的并集 */ - Set zUnion(final String[] keys, final Aggregate aggregate); + List zUnion(final String[] keys, final Aggregate aggregate); /** * 计算给定的一个或多个有序集的并集 @@ -3288,7 +3319,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 集合的并集 */ - Set zUnion(final byte[][] keys, final Aggregate aggregate); + List zUnion(final byte[][] keys, final Aggregate aggregate); /** * 计算给定的一个或多个有序集的并集 @@ -3302,7 +3333,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 集合的并集 */ - Set zUnion(final String[] keys, final double... weights); + List zUnion(final String[] keys, final double... weights); /** * 计算给定的一个或多个有序集的并集 @@ -3316,7 +3347,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 集合的并集 */ - Set zUnion(final byte[][] keys, final double... weights); + List zUnion(final byte[][] keys, final double... weights); /** * 计算给定的一个或多个有序集的并集 @@ -3332,7 +3363,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 集合的并集 */ - Set zUnion(final String[] keys, final Aggregate aggregate, final double... weights); + List zUnion(final String[] keys, final Aggregate aggregate, final double... weights); /** * 计算给定的一个或多个有序集的并集 @@ -3348,7 +3379,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 集合的并集 */ - Set zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights); + List zUnion(final byte[][] keys, final Aggregate aggregate, final double... weights); /** * 计算给定的一个或多个有序集的并集 @@ -3360,7 +3391,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 带有分数的集合的并集 */ - Set zUnionWithScores(final String... keys); + List zUnionWithScores(final String... keys); /** * 计算给定的一个或多个有序集的并集 @@ -3372,7 +3403,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 带有分数的集合的并集 */ - Set zUnionWithScores(final byte[]... keys); + List zUnionWithScores(final byte[]... keys); /** * 计算给定的一个或多个有序集的并集 @@ -3386,7 +3417,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 带有分数的集合的并集 */ - Set zUnionWithScores(final String[] keys, final Aggregate aggregate); + List zUnionWithScores(final String[] keys, final Aggregate aggregate); /** * 计算给定的一个或多个有序集的并集 @@ -3400,7 +3431,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 带有分数的集合的并集 */ - Set zUnionWithScores(final byte[][] keys, final Aggregate aggregate); + List zUnionWithScores(final byte[][] keys, final Aggregate aggregate); /** * 计算给定的一个或多个有序集的并集 @@ -3414,7 +3445,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 带有分数的集合的并集 */ - Set zUnionWithScores(final String[] keys, final double... weights); + List zUnionWithScores(final String[] keys, final double... weights); /** * 计算给定的一个或多个有序集的并集 @@ -3428,7 +3459,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 带有分数的集合的并集 */ - Set zUnionWithScores(final byte[][] keys, final double... weights); + List zUnionWithScores(final byte[][] keys, final double... weights); /** * 计算给定的一个或多个有序集的并集 @@ -3444,7 +3475,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 带有分数的集合的并集 */ - Set zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights); + List zUnionWithScores(final String[] keys, final Aggregate aggregate, final double... weights); /** * 计算给定的一个或多个有序集的并集 @@ -3460,7 +3491,7 @@ List zRevRangeByScoreWithScores(final byte[] key, final byte[] min, final * * @return 带有分数的集合的并集 */ - Set zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights); + List zUnionWithScores(final byte[][] keys, final Aggregate aggregate, final double... weights); /** * 计算给定的一个或多个有序集的并集,并将该并集储存到 destKey diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/StreamCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/StreamCommands.java index b238b5286..5a933a6eb 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/StreamCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/StreamCommands.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; @@ -1960,6 +1960,8 @@ class XTrimArgument { private String minId; + private Long limit; + private XTrimArgument() { } @@ -1979,13 +1981,18 @@ public String getMinId() { return minId; } + public Long getLimit() { + return limit; + } + @Override public String toString() { return ObjectStringBuilder.create(). add("maxLen", maxLen). add("approximateTrimming", approximateTrimming). add("exactTrimming", exactTrimming). - add("minId", minId).build(); + add("minId", minId). + add("limit", limit).build(); } public final static class Builder { @@ -2019,6 +2026,11 @@ public Builder minId(String minId) { return this; } + public Builder limit(long limit) { + xTrimArgument.limit = limit; + return this; + } + public XTrimArgument build() { return xTrimArgument; } diff --git a/buession-redis/src/main/java/com/buession/redis/core/command/TransactionCommands.java b/buession-redis/src/main/java/com/buession/redis/core/command/TransactionCommands.java index 74e8567eb..6d2dae7e6 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/command/TransactionCommands.java +++ b/buession-redis/src/main/java/com/buession/redis/core/command/TransactionCommands.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.command; @@ -38,13 +38,11 @@ public interface TransactionCommands extends RedisCommands { /** - * 标记事务开始 - * - *

详情说明 http://redisdoc.com/transaction/multi.html

+ * 取消事务,放弃执行事务块内的所有命令 * - * @return 开启事务状态 + *

详情说明 http://redisdoc.com/transaction/discard.html

*/ - Status multi(); + void discard(); /** * 执行所有事务块内的命令 @@ -56,11 +54,24 @@ public interface TransactionCommands extends RedisCommands { List exec(); /** - * 取消事务,放弃执行事务块内的所有命令 + * 标记事务开始 * - *

详情说明 http://redisdoc.com/transaction/discard.html

+ *

详情说明 http://redisdoc.com/transaction/multi.html

+ * + * @return 开启事务状态 */ - void discard(); + Status multi(); + + /** + * 取消 WATCH 命令对所有 key 的监视; + * 如果在执行 WATCH 命令之后, EXEC 命令或 DISCARD 命令先被执行了的话,那么就不需要再执行 UNWATCH 了 + * + *

详情说明 http://redisdoc + * .com/transaction/unwatch.html

+ * + * @return 总是返回 Status.SUCCESS + */ + Status unwatch(); /** * 监视一个或多个 key ,如果在事务执行之前这个或这些 key 被其他命令所改动,那么事务将被打断 @@ -86,15 +97,4 @@ public interface TransactionCommands extends RedisCommands { */ Status watch(final byte[]... keys); - /** - * 取消 WATCH 命令对所有 key 的监视; - * 如果在执行 WATCH 命令之后, EXEC 命令或 DISCARD 命令先被执行了的话,那么就不需要再执行 UNWATCH 了 - * - *

详情说明 http://redisdoc - * .com/transaction/unwatch.html

- * - * @return 总是返回 Status.SUCCESS - */ - Status unwatch(); - } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/AbstractRedisOperationsCommand.java b/buession-redis/src/main/java/com/buession/redis/core/internal/AbstractRedisOperationsCommand.java index 94e5159c0..f5fbe9793 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/AbstractRedisOperationsCommand.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/AbstractRedisOperationsCommand.java @@ -19,35 +19,47 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal; +import com.buession.core.converter.Converter; import com.buession.redis.client.RedisClient; import com.buession.redis.client.connection.RedisConnection; import com.buession.redis.core.AbstractRedisCommand; import com.buession.redis.core.command.ProtocolCommand; +import com.buession.redis.exception.RedisException; /** + * Redis 运算命令抽象类 + * * @author Yong.Teng * @since 2.3.0 */ -public abstract class AbstractRedisOperationsCommand - extends AbstractRedisCommand { +public abstract class AbstractRedisOperationsCommand extends AbstractRedisCommand { - protected CONN connection; + protected final CONN connection; - protected Runner runner; + protected final Executor executor; - protected Runner pipelineRunner; + protected final Converter converter; - protected Runner transactionRunner; + @SuppressWarnings({"unchecked"}) + public AbstractRedisOperationsCommand(final CLIENT client, final ProtocolCommand command) { + this(client, command, null, (value)->(R) value); + } @SuppressWarnings({"unchecked"}) - public AbstractRedisOperationsCommand(final CLIENT client, final ProtocolCommand command){ + public AbstractRedisOperationsCommand(final CLIENT client, final ProtocolCommand command, + final Executor executor, final Converter converter) { super(client, command); connection = (CONN) client.getConnection(); + this.executor = executor; + this.converter = converter; } + protected abstract R doExecute() throws RedisException; + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/Converters.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/Converters.java index 38c0507fc..fb1e2f114 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/Converters.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/Converters.java @@ -19,60 +19,59 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert; -import com.buession.core.converter.ArrayConverter; -import com.buession.core.converter.BinaryEnumConverter; -import com.buession.core.converter.BooleanStatusConverter; import com.buession.core.converter.Converter; -import com.buession.core.converter.EnumConverter; import com.buession.core.converter.ListConverter; +import com.buession.core.converter.ListSetConverter; import com.buession.core.converter.MapConverter; -import com.buession.core.converter.PredicateStatusConverter; -import com.buession.redis.core.ObjectEncoding; -import com.buession.redis.core.Type; +import com.buession.core.converter.SetConverter; import com.buession.redis.utils.SafeEncoder; /** * @author Yong.Teng - * @since 2.0.0 + * @since 3.0.0 */ public interface Converters { - Converter STRING_TO_BINARY_CONVERTER = SafeEncoder::encode; + static ListConverter listStringToBinary() { + return new ListConverter<>(SafeEncoder::encode); + } - Converter BINARY_TO_STRING_CONVERTER = SafeEncoder::encode; + static ListConverter listBinaryToString() { + return new ListConverter<>(SafeEncoder::encode); + } - PredicateStatusConverter ONE_STATUS_CONVERTER = new PredicateStatusConverter<>((val)->val == 1L); + static SetConverter setStringToBinary() { + return new SetConverter<>(SafeEncoder::encode); + } - Converter LONG_BOOLEAN_CONVERTER = (val)->val == 1L; + static SetConverter setBinaryToString() { + return new SetConverter<>(SafeEncoder::encode); + } - BooleanStatusConverter BOOLEAN_STATUS_CONVERTER = new BooleanStatusConverter(); + static ListSetConverter listSetBinaryToString() { + return new ListSetConverter<>(SafeEncoder::encode); + } - ListConverter STRING_LIST_TO_BINARY_LIST_CONVERTER = new ListConverter<>(SafeEncoder::encode); + static ListSetConverter setListBinaryToString() { + return new ListSetConverter<>(SafeEncoder::encode); + } - ListConverter BINARY_LIST_TO_STRING_LIST_CONVERTER = new ListConverter<>(SafeEncoder::encode); + static MapConverter mapStringToBinary() { + return new MapConverter<>(SafeEncoder::encode, SafeEncoder::encode); + } - MapConverter STRING_MAP_TO_BINARY_MAP_CONVERTER = new MapConverter<>( - SafeEncoder::encode, SafeEncoder::encode); + static MapConverter mapBinaryToString() { + return new MapConverter<>(SafeEncoder::encode, SafeEncoder::encode); + } - MapConverter BINARY_MAP_TO_STRING_MAP_CONVERTER = new MapConverter<>( - SafeEncoder::encode, SafeEncoder::encode); - - ArrayConverter STRING_ARRAY_TO_BINARY_ARRAY_CONVERTER = new ArrayConverter<>( - SafeEncoder::encode, byte[].class); - - ArrayConverter BINARY_ARRAY_TO_STRING_ARRAY_CONVERTER = new ArrayConverter<>( - SafeEncoder::encode, String.class); - - EnumConverter TYPE_RESULT_CONVERTER = new EnumConverter<>(Type.class); - - EnumConverter STRING_OBJECT_ENCODING_RESULT_CONVERTER = new EnumConverter<>(ObjectEncoding.class); - - Converter BINARY_OBJECT_ENCODING_RESULT_CONVERTER = new BinaryEnumConverter<>( - ObjectEncoding.class); + @SuppressWarnings({"unchecked"}) + static Converter always() { + return (value)->(T) value; + } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/BitCountOptionConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/BitCountOptionConverter.java index 723cefb1d..15e4718ea 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/BitCountOptionConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/BitCountOptionConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; @@ -36,10 +36,8 @@ public final class BitCountOptionConverter implements Converter { - public final static BitCountOptionConverter INSTANCE = new BitCountOptionConverter(); - @Override - public redis.clients.jedis.args.BitCountOption convert(final BitCountOption source){ + public redis.clients.jedis.args.BitCountOption convert(final BitCountOption source) { switch(source){ case BYTE: return redis.clients.jedis.args.BitCountOption.BYTE; diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/BitFieldArgumentConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/BitFieldArgumentConverter.java index 504acbce1..036826d55 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/BitFieldArgumentConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/BitFieldArgumentConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; @@ -37,11 +37,9 @@ */ public final class BitFieldArgumentConverter implements Converter { - public final static BitFieldArgumentConverter INSTANCE = new BitFieldArgumentConverter(); - @Nullable @Override - public String[] convert(final BitMapCommands.BitFieldArgument source){ + public String[] convert(final BitMapCommands.BitFieldArgument source) { return source == null ? null : StringUtils.split(source.toString(), " "); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/BitOperationConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/BitOperationConverter.java index 08cbf7af1..30c76f388 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/BitOperationConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/BitOperationConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; @@ -36,10 +36,8 @@ */ public final class BitOperationConverter implements Converter { - public final static BitOperationConverter INSTANCE = new BitOperationConverter(); - @Override - public BitOP convert(final BitOperation source){ + public BitOP convert(final BitOperation source) { switch(source){ case AND: return BitOP.AND; diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ClientTypeConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ClientTypeConverter.java index d0e673798..871927a52 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ClientTypeConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ClientTypeConverter.java @@ -35,10 +35,8 @@ */ public final class ClientTypeConverter implements Converter { - public final static ClientTypeConverter INSTANCE = new ClientTypeConverter(); - @Override - public redis.clients.jedis.args.ClientType convert(final ClientType source){ + public redis.clients.jedis.args.ClientType convert(final ClientType source) { switch(source){ case NORMAL: return redis.clients.jedis.args.ClientType.NORMAL; diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ClientUnblockTypeConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ClientUnblockTypeConverter.java index 7b0a298ce..ed9b2a877 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ClientUnblockTypeConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ClientUnblockTypeConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; @@ -36,10 +36,8 @@ */ public final class ClientUnblockTypeConverter implements Converter { - public final static ClientUnblockTypeConverter INSTANCE = new ClientUnblockTypeConverter(); - @Override - public UnblockType convert(final ClientUnblockType source){ + public UnblockType convert(final ClientUnblockType source) { switch(source){ case TIMEOUT: return UnblockType.TIMEOUT; diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ClusterFailoverOptionConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ClusterFailoverOptionConverter.java index 7f6494ba7..f6adb79b9 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ClusterFailoverOptionConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ClusterFailoverOptionConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; @@ -36,10 +36,8 @@ public final class ClusterFailoverOptionConverter implements Converter { - public final static ClusterFailoverOptionConverter INSTANCE = new ClusterFailoverOptionConverter(); - @Override - public redis.clients.jedis.args.ClusterFailoverOption convert(final ClusterFailoverOption source){ + public redis.clients.jedis.args.ClusterFailoverOption convert(final ClusterFailoverOption source) { switch(source){ case FORCE: return redis.clients.jedis.args.ClusterFailoverOption.FORCE; diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/DirectionConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/DirectionConverter.java index f3473aac2..08f04a77b 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/DirectionConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/DirectionConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; @@ -36,10 +36,8 @@ */ public final class DirectionConverter implements Converter { - public final static DirectionConverter INSTANCE = new DirectionConverter(); - @Override - public ListDirection convert(final Direction source){ + public ListDirection convert(final Direction source) { switch(source){ case LEFT: return ListDirection.LEFT; diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ExpireOptionConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ExpireOptionConverter.java index a7b059af3..9f6886d66 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ExpireOptionConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ExpireOptionConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; @@ -36,10 +36,8 @@ */ public final class ExpireOptionConverter implements Converter { - public final static ExpireOptionConverter INSTANCE = new ExpireOptionConverter(); - @Override - public ExpiryOption convert(final ExpireOption source){ + public ExpiryOption convert(final ExpireOption source) { switch(source){ case NX: return ExpiryOption.NX; diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/FlushModeConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/FlushModeConverter.java index 9e8e05935..5616a2187 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/FlushModeConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/FlushModeConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; @@ -35,10 +35,8 @@ */ public final class FlushModeConverter implements Converter { - public final static FlushModeConverter INSTANCE = new FlushModeConverter(); - @Override - public redis.clients.jedis.args.FlushMode convert(final FlushMode source){ + public redis.clients.jedis.args.FlushMode convert(final FlushMode source) { switch(source){ case ASYNC: return redis.clients.jedis.args.FlushMode.ASYNC; diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GeoConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GeoConverter.java index 605e57227..c90f0f2a5 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GeoConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GeoConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; @@ -37,17 +37,13 @@ */ public final class GeoConverter implements Converter { - public final static GeoConverter INSTANCE = new GeoConverter(); - - public final static MapConverter STRING_MAP_CONVERTER = new MapConverter<>( - (key)->key, INSTANCE); - - public final static MapConverter BINARY_MAP_CONVERTER = new MapConverter<>( - (key)->key, INSTANCE); - @Override - public GeoCoordinate convert(final Geo source){ + public GeoCoordinate convert(final Geo source) { return new GeoCoordinate(source.getLongitude(), source.getLatitude()); } + public static MapConverter mapConverter() { + return new MapConverter<>((key)->key, new GeoConverter()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GeoUnitConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GeoUnitConverter.java index 539dc3675..4d57fa146 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GeoUnitConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/GeoUnitConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; @@ -35,10 +35,8 @@ */ public final class GeoUnitConverter implements Converter { - public final static GeoUnitConverter INSTANCE = new GeoUnitConverter(); - @Override - public redis.clients.jedis.args.GeoUnit convert(final GeoUnit source){ + public redis.clients.jedis.args.GeoUnit convert(final GeoUnit source) { switch(source){ case M: return redis.clients.jedis.args.GeoUnit.M; diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ListPositionConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ListPositionConverter.java index c83698bec..52779a0c0 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ListPositionConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/ListPositionConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; @@ -35,10 +35,8 @@ */ public final class ListPositionConverter implements Converter { - public final static ListPositionConverter INSTANCE = new ListPositionConverter(); - @Override - public redis.clients.jedis.args.ListPosition convert(final ListPosition source){ + public redis.clients.jedis.args.ListPosition convert(final ListPosition source) { switch(source){ case BEFORE: return redis.clients.jedis.args.ListPosition.BEFORE; diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/StreamEntryIdConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/StreamEntryIdConverter.java index 9f4e7e0fc..d096bdbf8 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/StreamEntryIdConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/StreamEntryIdConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.params; @@ -28,39 +28,26 @@ import com.buession.core.converter.Converter; import com.buession.core.converter.MapConverter; import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.internal.jedis.JedisStreamEntryID; import redis.clients.jedis.StreamEntryID; +import java.util.Map; + /** * {@link StreamEntryId} 转换为 jedis {@link StreamEntryID} * * @author Yong.Teng * @since 2.0.0 */ -public final class StreamEntryIdConverter implements Converter { - - public final static StreamEntryIdConverter INSTANCE = new StreamEntryIdConverter(); +@FunctionalInterface +public interface StreamEntryIdConverter extends Converter { - public final static ArrayConverter ARRAY_CONVERTER = new ArrayConverter<>(INSTANCE, - StreamEntryID.class); - - @Override - public StreamEntryID convert(final StreamEntryId source){ - return new StreamEntryID(source.getTime(), source.getSequence()); + static ArrayConverter arrayConverter() { + return new ArrayConverter<>(JedisStreamEntryID::from, StreamEntryID.class); } - public final static class MapStreamEntryIdConverter - extends MapConverter { - - public final static MapStreamEntryIdConverter STRING_MAP_CONVERTER = new MapStreamEntryIdConverter<>( - (key)->key); - - public final static MapStreamEntryIdConverter BINARY_MAP_CONVERTER = new MapStreamEntryIdConverter<>( - (key)->key); - - public MapStreamEntryIdConverter(final Converter keyConverter){ - super(keyConverter, StreamEntryIdConverter.INSTANCE); - } - + static MapConverter mapConverter() { + return new MapConverter<>((key)->key, JedisStreamEntryID::from); } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/AccessControlLogEntryConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/AccessControlLogEntryConverter.java index 53bfa3cd5..e54a4077f 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/AccessControlLogEntryConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/AccessControlLogEntryConverter.java @@ -19,17 +19,16 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; -import com.buession.beans.BeanConverter; -import com.buession.beans.DefaultBeanConverter; import com.buession.core.converter.Converter; import com.buession.core.converter.ListConverter; import com.buession.redis.core.AclLog; import com.buession.redis.core.Client; +import com.buession.redis.core.internal.convert.response.ClientConverter; import redis.clients.jedis.resps.AccessControlLogEntry; /** @@ -40,20 +39,19 @@ */ public final class AccessControlLogEntryConverter implements Converter { - public final static AccessControlLogEntryConverter INSTANCE = new AccessControlLogEntryConverter(); - - public final static ListConverter LIST_CONVERTER = new ListConverter<>( - AccessControlLogEntryConverter.INSTANCE); + private final static ClientConverter clientConverter = new ClientConverter(); @Override public AclLog convert(final AccessControlLogEntry source) { - final BeanConverter beanConverter = new DefaultBeanConverter(); - final Client client = new Client(); + final Client client = clientConverter.convert((String) source.getlogEntry().get(AclLog.CLIENT_INFO)); - beanConverter.convert(source.getClientInfo(), client); + return new AclLog(source.getEntryId(), source.getCount(), source.getReason(), source.getContext(), + source.getObject(), source.getUsername(), source.getAgeSeconds(), client, source.getTimestampCreated(), + source.getTimestampLastUpdated(), source.getlogEntry()); + } - return new AclLog(source.getCount(), source.getReason(), source.getContext(), source.getObject(), - source.getUsername(), source.getAgeSeconds(), client, source.getlogEntry()); + public static ListConverter listConverter() { + return new ListConverter<>(new AccessControlLogEntryConverter()); } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/AccessControlUserConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/AccessControlUserConverter.java index fe786dd5a..ca2007f53 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/AccessControlUserConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/AccessControlUserConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -36,11 +36,10 @@ */ public final class AccessControlUserConverter implements Converter { - public final static AccessControlUserConverter INSTANCE = new AccessControlUserConverter(); - @Override - public AclUser convert(final AccessControlUser source){ - return new AclUser(source.getFlags(), source.getKeys(), source.getPassword(), source.getCommands()); + public AclUser convert(final AccessControlUser source) { + return new AclUser(source.getCommands(), source.getUserInfo(), source.getPasswords(), source.getFlags(), + source.getKeysList(), source.getChannelsList(), source.getSelectors()); } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ClusterReplicasConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ClusterReplicasConverter.java index 537db1c59..a931de928 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ClusterReplicasConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ClusterReplicasConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -32,33 +32,28 @@ import com.buession.redis.core.RedisClusterServer; import com.buession.redis.core.SlotRange; -import java.util.HashSet; +import java.util.Arrays; import java.util.Set; +import java.util.stream.Collectors; /** - * Jedis Cluster Replicas 命令结果转换为 {@link RedisClusterServer} 列表 + * Jedis Cluster Replicas 命令结果转换为 {@link RedisClusterServer} * * @author Yong.Teng * @since 2.0.0 */ public final class ClusterReplicasConverter implements Converter { - public final static ClusterReplicasConverter INSTANCE = new ClusterReplicasConverter(); - - public final static ListConverter LIST_CONVERTER = new ListConverter<>(INSTANCE); - @Override public ClusterRedisNode convert(final String source) { String[] values = StringUtils.split(source, " "); - String[] hostAndPort = StringUtils.split(values[1], ":"); + String[] hostAndPort = StringUtils.split(values[1], ':'); String host = hostAndPort[0]; String port = hostAndPort[1].substring(0, hostAndPort[1].indexOf('@')); - String[] flagsValues = StringUtils.split(values[2], ":"); - Set flags = new HashSet<>(flagsValues.length); - - for(String flagsValue : flagsValues){ - flags.add(EnumUtils.getEnumIgnoreCase(ClusterRedisNode.Flag.class, flagsValue)); - } + String[] flagsValues = StringUtils.split(values[2], ':'); + Set flags = + Arrays.stream(flagsValues).map((v)->EnumUtils.getEnumIgnoreCase(ClusterRedisNode.Flag.class, v)) + .collect(Collectors.toSet()); ClusterRedisNode.LinkState linkState = EnumUtils.getEnumIgnoreCase(ClusterRedisNode.LinkState.class, values[7]); SlotRange slotRange = null; @@ -72,4 +67,8 @@ public ClusterRedisNode convert(final String source) { Long.parseLong(values[4]), Long.parseLong(values[5]), Long.parseLong(values[6]), linkState, slotRange); } + public static ListConverter listConverter() { + return new ListConverter<>(new ClusterReplicasConverter()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ClusterResetOptionConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ClusterResetOptionConverter.java index cc809c6e0..f397cc96f 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ClusterResetOptionConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ClusterResetOptionConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -36,10 +36,8 @@ */ public final class ClusterResetOptionConverter implements Converter { - public final static ClusterResetOptionConverter INSTANCE = new ClusterResetOptionConverter(); - @Override - public ClusterResetType convert(final ClusterResetOption source){ + public ClusterResetType convert(final ClusterResetOption source) { switch(source){ case SOFT: return ClusterResetType.SOFT; diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/GeoCoordinateConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/GeoCoordinateConverter.java index 0a2dce200..63b52c566 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/GeoCoordinateConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/GeoCoordinateConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -29,21 +29,23 @@ import com.buession.lang.Geo; import redis.clients.jedis.GeoCoordinate; +import java.util.List; + /** - * jedis {@link GeoCoordinate} 转换为 {@link Geo} + * Jedis {@link GeoCoordinate} 转换为 {@link Geo} * * @author Yong.Teng * @since 2.0.0 */ public final class GeoCoordinateConverter implements Converter { - public final static GeoCoordinateConverter INSTANCE = new GeoCoordinateConverter(); - - public final static ListConverter LIST_CONVERTER = new ListConverter<>(INSTANCE); - @Override - public Geo convert(final GeoCoordinate source){ + public Geo convert(final GeoCoordinate source) { return new Geo(source.getLongitude(), source.getLatitude()); } + public static ListConverter listConverter() { + return new ListConverter<>(new GeoCoordinateConverter()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/GeoRadiusResponseConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/GeoRadiusResponseConverter.java index bc77272c5..0df49185b 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/GeoRadiusResponseConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/GeoRadiusResponseConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -29,22 +29,26 @@ import com.buession.redis.core.GeoRadius; import redis.clients.jedis.resps.GeoRadiusResponse; +import java.util.List; + /** - * jedis {@link GeoRadiusResponse} 转换为 {@link GeoRadius} + * Jedis {@link GeoRadiusResponse} 转换为 {@link GeoRadius} * * @author Yong.Teng * @since 2.0.0 */ public class GeoRadiusResponseConverter implements Converter { - public final static GeoRadiusResponseConverter INSTANCE = new GeoRadiusResponseConverter(); - - public final static ListConverter LIST_CONVERTER = new ListConverter<>(INSTANCE); + private final GeoCoordinateConverter geoCoordinateConverter = new GeoCoordinateConverter(); @Override - public GeoRadius convert(final GeoRadiusResponse source){ + public GeoRadius convert(final GeoRadiusResponse source) { return new GeoRadius(source.getMember(), source.getDistance(), - GeoCoordinateConverter.INSTANCE.convert(source.getCoordinate())); + source.getCoordinate() == null ? null : geoCoordinateConverter.convert(source.getCoordinate())); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new GeoRadiusResponseConverter()); } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/KeyValueConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/KeyValueConverter.java new file mode 100644 index 000000000..2e18ea30f --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/KeyValueConverter.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.lang.KeyValue; +import org.springframework.lang.Nullable; + +/** + * Jedis {@link redis.clients.jedis.util.KeyValue} 转换为 {@link com.buession.lang.KeyValue} + * + * @param + * 原始 Key 类型 + * @param + * 原始值类型 + * @param + * 目标 Key 类型 + * @param + * 目标值类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class KeyValueConverter implements Converter, + com.buession.lang.KeyValue> { + + /** + * Key 转换器 + */ + private final Converter keyConverter; + + /** + * 值转换器 + */ + private final Converter valueConverter; + + /** + * 构造函数 + * + * @param keyConverter + * Key 转换器 + * @param valueConverter + * 值转换器 + */ + public KeyValueConverter(final Converter keyConverter, final Converter valueConverter) { + this.keyConverter = keyConverter; + this.valueConverter = valueConverter; + } + + @Nullable + @Override + public KeyValue convert(final redis.clients.jedis.util.KeyValue source) { + return new com.buession.lang.KeyValue<>(keyConverter.convert(source.getKey()), valueConverter.convert( + source.getValue())); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/MemoryStatsConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/MemoryStatsConverter.java new file mode 100644 index 000000000..c90c95284 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/MemoryStatsConverter.java @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.utils.StringUtils; +import com.buession.redis.core.MemoryStats; + +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +/** + * Jedis memory-stats 命令结果转换 + * + * @author Yong.Teng + * @since 2.3.0 + */ +public final class MemoryStatsConverter implements Converter, MemoryStats> { + + @Override + public MemoryStats convert(final Map source) { + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); + final MemoryStats memoryStats = new MemoryStats(); + + source.forEach((name, value)->{ + if("dataset.bytes".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setDataset); + }else if("dataset.percentage".equals(name)){ + propertyMapper.from(value).as((v)->Double.parseDouble(v.toString())) + .to(memoryStats::setDatasetPercentage); + }else if("rss-overhead.bytes".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setRssOverhead); + }else if("rss-overhead.ratio".equals(name)){ + propertyMapper.from(value).as((v)->Double.parseDouble(v.toString())) + .to(memoryStats::setRssOverheadRatio); + }else if("peak.percentage".equals(name)){ + propertyMapper.from(value).as((v)->Double.parseDouble(v.toString())).to(memoryStats::setPeakPercentage); + }else if("aof.buffer".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setAofBuffer); + }else if("keys.bytes-per-key".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setKeysBytesPerKey); + }else if("allocator.allocated".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setAllocatorAllocated); + }else if("allocator-fragmentation.bytes".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setAllocatorFragmentation); + }else if("allocator-fragmentation.ratio".equals(name)){ + propertyMapper.from(value).as((v)->Double.parseDouble(v.toString())) + .to(memoryStats::setAllocatorFragmentationRatio); + }else if("allocator.active".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setAllocatorActive); + }else if("allocator-rss.bytes".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setAllocatorRss); + }else if("allocator-rss.ratio".equals(name)){ + propertyMapper.from(value).as((v)->Double.parseDouble(v.toString())) + .to(memoryStats::setAllocatorRssRatio); + }else if("allocator.resident".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setAllocatorResident); + }else if("clients.normal".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setClientsNormal); + }else if("clients.slaves".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setClientsSlaves); + }else if("fragmentation.bytes".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setFragmentation); + }else if("fragmentation".equals(name)){ + propertyMapper.from(value).as((v)->Double.parseDouble(v.toString())) + .to(memoryStats::setFragmentationRatio); + }else if("lua.caches".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setLuaCaches); + }else if("peak.allocated".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setPeakAllocated); + }else if("total.allocated".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setTotalAllocated); + }else if("replication.backlog".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setReplicationBacklog); + }else if("startup.allocated".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setStartupAllocated); + }else if("overhead.total".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setOverheadTotal); + }else if("keys.count".equals(name)){ + propertyMapper.from(value).as((v)->(Long) v).to(memoryStats::setKeysCount); + }else if(name.startsWith("db.")){ + String[] nameParts = StringUtils.split(name, '.'); + int db = Integer.parseInt(nameParts[1]); + MemoryStats.Db dbStat = new MemoryStats.Db(); + List dbStatTmp = (List) value; + + if(memoryStats.getDbs() == null){ + memoryStats.setDbs(new TreeMap<>()); + } + + for(int j = 0, jl = dbStatTmp.size(); j < jl; j++){ + Object v = dbStatTmp.get(j); + j++; + + if("overhead.hashtable.main".equals(v)){ + propertyMapper.from(dbStatTmp.get(j)).as((dv)->(Long) dv) + .to(dbStat::setOverheadHashTableMain); + }else if("overhead.hashtable.expires".equals(v)){ + propertyMapper.from(dbStatTmp.get(j)).as((dv)->(Long) dv) + .to(dbStat::setOverheadHashTableExpires); + } + } + + memoryStats.getDbs().put(db, dbStat); + } + }); + + return memoryStats; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ModuleConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ModuleConverter.java index 7b6ee8855..54c1602be 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ModuleConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ModuleConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -28,6 +28,8 @@ import com.buession.core.converter.ListConverter; import com.buession.redis.core.Module; +import java.util.List; + /** * jedis {@link redis.clients.jedis.Module} 转换为 {@link Module} * @@ -36,14 +38,13 @@ */ public final class ModuleConverter implements Converter { - public final static ModuleConverter INSTANCE = new ModuleConverter(); - - public final static ListConverter LIST_CONVERTER = new ListConverter<>( - INSTANCE); - @Override - public Module convert(final redis.clients.jedis.Module source){ + public Module convert(final redis.clients.jedis.Module source) { return new Module(source.getName(), source.getVersion()); } + public static ListConverter listConverter() { + return new ListConverter<>(new ModuleConverter()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/RedisServerTimeConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/RedisServerTimeConverter.java index 6e2653445..f5ccbf7aa 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/RedisServerTimeConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/RedisServerTimeConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2021 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -38,13 +38,9 @@ */ public final class RedisServerTimeConverter implements Converter, RedisServerTime> { - public final static RedisServerTimeConverter INSTANCE = new RedisServerTimeConverter(); - @Override - public RedisServerTime convert(final List source){ - Date date = new Date(); - date.setTime(Long.parseLong(source.get(0)) * 1000L); - + public RedisServerTime convert(final List source) { + Date date = new Date(Long.parseLong(source.get(0)) * 1000L); return new RedisServerTime(date, Long.parseLong(source.get(1))); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/RoleConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/RoleConverter.java index 7455a230a..60be6747d 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/RoleConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/RoleConverter.java @@ -19,30 +19,36 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; import com.buession.core.converter.Converter; import com.buession.core.converter.ListConverter; +import com.buession.core.utils.EnumUtils; import com.buession.redis.core.Role; -import redis.clients.jedis.resps.AccessControlLogEntry; + +import java.util.List; /** - * jedis {@link AccessControlLogEntry} 转换为 {@link Role} + * Jedis 角色信息 转换为 {@link Role} * * @author Yong.Teng * @since 2.0.0 */ public final class RoleConverter implements Converter { - public final static RoleConverter INSTANCE = new RoleConverter(); + @Override + public Role convert(final Object source) { + if(source instanceof List){ + List tmp = (List) source; - public final static ListConverter LIST_CONVERTER = new ListConverter<>(INSTANCE); + if(tmp.size() == 3){ + return EnumUtils.getEnum(Role.class, tmp.get(0).toString().toUpperCase()); + } + } - @Override - public Role convert(final Object source){ return null; } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ScanResultConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ScanResultConverter.java index 1fda88570..6343e474c 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ScanResultConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/ScanResultConverter.java @@ -19,13 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; import com.buession.core.converter.Converter; -import com.buession.core.converter.MapConverter; +import com.buession.core.converter.ListConverter; import com.buession.redis.core.ScanResult; import com.buession.redis.core.Tuple; @@ -51,10 +51,6 @@ public interface ScanResultConverter extends Converter implements ScanResultConverter> { - public final static ListScanResultConverter STRING_LIST_CONVERTER = new ListScanResultConverter<>(); - - public final static ListScanResultConverter BINARY_LIST_CONVERTER = new ListScanResultConverter<>(); - @Override public ScanResult> convert(final redis.clients.jedis.resps.ScanResult source) { return new ScanResult<>(source.getCursor(), source.getResult()); @@ -71,13 +67,14 @@ public ScanResult> convert(final redis.clients.jedis.resps.ScanResult final class ListTupleScanResultConverter implements ScanResultConverter> { - public final static ListTupleScanResultConverter INSTANCE = new ListTupleScanResultConverter(); + private final ListConverter listTupleConverter = + TupleConverter.listConverter(); @Override public ScanResult> convert( final redis.clients.jedis.resps.ScanResult source) { return new com.buession.redis.core.ScanResult<>(source.getCursor(), - TupleConverter.LIST_CONVERTER.convert(source.getResult())); + listTupleConverter.convert(source.getResult())); } } @@ -96,10 +93,6 @@ public ScanResult> convert( */ final class MapScanResultConverter implements ScanResultConverter, Map> { - public final static MapScanResultConverter STRING_MAP_CONVERTER = new MapScanResultConverter<>(); - - public final static MapScanResultConverter BINARY_MAP_CONVERTER = new MapScanResultConverter<>(); - @Override public ScanResult> convert(final redis.clients.jedis.resps.ScanResult> source) { final Map data = source.getResult().stream().collect(Collectors.toMap(Map.Entry::getKey, diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/SlowlogConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/SlowlogConverter.java index fce405dd5..ee621c75e 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/SlowlogConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/SlowlogConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -30,6 +30,8 @@ import com.buession.redis.core.SlowLog; import redis.clients.jedis.resps.Slowlog; +import java.util.List; + /** * jedis {@link Slowlog} 转换为 {@link SlowLog} * @@ -38,12 +40,8 @@ */ public final class SlowlogConverter implements Converter { - public final static SlowlogConverter INSTANCE = new SlowlogConverter(); - - public final static ListConverter LIST_CONVERTER = new ListConverter<>(INSTANCE); - @Override - public SlowLog convert(final Slowlog source){ + public SlowLog convert(final Slowlog source) { final Client client = new Client(); client.setHost(source.getClientIpPort().getHost()); @@ -53,4 +51,8 @@ public SlowLog convert(final Slowlog source){ client, source.getClientName()); } + public static ListConverter listConverter() { + return new ListConverter<>(new SlowlogConverter()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumerFullInfoConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumerFullInfoConverter.java index 98ea237a0..f019e5405 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumerFullInfoConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumerFullInfoConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -38,15 +38,10 @@ * @author Yong.Teng * @since 2.0.0 */ -public class StreamConsumerFullInfoConverter implements Converter { - - public final static StreamConsumerFullInfoConverter INSTANCE = new StreamConsumerFullInfoConverter(); - - public final static ListConverter LIST_CONVERTER = new ListConverter<>( - INSTANCE); +public final class StreamConsumerFullInfoConverter implements Converter { @Override - public StreamConsumerFull convert(final StreamConsumerFullInfo source){ + public StreamConsumerFull convert(final StreamConsumerFullInfo source) { final List pendings = new ArrayList<>(); if(source.getPending() != null){ @@ -61,4 +56,8 @@ public StreamConsumerFull convert(final StreamConsumerFullInfo source){ source.getConsumerInfo()); } + public static ListConverter listConverter() { + return new ListConverter<>(new StreamConsumerFullInfoConverter()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumersInfoConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumersInfoConverter.java index cd482999e..87c887764 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumersInfoConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamConsumersInfoConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -27,24 +27,26 @@ import com.buession.core.converter.Converter; import com.buession.core.converter.ListConverter; import com.buession.redis.core.StreamConsumer; +import com.buession.redis.core.StreamConsumerFull; import redis.clients.jedis.resps.StreamConsumersInfo; +import java.util.List; + /** * jedis {@link StreamConsumersInfo} 转换为 {@link StreamConsumer} * * @author Yong.Teng * @since 2.0.0 */ -public class StreamConsumersInfoConverter implements Converter { - - public final static StreamConsumersInfoConverter INSTANCE = new StreamConsumersInfoConverter(); - - public final static ListConverter LIST_CONVERTER = new ListConverter<>( - INSTANCE); +public final class StreamConsumersInfoConverter implements Converter { @Override - public StreamConsumer convert(final StreamConsumersInfo source){ + public StreamConsumer convert(final StreamConsumersInfo source) { return new StreamConsumer(source.getName(), source.getIdle(), source.getPending(), source.getConsumerInfo()); } + public static ListConverter listConverter() { + return new ListConverter<>(new StreamConsumersInfoConverter()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamEntryConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamEntryConverter.java index 22ed5ffdb..5da4e699e 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamEntryConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamEntryConverter.java @@ -19,86 +19,76 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; import com.buession.core.converter.Converter; import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapEntryMapConverter; import com.buession.redis.core.StreamEntry; import com.buession.redis.core.StreamEntryId; -import redis.clients.jedis.StreamEntryID; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; /** - * jedis {@link redis.clients.jedis.resps.StreamEntry} 转换为 {@link StreamEntry} + * Jedis {@link redis.clients.jedis.resps.StreamEntry} 转换为 {@link StreamEntry} * * @author Yong.Teng * @since 2.0.0 */ public final class StreamEntryConverter implements Converter { - public final static StreamEntryConverter INSTANCE = new StreamEntryConverter(); - - public final static ListConverter LIST_CONVERTER = new ListConverter<>( - INSTANCE); + private final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); @Override - public StreamEntry convert(final redis.clients.jedis.resps.StreamEntry source){ - final StreamEntryId id = StreamEntryIDConverter.INSTANCE.convert(source.getID()); + public StreamEntry convert(final redis.clients.jedis.resps.StreamEntry source) { + final StreamEntryId id = streamEntryIDConverter.convert(source.getID()); return new StreamEntry(id, source.getFields()); } - public final static class MapStreamEntryConverter implements - Converter>, Map>> { - - public final static MapStreamEntryConverter STREAMENTRYID_KEY_MAP_CONVERTER = new MapStreamEntryConverter<>( - StreamEntryIDConverter.INSTANCE); - - public final static MapStreamEntryConverter STRING_KEY_MAP_CONVERTER = new MapStreamEntryConverter<>( - (key)->key); - - private final Converter keyConverter; - - public MapStreamEntryConverter(final Converter keyConverter){ - this.keyConverter = keyConverter; - } - - @Override - public Map> convert( - final Map.Entry> source){ - final Map> result = new LinkedHashMap<>(); - final TK key = keyConverter.convert(source.getKey()); - - if(source.getValue() != null){ - result.put(key, StreamEntryConverter.LIST_CONVERTER.convert(source.getValue())); - }else{ - result.put(key, null); - } + public static ListConverter listConverter() { + return new ListConverter<>(new StreamEntryConverter()); + } - return result; + /** + * Jedis {@link redis.clients.jedis.resps.StreamEntry} 转换为 {@link StreamEntry} + * + * @param + * 转换器 key 类型 + * @param + * 目标 key 类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ + public final static class MapEntryStreamEntryConverter extends + MapEntryMapConverter, TK, List> { + + public MapEntryStreamEntryConverter(final Converter keyConverter) { + super(keyConverter, StreamEntryConverter.listConverter()); } } - public final static class ListMapStreamEntryConverter extends + /** + * Jedis {@link redis.clients.jedis.resps.StreamEntry} 转换为 {@link StreamEntry} + * + * @param + * 转换器 key 类型 + * @param + * 目标 key 类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ + public final static class ListMapEntryStreamEntryConverter extends ListConverter>, Map>> { - public final static ListMapStreamEntryConverter STRING_KEY_MAP_CONVERTER = new ListMapStreamEntryConverter<>( - (key)->key); - - public final static ListMapStreamEntryConverter BINARY_KEY_MAP_CONVERTER = new ListMapStreamEntryConverter<>( - (key)->key); - - public ListMapStreamEntryConverter(final Converter keyConverter){ - super((item)->{ - final MapStreamEntryConverter converter = new MapStreamEntryConverter<>(keyConverter); - return converter.convert(item); - }); + public ListMapEntryStreamEntryConverter(final Converter keyConverter) { + super(new MapEntryStreamEntryConverter<>(keyConverter)); } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamEntryIDConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamEntryIDConverter.java index 8e832275d..b843ebb84 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamEntryIDConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamEntryIDConverter.java @@ -19,70 +19,51 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; import com.buession.core.converter.Converter; import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapEntryMapConverter; import com.buession.redis.core.StreamEntryId; import redis.clients.jedis.StreamEntryID; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; /** - * jedis {@link StreamEntryID} 转换为 {@link StreamEntryId} + * Jedis {@link StreamEntryID} 转换为 {@link StreamEntryId} * * @author Yong.Teng * @since 2.0.0 */ public final class StreamEntryIDConverter implements Converter { - public final static StreamEntryIDConverter INSTANCE = new StreamEntryIDConverter(); - - public final static ListConverter LIST_CONVERTER = new ListConverter<>(INSTANCE); - @Override - public StreamEntryId convert(final StreamEntryID source){ + public StreamEntryId convert(final StreamEntryID source) { return new StreamEntryId(source.getTime(), source.getSequence()); } - public final static class BinaryStreamEntryIdConverter implements Converter { - - public final static BinaryStreamEntryIdConverter INSTANCE = new BinaryStreamEntryIdConverter(); - - @Override - public StreamEntryId convert(final byte[] source){ - return new StreamEntryId(source); - } - + public static ListConverter listConverter() { + return new ListConverter<>(new StreamEntryIDConverter()); } - public final static class MapStreamEntryIdConverter implements - Converter>, Map>> { - - public final static MapStreamEntryIdConverter INSTANCE = new MapStreamEntryIdConverter(); + public static MapEntryMapConverter, StreamEntryId, List> mapEntryMapConverter() { + return new MapEntryMapConverter<>(new StreamEntryIDConverter(), listConverter()); + } - private final static ListConverter LIST_ENTRY_ID_CONVERTER = new ListConverter<>( - StreamEntryIDConverter.INSTANCE); + /** + * Jedis {@link StreamEntryID} 转换为 {@link StreamEntryId} + * + * @author Yong.Teng + * @since 2.0.0 + */ + public final static class BinaryStreamEntryIdConverter implements Converter { @Override - public Map> convert( - final Map.Entry> source){ - final Map> result = new LinkedHashMap<>(); - final StreamEntryId id = StreamEntryIDConverter.INSTANCE.convert(source.getKey()); - - if(source.getValue() != null){ - final List streamEntryIdS = LIST_ENTRY_ID_CONVERTER.convert(source.getValue()); - result.put(id, streamEntryIdS); - }else{ - result.put(id, null); - } - - return result; + public StreamEntryId convert(final byte[] source) { + return new StreamEntryId(source); } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamFullInfoConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamFullInfoConverter.java index 6416184bc..1f259338e 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamFullInfoConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamFullInfoConverter.java @@ -19,14 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; import com.buession.core.converter.Converter; import com.buession.core.converter.ListConverter; -import com.buession.redis.core.StreamConsumerFull; import com.buession.redis.core.StreamEntry; import com.buession.redis.core.StreamEntryId; import com.buession.redis.core.StreamFull; @@ -41,42 +40,23 @@ * @author Yong.Teng * @since 2.0.0 */ -public class StreamFullInfoConverter implements Converter { +public final class StreamFullInfoConverter implements Converter { - public final static StreamFullInfoConverter INSTANCE = new StreamFullInfoConverter(); + private final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + private final ListConverter listStreamFullInfoGroupConverter = + StreamFullInfoGroupConverter.listConverter(); + + private final ListConverter listStreamEntryConverter = + StreamEntryConverter.listConverter(); @Override - public StreamFull convert(final StreamFullInfo source){ - final List groups = StreamFullInfoGroupConverter.LIST_CONVERTER.convert(source.getGroups()); - final StreamEntryId lastGeneratedId = StreamEntryIDConverter.INSTANCE.convert(source.getLastGeneratedId()); - final List entries = StreamEntryConverter.LIST_CONVERTER.convert(source.getEntries()); + public StreamFull convert(final StreamFullInfo source) { + final List groups = listStreamFullInfoGroupConverter.convert(source.getGroups()); + final StreamEntryId lastGeneratedId = streamEntryIDConverter.convert(source.getLastGeneratedId()); + final List entries = listStreamEntryConverter.convert(source.getEntries()); return new StreamFull(source.getLength(), source.getRadixTreeKeys(), source.getRadixTreeNodes(), groups, lastGeneratedId, entries, source.getStreamFullInfo()); } - /** - * jedis {@link StreamGroupFullInfo} 转换为 {@link StreamFull.Group} - * - * @author Yong.Teng - * @since 2.0.1 - */ - public final static class StreamFullInfoGroupConverter implements Converter { - - public final static StreamFullInfoGroupConverter INSTANCE = new StreamFullInfoGroupConverter(); - - public final static ListConverter LIST_CONVERTER = new ListConverter<>( - INSTANCE); - - @Override - public StreamFull.Group convert(final StreamGroupFullInfo source){ - final List consumers = StreamConsumerFullInfoConverter.LIST_CONVERTER.convert( - source.getConsumers()); - final StreamEntryId lastDeliveredId = StreamEntryIDConverter.INSTANCE.convert(source.getLastDeliveredId()); - - return new StreamFull.Group(source.getName(), consumers, source.getPending(), source.getPelCount(), - lastDeliveredId, source.getGroupFullInfo()); - } - - } - } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamFullInfoGroupConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamFullInfoGroupConverter.java new file mode 100644 index 000000000..048608e6c --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamFullInfoGroupConverter.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.jedis.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamConsumerFull; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamFull; +import redis.clients.jedis.resps.StreamConsumerFullInfo; +import redis.clients.jedis.resps.StreamGroupFullInfo; + +import java.util.List; + +/** + * Jedis {@link StreamGroupFullInfo} 转换为 {@link StreamFull.Group} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class StreamFullInfoGroupConverter implements Converter { + + private final ListConverter listStreamConsumerFullInfoConverter = + StreamConsumerFullInfoConverter.listConverter(); + + private final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); + + @Override + public StreamFull.Group convert(final StreamGroupFullInfo source) { + final List consumers = listStreamConsumerFullInfoConverter.convert( + source.getConsumers()); + final StreamEntryId lastDeliveredId = streamEntryIDConverter.convert(source.getLastDeliveredId()); + + return new StreamFull.Group(source.getName(), consumers, source.getPending(), source.getPelCount(), + lastDeliveredId, source.getGroupFullInfo()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new StreamFullInfoGroupConverter()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamGroupInfoConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamGroupInfoConverter.java index e0d0d32e6..53d062eb1 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamGroupInfoConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamGroupInfoConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -30,24 +30,27 @@ import com.buession.redis.core.StreamGroup; import redis.clients.jedis.resps.StreamGroupInfo; +import java.util.List; + /** * jedis {@link StreamGroupInfo} 转换为 {@link StreamGroup} * * @author Yong.Teng * @since 2.0.0 */ -public class StreamGroupInfoConverter implements Converter { - - public final static StreamGroupInfoConverter INSTANCE = new StreamGroupInfoConverter(); +public final class StreamGroupInfoConverter implements Converter { - public final static ListConverter LIST_CONVERTER = new ListConverter<>( - INSTANCE); + private final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); @Override - public StreamGroup convert(final StreamGroupInfo source){ - final StreamEntryId lastDeliveredId = StreamEntryIDConverter.INSTANCE.convert(source.getLastDeliveredId()); + public StreamGroup convert(final StreamGroupInfo source) { + final StreamEntryId lastDeliveredId = streamEntryIDConverter.convert(source.getLastDeliveredId()); return new StreamGroup(source.getName(), source.getConsumers(), source.getPending(), lastDeliveredId, source.getGroupInfo()); } + public static ListConverter listConverter() { + return new ListConverter<>(new StreamGroupInfoConverter()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamInfoConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamInfoConverter.java index aa13ebb03..745060355 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamInfoConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamInfoConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -37,15 +37,17 @@ * @author Yong.Teng * @since 2.0.0 */ -public class StreamInfoConverter implements Converter { +public final class StreamInfoConverter implements Converter { - public final static StreamInfoConverter INSTANCE = new StreamInfoConverter(); + private final StreamEntryConverter streamEntryConverter = new StreamEntryConverter(); + + private final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); @Override - public Stream convert(final StreamInfo source){ - final StreamEntryId lastGeneratedId = StreamEntryIDConverter.INSTANCE.convert(source.getLastGeneratedId()); - final StreamEntry firstEntry = StreamEntryConverter.INSTANCE.convert(source.getFirstEntry()); - final StreamEntry lastEntry = StreamEntryConverter.INSTANCE.convert(source.getLastEntry()); + public Stream convert(final StreamInfo source) { + final StreamEntryId lastGeneratedId = streamEntryIDConverter.convert(source.getLastGeneratedId()); + final StreamEntry firstEntry = streamEntryConverter.convert(source.getFirstEntry()); + final StreamEntry lastEntry = streamEntryConverter.convert(source.getLastEntry()); return new Stream(source.getLength(), source.getRadixTreeKeys(), source.getRadixTreeNodes(), source.getGroups(), lastGeneratedId, firstEntry, lastEntry, source.getStreamInfo()); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamPendingEntryConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamPendingEntryConverter.java index e4076ae95..ba8704e9d 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamPendingEntryConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamPendingEntryConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -30,22 +30,26 @@ import com.buession.redis.core.StreamPending; import redis.clients.jedis.resps.StreamPendingEntry; +import java.util.List; + /** * jedis {@link StreamPendingEntry} 转换为 {@link StreamPending} * * @author Yong.Teng * @since 2.0.0 */ -public class StreamPendingEntryConverter implements Converter { - - public final static StreamPendingEntryConverter INSTANCE = new StreamPendingEntryConverter(); +public final class StreamPendingEntryConverter implements Converter { - public final static ListConverter LIST_CONVERTER = new ListConverter<>(INSTANCE); + private final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); @Override - public StreamPending convert(final StreamPendingEntry source){ - final StreamEntryId id = StreamEntryIDConverter.INSTANCE.convert(source.getID()); + public StreamPending convert(final StreamPendingEntry source) { + final StreamEntryId id = streamEntryIDConverter.convert(source.getID()); return new StreamPending(id, source.getConsumerName(), source.getIdleTime(), source.getDeliveredTimes()); } + public static ListConverter listConverter() { + return new ListConverter<>(new StreamPendingEntryConverter()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamPendingSummaryConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamPendingSummaryConverter.java index 9cf5c3f04..a97ec439d 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamPendingSummaryConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/StreamPendingSummaryConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; @@ -34,15 +34,15 @@ * @author Yong.Teng * @since 2.0.0 */ -public class StreamPendingSummaryConverter +public final class StreamPendingSummaryConverter implements Converter { - public final static StreamPendingSummaryConverter INSTANCE = new StreamPendingSummaryConverter(); + private final StreamEntryIDConverter streamEntryIDConverter = new StreamEntryIDConverter(); @Override - public StreamPendingSummary convert(final redis.clients.jedis.resps.StreamPendingSummary source){ - final StreamEntryId minId = StreamEntryIDConverter.INSTANCE.convert(source.getMinId()); - final StreamEntryId maxId = StreamEntryIDConverter.INSTANCE.convert(source.getMaxId()); + public StreamPendingSummary convert(final redis.clients.jedis.resps.StreamPendingSummary source) { + final StreamEntryId minId = streamEntryIDConverter.convert(source.getMinId()); + final StreamEntryId maxId = streamEntryIDConverter.convert(source.getMaxId()); return new StreamPendingSummary(source.getTotal(), minId, maxId, source.getConsumerMessageCount()); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/TupleConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/TupleConverter.java index a46150bb7..2cc64187c 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/TupleConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/response/TupleConverter.java @@ -19,14 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.jedis.response; import com.buession.core.converter.Converter; import com.buession.core.converter.ListConverter; -import com.buession.core.converter.SetConverter; import com.buession.redis.core.Tuple; /** @@ -37,17 +36,13 @@ */ public final class TupleConverter implements Converter { - public final static TupleConverter INSTANCE = new TupleConverter(); - - public final static SetConverter SET_CONVERTER = new SetConverter<>( - INSTANCE); - - public final static ListConverter LIST_CONVERTER = new ListConverter<>( - INSTANCE); - @Override - public Tuple convert(final redis.clients.jedis.resps.Tuple source){ + public Tuple convert(final redis.clients.jedis.resps.Tuple source) { return new Tuple(source.getBinaryElement(), source.getScore()); } + public static ListConverter listConverter() { + return new ListConverter<>(new TupleConverter()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/package-info.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/package-info.java new file mode 100644 index 000000000..2062aa1c1 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.core.internal.convert.lettuce; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/params/ClientUnblockTypeConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/params/ClientUnblockTypeConverter.java new file mode 100644 index 000000000..4dc8489a6 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/params/ClientUnblockTypeConverter.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.params; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.ClientUnblockType; +import io.lettuce.core.UnblockType; + +/** + * {@link ClientUnblockType} 转换为 Lettuce {@link UnblockType} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class ClientUnblockTypeConverter implements Converter { + + @Override + public UnblockType convert(final ClientUnblockType source) { + switch(source){ + case TIMEOUT: + return UnblockType.TIMEOUT; + case ERROR: + return UnblockType.ERROR; + default: + return null; + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/params/GeoUnitConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/params/GeoUnitConverter.java new file mode 100644 index 000000000..dfca3eb36 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/params/GeoUnitConverter.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.params; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.GeoUnit; +import io.lettuce.core.GeoArgs; + +/** + * {@link GeoUnit} 转换为 Lettuce {@link GeoArgs.Unit} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class GeoUnitConverter implements Converter { + + @Override + public GeoArgs.Unit convert(final GeoUnit source) { + switch(source){ + case M: + return GeoArgs.Unit.m; + case KM: + return GeoArgs.Unit.km; + case MI: + return GeoArgs.Unit.mi; + case FT: + return GeoArgs.Unit.ft; + default: + return null; + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/params/StreamEntryIdConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/params/StreamEntryIdConverter.java new file mode 100644 index 000000000..e576cdb77 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/params/StreamEntryIdConverter.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.params; + +import com.buession.core.converter.ArrayConverter; +import com.buession.core.converter.Converter; +import com.buession.redis.core.StreamEntryId; + +/** + * {@link StreamEntryId} 转换为 Lettuce Stream MessageId + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class StreamEntryIdConverter implements Converter { + + @Override + public String convert(final StreamEntryId source) { + return source == null ? null : source.toString(); + } + + public static ArrayConverter arrayConverter() { + return new ArrayConverter<>(new StreamEntryIdConverter(), String.class); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/params/package-info.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/params/package-info.java new file mode 100644 index 000000000..eb5f6e1df --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/params/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.core.internal.convert.lettuce.params; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/ClusterReplicasConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/ClusterReplicasConverter.java new file mode 100644 index 000000000..e1e56fa56 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/ClusterReplicasConverter.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.utils.EnumUtils; +import com.buession.core.utils.StringUtils; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.RedisClusterServer; +import com.buession.redis.core.SlotRange; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Lettuce Cluster Replicas 命令结果转换为 {@link RedisClusterServer} 列表 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class ClusterReplicasConverter implements Converter> { + + @Override + public List convert(final String source) { + String[] rows = source.split("\r\n"); + return Arrays.stream(rows).map(this::rowConvert).collect(Collectors.toList()); + } + + private ClusterRedisNode rowConvert(final String row) { + String[] values = StringUtils.split(row, " "); + String[] hostAndPort = StringUtils.split(values[1], ':'); + String host = hostAndPort[0]; + String port = hostAndPort[1].substring(0, hostAndPort[1].indexOf('@')); + String[] flagsValues = StringUtils.split(values[2], ':'); + Set flags = + Arrays.stream(flagsValues).map((v)->EnumUtils.getEnumIgnoreCase(ClusterRedisNode.Flag.class, v)) + .collect(Collectors.toSet()); + + ClusterRedisNode.LinkState linkState = EnumUtils.getEnumIgnoreCase(ClusterRedisNode.LinkState.class, values[7]); + SlotRange slotRange = null; + + if(values.length == 9){ + String[] slotRangeValues = StringUtils.split(values[8], '-'); + slotRange = new SlotRange(Integer.parseInt(slotRangeValues[0]), Integer.parseInt(slotRangeValues[1])); + } + + return new ClusterRedisNode(values[0], host, Integer.parseInt(port), flags, values[3], + Long.parseLong(values[4]), Long.parseLong(values[5]), Long.parseLong(values[6]), linkState, slotRange); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/GeoCoordinateConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/GeoCoordinateConverter.java new file mode 100644 index 000000000..7b62b91cc --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/GeoCoordinateConverter.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.lang.Geo; +import io.lettuce.core.GeoCoordinates; + +import java.util.List; + +/** + * Lettuce {@link GeoCoordinates} 转换为 {@link Geo} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class GeoCoordinateConverter implements Converter { + + @Override + public Geo convert(final GeoCoordinates source) { + return new Geo(source.getX().doubleValue(), source.getY().doubleValue()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new GeoCoordinateConverter()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/GeoRadiusGeneralResultConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/GeoRadiusGeneralResultConverter.java new file mode 100644 index 000000000..953f613e9 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/GeoRadiusGeneralResultConverter.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.SetListConverter; +import com.buession.redis.core.GeoRadius; + +import java.util.List; + +/** + * Lettuce georadius 命令结果转换为 {@link GeoRadius} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class GeoRadiusGeneralResultConverter implements Converter { + + @Override + public GeoRadius convert(final byte[] source) { + return new GeoRadius(source); + } + + public static SetListConverter setListConverter() { + return new SetListConverter<>(new GeoRadiusGeneralResultConverter()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/GeoRadiusResponseConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/GeoRadiusResponseConverter.java new file mode 100644 index 000000000..6c8facfce --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/GeoRadiusResponseConverter.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.GeoRadius; +import io.lettuce.core.GeoWithin; + +import java.util.List; + +/** + * Lettuce georadius 命令结果转换为 {@link GeoRadius} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class GeoRadiusResponseConverter implements Converter, GeoRadius> { + + private final GeoCoordinateConverter geoCoordinateConverter = new GeoCoordinateConverter(); + + @Override + public GeoRadius convert(final GeoWithin source) { + return new GeoRadius(source.getMember(), source.getDistance(), + source.getCoordinates() == null ? null : geoCoordinateConverter.convert(source.getCoordinates())); + } + + public static ListConverter, GeoRadius> listConverter() { + return new ListConverter<>(new GeoRadiusResponseConverter()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/KeyValueConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/KeyValueConverter.java new file mode 100644 index 000000000..37e070456 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/KeyValueConverter.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.lang.KeyValue; +import org.springframework.lang.Nullable; + +/** + * Lettuce {@link io.lettuce.core.KeyValue} 转换为 {@link KeyValue} + * + * @param + * 原始 Key 类型 + * @param + * 原始值类型 + * @param + * 目标 Key 类型 + * @param + * 目标值类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class KeyValueConverter implements Converter, + KeyValue> { + + /** + * Key 转换器 + */ + private final Converter keyConverter; + + /** + * 值转换器 + */ + private final Converter valueConverter; + + /** + * 构造函数 + * + * @param keyConverter + * Key 转换器 + * @param valueConverter + * 值转换器 + */ + public KeyValueConverter(final Converter keyConverter, final Converter valueConverter) { + this.keyConverter = keyConverter; + this.valueConverter = valueConverter; + } + + @Nullable + @Override + public KeyValue convert(final io.lettuce.core.KeyValue source) { + return new KeyValue<>(keyConverter.convert(source.getKey()), valueConverter.convert( + source.getValue())); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/PendingMessageConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/PendingMessageConverter.java new file mode 100644 index 000000000..2c811cf49 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/PendingMessageConverter.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamPending; +import io.lettuce.core.models.stream.PendingMessage; +import org.springframework.lang.Nullable; + +/** + * Lettuce {@link PendingMessage} 转换为 {@link StreamPending} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class PendingMessageConverter implements Converter { + + @Nullable + @Override + public StreamPending convert(final PendingMessage source) { + if(source == null){ + return null; + }else{ + return new StreamPending(new StreamEntryId(source.getId()), source.getConsumer(), + source.getMsSinceLastDelivery(), source.getRedeliveryCount()); + } + } + + public static ListConverter listConverter() { + return new ListConverter<>(new PendingMessageConverter()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/PendingMessagesConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/PendingMessagesConverter.java new file mode 100644 index 000000000..c7b0b5068 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/PendingMessagesConverter.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.StreamPendingSummary; +import io.lettuce.core.Range; +import io.lettuce.core.models.stream.PendingMessages; +import org.springframework.lang.Nullable; + +/** + * Lettuce {@link PendingMessages} 转换为 {@link StreamPendingSummary} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class PendingMessagesConverter implements Converter { + + @Nullable + @Override + public StreamPendingSummary convert(final PendingMessages source) { + if(source == null){ + return null; + }else{ + final Range messageIds = source.getMessageIds(); + + return new StreamPendingSummary(source.getCount(), + new StreamEntryId(messageIds.getLower().getValue()), + new StreamEntryId(messageIds.getUpper().getValue()), source.getConsumerMessageCount()); + } + } + + public static ListConverter listConverter() { + return new ListConverter<>(new PendingMessagesConverter()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/RedisServerTimeConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/RedisServerTimeConverter.java new file mode 100644 index 000000000..540e93656 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/RedisServerTimeConverter.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.RedisServerTime; +import com.buession.redis.utils.SafeEncoder; + +import java.util.Date; +import java.util.List; + +/** + * Lettuce 返回的服务器时间转换为 {@link RedisServerTime} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class RedisServerTimeConverter implements Converter, RedisServerTime> { + + @Override + public RedisServerTime convert(final List source) { + if(source != null && source.size() == 2){ + Date date = new Date(Long.parseLong(SafeEncoder.encode(source.get(0))) * 1000L); + return new RedisServerTime(date, Long.parseLong(SafeEncoder.encode(source.get(1)))); + } + + return null; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/RoleConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/RoleConverter.java new file mode 100644 index 000000000..b6316afc4 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/RoleConverter.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.utils.EnumUtils; +import com.buession.redis.core.Role; + +import java.util.List; + +/** + * Lettuce 角色信息 转换为 {@link Role} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class RoleConverter implements Converter, Role> { + + @Override + public Role convert(final List source) { + if(source != null && source.size() == 3){ + return EnumUtils.getEnum(Role.class, new String((byte[]) source.get(0)).toUpperCase()); + } + + return null; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/ScanCursorConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/ScanCursorConverter.java new file mode 100644 index 000000000..266d97d68 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/ScanCursorConverter.java @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapConverter; +import com.buession.redis.core.ScanResult; +import com.buession.redis.core.Tuple; +import com.buession.redis.core.internal.convert.Converters; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.KeyScanCursor; +import io.lettuce.core.MapScanCursor; +import io.lettuce.core.ScanCursor; +import io.lettuce.core.ScoredValue; +import io.lettuce.core.ScoredValueScanCursor; +import io.lettuce.core.ValueScanCursor; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce {@link ScanCursor} 转换为 {@link ScanResult} + * + * @param + * {@link ScanCursor} 类型 + * @param + * {@link ScanResult} 类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface ScanCursorConverter extends Converter> { + + /** + * Lettuce {@link KeyScanCursor} 转换为 {@link ScanResult} + * + * @param + * Key 类型 + * + * @author Yong.Teng + */ + final class KeyScanCursorConverter implements ScanCursorConverter, List> { + + @Override + public ScanResult> convert(final KeyScanCursor source) { + return new ScanResult<>(source.getCursor(), source.getKeys()); + } + + /** + * Lettuce {@link KeyScanCursor} 转换为 {@link ScanResult} + * + * @author Yong.Teng + */ + public final static class BSKeyScanCursorConverter implements ScanCursorConverter, + List> { + + private final ListConverter binaryToStringListConverter = + new ListConverter<>(SafeEncoder::encode); + + @Override + public ScanResult> convert(final KeyScanCursor source) { + return new ScanResult<>(source.getCursor(), binaryToStringListConverter.convert(source.getKeys())); + } + + } + + } + + /** + * Lettuce {@link ValueScanCursor} 转换为 {@link ScanResult} + * + * @param + * Key 类型 + * + * @author Yong.Teng + */ + final class ValueScanCursorConverter implements ScanCursorConverter, List> { + + @Override + public ScanResult> convert(final ValueScanCursor source) { + return new ScanResult<>(source.getCursor(), source.getValues()); + } + + /** + * Lettuce {@link ValueScanCursor} 转换为 {@link ScanResult} + * + * @author Yong.Teng + */ + public final static class BSKeyScanCursorConverter implements ScanCursorConverter, + List> { + + private final ListConverter binaryToStringListConverter = + new ListConverter<>(SafeEncoder::encode); + + @Override + public ScanResult> convert(final ValueScanCursor source) { + return new ScanResult<>(source.getCursor(), binaryToStringListConverter.convert(source.getValues())); + } + + } + + /** + * Lettuce {@link ScoredValueScanCursor} 转换为 {@link ScanResult} + * + * @author Yong.Teng + */ + public final static class ScoredValueScanCursorConverter + implements ScanCursorConverter, List> { + + private final ListConverter, Tuple> listScoredValueConverter + = ScoredValueTupleConverter.BinaryScoredValueTupleConverter.listConverter(); + + @Override + public ScanResult> convert(final ScoredValueScanCursor source) { + return new ScanResult<>(source.getCursor(), listScoredValueConverter.convert(source.getValues())); + } + + } + + } + + /** + * Lettuce {@link MapScanCursor} 转换为 {@link ScanResult} + * + * @param + * Key 类型 + * @param + * 值类型 + * + * @author Yong.Teng + */ + final class MapScanCursorConverter implements ScanCursorConverter, Map> { + + @Override + public ScanResult> convert(final MapScanCursor source) { + return new ScanResult<>(source.getCursor(), source.getMap()); + } + + /** + * Lettuce {@link MapScanCursor} 转换为 {@link ScanResult} + * + * @author Yong.Teng + */ + public final static class BvSvMapScanCursorConverter implements ScanCursorConverter, Map> { + + private final MapConverter binaryToStringMapConverter = + Converters.mapBinaryToString(); + + @Override + public ScanResult> convert(final MapScanCursor source) { + return new ScanResult<>(source.getCursor(), binaryToStringMapConverter.convert(source.getMap())); + } + + } + + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/ScoredValueTupleConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/ScoredValueTupleConverter.java new file mode 100644 index 000000000..afff0cce6 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/ScoredValueTupleConverter.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.Tuple; +import io.lettuce.core.ScoredValue; +import org.springframework.lang.Nullable; + +/** + * Lettuce {@link ScoredValue} 转换为 {@link Tuple} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface ScoredValueTupleConverter extends Converter, Tuple> { + + final class StringScoredValueTupleConverter implements ScoredValueTupleConverter { + + @Nullable + @Override + public Tuple convert(final ScoredValue source) { + if(source == null){ + return null; + }else{ + return new Tuple(source.getValue(), source.getScore()); + } + } + + public static ListConverter, Tuple> listConverter() { + return new ListConverter<>(new StringScoredValueTupleConverter()); + } + + } + + final class BinaryScoredValueTupleConverter implements ScoredValueTupleConverter { + + @Nullable + @Override + public Tuple convert(final ScoredValue source) { + if(source == null){ + return null; + }else{ + return new Tuple(source.getValue(), source.getScore()); + } + } + + public static ListConverter, Tuple> listConverter() { + return new ListConverter<>(new BinaryScoredValueTupleConverter()); + } + + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/SlowlogConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/SlowlogConverter.java new file mode 100644 index 000000000..604c8bb45 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/SlowlogConverter.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.utils.StringUtils; +import com.buession.redis.core.Client; +import com.buession.redis.core.SlowLog; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Lettuce 慢日志对象转换为 {@link SlowLog} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class SlowlogConverter implements Converter { + + @Override + public SlowLog convert(final Object source) { + if(source instanceof List){ + final List tmp = (List) source; + + if(tmp.size() == 6){ + final Client client = parseHostAndPort(tmp.get(4)); + final String clientName = parseClientName(tmp.get(5)); + + return new SlowLog((long) tmp.get(0), (long) tmp.get(1), (long) tmp.get(2), parseArgs(tmp.get(3)), + client, clientName); + } + } + + return null; + } + + private static Client parseHostAndPort(final Object value) { + final Client client = new Client(); + + if(value != null){ + String[] hostAndPort = StringUtils.split(new String((byte[]) value), ':'); + client.setHost(hostAndPort[0]); + client.setPort(Integer.parseInt(hostAndPort[1])); + } + + return client; + } + + private static String parseClientName(final Object value) { + return value == null ? null : new String((byte[]) value); + } + + private static List parseArgs(final Object value) { + if(value == null){ + return null; + } + + final List tmp = (List) value; + return tmp.stream().map((v)->v == null ? null : new String(v)).collect(Collectors.toList()); + } + + public static ListConverter listConverter() { + return new ListConverter<>(new SlowlogConverter()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamConsumersInfoConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamConsumersInfoConverter.java new file mode 100644 index 000000000..9b037a568 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamConsumersInfoConverter.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamConsumer; +import org.springframework.lang.Nullable; + +import java.util.List; + +/** + * Lettuce 'xinfo-consumers' 命令结果转换为 {@link StreamConsumer} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class StreamConsumersInfoConverter implements Converter { + + @Nullable + @Override + public StreamConsumer convert(final Object source) { + return null; + } + + public static ListConverter listConverter() { + return new ListConverter<>(new StreamConsumersInfoConverter()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamEntryIDConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamEntryIDConverter.java new file mode 100644 index 000000000..79bea367a --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamEntryIDConverter.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.Tuple; +import io.lettuce.core.ScoredValue; +import io.lettuce.core.StreamMessage; +import org.springframework.lang.Nullable; +import redis.clients.jedis.StreamEntryID; + +import java.util.List; + +/** + * Lettuce Message Id 转换为 {@link StreamEntryId} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class StreamEntryIDConverter implements Converter { + + @Nullable + @Override + public StreamEntryId convert(final String source) { + return null; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamFullInfoConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamFullInfoConverter.java new file mode 100644 index 000000000..b742f5a20 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamFullInfoConverter.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.StreamFull; +import org.springframework.lang.Nullable; + +import java.util.List; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public final class StreamFullInfoConverter implements Converter, StreamFull> { + + @Nullable + @Override + public StreamFull convert(final List source) { + return null; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamGroupInfoConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamGroupInfoConverter.java new file mode 100644 index 000000000..c4b84e0ec --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamGroupInfoConverter.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamGroup; +import org.springframework.lang.Nullable; + +import java.util.List; + +/** + * Lettuce 'xinfo-groups' 命令结果转换为 {@link StreamGroup} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class StreamGroupInfoConverter implements Converter { + + @Nullable + @Override + public StreamGroup convert(final Object source) { + return null; + } + + public static ListConverter listConverter() { + return new ListConverter<>(new StreamGroupInfoConverter()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamInfoConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamInfoConverter.java new file mode 100644 index 000000000..51ec549c8 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamInfoConverter.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.Stream; +import org.springframework.lang.Nullable; + +import java.util.List; + +/** + * Lettuce 'xinfo-consumers' 命令结果转换为 {@link Stream} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class StreamInfoConverter implements Converter, Stream> { + + @Nullable + @Override + public Stream convert(final List source) { + return null; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamMessageConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamMessageConverter.java new file mode 100644 index 000000000..95aeef72a --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamMessageConverter.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapConverter; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.internal.convert.Converters; +import io.lettuce.core.StreamMessage; +import org.springframework.lang.Nullable; + +/** + * Lettuce {@link StreamMessage} 转换为 {@link StreamEntry} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class StreamMessageConverter implements Converter, StreamEntry> { + + private final MapConverter binaryToStringMapConverter = + Converters.mapBinaryToString(); + + @Nullable + @Override + public StreamEntry convert(final StreamMessage source) { + return new StreamEntry(new StreamEntryId(source.getId()), binaryToStringMapConverter.convert(source.getBody())); + } + + public static ListConverter, StreamEntry> listConverter() { + return new ListConverter<>(new StreamMessageConverter()); + } + + /** + * Lettuce {@link StreamMessage} 转换为 {@link StreamEntryId} + * + * @author Yong.Teng + * @since 3.0.0 + */ + public final static class StreamMessageStreamEntryIdConverter implements Converter, + StreamEntryId> { + + @Override + public StreamEntryId convert(final StreamMessage source) { + return new StreamEntryId(source.getId()); + } + + public static ListConverter, StreamEntryId> listConverter() { + return new ListConverter<>(new StreamMessageStreamEntryIdConverter()); + } + + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamMessageMapConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamMessageMapConverter.java new file mode 100644 index 000000000..6300db7e4 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamMessageMapConverter.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.core.converter.MapConverter; +import com.buession.redis.core.StreamEntry; +import com.buession.redis.core.internal.convert.Converters; +import io.lettuce.core.StreamMessage; +import org.springframework.lang.Nullable; + +import java.util.List; +import java.util.Map; + +/** + * Lettuce {@link StreamMessage} 转换为 {@link StreamEntry} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class StreamMessageMapConverter + implements Converter, Map>> { + + private final MapConverter binaryToStringMapConverter = + Converters.mapBinaryToString(); + + @Nullable + @Override + public Map> convert(final StreamMessage source) { + //return new StreamEntry(new StreamEntryId(source.getId()), + //binaryToStringMapConverter.convert(source.getBody())); + return null; + } + + public static ListConverter, Map>> listConverter() { + return new ListConverter<>(new StreamMessageMapConverter<>()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamPendingConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamPendingConverter.java new file mode 100644 index 000000000..531c57c91 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamPendingConverter.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.core.converter.ListConverter; +import com.buession.redis.core.StreamPending; +import io.lettuce.core.models.stream.PendingMessage; +import org.springframework.lang.Nullable; + +/** + * 'xpending' 命令结果转换为 {@link StreamPending} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class StreamPendingConverter implements Converter { + + @Nullable + @Override + public StreamPending convert(final PendingMessage source) { + return null; + } + + public static ListConverter listConverter() { + return new ListConverter<>(new StreamPendingConverter()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamPendingSummaryConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamPendingSummaryConverter.java new file mode 100644 index 000000000..a8583d4cd --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/StreamPendingSummaryConverter.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.lettuce.response; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.StreamPendingSummary; +import org.springframework.lang.Nullable; + +import java.util.List; + +/** + * 'xpending' 命令结果转换为 {@link StreamPendingSummary} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class StreamPendingSummaryConverter implements Converter, StreamPendingSummary> { + + @Nullable + @Override + public StreamPendingSummary convert(final List source) { + return null; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/ValueConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/ValueConverter.java new file mode 100644 index 000000000..57e970528 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/ValueConverter.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */package com.buession.redis.core.internal.convert.lettuce.response;/** + * + * + * @author Yong.Teng + * @since 3.0.0 + */public class ValueConverter { +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/package-info.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/package-info.java new file mode 100644 index 000000000..6642a50b8 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/lettuce/response/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.core.internal.convert.lettuce.response; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/package-info.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/package-info.java index 35077d0b8..66300b1f7 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/package-info.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/package-info.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ /** diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/BinaryObjectEncodingConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/BinaryObjectEncodingConverter.java new file mode 100644 index 000000000..4d0084184 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/BinaryObjectEncodingConverter.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.BinaryEnumConverter; +import com.buession.redis.core.ObjectEncoding; + +/** + * byte[] 形式的 ObjectEncoding 转换为 {@link ObjectEncoding} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class BinaryObjectEncodingConverter extends BinaryEnumConverter { + + public BinaryObjectEncodingConverter() { + super(ObjectEncoding.class); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/BumpEpochConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/BumpEpochConverter.java index 1643e089a..bdc5e5114 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/BumpEpochConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/BumpEpochConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.response; @@ -38,11 +38,9 @@ */ public final class BumpEpochConverter implements Converter> { - public final static BumpEpochConverter INSTANCE = new BumpEpochConverter(); - @Override - public KeyValue convert(final String source){ - KeyValueParser keyValueParser = new KeyValueParser(source, " "); + public KeyValue convert(final String source) { + final KeyValueParser keyValueParser = new KeyValueParser(source, " "); return new KeyValue<>(EnumUtils.getEnum(BumpEpoch.class, keyValueParser.getKey()), keyValueParser.getIntValue()); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClientConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClientConverter.java index 83f2f55ba..4d158cff3 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClientConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClientConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.response; @@ -32,10 +32,11 @@ import com.buession.redis.core.Client; import com.buession.redis.core.command.ProtocolCommand; -import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; /** * Client Info 命令结果转换为 {@link Client} @@ -45,10 +46,8 @@ */ public final class ClientConverter implements Converter { - public final static ClientConverter INSTANCE = new ClientConverter(); - @Override - public Client convert(final String source){ + public Client convert(final String source) { String[] properties = StringUtils.splitByWholeSeparatorPreserveAllTokens(source, " "); if(Validate.isEmpty(properties)){ @@ -122,30 +121,20 @@ public Client convert(final String source){ return client; } + /** + * Client Info 命令结果转换为 {@link List} {@link Client} + * + * @author Yong.Teng + * @since 2.3.0 + */ public final static class ClientListConverter implements Converter> { - public final static ClientListConverter INSTANCE = new ClientListConverter(); + private final ClientConverter clientConverter = new ClientConverter(); @Override - public List convert(final String source){ - if(Validate.isBlank(source)){ - return null; - } - - String[] clients = source.split("[\\r\\n]"); - List result = new ArrayList<>(clients.length); - - if(Validate.isNotEmpty(clients)){ - for(String s : clients){ - Client client = ClientConverter.INSTANCE.convert(s); - - if(client != null){ - result.add(client); - } - } - } - - return result; + public List convert(final String source) { + return Arrays.stream(StringUtils.split(source, "\r\n")).map(clientConverter::convert).collect( + Collectors.toList()); } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterInfoConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterInfoConverter.java index e6a2e7347..8fa81d747 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterInfoConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterInfoConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.response; @@ -37,8 +37,6 @@ */ public final class ClusterInfoConverter implements Converter { - public final static ClusterInfoConverter INSTANCE = new ClusterInfoConverter(); - @Override public ClusterInfo convert(final String source) { String[] rows = StringUtils.split(source, "\r\n"); diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterNodeConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterNodeConverter.java index 63cab3d82..b043333f9 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterNodeConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterNodeConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.response; @@ -29,26 +29,22 @@ import com.buession.core.utils.EnumUtils; import com.buession.core.utils.StringUtils; import com.buession.redis.core.ClusterRedisNode; -import com.buession.redis.core.RedisClusterServer; import com.buession.redis.core.SlotRange; import java.util.HashSet; +import java.util.List; import java.util.Set; /** - * Cluster Slaves 命令结果转换为 {@link RedisClusterServer} + * Cluster Slaves 命令结果转换为 {@link ClusterRedisNode} * * @author Yong.Teng * @since 2.3.0 */ public final class ClusterNodeConverter implements Converter { - public final static ClusterNodeConverter INSTANCE = new ClusterNodeConverter(); - - public final static ListConverter LIST_CONVERTER = new ListConverter<>(INSTANCE); - @Override - public ClusterRedisNode convert(final String source){ + public ClusterRedisNode convert(final String source) { String[] values = StringUtils.split(source, " "); String[] hostAndPort = StringUtils.split(values[1], ":"); String host = hostAndPort[0]; @@ -72,4 +68,8 @@ public ClusterRedisNode convert(final String source){ Long.parseLong(values[4]), Long.parseLong(values[5]), Long.parseLong(values[6]), linkState, slotRange); } + public static ListConverter listConverter() { + return new ListConverter<>(new ClusterNodeConverter()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterNodesConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterNodesConverter.java index 5abfc52fc..c929c1311 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterNodesConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterNodesConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.response; @@ -29,8 +29,9 @@ import com.buession.redis.core.ClusterRedisNode; import com.buession.redis.core.RedisClusterServer; -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; /** * Cluster Nodes 命令结果转换为 {@link RedisClusterServer} 列表 @@ -40,19 +41,12 @@ */ public final class ClusterNodesConverter implements Converter> { - public final static ClusterNodesConverter INSTANCE = new ClusterNodesConverter(); + private final ClusterNodeConverter clusterNodeConverter = new ClusterNodeConverter(); @Override public List convert(final String source) { - String[] rows = StringUtils.split(source, "\r\n"); - - final List nodes = new ArrayList<>(rows.length); - - for(String row : rows){ - nodes.add(ClusterNodeConverter.INSTANCE.convert(row)); - } - - return nodes; + return Arrays.stream(StringUtils.split(source, "\r\n")).map(clusterNodeConverter::convert).collect( + Collectors.toList()); } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterSlotConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterSlotConverter.java index c466e3606..384b9f9c3 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterSlotConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ClusterSlotConverter.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.convert.response; @@ -41,13 +41,9 @@ */ public final class ClusterSlotConverter implements Converter { - public final static ClusterSlotConverter INSTANCE = new ClusterSlotConverter(); - - public final static ListConverter LIST_CONVERTER = new ListConverter<>(INSTANCE); - @Override @SuppressWarnings({"unchecked"}) - public ClusterSlot convert(final Object source){ + public ClusterSlot convert(final Object source) { if(source instanceof List){ List data = (List) source; @@ -75,4 +71,8 @@ public ClusterSlot convert(final Object source){ return null; } + public static ListConverter listConverter() { + return new ListConverter<>(new ClusterSlotConverter()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/InfoConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/InfoConverter.java new file mode 100644 index 000000000..9ab5936cb --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/InfoConverter.java @@ -0,0 +1,480 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.Converter; +import com.buession.core.utils.EnumUtils; +import com.buession.core.utils.KeyValueParser; +import com.buession.core.utils.StringUtils; +import com.buession.lang.Arch; +import com.buession.lang.Uptime; +import com.buession.net.Multiplexing; +import com.buession.redis.core.AtomicvarApi; +import com.buession.redis.core.Info; +import com.buession.redis.core.MaxMemoryPolicy; +import com.buession.redis.core.RedisMode; +import com.buession.redis.core.RedisNode; +import com.buession.redis.core.Role; +import org.springframework.lang.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Info 转换 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class InfoConverter implements Converter { + + private final static Pattern PATTERN = Pattern.compile("# (\\S+)[\\s]+([^#]+)"); + + @Override + public Info convert(final String source) { + Info.Server server = null; + Info.Clients clients = null; + Info.Memory memory = null; + Info.Persistence persistence = null; + Info.Stats stats = null; + Info.Replication replication = null; + Info.Cpu cpu = null; + Info.Cluster cluster = null; + Info.Sentinel sentinel = null; + List keyspaces = null; + + Matcher matcher = PATTERN.matcher(source); + + while(matcher.find()){ + String groupName = matcher.group(1); + String groupValue = matcher.group(2); + + if("Server".equalsIgnoreCase(groupName)){ + final ServerParser serverParser = new ServerParser(); + server = serverParser.parse(groupValue); + }else if("Clients".equalsIgnoreCase(groupName)){ + final ClientsParser clientsParser = new ClientsParser(); + clients = clientsParser.parse(groupValue); + }else if("Memory".equalsIgnoreCase(groupName)){ + final MemoryParser memoryParser = new MemoryParser(); + memory = memoryParser.parse(groupValue); + }else if("Persistence".equalsIgnoreCase(groupName)){ + final PersistenceParser persistenceParser = new PersistenceParser(); + persistence = persistenceParser.parse(groupValue); + }else if("Stats".equalsIgnoreCase(groupName)){ + final StatsParser statsParser = new StatsParser(); + stats = statsParser.parse(groupValue); + }else if("Replication".equalsIgnoreCase(groupName)){ + final ReplicationParser replicationParser = new ReplicationParser(); + replication = replicationParser.parse(groupValue); + }else if("CPU".equalsIgnoreCase(groupName)){ + final CpuParser cpuParser = new CpuParser(); + cpu = cpuParser.parse(groupValue); + }else if("Cluster".equalsIgnoreCase(groupName)){ + final ClusterParser clusterParser = new ClusterParser(); + cluster = clusterParser.parse(groupValue); + }else if("Sentinel".equalsIgnoreCase(groupName)){ + final SentinelParser keyspaceParser = new SentinelParser(); + sentinel = keyspaceParser.parse(groupValue); + }else if("Keyspace".equalsIgnoreCase(groupName)){ + final KeyspaceParser keyspaceParser = new KeyspaceParser(); + keyspaces = keyspaceParser.parse(groupValue); + } + } + + return new Info(server, clients, memory, persistence, stats, replication, sentinel, cpu, cluster, keyspaces); + } + + @FunctionalInterface + private interface Parser { + + @Nullable + V parse(final String str); + + default String[] parseRows(final String str) { + return StringUtils.split(str, "\r\n"); + } + + } + + private final static class ServerParser implements Parser { + + @Override + public Info.Server parse(final String str) { + Uptime uptime = new Uptime(); + String[] rows = parseRows(str); + Properties properties = new Properties(); + KeyValueParser keyValueParser; + + for(String row : rows){ + keyValueParser = new KeyValueParser(row, ':'); + + if(Info.Server.Key.ARCH.getValue().equals(keyValueParser.getKey())){ + if("32".equals(keyValueParser.getValue())){ + properties.put(keyValueParser.getKey(), Arch.BIT_32); + }else if("64".equals(keyValueParser.getValue())){ + properties.put(keyValueParser.getKey(), Arch.BIT_64); + } + }else if(Info.Server.Key.ATOMICVAR_API.getValue().equals(keyValueParser.getKey())){ + for(AtomicvarApi v : AtomicvarApi.values()){ + if(v.getValue().equals(keyValueParser.getValue())){ + properties.put(keyValueParser.getKey(), v); + break; + } + } + }else if(Info.Server.Key.MODE.getValue().equals(keyValueParser.getKey())){ + properties.put(keyValueParser.getKey(), keyValueParser.getEnumValue(RedisMode.class)); + }else if(Info.Server.Key.MULTIPLEXING_API.getValue().equals(keyValueParser.getKey())){ + properties.put(keyValueParser.getKey(), keyValueParser.getEnumValue(Multiplexing.class)); + }else if("uptime_in_seconds".equals(keyValueParser.getKey())){ + uptime.setSeconds(keyValueParser.getIntValue()); + }else if("uptime_in_days".equals(keyValueParser.getKey())){ + uptime.setDays(keyValueParser.getIntValue()); + }else{ + properties.setProperty(keyValueParser.getKey(), keyValueParser.getValue()); + } + } + + properties.put(Info.Server.Key.UPTIME, uptime); + + return new Info.Server(properties); + } + + } + + private final static class ClientsParser implements Parser { + + @Override + public Info.Clients parse(final String str) { + String[] rows = parseRows(str); + Properties properties = new Properties(); + KeyValueParser keyValueParser; + + for(String row : rows){ + keyValueParser = new KeyValueParser(row, ':'); + properties.put(keyValueParser.getKey(), keyValueParser.getValue()); + } + + return new Info.Clients(properties); + } + + } + + private final static class MemoryParser implements Parser { + + @Override + public Info.Memory parse(final String str) { + String[] rows = parseRows(str); + Properties properties = new Properties(); + KeyValueParser keyValueParser; + + for(String row : rows){ + keyValueParser = new KeyValueParser(row, ':'); + + if(Info.Memory.Key.MAX_MEMORY_POLICY.getValue().equals(keyValueParser.getKey())){ + properties.put(keyValueParser.getKey(), EnumUtils.valueOf(MaxMemoryPolicy.class, + StringUtils.replace(keyValueParser.getValue().toUpperCase(), "-", "_"))); + }else{ + properties.put(keyValueParser.getKey(), keyValueParser.getValue()); + } + } + + return new Info.Memory(properties); + } + + } + + private final static class PersistenceParser implements Parser { + + @Override + public Info.Persistence parse(final String str) { + String[] rows = parseRows(str); + Properties properties = new Properties(); + KeyValueParser keyValueParser; + + for(String row : rows){ + keyValueParser = new KeyValueParser(row, ':'); + + if(Info.Persistence.Key.AOF_LAST_BGREWRITE_STATUS.getValue().equals(keyValueParser.getKey())){ + properties.put(keyValueParser.getKey(), keyValueParser.getStatusValue()); + }else if(Info.Persistence.Key.RDB_LAST_BGSAVE_STATUS.getValue().equals(keyValueParser.getKey())){ + properties.put(keyValueParser.getKey(), keyValueParser.getStatusValue()); + }else if(Info.Persistence.Key.AOF_LAST_WRITE_STATUS.getValue().equals(keyValueParser.getKey())){ + properties.put(keyValueParser.getKey(), keyValueParser.getStatusValue()); + }else{ + properties.put(keyValueParser.getKey(), keyValueParser.getValue()); + } + } + + return new Info.Persistence(properties); + } + + } + + private final static class StatsParser implements Parser { + + @Override + public Info.Stats parse(final String str) { + String[] rows = parseRows(str); + Properties properties = new Properties(); + KeyValueParser keyValueParser; + + for(String row : rows){ + keyValueParser = new KeyValueParser(row, ':'); + properties.put(keyValueParser.getKey(), keyValueParser.getValue()); + } + + return new Info.Stats(properties); + } + + } + + private final static class ReplicationParser implements Parser { + + private final static Pattern SLAVE_PATTERN = Pattern.compile("slave\\d"); + + @Override + public Info.Replication parse(final String str) { + String[] rows = parseRows(str); + Properties properties = new Properties(); + Properties replBackLogProperties = null; + String masterHost = null; + int masterPort = RedisNode.DEFAULT_PORT; + + List slaves = null; + KeyValueParser keyValueParser; + + for(String row : rows){ + keyValueParser = new KeyValueParser(row, ':'); + + if("master_host".equals(keyValueParser.getKey())){ + masterHost = keyValueParser.getValue(); + }else if("master_port".equals(keyValueParser.getKey())){ + masterPort = keyValueParser.getIntValue(); + }else if(keyValueParser.isKey(SLAVE_PATTERN)){ + if(slaves == null){ + slaves = new ArrayList<>(); + } + + slaves.add(parseSlave(keyValueParser.getValue())); + }else if(Info.Replication.Key.MASTER_LINK_STATUS.getValue().equals(keyValueParser.getKey())){ + properties.put(keyValueParser.getKey(), + keyValueParser.getEnumValue(Info.Replication.MasterLinkStatus.class)); + }else if(Info.Replication.ReplBacklog.Key.ACTIVE.getValue().equals(keyValueParser.getKey())){ + if(replBackLogProperties == null){ + replBackLogProperties = new Properties(); + } + + replBackLogProperties.put(keyValueParser.getKey(), keyValueParser.getValue()); + }else if(Info.Replication.ReplBacklog.Key.SIZE.getValue().equals(keyValueParser.getKey())){ + if(replBackLogProperties == null){ + replBackLogProperties = new Properties(); + } + + replBackLogProperties.put(keyValueParser.getKey(), keyValueParser.getValue()); + }else if(Info.Replication.ReplBacklog.Key.FIRST_BYTE_OFFSET.getValue().equals(keyValueParser.getKey())){ + if(replBackLogProperties == null){ + replBackLogProperties = new Properties(); + } + + replBackLogProperties.put(keyValueParser.getKey(), keyValueParser.getValue()); + }else if(Info.Replication.ReplBacklog.Key.HISTLEN.getValue().equals(keyValueParser.getKey())){ + if(replBackLogProperties == null){ + replBackLogProperties = new Properties(); + } + + replBackLogProperties.put(keyValueParser.getKey(), keyValueParser.getValue()); + }else if(Info.Replication.Key.ROLE.getValue().equals(keyValueParser.getKey())){ + properties.put(Info.Replication.Key.ROLE.getValue(), keyValueParser.getEnumValue(Role.class)); + }else{ + properties.put(keyValueParser.getKey(), keyValueParser.getValue()); + } + } + + if(masterHost != null){ + properties.put(Info.Replication.Key.MASTER.getValue(), new RedisNode(masterHost, masterPort)); + } + + if(slaves != null){ + properties.put(Info.Replication.Key.SLAVE.getValue(), slaves); + } + + if(replBackLogProperties != null){ + properties.put(Info.Replication.Key.REPL_BACK_LOG.getValue(), + new Info.Replication.ReplBacklog(replBackLogProperties)); + } + + return new Info.Replication(properties); + } + + private static Info.Replication.Slave parseSlave(final String str) { + String[] groups = StringUtils.splitByWholeSeparatorPreserveAllTokens(str, ","); + Properties properties = new Properties(); + KeyValueParser keyValueParser; + + for(String group : groups){ + keyValueParser = new KeyValueParser(group, '='); + + if(Info.Replication.Slave.Key.STATE.getValue().equals(keyValueParser.getKey())){ + properties.put(keyValueParser.getKey(), + keyValueParser.getEnumValue(Info.Replication.Slave.SlaveState.class)); + }else{ + properties.put(keyValueParser.getKey(), keyValueParser.getValue()); + } + } + + return new Info.Replication.Slave(properties); + } + + } + + private final static class CpuParser implements Parser { + + @Override + public Info.Cpu parse(final String str) { + String[] rows = parseRows(str); + Properties properties = new Properties(); + KeyValueParser keyValueParser; + + for(String row : rows){ + keyValueParser = new KeyValueParser(row, ':'); + properties.put(keyValueParser.getKey(), keyValueParser.getValue()); + } + + return new Info.Cpu(properties); + } + + } + + private final static class ClusterParser implements Parser { + + @Override + public Info.Cluster parse(final String str) { + String[] rows = parseRows(str); + Properties properties = new Properties(); + KeyValueParser keyValueParser; + + for(String row : rows){ + keyValueParser = new KeyValueParser(row, ':'); + properties.put(keyValueParser.getKey(), keyValueParser.getBoolValue()); + } + + return new Info.Cluster(properties); + } + + } + + private final static class SentinelParser implements Parser { + + private final static Pattern MASTER_PATTERN = Pattern.compile("master\\d"); + + @Override + public Info.Sentinel parse(final String str) { + String[] rows = parseRows(str); + Properties properties = new Properties(); + List masters = null; + KeyValueParser keyValueParser; + + for(String row : rows){ + keyValueParser = new KeyValueParser(row, ':'); + if(keyValueParser.isKey(MASTER_PATTERN)){ + if(masters == null){ + masters = new ArrayList<>(); + } + + masters.add(parseMaster(keyValueParser.getValue())); + }else{ + properties.put(keyValueParser.getKey(), keyValueParser.getValue()); + } + } + + return new Info.Sentinel(properties); + } + + private static Info.Sentinel.Master parseMaster(final String str) { + String[] groups = StringUtils.splitByWholeSeparatorPreserveAllTokens(str, ","); + Properties properties = new Properties(); + KeyValueParser keyValueParser; + + for(String group : groups){ + keyValueParser = new KeyValueParser(group, '='); + + if(Info.Sentinel.Master.Key.ADDRESS.getValue().equals(keyValueParser.getKey())){ + KeyValueParser addressKeyValueParser = new KeyValueParser(group, ':'); + + properties.setProperty(Info.Sentinel.Master.Key.HOST.getValue(), addressKeyValueParser.getKey()); + properties.setProperty(Info.Sentinel.Master.Key.PORT.getValue(), addressKeyValueParser.getValue()); + + properties.put(keyValueParser.getKey(), keyValueParser.getValue()); + }else{ + properties.put(keyValueParser.getKey(), keyValueParser.getValue()); + } + } + + return new Info.Sentinel.Master(properties); + } + + } + + private final static class KeyspaceParser implements Parser> { + + @Override + public List parse(final String str) { + String[] rows = parseRows(str); + KeyValueParser paramKeyValueParser; + Properties properties; + List keyspaces = new ArrayList<>(rows.length); + + for(String row : rows){ + String[] v = StringUtils.splitByWholeSeparatorPreserveAllTokens(row, ":"); + if(v == null || v.length < 2){ + continue; + } + + properties = new Properties(); + String db = StringUtils.replace(v[0], "\n", "").substring(2); + String[] params = StringUtils.splitByWholeSeparatorPreserveAllTokens(v[1], ","); + + properties.put(Info.Keyspace.Key.DB.getValue(), db); + + if(params != null){ + for(String s : params){ + paramKeyValueParser = new KeyValueParser(s, '='); + properties.put(paramKeyValueParser.getKey(), paramKeyValueParser.getValue()); + } + } + + keyspaces.add(new Info.Keyspace(properties)); + } + + return keyspaces; + } + + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ObjectEncodingConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ObjectEncodingConverter.java new file mode 100644 index 000000000..171ecd107 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/ObjectEncodingConverter.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.EnumConverter; +import com.buession.redis.core.ObjectEncoding; + +/** + * 字符串形式的 ObjectEncoding 转换为 {@link ObjectEncoding} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class ObjectEncodingConverter extends EnumConverter { + + public ObjectEncodingConverter() { + super(ObjectEncoding.class); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/OkStatusConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/OkStatusConverter.java index b9ec07579..cb31b8b0a 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/OkStatusConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/OkStatusConverter.java @@ -36,8 +36,6 @@ */ public final class OkStatusConverter implements Converter { - public final static OkStatusConverter INSTANCE = new OkStatusConverter(); - @Override public Status convert(final String source) { return Status.valueOf(Constants.OK.equalsIgnoreCase(source)); diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/OneBooleanConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/OneBooleanConverter.java new file mode 100644 index 000000000..2cb302758 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/OneBooleanConverter.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.PredicateConverter; + +/** + * "1" 到 {@link Boolean} 转换 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class OneBooleanConverter extends PredicateConverter { + + public OneBooleanConverter() { + super((val)->val == 1L); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/OneStatusConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/OneStatusConverter.java new file mode 100644 index 000000000..8582481b7 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/OneStatusConverter.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.PredicateStatusConverter; +import com.buession.lang.Status; + +/** + * "1" 到 {@link Status} 转换 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class OneStatusConverter extends PredicateStatusConverter { + + public OneStatusConverter() { + super((val)->val == 1L); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/PingResultConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/PingResultConverter.java index aabf6c7b7..906967fe8 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/PingResultConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/PingResultConverter.java @@ -36,8 +36,6 @@ */ public final class PingResultConverter implements Converter { - public final static PingResultConverter INSTANCE = new PingResultConverter(); - @Override public Status convert(final String source) { return Status.valueOf(Constants.PONG.equalsIgnoreCase(source)); diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/TypeConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/TypeConverter.java new file mode 100644 index 000000000..3732d3e18 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/convert/response/TypeConverter.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.convert.response; + +import com.buession.core.converter.EnumConverter; +import com.buession.redis.core.Type; + +/** + * 字符串形式的 type 转换为 {@link Type} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class TypeConverter extends EnumConverter { + + public TypeConverter() { + super(Type.class); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisClientConfigBuilder.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisClientConfigBuilder.java index acdc63d82..80d4e764d 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisClientConfigBuilder.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisClientConfigBuilder.java @@ -19,11 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.jedis; +import com.buession.core.converter.mapper.PropertyMapper; import com.buession.core.validator.Validate; import com.buession.net.ssl.SslConfiguration; import com.buession.redis.client.connection.datasource.jedis.JedisRedisDataSource; @@ -37,21 +38,18 @@ public class JedisClientConfigBuilder { private final DefaultJedisClientConfig.Builder builder = DefaultJedisClientConfig.builder(); - private JedisClientConfigBuilder(final JedisRedisDataSource dataSource, final SslConfiguration sslConfiguration){ + private final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); + + private JedisClientConfigBuilder(final JedisRedisDataSource dataSource, final SslConfiguration sslConfiguration) { builder.connectionTimeoutMillis(dataSource.getConnectTimeout()) .socketTimeoutMillis(dataSource.getSoTimeout()) .blockingSocketTimeoutMillis(dataSource.getInfiniteSoTimeout()) .ssl(sslConfiguration != null); - if(Validate.hasText(dataSource.getClientName())){ - builder.clientName(dataSource.getClientName()); - } + propertyMapper.from(dataSource.getClientName()).to(builder::clientName); if(Validate.hasText(dataSource.getPassword())){ - if(Validate.hasText(dataSource.getUsername())){ - builder.user(dataSource.getUsername()); - } - + propertyMapper.from(dataSource.getUsername()).to(builder::user); builder.password(dataSource.getPassword()); } @@ -63,31 +61,48 @@ private JedisClientConfigBuilder(final JedisRedisDataSource dataSource, final Ss } public static JedisClientConfigBuilder create(final JedisRedisDataSource dataSource, - final SslConfiguration sslConfiguration){ + final SslConfiguration sslConfiguration) { return new JedisClientConfigBuilder(dataSource, sslConfiguration); } - public JedisClientConfigBuilder user(final String user){ - builder.user(user); + public JedisClientConfigBuilder user(final String user) { + propertyMapper.from(user).to(builder::user); + return this; + } + + public JedisClientConfigBuilder password(final String password) { + propertyMapper.from(password).to(builder::password); + return this; + } + + public JedisClientConfigBuilder database(final int database) { + if(database >= 0){ + builder.database(database); + } + return this; + } + + public JedisClientConfigBuilder clientName(final String clientName) { + propertyMapper.from(clientName).to(builder::clientName); return this; } - public JedisClientConfigBuilder password(final String password){ - builder.password(password); + public JedisClientConfigBuilder connectTimeout(final int connectTimeout) { + builder.connectionTimeoutMillis(connectTimeout); return this; } - public JedisClientConfigBuilder database(final int database){ - builder.database(database); + public JedisClientConfigBuilder socketTimeout(final int socketTimeout) { + builder.socketTimeoutMillis(socketTimeout); return this; } - public JedisClientConfigBuilder clientName(final String clientName){ - builder.clientName(clientName); + public JedisClientConfigBuilder infiniteSoTimeout(final int blockingSocketTimeout) { + builder.blockingSocketTimeoutMillis(blockingSocketTimeout); return this; } - public DefaultJedisClientConfig build(){ + public DefaultJedisClientConfig build() { return builder.build(); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisFailoverParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisFailoverParams.java index 66f3a91ac..93b2b7b12 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisFailoverParams.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisFailoverParams.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.jedis; @@ -27,31 +27,86 @@ import redis.clients.jedis.params.FailoverParams; /** + * Jedis {@link FailoverParams} 扩展 + * * @author Yong.Teng * @since 2.0.0 */ public final class JedisFailoverParams extends FailoverParams { + /** + * 构造函数 + */ + public JedisFailoverParams() { + super(); + } + + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + */ public JedisFailoverParams(final String host, final int port) { super(); to(host, port); } + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + * @param timeout + * 超时 + */ public JedisFailoverParams(final String host, final int port, final int timeout) { this(host, port); timeout(timeout); } + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + * @param force + * 是否强制 + */ public JedisFailoverParams(final String host, final int port, final boolean force) { this(host, port); force(force); } + /** + * 构造函数 + * + * @param host + * 主机地址 + * @param port + * 端口 + * @param timeout + * 超时 + * @param force + * 是否强制 + */ public JedisFailoverParams(final String host, final int port, final int timeout, final boolean force) { this(host, port, timeout); force(force); } + /** + * 构造函数 + * + * @param timeout + * 超时 + */ public JedisFailoverParams(final int timeout) { super(); timeout(timeout); diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisGeoCoordinate.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisGeoCoordinate.java new file mode 100644 index 000000000..a96a3e39e --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisGeoCoordinate.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.lang.Geo; +import redis.clients.jedis.GeoCoordinate; + +/** + * Jedis {@link GeoCoordinate} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisGeoCoordinate extends GeoCoordinate { + + /** + * 构造函数 + * + * @param longitude + * 精度 + * @param latitude + * 纬度 + */ + public JedisGeoCoordinate(final double longitude, final double latitude) { + super(longitude, latitude); + } + + /** + * 从 {@link Geo} 创建 {@link JedisGeoCoordinate} 实例 + * + * @param geo + * {@link Geo} + * + * @return {@link JedisGeoCoordinate} 实例 + */ + public static JedisGeoCoordinate from(final Geo geo) { + return new JedisGeoCoordinate(geo.getLongitude(), geo.getLatitude()); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisGeoRadiusParam.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisGeoRadiusParam.java new file mode 100644 index 000000000..2b324010a --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisGeoRadiusParam.java @@ -0,0 +1,206 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.lang.Order; +import com.buession.redis.core.command.GeoCommands; +import redis.clients.jedis.params.GeoRadiusParam; + +import java.util.Optional; + +/** + * Jedis {@link GeoRadiusParam} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisGeoRadiusParam extends GeoRadiusParam { + + /** + * 构造函数 + */ + public JedisGeoRadiusParam() { + super(); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + */ + public JedisGeoRadiusParam(final boolean withCoord, final boolean withDist, final boolean withHash) { + super(); + withCoord(this, withCoord); + withDist(this, withDist); + withHash(this, withHash); + } + + /** + * 构造函数 + * + * @param order + * 排序 + */ + public JedisGeoRadiusParam(final Order order) { + super(); + sort(this, order); + } + + /** + * 构造函数 + * + * @param count + * 返回数量 + */ + public JedisGeoRadiusParam(final int count) { + super(); + count(count); + } + + /** + * 构造函数 + * + * @param order + * 排序 + * @param count + * 返回数量 + */ + public JedisGeoRadiusParam(final Order order, final int count) { + this(order); + count(count); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param order + * 排序 + */ + public JedisGeoRadiusParam(final boolean withCoord, final boolean withDist, final boolean withHash, + final Order order) { + this(withCoord, withDist, withHash); + sort(this, order); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param count + * 返回数量 + */ + public JedisGeoRadiusParam(final boolean withCoord, final boolean withDist, final boolean withHash, + final int count) { + this(withCoord, withDist, withHash); + count(count); + } + + /** + * 构造函数 + * + * @param withCoord + * 是否将位置元素的经度和纬度也一并返回 + * @param withDist + * 在返回位置元素的同时, 将位置元素与中心之间的距离也一并返回 + * @param withHash + * 是否以 52 位有符号整数的形式, 返回位置元素经过原始 geohash 编码的有序集合分值 + * @param order + * 排序 + * @param count + * 返回数量 + */ + public JedisGeoRadiusParam(final boolean withCoord, final boolean withDist, final boolean withHash, + final Order order, final int count) { + this(withCoord, withDist, withHash, order); + count(count); + } + + /** + * 从 {@link GeoCommands.GeoRadiusArgument} 创建 {@link JedisGeoRadiusParam} 实例 + * + * @param geoRadiusArgument + * {@link GeoCommands.GeoRadiusArgument} + * + * @return {@link JedisGeoRadiusParam} 实例 + * + * @since 3.0.0 + */ + public static JedisGeoRadiusParam from(final GeoCommands.GeoRadiusArgument geoRadiusArgument) { + final JedisGeoRadiusParam geoRadiusParam = new JedisGeoRadiusParam(); + + if(geoRadiusArgument != null){ + withCoord(geoRadiusParam, geoRadiusArgument.isWithCoord()); + withDist(geoRadiusParam, geoRadiusArgument.isWithDist()); + withHash(geoRadiusParam, geoRadiusArgument.isWithHash()); + sort(geoRadiusParam, geoRadiusArgument.getOrder()); + Optional.ofNullable(geoRadiusArgument.getCount()).ifPresent(geoRadiusParam::count); + } + + return geoRadiusParam; + } + + private static void withCoord(final JedisGeoRadiusParam geoRadiusParam, final Boolean withCoord) { + if(Boolean.TRUE.equals(withCoord)){ + geoRadiusParam.withCoord(); + } + } + + private static void withDist(final JedisGeoRadiusParam geoRadiusParam, final Boolean withDist) { + if(Boolean.TRUE.equals(withDist)){ + geoRadiusParam.withDist(); + } + } + + private static void withHash(final JedisGeoRadiusParam geoRadiusParam, final Boolean withHash) { + if(Boolean.TRUE.equals(withHash)){ + geoRadiusParam.withHash(); + } + } + + private static void sort(final JedisGeoRadiusParam geoRadiusParam, final Order order) { + if(order == Order.ASC){ + geoRadiusParam.sortAscending(); + }else if(order == Order.DESC){ + geoRadiusParam.sortDescending(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisGetExParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisGetExParams.java new file mode 100644 index 000000000..81ec2f380 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisGetExParams.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.command.StringCommands; +import redis.clients.jedis.params.GetExParams; + +import java.util.Optional; + +/** + * Jedis {@link GetExParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisGetExParams extends GetExParams { + + public JedisGetExParams() { + super(); + } + + public JedisGetExParams(final boolean persist) { + super(); + persist(this, persist); + } + + public JedisGetExParams(final long ex, final long exAt, final long px, final long pxAt) { + super(); + ex(ex); + exAt(exAt); + px(px); + pxAt(pxAt); + } + + public JedisGetExParams(final long ex, final long exAt, final long px, final long pxAt, final boolean persist) { + this(ex, exAt, px, pxAt); + persist(this, persist); + } + + public static JedisGetExParams from(final StringCommands.GetExArgument getExArgument) { + final JedisGetExParams getExParams = new JedisGetExParams(); + + if(getExArgument != null){ + Optional.ofNullable(getExArgument.getEx()).ifPresent(getExParams::ex); + Optional.ofNullable(getExArgument.getExAt()).ifPresent(getExParams::exAt); + Optional.ofNullable(getExArgument.getPx()).ifPresent(getExParams::px); + Optional.ofNullable(getExArgument.getPxAt()).ifPresent(getExParams::pxAt); + persist(getExParams, getExArgument.isPersist()); + } + + return getExParams; + } + + private static void persist(final JedisGetExParams getExParams, final Boolean persist) { + if(Boolean.TRUE.equals(persist)){ + getExParams.persist(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisLPosParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisLPosParams.java new file mode 100644 index 000000000..08fd69641 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisLPosParams.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.command.ListCommands; +import redis.clients.jedis.params.LPosParams; + +import java.util.Optional; + +/** + * Jedis {@link LPosParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisLPosParams extends LPosParams { + + public JedisLPosParams() { + super(); + } + + public JedisLPosParams(final int rank) { + super(); + rank(rank); + } + + public JedisLPosParams(final int rank, final int maxLen) { + super(); + rank(rank); + maxlen(maxLen); + } + + public static JedisLPosParams from(final ListCommands.LPosArgument lPosArgument) { + final JedisLPosParams lPosParams = new JedisLPosParams(); + + if(lPosArgument != null){ + Optional.ofNullable(lPosArgument.getRank()).ifPresent(lPosParams::rank); + Optional.ofNullable(lPosArgument.getMaxLen()).ifPresent(lPosParams::maxlen); + } + + return lPosParams; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisMigrateParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisMigrateParams.java index 55a5d56af..788ed00fe 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisMigrateParams.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisMigrateParams.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.jedis; @@ -29,16 +29,18 @@ import redis.clients.jedis.params.MigrateParams; /** + * Jedis {@link MigrateParams} 扩展 + * * @author Yong.Teng * @since 2.0.0 */ public final class JedisMigrateParams extends MigrateParams { - public JedisMigrateParams(){ + public JedisMigrateParams() { super(); } - public JedisMigrateParams(final MigrateOperation migrateOperation){ + public JedisMigrateParams(final MigrateOperation migrateOperation) { super(); switch(migrateOperation){ case COPY: @@ -52,39 +54,39 @@ public JedisMigrateParams(final MigrateOperation migrateOperation){ } } - public JedisMigrateParams(final String password){ + public JedisMigrateParams(final String password) { super(); auth(password); } - public JedisMigrateParams(final byte[] password){ + public JedisMigrateParams(final byte[] password) { this(SafeEncoder.encode(password)); } - public JedisMigrateParams(final String username, final String password){ + public JedisMigrateParams(final String username, final String password) { super(); auth2(username, password); } - public JedisMigrateParams(final byte[] username, final byte[] password){ + public JedisMigrateParams(final byte[] username, final byte[] password) { this(SafeEncoder.encode(username), SafeEncoder.encode(password)); } - public JedisMigrateParams(final MigrateOperation migrateOperation, final String password){ + public JedisMigrateParams(final MigrateOperation migrateOperation, final String password) { this(migrateOperation); auth(password); } - public JedisMigrateParams(final MigrateOperation migrateOperation, final byte[] password){ + public JedisMigrateParams(final MigrateOperation migrateOperation, final byte[] password) { this(migrateOperation, SafeEncoder.encode(password)); } - public JedisMigrateParams(final MigrateOperation migrateOperation, final String username, final String password){ + public JedisMigrateParams(final MigrateOperation migrateOperation, final String username, final String password) { this(migrateOperation); auth2(username, password); } - public JedisMigrateParams(final MigrateOperation migrateOperation, final byte[] username, final byte[] password){ + public JedisMigrateParams(final MigrateOperation migrateOperation, final byte[] username, final byte[] password) { this(migrateOperation, SafeEncoder.encode(username), SafeEncoder.encode(password)); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisRestoreParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisRestoreParams.java new file mode 100644 index 000000000..3bdd9ff0e --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisRestoreParams.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.command.KeyCommands; +import redis.clients.jedis.params.RestoreParams; + +import java.util.Optional; + +/** + * Jedis {@link RestoreParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisRestoreParams extends RestoreParams { + + public JedisRestoreParams() { + super(); + } + + public JedisRestoreParams(final boolean replace) { + super(); + replace(this, replace); + } + + public JedisRestoreParams(final boolean replace, final boolean absTtl) { + this(replace); + absTtl(this, absTtl); + } + + public JedisRestoreParams(final boolean replace, final boolean absTtl, final long idleTime, final long frequency) { + this(replace, absTtl); + idleTime(idleTime); + frequency(frequency); + } + + public static JedisRestoreParams from(final KeyCommands.RestoreArgument argument) { + final JedisRestoreParams restoreParams = new JedisRestoreParams(); + + if(argument != null){ + replace(restoreParams, argument.isReplace()); + absTtl(restoreParams, argument.isAbsTtl()); + Optional.ofNullable(argument.getIdleTime()).ifPresent(restoreParams::idleTime); + Optional.ofNullable(argument.getFrequency()).ifPresent(restoreParams::frequency); + } + + return restoreParams; + } + + private static void replace(final JedisRestoreParams restoreParams, final Boolean replace) { + if(Boolean.TRUE.equals(replace)){ + restoreParams.replace(); + } + } + + private static void absTtl(final JedisRestoreParams restoreParams, final Boolean absTtl) { + if(Boolean.TRUE.equals(absTtl)){ + restoreParams.absTtl(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisResult.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisResult.java index 6125073bd..5a11bc56f 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisResult.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisResult.java @@ -19,13 +19,14 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.jedis; import com.buession.core.converter.Converter; import com.buession.redis.core.FutureResult; +import com.buession.redis.core.internal.convert.Converters; import redis.clients.jedis.Response; /** @@ -33,13 +34,13 @@ * * @author Yong.Teng */ -public class JedisResult extends FutureResult, SV, TV> { +public class JedisResult extends FutureResult> { public JedisResult(final Response resultHolder) { super(resultHolder); } - public JedisResult(final Response resultHolder, final Converter converter) { + public JedisResult(final Response resultHolder, final Converter converter) { super(resultHolder, converter); } @@ -59,14 +60,8 @@ private Builder(final Response response, final Converter converter) this.converter = converter; } - @Deprecated - public static Builder forResponse(Response response) { - return fromResponse(response); - } - - @SuppressWarnings("unchecked") public static Builder fromResponse(Response response) { - return new Builder<>(response, (source)->(TV) source); + return new Builder<>(response, Converters.always()); } public Builder mappedWith(Converter converter) { diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisScanParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisScanParams.java index a04d01e48..e2924e7fc 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisScanParams.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisScanParams.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.jedis; @@ -27,50 +27,52 @@ import redis.clients.jedis.params.ScanParams; /** + * Jedis {@link ScanParams} 扩展 + * * @author Yong.Teng */ public final class JedisScanParams extends ScanParams { - public JedisScanParams(){ + public JedisScanParams() { super(); } - public JedisScanParams(final String pattern){ + public JedisScanParams(final String pattern) { super(); match(pattern); } - public JedisScanParams(final byte[] pattern){ + public JedisScanParams(final byte[] pattern) { super(); match(pattern); } - public JedisScanParams(final int count){ + public JedisScanParams(final int count) { super(); count(count); } - public JedisScanParams(final String pattern, final int count){ + public JedisScanParams(final String pattern, final int count) { super(); match(pattern); count(count); } - public JedisScanParams(final byte[] pattern, final int count){ + public JedisScanParams(final byte[] pattern, final int count) { super(); match(pattern); count(count); } - public JedisScanParams(final long count){ + public JedisScanParams(final long count) { this((int) count); } - public JedisScanParams(final String pattern, final long count){ + public JedisScanParams(final String pattern, final long count) { this(pattern, (int) count); } - public JedisScanParams(final byte[] pattern, final long count){ + public JedisScanParams(final byte[] pattern, final long count) { this(pattern, (int) count); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisSetParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisSetParams.java new file mode 100644 index 000000000..dbc096748 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisSetParams.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.NxXx; +import com.buession.redis.core.command.StringCommands; +import redis.clients.jedis.params.SetParams; + +import java.util.Optional; + +/** + * Jedis {@link SetParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisSetParams extends SetParams { + + public JedisSetParams() { + super(); + } + + public JedisSetParams(final NxXx nx) { + super(); + nxxx(this, nx); + } + + public JedisSetParams(final boolean keepTtl) { + super(); + keepTtl(this, keepTtl); + } + + public JedisSetParams(final long ex, final long exAt, final long px, final long pxAt) { + super(); + ex(ex); + exAt(exAt); + px(px); + pxAt(pxAt); + } + + public JedisSetParams(final long ex, final long exAt, final long px, final long pxAt, final NxXx nx) { + this(ex, exAt, px, pxAt); + nxxx(this, nx); + } + + public JedisSetParams(final long ex, final long exAt, final long px, final long pxAt, final boolean keepTtl) { + this(ex, exAt, px, pxAt); + keepTtl(this, keepTtl); + } + + public JedisSetParams(final long ex, final long exAt, final long px, final long pxAt, final NxXx nx, + final boolean keepTtl) { + this(ex, exAt, px, pxAt, nx); + keepTtl(this, keepTtl); + } + + public static JedisSetParams from(final StringCommands.SetArgument setArgument) { + final JedisSetParams setParams = new JedisSetParams(); + + if(setArgument != null){ + Optional.ofNullable(setArgument.getEx()).ifPresent(setParams::ex); + Optional.ofNullable(setArgument.getExAt()).ifPresent(setParams::exAt); + Optional.ofNullable(setArgument.getPx()).ifPresent(setParams::px); + Optional.ofNullable(setArgument.getPxAt()).ifPresent(setParams::pxAt); + + nxxx(setParams, setArgument.getNxXx()); + keepTtl(setParams, setArgument.isKeepTtl()); + } + + return setParams; + } + + private static void nxxx(final JedisSetParams setParams, final NxXx nx) { + if(nx == NxXx.NX){ + setParams.nx(); + }else if(nx == NxXx.XX){ + setParams.xx(); + } + } + + private static void keepTtl(final JedisSetParams setParams, final Boolean keepTtl) { + if(Boolean.TRUE.equals(keepTtl)){ + setParams.keepttl(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisSortingParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisSortingParams.java new file mode 100644 index 000000000..942443d9a --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisSortingParams.java @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.lang.Order; +import com.buession.redis.core.Limit; +import com.buession.redis.core.command.KeyCommands; +import redis.clients.jedis.params.SortingParams; + +import java.util.Optional; + +/** + * Jedis {@link SortingParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisSortingParams extends SortingParams { + + public JedisSortingParams() { + super(); + } + + public JedisSortingParams(final String by) { + super(); + by(by); + } + + public JedisSortingParams(final byte[] by) { + super(); + by(by); + } + + public JedisSortingParams(final String by, final String[] gets) { + super(); + by(by); + get(gets); + } + + public JedisSortingParams(final byte[] by, final byte[][] gets) { + super(); + by(by); + get(gets); + } + + public JedisSortingParams(final String by, final Order order) { + this(by); + order(this, order); + } + + public JedisSortingParams(final byte[] by, final Order order) { + this(by); + order(this, order); + } + + public JedisSortingParams(final String by, final String[] gets, final Order order) { + this(by, gets); + order(this, order); + } + + public JedisSortingParams(final byte[] by, final byte[][] gets, final Order order) { + this(by, gets); + order(this, order); + } + + public JedisSortingParams(final String by, final String[] gets, final Limit limit) { + this(by, gets); + limit(this, limit); + } + + public JedisSortingParams(final byte[] by, final byte[][] gets, final Limit limit) { + this(by, gets); + limit(this, limit); + } + + public JedisSortingParams(final String by, final String[] gets, final Order order, final Limit limit) { + this(by, gets, order); + limit(this, limit); + } + + public JedisSortingParams(final byte[] by, final byte[][] gets, final Order order, final Limit limit) { + this(by, gets, order); + limit(this, limit); + } + + public JedisSortingParams(final String by, final String[] gets, final Order order, final Limit limit, + final boolean alpha) { + this(by, gets, order, limit); + alpha(this, alpha); + } + + public JedisSortingParams(final byte[] by, final byte[][] gets, final Order order, final Limit limit, + final boolean alpha) { + this(by, gets, order, limit); + alpha(this, alpha); + } + + public static JedisSortingParams from(final KeyCommands.SortArgument sortArgument) { + final JedisSortingParams sortingParams = new JedisSortingParams(); + + if(sortArgument != null){ + Optional.ofNullable(sortArgument.getBy()).ifPresent(sortingParams::by); + Optional.ofNullable(sortArgument.getGetPatterns()).ifPresent(sortingParams::get); + order(sortingParams, sortArgument.getOrder()); + limit(sortingParams, sortArgument.getLimit()); + alpha(sortingParams, sortArgument.isAlpha()); + } + + return sortingParams; + } + + private static void alpha(final JedisSortingParams sortingParams, final Boolean alpha) { + if(Boolean.TRUE.equals(alpha)){ + sortingParams.alpha(); + } + } + + private static void limit(final JedisSortingParams sortingParams, final Limit limit) { + if(limit != null){ + sortingParams.limit((int) limit.getOffset(), (int) limit.getCount()); + } + } + + private static void order(final JedisSortingParams sortingParams, final Order order) { + if(order == Order.ASC){ + sortingParams.asc(); + }else if(order == Order.DESC){ + sortingParams.desc(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisStreamEntryID.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisStreamEntryID.java new file mode 100644 index 000000000..ded357fed --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisStreamEntryID.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.StreamEntryId; +import redis.clients.jedis.StreamEntryID; + +/** + * Jedis {@link StreamEntryID} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisStreamEntryID extends StreamEntryID { + + public JedisStreamEntryID() { + super(); + } + + public JedisStreamEntryID(final String id) { + super(id); + } + + public JedisStreamEntryID(final byte[] id) { + super(id); + } + + public JedisStreamEntryID(final long time) { + super(time); + } + + public JedisStreamEntryID(final long time, final long sequence) { + super(time, sequence); + } + + public static JedisStreamEntryID from(final StreamEntryId streamEntryId) { + if(streamEntryId == null){ + return new JedisStreamEntryID(); + }else{ + return new JedisStreamEntryID(streamEntryId.getTime(), streamEntryId.getSequence()); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXAddParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXAddParams.java new file mode 100644 index 000000000..1c9916bf1 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXAddParams.java @@ -0,0 +1,242 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.command.StreamCommands; +import com.buession.redis.utils.SafeEncoder; +import redis.clients.jedis.StreamEntryID; +import redis.clients.jedis.params.XAddParams; + +import java.util.Optional; + +/** + * Jedis {@link XAddParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisXAddParams extends XAddParams { + + public JedisXAddParams() { + super(); + } + + public JedisXAddParams(final String id) { + super(); + id(id); + } + + public JedisXAddParams(final byte[] id) { + super(); + id(id); + } + + public JedisXAddParams(final StreamEntryID id) { + super(); + id(id); + } + + public JedisXAddParams(final StreamEntryId id) { + this(JedisStreamEntryID.from(id)); + } + + public JedisXAddParams(final String id, final String minId) { + this(id); + minId(minId); + } + + public JedisXAddParams(final byte[] id, final byte[] minId) { + this(id); + minId(SafeEncoder.encode(minId)); + } + + public JedisXAddParams(final StreamEntryID id, final String minId) { + this(id); + minId(minId); + } + + public JedisXAddParams(final StreamEntryID id, final byte[] minId) { + this(id); + minId(SafeEncoder.encode(minId)); + } + + public JedisXAddParams(final StreamEntryId id, final String minId) { + this(id); + minId(minId); + } + + public JedisXAddParams(final StreamEntryId id, final byte[] minId) { + this(id); + minId(SafeEncoder.encode(minId)); + } + + public JedisXAddParams(final long maxLen) { + super(); + maxLen(maxLen); + } + + public JedisXAddParams(final String id, final long maxLen) { + this(id); + maxLen(maxLen); + } + + public JedisXAddParams(final byte[] id, final long maxLen) { + this(id); + maxLen(maxLen); + } + + public JedisXAddParams(final StreamEntryID id, final long maxLen) { + this(id); + maxLen(maxLen); + } + + public JedisXAddParams(final StreamEntryId id, final long maxLen) { + this(id); + maxLen(maxLen); + } + + public JedisXAddParams(final String id, final String minId, final long maxLen) { + this(id, minId); + maxLen(maxLen); + } + + public JedisXAddParams(final byte[] id, final byte[] minId, final long maxLen) { + this(id, minId); + maxLen(maxLen); + } + + public JedisXAddParams(final StreamEntryID id, final String minId, final long maxLen) { + this(id, minId); + maxLen(maxLen); + } + + public JedisXAddParams(final StreamEntryID id, final byte[] minId, final long maxLen) { + this(id, minId); + maxLen(maxLen); + } + + public JedisXAddParams(final StreamEntryId id, final String minId, final long maxLen) { + this(id, minId); + maxLen(maxLen); + } + + public JedisXAddParams(final StreamEntryId id, final byte[] minId, final long maxLen) { + this(id, minId); + maxLen(maxLen); + } + + public JedisXAddParams(final String id, final String minId, final long maxLen, final boolean approximateTrimming, + final boolean exactTrimming, final boolean noMkStream, final long limit) { + this(id, minId, maxLen); + approximateTrimming(this, approximateTrimming); + exactTrimming(this, exactTrimming); + noMkStream(this, noMkStream); + limit(limit); + } + + public JedisXAddParams(final byte[] id, final byte[] minId, final long maxLen, final boolean approximateTrimming, + final boolean exactTrimming, final boolean noMkStream, final long limit) { + this(id, minId, maxLen); + approximateTrimming(this, approximateTrimming); + exactTrimming(this, exactTrimming); + noMkStream(this, noMkStream); + limit(limit); + } + + public JedisXAddParams(final StreamEntryID id, final String minId, final long maxLen, + final boolean approximateTrimming, final boolean exactTrimming, final boolean noMkStream, + final long limit) { + this(id, minId, maxLen); + approximateTrimming(this, approximateTrimming); + exactTrimming(this, exactTrimming); + noMkStream(this, noMkStream); + limit(limit); + } + + public JedisXAddParams(final StreamEntryID id, final byte[] minId, final long maxLen, + final boolean approximateTrimming, final boolean exactTrimming, final boolean noMkStream, + final long limit) { + this(id, minId, maxLen); + approximateTrimming(this, approximateTrimming); + exactTrimming(this, exactTrimming); + noMkStream(this, noMkStream); + limit(limit); + } + + public JedisXAddParams(final StreamEntryId id, final String minId, final long maxLen, + final boolean approximateTrimming, final boolean exactTrimming, final boolean noMkStream, + final long limit) { + this(id, minId, maxLen); + approximateTrimming(this, approximateTrimming); + exactTrimming(this, exactTrimming); + noMkStream(this, noMkStream); + limit(limit); + } + + public JedisXAddParams(final StreamEntryId id, final byte[] minId, final long maxLen, + final boolean approximateTrimming, final boolean exactTrimming, final boolean noMkStream, + final long limit) { + this(id, minId, maxLen); + approximateTrimming(this, approximateTrimming); + exactTrimming(this, exactTrimming); + noMkStream(this, noMkStream); + limit(limit); + } + + public static JedisXAddParams from(final StreamCommands.XAddArgument xAddArgument) { + final JedisXAddParams xAddParams = new JedisXAddParams(); + + if(xAddArgument != null){ + Optional.ofNullable(xAddArgument.getMinId()).ifPresent(xAddParams::minId); + Optional.ofNullable(xAddArgument.getMaxLen()).ifPresent(xAddParams::maxLen); + approximateTrimming(xAddParams, xAddArgument.isApproximateTrimming()); + exactTrimming(xAddParams, xAddArgument.isExactTrimming()); + noMkStream(xAddParams, xAddArgument.isNoMkStream()); + Optional.ofNullable(xAddArgument.getLimit()).ifPresent(xAddParams::limit); + } + + return xAddParams; + } + + private static void approximateTrimming(final JedisXAddParams xAddParams, final Boolean approximateTrimming) { + if(Boolean.TRUE.equals(approximateTrimming)){ + xAddParams.approximateTrimming(); + } + } + + private static void exactTrimming(final JedisXAddParams xAddParams, final Boolean exactTrimming) { + if(Boolean.TRUE.equals(exactTrimming)){ + xAddParams.exactTrimming(); + } + } + + private static void noMkStream(final JedisXAddParams xAddParams, final Boolean noMkStream) { + if(Boolean.TRUE.equals(noMkStream)){ + xAddParams.noMkStream(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXClaimParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXClaimParams.java new file mode 100644 index 000000000..be71bc9b2 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXClaimParams.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.command.StreamCommands; +import redis.clients.jedis.params.XClaimParams; + +/** + * Jedis {@link XClaimParams} 扩展类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class JedisXClaimParams extends XClaimParams { + + public JedisXClaimParams() { + super(); + } + + public static JedisXClaimParams from(final StreamCommands.XClaimArgument xClaimArgument) { + final JedisXClaimParams xClaimParams = new JedisXClaimParams(); + + return xClaimParams; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXPendingParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXPendingParams.java index 90e3d48b7..78d96fd23 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXPendingParams.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXPendingParams.java @@ -19,59 +19,59 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.jedis; import com.buession.redis.core.StreamEntryId; -import com.buession.redis.core.internal.convert.jedis.params.StreamEntryIdConverter; import redis.clients.jedis.params.XPendingParams; /** + * Jedis {@link XPendingParams} 扩展 + * * @author Yong.Teng * @since 2.0.0 */ -public class JedisXPendingParams extends XPendingParams { +public final class JedisXPendingParams extends XPendingParams { - public JedisXPendingParams(){ + public JedisXPendingParams() { super(); } - public JedisXPendingParams(final long minIdleTime){ + public JedisXPendingParams(final long idle) { this(); - idle(minIdleTime); + idle(idle); } - public JedisXPendingParams(final long minIdleTime, final StreamEntryId start, final StreamEntryId end, - final long count){ + public JedisXPendingParams(final long idle, final StreamEntryId start, final StreamEntryId end, + final long count) { this(start, end, count); - idle(minIdleTime); + idle(idle); } - public JedisXPendingParams(final long minIdleTime, final String consumer){ - this(minIdleTime); + public JedisXPendingParams(final long idle, final String consumer) { + this(idle); consumer(consumer); } - public JedisXPendingParams(final StreamEntryId start, final StreamEntryId end, final long count){ - super(StreamEntryIdConverter.INSTANCE.convert(start), StreamEntryIdConverter.INSTANCE.convert(end), - (int) count); + public JedisXPendingParams(final StreamEntryId start, final StreamEntryId end, final long count) { + super(JedisStreamEntryID.from(start), JedisStreamEntryID.from(end), (int) count); } public JedisXPendingParams(final StreamEntryId start, final StreamEntryId end, final long count, - final String consumer){ + final String consumer) { this(start, end, count); consumer(consumer); } - public JedisXPendingParams(final long minIdleTime, final StreamEntryId start, final StreamEntryId end, - final long count, final String consumer){ - this(minIdleTime, start, end, count); + public JedisXPendingParams(final long idle, final StreamEntryId start, final StreamEntryId end, + final long count, final String consumer) { + this(idle, start, end, count); consumer(consumer); } - public JedisXPendingParams(final String consumer){ + public JedisXPendingParams(final String consumer) { this(); consumer(consumer); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXReadGroupParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXReadGroupParams.java index 9929f6750..78316867e 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXReadGroupParams.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXReadGroupParams.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.jedis; @@ -30,43 +30,43 @@ * @author Yong.Teng * @since 2.0.0 */ -public class JedisXReadGroupParams extends XReadGroupParams { +public final class JedisXReadGroupParams extends XReadGroupParams { - public JedisXReadGroupParams(){ + public JedisXReadGroupParams() { super(); } - public JedisXReadGroupParams(final long count){ + public JedisXReadGroupParams(final long count) { super(); count((int) count); } - public JedisXReadGroupParams(final long count, final int block){ + public JedisXReadGroupParams(final long count, final int block) { this(count); block(block); } - public JedisXReadGroupParams(final long count, final boolean noAck){ + public JedisXReadGroupParams(final long count, final boolean noAck) { this(noAck); count((int) count); } - public JedisXReadGroupParams(final long count, final int block, final boolean noAck){ + public JedisXReadGroupParams(final long count, final int block, final boolean noAck) { this(count, noAck); block(block); } - public JedisXReadGroupParams(final int block){ + public JedisXReadGroupParams(final int block) { super(); block(block); } - public JedisXReadGroupParams(final int block, final boolean noAck){ + public JedisXReadGroupParams(final int block, final boolean noAck) { this(noAck); block(block); } - public JedisXReadGroupParams(final boolean noAck){ + public JedisXReadGroupParams(final boolean noAck) { super(); if(noAck){ diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXReadParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXReadParams.java index 715c0be8b..fff7cf1a2 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXReadParams.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXReadParams.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.jedis; @@ -30,23 +30,23 @@ * @author Yong.Teng * @since 2.0.0 */ -public class JedisXReadParams extends XReadParams { +public final class JedisXReadParams extends XReadParams { - public JedisXReadParams(){ + public JedisXReadParams() { super(); } - public JedisXReadParams(final long count){ + public JedisXReadParams(final long count) { super(); count((int) count); } - public JedisXReadParams(final long count, final int block){ + public JedisXReadParams(final long count, final int block) { this(count); block(block); } - public JedisXReadParams(final int block){ + public JedisXReadParams(final int block) { super(); block(block); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXTrimParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXTrimParams.java new file mode 100644 index 000000000..59f16bc88 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisXTrimParams.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.jedis; + +import com.buession.redis.core.command.StreamCommands; +import redis.clients.jedis.params.XTrimParams; + +import java.util.Optional; + +/** + * Jedis {@link XTrimParams} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class JedisXTrimParams extends XTrimParams { + + public JedisXTrimParams() { + super(); + } + + public JedisXTrimParams(final long maxLen) { + super(); + maxLen(maxLen); + } + + public JedisXTrimParams(final long maxLen, final String minId) { + this(maxLen); + minId(minId); + } + + public JedisXTrimParams(final long maxLen, final long limit) { + this(maxLen); + limit(limit); + } + + public JedisXTrimParams(final long maxLen, final String minId, final long limit) { + this(maxLen, minId); + limit(limit); + } + + public JedisXTrimParams(final long maxLen, final boolean approximateTrimming, final boolean exactTrimming) { + this(maxLen); + approximateTrimming(this, approximateTrimming); + exactTrimming(this, exactTrimming); + } + + public JedisXTrimParams(final long maxLen, final String minId, final long limit, final boolean approximateTrimming, + final boolean exactTrimming) { + this(maxLen, approximateTrimming, exactTrimming); + maxLen(maxLen); + minId(minId); + limit(limit); + } + + public static JedisXTrimParams from(final StreamCommands.XTrimArgument xTrimArgument) { + final JedisXTrimParams xTrimParams = new JedisXTrimParams(); + + if(xTrimArgument != null){ + Optional.ofNullable(xTrimArgument.getMaxLen()).ifPresent(xTrimParams::maxLen); + Optional.ofNullable(xTrimArgument.getMinId()).ifPresent(xTrimParams::minId); + Optional.ofNullable(xTrimArgument.getLimit()).ifPresent(xTrimParams::limit); + + approximateTrimming(xTrimParams, xTrimArgument.isApproximateTrimming()); + exactTrimming(xTrimParams, xTrimArgument.isExactTrimming()); + } + + return xTrimParams; + } + + private static void approximateTrimming(final JedisXTrimParams xTrimParams, final Boolean approximateTrimming) { + if(Boolean.TRUE.equals(approximateTrimming)){ + xTrimParams.approximateTrimming(); + } + } + + private static void exactTrimming(final JedisXTrimParams xTrimParams, final Boolean exactTrimming) { + if(Boolean.TRUE.equals(exactTrimming)){ + xTrimParams.exactTrimming(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZAddParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZAddParams.java index 7383ed68a..220cd63dd 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZAddParams.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZAddParams.java @@ -19,19 +19,22 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.jedis; import com.buession.redis.core.GtLt; import com.buession.redis.core.NxXx; +import redis.clients.jedis.params.ZAddParams; /** + * Jedis {@link ZAddParams} 扩展 + * * @author Yong.Teng * @since 2.0.0 */ -public final class JedisZAddParams extends redis.clients.jedis.params.ZAddParams { +public final class JedisZAddParams extends ZAddParams { /** * 构造函数 @@ -139,15 +142,17 @@ public JedisZAddParams(final NxXx nxXx, final GtLt gtLt, final boolean ch) { * 更新成员方式 */ private void nxXx(final NxXx nxXx) { - switch(nxXx){ - case NX: - nx(); - break; - case XX: - xx(); - break; - default: - break; + if(nxXx != null){ + switch(nxXx){ + case NX: + nx(); + break; + case XX: + xx(); + break; + default: + break; + } } } @@ -158,15 +163,17 @@ private void nxXx(final NxXx nxXx) { * 更新新的分值方式 */ private void gtLt(final GtLt gtLt) { - switch(gtLt){ - case GT: - gt(); - break; - case LT: - lt(); - break; - default: - break; + if(gtLt != null){ + switch(gtLt){ + case GT: + gt(); + break; + case LT: + lt(); + break; + default: + break; + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZParams.java index a7db90366..06d1bb6ed 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZParams.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZParams.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2020 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.jedis; @@ -34,7 +34,7 @@ public final class JedisZParams extends ZParams { /** * 构造函数 */ - public JedisZParams(){ + public JedisZParams() { super(); } @@ -44,7 +44,8 @@ public JedisZParams(){ * @param aggregate * {@link Aggregate} */ - public JedisZParams(final com.buession.redis.core.Aggregate aggregate){ + public JedisZParams(final com.buession.redis.core.Aggregate aggregate) { + super(); aggregate(aggregate); } @@ -54,7 +55,8 @@ public JedisZParams(final com.buession.redis.core.Aggregate aggregate){ * @param weights * 权重 */ - public JedisZParams(final double... weights){ + public JedisZParams(final double... weights) { + super(); weights(weights); } @@ -66,24 +68,27 @@ public JedisZParams(final double... weights){ * @param weights * 权重 */ - public JedisZParams(final com.buession.redis.core.Aggregate aggregate, final double... weights){ + public JedisZParams(final com.buession.redis.core.Aggregate aggregate, final double... weights) { + super(); aggregate(aggregate); weights(weights); } - private void aggregate(final com.buession.redis.core.Aggregate aggregate){ - switch(aggregate){ - case MIN: - aggregate(Aggregate.MIN); - break; - case MAX: - aggregate(Aggregate.MAX); - break; - case SUM: - aggregate(Aggregate.SUM); - break; - default: - break; + private void aggregate(final com.buession.redis.core.Aggregate aggregate) { + if(aggregate != null){ + switch(aggregate){ + case MIN: + aggregate(Aggregate.MIN); + break; + case MAX: + aggregate(Aggregate.MAX); + break; + case SUM: + aggregate(Aggregate.SUM); + break; + default: + break; + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZRangeParams.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZRangeParams.java index fe8532c4c..f04aa53ca 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZRangeParams.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/JedisZRangeParams.java @@ -19,11 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.internal.jedis; +import com.buession.core.utils.NumberUtils; import com.buession.redis.core.ZRangeBy; import redis.clients.jedis.Protocol; import redis.clients.jedis.params.ZRangeParams; @@ -43,11 +44,11 @@ public JedisZRangeParams(final long min, final long max) { } public JedisZRangeParams(final ZRangeBy by, final int min, final int max) { - super(byKeyword(by), Integer.toString(min), Integer.toString(max)); + super(byKeyword(by), NumberUtils.int2bytes(min), NumberUtils.int2bytes(max)); } public JedisZRangeParams(final ZRangeBy by, final long min, final long max) { - super(byKeyword(by), Long.toString(min), Long.toString(max)); + super(byKeyword(by), NumberUtils.long2bytes(min), NumberUtils.long2bytes(max)); } public JedisZRangeParams(final ZRangeBy by, final int min, final int max, final boolean rev) { @@ -111,14 +112,18 @@ public JedisZRangeParams(final ZRangeBy by, final long min, final long max, fina } private static Protocol.Keyword byKeyword(final ZRangeBy by) { - switch(by){ - case BYLEX: - return Protocol.Keyword.BYLEX; - case BYSCORE: - return Protocol.Keyword.BYSCORE; - default: - return null; + if(by != null){ + switch(by){ + case BYLEX: + return Protocol.Keyword.BYLEX; + case BYSCORE: + return Protocol.Keyword.BYSCORE; + default: + break; + } } + + return null; } private void rev(boolean rev) { diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/package-info.java b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/package-info.java index 28596ad47..c8d311672 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/package-info.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/jedis/package-info.java @@ -19,7 +19,10 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ +/** + * @author Yong.Teng + */ package com.buession.redis.core.internal.jedis; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceBitFieldArgs.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceBitFieldArgs.java new file mode 100644 index 000000000..c31ef1894 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceBitFieldArgs.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.command.BitMapCommands; +import io.lettuce.core.BitFieldArgs; + +/** + * Lettuce {@link BitFieldArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceBitFieldArgs extends BitFieldArgs { + + public LettuceBitFieldArgs() { + super(); + } + + public LettuceBitFieldArgs(final int set, final int get, final int incrBy) { + super(); + set(set); + get(set); + incrBy(incrBy); + } + + public LettuceBitFieldArgs(final int set, final int get, final int incrBy, + final BitMapCommands.BitFieldArgument.Overflow overflow) { + this(set, get, incrBy); + overflow(this, overflow); + } + + public static LettuceBitFieldArgs from(final BitMapCommands.BitFieldArgument bitFieldArgument) { + final LettuceBitFieldArgs bitFieldArgs = new LettuceBitFieldArgs(); + + if(bitFieldArgument != null){ + final BitMapCommands.BitFieldArgument.Op setOp = bitFieldArgument.getSet(); + if(setOp != null){ + bitFieldArgs.set( + setOp.getBitFieldType().isSigned() ? BitFieldArgs.signed(setOp.getBitFieldType().getBits()) : + BitFieldArgs.unsigned(setOp.getBitFieldType().getBits()), setOp.getOffset(), + setOp.getValue()); + } + + final BitMapCommands.BitFieldArgument.Op getOp = bitFieldArgument.getSet(); + if(getOp != null){ + bitFieldArgs.get( + getOp.getBitFieldType().isSigned() ? BitFieldArgs.signed(getOp.getBitFieldType().getBits()) : + BitFieldArgs.unsigned(getOp.getBitFieldType().getBits()), getOp.getOffset()); + } + + final BitMapCommands.BitFieldArgument.Op incrByOp = bitFieldArgument.getIncrBy(); + if(incrByOp != null){ + bitFieldArgs.incrBy( + incrByOp.getBitFieldType().isSigned() ? BitFieldArgs.signed( + incrByOp.getBitFieldType().getBits()) : + BitFieldArgs.unsigned(incrByOp.getBitFieldType().getBits()), incrByOp.getOffset(), + incrByOp.getValue()); + } + + overflow(bitFieldArgs, bitFieldArgument.getOverflow()); + } + + return bitFieldArgs; + } + + private static void overflow(final BitFieldArgs bitFieldArgs, + final BitMapCommands.BitFieldArgument.Overflow overflow) { + if(overflow != null){ + switch(overflow){ + case FAIL: + bitFieldArgs.overflow(OverflowType.FAIL); + break; + case SAT: + bitFieldArgs.overflow(OverflowType.SAT); + break; + case WRAP: + bitFieldArgs.overflow(OverflowType.WRAP); + break; + default: + break; + } + } + + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceClientConfigBuilder.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceClientConfigBuilder.java new file mode 100644 index 000000000..0dba10b56 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceClientConfigBuilder.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.validator.Validate; +import com.buession.net.ssl.SslConfiguration; +import com.buession.redis.client.connection.datasource.lettuce.LettuceRedisDataSource; +import io.lettuce.core.DefaultLettuceClientConfig; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceClientConfigBuilder { + + private final DefaultLettuceClientConfig.Builder builder = DefaultLettuceClientConfig.builder(); + + private final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); + + private LettuceClientConfigBuilder(final LettuceRedisDataSource dataSource, + final SslConfiguration sslConfiguration) { + builder.connectionTimeoutMillis(dataSource.getConnectTimeout()) + .socketTimeoutMillis(dataSource.getSoTimeout()) + .ssl(sslConfiguration != null); + + propertyMapper.from(dataSource.getClientName()).to(builder::clientName); + + if(Validate.hasText(dataSource.getPassword())){ + propertyMapper.from(dataSource.getUsername()).to(builder::user); + builder.password(dataSource.getPassword()); + } + + if(sslConfiguration != null){ + builder.sslSocketFactory(sslConfiguration.getSslSocketFactory()) + .sslParameters(sslConfiguration.getSslParameters()) + .hostnameVerifier(sslConfiguration.getHostnameVerifier()); + } + } + + public static LettuceClientConfigBuilder create(final LettuceRedisDataSource dataSource, + final SslConfiguration sslConfiguration) { + return new LettuceClientConfigBuilder(dataSource, sslConfiguration); + } + + public LettuceClientConfigBuilder user(final String user) { + propertyMapper.from(user).to(builder::user); + return this; + } + + public LettuceClientConfigBuilder password(final String password) { + propertyMapper.from(password).to(builder::password); + return this; + } + + public LettuceClientConfigBuilder database(final int database) { + if(database >= 0){ + builder.database(database); + } + return this; + } + + public LettuceClientConfigBuilder clientName(final String clientName) { + propertyMapper.from(clientName).to(builder::clientName); + return this; + } + + public LettuceClientConfigBuilder connectTimeout(final int connectTimeout) { + builder.connectionTimeoutMillis(connectTimeout); + return this; + } + + public LettuceClientConfigBuilder socketTimeout(final int socketTimeout) { + builder.socketTimeoutMillis(socketTimeout); + return this; + } + + public LettuceClientConfigBuilder infiniteSoTimeout(final int blockingSocketTimeout) { + return this; + } + + public DefaultLettuceClientConfig build() { + return builder.build(); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceGeoArgs.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceGeoArgs.java new file mode 100644 index 000000000..e5ea77d99 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceGeoArgs.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.lang.Order; +import com.buession.redis.core.command.GeoCommands; +import io.lettuce.core.GeoArgs; + +import java.util.Optional; + +/** + * Lettuce {@link GeoArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceGeoArgs extends GeoArgs { + + public LettuceGeoArgs() { + super(); + } + + public LettuceGeoArgs(final boolean withCoord, final boolean withDist, final boolean withHash) { + super(); + withCoordinates(this, withCoord); + withDistance(this, withDist); + withHash(this, withHash); + } + + public LettuceGeoArgs(final Order order) { + super(); + sort(this, order); + } + + public LettuceGeoArgs(final int count) { + super(); + withCount(count); + } + + public LettuceGeoArgs(final Order order, final int count) { + this(order); + withCount(count); + } + + public LettuceGeoArgs(final boolean withCoord, final boolean withDist, final boolean withHash, + final Order order) { + this(withCoord, withDist, withHash); + sort(this, order); + } + + public LettuceGeoArgs(final boolean withCoord, final boolean withDist, final boolean withHash, + final int count) { + this(withCoord, withDist, withHash); + withCount(count); + } + + public LettuceGeoArgs(final boolean withCoord, final boolean withDist, final boolean withHash, + final Order order, final int count) { + this(withCoord, withDist, withHash, order); + withCount(count); + } + + public static LettuceGeoArgs from(final GeoCommands.GeoRadiusArgument geoRadiusArgument) { + final LettuceGeoArgs geoArgs = new LettuceGeoArgs(); + + if(geoRadiusArgument != null){ + withCoordinates(geoArgs, geoRadiusArgument.isWithCoord()); + withDistance(geoArgs, geoRadiusArgument.isWithDist()); + withHash(geoArgs, geoRadiusArgument.isWithHash()); + sort(geoArgs, geoRadiusArgument.getOrder()); + Optional.ofNullable(geoRadiusArgument.getCount()).ifPresent(geoArgs::withCount); + } + + return geoArgs; + } + + private static void withCoordinates(final LettuceGeoArgs geoArgs, final Boolean withCoord) { + if(Boolean.TRUE.equals(withCoord)){ + geoArgs.withCoordinates(); + } + } + + private static void withDistance(final LettuceGeoArgs geoArgs, final Boolean withDist) { + if(Boolean.TRUE.equals(withDist)){ + geoArgs.withDistance(); + } + } + + private static void withHash(final LettuceGeoArgs geoArgs, final Boolean withHash) { + if(Boolean.TRUE.equals(withHash)){ + geoArgs.withHash(); + } + } + + private static void sort(final LettuceGeoArgs geoArgs, final Order order) { + if(order == Order.ASC){ + geoArgs.sort(Sort.asc); + }else if(order == Order.DESC){ + geoArgs.sort(Sort.desc); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceLPosArgs.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceLPosArgs.java new file mode 100644 index 000000000..741b7c792 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceLPosArgs.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.command.ListCommands; +import io.lettuce.core.LPosArgs; + +import java.util.Optional; + +/** + * Lettuce {@link LPosArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceLPosArgs extends LPosArgs { + + public LettuceLPosArgs() { + super(); + } + + public LettuceLPosArgs(final int rank) { + super(); + rank(rank); + } + + public LettuceLPosArgs(final int rank, final int maxLen) { + super(); + rank(rank); + maxlen(maxLen); + } + + public static LettuceLPosArgs from(final ListCommands.LPosArgument lPosArgument) { + final LettuceLPosArgs lPosArgs = new LettuceLPosArgs(); + + if(lPosArgument != null){ + Optional.ofNullable(lPosArgument.getRank()).ifPresent(lPosArgs::rank); + Optional.ofNullable(lPosArgument.getMaxLen()).ifPresent(lPosArgs::maxlen); + } + + return lPosArgs; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceMigrateArgs.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceMigrateArgs.java new file mode 100644 index 000000000..9994c85b0 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceMigrateArgs.java @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.MigrateOperation; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.MigrateArgs; + +/** + * Lettuce {@link MigrateArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceMigrateArgs extends MigrateArgs { + + public LettuceMigrateArgs() { + super(); + } + + public LettuceMigrateArgs(final MigrateOperation migrateOperation) { + super(); + + if(migrateOperation != null){ + switch(migrateOperation){ + case COPY: + copy(); + break; + case REPLACE: + replace(); + break; + default: + break; + } + } + } + + public LettuceMigrateArgs(final MigrateOperation migrateOperation, final T[] keys) { + this(migrateOperation); + keys(keys); + } + + public LettuceMigrateArgs(final String password) { + super(); + auth(password); + } + + public LettuceMigrateArgs(final byte[] password) { + this(SafeEncoder.encode(password)); + } + + public LettuceMigrateArgs(final String username, final String password) { + super(); + auth(password); + } + + public LettuceMigrateArgs(final byte[] username, final byte[] password) { + this(SafeEncoder.encode(username), SafeEncoder.encode(password)); + } + + public LettuceMigrateArgs(final T[] keys, final String password) { + this(keys); + auth(password); + } + + public LettuceMigrateArgs(final T[] keys, final byte[] password) { + this(keys, SafeEncoder.encode(password)); + } + + public LettuceMigrateArgs(final T[] keys, final String username, final String password) { + this(keys, password); + } + + public LettuceMigrateArgs(final T[] keys, final byte[] username, final byte[] password) { + this(keys, SafeEncoder.encode(username), SafeEncoder.encode(password)); + } + + public LettuceMigrateArgs(final MigrateOperation migrateOperation, final String password) { + this(migrateOperation); + auth(password); + } + + public LettuceMigrateArgs(final MigrateOperation migrateOperation, final byte[] password) { + this(migrateOperation, SafeEncoder.encode(password)); + } + + public LettuceMigrateArgs(final MigrateOperation migrateOperation, final String username, final String password) { + this(migrateOperation); + auth(password); + } + + public LettuceMigrateArgs(final MigrateOperation migrateOperation, final byte[] username, final byte[] password) { + this(migrateOperation, SafeEncoder.encode(username), SafeEncoder.encode(password)); + } + + public LettuceMigrateArgs(final MigrateOperation migrateOperation, final T[] keys, final String password) { + this(migrateOperation, keys); + auth(password); + } + + public LettuceMigrateArgs(final MigrateOperation migrateOperation, final T[] keys, final byte[] password) { + this(migrateOperation, keys, SafeEncoder.encode(password)); + } + + public LettuceMigrateArgs(final MigrateOperation migrateOperation, final T[] keys, final String username, + final String password) { + this(migrateOperation, keys); + auth(password); + } + + public LettuceMigrateArgs(final MigrateOperation migrateOperation, final T[] keys, final byte[] username, + final byte[] password) { + this(migrateOperation, keys, SafeEncoder.encode(username), SafeEncoder.encode(password)); + } + + public LettuceMigrateArgs(final T[] keys) { + super(); + keys(keys); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/RestoreArgumentConverter.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceRestoreArgs.java similarity index 58% rename from buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/RestoreArgumentConverter.java rename to buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceRestoreArgs.java index 45d94c8cc..e7bf16d76 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/internal/convert/jedis/params/RestoreArgumentConverter.java +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceRestoreArgs.java @@ -19,43 +19,54 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.redis.core.internal.convert.jedis.params; +package com.buession.redis.core.internal.lettuce; -import com.buession.core.converter.Converter; -import com.buession.core.converter.mapper.PropertyMapper; import com.buession.redis.core.command.KeyCommands; -import redis.clients.jedis.params.RestoreParams; +import io.lettuce.core.RestoreArgs; /** - * {@link KeyCommands.RestoreArgument} 转换为 jedis {@link RestoreParams} + * Lettuce {@link RestoreArgs} 扩展 * * @author Yong.Teng - * @since 2.0.0 + * @since 3.0.0 */ -public final class RestoreArgumentConverter implements Converter { +public final class LettuceRestoreArgs extends RestoreArgs { - public final static RestoreArgumentConverter INSTANCE = new RestoreArgumentConverter(); + public LettuceRestoreArgs() { + super(); + } - @Override - public RestoreParams convert(final KeyCommands.RestoreArgument source) { - final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull(); - final RestoreParams restoreParams = new RestoreParams(); + public LettuceRestoreArgs(final boolean replace) { + super(); + replace(this, replace); + } - if(Boolean.TRUE.equals(source.isReplace())){ - restoreParams.replace(); - } + public LettuceRestoreArgs(final boolean replace, final long ttl) { + this(replace); + ttl(ttl); + } - if(Boolean.TRUE.equals(source.isAbsTtl())){ - restoreParams.absTtl(); + public LettuceRestoreArgs(final boolean replace, final long ttl, final long idleTime, final long frequency) { + this(replace, ttl); + } + + public static LettuceRestoreArgs from(final KeyCommands.RestoreArgument restoreArgument) { + final LettuceRestoreArgs restoreArgs = new LettuceRestoreArgs(); + + if(restoreArgument != null){ + replace(restoreArgs, restoreArgument.isReplace()); } - propertyMapper.from(source.getIdleTime()).to(restoreParams::idleTime); - propertyMapper.from(source.getFrequency()).to(restoreParams::frequency); + return restoreArgs; + } - return restoreParams; + private static void replace(final LettuceRestoreArgs restoreArgs, final Boolean replace) { + if(Boolean.TRUE.equals(replace)){ + restoreArgs.replace(); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceResult.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceResult.java new file mode 100644 index 000000000..dbf9f39d9 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceResult.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.core.converter.Converter; +import com.buession.redis.core.FutureResult; +import com.buession.redis.core.internal.convert.Converters; +import io.lettuce.core.RedisFuture; +import io.lettuce.core.protocol.RedisCommand; + +/** + * Lettuce 事务、管道异步结果 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceResult extends FutureResult> { + + @SuppressWarnings({"unchecked"}) + public LettuceResult(final RedisFuture resultHolder) { + super((RedisCommand) resultHolder); + } + + @SuppressWarnings({"unchecked"}) + public LettuceResult(final RedisFuture resultHolder, final Converter converter) { + super((RedisCommand) resultHolder, converter); + } + + @SuppressWarnings({"unchecked"}) + @Override + public SV get() { + return (SV) getHolder().getOutput().get(); + } + + public final static class Builder { + + private final RedisFuture response; + + private Converter converter; + + private Builder(final RedisFuture response, final Converter converter) { + this.response = response; + this.converter = converter; + } + + public static Builder fromRedisFuture(RedisFuture redisFuture) { + return new LettuceResult.Builder<>(redisFuture, Converters.always()); + } + + public Builder mappedWith(Converter converter) { + this.converter = converter; + return this; + } + + public LettuceResult build() { + return new LettuceResult<>(response, converter); + } + + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceScanArgs.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceScanArgs.java new file mode 100644 index 000000000..cbff76fd2 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceScanArgs.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ScanArgs; + +/** + * Lettuce {@link ScanArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceScanArgs extends ScanArgs { + + public LettuceScanArgs() { + super(); + } + + public LettuceScanArgs(final String pattern) { + super(); + match(pattern); + } + + public LettuceScanArgs(final byte[] pattern) { + this(SafeEncoder.encode(pattern)); + } + + public LettuceScanArgs(final int count) { + super(); + limit(count); + } + + public LettuceScanArgs(final String pattern, final int count) { + this(pattern); + limit(count); + } + + public LettuceScanArgs(final byte[] pattern, final int count) { + this(pattern); + limit(count); + } + + public LettuceScanArgs(final long count) { + this((int) count); + } + + public LettuceScanArgs(final String pattern, final long count) { + this(pattern, (int) count); + } + + public LettuceScanArgs(final byte[] pattern, final long count) { + this(pattern, (int) count); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceScanCursor.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceScanCursor.java new file mode 100644 index 000000000..11f33bd36 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceScanCursor.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ScanCursor; + +/** + * Lettuce {@link ScanCursor} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceScanCursor extends ScanCursor { + + public LettuceScanCursor() { + super(); + } + + public LettuceScanCursor(final String pattern) { + super(pattern, false); + } + + public LettuceScanCursor(final byte[] pattern) { + this(SafeEncoder.encode(pattern)); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceSetArgs.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceSetArgs.java new file mode 100644 index 000000000..57b4a88cb --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceSetArgs.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.NxXx; +import com.buession.redis.core.command.StringCommands; +import io.lettuce.core.SetArgs; + +import java.util.Optional; + +/** + * Lettuce {@link SetArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceSetArgs extends SetArgs { + + public LettuceSetArgs() { + super(); + } + + public LettuceSetArgs(final NxXx nx) { + super(); + nxxx(this, nx); + } + + public LettuceSetArgs(final boolean keepTtl) { + super(); + keepTtl(this, keepTtl); + } + + public LettuceSetArgs(final long ex, final long exAt, final long px, final long pxAt) { + super(); + ex(ex); + px(px); + } + + public LettuceSetArgs(final long ex, final long exAt, final long px, final long pxAt, final NxXx nx) { + this(ex, exAt, px, pxAt); + nxxx(this, nx); + } + + public LettuceSetArgs(final long ex, final long exAt, final long px, final long pxAt, final boolean keepTtl) { + this(ex, exAt, px, pxAt); + keepTtl(this, keepTtl); + } + + public LettuceSetArgs(final long ex, final long exAt, final long px, final long pxAt, final NxXx nx, + final boolean keepTtl) { + this(ex, exAt, px, pxAt, nx); + keepTtl(this, keepTtl); + } + + public static LettuceSetArgs from(final StringCommands.SetArgument setArgument) { + final LettuceSetArgs setArgs = new LettuceSetArgs(); + + if(setArgument != null){ + Optional.ofNullable(setArgument.getEx()).ifPresent(setArgs::ex); + //Optional.ofNullable(setArgument.getExAt()).ifPresent(setArgs::exAt); + Optional.ofNullable(setArgument.getPx()).ifPresent(setArgs::px); + //Optional.ofNullable(setArgument.getPxAt()).ifPresent(setArgs::pxAt); + + nxxx(setArgs, setArgument.getNxXx()); + keepTtl(setArgs, setArgument.isKeepTtl()); + } + + return setArgs; + } + + private static void nxxx(final LettuceSetArgs setArgs, final NxXx nx) { + if(nx == NxXx.NX){ + setArgs.nx(); + }else if(nx == NxXx.XX){ + setArgs.xx(); + } + } + + private static void keepTtl(final LettuceSetArgs setArgs, final Boolean keepTtl) { + if(Boolean.TRUE.equals(keepTtl)){ + setArgs.keepttl(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceSortArgs.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceSortArgs.java new file mode 100644 index 000000000..c5d10e806 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceSortArgs.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.lang.Order; +import com.buession.redis.core.Limit; +import com.buession.redis.core.command.KeyCommands; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.SortArgs; + +import java.util.Arrays; +import java.util.Optional; + +/** + * Lettuce {@link SortArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceSortArgs extends SortArgs { + + public LettuceSortArgs() { + super(); + } + + public LettuceSortArgs(final String by) { + super(); + by(by); + } + + public LettuceSortArgs(final byte[] by) { + super(); + by(SafeEncoder.encode(by)); + } + + public LettuceSortArgs(final String by, final String[] gets) { + this(by); + if(gets != null){ + Arrays.stream(gets).forEach(this::get); + } + } + + public LettuceSortArgs(final byte[] by, final byte[][] gets) { + this(by); + if(gets != null){ + Arrays.stream(gets).forEach((v)->this.get(SafeEncoder.encode(v))); + } + } + + public LettuceSortArgs(final String by, final Order order) { + this(by); + order(this, order); + } + + public LettuceSortArgs(final byte[] by, final Order order) { + this(by); + order(this, order); + } + + public LettuceSortArgs(final String by, final String[] gets, final Order order) { + this(by, gets); + order(this, order); + } + + public LettuceSortArgs(final byte[] by, final byte[][] gets, final Order order) { + this(by, gets); + order(this, order); + } + + public LettuceSortArgs(final String by, final String[] gets, final Limit limit) { + this(by, gets); + limit(this, limit); + } + + public LettuceSortArgs(final byte[] by, final byte[][] gets, final Limit limit) { + this(by, gets); + limit(this, limit); + } + + public LettuceSortArgs(final String by, final String[] gets, final Order order, final Limit limit) { + this(by, gets, order); + limit(this, limit); + } + + public LettuceSortArgs(final byte[] by, final byte[][] gets, final Order order, final Limit limit) { + this(by, gets, order); + limit(this, limit); + } + + public LettuceSortArgs(final String by, final String[] gets, final Order order, final Limit limit, + final Boolean alpha) { + this(by, gets, order, limit); + alpha(this, alpha); + } + + public LettuceSortArgs(final byte[] by, final byte[][] gets, final Order order, final Limit limit, + final Boolean alpha) { + this(by, gets, order, limit); + alpha(this, alpha); + } + + public static LettuceSortArgs from(final KeyCommands.SortArgument sortArgument) { + final LettuceSortArgs sortArgs = new LettuceSortArgs(); + + if(sortArgument != null){ + Optional.ofNullable(sortArgument.getBy()).ifPresent((v)->sortArgs.by(SafeEncoder.encode(v))); + if(sortArgument.getGetPatterns() != null){ + Arrays.stream(sortArgument.getGetPatterns()).forEach((v)->sortArgs.get(SafeEncoder.encode(v))); + } + order(sortArgs, sortArgument.getOrder()); + limit(sortArgs, sortArgument.getLimit()); + alpha(sortArgs, sortArgument.isAlpha()); + } + + return sortArgs; + } + + private static void alpha(final LettuceSortArgs sortArgs, final Boolean alpha) { + if(Boolean.TRUE.equals(alpha)){ + sortArgs.alpha(); + } + } + + private static void limit(final LettuceSortArgs sortArgs, final Limit limit) { + if(limit != null){ + sortArgs.limit((int) limit.getOffset(), (int) limit.getCount()); + } + } + + private static void order(final LettuceSortArgs sortArgs, final Order order) { + if(order == Order.ASC){ + sortArgs.asc(); + }else if(order == Order.DESC){ + sortArgs.desc(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceXAddArgs.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceXAddArgs.java new file mode 100644 index 000000000..4d1a76c0b --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceXAddArgs.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.StreamEntryId; +import com.buession.redis.core.command.StreamCommands; +import com.buession.redis.core.internal.convert.lettuce.params.StreamEntryIdConverter; +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.XAddArgs; + +import java.util.Optional; + +/** + * Lettuce {@link XAddArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceXAddArgs extends XAddArgs { + + public LettuceXAddArgs() { + super(); + } + + public LettuceXAddArgs(final String id) { + super(); + id(id); + } + + public LettuceXAddArgs(final byte[] id) { + this(SafeEncoder.encode(id)); + } + + public LettuceXAddArgs(final StreamEntryId id) { + this((new StreamEntryIdConverter()).convert(id)); + } + + public LettuceXAddArgs(final long maxLen) { + super(); + maxlen(maxLen); + } + + public LettuceXAddArgs(final String id, final long maxLen) { + this(id); + maxlen(maxLen); + } + + public LettuceXAddArgs(final byte[] id, final long maxLen) { + this(id); + maxlen(maxLen); + } + + public LettuceXAddArgs(final StreamEntryId id, final long maxLen) { + this(id); + maxlen(maxLen); + } + + public LettuceXAddArgs(final boolean approximateTrimming) { + super(); + approximateTrimming(this, approximateTrimming); + } + + public LettuceXAddArgs(final String id, final boolean approximateTrimming) { + this(id); + approximateTrimming(this, approximateTrimming); + } + + public LettuceXAddArgs(final byte[] id, final boolean approximateTrimming) { + this(id); + approximateTrimming(this, approximateTrimming); + } + + public LettuceXAddArgs(final StreamEntryId id, final boolean approximateTrimming) { + this(id); + approximateTrimming(this, approximateTrimming); + } + + public LettuceXAddArgs(final String id, final long maxLen, final boolean approximateTrimming) { + this(id, approximateTrimming); + maxlen(maxLen); + } + + public LettuceXAddArgs(final byte[] id, final long maxLen, final boolean approximateTrimming) { + this(id, approximateTrimming); + maxlen(maxLen); + } + + public LettuceXAddArgs(final StreamEntryId id, final long maxLen, final boolean approximateTrimming) { + this(id, approximateTrimming); + maxlen(maxLen); + } + + public static LettuceXAddArgs from(final StreamCommands.XAddArgument xAddArgument) { + final LettuceXAddArgs xAddArgs = new LettuceXAddArgs(); + + if(xAddArgument != null){ + Optional.ofNullable(xAddArgument.getMaxLen()).ifPresent(xAddArgs::maxlen); + approximateTrimming(xAddArgs, xAddArgument.isApproximateTrimming()); + } + + return xAddArgs; + } + + private static void approximateTrimming(final LettuceXAddArgs xAddArgs, final Boolean approximateTrimming) { + if(Boolean.TRUE.equals(approximateTrimming)){ + xAddArgs.approximateTrimming(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceXClaimArgs.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceXClaimArgs.java new file mode 100644 index 000000000..87183b999 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceXClaimArgs.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.command.StreamCommands; +import io.lettuce.core.XClaimArgs; + +import java.util.Optional; + +/** + * Lettuce {@link XClaimArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceXClaimArgs extends XClaimArgs { + + public LettuceXClaimArgs() { + super(); + } + + public LettuceXClaimArgs(final long minIdleTime) { + super(); + minIdleTime((minIdleTime)); + } + + public LettuceXClaimArgs(final long minIdleTime, final boolean justId) { + this(minIdleTime); + justId(this, justId); + } + + public LettuceXClaimArgs(final long minIdleTime, final long idle, final long time, + final long retryCount, final boolean force, final boolean justId) { + this(minIdleTime, force); + idle(idle); + time(time); + retryCount(retryCount); + force(this, force); + justId(this, justId); + } + + public static LettuceXClaimArgs from(final StreamCommands.XClaimArgument xClaimArgument) { + final LettuceXClaimArgs xClaimArgs = new LettuceXClaimArgs(); + + if(xClaimArgument != null){ + Optional.ofNullable(xClaimArgument.getIdleTime()).ifPresent(xClaimArgs::idle); + Optional.ofNullable(xClaimArgument.getIdleUnixTime()).ifPresent(xClaimArgs::time); + Optional.ofNullable(xClaimArgument.getIdleUnixTime()).ifPresent(xClaimArgs::time); + Optional.ofNullable(xClaimArgument.getRetryCount()).ifPresent(xClaimArgs::retryCount); + force(xClaimArgs, xClaimArgument.isForce()); + } + + return xClaimArgs; + } + + private static void force(final LettuceXClaimArgs xClaimArgs, final Boolean force) { + if(Boolean.TRUE.equals(force)){ + xClaimArgs.force(); + } + } + + private static void justId(final LettuceXClaimArgs xClaimArgs, final Boolean justId) { + if(Boolean.TRUE.equals(justId)){ + xClaimArgs.justid(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceXGroupCreateArgs.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceXGroupCreateArgs.java new file mode 100644 index 000000000..abf33917a --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceXGroupCreateArgs.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import io.lettuce.core.XGroupCreateArgs; + +/** + * Lettuce {@link XGroupCreateArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceXGroupCreateArgs extends XGroupCreateArgs { + + public LettuceXGroupCreateArgs() { + super(); + } + + public LettuceXGroupCreateArgs(final boolean mkstream) { + super(); + mkstream(mkstream); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceXPendingArgs.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceXPendingArgs.java new file mode 100644 index 000000000..673c594e8 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceXPendingArgs.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.StreamEntryId; +import io.lettuce.core.Consumer; +import io.lettuce.core.Limit; +import io.lettuce.core.Range; +import io.lettuce.core.XPendingArgs; + +/** + * Lettuce {@link XPendingArgs} 扩展 + * + * @param + * 类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceXPendingArgs extends XPendingArgs { + + public LettuceXPendingArgs() { + super(); + } + + public LettuceXPendingArgs(final long idle) { + this(); + idle(idle); + } + + public LettuceXPendingArgs(final long idle, final StreamEntryId start, final StreamEntryId end, + final long count) { + this(start, end, count); + idle(idle); + } + + public LettuceXPendingArgs(final long idle, final T groupName, final T consumerName) { + this(idle); + consumer(Consumer.from(groupName, consumerName)); + } + + public LettuceXPendingArgs(final long idle, final Consumer consumer) { + this(idle); + consumer(consumer); + } + + public LettuceXPendingArgs(final StreamEntryId start, final StreamEntryId end, final long count) { + range(Range.create(start.toString(), end.toString())); + limit(Limit.from(count)); + } + + public LettuceXPendingArgs(final StreamEntryId start, final StreamEntryId end, final long count, + final T groupName, final T consumerName) { + this(start, end, count, Consumer.from(groupName, consumerName)); + } + + public LettuceXPendingArgs(final StreamEntryId start, final StreamEntryId end, final long count, + final Consumer consumer) { + this(start, end, count); + consumer(consumer); + } + + public LettuceXPendingArgs(final long idle, final StreamEntryId start, final StreamEntryId end, + final long count, final T groupName, final T consumerName) { + this(idle, start, end, count, Consumer.from(groupName, consumerName)); + } + + public LettuceXPendingArgs(final long idle, final StreamEntryId start, final StreamEntryId end, + final long count, final Consumer consumer) { + this(idle, start, end, count); + consumer(consumer); + } + + public LettuceXPendingArgs(final T groupName, final T consumerName) { + this(Consumer.from(groupName, consumerName)); + } + + public LettuceXPendingArgs(final Consumer consumer) { + this(); + consumer(consumer); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceXReadArgs.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceXReadArgs.java new file mode 100644 index 000000000..bdb1ad473 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceXReadArgs.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import io.lettuce.core.XReadArgs; + +/** + * Lettuce {@link XReadArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceXReadArgs extends XReadArgs { + + public LettuceXReadArgs() { + super(); + } + + public LettuceXReadArgs(final long count) { + super(); + count(count); + } + + public LettuceXReadArgs(final long block, final long count) { + this(count); + block(block); + } + + public LettuceXReadArgs(final boolean noack, final long count) { + this(count); + noack(noack); + } + + public LettuceXReadArgs(final long block, final boolean noack, final long count) { + this(block, count); + noack(noack); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceZAddArgs.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceZAddArgs.java new file mode 100644 index 000000000..1d78f4e84 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceZAddArgs.java @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import com.buession.redis.core.GtLt; +import com.buession.redis.core.NxXx; +import io.lettuce.core.ZAddArgs; + +/** + * Lettuce {@link ZAddArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceZAddArgs extends ZAddArgs { + + /** + * 构造函数 + */ + public LettuceZAddArgs() { + super(); + } + + /** + * 构造函数 + * + * @param nxXx + * 更新成员方式 + */ + public LettuceZAddArgs(final NxXx nxXx) { + super(); + nxXx(nxXx); + } + + /** + * 构造函数 + * + * @param gtLt + * {@link GtLt} + */ + public LettuceZAddArgs(final GtLt gtLt) { + super(); + gtLt(gtLt); + } + + /** + * 构造函数 + * + * @param ch + * 是否返回变更成员的数量 + */ + public LettuceZAddArgs(final boolean ch) { + super(); + ch(ch); + } + + /** + * 构造函数 + * + * @param nxXx + * 更新成员方式 + * @param gtLt + * 更新新的分值方式 + */ + public LettuceZAddArgs(final NxXx nxXx, final GtLt gtLt) { + super(); + nxXx(nxXx); + gtLt(gtLt); + } + + /** + * 构造函数 + * + * @param nxXx + * 更新成员方式 + * @param ch + * 是否返回变更成员的数量 + */ + public LettuceZAddArgs(final NxXx nxXx, final boolean ch) { + super(); + nxXx(nxXx); + ch(ch); + } + + /** + * 构造函数 + * + * @param gtLt + * 更新新的分值方式 + * @param ch + * 是否返回变更成员的数量 + */ + public LettuceZAddArgs(final GtLt gtLt, final boolean ch) { + super(); + gtLt(gtLt); + ch(ch); + } + + /** + * 构造函数 + * + * @param nxXx + * 更新成员方式 + * @param gtLt + * 更新新的分值方式 + * @param ch + * 是否返回变更成员的数量 + */ + public LettuceZAddArgs(final NxXx nxXx, final GtLt gtLt, final boolean ch) { + super(); + nxXx(nxXx); + gtLt(gtLt); + ch(ch); + } + + /** + * 设置更新成员方式 + * + * @param nxXx + * 更新成员方式 + */ + private void nxXx(final NxXx nxXx) { + if(nxXx != null){ + switch(nxXx){ + case NX: + nx(); + break; + case XX: + xx(); + break; + default: + break; + } + } + } + + /** + * 更新新的分值方式 + * + * @param gtLt + * 更新新的分值方式 + */ + private void gtLt(final GtLt gtLt) { + if(gtLt != null){ + switch(gtLt){ + case GT: + break; + case LT: + break; + default: + break; + } + } + } + + private void ch(boolean ch) { + if(ch){ + ch(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceZStoreArgs.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceZStoreArgs.java new file mode 100644 index 000000000..54c912252 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/LettuceZStoreArgs.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce; + +import io.lettuce.core.ZStoreArgs; +import redis.clients.jedis.params.ZParams; + +/** + * Lettuce {@link ZStoreArgs} 扩展 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public final class LettuceZStoreArgs extends ZStoreArgs { + + /** + * 构造函数 + */ + public LettuceZStoreArgs() { + super(); + } + + /** + * 构造函数 + * + * @param aggregate + * {@link ZParams.Aggregate} + */ + public LettuceZStoreArgs(final com.buession.redis.core.Aggregate aggregate) { + super(); + + if(aggregate != null){ + switch(aggregate){ + case MIN: + min(); + break; + case MAX: + max(); + break; + case SUM: + sum(); + break; + default: + break; + } + } + } + + /** + * 构造函数 + * + * @param weights + * 权重 + */ + public LettuceZStoreArgs(final double... weights) { + super(); + weights(weights); + } + + /** + * 构造函数 + * + * @param aggregate + * {@link ZParams.Aggregate} + * @param weights + * 权重 + */ + public LettuceZStoreArgs(final com.buession.redis.core.Aggregate aggregate, final double... weights) { + this(aggregate); + weights(weights); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/package-info.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/package-info.java new file mode 100644 index 000000000..501fa66ee --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.core.internal.lettuce; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/utils/ScoredValueUtils.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/utils/ScoredValueUtils.java new file mode 100644 index 000000000..ab7bcfa30 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/utils/ScoredValueUtils.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.internal.lettuce.utils; + +import com.buession.redis.utils.SafeEncoder; +import io.lettuce.core.ScoredValue; + +import java.util.Map; + +/** + * Lettuce {@link ScoredValue} 工具类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class ScoredValueUtils { + + protected ScoredValueUtils() { + + } + + @SuppressWarnings({"unchecked"}) + public static ScoredValue[] fromStringMap(final Map values) { + if(values == null){ + return null; + }else{ + final ScoredValue[] result = new ScoredValue[values.size()]; + int i = 0; + + for(Map.Entry e : values.entrySet()){ + result[i++] = e.getValue() == null ? ScoredValue.empty() : ScoredValue.just(e.getValue(), + SafeEncoder.encode(e.getKey())); + } + + return result; + } + } + + @SuppressWarnings({"unchecked"}) + public static ScoredValue[] fromBinaryMap(final Map values) { + if(values == null){ + return null; + }else{ + final ScoredValue[] result = new ScoredValue[values.size()]; + int i = 0; + + for(Map.Entry e : values.entrySet()){ + result[i++] = e.getValue() == null ? ScoredValue.empty() : ScoredValue.just(e.getValue(), + e.getKey()); + } + + return result; + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/utils/package-info.java b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/utils/package-info.java new file mode 100644 index 000000000..48b2f2adf --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/internal/lettuce/utils/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.core.internal.lettuce.utils; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/core/operations/ClusterOperations.java b/buession-redis/src/main/java/com/buession/redis/core/operations/ClusterOperations.java index 8a63f8a68..6b2ce994c 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/operations/ClusterOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/core/operations/ClusterOperations.java @@ -19,16 +19,26 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.operations; import com.buession.core.utils.Assert; +import com.buession.lang.KeyValue; import com.buession.lang.Status; +import com.buession.redis.core.BumpEpoch; +import com.buession.redis.core.ClusterFailoverOption; +import com.buession.redis.core.ClusterInfo; +import com.buession.redis.core.ClusterRedisNode; +import com.buession.redis.core.ClusterResetOption; +import com.buession.redis.core.ClusterSetSlotOption; +import com.buession.redis.core.ClusterSlot; import com.buession.redis.core.RedisNode; import com.buession.redis.core.command.ClusterCommands; +import java.util.List; + /** * 集群命令 * @@ -39,6 +49,77 @@ */ public interface ClusterOperations extends ClusterCommands, RedisOperations { + + @Override + default String clusterMyId() { + return execute((client)->client.clusterOperations().clusterMyId()); + } + + @Override + default Status clusterAddSlots(final int... slots) { + return execute((client)->client.clusterOperations().clusterAddSlots(slots)); + } + + @Override + default List clusterSlots() { + return execute((client)->client.clusterOperations().clusterSlots()); + } + + @Override + default Integer clusterCountFailureReports(final String nodeId) { + return execute((client)->client.clusterOperations().clusterCountFailureReports(nodeId)); + } + + @Override + default Integer clusterCountFailureReports(final byte[] nodeId) { + return execute((client)->client.clusterOperations().clusterCountFailureReports(nodeId)); + } + + @Override + default Long clusterCountKeysInSlot(final int slot) { + return execute((client)->client.clusterOperations().clusterCountKeysInSlot(slot)); + } + + @Override + default Status clusterDelSlots(final int... slots) { + return execute((client)->client.clusterOperations().clusterDelSlots(slots)); + } + + @Override + default Status clusterFlushSlots() { + return execute((client)->client.clusterOperations().clusterFlushSlots()); + } + + @Override + default Status clusterFailover(final ClusterFailoverOption clusterFailoverOption) { + return execute((client)->client.clusterOperations().clusterFailover(clusterFailoverOption)); + } + + @Override + default Status clusterForget(final String nodeId) { + return execute((client)->client.clusterOperations().clusterForget(nodeId)); + } + + @Override + default Status clusterForget(final byte[] nodeId) { + return execute((client)->client.clusterOperations().clusterForget(nodeId)); + } + + @Override + default List clusterGetKeysInSlot(final int slot, final long count) { + return execute((client)->client.clusterOperations().clusterGetKeysInSlot(slot, count)); + } + + @Override + default ClusterInfo clusterInfo() { + return execute((client)->client.clusterOperations().clusterInfo()); + } + + @Override + default Status clusterMeet(final String ip, final int port) { + return execute((client)->client.clusterOperations().clusterMeet(ip, port)); + } + /** * 用来连接不同的开启集群支持的 Redis 节点,以进入工作集群 * @@ -50,7 +131,7 @@ public interface ClusterOperations extends ClusterCommands, RedisOperations { * * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE */ - default Status clusterMeet(final String ip){ + default Status clusterMeet(final String ip) { return clusterMeet(ip, RedisNode.DEFAULT_PORT); } @@ -65,11 +146,96 @@ default Status clusterMeet(final String ip){ * * @return 命令成功执行返回 Status.SUCCESS;否则返回 Status.FAILURE */ - default Status clusterMeet(final RedisNode node){ + default Status clusterMeet(final RedisNode node) { Assert.isNull(node, "Redis cluster node cloud not be null"); Assert.isBlank(node.getHost(), "Redis cluster host cloud not be null or empty"); return clusterMeet(node.getHost(), node.getPort()); } + @Override + default List clusterNodes() { + return execute((client)->client.clusterOperations().clusterNodes()); + } + + @Override + default List clusterSlaves(final String nodeId) { + return execute((client)->client.clusterOperations().clusterSlaves(nodeId)); + } + + @Override + default List clusterSlaves(final byte[] nodeId) { + return execute((client)->client.clusterOperations().clusterSlaves(nodeId)); + } + + @Override + default List clusterReplicas(final String nodeId) { + return execute((client)->client.clusterOperations().clusterReplicas(nodeId)); + } + + @Override + default List clusterReplicas(final byte[] nodeId) { + return execute((client)->client.clusterOperations().clusterReplicas(nodeId)); + } + + @Override + default Status clusterReplicate(final String nodeId) { + return execute((client)->client.clusterOperations().clusterReplicate(nodeId)); + } + + @Override + default Status clusterReplicate(final byte[] nodeId) { + return execute((client)->client.clusterOperations().clusterReplicate(nodeId)); + } + + @Override + default Status clusterReset() { + return execute((client)->client.clusterOperations().clusterReset()); + } + + @Override + default Status clusterReset(final ClusterResetOption clusterResetOption) { + return execute((client)->client.clusterOperations().clusterReset(clusterResetOption)); + } + + @Override + default Status clusterSaveConfig() { + return execute((client)->client.clusterOperations().clusterSaveConfig()); + } + + @Override + default Status clusterSetConfigEpoch(final long configEpoch) { + return execute((client)->client.clusterOperations().clusterSetConfigEpoch(configEpoch)); + } + + @Override + default KeyValue clusterBumpEpoch() { + return execute((client)->client.clusterOperations().clusterBumpEpoch()); + } + + @Override + default Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final String nodeId) { + return execute((client)->client.clusterOperations().clusterSetSlot(slot, setSlotOption, nodeId)); + } + + @Override + default Status clusterSetSlot(final int slot, final ClusterSetSlotOption setSlotOption, final byte[] nodeId) { + return execute((client)->client.clusterOperations().clusterSetSlot(slot, setSlotOption, nodeId)); + } + + @Override + default Status asking() { + return execute((client)->client.clusterOperations().asking()); + } + + @Override + default Status readWrite() { + return execute((client)->client.clusterOperations().readWrite()); + } + + @Override + default Status readOnly() { + return execute((client)->client.clusterOperations().readOnly()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/operations/ConnectionOperations.java b/buession-redis/src/main/java/com/buession/redis/core/operations/ConnectionOperations.java index a8a372484..3017382af 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/operations/ConnectionOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/core/operations/ConnectionOperations.java @@ -26,9 +26,15 @@ import com.buession.core.utils.Assert; import com.buession.lang.Status; +import com.buession.redis.core.Client; +import com.buession.redis.core.ClientReply; +import com.buession.redis.core.ClientType; +import com.buession.redis.core.ClientUnblockType; import com.buession.redis.core.RedisNode; import com.buession.redis.core.command.ConnectionCommands; +import java.util.List; + /** * 连接相关命令 * @@ -38,6 +44,116 @@ */ public interface ConnectionOperations extends ConnectionCommands, RedisOperations { + @Override + default Status auth(final String user, final String password) { + return execute((client)->client.connectionOperations().auth(user, password)); + } + + @Override + default Status auth(final byte[] user, final byte[] password) { + return execute((client)->client.connectionOperations().auth(user, password)); + } + + @Override + default Status auth(final String password) { + return execute((client)->client.connectionOperations().auth(password)); + } + + @Override + default Status auth(final byte[] password) { + return execute((client)->client.connectionOperations().auth(password)); + } + + @Override + default String echo(final String str) { + return execute((client)->client.connectionOperations().echo(str)); + } + + @Override + default byte[] echo(final byte[] str) { + return execute((client)->client.connectionOperations().echo(str)); + } + + @Override + default Status ping() { + return execute((client)->client.connectionOperations().ping()); + } + + @Override + default Status reset() { + return execute((client)->client.connectionOperations().reset()); + } + + @Override + default Status quit() { + return execute((client)->client.connectionOperations().quit()); + } + + @Override + default Status select(final int db) { + return execute((client)->client.connectionOperations().select(db)); + } + + @Override + default Status clientCaching(final boolean isYes) { + return execute((client)->client.connectionOperations().clientCaching(isYes)); + } + + @Override + default Long clientId() { + return execute((client)->client.connectionOperations().clientId()); + } + + @Override + default Status clientSetName(final String name) { + return execute((client)->client.connectionOperations().clientSetName(name)); + } + + @Override + default Status clientSetName(final byte[] name) { + return execute((client)->client.connectionOperations().clientSetName(name)); + } + + @Override + default String clientGetName() { + return execute((client)->client.connectionOperations().clientGetName()); + } + + @Override + default Integer clientGetRedir() { + return execute((client)->client.connectionOperations().clientGetRedir()); + } + + @Override + default List clientList() { + return execute((client)->client.connectionOperations().clientList()); + } + + @Override + default List clientList(final ClientType clientType) { + return execute((client)->client.connectionOperations().clientList(clientType)); + } + + @Override + default Client clientInfo() { + return execute((client)->client.connectionOperations().clientInfo()); + } + + @Override + default Status clientPause(final int timeout) { + return execute((client)->client.connectionOperations().clientPause(timeout)); + } + + @Override + default Status clientReply(final ClientReply option) { + return execute((client)->client.connectionOperations().clientReply(option)); + } + + @Override + default Status clientKill(final String host, final int port) { + return execute((client)->client.connectionOperations().clientKill(host, port)); + } + /** * 关闭地址为 host:port 的客户端 * @@ -48,9 +164,19 @@ public interface ConnectionOperations extends ConnectionCommands, RedisOperation * * @return 当指定的客户端存在,且被成功关闭时,返回 Status.SUCCESS;否则,返回 Status.FAILURE */ - default Status clientKill(final RedisNode server){ + default Status clientKill(final RedisNode server) { Assert.isNull(server, "Redis server cloud not be null."); return clientKill(server.getHost(), server.getPort()); } + @Override + default Status clientUnblock(final int clientId) { + return execute((client)->client.connectionOperations().clientUnblock(clientId)); + } + + @Override + default Status clientUnblock(final int clientId, final ClientUnblockType type) { + return execute((client)->client.connectionOperations().clientUnblock(clientId, type)); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/operations/GenericOperations.java b/buession-redis/src/main/java/com/buession/redis/core/operations/GenericOperations.java new file mode 100644 index 000000000..f2ee8072b --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/core/operations/GenericOperations.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.core.operations; + +import com.buession.lang.KeyValue; +import com.buession.redis.core.command.GenericCommand; + +/** + * 一般运算 + * + *

详情说明 https://redis.io/docs/latest/commands/?group=generic

+ * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface GenericOperations extends GenericCommand, RedisOperations { + + @Override + default Long wait(final int replicas, final int timeout) { + return execute((client)->client.genericOperations().wait(replicas, timeout)); + } + + @Override + default KeyValue waitOf(final int locals, final int replicas, final int timeout) { + return execute((client)->client.genericOperations().waitOf(locals, replicas, timeout)); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/core/operations/HashOperations.java b/buession-redis/src/main/java/com/buession/redis/core/operations/HashOperations.java index d5f0fe388..1f4d0cb01 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/operations/HashOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/core/operations/HashOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.operations; @@ -30,6 +30,7 @@ import com.buession.redis.core.ScanResult; import com.buession.redis.core.command.HashCommands; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -54,7 +55,7 @@ public interface HashOperations extends HashCommands, RedisOperations { * * @return 被成功删除的域的数量 */ - default Long hDelete(final String key, final String... fields){ + default Long hDelete(final String key, final String... fields) { return hDel(key, fields); } @@ -70,7 +71,7 @@ default Long hDelete(final String key, final String... fields){ * * @return 被成功删除的域的数量 */ - default Long hDelete(final byte[] key, final byte[]... fields){ + default Long hDelete(final byte[] key, final byte[]... fields) { return hDel(key, fields); } @@ -276,7 +277,7 @@ default Long hDelete(final byte[] key, final byte[]... fields){ * * @see TypeReference */ - Map hGetAllObject(final byte[] key, TypeReference type); + Map hGetAllObject(final byte[] key, final TypeReference type); /** * 为哈希表 key 中的域 field 的值加上减量 increment @@ -292,7 +293,7 @@ default Long hDelete(final byte[] key, final byte[]... fields){ * * @return 哈希表 key 中域 field 减量 increment 后的值 */ - default Long hDecrBy(final String key, final String field, final long value){ + default Long hDecrBy(final String key, final String field, final long value) { return hIncrBy(key, field, value > 0 ? value * -1 : value); } @@ -310,7 +311,7 @@ default Long hDecrBy(final String key, final String field, final long value){ * * @return 哈希表 key 中域 field 减量 increment 后的值 */ - default Long hDecrBy(final byte[] key, final byte[] field, final long value){ + default Long hDecrBy(final byte[] key, final byte[] field, final long value) { return hIncrBy(key, field, value > 0 ? value * -1 : value); } @@ -328,7 +329,7 @@ default Long hDecrBy(final byte[] key, final byte[] field, final long value){ * * @return 哈希表 key 中域 field 减量 increment 后的值 */ - default Double hDecrByFloat(final String key, final String field, final double value){ + default Double hDecrByFloat(final String key, final String field, final double value) { return hIncrByFloat(key, field, value > 0 ? value * -1 : value); } @@ -346,7 +347,7 @@ default Double hDecrByFloat(final String key, final String field, final double v * * @return 哈希表 key 中域 field 减量 increment 后的值 */ - default Double hDecrByFloat(final byte[] key, final byte[] field, final double value){ + default Double hDecrByFloat(final byte[] key, final byte[] field, final double value) { return hIncrByFloat(key, field, value > 0 ? value * -1 : value); } @@ -467,12 +468,24 @@ default Double hDecrByFloat(final byte[] key, final byte[] field, final double v * Key * @param data * field => value (域-值)对 - * @param - * 值类型 * * @return 执行成功返回 Status.Success,否则返回 Status.FAILURE */ - Status hMSet(final String key, final List> data); + Status hMSet(final String key, final List> data); + + /** + * 批量将多个 field => value (域-值)对设置到哈希表 key 中 + * + *

详情说明 http://redisdoc.com/hash/hmset.html

+ * + * @param key + * Key + * @param data + * field => value (域-值)对 + * + * @return 执行成功返回 Status.Success,否则返回 Status.FAILURE + */ + Status hMSet(final byte[] key, final List> data); /** * 批量将多个 field => value (域-值)对设置到哈希表 key 中 @@ -483,12 +496,32 @@ default Double hDecrByFloat(final byte[] key, final byte[] field, final double v * Key * @param data * field => value (域-值)对 - * @param - * 值类型 * * @return 执行成功返回 Status.Success,否则返回 Status.FAILURE + * + * @since 3.0.0 */ - Status hMSet(final byte[] key, final List> data); + default Status hMSet(final String key, final KeyValue... data) { + return hMSet(key, Arrays.asList(data)); + } + + /** + * 批量将多个 field => value (域-值)对设置到哈希表 key 中 + * + *

详情说明 http://redisdoc.com/hash/hmset.html

+ * + * @param key + * Key + * @param data + * field => value (域-值)对 + * + * @return 执行成功返回 Status.Success,否则返回 Status.FAILURE + * + * @since 3.0.0 + */ + default Status hMSet(final byte[] key, final KeyValue... data) { + return hMSet(key, Arrays.asList(data)); + } /** * When called with just the key argument, return a random field from the hash value stored at key. diff --git a/buession-redis/src/main/java/com/buession/redis/core/operations/PubSubOperations.java b/buession-redis/src/main/java/com/buession/redis/core/operations/PubSubOperations.java index 22e4e2679..69598571a 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/operations/PubSubOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/core/operations/PubSubOperations.java @@ -19,13 +19,17 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.operations; +import com.buession.redis.core.PubSubListener; import com.buession.redis.core.command.PubSubCommands; +import java.util.List; +import java.util.Map; + /** * 发布与订阅命运算 * @@ -35,4 +39,106 @@ */ public interface PubSubOperations extends PubSubCommands, RedisOperations { + @Override + default void pSubscribe(final String[] patterns, final PubSubListener pubSubListener) { + execute((client)->{ + client.pubSubOperations().pSubscribe(patterns, pubSubListener); + return null; + }); + } + + @Override + default void pSubscribe(final byte[][] patterns, final PubSubListener pubSubListener) { + execute((client)->{ + client.pubSubOperations().pSubscribe(patterns, pubSubListener); + return null; + }); + } + + @Override + default Long publish(final String channel, final String message) { + return execute((client)->client.pubSubOperations().publish(channel, message)); + } + + @Override + default Long publish(final byte[] channel, final byte[] message) { + return execute((client)->client.pubSubOperations().publish(channel, message)); + } + + @Override + default List pubsubChannels() { + return execute((client)->client.pubSubOperations().pubsubChannels()); + } + + @Override + default List pubsubChannels(final String pattern) { + return execute((client)->client.pubSubOperations().pubsubChannels(pattern)); + } + + @Override + default List pubsubChannels(final byte[] pattern) { + return execute((client)->client.pubSubOperations().pubsubChannels(pattern)); + } + + @Override + default Long pubsubNumPat() { + return execute((client)->client.pubSubOperations().pubsubNumPat()); + } + + @Override + default Map pubsubNumSub(final String... channels) { + return execute((client)->client.pubSubOperations().pubsubNumSub(channels)); + } + + @Override + default Map pubsubNumSub(final byte[]... channels) { + return execute((client)->client.pubSubOperations().pubsubNumSub(channels)); + } + + @Override + default Object pUnSubscribe() { + return execute((client)->client.pubSubOperations().pUnSubscribe()); + } + + @Override + default Object pUnSubscribe(final String... patterns) { + return execute((client)->client.pubSubOperations().pUnSubscribe(patterns)); + } + + @Override + default Object pUnSubscribe(final byte[]... patterns) { + return execute((client)->client.pubSubOperations().pUnSubscribe(patterns)); + } + + @Override + default void subscribe(final String[] channels, final PubSubListener pubSubListener) { + execute((client)->{ + client.pubSubOperations().subscribe(channels, pubSubListener); + return null; + }); + } + + @Override + default void subscribe(final byte[][] channels, final PubSubListener pubSubListener) { + execute((client)->{ + client.pubSubOperations().subscribe(channels, pubSubListener); + return null; + }); + } + + @Override + default Object unSubscribe() { + return execute((client)->client.pubSubOperations().unSubscribe()); + } + + @Override + default Object unSubscribe(final String... channels) { + return execute((client)->client.pubSubOperations().unSubscribe(channels)); + } + + @Override + default Object unSubscribe(final byte[]... channels) { + return execute((client)->client.pubSubOperations().unSubscribe(channels)); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/operations/RedisOperations.java b/buession-redis/src/main/java/com/buession/redis/core/operations/RedisOperations.java index 7675e51b9..be34f144c 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/operations/RedisOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/core/operations/RedisOperations.java @@ -19,14 +19,32 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.operations; +import com.buession.redis.core.SessionCallback; +import com.buession.redis.exception.RedisException; + /** * @author Yong.Teng */ public interface RedisOperations { + /** + * Redis 执行命令 + * + * @param callback + * 会话回调 + * @param + * 返回值类型 + * + * @return 返回值 + * + * @throws RedisException + * 异常 + */ + R execute(final SessionCallback callback) throws RedisException; + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/operations/ScriptingOperations.java b/buession-redis/src/main/java/com/buession/redis/core/operations/ScriptingOperations.java index 480fe3a9d..62f6efeec 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/operations/ScriptingOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/core/operations/ScriptingOperations.java @@ -19,13 +19,17 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.operations; +import com.buession.lang.Status; +import com.buession.redis.core.FlushMode; import com.buession.redis.core.command.ScriptingCommands; +import java.util.List; + /** * LUA 脚本运算 * @@ -35,4 +39,79 @@ */ public interface ScriptingOperations extends ScriptingCommands, RedisOperations { + @Override + default Object eval(final String script) { + return execute((client)->client.scriptingOperations().eval(script)); + } + + @Override + default Object eval(final byte[] script) { + return execute((client)->client.scriptingOperations().eval(script)); + } + + @Override + default Object eval(final String script, final String... params) { + return execute((client)->client.scriptingOperations().eval(script, params)); + } + + @Override + default Object eval(final byte[] script, final byte[]... params) { + return execute((client)->client.scriptingOperations().eval(script, params)); + } + + @Override + default Object evalSha(final String digest) { + return execute((client)->client.scriptingOperations().evalSha(digest)); + } + + @Override + default Object evalSha(final byte[] digest) { + return execute((client)->client.scriptingOperations().evalSha(digest)); + } + + @Override + default Object evalSha(final String digest, final String... params) { + return execute((client)->client.scriptingOperations().evalSha(digest, params)); + } + + @Override + default Object evalSha(final byte[] digest, final byte[]... params) { + return execute((client)->client.scriptingOperations().evalSha(digest, params)); + } + + @Override + default List scriptExists(final String... sha1) { + return execute((client)->client.scriptingOperations().scriptExists(sha1)); + } + + @Override + default List scriptExists(final byte[]... sha1) { + return execute((client)->client.scriptingOperations().scriptExists(sha1)); + } + + @Override + default Status scriptFlush() { + return execute((client)->client.scriptingOperations().scriptFlush()); + } + + @Override + default Status scriptFlush(final FlushMode mode) { + return execute((client)->client.scriptingOperations().scriptFlush(mode)); + } + + @Override + default String scriptLoad(final String script) { + return execute((client)->client.scriptingOperations().scriptLoad(script)); + } + + @Override + default byte[] scriptLoad(final byte[] script) { + return execute((client)->client.scriptingOperations().scriptLoad(script)); + } + + @Override + default Status scriptKill() { + return execute((client)->client.scriptingOperations().scriptKill()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/operations/ServerOperations.java b/buession-redis/src/main/java/com/buession/redis/core/operations/ServerOperations.java index d5f63cf9d..d155eb37e 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/operations/ServerOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/core/operations/ServerOperations.java @@ -19,17 +19,29 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.operations; import com.buession.core.utils.Assert; import com.buession.lang.Status; +import com.buession.redis.core.AclLog; +import com.buession.redis.core.AclUser; +import com.buession.redis.core.FlushMode; +import com.buession.redis.core.Info; +import com.buession.redis.core.MemoryStats; +import com.buession.redis.core.Module; +import com.buession.redis.core.RedisMonitor; import com.buession.redis.core.RedisNode; +import com.buession.redis.core.RedisServerTime; +import com.buession.redis.core.Role; +import com.buession.redis.core.SlowLog; import com.buession.redis.core.command.ServerCommands; import java.util.Date; +import java.util.List; +import java.util.Map; /** * 服务端运算 @@ -40,6 +52,171 @@ */ public interface ServerOperations extends ServerCommands, RedisOperations { + @Override + default List aclCat() { + return execute((client)->client.serverOperations().aclCat()); + } + + @Override + default List aclCat(final String categoryName) { + return execute((client)->client.serverOperations().aclCat(categoryName)); + } + + @Override + default List aclCat(final byte[] categoryName) { + return execute((client)->client.serverOperations().aclCat(categoryName)); + } + + @Override + default Status aclSetUser(final String username, final String... rules) { + return execute((client)->client.serverOperations().aclSetUser(username, rules)); + } + + @Override + default Status aclSetUser(final byte[] username, final byte[]... rules) { + return execute((client)->client.serverOperations().aclSetUser(username, rules)); + } + + @Override + default AclUser aclGetUser(final String username) { + return execute((client)->client.serverOperations().aclGetUser(username)); + } + + @Override + default AclUser aclGetUser(final byte[] username) { + return execute((client)->client.serverOperations().aclGetUser(username)); + } + + @Override + default List aclUsers() { + return execute((client)->client.serverOperations().aclUsers()); + } + + @Override + default String aclWhoAmI() { + return execute((client)->client.serverOperations().aclWhoAmI()); + } + + @Override + default Long aclDelUser(final String... usernames) { + return execute((client)->client.serverOperations().aclDelUser(usernames)); + } + + @Override + default Long aclDelUser(final byte[]... username) { + return execute((client)->client.serverOperations().aclDelUser(username)); + } + + @Override + default String aclGenPass() { + return execute((client)->client.serverOperations().aclGenPass()); + } + + @Override + default List aclList() { + return execute((client)->client.serverOperations().aclList()); + } + + @Override + default Status aclLoad() { + return execute((client)->client.serverOperations().aclLoad()); + } + + @Override + default List aclLog() { + return execute((client)->client.serverOperations().aclLog()); + } + + @Override + default List aclLog(final long count) { + return execute((client)->client.serverOperations().aclLog(count)); + } + + @Override + default Status aclLogReset() { + return execute((client)->client.serverOperations().aclLogReset()); + } + + @Override + default Status aclLogSave() { + return execute((client)->client.serverOperations().aclLogSave()); + } + + @Override + default String bgRewriteAof() { + return execute((client)->client.serverOperations().bgRewriteAof()); + } + + @Override + default String bgSave() { + return execute((client)->client.serverOperations().bgSave()); + } + + @Override + default Status configSet(final String parameter, final String value) { + return execute((client)->client.serverOperations().configSet(parameter, value)); + } + + @Override + default Status configSet(final byte[] parameter, final byte[] value) { + return execute((client)->client.serverOperations().configSet(parameter, value)); + } + + @Override + default Status configSet(final Map configs) { + return execute((client)->client.serverOperations().configSet(configs)); + } + + @Override + default Map configGet(final String pattern) { + return execute((client)->client.serverOperations().configGet(pattern)); + } + + @Override + default Map configGet(final byte[] pattern) { + return execute((client)->client.serverOperations().configGet(pattern)); + } + + @Override + default Status configResetStat() { + return execute((client)->client.serverOperations().configResetStat()); + } + + @Override + default Status configRewrite() { + return execute((client)->client.serverOperations().configRewrite()); + } + + @Override + default Long dbSize() { + return execute((client)->client.serverOperations().dbSize()); + } + + @Override + default Status failover() { + return execute((client)->client.serverOperations().failover()); + } + + @Override + default Status failover(final String host, final int port) { + return execute((client)->client.serverOperations().failover(host, port)); + } + + @Override + default Status failover(final String host, final int port, final int timeout) { + return execute((client)->client.serverOperations().failover(host, port, timeout)); + } + + @Override + default Status failover(final String host, final int port, final boolean isForce, final int timeout) { + return execute((client)->client.serverOperations().failover(host, port, isForce, timeout)); + } + + @Override + default Status failover(final int timeout) { + return execute((client)->client.serverOperations().failover(timeout)); + } + /** * This command will start a coordinated failover between the currently-connected-to master and one of its replicas * @@ -50,7 +227,7 @@ public interface ServerOperations extends ServerCommands, RedisOperations { * * @return Status.SUCCESS if the command was accepted and a coordinated failover is in progress */ - default Status failover(final RedisNode server){ + default Status failover(final RedisNode server) { Assert.isNull(server, "Redis server cloud not be null"); return failover(server.getHost(), server.getPort()); } @@ -67,7 +244,7 @@ default Status failover(final RedisNode server){ * * @return Status.SUCCESS if the command was accepted and a coordinated failover is in progress */ - default Status failover(final RedisNode server, final int timeout){ + default Status failover(final RedisNode server, final int timeout) { Assert.isNull(server, "Redis server cloud not be null"); return failover(server.getHost(), server.getPort(), timeout); } @@ -86,11 +263,46 @@ default Status failover(final RedisNode server, final int timeout){ * * @return Status.SUCCESS if the command was accepted and a coordinated failover is in progress */ - default Status failover(final RedisNode server, final boolean isForce, final int timeout){ + default Status failover(final RedisNode server, final boolean isForce, final int timeout) { Assert.isNull(server, "Redis server cloud not be null"); return failover(server.getHost(), server.getPort(), isForce, timeout); } + @Override + default Status flushAll() { + return execute((client)->client.serverOperations().flushAll()); + } + + @Override + default Status flushAll(final FlushMode mode) { + return execute((client)->client.serverOperations().flushAll(mode)); + } + + @Override + default Status flushDb() { + return execute((client)->client.serverOperations().flushDb()); + } + + @Override + default Status flushDb(final FlushMode mode) { + return execute((client)->client.serverOperations().flushDb(mode)); + } + + @Override + default Info info() { + return execute((client)->client.serverOperations().info()); + } + + @Override + default Info info(final Info.Section section) { + return execute((client)->client.serverOperations().info(section)); + } + + @Override + default Long lastSave() { + return execute((client)->client.serverOperations().lastSave()); + } + /** * 获取最近一次 Redis 成功将数据保存到磁盘上的时间 * @@ -98,10 +310,81 @@ default Status failover(final RedisNode server, final boolean isForce, final int * * @return 最近一次成功将数据保存到磁盘上的时间 */ - default Date lastSaveAt(){ + default Date lastSaveAt() { return new Date(lastSave()); } + @Override + default String memoryDoctor() { + return execute((client)->client.serverOperations().memoryDoctor()); + } + + @Override + default Status memoryPurge() { + return execute((client)->client.serverOperations().memoryPurge()); + } + + @Override + default MemoryStats memoryStats() { + return execute((client)->client.serverOperations().memoryStats()); + } + + @Override + default List moduleList() { + return execute((client)->client.serverOperations().moduleList()); + } + + @Override + default Status moduleLoad(final String path, final String... arguments) { + return execute((client)->client.serverOperations().moduleLoad(path, arguments)); + } + + @Override + default Status moduleLoad(final byte[] path, final byte[]... arguments) { + return execute((client)->client.serverOperations().moduleLoad(path, arguments)); + } + + @Override + default Status moduleUnLoad(final String name) { + return execute((client)->client.serverOperations().moduleUnLoad(name)); + } + + @Override + default Status moduleUnLoad(final byte[] name) { + return execute((client)->client.serverOperations().moduleUnLoad(name)); + } + + @Override + default void monitor(final RedisMonitor redisMonitor) { + execute((client)->{ + client.serverOperations().monitor(redisMonitor); + return null; + }); + } + + @Override + default Object pSync(final String replicationId, final long offset) { + return execute((client)->client.serverOperations().pSync(replicationId, offset)); + } + + @Override + default Object pSync(final byte[] replicationId, final long offset) { + return execute((client)->client.serverOperations().pSync(replicationId, offset)); + } + + @Override + default void sync() { + execute((client)->{ + client.serverOperations().sync(); + return null; + }); + } + + @Override + default Status replicaOf(final String host, final int port) { + return execute((client)->client.serverOperations().replicaOf(host, port)); + } + /** * 用于在 Redis 运行时动态地修改复制(replication)功能的行为; * 可以将当前服务器转变为指定服务器的从属服务器(slave server) @@ -113,7 +396,7 @@ default Date lastSaveAt(){ * * @return 总是返回 Status.SUCCESS */ - default Status replicaOf(final String host){ + default Status replicaOf(final String host) { return replicaOf(host, RedisNode.DEFAULT_PORT); } @@ -129,11 +412,16 @@ default Status replicaOf(final String host){ * * @return 操作结果 */ - default Status replicaOf(final RedisNode server){ + default Status replicaOf(final RedisNode server) { Assert.isNull(server, "Redis server cloud not be null."); return replicaOf(server.getHost(), server.getPort()); } + @Override + default Status slaveOf(final String host, final int port) { + return execute((client)->client.serverOperations().slaveOf(host, port)); + } + /** * 用于在 Redis 运行时动态地修改复制(replication)功能的行为; * 可以将当前服务器转变为指定服务器的从属服务器(slave server) @@ -145,7 +433,7 @@ default Status replicaOf(final RedisNode server){ * * @return 总是返回 Status.SUCCESS */ - default Status slaveOf(final String host){ + default Status slaveOf(final String host) { return slaveOf(host, RedisNode.DEFAULT_PORT); } @@ -160,9 +448,65 @@ default Status slaveOf(final String host){ * * @return 总是返回 Status.SUCCESS */ - default Status slaveOf(final RedisNode server){ + default Status slaveOf(final RedisNode server) { Assert.isNull(server, "Redis server cloud not be null."); return replicaOf(server.getHost(), server.getPort()); } + @Override + default Role role() { + return execute((client)->client.serverOperations().role()); + } + + @Override + default Status save() { + return execute((client)->client.serverOperations().save()); + } + + @Override + default void shutdown() { + execute((client)->{ + client.serverOperations().shutdown(); + return null; + }); + } + + @Override + default void shutdown(final boolean save) { + execute((client)->{ + client.serverOperations().shutdown(save); + return null; + }); + } + + @Override + default List slowLogGet() { + return execute((client)->client.serverOperations().slowLogGet()); + } + + @Override + default List slowLogGet(final long count) { + return execute((client)->client.serverOperations().slowLogGet(count)); + } + + @Override + default Long slowLogLen() { + return execute((client)->client.serverOperations().slowLogLen()); + } + + @Override + default Status slowLogReset() { + return execute((client)->client.serverOperations().slowLogReset()); + } + + @Override + default Status swapdb(final int db1, final int db2) { + return execute((client)->client.serverOperations().swapdb(db1, db2)); + } + + @Override + default RedisServerTime time() { + return execute((client)->client.serverOperations().time()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/core/operations/SortedSetOperations.java b/buession-redis/src/main/java/com/buession/redis/core/operations/SortedSetOperations.java index 10c5ea7fc..1710c7e2c 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/operations/SortedSetOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/core/operations/SortedSetOperations.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.operations; @@ -32,7 +32,6 @@ import com.buession.redis.core.command.SortedSetCommands; import java.util.List; -import java.util.Set; /** * 有序集合运算 @@ -57,7 +56,7 @@ public interface SortedSetOperations extends SortedSetCommands, RedisOperations * * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ - default Long zAdd(final String key, final double score, final String member){ + default Long zAdd(final String key, final double score, final String member) { return zAdd(key, MapBuilder.of(member, score)); } @@ -75,7 +74,7 @@ default Long zAdd(final String key, final double score, final String member){ * * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ - default Long zAdd(final byte[] key, final double score, final byte[] member){ + default Long zAdd(final byte[] key, final double score, final byte[] member) { return zAdd(key, MapBuilder.of(member, score)); } @@ -97,7 +96,7 @@ default Long zAdd(final byte[] key, final double score, final byte[] member){ * * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ - default Long zAdd(final String key, final double score, final String member, final NxXx nxXx){ + default Long zAdd(final String key, final double score, final String member, final NxXx nxXx) { return zAdd(key, MapBuilder.of(member, score), nxXx); } @@ -119,7 +118,7 @@ default Long zAdd(final String key, final double score, final String member, fin * * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ - default Long zAdd(final byte[] key, final double score, final byte[] member, final NxXx nxXx){ + default Long zAdd(final byte[] key, final double score, final byte[] member, final NxXx nxXx) { return zAdd(key, MapBuilder.of(member, score), nxXx); } @@ -141,7 +140,7 @@ default Long zAdd(final byte[] key, final double score, final byte[] member, fin * * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ - default Long zAdd(final String key, final double score, final String member, final GtLt gtLt){ + default Long zAdd(final String key, final double score, final String member, final GtLt gtLt) { return zAdd(key, MapBuilder.of(member, score), gtLt); } @@ -163,7 +162,7 @@ default Long zAdd(final String key, final double score, final String member, fin * * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ - default Long zAdd(final byte[] key, final double score, final byte[] member, final GtLt gtLt){ + default Long zAdd(final byte[] key, final double score, final byte[] member, final GtLt gtLt) { return zAdd(key, MapBuilder.of(member, score), gtLt); } @@ -184,7 +183,7 @@ default Long zAdd(final byte[] key, final double score, final byte[] member, fin * * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ - default Long zAdd(final String key, final double score, final String member, final boolean ch){ + default Long zAdd(final String key, final double score, final String member, final boolean ch) { return zAdd(key, MapBuilder.of(member, score), ch); } @@ -205,7 +204,7 @@ default Long zAdd(final String key, final double score, final String member, fin * * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ - default Long zAdd(final byte[] key, final double score, final byte[] member, final boolean ch){ + default Long zAdd(final byte[] key, final double score, final byte[] member, final boolean ch) { return zAdd(key, MapBuilder.of(member, score), ch); } @@ -231,7 +230,7 @@ default Long zAdd(final byte[] key, final double score, final byte[] member, fin * * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ - default Long zAdd(final String key, final double score, final String member, final NxXx nxXx, final GtLt gtLt){ + default Long zAdd(final String key, final double score, final String member, final NxXx nxXx, final GtLt gtLt) { return zAdd(key, MapBuilder.of(member, score), nxXx, gtLt); } @@ -257,7 +256,7 @@ default Long zAdd(final String key, final double score, final String member, fin * * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ - default Long zAdd(final byte[] key, final double score, final byte[] member, final NxXx nxXx, final GtLt gtLt){ + default Long zAdd(final byte[] key, final double score, final byte[] member, final NxXx nxXx, final GtLt gtLt) { return zAdd(key, MapBuilder.of(member, score), nxXx, gtLt); } @@ -282,7 +281,7 @@ default Long zAdd(final byte[] key, final double score, final byte[] member, fin * * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ - default Long zAdd(final String key, final double score, final String member, final NxXx nxXx, final boolean ch){ + default Long zAdd(final String key, final double score, final String member, final NxXx nxXx, final boolean ch) { return zAdd(key, MapBuilder.of(member, score), nxXx, ch); } @@ -307,7 +306,7 @@ default Long zAdd(final String key, final double score, final String member, fin * * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ - default Long zAdd(final byte[] key, final double score, final byte[] member, final NxXx nxXx, final boolean ch){ + default Long zAdd(final byte[] key, final double score, final byte[] member, final NxXx nxXx, final boolean ch) { return zAdd(key, MapBuilder.of(member, score), nxXx, ch); } @@ -332,7 +331,7 @@ default Long zAdd(final byte[] key, final double score, final byte[] member, fin * * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ - default Long zAdd(final String key, final double score, final String member, final GtLt gtLt, final boolean ch){ + default Long zAdd(final String key, final double score, final String member, final GtLt gtLt, final boolean ch) { return zAdd(key, MapBuilder.of(member, score), gtLt, ch); } @@ -357,7 +356,7 @@ default Long zAdd(final String key, final double score, final String member, fin * * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ - default Long zAdd(final byte[] key, final double score, final byte[] member, final GtLt gtLt, final boolean ch){ + default Long zAdd(final byte[] key, final double score, final byte[] member, final GtLt gtLt, final boolean ch) { return zAdd(key, MapBuilder.of(member, score), gtLt, ch); } @@ -387,7 +386,7 @@ default Long zAdd(final byte[] key, final double score, final byte[] member, fin * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ default Long zAdd(final String key, final double score, final String member, final NxXx nxXx, final GtLt gtLt, - final boolean ch){ + final boolean ch) { return zAdd(key, MapBuilder.of(member, score), nxXx, gtLt, ch); } @@ -417,7 +416,7 @@ default Long zAdd(final String key, final double score, final String member, fin * @return 被成功添加的新成员的数量,不包括那些被更新的、已经存在的成员 */ default Long zAdd(final byte[] key, final double score, final byte[] member, final NxXx nxXx, final GtLt gtLt, - final boolean ch){ + final boolean ch) { return zAdd(key, MapBuilder.of(member, score), nxXx, gtLt, ch); } @@ -811,7 +810,7 @@ Long zAdd(final byte[] key, final double score, final V member, final NxXx n * * @return The result of the difference */ - Set zDiffObject(final String[] keys); + List zDiffObject(final String[] keys); /** * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client @@ -825,7 +824,7 @@ Long zAdd(final byte[] key, final double score, final V member, final NxXx n * * @return The result of the difference */ - Set zDiffObject(final byte[][] keys); + List zDiffObject(final byte[][] keys); /** * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client @@ -841,7 +840,7 @@ Long zAdd(final byte[] key, final double score, final V member, final NxXx n * * @return The result of the difference */ - Set zDiffObject(final String[] keys, final Class clazz); + List zDiffObject(final String[] keys, final Class clazz); /** * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client @@ -857,7 +856,7 @@ Long zAdd(final byte[] key, final double score, final V member, final NxXx n * * @return The result of the difference */ - Set zDiffObject(final byte[][] keys, final Class clazz); + List zDiffObject(final byte[][] keys, final Class clazz); /** * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client @@ -875,7 +874,7 @@ Long zAdd(final byte[] key, final double score, final V member, final NxXx n * * @see TypeReference */ - Set zDiffObject(final String[] keys, final TypeReference type); + List zDiffObject(final String[] keys, final TypeReference type); /** * This command is similar to ZDIFFSTORE, but instead of storing the resulting sorted set, it is returned to the client @@ -893,7 +892,7 @@ Long zAdd(final byte[] key, final double score, final V member, final NxXx n * * @see TypeReference */ - Set zDiffObject(final byte[][] keys, final TypeReference type); + List zDiffObject(final byte[][] keys, final TypeReference type); /** * 为有序集 key 的成员 member 的 score 值加上增量一 @@ -905,7 +904,7 @@ Long zAdd(final byte[] key, final double score, final V member, final NxXx n * * @return member 成员的新 score 值 */ - default Double zIncr(final String key, final String member){ + default Double zIncr(final String key, final String member) { return zIncrBy(key, 1, member); } @@ -919,7 +918,7 @@ default Double zIncr(final String key, final String member){ * * @return member 成员的新 score 值 */ - default Double zIncr(final byte[] key, final byte[] member){ + default Double zIncr(final byte[] key, final byte[] member) { return zIncrBy(key, 1, member); } @@ -933,7 +932,7 @@ default Double zIncr(final byte[] key, final byte[] member){ * * @return member 成员的新 score 值 */ - default Double zDecr(final String key, final String member){ + default Double zDecr(final String key, final String member) { return zIncrBy(key, -1, member); } @@ -947,7 +946,7 @@ default Double zDecr(final String key, final String member){ * * @return member 成员的新 score 值 */ - default Double zDecr(final byte[] key, final byte[] member){ + default Double zDecr(final byte[] key, final byte[] member) { return zIncrBy(key, -1, member); } @@ -965,7 +964,7 @@ default Double zDecr(final byte[] key, final byte[] member){ * * @return member 成员的新 score 值 */ - default Double zDecrBy(final String key, final double increment, final String member){ + default Double zDecrBy(final String key, final double increment, final String member) { return zIncrBy(key, increment * -1, member); } @@ -983,7 +982,7 @@ default Double zDecrBy(final String key, final double increment, final String me * * @return member 成员的新 score 值 */ - default Double zDecrBy(final byte[] key, final double increment, final byte[] member){ + default Double zDecrBy(final byte[] key, final double increment, final byte[] member) { return zIncrBy(key, increment * -1, member); } @@ -999,7 +998,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @return 有序集合的交集反序列为对象 */ - Set zInterObject(final String[] keys); + List zInterObject(final String[] keys); /** * 计算给定的一个或多个有序集合的交集,并反序列为对象 @@ -1013,7 +1012,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @return 有序集合的交集反序列为对象 */ - Set zInterObject(final byte[][] keys); + List zInterObject(final byte[][] keys); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 @@ -1029,7 +1028,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @return 有序集合的交集反序列为对象 */ - Set zInterObject(final String[] keys, final Class clazz); + List zInterObject(final String[] keys, final Class clazz); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 @@ -1045,7 +1044,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @return 有序集合的交集反序列为对象 */ - Set zInterObject(final byte[][] keys, final Class clazz); + List zInterObject(final byte[][] keys, final Class clazz); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 type 指定的对象 @@ -1063,7 +1062,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @see TypeReference */ - Set zInterObject(final String[] keys, final TypeReference type); + List zInterObject(final String[] keys, final TypeReference type); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 type 指定的对象 @@ -1081,7 +1080,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @see TypeReference */ - Set zInterObject(final byte[][] keys, final TypeReference type); + List zInterObject(final byte[][] keys, final TypeReference type); /** * 计算给定的一个或多个有序集合的交集,并反序列化为对象 @@ -1097,7 +1096,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @return 有序集合的交集反序列为对象 */ - Set zInterObject(final String[] keys, final Aggregate aggregate); + List zInterObject(final String[] keys, final Aggregate aggregate); /** * 计算给定的一个或多个有序集合的交集,并反序列化为对象 @@ -1113,7 +1112,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @return 有序集合的交集反序列为对象 */ - Set zInterObject(final byte[][] keys, final Aggregate aggregate); + List zInterObject(final byte[][] keys, final Aggregate aggregate); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 @@ -1131,7 +1130,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @return 有序集合的交集反序列为对象 */ - Set zInterObject(final String[] keys, final Aggregate aggregate, final Class clazz); + List zInterObject(final String[] keys, final Aggregate aggregate, final Class clazz); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 @@ -1149,7 +1148,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @return 有序集合的交集反序列为对象 */ - Set zInterObject(final byte[][] keys, final Aggregate aggregate, final Class clazz); + List zInterObject(final byte[][] keys, final Aggregate aggregate, final Class clazz); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 @@ -1169,7 +1168,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @see TypeReference */ - Set zInterObject(final String[] keys, final Aggregate aggregate, final TypeReference type); + List zInterObject(final String[] keys, final Aggregate aggregate, final TypeReference type); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 type 指定的对象 @@ -1189,7 +1188,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @see TypeReference */ - Set zInterObject(final byte[][] keys, final Aggregate aggregate, final TypeReference type); + List zInterObject(final byte[][] keys, final Aggregate aggregate, final TypeReference type); /** * 计算给定的一个或多个有序集合的交集,并反序列化对象 @@ -1205,7 +1204,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @return 有序集合的交集反序列为对象 */ - Set zInterObject(final String[] keys, final double[] weights); + List zInterObject(final String[] keys, final double[] weights); /** * 计算给定的一个或多个有序集合的交集,并反序列化为对象 @@ -1221,7 +1220,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @return 有序集合的交集反序列为对象 */ - Set zInterObject(final byte[][] keys, final double[] weights); + List zInterObject(final byte[][] keys, final double[] weights); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 @@ -1239,7 +1238,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @return 有序集合的交集反序列为对象 */ - Set zInterObject(final String[] keys, final double[] weights, final Class clazz); + List zInterObject(final String[] keys, final double[] weights, final Class clazz); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 @@ -1257,7 +1256,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @return 有序集合的交集反序列为对象 */ - Set zInterObject(final byte[][] keys, final double[] weights, final Class clazz); + List zInterObject(final byte[][] keys, final double[] weights, final Class clazz); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 type 指定的对象 @@ -1277,7 +1276,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @see TypeReference */ - Set zInterObject(final String[] keys, final double[] weights, final TypeReference type); + List zInterObject(final String[] keys, final double[] weights, final TypeReference type); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 type 指定的对象 @@ -1297,7 +1296,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @see TypeReference */ - Set zInterObject(final byte[][] keys, final double[] weights, final TypeReference type); + List zInterObject(final byte[][] keys, final double[] weights, final TypeReference type); /** * 计算给定的一个或多个有序集合的交集,并反序列化为对象 @@ -1315,7 +1314,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @return 有序集合的交集反序列为对象 */ - Set zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights); + List zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights); /** * 计算给定的一个或多个有序集合的交集,并反序列化为对象 @@ -1333,7 +1332,7 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @return The result of intersection */ - Set zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights); + List zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 @@ -1353,8 +1352,8 @@ default Double zDecrBy(final byte[] key, final double increment, final byte[] me * * @return 有序集合的交集反序列为对象 */ - Set zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights, - final Class clazz); + List zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final Class clazz); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 clazz 指定的对象 @@ -1374,8 +1373,8 @@ Set zInterObject(final String[] keys, final Aggregate aggregate, final do * * @return 有序集合的交集反序列为对象 */ - Set zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, - final Class clazz); + List zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final Class clazz); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 type 指定的对象 @@ -1397,8 +1396,8 @@ Set zInterObject(final byte[][] keys, final Aggregate aggregate, final do * * @see TypeReference */ - Set zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights, - final TypeReference type); + List zInterObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type); /** * 计算给定的一个或多个有序集合的交集,并反序列化为 type 指定的对象 @@ -1420,8 +1419,8 @@ Set zInterObject(final String[] keys, final Aggregate aggregate, final do * * @see TypeReference */ - Set zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, - final TypeReference type); + List zInterObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type); /** * 返回有序集合 key 中的一个随机元素,并反序列为对象 @@ -2599,7 +2598,7 @@ List zRangeByScoreObject(final byte[] key, final byte[] min, final byte[] * * @return 被成功移除的成员的数量,不包括被忽略的成员 */ - default long zRem(final String key, final String member){ + default long zRem(final String key, final String member) { return zRem(key, new String[]{member}); } @@ -2615,7 +2614,7 @@ default long zRem(final String key, final String member){ * * @return 被成功移除的成员的数量,不包括被忽略的成员 */ - default long zRem(final byte[] key, final byte[] member){ + default long zRem(final byte[] key, final byte[] member) { return zRem(key, new byte[][]{member}); } @@ -3931,7 +3930,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @return 反序列化为对象后的集合并集 */ - Set zUnionObject(final String[] keys); + List zUnionObject(final String[] keys); /** * 计算给定的一个或多个有序集的并集,并反序列为对象 @@ -3945,7 +3944,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @return 反序列化为对象后的集合并集 */ - Set zUnionObject(final byte[][] keys); + List zUnionObject(final byte[][] keys); /** * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 @@ -3961,7 +3960,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @return 反序列化为对象后的集合并集 */ - Set zUnionObject(final String[] keys, final Class clazz); + List zUnionObject(final String[] keys, final Class clazz); /** * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 @@ -3977,7 +3976,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @return 反序列化为对象后的集合并集 */ - Set zUnionObject(final byte[][] keys, final Class clazz); + List zUnionObject(final byte[][] keys, final Class clazz); /** * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 @@ -3995,7 +3994,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @see TypeReference */ - Set zUnionObject(final String[] keys, final TypeReference type); + List zUnionObject(final String[] keys, final TypeReference type); /** * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 @@ -4013,7 +4012,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @see TypeReference */ - Set zUnionObject(final byte[][] keys, final TypeReference type); + List zUnionObject(final byte[][] keys, final TypeReference type); /** * 计算给定的一个或多个有序集的并集,并反序列为对象 @@ -4029,7 +4028,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @return 并集成员反序列化为对象的列表 */ - Set zUnionObject(final String[] keys, final Aggregate aggregate); + List zUnionObject(final String[] keys, final Aggregate aggregate); /** * 计算给定的一个或多个有序集的并集,并反序列为对象 @@ -4045,7 +4044,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @return 并集成员反序列化为对象的列表 */ - Set zUnionObject(final byte[][] keys, final Aggregate aggregate); + List zUnionObject(final byte[][] keys, final Aggregate aggregate); /** * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 @@ -4063,7 +4062,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @return 并集成员反序列化为对象的列表 */ - Set zUnionObject(final String[] keys, final Aggregate aggregate, final Class clazz); + List zUnionObject(final String[] keys, final Aggregate aggregate, final Class clazz); /** * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 @@ -4081,7 +4080,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @return 并集成员反序列化为对象的列表 */ - Set zUnionObject(final byte[][] keys, final Aggregate aggregate, final Class clazz); + List zUnionObject(final byte[][] keys, final Aggregate aggregate, final Class clazz); /** * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 @@ -4101,7 +4100,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @see TypeReference */ - Set zUnionObject(final String[] keys, final Aggregate aggregate, final TypeReference type); + List zUnionObject(final String[] keys, final Aggregate aggregate, final TypeReference type); /** * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 @@ -4121,7 +4120,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @see TypeReference */ - Set zUnionObject(final byte[][] keys, final Aggregate aggregate, final TypeReference type); + List zUnionObject(final byte[][] keys, final Aggregate aggregate, final TypeReference type); /** * 计算给定的一个或多个有序集的并集,并反序列为对象 @@ -4137,7 +4136,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @return 并集成员反序列化为对象的列表 */ - Set zUnionObject(final String[] keys, final double[] weights); + List zUnionObject(final String[] keys, final double[] weights); /** * 计算给定的一个或多个有序集的并集,并反序列为对象 @@ -4153,7 +4152,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @return 并集成员反序列化为对象的列表 */ - Set zUnionObject(final byte[][] keys, final double[] weights); + List zUnionObject(final byte[][] keys, final double[] weights); /** * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 @@ -4171,7 +4170,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @return 并集成员反序列化为对象的列表 */ - Set zUnionObject(final String[] keys, final double[] weights, final Class clazz); + List zUnionObject(final String[] keys, final double[] weights, final Class clazz); /** * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 @@ -4189,7 +4188,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @return 并集成员反序列化为对象的列表 */ - Set zUnionObject(final byte[][] keys, final double[] weights, final Class clazz); + List zUnionObject(final byte[][] keys, final double[] weights, final Class clazz); /** * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 @@ -4209,7 +4208,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @see TypeReference */ - Set zUnionObject(final String[] keys, final double[] weights, final TypeReference type); + List zUnionObject(final String[] keys, final double[] weights, final TypeReference type); /** * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 @@ -4229,7 +4228,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @see TypeReference */ - Set zUnionObject(final byte[][] keys, final double[] weights, final TypeReference type); + List zUnionObject(final byte[][] keys, final double[] weights, final TypeReference type); /** * 计算给定的一个或多个有序集的并集,并反序列为对象 @@ -4247,7 +4246,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @return 并集成员反序列化为对象的列表 */ - Set zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights); + List zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights); /** * 计算给定的一个或多个有序集的并集,并反序列为对象 @@ -4265,7 +4264,7 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @return 并集成员反序列化为对象的列表 */ - Set zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights); + List zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights); /** * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 @@ -4285,8 +4284,8 @@ List zRevRangeByScoreObject(final byte[] key, final byte[] min, final byt * * @return 并集成员反序列化为对象的列表 */ - Set zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights, - final Class clazz); + List zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final Class clazz); /** * 计算给定的一个或多个有序集的并集,并反序列化为 clazz 指定的对象 @@ -4306,8 +4305,8 @@ Set zUnionObject(final String[] keys, final Aggregate aggregate, final do * * @return 并集成员反序列化为对象的列表 */ - Set zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, - final Class clazz); + List zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final Class clazz); /** * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 @@ -4329,8 +4328,8 @@ Set zUnionObject(final byte[][] keys, final Aggregate aggregate, final do * * @see TypeReference */ - Set zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights, - final TypeReference type); + List zUnionObject(final String[] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type); /** * 计算给定的一个或多个有序集的并集,并反序列化为 type 指定的对象 @@ -4352,7 +4351,7 @@ Set zUnionObject(final String[] keys, final Aggregate aggregate, final do * * @see TypeReference */ - Set zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, - final TypeReference type); + List zUnionObject(final byte[][] keys, final Aggregate aggregate, final double[] weights, + final TypeReference type); } diff --git a/buession-redis/src/main/java/com/buession/redis/core/operations/TransactionOperations.java b/buession-redis/src/main/java/com/buession/redis/core/operations/TransactionOperations.java index b79f39e6a..d9ede8c41 100644 --- a/buession-redis/src/main/java/com/buession/redis/core/operations/TransactionOperations.java +++ b/buession-redis/src/main/java/com/buession/redis/core/operations/TransactionOperations.java @@ -19,12 +19,14 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2020 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.core.operations; +import com.buession.lang.Status; import com.buession.redis.core.command.TransactionCommands; +import com.buession.redis.transaction.Transaction; /** * 事务运算 @@ -35,4 +37,21 @@ */ public interface TransactionOperations extends TransactionCommands, RedisOperations { + @Override + default Status multi() { + return execute((client)->{ + try{ + final Transaction transaction = client.getConnection().multi(); + return transaction != null ? Status.SUCCESS : Status.FAILURE; + }catch(Exception e){ + return Status.FAILURE; + } + }); + } + + @Override + default Status unwatch() { + return execute((client)->client.transactionOperations().unwatch()); + } + } diff --git a/buession-redis/src/main/java/com/buession/redis/exception/LettuceRedisExceptionUtils.java b/buession-redis/src/main/java/com/buession/redis/exception/LettuceRedisExceptionUtils.java new file mode 100644 index 000000000..381f5f19a --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/exception/LettuceRedisExceptionUtils.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2023 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.exception; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceRedisExceptionUtils { + + public static RedisException convert(final Exception e) { + /* + if(e instanceof JedisConnectionException){ + if(StringUtils.contains(e.getMessage(), "pool")){ + return new PoolException(e.getMessage(), e); + }else{ + return new RedisConnectionFailureException(e.getMessage(), e); + } + }else + + } + + */ + if(e instanceof NotSupportedCommandException){ + return (NotSupportedCommandException) e; + }else{ + return new RedisException(e.getMessage(), e); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/exception/RedisPipelineException.java b/buession-redis/src/main/java/com/buession/redis/exception/RedisPipelineException.java new file mode 100644 index 000000000..167601dea --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/exception/RedisPipelineException.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.exception; + +import com.buession.core.builder.ListBuilder; + +import java.util.Collections; +import java.util.List; + +/** + * Redis 管道异常 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class RedisPipelineException extends RedisException { + + private final static long serialVersionUID = 1470569084378076197L; + + private final List results; + + public RedisPipelineException() { + this(ListBuilder.empty()); + } + + public RedisPipelineException(String message) { + this(message, ListBuilder.empty()); + } + + public RedisPipelineException(String message, Throwable cause) { + this(message, cause, ListBuilder.empty()); + } + + public RedisPipelineException(Throwable cause) { + this(cause, ListBuilder.empty()); + } + + public RedisPipelineException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { + this(message, cause, enableSuppression, writableStackTrace, ListBuilder.empty()); + } + + public RedisPipelineException(List results) { + super("Pipeline contained one or more invalid commands"); + this.results = Collections.unmodifiableList(results); + } + + public RedisPipelineException(String message, List results) { + super(message); + this.results = Collections.unmodifiableList(results); + } + + public RedisPipelineException(String message, Throwable cause, List results) { + super(message, cause); + this.results = Collections.unmodifiableList(results); + } + + public RedisPipelineException(Throwable cause, List results) { + super("Pipeline contained one or more invalid commands", cause); + this.results = Collections.unmodifiableList(results); + } + + public RedisPipelineException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace, List results) { + super(message, cause, enableSuppression, writableStackTrace); + this.results = Collections.unmodifiableList(results); + } + + public List getPipelineResult() { + return results; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/exception/RedisTransactionException.java b/buession-redis/src/main/java/com/buession/redis/exception/RedisTransactionException.java new file mode 100644 index 000000000..60ddca0af --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/exception/RedisTransactionException.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.exception; + +import com.buession.core.builder.ListBuilder; + +import java.util.Collections; +import java.util.List; + +/** + * Redis 事务异常 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class RedisTransactionException extends RedisException { + + private final static long serialVersionUID = 1470569084378076197L; + + private final List results; + + public RedisTransactionException() { + this(ListBuilder.empty()); + } + + public RedisTransactionException(String message) { + this(message, ListBuilder.empty()); + } + + public RedisTransactionException(String message, Throwable cause) { + this(message, cause, ListBuilder.empty()); + } + + public RedisTransactionException(Throwable cause) { + this(cause, ListBuilder.empty()); + } + + public RedisTransactionException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { + this(message, cause, enableSuppression, writableStackTrace, ListBuilder.empty()); + } + + public RedisTransactionException(List results) { + super("Transaction contained one or more invalid commands"); + this.results = Collections.unmodifiableList(results); + } + + public RedisTransactionException(String message, List results) { + super(message); + this.results = Collections.unmodifiableList(results); + } + + public RedisTransactionException(String message, Throwable cause, List results) { + super(message, cause); + this.results = Collections.unmodifiableList(results); + } + + public RedisTransactionException(Throwable cause, List results) { + super("Transaction contained one or more invalid commands", cause); + this.results = Collections.unmodifiableList(results); + } + + public RedisTransactionException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace, List results) { + super(message, cause, enableSuppression, writableStackTrace); + this.results = Collections.unmodifiableList(results); + } + + public List getPipelineResult() { + return results; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/package-info.java b/buession-redis/src/main/java/com/buession/redis/package-info.java index 3c425f789..5f1d346ce 100644 --- a/buession-redis/src/main/java/com/buession/redis/package-info.java +++ b/buession-redis/src/main/java/com/buession/redis/package-info.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ /** diff --git a/buession-redis/src/main/java/com/buession/redis/pipeline/AbstractPipelineProxy.java b/buession-redis/src/main/java/com/buession/redis/pipeline/AbstractPipelineProxy.java new file mode 100644 index 000000000..cfcf33e2f --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/pipeline/AbstractPipelineProxy.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.pipeline; + +import com.buession.redis.core.FutureResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.stream.Collectors; + +/** + * 管道代理抽象类 + * + * @param + * 原生管道类型 + * @param + * 管道异步结果 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractPipelineProxy> implements PipelineProxy { + + private Pipeline target; + + private final T object; + + private final Queue txResults = new LinkedList<>(); + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + public AbstractPipelineProxy(final Pipeline target, final T object) { + //Assert.isNull(target, "Redis Pipeline cloud not be null."); + this.target = target; + this.object = object; + } + + @Override + public T getObject() { + return object; + } + + @Override + public Queue getTxResults() { + return txResults; + } + + @Override + public void sync() { + logger.info("Redis pipeline sync."); + target.sync(); + } + + @Override + public List syncAndReturnAll() { + logger.info("Redis pipeline syncAndReturnAll."); + + target.sync(); + return txResults.stream().map((r)->r.convert(r.get())).collect(Collectors.toList()); + } + + @Override + public void close() { + logger.info("Redis pipeline close."); + txResults.clear(); + target.close(); + } + + protected void setTarget(Pipeline target) { + this.target = target; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/pipeline/Pipeline.java b/buession-redis/src/main/java/com/buession/redis/pipeline/Pipeline.java index decd5482b..f5ef9780e 100644 --- a/buession-redis/src/main/java/com/buession/redis/pipeline/Pipeline.java +++ b/buession-redis/src/main/java/com/buession/redis/pipeline/Pipeline.java @@ -27,14 +27,27 @@ import java.util.List; /** + * 管道 + * * @author Yong.Teng */ public interface Pipeline { + /** + * 同步管道 + */ void sync(); + /** + * 同步管道,并返回所有命令执行结果 + * + * @return 命令执行结果 + */ List syncAndReturnAll(); + /** + * 关闭管道 + */ void close(); } diff --git a/buession-redis/src/main/java/com/buession/redis/pipeline/PipelineProxy.java b/buession-redis/src/main/java/com/buession/redis/pipeline/PipelineProxy.java new file mode 100644 index 000000000..9557dd440 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/pipeline/PipelineProxy.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.pipeline; + +import com.buession.redis.core.FutureResult; + +import java.util.Queue; + +/** + * 管道代理 + * + * @param + * 原生管道类型 + * @param + * 管道异步结果 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface PipelineProxy> extends Pipeline { + + /** + * 返回原生管道实例 + * + * @return 原生管道实例 + */ + T getObject(); + + Queue getTxResults(); + +} diff --git a/buession-redis/src/main/java/com/buession/redis/pipeline/jedis/JedisClusterPipeline.java b/buession-redis/src/main/java/com/buession/redis/pipeline/jedis/JedisClusterPipeline.java new file mode 100644 index 000000000..1586b87ad --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/pipeline/jedis/JedisClusterPipeline.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.pipeline.jedis; + +import com.buession.core.utils.Assert; +import com.buession.redis.pipeline.Pipeline; + +import java.util.List; + +/** + * Jedis 集群模式管道 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class JedisClusterPipeline implements Pipeline { + + private final redis.clients.jedis.ClusterPipeline delegate; + + public JedisClusterPipeline(final redis.clients.jedis.ClusterPipeline pipeline) { + Assert.isNull(pipeline, "Redis Pipeline cloud not be null."); + this.delegate = pipeline; + } + + @Override + public void sync() { + delegate.sync(); + } + + @Override + public List syncAndReturnAll() { + return null; + } + + @Override + public void close() { + delegate.close(); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/pipeline/jedis/JedisPipeline.java b/buession-redis/src/main/java/com/buession/redis/pipeline/jedis/JedisPipeline.java index 57a276df8..ea97563ad 100644 --- a/buession-redis/src/main/java/com/buession/redis/pipeline/jedis/JedisPipeline.java +++ b/buession-redis/src/main/java/com/buession/redis/pipeline/jedis/JedisPipeline.java @@ -19,51 +19,42 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.pipeline.jedis; import com.buession.core.utils.Assert; import com.buession.redis.pipeline.Pipeline; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.List; /** + * Jedis 单例、哨兵模式管道 + * * @author Yong.Teng */ public class JedisPipeline implements Pipeline { private final redis.clients.jedis.Pipeline delegate; - private final static Logger logger = LoggerFactory.getLogger(JedisPipeline.class); - - public JedisPipeline(redis.clients.jedis.Pipeline pipeline) { + public JedisPipeline(final redis.clients.jedis.Pipeline pipeline) { Assert.isNull(pipeline, "Redis Pipeline cloud not be null."); this.delegate = pipeline; } - public redis.clients.jedis.Pipeline primitive() { - return delegate; - } - @Override public void sync() { - logger.info("Redis pipeline sync."); delegate.sync(); } @Override public List syncAndReturnAll() { - logger.info("Redis pipeline syncAndReturnAll."); return delegate.syncAndReturnAll(); } @Override public void close() { - logger.info("Redis pipeline close."); delegate.close(); } diff --git a/buession-redis/src/main/java/com/buession/redis/pipeline/jedis/JedisPipelineProxy.java b/buession-redis/src/main/java/com/buession/redis/pipeline/jedis/JedisPipelineProxy.java new file mode 100644 index 000000000..c8718d352 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/pipeline/jedis/JedisPipelineProxy.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.pipeline.jedis; + +import com.buession.redis.core.internal.jedis.JedisResult; +import com.buession.redis.pipeline.AbstractPipelineProxy; +import com.buession.redis.pipeline.Pipeline; + +/** + * Jedis 管道代理 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class JedisPipelineProxy extends AbstractPipelineProxy> { + + public JedisPipelineProxy(final Pipeline target, final T object) { + super(target, object); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/pipeline/lettuce/LettucePipeline.java b/buession-redis/src/main/java/com/buession/redis/pipeline/lettuce/LettucePipeline.java new file mode 100644 index 000000000..412b71ef9 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/pipeline/lettuce/LettucePipeline.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.pipeline.lettuce; + +import com.buession.core.utils.Assert; +import com.buession.redis.core.internal.lettuce.LettuceResult; +import com.buession.redis.exception.RedisPipelineException; +import com.buession.redis.pipeline.Pipeline; +import io.lettuce.core.LettuceFutures; +import io.lettuce.core.RedisFuture; +import io.lettuce.core.api.PipeliningFlushState; +import io.lettuce.core.api.StatefulConnection; +import io.lettuce.core.output.CommandOutput; +import io.lettuce.core.protocol.RedisCommand; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.Queue; +import java.util.concurrent.TimeUnit; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettucePipeline implements Pipeline { + + private final PipeliningFlushState flushState; + + private final StatefulConnection connection; + + private Queue> ppline; + + public LettucePipeline(final StatefulConnection connection, final PipeliningFlushState flushState) { + Assert.isNull(flushState, "Redis Pipeline cloud not be null."); + this.connection = connection; + this.flushState = flushState; + this.flushState.onOpen(connection); + } + + public LettucePipeline(final StatefulConnection connection, final PipeliningFlushState flushState + , final Queue> ppline) { + this(connection, flushState); + this.ppline = Optional.ofNullable(ppline).orElse(new LinkedList<>()); + } + + @Override + public void sync() { + List> futures = new ArrayList<>(ppline.size()); + + for(LettuceResult result : ppline){ + futures.add(result.getHolder()); + } + + try{ + boolean done = LettuceFutures.awaitAll(connection.getTimeout().toMillis(), TimeUnit.MILLISECONDS, + futures.toArray(new RedisFuture[futures.size()])); + + Exception problem = null; + + if(done){ + CommandOutput output; + + for(LettuceResult result : ppline){ + output = result.getHolder().getOutput(); + if(output.hasError()){ + Exception err = new RedisPipelineException(output.getError()); + if(problem == null){ + problem = err; + } + }else{ + result.get(); + } + } + } + + if(problem != null){ + throw new RedisPipelineException(problem.getMessage(), problem); + } + + if(done){ + return; + } + + throw new RedisPipelineException("Redis command timed out"); + }catch(Exception e){ + throw new RedisPipelineException(e); + } + } + + @Override + public List syncAndReturnAll() { + List> futures = new ArrayList<>(ppline.size()); + + for(LettuceResult result : ppline){ + futures.add(result.getHolder()); + } + + try{ + boolean done = LettuceFutures.awaitAll(connection.getTimeout().toMillis(), TimeUnit.MILLISECONDS, + futures.toArray(new RedisFuture[futures.size()])); + + List results = new ArrayList<>(futures.size()); + + Exception problem = null; + + if(done){ + CommandOutput output; + + for(LettuceResult result : ppline){ + output = result.getHolder().getOutput(); + if(output.hasError()){ + Exception err = new RedisPipelineException(output.getError()); + if(problem == null){ + problem = err; + } + results.add(err); + }else{ + try{ + results.add(result.get()); + }catch(Exception e){ + if(problem == null){ + problem = e; + } + results.add(e); + } + } + } + } + + if(problem != null){ + throw new RedisPipelineException(problem.getMessage(), problem); + } + + if(done){ + return results; + } + + throw new RedisPipelineException("Redis command timed out"); + }catch(Exception e){ + throw new RedisPipelineException(e); + } + } + + @Override + public void close() { + flushState.onClose(connection); + if(ppline != null){ + ppline.clear(); + } + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/pipeline/lettuce/LettucePipelineProxy.java b/buession-redis/src/main/java/com/buession/redis/pipeline/lettuce/LettucePipelineProxy.java new file mode 100644 index 000000000..79127d633 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/pipeline/lettuce/LettucePipelineProxy.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.pipeline.lettuce; + +import com.buession.redis.core.internal.lettuce.LettuceResult; +import com.buession.redis.pipeline.AbstractPipelineProxy; +import com.buession.redis.pipeline.Pipeline; + +/** + * Lettuce 管道代理 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettucePipelineProxy extends AbstractPipelineProxy> { + + public LettucePipelineProxy(final T object) { + super(null, object); + } + + public LettucePipelineProxy(final Pipeline target, final T object) { + super(target, object); + } + + @Override + public void setTarget(Pipeline target) { + super.setTarget(target); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/pipeline/lettuce/package-info.java b/buession-redis/src/main/java/com/buession/redis/pipeline/lettuce/package-info.java new file mode 100644 index 000000000..43b559102 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/pipeline/lettuce/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.pipeline.lettuce; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/pubsub/lettuce/package-info.java b/buession-redis/src/main/java/com/buession/redis/pubsub/lettuce/package-info.java new file mode 100644 index 000000000..eda5e3981 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/pubsub/lettuce/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.pubsub.lettuce; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/serializer/AbstractSerializer.java b/buession-redis/src/main/java/com/buession/redis/serializer/AbstractSerializer.java index fbd42b25e..4943ded02 100644 --- a/buession-redis/src/main/java/com/buession/redis/serializer/AbstractSerializer.java +++ b/buession-redis/src/main/java/com/buession/redis/serializer/AbstractSerializer.java @@ -21,15 +21,12 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.redis.serializer; import com.buession.core.collect.Arrays; -import com.buession.core.deserializer.DeserializerException; -import com.buession.core.serializer.SerializerException; -import com.buession.core.utils.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,96 +35,18 @@ * * @author Yong.Teng */ -public abstract class AbstractSerializer implements Serializer { - - /** - * 序列化器 - */ - protected final S serializer; - - /** - * 反序列化器 - */ - protected final D deserializer; +public abstract class AbstractSerializer implements Serializer { protected final Logger logger = LoggerFactory.getLogger(getClass()); - /** - * 构造函数 - * - * @param serializer - * 序列化器 - * @param deserializer - * 反序列化器 - */ - protected AbstractSerializer(final S serializer, final D deserializer) { - Assert.isNull(serializer, "original serializer object cloud not be null."); - Assert.isNull(deserializer, "original deserializer object cloud not be null."); - this.serializer = serializer; - this.deserializer = deserializer; - } - - @Override - public String serialize(final V object) { - if(object != null){ - try{ - return serializer.serialize(object); - }catch(SerializerException e){ - logger.error("{} serializer error.", object, e); - } - } - - return null; - } - @Override public final String[] serialize(final V[] objects) { return Arrays.map(objects, String.class, this::serialize); } - @Override - public byte[] serializeAsBytes(final V object) { - if(object != null){ - try{ - return serializer.serializeAsBytes(object); - }catch(SerializerException e){ - logger.error("{} serializer error.", object, e); - } - } - - return null; - } - @Override public byte[][] serializeAsBytes(final V[] objects) { return Arrays.map(objects, byte[].class, this::serializeAsBytes); } - @Override - public V deserialize(final String str) { - if(str != null){ - try{ - return deserializer.deserialize(str); - }catch(DeserializerException e){ - logger.error("{} serializer error.", str, e); - } - } - - return null; - } - - @Override - public V deserializeBytes(final byte[] bytes) { - if(bytes != null){ - try{ - return deserializer.deserialize(bytes); - }catch(DeserializerException e){ - logger.error("{} serializer error.", bytes, e); - } - } - - return null; - } - } diff --git a/buession-redis/src/main/java/com/buession/redis/serializer/ByteArraySerializer.java b/buession-redis/src/main/java/com/buession/redis/serializer/ByteArraySerializer.java index 25b447557..05a3ce85a 100644 --- a/buession-redis/src/main/java/com/buession/redis/serializer/ByteArraySerializer.java +++ b/buession-redis/src/main/java/com/buession/redis/serializer/ByteArraySerializer.java @@ -21,13 +21,15 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.redis.serializer; import com.buession.core.deserializer.DefaultByteArrayDeserializer; +import com.buession.core.deserializer.DeserializerException; import com.buession.core.serializer.DefaultByteArraySerializer; +import com.buession.core.serializer.SerializerException; import com.buession.core.type.TypeReference; /** @@ -35,33 +37,136 @@ * * @author Yong.Teng */ -public class ByteArraySerializer extends AbstractSerializer { +public class ByteArraySerializer extends AbstractSerializer { /** - * 构造函数 + * 序列化器 */ - public ByteArraySerializer(){ - super(new DefaultByteArraySerializer(), new DefaultByteArrayDeserializer()); + private final com.buession.core.serializer.ByteArraySerializer serializer = new DefaultByteArraySerializer(); + + /** + * 反序列化器 + */ + private final com.buession.core.deserializer.ByteArrayDeserializer deserializer = new DefaultByteArrayDeserializer(); + + @Override + public String serialize(final V object) { + if(object != null){ + try{ + return serializer.serialize(object); + }catch(SerializerException e){ + if(logger.isErrorEnabled()){ + logger.error("{} serializer error.", object, e); + } + } + } + + return null; + } + + @Override + public byte[] serializeAsBytes(final V object) { + if(object != null){ + try{ + return serializer.serializeAsBytes(object); + }catch(SerializerException e){ + if(logger.isErrorEnabled()){ + logger.error("{} serializer error.", object, e); + } + } + } + + return null; + } + + @Override + public V deserialize(final String str) { + if(str != null){ + try{ + return deserializer.deserialize(str); + }catch(DeserializerException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize error.", str, e); + } + } + } + + return null; } @Override - public V deserialize(final String str, final Class clazz){ - return deserialize(str); + public V deserialize(final String str, final Class clazz) { + if(str != null){ + try{ + return deserializer.deserialize(str); + }catch(DeserializerException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize to: [{}] error.", str, clazz.getName(), e); + } + } + } + + return null; } @Override - public V deserializeBytes(final byte[] bytes, final Class clazz){ - return deserializeBytes(bytes); + public V deserialize(final String str, final TypeReference type) { + if(str != null){ + try{ + return deserializer.deserialize(str); + }catch(DeserializerException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize to: [{}] error.", str, type.getType().getTypeName(), e); + } + } + } + + return null; } @Override - public V deserialize(final String str, final TypeReference type){ - return deserialize(str); + public V deserializeBytes(final byte[] bytes) { + if(bytes != null){ + try{ + return deserializer.deserialize(bytes); + }catch(DeserializerException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize error.", bytes, e); + } + } + } + + return null; } @Override - public V deserializeBytes(final byte[] bytes, final TypeReference type){ - return deserializeBytes(bytes); + public V deserializeBytes(final byte[] bytes, final Class clazz) { + if(bytes != null){ + try{ + return deserializer.deserialize(bytes); + }catch(DeserializerException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize to: [{}] error.", bytes, clazz.getName(), e); + } + } + } + + return null; + } + + @Override + public V deserializeBytes(final byte[] bytes, final TypeReference type) { + if(bytes != null){ + try{ + return deserializer.deserialize(bytes); + }catch(DeserializerException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize to: [{}] error.", bytes, type.getType().getTypeName(), e); + } + } + } + + return null; } } diff --git a/buession-redis/src/main/java/com/buession/redis/serializer/FastJsonJsonSerializer.java b/buession-redis/src/main/java/com/buession/redis/serializer/FastJsonJsonSerializer.java index a9fcaa305..8d08cf0b9 100644 --- a/buession-redis/src/main/java/com/buession/redis/serializer/FastJsonJsonSerializer.java +++ b/buession-redis/src/main/java/com/buession/redis/serializer/FastJsonJsonSerializer.java @@ -21,80 +21,76 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.redis.serializer; -import com.buession.core.deserializer.DeserializerException; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.serializer.SerializeConfig; +import com.alibaba.fastjson.serializer.SerializeFilter; import com.buession.core.type.TypeReference; +import java.nio.charset.Charset; + /** * FastJSON 序列化和反序列化 * * @author Yong.Teng */ -public class FastJsonJsonSerializer extends AbstractSerializer { - - /** - * 构造函数 - */ - public FastJsonJsonSerializer(){ - super(new com.buession.core.serializer.FastJsonJsonSerializer(), - new com.buession.core.deserializer.FastJsonJsonDeserializer()); +public class FastJsonJsonSerializer extends AbstractSerializer { + + @Override + public String serialize(final V object) { + return object == null ? null : JSON.toJSONString(object); } @Override - public V deserialize(final String str, final Class clazz){ - if(str != null){ - try{ - return deserializer.deserialize(str, clazz); - }catch(DeserializerException e){ - logger.error("{} deserialize to {} error.", str, clazz.getName(), e); - } + public byte[] serializeAsBytes(final V object) { + if(object != null){ + return JSON.toJSONBytes(Charset.defaultCharset(), object, SerializeConfig.globalInstance, + new SerializeFilter[0], null, JSON.DEFAULT_GENERATE_FEATURE); } return null; } @Override - public V deserializeBytes(final byte[] bytes, final Class clazz){ - if(bytes != null){ - try{ - return deserializer.deserialize(bytes, clazz); - }catch(DeserializerException e){ - logger.error("{} deserialize to {} error.", bytes, clazz.getName(), e); - } + public V deserialize(final String str) { + if(str != null){ + return JSON.parseObject(str, new com.alibaba.fastjson.TypeReference() { + + }); } return null; } @Override - public V deserialize(final String str, final TypeReference type){ - if(str != null){ - try{ - return deserializer.deserialize(str, type); - }catch(DeserializerException e){ - logger.error("{} deserialize to {} error.", str, type.getType().getTypeName(), e); - } - } + public V deserialize(final String str, final Class clazz) { + return str == null ? null : JSON.parseObject(str, clazz); + } - return null; + @Override + public V deserialize(final String str, final TypeReference type) { + return str == null ? null : JSON.parseObject(str, type.getType()); } @Override - public V deserializeBytes(final byte[] bytes, final TypeReference type){ - if(bytes != null){ - try{ - return deserializer.deserialize(bytes, type); - }catch(DeserializerException e){ - logger.error("{} deserialize to {} error.", bytes, type.getType().getTypeName(), e); - } - } + public V deserializeBytes(final byte[] bytes) { + return bytes == null ? null : JSON.parseObject(new String(bytes), new com.alibaba.fastjson.TypeReference() { - return null; + }); + } + + @Override + public V deserializeBytes(final byte[] bytes, final Class clazz) { + return bytes == null ? null : JSON.parseObject(new String(bytes), clazz); + } + + @Override + public V deserializeBytes(final byte[] bytes, final TypeReference type) { + return bytes == null ? null : JSON.parseObject(new String(bytes), type.getType()); } } diff --git a/buession-redis/src/main/java/com/buession/redis/serializer/GsonJsonSerializer.java b/buession-redis/src/main/java/com/buession/redis/serializer/GsonJsonSerializer.java index 963cc4f3d..6a0d62970 100644 --- a/buession-redis/src/main/java/com/buession/redis/serializer/GsonJsonSerializer.java +++ b/buession-redis/src/main/java/com/buession/redis/serializer/GsonJsonSerializer.java @@ -21,37 +21,47 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.redis.serializer; -import com.buession.core.deserializer.DeserializerException; import com.buession.core.type.TypeReference; +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; + +import java.nio.charset.StandardCharsets; /** * GSON 序列化和反序列化 * * @author Yong.Teng */ -public class GsonJsonSerializer extends AbstractSerializer { - - /** - * 构造函数 - */ - public GsonJsonSerializer(){ - super(new com.buession.core.serializer.GsonJsonSerializer(), - new com.buession.core.deserializer.GsonJsonDeserializer()); +public class GsonJsonSerializer extends AbstractSerializer { + + private final Gson gson = new Gson(); + + @Override + public String serialize(final V object) { + return object == null ? null : gson.toJson(object); } @Override - public V deserialize(final String str, final Class clazz){ + public byte[] serializeAsBytes(final V object) { + return object == null ? null : gson.toJson(object).getBytes(StandardCharsets.UTF_8); + } + + @Override + public V deserialize(final String str) { if(str != null){ try{ - return deserializer.deserialize(str, clazz); - }catch(DeserializerException e){ - logger.error("{} deserialize to {} error.", str, clazz.getName(), e); + return gson.fromJson(str, new TypeReference() { + + }.getType()); + }catch(JsonSyntaxException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize error.", str, e); + } } } @@ -59,12 +69,14 @@ public V deserialize(final String str, final Class clazz){ } @Override - public V deserializeBytes(final byte[] bytes, final Class clazz){ - if(bytes != null){ + public V deserialize(final String str, final Class clazz) { + if(str != null){ try{ - return deserializer.deserialize(bytes, clazz); - }catch(DeserializerException e){ - logger.error("{} deserialize to {} error.", bytes, clazz.getName(), e); + return gson.fromJson(str, clazz); + }catch(JsonSyntaxException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize to: [{}] error.", str, clazz.getName(), e); + } } } @@ -72,12 +84,14 @@ public V deserializeBytes(final byte[] bytes, final Class clazz){ } @Override - public V deserialize(final String str, final TypeReference type){ + public V deserialize(final String str, final TypeReference type) { if(str != null){ try{ - return deserializer.deserialize(str, type); - }catch(DeserializerException e){ - logger.error("{} deserialize to {} error.", str, type.getType().getTypeName(), e); + return gson.fromJson(str, type.getType()); + }catch(JsonSyntaxException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize to: [{}] error.", str, type.getType().getTypeName(), e); + } } } @@ -85,16 +99,18 @@ public V deserialize(final String str, final TypeReference type){ } @Override - public V deserializeBytes(final byte[] bytes, final TypeReference type){ - if(bytes != null){ - try{ - return deserializer.deserialize(bytes, type); - }catch(DeserializerException e){ - logger.error("{} deserialize to {} error.", bytes, type.getType().getTypeName(), e); - } - } + public V deserializeBytes(final byte[] bytes) { + return bytes == null ? null : deserialize(new String(bytes)); + } - return null; + @Override + public V deserializeBytes(final byte[] bytes, final Class clazz) { + return bytes == null ? null : deserialize(new String(bytes), clazz); + } + + @Override + public V deserializeBytes(final byte[] bytes, final TypeReference type) { + return bytes == null ? null : deserialize(new String(bytes), type); } } diff --git a/buession-redis/src/main/java/com/buession/redis/serializer/JacksonJsonSerializer.java b/buession-redis/src/main/java/com/buession/redis/serializer/JacksonJsonSerializer.java index 5d2df38b4..f003b0e72 100644 --- a/buession-redis/src/main/java/com/buession/redis/serializer/JacksonJsonSerializer.java +++ b/buession-redis/src/main/java/com/buession/redis/serializer/JacksonJsonSerializer.java @@ -21,37 +21,68 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.redis.serializer; -import com.buession.core.deserializer.DeserializerException; import com.buession.core.type.TypeReference; +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.IOException; +import java.lang.reflect.Type; /** * Jackson2 序列化和反序列化 * * @author Yong.Teng */ -public class JacksonJsonSerializer extends AbstractSerializer { - - /** - * 构造函数 - */ - public JacksonJsonSerializer(){ - super(new com.buession.core.serializer.JacksonJsonSerializer(), - new com.buession.core.deserializer.JacksonJsonDeserializer()); +public class JacksonJsonSerializer extends AbstractSerializer { + + private final ObjectMapper objectMapper = new ObjectMapper(); + + @Override + public String serialize(final V object) { + if(object != null){ + try{ + return objectMapper.writeValueAsString(object); + }catch(JacksonException e){ + if(logger.isErrorEnabled()){ + logger.error("{} serializer error.", object, e); + } + } + } + + return null; + } + + @Override + public byte[] serializeAsBytes(final V object) { + if(object != null){ + try{ + return objectMapper.writeValueAsBytes(object); + }catch(JacksonException e){ + if(logger.isErrorEnabled()){ + logger.error("{} serializer error.", object, e); + } + } + } + + return null; } @Override - public V deserialize(final String str, final Class clazz){ + public V deserialize(final String str) { if(str != null){ try{ - return deserializer.deserialize(str, clazz); - }catch(DeserializerException e){ - logger.error("{} deserialize to {} error.", str, clazz.getName(), e); + return objectMapper.readValue(str, new com.fasterxml.jackson.core.type.TypeReference() { + + }); + }catch(JacksonException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize error.", str, e); + } } } @@ -59,12 +90,14 @@ public V deserialize(final String str, final Class clazz){ } @Override - public V deserializeBytes(final byte[] bytes, final Class clazz){ - if(bytes != null){ + public V deserialize(final String str, final Class clazz) { + if(str != null){ try{ - return deserializer.deserialize(bytes, clazz); - }catch(DeserializerException e){ - logger.error("{} deserialize to {} error.", bytes, clazz.getName(), e); + return objectMapper.readValue(str, clazz); + }catch(JacksonException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize to: [{}] error.", str, clazz.getName(), e); + } } } @@ -72,12 +105,21 @@ public V deserializeBytes(final byte[] bytes, final Class clazz){ } @Override - public V deserialize(final String str, final TypeReference type){ + public V deserialize(final String str, final TypeReference type) { if(str != null){ try{ - return deserializer.deserialize(str, type); - }catch(DeserializerException e){ - logger.error("{} deserialize to {} error.", str, type.getType().getTypeName(), e); + return objectMapper.readValue(str, new com.fasterxml.jackson.core.type.TypeReference() { + + @Override + public Type getType() { + return type.getType(); + } + + }); + }catch(JacksonException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize to: [{}] error.", str, type.getType().getTypeName(), e); + } } } @@ -85,12 +127,65 @@ public V deserialize(final String str, final TypeReference type){ } @Override - public V deserializeBytes(final byte[] bytes, final TypeReference type){ + public V deserializeBytes(final byte[] bytes) { if(bytes != null){ try{ - return deserializer.deserialize(bytes, type); - }catch(DeserializerException e){ - logger.error("{} deserialize to {} error.", bytes, type.getType().getTypeName(), e); + return objectMapper.readValue(bytes, new com.fasterxml.jackson.core.type.TypeReference() { + + }); + }catch(JacksonException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize error.", bytes, e); + } + }catch(IOException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize error.", bytes, e); + } + } + } + + return null; + } + + @Override + public V deserializeBytes(final byte[] bytes, final Class clazz) { + if(bytes != null){ + try{ + return objectMapper.readValue(bytes, clazz); + }catch(JacksonException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize to: [{}] error.", bytes, clazz.getName(), e); + } + }catch(IOException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize to: [{}] error.", bytes, clazz.getName(), e); + } + } + } + + return null; + } + + @Override + public V deserializeBytes(final byte[] bytes, final TypeReference type) { + if(bytes != null){ + try{ + return objectMapper.readValue(bytes, new com.fasterxml.jackson.core.type.TypeReference() { + + @Override + public Type getType() { + return type.getType(); + } + + }); + }catch(JacksonException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize to: [{}] error.", bytes, type.getType().getTypeName(), e); + } + }catch(IOException e){ + if(logger.isErrorEnabled()){ + logger.error("{} deserialize to: [{}] error.", bytes, type.getType().getTypeName(), e); + } } } diff --git a/buession-redis/src/main/java/com/buession/redis/serializer/Serializer.java b/buession-redis/src/main/java/com/buession/redis/serializer/Serializer.java index 6d2bc937c..dd2c80190 100644 --- a/buession-redis/src/main/java/com/buession/redis/serializer/Serializer.java +++ b/buession-redis/src/main/java/com/buession/redis/serializer/Serializer.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.redis.serializer; @@ -96,58 +96,58 @@ public interface Serializer { V deserialize(final String str); /** - * 将字节反序列化为对象 + * 将字符串反序列化为 clazz 指定的对象 * - * @param bytes - * 待反序列化的字节 + * @param str + * 待反序列化的字符串 + * @param clazz + * 对象类 * @param * 对象类型 * * @return 反序列化后的对象 */ - V deserializeBytes(final byte[] bytes); + V deserialize(final String str, final Class clazz); /** - * 将字符串反序列化为 clazz 指定的对象 + * 将字符串反序列化为 type 指定的对象 * * @param str * 待反序列化的字符串 - * @param clazz - * 对象类 + * @param type + * 对象引用 * @param * 对象类型 * * @return 反序列化后的对象 */ - V deserialize(final String str, final Class clazz); + V deserialize(final String str, final TypeReference type); /** - * 将字节反序列化为 clazz 指定的对象 + * 将字节反序列化为对象 * * @param bytes * 待反序列化的字节 - * @param clazz - * 对象类 * @param * 对象类型 * * @return 反序列化后的对象 */ - V deserializeBytes(final byte[] bytes, final Class clazz); + V deserializeBytes(final byte[] bytes); /** - * 将字符串反序列化为 type 指定的对象 + * 将字节反序列化为 clazz 指定的对象 * - * @param str - * 待反序列化的字符串 - * @param type - * 对象引用 + * @param bytes + * 待反序列化的字节 + * @param clazz + * 对象类 * @param * 对象类型 * * @return 反序列化后的对象 */ - V deserialize(final String str, final TypeReference type); + V deserializeBytes(final byte[] bytes, final Class clazz); /** * 将字符串反序列化为 type 指定的对象 diff --git a/buession-redis/src/main/java/com/buession/redis/transaction/AbstractTransactionProxy.java b/buession-redis/src/main/java/com/buession/redis/transaction/AbstractTransactionProxy.java new file mode 100644 index 000000000..09823b9af --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/transaction/AbstractTransactionProxy.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.transaction; + +import com.buession.redis.core.FutureResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import java.util.stream.Collectors; + +/** + * 事务代理抽象类 + * + * @param + * 原生事务类型 + * @param + * 事务异步结果 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractTransactionProxy> implements TransactionProxy { + + private Transaction target; + + private final T object; + + private final Queue txResults = new LinkedList<>(); + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + public AbstractTransactionProxy(final Transaction target, final T object) { + //Assert.isNull(target, "Redis Transaction cloud not be null."); + this.target = target; + this.object = object; + } + + @Override + public T getObject() { + return object; + } + + @Override + public Queue getTxResults() { + return txResults; + } + + @Override + public List exec() { + logger.info("Redis transaction exec."); + target.exec(); + return txResults.stream().map((r)->r.convert(r.get())).collect(Collectors.toList()); + } + + @Override + public String discard() { + logger.info("Redis transaction discard."); + return target.discard(); + } + + @Override + public void close() { + logger.info("Redis pipeline close."); + txResults.clear(); + target.close(); + } + + protected void setTarget(Transaction target) { + this.target = target; + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/transaction/TransactionProxy.java b/buession-redis/src/main/java/com/buession/redis/transaction/TransactionProxy.java new file mode 100644 index 000000000..57c566ba2 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/transaction/TransactionProxy.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.transaction; + +import com.buession.redis.core.FutureResult; + +import java.util.Queue; + +/** + * 事务代理 + * + * @param + * 事务管道类型 + * @param + * 事务异步结果 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface TransactionProxy> extends Transaction { + + /** + * 返回原生事务实例 + * + * @return 原生事务实例 + */ + T getObject(); + + Queue getTxResults(); + +} diff --git a/buession-redis/src/main/java/com/buession/redis/transaction/jedis/JedisTransaction.java b/buession-redis/src/main/java/com/buession/redis/transaction/jedis/JedisTransaction.java index de9f3a76c..8ffbb88fd 100644 --- a/buession-redis/src/main/java/com/buession/redis/transaction/jedis/JedisTransaction.java +++ b/buession-redis/src/main/java/com/buession/redis/transaction/jedis/JedisTransaction.java @@ -19,15 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.transaction.jedis; import com.buession.core.utils.Assert; import com.buession.redis.transaction.Transaction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.List; @@ -40,32 +38,23 @@ public class JedisTransaction implements Transaction { private final redis.clients.jedis.Transaction delegate; - private final static Logger logger = LoggerFactory.getLogger(JedisTransaction.class); - public JedisTransaction(redis.clients.jedis.Transaction transaction) { Assert.isNull(transaction, "Redis Transaction cloud not be null."); this.delegate = transaction; } - public redis.clients.jedis.Transaction primitive() { - return delegate; - } - @Override public List exec() { - logger.info("Redis transaction exec."); return delegate.exec(); } @Override public String discard() { - logger.info("Redis transaction discard."); return delegate.discard(); } @Override public void close() { - logger.info("Redis transaction close."); delegate.close(); } diff --git a/buession-redis/src/main/java/com/buession/redis/transaction/jedis/JedisTransactionProxy.java b/buession-redis/src/main/java/com/buession/redis/transaction/jedis/JedisTransactionProxy.java new file mode 100644 index 000000000..adc34b1d8 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/transaction/jedis/JedisTransactionProxy.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.transaction.jedis; + +import com.buession.redis.core.internal.jedis.JedisResult; +import com.buession.redis.transaction.AbstractTransactionProxy; +import com.buession.redis.transaction.Transaction; + +/** + * Jedis 事务代理类 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class JedisTransactionProxy + extends AbstractTransactionProxy> { + + public JedisTransactionProxy(final Transaction target, final redis.clients.jedis.Transaction object) { + super(target, object); + } + +} diff --git a/buession-httpclient/src/main/java/com/buession/httpclient/core/Request.java b/buession-redis/src/main/java/com/buession/redis/transaction/lettuce/LettuceTransaction.java similarity index 58% rename from buession-httpclient/src/main/java/com/buession/httpclient/core/Request.java rename to buession-redis/src/main/java/com/buession/redis/transaction/lettuce/LettuceTransaction.java index 20cc2e2b9..6549b2e68 100644 --- a/buession-httpclient/src/main/java/com/buession/httpclient/core/Request.java +++ b/buession-redis/src/main/java/com/buession/redis/transaction/lettuce/LettuceTransaction.java @@ -19,77 +19,53 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ -package com.buession.httpclient.core; +package com.buession.redis.transaction.lettuce; + +import com.buession.core.utils.Assert; +import com.buession.redis.transaction.Transaction; +import io.lettuce.core.api.sync.RedisCommands; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import java.net.URI; import java.util.List; +import java.util.stream.Collectors; /** + * Lettuce 事务 + * * @author Yong.Teng + * @since 3.0.0 */ -public class Request { - - private RequestMethod method; - - @Deprecated - private String url; - - private URI uri; - - private List
headers; +public class LettuceTransaction implements Transaction { - private RequestBody requestBody; + private final RedisCommands delegate; - public RequestMethod getMethod(){ - return method; - } - - public void setMethod(RequestMethod method){ - this.method = method; - } - - public String getUrl(){ - return url; - } + private final static Logger logger = LoggerFactory.getLogger(LettuceTransaction.class); - @Deprecated - public void setUrl(String url){ - this.url = url; - this.uri = URI.create(url); + public LettuceTransaction(RedisCommands transaction) { + Assert.isNull(transaction, "Redis Transaction cloud not be null."); + this.delegate = transaction; } - public URI getUri(){ - return uri; - } - - public void setUri(URI uri){ - this.uri = uri; - this.url = uri.toString(); - } - - public List
getHeaders(){ - return headers; - } - - public void setHeaders(List
headers){ - this.headers = headers; - } - - public RequestBody getRequestBody(){ - return requestBody; + @Override + public List exec() { + logger.info("Redis transaction exec."); + return delegate.exec().stream().collect(Collectors.toList()); } - public void setRequestBody(RequestBody requestBody){ - this.requestBody = requestBody; + @Override + public String discard() { + logger.info("Redis transaction discard."); + return delegate.discard(); } @Override - public String toString(){ - return "Request{" + "method=" + method + ", url='" + uri + '\'' + ", headers=" + headers + ", requestBody=" + - requestBody + '}'; + public void close() { + logger.info("Redis transaction close."); + //delegate.close(); } -} +} \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/transaction/lettuce/LettuceTransactionProxy.java b/buession-redis/src/main/java/com/buession/redis/transaction/lettuce/LettuceTransactionProxy.java new file mode 100644 index 000000000..48d0ae587 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/transaction/lettuce/LettuceTransactionProxy.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.transaction.lettuce; + +import com.buession.redis.core.internal.lettuce.LettuceResult; +import com.buession.redis.transaction.AbstractTransactionProxy; +import com.buession.redis.transaction.Transaction; +import io.lettuce.core.api.sync.RedisCommands; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceTransactionProxy + extends AbstractTransactionProxy, LettuceResult> { + + public LettuceTransactionProxy(final Transaction target, final RedisCommands object) { + super(target, object); + } + +} diff --git a/buession-redis/src/main/java/com/buession/redis/transaction/lettuce/package-info.java b/buession-redis/src/main/java/com/buession/redis/transaction/lettuce/package-info.java new file mode 100644 index 000000000..f922efaf0 --- /dev/null +++ b/buession-redis/src/main/java/com/buession/redis/transaction/lettuce/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package com.buession.redis.transaction.lettuce; \ No newline at end of file diff --git a/buession-redis/src/main/java/com/buession/redis/utils/ObjectStringBuilder.java b/buession-redis/src/main/java/com/buession/redis/utils/ObjectStringBuilder.java index 221eddc55..d9ce9c714 100644 --- a/buession-redis/src/main/java/com/buession/redis/utils/ObjectStringBuilder.java +++ b/buession-redis/src/main/java/com/buession/redis/utils/ObjectStringBuilder.java @@ -19,12 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.utils; -import java.util.StringJoiner; +import com.buession.core.utils.StringJoiner; /** * @author Yong.Teng @@ -34,44 +34,44 @@ public final class ObjectStringBuilder { private final StringJoiner joiner = new StringJoiner(", ", "{", "}"); - private ObjectStringBuilder(){ + private ObjectStringBuilder() { } - public static ObjectStringBuilder create(){ + public static ObjectStringBuilder create() { return new ObjectStringBuilder(); } - public ObjectStringBuilder add(final String name, final boolean value){ + public ObjectStringBuilder add(final String name, final boolean value) { joiner.add(name + '=' + value); return this; } - public ObjectStringBuilder add(final String name, final short value){ + public ObjectStringBuilder add(final String name, final short value) { joiner.add(name + '=' + value); return this; } - public ObjectStringBuilder add(final String name, final int value){ + public ObjectStringBuilder add(final String name, final int value) { joiner.add(name + '=' + value); return this; } - public ObjectStringBuilder add(final String name, final long value){ + public ObjectStringBuilder add(final String name, final long value) { joiner.add(name + '=' + value); return this; } - public ObjectStringBuilder add(final String name, final float value){ + public ObjectStringBuilder add(final String name, final float value) { joiner.add(name + '=' + value); return this; } - public ObjectStringBuilder add(final String name, final double value){ + public ObjectStringBuilder add(final String name, final double value) { joiner.add(name + '=' + value); return this; } - public ObjectStringBuilder add(final String name, final byte[] value){ + public ObjectStringBuilder add(final String name, final byte[] value) { if(value != null){ joiner.add(name + '=' + SafeEncoder.encode(value)); } @@ -79,15 +79,12 @@ public ObjectStringBuilder add(final String name, final byte[] value){ return this; } - public ObjectStringBuilder add(final String name, final String value){ - if(value != null){ - joiner.add(name + '=' + value); - } - + public ObjectStringBuilder add(final String name, final Object value) { + joiner.add(name + '=' + value); return this; } - public ObjectStringBuilder add(final String name, final Object value){ + public ObjectStringBuilder addIfAbsent(final String name, final Object value) { if(value != null){ joiner.add(name + '=' + value); } @@ -95,7 +92,7 @@ public ObjectStringBuilder add(final String name, final Object value){ return this; } - public ObjectStringBuilder append(final CharSequence seq){ + public ObjectStringBuilder append(final CharSequence seq) { if(seq != null){ joiner.add(seq); } @@ -103,7 +100,7 @@ public ObjectStringBuilder append(final CharSequence seq){ return this; } - public String build(){ + public String build() { return joiner.toString(); } diff --git a/buession-redis/src/main/java/com/buession/redis/utils/SafeEncoder.java b/buession-redis/src/main/java/com/buession/redis/utils/SafeEncoder.java index c7a227b98..0f4321d5a 100644 --- a/buession-redis/src/main/java/com/buession/redis/utils/SafeEncoder.java +++ b/buession-redis/src/main/java/com/buession/redis/utils/SafeEncoder.java @@ -19,14 +19,11 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.redis.utils; -import com.buession.core.collect.Arrays; -import com.buession.core.utils.Assert; - import java.nio.charset.StandardCharsets; /** @@ -34,25 +31,44 @@ */ public class SafeEncoder { - private SafeEncoder(){ + private SafeEncoder() { } - public static byte[] encode(final String str){ - Assert.isNull(str, "Value cloud not be null."); - return str.getBytes(StandardCharsets.UTF_8); + public static byte[] encode(final String str) { + return str == null ? null : str.getBytes(StandardCharsets.UTF_8); } - public static byte[][] encode(final String... strs){ - return Arrays.map(strs, byte[].class, (v)->v.getBytes(StandardCharsets.UTF_8)); + public static byte[][] encode(final String... strs) { + if(strs == null){ + return null; + }else{ + final byte[][] result = new byte[strs.length][]; + + for(int i = 0; i < strs.length; i++){ + result[i] = strs[i] == null ? null : strs[i].getBytes(StandardCharsets.UTF_8); + } + + return result; + } } - public static String encode(final byte[] data){ - return new String(data, StandardCharsets.UTF_8); + public static String encode(final byte[] data) { + return data == null ? null : new String(data, StandardCharsets.UTF_8); } - public static String[] encode(final byte[]... data){ - return Arrays.map(data, String.class, (v)->new String(v, StandardCharsets.UTF_8)); + public static String[] encode(final byte[]... data) { + if(data == null){ + return null; + }else{ + final String[] result = new String[data.length]; + + for(int i = 0; i < data.length; i++){ + result[i] = data[i] == null ? null : new String(data[i], StandardCharsets.UTF_8); + } + + return result; + } } } diff --git a/buession-redis/src/main/java/io/lettuce/core/AbstractLettuceFactory.java b/buession-redis/src/main/java/io/lettuce/core/AbstractLettuceFactory.java new file mode 100644 index 000000000..ea585f0c7 --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/AbstractLettuceFactory.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core; + +import io.lettuce.core.api.StatefulConnection; +import org.apache.commons.pool2.BasePooledObjectFactory; +import org.apache.commons.pool2.PooledObject; +import org.apache.commons.pool2.impl.DefaultPooledObject; + +/** + * Lettuce 连接池对象工厂抽象类 + * + * @param + * 原生连接类型 + * @param + * {@link AbstractRedisClient} + * + * @author Yong.Teng + * @since 3.0.0 + */ +public abstract class AbstractLettuceFactory, + C extends AbstractRedisClient> extends BasePooledObjectFactory { + + private final C client; + + protected AbstractLettuceFactory(final C client) { + this.client = client; + } + + @Override + public PooledObject wrap(CONN connection) { + return new DefaultPooledObject<>(connection); + } + + @Override + public void activateObject(PooledObject pooledObject) throws Exception { + CONN connection = pooledObject.getObject(); + //connection.sync().select(database); + } + + @Override + public void destroyObject(PooledObject pooledObject) throws Exception { + CONN connection = pooledObject.getObject(); + + if(connection.isOpen()){ + connection.close(); + } + } + + protected C getClient() { + return client; + } + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/BufferedFlushing.java b/buession-redis/src/main/java/io/lettuce/core/BufferedFlushing.java new file mode 100644 index 000000000..705addebe --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/BufferedFlushing.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core; + +import io.lettuce.core.api.PipeliningFlushState; +import io.lettuce.core.api.StatefulConnection; + +import java.util.concurrent.atomic.AtomicLong; + +/** + * Pipeline state for buffered flushing. + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class BufferedFlushing implements PipeliningFlushState { + + private final AtomicLong commands = new AtomicLong(); + + private final int flushAfter; + + public BufferedFlushing(final int flushAfter) { + this.flushAfter = flushAfter; + } + + @Override + public void onOpen(StatefulConnection connection) { + connection.setAutoFlushCommands(false); + } + + @Override + public void onCommand(StatefulConnection connection) { + if(commands.incrementAndGet() % flushAfter == 0){ + connection.flushCommands(); + } + } + + @Override + public void onClose(StatefulConnection connection) { + connection.flushCommands(); + connection.setAutoFlushCommands(true); + } + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/DefaultLettuceClientConfig.java b/buession-redis/src/main/java/io/lettuce/core/DefaultLettuceClientConfig.java new file mode 100644 index 000000000..9b07e7d00 --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/DefaultLettuceClientConfig.java @@ -0,0 +1,245 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core; + +import com.buession.redis.core.RedisNode; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLParameters; +import javax.net.ssl.SSLSocketFactory; +import java.time.Duration; + +/** + * 默认客户端配置 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class DefaultLettuceClientConfig implements LettuceClientConfig { + + private Duration connectionTimeout = Duration.ofMillis(RedisURI.DEFAULT_TIMEOUT); + + private Duration socketTimeout = connectionTimeout; + + private String user; + + private String password; + + private int database = RedisNode.DEFAULT_DATABASE; + + private String clientName; + + private boolean isSsl; + + private SSLSocketFactory sslSocketFactory; + + private SSLParameters sslParameters; + + private HostnameVerifier hostnameVerifier; + + private DefaultLettuceClientConfig() { + + } + + private DefaultLettuceClientConfig(final Duration connectionTimeout, final Duration socketTimeout, + final String user, final String password, final int database, + final String clientName, final boolean isSsl, + final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters, + final HostnameVerifier hostnameVerifier) { + this.connectionTimeout = connectionTimeout; + this.socketTimeout = socketTimeout; + this.user = user; + this.password = password; + this.database = database; + this.clientName = clientName; + this.isSsl = isSsl; + this.sslSocketFactory = sslSocketFactory; + this.sslParameters = sslParameters; + this.hostnameVerifier = hostnameVerifier; + } + + @Override + public Duration getConnectionTimeout() { + return connectionTimeout; + } + + @Override + public Duration getSocketTimeout() { + return socketTimeout; + } + + @Override + public String getUser() { + return user; + } + + @Override + public String getPassword() { + return password; + } + + @Override + public int getDatabase() { + return database; + } + + @Override + public String getClientName() { + return clientName; + } + + @Override + public boolean isSsl() { + return isSsl; + } + + @Override + public SSLSocketFactory getSslSocketFactory() { + return sslSocketFactory; + } + + @Override + public SSLParameters getSslParameters() { + return sslParameters; + } + + @Override + public HostnameVerifier getHostnameVerifier() { + return hostnameVerifier; + } + + public static Builder builder() { + return new Builder(); + } + + public final static class Builder { + + private final DefaultLettuceClientConfig lettuceClientConfig = new DefaultLettuceClientConfig(); + + private Builder() { + } + + public Builder timeout(final Duration timeout) { + lettuceClientConfig.connectionTimeout = timeout; + lettuceClientConfig.socketTimeout = timeout; + return this; + } + + public Builder timeoutMillis(final long timeoutMillis) { + return timeout(Duration.ofMillis(timeoutMillis)); + } + + public Builder connectionTimeout(final Duration timeout) { + lettuceClientConfig.connectionTimeout = timeout; + return this; + } + + public Builder connectionTimeoutMillis(final long timeoutMillis) { + return connectionTimeout(Duration.ofMillis(timeoutMillis)); + } + + public Builder socketTimeout(final Duration timeout) { + lettuceClientConfig.socketTimeout = timeout; + return this; + } + + public Builder socketTimeoutMillis(final long timeoutMillis) { + return connectionTimeout(Duration.ofMillis(timeoutMillis)); + } + + public Builder user(final String user) { + lettuceClientConfig.user = user; + return this; + } + + public Builder password(final String password) { + lettuceClientConfig.password = password; + return this; + } + + public Builder credentials(final String user, final String password) { + lettuceClientConfig.user = user; + lettuceClientConfig.password = password; + return this; + } + + public Builder database(final int database) { + lettuceClientConfig.database = database; + return this; + } + + public Builder clientName(final String clientName) { + lettuceClientConfig.clientName = clientName; + return this; + } + + public Builder ssl(boolean isSsl) { + lettuceClientConfig.isSsl = isSsl; + return this; + } + + public Builder sslSocketFactory(SSLSocketFactory sslSocketFactory) { + lettuceClientConfig.sslSocketFactory = sslSocketFactory; + return this; + } + + public Builder sslParameters(SSLParameters sslParameters) { + lettuceClientConfig.sslParameters = sslParameters; + return this; + } + + public Builder hostnameVerifier(HostnameVerifier hostnameVerifier) { + lettuceClientConfig.hostnameVerifier = hostnameVerifier; + return this; + } + + public DefaultLettuceClientConfig build() { + return lettuceClientConfig; + } + + public static LettuceClientConfig create(final int connectionTimeoutMillis, final int soTimeoutMillis, + final String user, final String password, final int database, + final String clientName, final boolean isSsl, + final SSLSocketFactory sslSocketFactory, + final SSLParameters sslParameters, + final HostnameVerifier hostnameVerifier) { + return new DefaultLettuceClientConfig(Duration.ofMillis(connectionTimeoutMillis), + Duration.ofMillis(soTimeoutMillis), user, password, database, clientName, isSsl, sslSocketFactory + , sslParameters, hostnameVerifier); + } + + public static LettuceClientConfig create(final Duration connectionTimeout, final Duration soTimeoutMillis, + final String user, final String password, final int database, + final String clientName, final boolean isSsl, + final SSLSocketFactory sslSocketFactory, + final SSLParameters sslParameters, + final HostnameVerifier hostnameVerifier) { + return new DefaultLettuceClientConfig(connectionTimeout, soTimeoutMillis, user, password, database, + clientName, isSsl, sslSocketFactory, sslParameters, hostnameVerifier); + } + + } + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/FlushEachCommand.java b/buession-redis/src/main/java/io/lettuce/core/FlushEachCommand.java new file mode 100644 index 000000000..68f49a272 --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/FlushEachCommand.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core; + +import io.lettuce.core.api.PipeliningFlushPolicy; +import io.lettuce.core.api.PipeliningFlushState; +import io.lettuce.core.api.StatefulConnection; + +/** + * Implementation to flush on each command. + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class FlushEachCommand implements PipeliningFlushPolicy, PipeliningFlushState { + + @Override + public PipeliningFlushState newPipeline() { + return this; + } + + @Override + public void onOpen(StatefulConnection connection) { + } + + @Override + public void onCommand(StatefulConnection connection) { + } + + @Override + public void onClose(StatefulConnection connection) { + } + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/FlushOnClose.java b/buession-redis/src/main/java/io/lettuce/core/FlushOnClose.java new file mode 100644 index 000000000..950578c71 --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/FlushOnClose.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core; + +import io.lettuce.core.api.PipeliningFlushPolicy; +import io.lettuce.core.api.PipeliningFlushState; +import io.lettuce.core.api.StatefulConnection; + +/** + * Implementation to flush on closing the pipeline. + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class FlushOnClose implements PipeliningFlushPolicy, PipeliningFlushState { + + @Override + public PipeliningFlushState newPipeline() { + return this; + } + + @Override + public void onOpen(StatefulConnection connection) { + connection.setAutoFlushCommands(false); + } + + @Override + public void onCommand(StatefulConnection connection) { + + } + + @Override + public void onClose(StatefulConnection connection) { + connection.flushCommands(); + connection.setAutoFlushCommands(true); + } + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/LettuceClientConfig.java b/buession-redis/src/main/java/io/lettuce/core/LettuceClientConfig.java new file mode 100644 index 000000000..22133fe1c --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/LettuceClientConfig.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core; + +import com.buession.redis.core.RedisNode; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLParameters; +import javax.net.ssl.SSLSocketFactory; +import java.time.Duration; + +/** + * 客户端配置 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface LettuceClientConfig { + + /** + * 返回连接超时 + * + * @return 连接超时 + */ + default Duration getConnectionTimeout() { + return RedisURI.DEFAULT_TIMEOUT_DURATION; + } + + /** + * 返回读取超时 + * + * @return 读取超时 + */ + default Duration getSocketTimeout() { + return RedisURI.DEFAULT_TIMEOUT_DURATION; + } + + /** + * 返回用户名 + * + * @return 用户名 + */ + default String getUser() { + return null; + } + + /** + * 返回密码 + * + * @return 密码 + */ + default String getPassword() { + return null; + } + + /** + * 返回数据库 + * + * @return 数据库 + */ + default int getDatabase() { + return RedisNode.DEFAULT_DATABASE; + } + + /** + * 返回客户端名称 + * + * @return 客户端名称 + */ + default String getClientName() { + return null; + } + + /** + * 返回是否为 TLS 连接 + * + * @return true - to create a TLS connection. false - otherwise. + */ + default boolean isSsl() { + return false; + } + + /** + * 返回 {@link SSLSocketFactory} + * + * @return {@link SSLSocketFactory} + */ + default SSLSocketFactory getSslSocketFactory() { + return null; + } + + /** + * 返回 {@link SSLParameters} + * + * @return {@link SSLParameters} + */ + default SSLParameters getSslParameters() { + return null; + } + + /** + * 返回 {@link HostnameVerifier} + * + * @return {@link HostnameVerifier} + */ + default HostnameVerifier getHostnameVerifier() { + return null; + } + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/LettuceClusterFactory.java b/buession-redis/src/main/java/io/lettuce/core/LettuceClusterFactory.java new file mode 100644 index 000000000..5eb97d2bb --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/LettuceClusterFactory.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core; + +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.validator.Validate; +import com.buession.net.HostAndPort; +import io.lettuce.core.cluster.RedisClusterClient; +import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; +import io.lettuce.core.codec.ByteArrayCodec; + +import java.util.Set; + +/** + * Lettuce 集群连接对象工厂 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceClusterFactory + extends AbstractLettuceFactory, RedisClusterClient> { + + /** + * 构造函数 + * + * @param nodes + * Redis 集群节点 + */ + public LettuceClusterFactory(final Set nodes) { + this(buildRedisURI(nodes, DefaultLettuceClientConfig.builder().build())); + } + + /** + * 构造函数 + * + * @param nodes + * Redis 集群节点 + * @param lettuceClientConfig + * 客户端配置 + */ + public LettuceClusterFactory(final Set nodes, final LettuceClientConfig lettuceClientConfig) { + this(buildRedisURI(nodes, lettuceClientConfig)); + } + + protected LettuceClusterFactory(final RedisURI uri) { + super(RedisClusterClient.create(uri)); + } + + @Override + public StatefulRedisClusterConnection create() throws Exception { + return getClient().connect(new ByteArrayCodec()); + } + + private static RedisURI buildRedisURI(final Set nodes, final LettuceClientConfig lettuceClientConfig) { + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); + final RedisURI.Builder builder = RedisURI.builder().withDatabase(lettuceClientConfig.getDatabase()) + .withSsl(lettuceClientConfig.isSsl()); + + propertyMapper.alwaysApplyingWhenNonNull().from(lettuceClientConfig.getConnectionTimeout()) + .to(builder::withTimeout); + propertyMapper.from(lettuceClientConfig.getClientName()).to(builder::withClientName); + nodes.forEach((node)->{ + builder.withHost(node.getHost()).withPort(node.getPort()); + if(Validate.hasText(lettuceClientConfig.getPassword())){ + if(Validate.hasText(lettuceClientConfig.getUser())){ + builder.withAuthentication(lettuceClientConfig.getUser(), lettuceClientConfig.getPassword()); + }else{ + builder.withPassword(lettuceClientConfig.getPassword().toCharArray()); + } + } + }); + + return builder.build(); + } + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/LettuceClusterPool.java b/buession-redis/src/main/java/io/lettuce/core/LettuceClusterPool.java new file mode 100644 index 000000000..1469ce764 --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/LettuceClusterPool.java @@ -0,0 +1,300 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core; + +import com.buession.net.HostAndPort; +import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; +import org.apache.commons.pool2.PooledObjectFactory; +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.Set; + +/** + * Lettuce 集群连接池 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceClusterPool extends Pool> { + + private volatile HostAndPort currentMaster; + + private final Object initPoolLock = new Object(); + + private final static Logger logger = LoggerFactory.getLogger(LettuceClusterPool.class); + + /** + * 构造函数 + * + * @param nodes + * 集群节点 + */ + public LettuceClusterPool(final Set nodes) { + this(nodes, DefaultLettuceClientConfig.builder().build()); + } + + /** + * 构造函数 + * + * @param nodes + * 集群节点 + * @param lettuceClientConfig + * 客户端配置 + */ + public LettuceClusterPool(final Set nodes, final LettuceClientConfig lettuceClientConfig) { + super(new LettuceClusterFactory(nodes, lettuceClientConfig)); + } + + /** + * 构造函数 + * + * @param poolConfig + * 线程池配置 + * @param nodes + * 集群节点 + */ + public LettuceClusterPool(final GenericObjectPoolConfig> poolConfig, + final Set nodes) { + this(nodes, poolConfig, DefaultLettuceClientConfig.builder().build()); + } + + /** + * 构造函数 + * + * @param nodes + * 集群节点 + * @param poolConfig + * 哨兵节点 + * @param lettuceClientConfig + * 客户端配置 + */ + public LettuceClusterPool(final Set nodes, + final GenericObjectPoolConfig> poolConfig, + final LettuceClientConfig lettuceClientConfig) { + this(nodes, poolConfig, new LettuceClusterFactory(nodes, lettuceClientConfig)); + } + + /** + * 构造函数 + * + * @param nodes + * 集群节点 + * @param poolConfig + * 线程池配置 + * @param factory + * 连接线对象工厂 + */ + protected LettuceClusterPool(final Set nodes, + final GenericObjectPoolConfig> poolConfig, + final PooledObjectFactory> factory) { + super(factory, poolConfig); + + //HostAndPort master = initSentinels(nodes); + //initMaster(master); + } + + @Override + public StatefulRedisClusterConnection getResource() { + StatefulRedisClusterConnection connection = super.getResource(); + //jedis.setDataSource(this); + return connection; + } + + @Override + public void returnResource(final StatefulRedisClusterConnection resource) { + if(resource != null){ + try{ + super.returnResource(resource); + }catch(RuntimeException e){ + super.returnBrokenResource(resource); + logger.warn("Resource is returned to the pool as broken", e); + } + } + } + + @Override + public void destroy() { + //for(MasterListener m : masterListeners){ + //m.shutdown(); + //} + + super.destroy(); + } + + private void initMaster(final HostAndPort master) { + synchronized(initPoolLock){ + if(master.equals(currentMaster) == false){ + currentMaster = master; + //factory.setHostAndPort(currentHostMaster); although we clear the pool, we still have to check the + // returned object in getResource, this call only clears idle instances, not borrowed instances + super.clear(); + + logger.info("Created LettuceSentinelPool to master at {}", master); + } + } + } + + private HostAndPort initSentinels(final String masterName, final Set sentinels) { + return null; + } + + private static HostAndPort toHostAndPort(final List getMasterAddrByNameResult) { + String host = getMasterAddrByNameResult.get(0); + int port = Integer.parseInt(getMasterAddrByNameResult.get(1)); + + return new HostAndPort(host, port); + } + + /* + protected final class MasterListener extends Thread { + + private String masterName; + + private String host; + + private int port; + + private long subscribeRetryWaitTimeMillis = 5000; + + private volatile Jedis j; + + private final AtomicBoolean running = new AtomicBoolean(false); + + private final Logger logger = LoggerFactory.getLogger(MasterListener.class); + + private MasterListener() { + super(); + } + + public MasterListener(String masterName, String host, int port) { + super(String.format("MasterListener-%s-[%s:%d]", masterName, host, port)); + this.masterName = masterName; + this.host = host; + this.port = port; + } + + public MasterListener(String masterName, String host, int port, long subscribeRetryWaitTimeMillis) { + this(masterName, host, port); + this.subscribeRetryWaitTimeMillis = subscribeRetryWaitTimeMillis; + } + + @Override + public void run() { + running.set(true); + + while(running.get()){ + try{ + // double check that it is not being shutdown + if(running.get() == false){ + break; + } + + final HostAndPort hostPort = new HostAndPort(host, port); + StatefulRedisSentinelConnection connection = + RedisClient.create(RedisURI.create(host, port)).connect(new ByteArrayCodec()); + RedisCommands commands = connection.sync(); + j = new Jedis(hostPort, sentinelClientConfig); + + // code for active refresh + List masterAddr = j.sentinelGetMasterAddrByName(masterName); + if(masterAddr == null || masterAddr.size() != 2){ + logger.warn("Can not get master addr, master name: {}. Sentinel: {}.", masterName, + hostPort); + }else{ + initMaster(toHostAndPort(masterAddr)); + } + + j.subscribe(new JedisPubSub() { + + @Override + public void onMessage(String channel, String message) { + logger.debug("Sentinel {} published: {}.", hostPort, message); + + String[] switchMasterMsg = message.split(" "); + + if(switchMasterMsg.length > 3){ + + if(masterName.equals(switchMasterMsg[0])){ + initMaster(toHostAndPort(Arrays.asList(switchMasterMsg[3], switchMasterMsg[4]))); + }else{ + if(logger.isDebugEnabled()){ + logger.debug( + "Ignoring message on +switch-master for master name {}, our master name is {}", + switchMasterMsg[0], masterName); + } + } + + }else{ + logger.error("Invalid message received on Sentinel {} on channel +switch-master: {}", + hostPort, message); + } + } + }, "+switch-master"); + + }catch(JedisException e){ + if(running.get()){ + logger.error("Lost connection to Sentinel at {}:{}. Sleeping 5000ms and retrying.", host, + port, e); + try{ + Thread.sleep(subscribeRetryWaitTimeMillis); + }catch(InterruptedException e1){ + logger.error("Sleep interrupted: ", e1); + } + }else{ + if(logger.isDebugEnabled()){ + logger.debug("Unsubscribing from Sentinel at {}:{}", host, port); + } + } + }finally{ + if(j != null){ + j.close(); + } + } + } + } + + public void shutdown() { + try{ + if(logger.isDebugEnabled()){ + logger.debug("Shutting down listener on {}:{}", host, port); + } + running.set(false); + // This isn't good, the Jedis object is not thread safe + if(j != null){ + j.close(); + } + }catch(RuntimeException e){ + logger.error("Caught exception while shutting down: ", e); + } + } + + } + + */ + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/LettuceFactory.java b/buession-redis/src/main/java/io/lettuce/core/LettuceFactory.java new file mode 100644 index 000000000..a60cdada8 --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/LettuceFactory.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core; + +import com.buession.core.validator.Validate; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.codec.ByteArrayCodec; + +import java.util.Optional; + +/** + * Lettuce 单机连接池对象工厂 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceFactory extends AbstractLettuceFactory, RedisClient> { + + /** + * 构造函数 + * + * @param host + * Redis 主机地址 + * @param port + * Redis 端口 + */ + public LettuceFactory(final String host, final int port) { + this(host, port, null); + } + + /** + * 构造函数 + * + * @param host + * Redis 主机地址 + * @param port + * Redis 端口 + * @param lettuceClientConfig + * 客户端配置 + */ + public LettuceFactory(final String host, final int port, final LettuceClientConfig lettuceClientConfig) { + this(RedisURI.builder().withHost(host).withPort(port).build(), lettuceClientConfig); + } + + /** + * 构造函数 + * + * @param uri + * {@link RedisURI} + */ + public LettuceFactory(final RedisURI uri) { + super(RedisClient.create(uri)); + } + + /** + * 构造函数 + * + * @param uri + * {@link RedisURI} + * @param lettuceClientConfig + * 客户端配置 + */ + public LettuceFactory(final RedisURI uri, final LettuceClientConfig lettuceClientConfig) { + this(buildRedisURI(uri, lettuceClientConfig)); + } + + @Override + public StatefulRedisConnection create() throws Exception { + return getClient().connect(new ByteArrayCodec()); + } + + private static RedisURI buildRedisURI(final RedisURI uri, final LettuceClientConfig lettuceClientConfig) { + if(lettuceClientConfig != null){ + if(Validate.hasText(lettuceClientConfig.getPassword())){ + final RedisCredentialsProvider redisCredentialsProvider = Validate.hasText( + lettuceClientConfig.getPassword()) ? new StaticCredentialsProvider( + Validate.hasText(lettuceClientConfig.getUser()) ? lettuceClientConfig.getUser() : + null, lettuceClientConfig.getPassword().toCharArray()) : null; + uri.setCredentialsProvider(redisCredentialsProvider); + } + + uri.setDatabase(lettuceClientConfig.getDatabase()); + Optional.ofNullable(lettuceClientConfig.getConnectionTimeout()).ifPresent(uri::setTimeout); + uri.setClientName(lettuceClientConfig.getClientName()); + } + + return uri; + } + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/LettucePool.java b/buession-redis/src/main/java/io/lettuce/core/LettucePool.java new file mode 100644 index 000000000..327bd003f --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/LettucePool.java @@ -0,0 +1,271 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core; + +import com.buession.redis.core.RedisNode; +import io.lettuce.core.api.StatefulRedisConnection; +import org.apache.commons.pool2.PooledObjectFactory; +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.URI; + +/** + * Lettuce 连接池 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettucePool extends Pool> { + + private final static Logger logger = LoggerFactory.getLogger(LettucePool.class); + + /** + * 构造函数 + */ + public LettucePool() { + this(RedisNode.DEFAULT_HOST, RedisNode.DEFAULT_PORT); + } + + /** + * 构造函数 + * + * @param url + * 连接地址 + */ + public LettucePool(final String url) { + this(URI.create(url)); + } + + /** + * 构造函数 + * + * @param url + * 连接地址 + * @param lettuceClientConfig + * 客户端配置 + */ + public LettucePool(final String url, final LettuceClientConfig lettuceClientConfig) { + this(new GenericObjectPoolConfig<>(), new LettuceFactory(RedisURI.create(url), lettuceClientConfig)); + } + + /** + * 构造函数 + * + * @param host + * Redis 主机地址 + * @param port + * Redis 端口 + */ + public LettucePool(final String host, final int port) { + this(new LettuceFactory(host, port)); + } + + /** + * 构造函数 + * + * @param host + * Redis 主机地址 + * @param port + * Redis 端口 + * @param lettuceClientConfig + * 客户端配置 + */ + public LettucePool(final String host, final int port, final LettuceClientConfig lettuceClientConfig) { + this(new LettuceFactory(host, port, lettuceClientConfig)); + } + + /** + * 构造函数 + * + * @param host + * Redis 主机地址 + * @param port + * Redis 端口 + * @param user + * 用户名 + * @param password + * 密码 + */ + public LettucePool(final String host, final int port, final String user, final String password) { + this(new LettuceFactory(host, port, DefaultLettuceClientConfig.builder().credentials(user, password).build())); + } + + /** + * 构造函数 + * + * @param factory + * 线程池对象工厂 + */ + public LettucePool(final PooledObjectFactory> factory) { + super(factory); + } + + /** + * 构造函数 + * + * @param poolConfig + * 线程池配置 + */ + public LettucePool(final GenericObjectPoolConfig> poolConfig) { + this(poolConfig, RedisNode.DEFAULT_HOST, RedisNode.DEFAULT_PORT); + } + + /** + * 构造函数 + * + * @param poolConfig + * 线程池配置 + * @param url + * 连接地址 + */ + public LettucePool(final GenericObjectPoolConfig> poolConfig, + final String url) { + this(poolConfig, URI.create(url)); + } + + /** + * 构造函数 + * + * @param poolConfig + * 线程池配置 + * @param host + * Redis 主机地址 + * @param port + * Redis 端口 + */ + public LettucePool(final GenericObjectPoolConfig> poolConfig, + final String host, final int port) { + this(poolConfig, new LettuceFactory(host, port, DefaultLettuceClientConfig.builder().build())); + } + + /** + * 构造函数 + * + * @param poolConfig + * 线程池配置 + * @param host + * Redis 主机地址 + * @param port + * Redis 端口 + * @param user + * 用户名 + * @param password + * 密码 + */ + public LettucePool(final GenericObjectPoolConfig> poolConfig, + final String host, final int port, final String user, final String password) { + this(poolConfig, new LettuceFactory(host, port, + DefaultLettuceClientConfig.builder().credentials(user, password).build())); + } + + /** + * 构造函数 + * + * @param poolConfig + * 线程池配置 + * @param host + * Redis 主机地址 + * @param port + * Redis 端口 + * @param lettuceClientConfig + * 客户端配置 + */ + public LettucePool(final GenericObjectPoolConfig> poolConfig, + final String host, final int port, final LettuceClientConfig lettuceClientConfig) { + this(poolConfig, new LettuceFactory(host, port, lettuceClientConfig)); + } + + /** + * 构造函数 + * + * @param uri + * 连接 URL + */ + public LettucePool(final URI uri) { + this(new LettucePoolConfig<>(), uri); + } + + /** + * 构造函数 + * + * @param poolConfig + * 线程池配置 + * @param uri + * 连接 URL + */ + public LettucePool(final GenericObjectPoolConfig> poolConfig, + final URI uri) { + this(poolConfig, uri, DefaultLettuceClientConfig.builder().build()); + } + + /** + * 构造函数 + * + * @param poolConfig + * 线程池配置 + * @param uri + * 连接 URL + * @param lettuceClientConfig + * 客户端配置 + */ + public LettucePool(final GenericObjectPoolConfig> poolConfig, final URI uri, + final LettuceClientConfig lettuceClientConfig) { + this(poolConfig, new LettuceFactory(RedisURI.create(uri), lettuceClientConfig)); + } + + /** + * 构造函数 + * + * @param poolConfig + * 线程池配置 + * @param factory + * 连接线对象工厂 + */ + public LettucePool(final GenericObjectPoolConfig> poolConfig, + final PooledObjectFactory> factory) { + super(factory, poolConfig); + } + + @Override + public StatefulRedisConnection getResource() { + StatefulRedisConnection connection = super.getResource(); + return connection; + } + + @Override + public void returnResource(final StatefulRedisConnection resource) { + if(resource != null){ + try{ + super.returnResource(resource); + }catch(RuntimeException e){ + super.returnBrokenResource(resource); + logger.warn("Resource is returned to the pool as broken", e); + } + } + } + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/LettucePoolConfig.java b/buession-redis/src/main/java/io/lettuce/core/LettucePoolConfig.java new file mode 100644 index 000000000..f5ff2b5a4 --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/LettucePoolConfig.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core; + +import io.lettuce.core.api.StatefulConnection; +import io.lettuce.core.support.BoundedPoolConfig; +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; + +import java.time.Duration; + +/** + * Lettuce 连接池配置 + * + * @param + * Key 类型 + * @param + * 值类型 + * @param + * {@link StatefulConnection} 类型 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettucePoolConfig> extends GenericObjectPoolConfig { + + /** + * 构造函数 + */ + public LettucePoolConfig() { + final BoundedPoolConfig boundedPoolConfig = BoundedPoolConfig.create(); + + setMaxTotal(boundedPoolConfig.getMaxTotal()); + setMinIdle(boundedPoolConfig.getMinIdle()); + setMaxIdle(boundedPoolConfig.getMaxIdle()); + setTestOnCreate(boundedPoolConfig.isTestOnCreate()); + setTestWhileIdle(true); + setMinEvictableIdleTime(Duration.ofMillis(60000)); + setTimeBetweenEvictionRuns(Duration.ofMillis(30000)); + setNumTestsPerEvictionRun(-1); + } + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/LettuceSentinelFactory.java b/buession-redis/src/main/java/io/lettuce/core/LettuceSentinelFactory.java new file mode 100644 index 000000000..16a5af331 --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/LettuceSentinelFactory.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core; + +import com.buession.core.converter.mapper.PropertyMapper; +import com.buession.core.validator.Validate; +import com.buession.net.HostAndPort; +import io.lettuce.core.codec.ByteArrayCodec; +import io.lettuce.core.sentinel.api.StatefulRedisSentinelConnection; + +import java.util.Set; + +/** + * Lettuce 哨兵连接对象工厂 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceSentinelFactory + extends AbstractLettuceFactory, RedisClient> { + + /** + * 构造函数 + * + * @param masterName + * Master 名称 + * @param sentinels + * Redis 哨兵节点 + */ + public LettuceSentinelFactory(final String masterName, final Set sentinels) { + this(buildRedisURI(masterName, sentinels, DefaultLettuceClientConfig.builder().build())); + } + + /** + * 构造函数 + * + * @param masterName + * Master 名称 + * @param sentinels + * Redis 哨兵节点 + * @param lettuceClientConfig + * 客户端配置 + */ + public LettuceSentinelFactory(final String masterName, final Set sentinels, + final LettuceClientConfig lettuceClientConfig) { + this(buildRedisURI(masterName, sentinels, lettuceClientConfig)); + } + + protected LettuceSentinelFactory(final RedisURI uri) { + super(RedisClient.create(uri)); + } + + @Override + public StatefulRedisSentinelConnection create() throws Exception { + return getClient().connectSentinel(new ByteArrayCodec()); + } + + private static RedisURI buildRedisURI(final String masterName, final Set sentinels, + final LettuceClientConfig lettuceClientConfig) { + final PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenHasText(); + final RedisURI.Builder builder = RedisURI.builder().withDatabase(lettuceClientConfig.getDatabase()) + .withSsl(lettuceClientConfig.isSsl()); + + propertyMapper.from(masterName).to(builder::withSentinelMasterId); + propertyMapper.alwaysApplyingWhenNonNull().from(lettuceClientConfig.getConnectionTimeout()) + .to(builder::withTimeout); + propertyMapper.from(lettuceClientConfig.getClientName()).to(builder::withClientName); + sentinels.forEach((sentinel)->{ + builder.withSentinel(sentinel.getHost(), sentinel.getPort()); + if(Validate.hasText(lettuceClientConfig.getPassword())){ + if(Validate.hasText(lettuceClientConfig.getUser())){ + builder.withAuthentication(lettuceClientConfig.getUser(), lettuceClientConfig.getPassword()); + }else{ + builder.withPassword(lettuceClientConfig.getPassword().toCharArray()); + } + } + }); + + return builder.build(); + } + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/LettuceSentinelPool.java b/buession-redis/src/main/java/io/lettuce/core/LettuceSentinelPool.java new file mode 100644 index 000000000..e4bed6f8b --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/LettuceSentinelPool.java @@ -0,0 +1,326 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core; + +import com.buession.net.HostAndPort; +import io.lettuce.core.sentinel.api.StatefulRedisSentinelConnection; +import org.apache.commons.pool2.PooledObjectFactory; +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.Set; + +/** + * Lettuce 哨兵连接池 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceSentinelPool extends Pool> { + + private LettuceSentinelFactory lettuceFactory; + + private LettuceClientConfig sentinelClientConfig; + + //protected final Collection masterListeners = new ArrayList<>(); + + private volatile HostAndPort currentMaster; + + private final Object initPoolLock = new Object(); + + private final static Logger logger = LoggerFactory.getLogger(LettuceSentinelPool.class); + + /** + * 构造函数 + * + * @param masterName + * Master 节点名称 + * @param sentinels + * 哨兵节点 + */ + public LettuceSentinelPool(final String masterName, final Set sentinels) { + this(masterName, sentinels, DefaultLettuceClientConfig.builder().build(), + DefaultLettuceClientConfig.builder().build()); + } + + /** + * 构造函数 + * + * @param masterName + * Master 节点名称 + * @param sentinels + * 哨兵节点 + * @param lettuceClientConfig + * 客户端配置 + * @param sentinelClientConfig + * 哨兵节点客户端配置 + */ + public LettuceSentinelPool(final String masterName, final Set sentinels, + final LettuceClientConfig lettuceClientConfig, + final LettuceClientConfig sentinelClientConfig) { + super(new LettuceSentinelFactory(masterName, sentinels, sentinelClientConfig)); + } + + /** + * 构造函数 + * + * @param masterName + * Master 节点名称 + * @param poolConfig + * 线程池配置 + * @param sentinels + * 哨兵节点 + */ + public LettuceSentinelPool(final String masterName, + final GenericObjectPoolConfig> poolConfig, + final Set sentinels) { + this(masterName, sentinels, poolConfig, DefaultLettuceClientConfig.builder().build(), + DefaultLettuceClientConfig.builder().build()); + } + + /** + * 构造函数 + * + * @param masterName + * Master 节点名称 + * @param sentinels + * 哨兵节点 + * @param poolConfig + * 线程池配置 + * @param lettuceClientConfig + * 客户端配置 + * @param sentinelClientConfig + * 哨兵节点客户端配置 + */ + public LettuceSentinelPool(final String masterName, final Set sentinels, + final GenericObjectPoolConfig> poolConfig, + final LettuceClientConfig lettuceClientConfig, + final LettuceClientConfig sentinelClientConfig) { + this(masterName, sentinels, poolConfig, new LettuceSentinelFactory(masterName, sentinels, lettuceClientConfig)); + } + + /** + * 构造函数 + * + * @param masterName + * Master 节点名称 + * @param sentinels + * 哨兵节点 + * @param poolConfig + * 线程池配置 + * @param factory + * 连接线对象工厂 + */ + protected LettuceSentinelPool(final String masterName, final Set sentinels, + final GenericObjectPoolConfig> poolConfig, + final PooledObjectFactory> factory) { + super(factory, poolConfig); + + HostAndPort master = initSentinels(masterName, sentinels); + initMaster(master); + } + + @Override + public StatefulRedisSentinelConnection getResource() { + StatefulRedisSentinelConnection connection = super.getResource(); + //jedis.setDataSource(this); + return connection; + } + + @Override + public void returnResource(final StatefulRedisSentinelConnection resource) { + if(resource != null){ + try{ + super.returnResource(resource); + }catch(RuntimeException e){ + super.returnBrokenResource(resource); + logger.warn("Resource is returned to the pool as broken", e); + } + } + } + + @Override + public void destroy() { + //for(MasterListener m : masterListeners){ + //m.shutdown(); + //} + + super.destroy(); + } + + private void initMaster(final HostAndPort master) { + synchronized(initPoolLock){ + if(master.equals(currentMaster) == false){ + currentMaster = master; + //factory.setHostAndPort(currentHostMaster); although we clear the pool, we still have to check the + // returned object in getResource, this call only clears idle instances, not borrowed instances + super.clear(); + + logger.info("Created LettuceSentinelPool to master at {}", master); + } + } + } + + private HostAndPort initSentinels(final String masterName, final Set sentinels) { + return null; + } + + private static HostAndPort toHostAndPort(final List getMasterAddrByNameResult) { + String host = getMasterAddrByNameResult.get(0); + int port = Integer.parseInt(getMasterAddrByNameResult.get(1)); + + return new HostAndPort(host, port); + } + + /* + protected final class MasterListener extends Thread { + + private String masterName; + + private String host; + + private int port; + + private long subscribeRetryWaitTimeMillis = 5000; + + private volatile Jedis j; + + private final AtomicBoolean running = new AtomicBoolean(false); + + private final Logger logger = LoggerFactory.getLogger(MasterListener.class); + + private MasterListener() { + super(); + } + + public MasterListener(String masterName, String host, int port) { + super(String.format("MasterListener-%s-[%s:%d]", masterName, host, port)); + this.masterName = masterName; + this.host = host; + this.port = port; + } + + public MasterListener(String masterName, String host, int port, long subscribeRetryWaitTimeMillis) { + this(masterName, host, port); + this.subscribeRetryWaitTimeMillis = subscribeRetryWaitTimeMillis; + } + + @Override + public void run() { + running.set(true); + + while(running.get()){ + try{ + // double check that it is not being shutdown + if(running.get() == false){ + break; + } + + final HostAndPort hostPort = new HostAndPort(host, port); + StatefulRedisSentinelConnection connection = + RedisClient.create(RedisURI.create(host, port)).connect(new ByteArrayCodec()); + RedisCommands commands = connection.sync(); + j = new Jedis(hostPort, sentinelClientConfig); + + // code for active refresh + List masterAddr = j.sentinelGetMasterAddrByName(masterName); + if(masterAddr == null || masterAddr.size() != 2){ + logger.warn("Can not get master addr, master name: {}. Sentinel: {}.", masterName, + hostPort); + }else{ + initMaster(toHostAndPort(masterAddr)); + } + + j.subscribe(new JedisPubSub() { + + @Override + public void onMessage(String channel, String message) { + logger.debug("Sentinel {} published: {}.", hostPort, message); + + String[] switchMasterMsg = message.split(" "); + + if(switchMasterMsg.length > 3){ + + if(masterName.equals(switchMasterMsg[0])){ + initMaster(toHostAndPort(Arrays.asList(switchMasterMsg[3], switchMasterMsg[4]))); + }else{ + if(logger.isDebugEnabled()){ + logger.debug( + "Ignoring message on +switch-master for master name {}, our master name is {}", + switchMasterMsg[0], masterName); + } + } + + }else{ + logger.error("Invalid message received on Sentinel {} on channel +switch-master: {}", + hostPort, message); + } + } + }, "+switch-master"); + + }catch(JedisException e){ + if(running.get()){ + logger.error("Lost connection to Sentinel at {}:{}. Sleeping 5000ms and retrying.", host, + port, e); + try{ + Thread.sleep(subscribeRetryWaitTimeMillis); + }catch(InterruptedException e1){ + logger.error("Sleep interrupted: ", e1); + } + }else{ + if(logger.isDebugEnabled()){ + logger.debug("Unsubscribing from Sentinel at {}:{}", host, port); + } + } + }finally{ + if(j != null){ + j.close(); + } + } + } + } + + public void shutdown() { + try{ + if(logger.isDebugEnabled()){ + logger.debug("Shutting down listener on {}:{}", host, port); + } + running.set(false); + // This isn't good, the Jedis object is not thread safe + if(j != null){ + j.close(); + } + }catch(RuntimeException e){ + logger.error("Caught exception while shutting down: ", e); + } + } + + } + + */ + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/Pool.java b/buession-redis/src/main/java/io/lettuce/core/Pool.java new file mode 100644 index 000000000..479570b99 --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/Pool.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core; + +import org.apache.commons.pool2.PooledObjectFactory; +import org.apache.commons.pool2.impl.AbandonedConfig; +import org.apache.commons.pool2.impl.GenericObjectPool; +import org.apache.commons.pool2.impl.GenericObjectPoolConfig; + +/** + * 连接池 + * + * @author Yong.Teng + * @since 3.0.0 + */ +public class Pool extends GenericObjectPool { + + public Pool(PooledObjectFactory factory) { + super(factory); + } + + public Pool(PooledObjectFactory factory, GenericObjectPoolConfig config) { + super(factory, config); + } + + public Pool(PooledObjectFactory factory, GenericObjectPoolConfig config, AbandonedConfig abandonedConfig) { + super(factory, config, abandonedConfig); + } + + public T getResource() { + try{ + return super.borrowObject(); + }catch(RedisException re){ + throw re; + }catch(Exception e){ + throw new RedisException("Could not get a resource from the pool", e); + } + } + + public void returnResource(final T resource) { + if(resource == null){ + return; + } + try{ + super.returnObject(resource); + }catch(RuntimeException e){ + throw new RedisException("Could not return the resource to the pool", e); + } + } + + public void returnBrokenResource(final T resource) { + if(resource == null){ + return; + } + try{ + super.invalidateObject(resource); + }catch(Exception e){ + throw new RedisException("Could not return the broken resource to the pool", e); + } + } + + @Override + public void addObjects(int count) { + try{ + for(int i = 0; i < count; i++){ + addObject(); + } + }catch(Exception e){ + throw new RedisException("Error trying to add idle objects", e); + } + } + + @Override + public void close() { + destroy(); + } + + public void destroy() { + try{ + super.close(); + }catch(RuntimeException e){ + throw new RedisException("Could not destroy the pool", e); + } + } + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/api/PipeliningFlushPolicy.java b/buession-redis/src/main/java/io/lettuce/core/api/PipeliningFlushPolicy.java new file mode 100644 index 000000000..c3d71e46b --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/api/PipeliningFlushPolicy.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core.api; + +import com.buession.core.utils.Assert; +import com.buession.redis.client.connection.lettuce.LettuceRedisConnection; +import io.lettuce.core.BufferedFlushing; +import io.lettuce.core.FlushEachCommand; +import io.lettuce.core.FlushOnClose; + +/** + * Strategy interface to control pipelining flush behavior. Lettuce writes (flushes) each command individually to the + * Redis connection. Flushing behavior can be customized to optimize for performance. Flushing can be either stateless + * or stateful. An example for stateful flushing is size-based (buffer) flushing to flush after a configured number of + * commands. + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface PipeliningFlushPolicy { + + /** + * Return a policy to flush after each command (default behavior). + * + * @return A policy to flush after each command. + */ + static PipeliningFlushPolicy flushEachCommand() { + return new FlushEachCommand(); + } + + /** + * Return a policy to flush only if {@link LettuceRedisConnection#closePipeline()} is called. + * + * @return A policy to flush after each command. + */ + static PipeliningFlushPolicy flushOnClose() { + return new FlushOnClose(); + } + + /** + * Return a policy to buffer commands and to flush once reaching the configured {@code bufferSize}. The buffer is + * recurring so a buffer size of e.g. {@code 2} will flush after 2, 4, 6, … commands. + * + * @param bufferSize + * the number of commands to buffer before flushing. Must be greater than zero. + * + * @return A policy to flush buffered commands to the Redis connection once the configured number of commands was + * issued. + */ + static PipeliningFlushPolicy buffered(int bufferSize) { + Assert.isFalse(bufferSize > 0, "Buffer size must be greater than 0"); + return ()->new BufferedFlushing(bufferSize); + } + + PipeliningFlushState newPipeline(); + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/api/PipeliningFlushState.java b/buession-redis/src/main/java/io/lettuce/core/api/PipeliningFlushState.java new file mode 100644 index 000000000..40f2ffba5 --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/api/PipeliningFlushState.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core.api; + +/** + * State object associated with flushing of the currently ongoing pipeline. + * + * @author Yong.Teng + * @since 3.0.0 + */ +public interface PipeliningFlushState { + + /** + * Callback if the pipeline gets opened. + * + * @param connection + * {@link StatefulConnection} + */ + void onOpen(StatefulConnection connection); + + /** + * Callback for each issued Redis command. + * + * @param connection + * {@link StatefulConnection} + */ + void onCommand(StatefulConnection connection); + + /** + * Callback if the pipeline gets closed. + * + * @param connection + * {@link StatefulConnection} + */ + void onClose(StatefulConnection connection); + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/api/package-info.java b/buession-redis/src/main/java/io/lettuce/core/api/package-info.java new file mode 100644 index 000000000..1c7ce6c2a --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/api/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package io.lettuce.core.api; \ No newline at end of file diff --git a/buession-redis/src/main/java/io/lettuce/core/package-info.java b/buession-redis/src/main/java/io/lettuce/core/package-info.java new file mode 100644 index 000000000..0aaaf415b --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package io.lettuce.core; \ No newline at end of file diff --git a/buession-redis/src/main/java/io/lettuce/core/support/ConnectionPoolUtils.java b/buession-redis/src/main/java/io/lettuce/core/support/ConnectionPoolUtils.java new file mode 100644 index 000000000..cc86c52d4 --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/support/ConnectionPoolUtils.java @@ -0,0 +1,173 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core.support; + +import com.buession.net.HostAndPort; +import io.lettuce.core.LettuceClientConfig; +import io.lettuce.core.LettuceClusterPool; +import io.lettuce.core.LettucePool; +import io.lettuce.core.LettucePoolConfig; +import io.lettuce.core.LettuceSentinelPool; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; +import io.lettuce.core.sentinel.api.StatefulRedisSentinelConnection; + +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class ConnectionPoolUtils { + + private ConnectionPoolUtils() { + + } + + public static LettucePool createLettucePool( + final LettucePoolConfig> lettucePoolConfig, + final String host, final int port, final LettuceClientConfig lettuceClientConfig) { + return createLettucePool(lettucePoolConfig, host, port, lettuceClientConfig, true); + } + + public static LettucePool createLettucePool( + final LettucePoolConfig> lettucePoolConfig, + final String host, final int port, final LettuceClientConfig lettuceClientConfig, final + boolean wrapConnections) { + AtomicReference>> poolRef = new AtomicReference<>(); + + LettucePool pool = new LettucePool(lettucePoolConfig, host, port, lettuceClientConfig) { + + @Override + public StatefulRedisConnection borrowObject() throws Exception { + return wrapConnections ? ConnectionWrapping.wrapConnection(super.borrowObject(), poolRef.get()) + : super.borrowObject(); + } + + @SuppressWarnings({"unchecked"}) + @Override + public void returnObject(StatefulRedisConnection obj) { + if(wrapConnections && obj instanceof ConnectionWrapping.HasTargetConnection){ + StatefulRedisConnection connection = + (StatefulRedisConnection) ((ConnectionWrapping.HasTargetConnection) obj).getTargetConnection(); + super.returnObject(connection); + return; + } + + super.returnObject(obj); + } + }; + + poolRef.set(new ObjectPoolWrapper<>(pool)); + + return pool; + } + + public static LettuceSentinelPool createLettuceSentinelPool(final String masterName, + final LettucePoolConfig> lettucePoolConfig, + final Set sentinels, + final LettuceClientConfig lettuceClientConfig, + final LettuceClientConfig sentinelClientConfig) { + return createLettuceSentinelPool(masterName, lettucePoolConfig, sentinels, lettuceClientConfig, + sentinelClientConfig, true); + } + + public static LettuceSentinelPool createLettuceSentinelPool(final String masterName, + final LettucePoolConfig> lettucePoolConfig, + final Set sentinels, + final LettuceClientConfig lettuceClientConfig, + final LettuceClientConfig sentinelClientConfig, + final boolean wrapConnections) { + AtomicReference>> poolRef = new AtomicReference<>(); + + final LettuceSentinelPool pool = new LettuceSentinelPool(masterName, sentinels, lettucePoolConfig, + lettuceClientConfig, sentinelClientConfig) { + + @Override + public StatefulRedisSentinelConnection borrowObject() throws Exception { + return wrapConnections ? ConnectionWrapping.wrapConnection(super.borrowObject(), poolRef.get()) + : super.borrowObject(); + } + + @SuppressWarnings({"unchecked"}) + @Override + public void returnObject(StatefulRedisSentinelConnection obj) { + if(wrapConnections && obj instanceof ConnectionWrapping.HasTargetConnection){ + StatefulRedisSentinelConnection connection = + (StatefulRedisSentinelConnection) ((ConnectionWrapping.HasTargetConnection) obj).getTargetConnection(); + super.returnObject(connection); + return; + } + + super.returnObject(obj); + } + }; + + poolRef.set(new ObjectPoolWrapper<>(pool)); + + return pool; + } + + public static LettuceClusterPool createLettuceClusterPool( + final LettucePoolConfig> lettucePoolConfig, + final Set nodes, final LettuceClientConfig lettuceClientConfig) { + return createLettuceClusterPool(lettucePoolConfig, nodes, lettuceClientConfig, true); + } + + public static LettuceClusterPool createLettuceClusterPool( + final LettucePoolConfig> lettucePoolConfig, + final Set nodes, final LettuceClientConfig lettuceClientConfig, + final boolean wrapConnections) { + AtomicReference>> poolRef = new AtomicReference<>(); + + final LettuceClusterPool pool = new LettuceClusterPool(nodes, lettucePoolConfig, lettuceClientConfig) { + + @Override + public StatefulRedisClusterConnection borrowObject() throws Exception { + return wrapConnections ? ConnectionWrapping.wrapConnection(super.borrowObject(), poolRef.get()) + : super.borrowObject(); + } + + @SuppressWarnings({"unchecked"}) + @Override + public void returnObject(StatefulRedisClusterConnection obj) { + if(wrapConnections && obj instanceof ConnectionWrapping.HasTargetConnection){ + StatefulRedisClusterConnection connection = + (StatefulRedisClusterConnection) ((ConnectionWrapping.HasTargetConnection) obj).getTargetConnection(); + super.returnObject(connection); + return; + } + + super.returnObject(obj); + } + }; + + poolRef.set(new ObjectPoolWrapper<>(pool)); + + return pool; + } + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/support/ObjectPoolWrapper.java b/buession-redis/src/main/java/io/lettuce/core/support/ObjectPoolWrapper.java new file mode 100644 index 000000000..1b313db20 --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/support/ObjectPoolWrapper.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package io.lettuce.core.support; + +import org.apache.commons.pool2.ObjectPool; + +import java.util.concurrent.CompletableFuture; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +class ObjectPoolWrapper implements ConnectionWrapping.Origin { + + private static final CompletableFuture COMPLETED = CompletableFuture.completedFuture(null); + + private final ObjectPool pool; + + ObjectPoolWrapper(ObjectPool pool) { + this.pool = pool; + } + + @Override + public void returnObject(T o) throws Exception { + pool.returnObject(o); + } + + @Override + public CompletableFuture returnObjectAsync(T o) throws Exception { + pool.returnObject(o); + return COMPLETED; + } + +} diff --git a/buession-redis/src/main/java/io/lettuce/core/support/package-info.java b/buession-redis/src/main/java/io/lettuce/core/support/package-info.java new file mode 100644 index 000000000..bdf46fb76 --- /dev/null +++ b/buession-redis/src/main/java/io/lettuce/core/support/package-info.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +/** + * @author Yong.Teng + */ +package io.lettuce.core.support; \ No newline at end of file diff --git a/buession-redis/src/test/java/com/buession/redis/jedis/AbstractJedisRedisTest.java b/buession-redis/src/test/java/com/buession/redis/jedis/AbstractJedisRedisTest.java new file mode 100644 index 000000000..1faca39c3 --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/jedis/AbstractJedisRedisTest.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2020 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.jedis; + +import com.buession.redis.RedisTemplate; +import com.buession.redis.client.connection.datasource.jedis.JedisDataSource; +import com.buession.redis.core.PoolConfig; + +/** + * @author Yong.Teng + */ +public abstract class AbstractJedisRedisTest { + + protected JedisDataSource dataSource() { + JedisDataSource dataSource = new JedisDataSource(); + + dataSource.setHost("192.168.0.231"); + dataSource.setPort(6379); + dataSource.setDatabase(1); + dataSource.setPassword("rds_PWD"); + dataSource.setPoolConfig(new PoolConfig()); + + return dataSource; + } + + protected RedisTemplate redisTemplate() { + RedisTemplate redisTemplate = new RedisTemplate(dataSource()); + + redisTemplate.afterPropertiesSet(); + + return redisTemplate; + } + +} diff --git a/buession-redis/src/test/java/com/buession/redis/jedis/JedisGeoTest.java b/buession-redis/src/test/java/com/buession/redis/jedis/JedisGeoTest.java new file mode 100644 index 000000000..c70f07b92 --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/jedis/JedisGeoTest.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.jedis; + +import com.buession.lang.Geo; +import com.buession.redis.RedisTemplate; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class JedisGeoTest extends AbstractJedisRedisTest { + + @Test + public void geoAdd() { + RedisTemplate redisTemplate = redisTemplate(); + Assertions.assertEquals(redisTemplate.geoAdd("beijing", "gugong", 116.405706, 39.921797), 1L); + Assertions.assertEquals(redisTemplate.geoAdd("beijing", "tiantan", 116.416629, 39.885709), 1L); + } + + @Test + public void geoHash() { + RedisTemplate redisTemplate = redisTemplate(); + List result = redisTemplate.geoHash("beijing", "gugong", "tiantan"); + result.forEach(System.out::println); + } + + @Test + public void geoPos() { + RedisTemplate redisTemplate = redisTemplate(); + List result = redisTemplate.geoPos("beijing", "gugong", "tiantan"); + result.forEach(System.out::println); + } + + @Test + public void geoDist() { + RedisTemplate redisTemplate = redisTemplate(); + Double result = redisTemplate.geoDist("beijing", "gugong", "tiantan"); + System.out.println(result); + } + + @Test + public void geoRadius() { + RedisTemplate redisTemplate = redisTemplate(); + List result = redisTemplate.geoRadius("beijing", 116.405706, 39.921797, 5.0, GeoUnit.KM); + result.forEach(System.out::println); + } + + @Test + public void geoRadiusWithadiusArgument() { + RedisTemplate redisTemplate = redisTemplate(); + List result = redisTemplate.geoRadius("beijing", 116.405706, 39.921797, 5.0, GeoUnit.KM); + result.forEach(System.out::println); + } + +} diff --git a/buession-redis/src/test/java/com/buession/redis/jedis/JedisKeyTest.java b/buession-redis/src/test/java/com/buession/redis/jedis/JedisKeyTest.java new file mode 100644 index 000000000..4b6d1a227 --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/jedis/JedisKeyTest.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.jedis; + +import com.buession.redis.RedisTemplate; +import com.buession.redis.core.ScanResult; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class JedisKeyTest extends AbstractJedisRedisTest { + + @Test + public void exists() { + RedisTemplate redisTemplate = redisTemplate(); + Assertions.assertTrue(redisTemplate.exists("a")); + } + + @Test + public void scan() { + RedisTemplate redisTemplate = redisTemplate(); + ScanResult> result = redisTemplate.scan(0); + System.out.println(result.getCursorAsString()); + result.getResults().forEach(System.out::println); + } + +} diff --git a/buession-redis/src/test/java/com/buession/redis/jedis/JedisPipelineTest.java b/buession-redis/src/test/java/com/buession/redis/jedis/JedisPipelineTest.java new file mode 100644 index 000000000..833c321b6 --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/jedis/JedisPipelineTest.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.jedis; + +import com.buession.redis.RedisTemplate; +import org.junit.jupiter.api.Test; + +import java.util.List; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class JedisPipelineTest extends AbstractJedisRedisTest { + + @Test + public void test() { + RedisTemplate redisTemplate = redisTemplate(); + redisTemplate.pipeline(); + redisTemplate.set("a", "A"); + redisTemplate.exists("a"); + redisTemplate.expire("a", 60); + String ret = redisTemplate.get("a"); + //redisTemplate.role(); + List result = redisTemplate.exec(); + System.out.println(result); + } + +} diff --git a/buession-redis/src/test/java/com/buession/redis/jedis/JedisServerTest.java b/buession-redis/src/test/java/com/buession/redis/jedis/JedisServerTest.java new file mode 100644 index 000000000..3f5b5c6dc --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/jedis/JedisServerTest.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.jedis; + +import com.buession.redis.RedisTemplate; +import com.buession.redis.core.MemoryStats; +import com.buession.redis.core.Module; +import com.buession.redis.core.SlowLog; +import org.junit.jupiter.api.Test; + +import java.util.List; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class JedisServerTest extends AbstractJedisRedisTest { + + @Test + public void time() { + RedisTemplate redisTemplate = redisTemplate(); + System.out.println(redisTemplate.time()); + } + + @Test + public void role() { + RedisTemplate redisTemplate = redisTemplate(); + System.out.println(redisTemplate.role()); + } + + @Test + public void info() { + RedisTemplate redisTemplate = redisTemplate(); + System.out.println(redisTemplate.info()); + } + + @Test + public void slowLogGet() { + RedisTemplate redisTemplate = redisTemplate(); + List result = redisTemplate.slowLogGet(3); + result.forEach(System.out::println); + } + + @Test + public void memoryStats() { + RedisTemplate redisTemplate = redisTemplate(); + MemoryStats result = redisTemplate.memoryStats(); + System.out.println(result); + } + + @Test + public void moduleList() { + RedisTemplate redisTemplate = redisTemplate(); + List result = redisTemplate.moduleList(); + result.forEach(System.out::println); + } + +} diff --git a/buession-redis/src/test/java/com/buession/redis/jedis/JedisStringTest.java b/buession-redis/src/test/java/com/buession/redis/jedis/JedisStringTest.java new file mode 100644 index 000000000..a423750bf --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/jedis/JedisStringTest.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.jedis; + +import com.buession.lang.Status; +import com.buession.redis.RedisTemplate; +import com.buession.redis.core.Options; +import com.buession.redis.core.ScanResult; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class JedisStringTest extends AbstractJedisRedisTest { + + @Test + public void set() { + RedisTemplate redisTemplate = redisTemplate(); + Assertions.assertTrue(redisTemplate.set("jedis", new Options()) == Status.SUCCESS); + } + + @Test + public void get() { + RedisTemplate redisTemplate = redisTemplate(); + String result = redisTemplate.get("jedis"); + System.out.println(result); + } + + @Test + public void getObject() { + RedisTemplate redisTemplate = redisTemplate(); + Options result = redisTemplate.getObject("jedis", Options.class); + System.out.println(result); + } + +} diff --git a/buession-redis/src/test/java/com/buession/redis/jedis/JedisThreadTest.java b/buession-redis/src/test/java/com/buession/redis/jedis/JedisThreadTest.java new file mode 100644 index 000000000..b96ae3fc6 --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/jedis/JedisThreadTest.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.jedis; + +import com.buession.redis.RedisTemplate; +import org.junit.jupiter.api.Test; +import redis.clients.jedis.DefaultJedisClientConfig; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisClientConfig; + +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class JedisThreadTest extends AbstractJedisRedisTest { + + @Test + public void test() { + //RedisTemplate redisTemplate = redisTemplate(); + + //拒绝策略 + ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor( + 4, + 8, + 10000, + TimeUnit.MILLISECONDS, + new LinkedBlockingQueue<>(8) + ); + + JedisClientConfig clientConfig = DefaultJedisClientConfig.builder().password("rds_PWD").build(); + for(int i = 0; i < 1; i++){ + threadPoolExecutor.execute(()->{ + try{ + Jedis jedis = new Jedis("192.168.0.231", 6379, clientConfig); + //String result = redisTemplate.get("a"); + System.out.println(jedis); + }catch(Exception e){ + System.out.println(e.getMessage()); + } + }); + } + } + +} diff --git a/buession-redis/src/test/java/com/buession/redis/jedis/JedisTransactionTest.java b/buession-redis/src/test/java/com/buession/redis/jedis/JedisTransactionTest.java new file mode 100644 index 000000000..12f0c071d --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/jedis/JedisTransactionTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.jedis; + +import com.buession.redis.RedisTemplate; +import org.junit.jupiter.api.Test; + +import java.util.List; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class JedisTransactionTest extends AbstractJedisRedisTest { + + @Test + public void exec() { + RedisTemplate redisTemplate = redisTemplate(); + redisTemplate.multi(); + redisTemplate.set("a", "Jedis"); + redisTemplate.exists("a"); + redisTemplate.expire("a", 60); + String ret = redisTemplate.get("a"); + //redisTemplate.role(); + List result = redisTemplate.exec(); + System.out.println(result); + } + + @Test + public void discard() { + RedisTemplate redisTemplate = redisTemplate(); + redisTemplate.multi(); + redisTemplate.set("b", "B"); + redisTemplate.discard(); + } + +} diff --git a/buession-redis/src/test/java/com/buession/redis/lettuce/AbstractLettuceRedisTest.java b/buession-redis/src/test/java/com/buession/redis/lettuce/AbstractLettuceRedisTest.java new file mode 100644 index 000000000..3e56e860b --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/lettuce/AbstractLettuceRedisTest.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2020 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.lettuce; + +import com.buession.redis.RedisTemplate; +import com.buession.redis.client.connection.datasource.lettuce.LettuceDataSource; +import com.buession.redis.core.PoolConfig; + +/** + * @author Yong.Teng + */ +public abstract class AbstractLettuceRedisTest { + + protected LettuceDataSource dataSource() { + LettuceDataSource dataSource = new LettuceDataSource(); + + dataSource.setHost("192.168.0.231"); + dataSource.setPort(6379); + dataSource.setDatabase(1); + dataSource.setPassword("rds_PWD"); + // dataSource.setPoolConfig(new PoolConfig()); + + return dataSource; + } + + protected RedisTemplate redisTemplate() { + RedisTemplate redisTemplate = new RedisTemplate(dataSource()); + + redisTemplate.afterPropertiesSet(); + + return redisTemplate; + } + +} diff --git a/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceGeoTest.java b/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceGeoTest.java new file mode 100644 index 000000000..debac0828 --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceGeoTest.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.lettuce; + +import com.buession.lang.Geo; +import com.buession.redis.RedisTemplate; +import com.buession.redis.core.GeoRadius; +import com.buession.redis.core.GeoUnit; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceGeoTest extends AbstractLettuceRedisTest { + + @Test + public void geoAdd() { + RedisTemplate redisTemplate = redisTemplate(); + Assertions.assertEquals(redisTemplate.geoAdd("beijing", "gugong", 116.405706, 39.921797), 1L); + Assertions.assertEquals(redisTemplate.geoAdd("beijing", "tiantan", 116.416629, 39.885709), 1L); + } + + @Test + public void geoHash() { + RedisTemplate redisTemplate = redisTemplate(); + List result = redisTemplate.geoHash("beijing", "gugong", "tiantan"); + result.forEach(System.out::println); + } + + @Test + public void geoPos() { + RedisTemplate redisTemplate = redisTemplate(); + List result = redisTemplate.geoPos("beijing", "gugong", "tiantan"); + result.forEach(System.out::println); + } + + @Test + public void geoDist() { + RedisTemplate redisTemplate = redisTemplate(); + Double result = redisTemplate.geoDist("beijing", "gugong", "tiantan"); + System.out.println(result); + } + + @Test + public void geoRadius() { + RedisTemplate redisTemplate = redisTemplate(); + List result = redisTemplate.geoRadius("beijing", 116.405706, 39.921797, 5.0, GeoUnit.KM); + result.forEach(System.out::println); + } + + @Test + public void geoRadiusWithadiusArgument() { + RedisTemplate redisTemplate = redisTemplate(); + List result = redisTemplate.geoRadius("beijing", 116.405706, 39.921797, 5.0, GeoUnit.KM); + result.forEach(System.out::println); + } + +} diff --git a/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceKeyTest.java b/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceKeyTest.java new file mode 100644 index 000000000..696342fd7 --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceKeyTest.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.lettuce; + +import com.buession.redis.RedisTemplate; +import com.buession.redis.core.ScanResult; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceKeyTest extends AbstractLettuceRedisTest { + + @Test + public void exists() { + RedisTemplate redisTemplate = redisTemplate(); + Assertions.assertTrue(redisTemplate.exists("a")); + } + + @Test + public void scan() { + RedisTemplate redisTemplate = redisTemplate(); + ScanResult> result = redisTemplate.scan(0); + System.out.println(result.getCursorAsString()); + result.getResults().forEach(System.out::println); + } + +} diff --git a/buession-redis/src/test/java/com/buession/redis/lettuce/LettucePipelineTest.java b/buession-redis/src/test/java/com/buession/redis/lettuce/LettucePipelineTest.java new file mode 100644 index 000000000..e3f1a29b3 --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/lettuce/LettucePipelineTest.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.lettuce; + +import com.buession.redis.RedisTemplate; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettucePipelineTest extends AbstractLettuceRedisTest { + + @Test + public void test() { + RedisTemplate redisTemplate = redisTemplate(); + redisTemplate.pipeline(); + redisTemplate.set("a", "A"); + redisTemplate.exists("a"); + redisTemplate.expire("a", 60); + String ret = redisTemplate.get("a"); + //redisTemplate.role(); + List result = redisTemplate.exec(); + System.out.println(result); + } + +} diff --git a/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceServerTest.java b/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceServerTest.java new file mode 100644 index 000000000..18eebb873 --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceServerTest.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.lettuce; + +import com.buession.redis.RedisTemplate; +import com.buession.redis.core.MemoryStats; +import com.buession.redis.core.Module; +import com.buession.redis.core.SlowLog; +import org.junit.jupiter.api.Test; + +import java.util.List; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceServerTest extends AbstractLettuceRedisTest { + + @Test + public void time() { + RedisTemplate redisTemplate = redisTemplate(); + System.out.println(redisTemplate.time()); + } + + @Test + public void role() { + RedisTemplate redisTemplate = redisTemplate(); + System.out.println(redisTemplate.role()); + } + + @Test + public void info() { + RedisTemplate redisTemplate = redisTemplate(); + System.out.println(redisTemplate.info()); + } + + @Test + public void slowLogGet() { + RedisTemplate redisTemplate = redisTemplate(); + List result = redisTemplate.slowLogGet(3); + result.forEach(System.out::println); + } + + @Test + public void memoryStats() { + RedisTemplate redisTemplate = redisTemplate(); + MemoryStats result = redisTemplate.memoryStats(); + System.out.println(result); + } + + @Test + public void moduleList() { + RedisTemplate redisTemplate = redisTemplate(); + List result = redisTemplate.moduleList(); + result.forEach(System.out::println); + } + +} diff --git a/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceStringTest.java b/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceStringTest.java new file mode 100644 index 000000000..6eb9e1fc6 --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceStringTest.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.lettuce; + +import com.buession.lang.Status; +import com.buession.redis.RedisTemplate; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceStringTest extends AbstractLettuceRedisTest { + + @Test + public void set() { + RedisTemplate redisTemplate = redisTemplate(); + Assertions.assertEquals(redisTemplate.set("a", "A"), Status.SUCCESS); + } + + @Test + public void get() { + RedisTemplate redisTemplate = redisTemplate(); + Assertions.assertEquals(redisTemplate.get("a"), "A"); + } + +} diff --git a/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceThreadTest.java b/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceThreadTest.java new file mode 100644 index 000000000..ebc7b1a4d --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceThreadTest.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.lettuce; + +import com.buession.redis.RedisTemplate; +import org.junit.jupiter.api.Test; + +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceThreadTest extends AbstractLettuceRedisTest { + + @Test + public void test() { + RedisTemplate redisTemplate = redisTemplate(); + + int corePoolSize = 4; //核心线程数 + int maximumPoolSize = 8; //最大线程数 + long keepAliveTime = 10000; //空闲线程存活时间 + BlockingQueue workQueue = new LinkedBlockingQueue<>(8); //阻塞队列 + //拒绝策略 + ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor( + corePoolSize, + maximumPoolSize, + keepAliveTime, + TimeUnit.MILLISECONDS, //空闲线程存活时间的单位 + workQueue + ); + for(int i = 0; i < 8; i++){ + threadPoolExecutor.execute(()->{ + try{ + redisTemplate.multi(); + }catch(Exception e){ + System.out.println(e.getMessage()); + } + }); + } + } + +} diff --git a/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceTransactionTest.java b/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceTransactionTest.java new file mode 100644 index 000000000..9530e6e7a --- /dev/null +++ b/buession-redis/src/test/java/com/buession/redis/lettuce/LettuceTransactionTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. + * See the NOTICE file distributed with this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and limitations under the License. + * + * ========================================================================================================= + * + * This software consists of voluntary contributions made by many individuals on behalf of the + * Apache Software Foundation. For more information on the Apache Software Foundation, please see + * . + * + * +-------------------------------------------------------------------------------------------------------+ + * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | + * | Author: Yong.Teng | + * | Copyright @ 2013-2024 Buession.com Inc. | + * +-------------------------------------------------------------------------------------------------------+ + */ +package com.buession.redis.lettuce; + +import com.buession.redis.RedisTemplate; +import org.junit.jupiter.api.Test; + +import java.util.List; + +/** + * @author Yong.Teng + * @since 3.0.0 + */ +public class LettuceTransactionTest extends AbstractLettuceRedisTest { + + @Test + public void exec() { + RedisTemplate redisTemplate = redisTemplate(); + redisTemplate.multi(); + redisTemplate.set("a", "Lettuce"); + redisTemplate.exists("a"); + redisTemplate.expire("a", 60); + String ret = redisTemplate.get("a"); + //redisTemplate.role(); + List result = redisTemplate.exec(); + System.out.println(result); + } + + @Test + public void discard() { + RedisTemplate redisTemplate = redisTemplate(); + redisTemplate.multi(); + redisTemplate.set("b", "B"); + redisTemplate.discard(); + } + +} diff --git a/buession-session/pom.xml b/buession-session/pom.xml deleted file mode 100644 index 30ae8b032..000000000 --- a/buession-session/pom.xml +++ /dev/null @@ -1,152 +0,0 @@ - - - Buession Session - 4.0.0 - - com.buession - buession-parent - ../buession-parent - 2.3.3 - - buession-session - http://www.buession.com/ - Buession Framework Web Session - jar - - - buession.com Inc. - http://www.buession.com/ - - - - - yong.teng - yong.teng - webmaster@buession.com - - Project Manager - Developer - - - - - - - The Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - A business-friendly OSS license - - - - - scm:git:https://github.com/buession/buessionframework.git - scm:git:https://github.com/buession/buessionframework.git - https://github.com/buession/buessionframework - - - - github - https://github.com/buession/buessionframework/issues - - - - - org.springframework - spring-context-support - - - org.springframework - spring-oxm - - - org.springframework - spring-tx - - - - org.springframework.data - spring-data-redis - - - org.springframework.session - spring-session-data-redis - - - - org.apache.commons - commons-pool2 - - - - redis.clients - jedis - provided - true - - - - io.lettuce - lettuce-core - provided - true - - - - org.slf4j - slf4j-api - - - - junit - junit - - - - - buession-session - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-jar-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-javadoc-plugin - - - org.apache.maven.plugins - maven-resources-plugin - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - org.apache.maven.plugins - maven-release-plugin - - - org.apache.maven.plugins - maven-gpg-plugin - - - org.sonatype.plugins - nexus-staging-maven-plugin - - - - \ No newline at end of file diff --git a/buession-thesaurus/pom.xml b/buession-thesaurus/pom.xml index 03e2bc21d..63957aef5 100644 --- a/buession-thesaurus/pom.xml +++ b/buession-thesaurus/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-thesaurus http://www.buession.com/ @@ -64,8 +64,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -109,8 +109,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-velocity/pom.xml b/buession-velocity/pom.xml index 04aad78c7..a2d8b474f 100644 --- a/buession-velocity/pom.xml +++ b/buession-velocity/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-velocity http://www.buession.com/ @@ -94,14 +94,30 @@ com.fasterxml.jackson.core jackson-core + provided com.fasterxml.jackson.core jackson-annotations + provided com.fasterxml.jackson.core jackson-databind + provided + + + + org.apache.commons + commons-digester3 + + + commons-beanutils + commons-beanutils + + + commons-logging + commons-logging @@ -110,8 +126,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -155,8 +171,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-web/pom.xml b/buession-web/pom.xml index 5a58f64d8..3184eacfd 100644 --- a/buession-web/pom.xml +++ b/buession-web/pom.xml @@ -7,7 +7,7 @@ com.buession buession-parent ../buession-parent - 2.3.3 + 3.0.0 buession-web http://www.buession.com/ @@ -62,11 +62,6 @@ buession-aop ${project.version} - - com.buession - buession-net - ${project.version} - jakarta.servlet @@ -102,7 +97,7 @@ com.fasterxml.jackson.core jackson-annotations - compile + provided true @@ -121,8 +116,8 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api @@ -166,8 +161,8 @@ maven-gpg-plugin - org.sonatype.plugins - nexus-staging-maven-plugin + org.sonatype.central + central-publishing-maven-plugin diff --git a/buession-web/src/main/java/com/buession/web/bind/converter/IgnoreCaseEnumConverterFactory.java b/buession-web/src/main/java/com/buession/web/bind/converter/IgnoreCaseEnumConverterFactory.java index 883c715c4..318996b57 100644 --- a/buession-web/src/main/java/com/buession/web/bind/converter/IgnoreCaseEnumConverterFactory.java +++ b/buession-web/src/main/java/com/buession/web/bind/converter/IgnoreCaseEnumConverterFactory.java @@ -30,6 +30,7 @@ import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.ConverterFactory; import org.springframework.lang.Nullable; +import org.springframework.util.ClassUtils; /** * 忽略大小写将字符串转换为枚举值 @@ -41,11 +42,11 @@ public class IgnoreCaseEnumConverterFactory implements ConverterFactory { @Override - public Converter getConverter(Class targetType){ + public Converter getConverter(Class targetType) { return new StringToEnum(getEnumType(targetType)); } - private static Class getEnumType(Class targetType){ + private static Class getEnumType(Class targetType) { Class enumType = targetType; while(enumType != null && enumType.isEnum() == false){ @@ -62,13 +63,13 @@ private static class StringToEnum> implements Converter enumType; - public StringToEnum(Class enumType){ + public StringToEnum(Class enumType) { this.enumType = enumType; } @Override @Nullable - public T convert(String source){ + public T convert(String source) { if(Validate.isEmpty(source)){ return null; } diff --git a/buession-web/src/main/java/com/buession/web/http/request/annotation/RequestClientIpAnnotationUtils.java b/buession-web/src/main/java/com/buession/web/http/request/annotation/RequestClientIpAnnotationUtils.java index 98f99f1b4..3979e7b90 100644 --- a/buession-web/src/main/java/com/buession/web/http/request/annotation/RequestClientIpAnnotationUtils.java +++ b/buession-web/src/main/java/com/buession/web/http/request/annotation/RequestClientIpAnnotationUtils.java @@ -19,12 +19,12 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.http.request.annotation; -import com.buession.net.utils.InetAddressUtils; +import com.buession.core.utils.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.MethodParameter; @@ -62,7 +62,14 @@ public static Object resolveNamedValue(final MethodParameter parameter, Class clazz = parameter.nestedIfOptional().getNestedParameterType(); if(Long.class.isAssignableFrom(clazz)){ - return InetAddressUtils.ip2long(fn.apply(parameter)); + String[] numbers = StringUtils.splitByWholeSeparatorPreserveAllTokens(fn.apply(parameter), "."); + long result = 0L; + + for(int i = 0; i < 4; ++i){ + result = result << 8 | Integer.parseInt(numbers[i]); + } + + return result; }else if(CharSequence.class.isAssignableFrom(clazz)){ return fn.apply(parameter); }else if(InetAddress.class.isAssignableFrom(clazz)){ diff --git a/buession-web/src/main/java/com/buession/web/mvc/Pagination.java b/buession-web/src/main/java/com/buession/web/mvc/Pagination.java index 4c722a7ea..43618c93b 100644 --- a/buession-web/src/main/java/com/buession/web/mvc/Pagination.java +++ b/buession-web/src/main/java/com/buession/web/mvc/Pagination.java @@ -19,7 +19,7 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.mvc; @@ -32,6 +32,8 @@ */ public class Pagination extends com.buession.core.Pagination { + private final static long serialVersionUID = 6875304438792189818L; + /** * Constructs with default configuration. */ diff --git a/buession-web/src/main/java/com/buession/web/mvc/Response.java b/buession-web/src/main/java/com/buession/web/mvc/Response.java index 27e0d8094..dd1b1d39b 100644 --- a/buession-web/src/main/java/com/buession/web/mvc/Response.java +++ b/buession-web/src/main/java/com/buession/web/mvc/Response.java @@ -21,7 +21,7 @@ * +------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +------------------------------------------------------------------------------------------------+ */ package com.buession.web.mvc; @@ -173,26 +173,6 @@ public Response(boolean state, int code, String message, E data, Pagination pagi setPagination(pagination); } - /** - * 构造函数 - * - * @param state - * 状态,true 为逻辑成功;false 为逻辑失败或出现异常 - * @param code - * 错误码 - * @param message - * 提示或错误消息 - * @param data - * 数据 - * @param pagination - * 分页对象 - */ - @Deprecated - public Response(boolean state, int code, String message, E data, com.buession.core.Pagination pagination) { - this(state, code, message, data); - setPagination(pagination); - } - /** * 构造函数 * @@ -212,24 +192,6 @@ public Response(boolean state, String message, E data, Pagination pagination) { setPagination(pagination); } - /** - * 构造函数 - * - * @param state - * 状态,true 为逻辑成功;false 为逻辑失败或出现异常 - * @param message - * 提示或错误消息 - * @param data - * 数据 - * @param pagination - * 分页对象 - */ - @Deprecated - public Response(boolean state, String message, E data, com.buession.core.Pagination pagination) { - this(state, message, data); - setPagination(pagination); - } - /** * 返回状态,true 为逻辑成功;false 为逻辑失败或出现异常 * @@ -347,13 +309,4 @@ public String toString() { .toString(); } - @Deprecated - protected void setPagination(com.buession.core.Pagination pagination) { - if(pagination != null){ - this.pagination = new Pagination(pagination.getPage(), pagination.getPagesize(), - pagination.getTotalRecords()); - this.pagination.setTotalPages(pagination.getTotalPages()); - } - } - } diff --git a/buession-web/src/main/java/com/buession/web/reactive/filter/PoweredByHeaderFilter.java b/buession-web/src/main/java/com/buession/web/reactive/filter/PoweredByHeaderFilter.java deleted file mode 100644 index bf73738fd..000000000 --- a/buession-web/src/main/java/com/buession/web/reactive/filter/PoweredByHeaderFilter.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - * ================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | - * +------------------------------------------------------------------------------------------------+ - */ -package com.buession.web.reactive.filter; - -/** - * @author Yong.Teng - * @see PoweredByFilter - */ -@Deprecated -public class PoweredByHeaderFilter extends PoweredByFilter { - - /** - * 构造函数 - */ - public PoweredByHeaderFilter(){ - super(); - } - -} diff --git a/buession-web/src/main/java/com/buession/web/servlet/filter/MobileFilter.java b/buession-web/src/main/java/com/buession/web/servlet/filter/MobileFilter.java deleted file mode 100644 index 8a87c6727..000000000 --- a/buession-web/src/main/java/com/buession/web/servlet/filter/MobileFilter.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - * ================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2022 Buession.com Inc. | - * +------------------------------------------------------------------------------------------------+ - */ -package com.buession.web.servlet.filter; - -import java.io.IOException; - -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import com.buession.web.servlet.http.request.RequestUtils; -import org.springframework.web.filter.OncePerRequestFilter; - -/** - * 移动设备过滤器,通过 {@link RequestUtils#isMobile(HttpServletRequest)} 获取到的值设置到 HttpServletRequest attribute 中 - * - * @author Yong.Teng - */ -@Deprecated -public class MobileFilter extends OncePerRequestFilter { - - @Override - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain - filterChain) throws ServletException, IOException{ - request.setAttribute("isMobile", RequestUtils.isMobile(request)); - filterChain.doFilter(request, response); - } - -} \ No newline at end of file diff --git a/buession-web/src/main/java/com/buession/web/servlet/filter/PoweredByHeaderFilter.java b/buession-web/src/main/java/com/buession/web/servlet/filter/PoweredByHeaderFilter.java deleted file mode 100644 index 6d84f07a7..000000000 --- a/buession-web/src/main/java/com/buession/web/servlet/filter/PoweredByHeaderFilter.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with the License. You may obtain - * a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - * ================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +------------------------------------------------------------------------------------------------+ - * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | - * | Author: Yong.Teng | - * | Copyright @ 2013-2019 Buession.com Inc. | - * +------------------------------------------------------------------------------------------------+ - */ -package com.buession.web.servlet.filter; - -/** - * @author Yong.Teng - * @see PoweredByFilter - */ -@Deprecated -public class PoweredByHeaderFilter extends PoweredByFilter { - - public PoweredByHeaderFilter(){ - super(); - } - -} diff --git a/buession-web/src/test/java/com/buession/web/HostName.java b/buession-web/src/test/java/com/buession/web/HostName.java deleted file mode 100644 index 84bdd7061..000000000 --- a/buession-web/src/test/java/com/buession/web/HostName.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. - * See the NOTICE file distributed with this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - * - * ========================================================================================================= - * - * This software consists of voluntary contributions made by many individuals on behalf of the - * Apache Software Foundation. For more information on the Apache Software Foundation, please see - * . - * - * +-------------------------------------------------------------------------------------------------------+ - * | License: http://buession.buession.com.cn/LICENSE | - * | Author: Yong.Teng | - * | Copyright @ 2013-2018 Buession.com Inc. | - * +-------------------------------------------------------------------------------------------------------+ - */ -package com.buession.web; - -import org.junit.Test; - -import java.net.InetAddress; -import java.net.UnknownHostException; - -/** - * @author Yong.Teng - */ -public class HostName { - - @Test - public void test() { - } - -} diff --git a/buession-web/src/test/java/com/buession/web/utils/useragentutils/BrowserTest.java b/buession-web/src/test/java/com/buession/web/utils/useragentutils/BrowserTest.java index ef66d88e2..6ee76a45b 100644 --- a/buession-web/src/test/java/com/buession/web/utils/useragentutils/BrowserTest.java +++ b/buession-web/src/test/java/com/buession/web/utils/useragentutils/BrowserTest.java @@ -19,17 +19,15 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.utils.useragentutils; import com.buession.core.utils.StringUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; -import java.util.LinkedHashSet; -import java.util.stream.Collectors; /** * @author Yong.Teng diff --git a/buession-web/src/test/java/com/buession/web/utils/useragentutils/OperatingSystemTest.java b/buession-web/src/test/java/com/buession/web/utils/useragentutils/OperatingSystemTest.java index 488bd4d9c..421be2281 100644 --- a/buession-web/src/test/java/com/buession/web/utils/useragentutils/OperatingSystemTest.java +++ b/buession-web/src/test/java/com/buession/web/utils/useragentutils/OperatingSystemTest.java @@ -19,13 +19,13 @@ * +-------------------------------------------------------------------------------------------------------+ * | License: http://www.apache.org/licenses/LICENSE-2.0.txt | * | Author: Yong.Teng | - * | Copyright @ 2013-2023 Buession.com Inc. | + * | Copyright @ 2013-2024 Buession.com Inc. | * +-------------------------------------------------------------------------------------------------------+ */ package com.buession.web.utils.useragentutils; import com.buession.core.utils.StringUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays;